|
18 | 18 | import cpp
|
19 | 19 | import codingstandards.cpp.autosar
|
20 | 20 |
|
| 21 | +predicate hasResponseFileArgument(Compilation c) { c.getAnArgument().matches("@%") } |
| 22 | + |
21 | 23 | class CompilationWithNoWarnings extends Compilation {
|
22 | 24 | CompilationWithNoWarnings() {
|
23 | 25 | getAnArgument() = "-w" or
|
24 |
| - not getAnArgument().regexpMatch("-W[\\w=-]+") |
| 26 | + not exists(EnableWarningFlag enableFlag | |
| 27 | + this.getAnArgument() = enableFlag and |
| 28 | + not exists(DisableWarningFlag disableFlag | |
| 29 | + this.getAnArgument() = disableFlag and |
| 30 | + enableFlag.getWarningType() = disableFlag.getWarningType() |
| 31 | + ) |
| 32 | + ) |
25 | 33 | }
|
26 | 34 | }
|
27 | 35 |
|
28 |
| -predicate hasResponseFileArgument(Compilation c) { c.getAnArgument().matches("@%") } |
| 36 | +class CompilationArgument extends string { |
| 37 | + Compilation compilation; |
| 38 | + |
| 39 | + CompilationArgument() { |
| 40 | + this = compilation.getAnArgument() |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +/** |
| 45 | + * Compiler flags of type -Wfoo or -Wfoo=bar, which enables the `foo` warning. |
| 46 | + */ |
| 47 | +class EnableWarningFlag extends CompilationArgument { |
| 48 | + string warningType; |
| 49 | + |
| 50 | + EnableWarningFlag() { |
| 51 | + warningType = regexpCapture("^-W([\\w-]+)(=.*)?$", 1) |
| 52 | + and not this instanceof DisableWarningFlag |
| 53 | + } |
| 54 | + |
| 55 | + string getWarningType() { |
| 56 | + result = warningType |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | +/** |
| 61 | + * Compiler flags of type -Wno-foo or -Wfoo=0, which disables the `foo` warning |
| 62 | + * and overrules -Wfoo. |
| 63 | + */ |
| 64 | +class DisableWarningFlag extends CompilationArgument { |
| 65 | + string warningType; |
| 66 | + |
| 67 | + DisableWarningFlag() { |
| 68 | + warningType = regexpCapture("^-Wno-([\\w-]+)", 1) or |
| 69 | + warningType = regexpCapture("^-W([\\w-]+)=0", 1) |
| 70 | + } |
| 71 | + |
| 72 | + string getWarningType() { |
| 73 | + result = warningType |
| 74 | + } |
| 75 | +} |
29 | 76 |
|
30 | 77 | from File f
|
31 | 78 | where
|
|
0 commit comments