Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 28 additions & 5 deletions cpp/ql/src/jsf/4.07 Header Files/AV Rule 35.ql
Original file line number Diff line number Diff line change
Expand Up @@ -95,32 +95,55 @@ predicate usesMacro(HeaderFile hf, string macroName) {
)
}

/**
* File `f` both defines and un-defines a macro called `macroName`.
*/
predicate defUndef(File f, 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
) and exists(PreprocessorUndef ud |
)
}

/** 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`.
*/
predicate defUndef(File f, string macroName) {
definesMacro(f, macroName) and
undefinesMacro(f, macroName)
}

/**
* Header file `hf` looks like it contains an x-macro.
* That is, a macro that is used to interpret the
* data in `hf`, usually defined just before including that file
* and undefined immediately afterwards.
*/
predicate hasXMacro(HeaderFile hf) {
// Every header that includes `hf` both defines and undefines a macro that's
// used in `hf`.
exists(string macroName |
usesMacro(hf, macroName) and
forex(File f | f.getAnIncludedFile() = hf |
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,8 @@ enum Items {
#define XMACRO2(id,desc) void use_##();
#include "items2.h"
#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.
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@ enum Items {
#define XMACRO2(id,desc) void use_##();
#include "items2.h"
#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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
XMACRO3(shield, "Wooden Shield")
XMACRO3(boots, "Leather Boots")
XMACRO3(helmet, "Helmet")

#undef XMACRO3