diff options
| author | Haojian Wu <hokein@google.com> | 2019-10-07 10:10:31 +0000 |
|---|---|---|
| committer | Haojian Wu <hokein@google.com> | 2019-10-07 10:10:31 +0000 |
| commit | 2fa81d201f4b6238c9cc92fdca5cd77ca7fe2435 (patch) | |
| tree | 1284435ad71c67009c0c7b4948e6a5d348007fcc /clang-tools-extra/clangd/CollectMacros.h | |
| parent | 6942327a8f3ba90b2480f39318901e22269d16e7 (diff) | |
| download | bcm5719-llvm-2fa81d201f4b6238c9cc92fdca5cd77ca7fe2435.tar.gz bcm5719-llvm-2fa81d201f4b6238c9cc92fdca5cd77ca7fe2435.zip | |
[clangd] Collect missing macro references.
Summary: Semantic highlghting is missing a few macro references.
Reviewers: ilya-biryukov
Subscribers: MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D68458
llvm-svn: 373889
Diffstat (limited to 'clang-tools-extra/clangd/CollectMacros.h')
| -rw-r--r-- | clang-tools-extra/clangd/CollectMacros.h | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/clang-tools-extra/clangd/CollectMacros.h b/clang-tools-extra/clangd/CollectMacros.h index 21227e1ed57..619c9f54b58 100644 --- a/clang-tools-extra/clangd/CollectMacros.h +++ b/clang-tools-extra/clangd/CollectMacros.h @@ -25,7 +25,8 @@ struct MainFileMacros { std::vector<Range> Ranges; }; -/// Collects macro definitions and expansions in the main file. It is used to: +/// Collects macro references (e.g. definitions, expansions) in the main file. +/// It is used to: /// - collect macros in the preamble section of the main file (in Preamble.cpp) /// - collect macros after the preamble of the main file (in ParsedAST.cpp) class CollectMainFileMacros : public PPCallbacks { @@ -49,6 +50,27 @@ public: add(MacroName, MD.getMacroInfo()); } + void MacroUndefined(const clang::Token &MacroName, + const clang::MacroDefinition &MD, + const clang::MacroDirective *Undef) override { + add(MacroName, MD.getMacroInfo()); + } + + void Ifdef(SourceLocation Loc, const Token &MacroName, + const MacroDefinition &MD) override { + add(MacroName, MD.getMacroInfo()); + } + + void Ifndef(SourceLocation Loc, const Token &MacroName, + const MacroDefinition &MD) override { + add(MacroName, MD.getMacroInfo()); + } + + void Defined(const Token &MacroName, const MacroDefinition &MD, + SourceRange Range) override { + add(MacroName, MD.getMacroInfo()); + } + private: void add(const Token &MacroNameTok, const MacroInfo *MI) { if (!InMainFile) @@ -57,7 +79,7 @@ private: if (Loc.isMacroID()) return; - if (auto Range = getTokenRange(SM, LangOpts, MacroNameTok.getLocation())) { + if (auto Range = getTokenRange(SM, LangOpts, Loc)) { Out.Names.insert(MacroNameTok.getIdentifierInfo()->getName()); Out.Ranges.push_back(*Range); } |

