Skip to content

Commit d64b125

Browse files
committed
Macro: Add classes for library vs user macro.
1 parent e9c0c18 commit d64b125

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

cpp/autosar/src/rules/A5-2-2/TraditionalCStyleCastsUsed.ql

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import cpp
1717
import codingstandards.cpp.autosar
18+
import codingstandards.cpp.Macro
1819

1920
/**
2021
* Gets the macro (if any) that generated the given `CStyleCast`.
@@ -34,16 +35,6 @@ Macro getGeneratedFrom(CStyleCast c) {
3435
)
3536
}
3637

37-
/** A macro within the source location of this project. */
38-
class UserProvidedMacro extends Macro {
39-
UserProvidedMacro() { exists(this.getFile().getRelativePath()) }
40-
}
41-
42-
/** A macro defined within a library used by this project. */
43-
class LibraryMacro extends Macro {
44-
LibraryMacro() { not this instanceof UserProvidedMacro }
45-
}
46-
4738
/*
4839
* In theory this query should exclude casts using the "functional notation" syntax, e.g.
4940
* ```

cpp/common/src/codingstandards/cpp/Macro.qll

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,13 @@ pragma[noinline]
6868
predicate isMacroInvocationLocation(MacroInvocation mi, File f, int startChar, int endChar) {
6969
mi.getActualLocation().charLoc(f, startChar, endChar)
7070
}
71+
72+
/** A macro within the source location of this project. */
73+
class UserProvidedMacro extends Macro {
74+
UserProvidedMacro() { exists(this.getFile().getRelativePath()) }
75+
}
76+
77+
/** A macro defined within a library used by this project. */
78+
class LibraryMacro extends Macro {
79+
LibraryMacro() { not this instanceof UserProvidedMacro }
80+
}

0 commit comments

Comments
 (0)