diff options
Diffstat (limited to 'tools/c-index-test/core_main.cpp')
-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 |