diff options
author | Eric Liu <ioeric@google.com> | 2018-07-09 08:44:05 +0000 |
---|---|---|
committer | Eric Liu <ioeric@google.com> | 2018-07-09 08:44:05 +0000 |
commit | 8576df59f2fe52ae305fdb91b36cbed8946981a1 (patch) | |
tree | 6bff3cf16984dc383c77c4e54d79bb862a48f9a3 /tools/c-index-test | |
parent | 72faa33b45d4a43de5587623948b1635059a5ab5 (diff) | |
download | clang-8576df59f2fe52ae305fdb91b36cbed8946981a1.tar.gz |
[Index] Add indexing support for MACROs.
Reviewers: akyrtzi, arphaman, sammccall
Reviewed By: sammccall
Subscribers: malaperle, sammccall, cfe-commits
Differential Revision: https://reviews.llvm.org/D48961
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@336524 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/c-index-test')
-rw-r--r-- | tools/c-index-test/core_main.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/tools/c-index-test/core_main.cpp b/tools/c-index-test/core_main.cpp index 6093df5285..a7732c09d5 100644 --- a/tools/c-index-test/core_main.cpp +++ b/tools/c-index-test/core_main.cpp @@ -7,6 +7,7 @@ // //===----------------------------------------------------------------------===// +#include "clang/Basic/LangOptions.h" #include "clang/CodeGen/ObjectFilePCHContainerOperations.h" #include "clang/Frontend/ASTUnit.h" #include "clang/Frontend/CompilerInstance.h" @@ -16,6 +17,7 @@ #include "clang/Index/IndexDataConsumer.h" #include "clang/Index/USRGeneration.h" #include "clang/Index/CodegenNameGenerator.h" +#include "clang/Lex/Preprocessor.h" #include "clang/Serialization/ASTReader.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Signals.h" @@ -77,6 +79,7 @@ namespace { class PrintIndexDataConsumer : public IndexDataConsumer { raw_ostream &OS; std::unique_ptr<CodegenNameGenerator> CGNameGen; + std::shared_ptr<Preprocessor> PP; public: PrintIndexDataConsumer(raw_ostream &OS) : OS(OS) { @@ -86,6 +89,10 @@ public: CGNameGen.reset(new CodegenNameGenerator(Ctx)); } + void setPreprocessor(std::shared_ptr<Preprocessor> PP) override { + this->PP = std::move(PP); + } + bool handleDeclOccurence(const Decl *D, SymbolRoleSet Roles, ArrayRef<SymbolRelation> Relations, SourceLocation Loc, ASTNodeInfo ASTNode) override { @@ -145,6 +152,37 @@ public: return true; } + + bool handleMacroOccurence(const IdentifierInfo *Name, const MacroInfo *MI, + SymbolRoleSet Roles, SourceLocation Loc) override { + assert(PP); + SourceManager &SM = PP->getSourceManager(); + + Loc = SM.getFileLoc(Loc); + FileID FID = SM.getFileID(Loc); + unsigned Line = SM.getLineNumber(FID, SM.getFileOffset(Loc)); + unsigned Col = SM.getColumnNumber(FID, SM.getFileOffset(Loc)); + OS << Line << ':' << Col << " | "; + + printSymbolInfo(getSymbolInfoForMacro(*MI), OS); + OS << " | "; + + OS << Name->getName(); + OS << " | "; + + SmallString<256> USRBuf; + if (generateUSRForMacro(Name->getName(), MI->getDefinitionLoc(), SM, + USRBuf)) { + OS << "<no-usr>"; + } else { + OS << USRBuf; + } + OS << " | "; + + printSymbolRoles(Roles, OS); + OS << " |\n"; + return true; + } }; } // anonymous namespace |