@@ -25,7 +25,8 @@ struct MainFileMacros {
25
25
std::vector<Range> Ranges;
26
26
};
27
27
28
- // / Collects macro definitions and expansions in the main file. It is used to:
28
+ // / Collects macro references (e.g. definitions, expansions) in the main file.
29
+ // / It is used to:
29
30
// / - collect macros in the preamble section of the main file (in Preamble.cpp)
30
31
// / - collect macros after the preamble of the main file (in ParsedAST.cpp)
31
32
class CollectMainFileMacros : public PPCallbacks {
@@ -49,6 +50,27 @@ class CollectMainFileMacros : public PPCallbacks {
49
50
add (MacroName, MD.getMacroInfo ());
50
51
}
51
52
53
+ void MacroUndefined (const clang::Token &MacroName,
54
+ const clang::MacroDefinition &MD,
55
+ const clang::MacroDirective *Undef) override {
56
+ add (MacroName, MD.getMacroInfo ());
57
+ }
58
+
59
+ void Ifdef (SourceLocation Loc, const Token &MacroName,
60
+ const MacroDefinition &MD) override {
61
+ add (MacroName, MD.getMacroInfo ());
62
+ }
63
+
64
+ void Ifndef (SourceLocation Loc, const Token &MacroName,
65
+ const MacroDefinition &MD) override {
66
+ add (MacroName, MD.getMacroInfo ());
67
+ }
68
+
69
+ void Defined (const Token &MacroName, const MacroDefinition &MD,
70
+ SourceRange Range) override {
71
+ add (MacroName, MD.getMacroInfo ());
72
+ }
73
+
52
74
private:
53
75
void add (const Token &MacroNameTok, const MacroInfo *MI) {
54
76
if (!InMainFile)
@@ -57,7 +79,7 @@ class CollectMainFileMacros : public PPCallbacks {
57
79
if (Loc.isMacroID ())
58
80
return ;
59
81
60
- if (auto Range = getTokenRange (SM, LangOpts, MacroNameTok. getLocation () )) {
82
+ if (auto Range = getTokenRange (SM, LangOpts, Loc )) {
61
83
Out.Names .insert (MacroNameTok.getIdentifierInfo ()->getName ());
62
84
Out.Ranges .push_back (*Range);
63
85
}
0 commit comments