@@ -25,7 +25,8 @@ struct MainFileMacros {
2525 std::vector<Range> Ranges;
2626};
2727
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:
2930// / - collect macros in the preamble section of the main file (in Preamble.cpp)
3031// / - collect macros after the preamble of the main file (in ParsedAST.cpp)
3132class CollectMainFileMacros : public PPCallbacks {
@@ -49,6 +50,27 @@ class CollectMainFileMacros : public PPCallbacks {
4950 add (MacroName, MD.getMacroInfo ());
5051 }
5152
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+
5274private:
5375 void add (const Token &MacroNameTok, const MacroInfo *MI) {
5476 if (!InMainFile)
@@ -57,7 +79,7 @@ class CollectMainFileMacros : public PPCallbacks {
5779 if (Loc.isMacroID ())
5880 return ;
5981
60- if (auto Range = getTokenRange (SM, LangOpts, MacroNameTok. getLocation () )) {
82+ if (auto Range = getTokenRange (SM, LangOpts, Loc )) {
6183 Out.Names .insert (MacroNameTok.getIdentifierInfo ()->getName ());
6284 Out.Ranges .push_back (*Range);
6385 }
0 commit comments