зеркало из https://github.com/github/codeql.git
Merge pull request #1836 from jbj/xheader-undef
C++: Support x-macros that are #undef'ed in header
This commit is contained in:
Коммит
2e0c1af6c4
|
@ -95,17 +95,28 @@ predicate usesMacro(HeaderFile hf, string macroName) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** File `f` defines a macro called `macroName`. */
|
||||||
|
predicate definesMacro(File f, string macroName) {
|
||||||
|
exists(Macro m |
|
||||||
|
m.getFile() = f and
|
||||||
|
m.getName() = macroName
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** File `f` un-defines a macro called `macroName`. */
|
||||||
|
predicate undefinesMacro(File f, string macroName) {
|
||||||
|
exists(PreprocessorUndef ud |
|
||||||
|
ud.getFile() = f and
|
||||||
|
ud.getName() = macroName
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* File `f` both defines and un-defines a macro called `macroName`.
|
* File `f` both defines and un-defines a macro called `macroName`.
|
||||||
*/
|
*/
|
||||||
predicate defUndef(File f, string macroName) {
|
predicate defUndef(File f, string macroName) {
|
||||||
exists(Macro m |
|
definesMacro(f, macroName) and
|
||||||
m.getFile() = f and
|
undefinesMacro(f, macroName)
|
||||||
m.getName() = macroName
|
|
||||||
) and exists(PreprocessorUndef ud |
|
|
||||||
ud.getFile() = f and
|
|
||||||
ud.getName() = macroName
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -115,12 +126,24 @@ predicate defUndef(File f, string macroName) {
|
||||||
* and undefined immediately afterwards.
|
* and undefined immediately afterwards.
|
||||||
*/
|
*/
|
||||||
predicate hasXMacro(HeaderFile hf) {
|
predicate hasXMacro(HeaderFile hf) {
|
||||||
|
// Every header that includes `hf` both defines and undefines a macro that's
|
||||||
|
// used in `hf`.
|
||||||
exists(string macroName |
|
exists(string macroName |
|
||||||
usesMacro(hf, macroName) and
|
usesMacro(hf, macroName) and
|
||||||
forex(File f | f.getAnIncludedFile() = hf |
|
forex(File f | f.getAnIncludedFile() = hf |
|
||||||
defUndef(f, macroName)
|
defUndef(f, macroName)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
or
|
||||||
|
// Every header that includes `hf` defines a macro that's used in `hf`, and
|
||||||
|
// `hf` itself undefines it.
|
||||||
|
exists(string macroName |
|
||||||
|
usesMacro(hf, macroName) and
|
||||||
|
undefinesMacro(hf, macroName) and
|
||||||
|
forex(File f | f.getAnIncludedFile() = hf |
|
||||||
|
definesMacro(f, macroName)
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
from HeaderFile hf, string detail, MaybePreprocessorDirective detail1, MaybePreprocessorDirective detail2
|
from HeaderFile hf, string detail, MaybePreprocessorDirective detail1, MaybePreprocessorDirective detail2
|
||||||
|
|
|
@ -53,3 +53,8 @@ enum Items {
|
||||||
#define XMACRO2(id,desc) void use_##();
|
#define XMACRO2(id,desc) void use_##();
|
||||||
#include "items2.h"
|
#include "items2.h"
|
||||||
#undef XMACRO2
|
#undef XMACRO2
|
||||||
|
|
||||||
|
|
||||||
|
#define XMACRO3(id,desc) static const char * id##_item = "The " desc " item";
|
||||||
|
#include "items3.h"
|
||||||
|
// No #undef of XMACRO3. That's handled in items3.h.
|
||||||
|
|
|
@ -32,3 +32,7 @@ enum Items {
|
||||||
#define XMACRO2(id,desc) void use_##();
|
#define XMACRO2(id,desc) void use_##();
|
||||||
#include "items2.h"
|
#include "items2.h"
|
||||||
#undef XMACRO2
|
#undef XMACRO2
|
||||||
|
|
||||||
|
#define XMACRO3(id,desc) static const char * id##_name = desc;
|
||||||
|
#include "items3.h"
|
||||||
|
// No #undef of XMACRO3. That's handled in items3.h.
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
XMACRO3(shield, "Wooden Shield")
|
||||||
|
XMACRO3(boots, "Leather Boots")
|
||||||
|
XMACRO3(helmet, "Helmet")
|
||||||
|
|
||||||
|
#undef XMACRO3
|
Загрузка…
Ссылка в новой задаче