diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2018-07-28 11:06:01 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2018-07-28 11:06:01 +0000 |
| commit | 486754660bb926339aefcf012a3f848592babb8b (patch) | |
| tree | ecdbc446c9876f4f120f701c243373cd3cb43db3 /tools/c-index-test/core_main.cpp | |
| parent | 55e6d896ad333f07bb3b1ba487df214fc268a4ab (diff) | |
Notes
Diffstat (limited to 'tools/c-index-test/core_main.cpp')
| -rw-r--r-- | tools/c-index-test/core_main.cpp | 59 |
1 files changed, 50 insertions, 9 deletions
diff --git a/tools/c-index-test/core_main.cpp b/tools/c-index-test/core_main.cpp index c255f54ba68c..a7732c09d5b0 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,15 +89,20 @@ 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, - FileID FID, unsigned Offset, - ASTNodeInfo ASTNode) override { + SourceLocation Loc, ASTNodeInfo ASTNode) override { ASTContext &Ctx = D->getASTContext(); SourceManager &SM = Ctx.getSourceManager(); - unsigned Line = SM.getLineNumber(FID, Offset); - unsigned Col = SM.getColumnNumber(FID, Offset); + 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(getSymbolInfo(D), OS); @@ -124,12 +132,14 @@ public: } bool handleModuleOccurence(const ImportDecl *ImportD, SymbolRoleSet Roles, - FileID FID, unsigned Offset) override { + SourceLocation Loc) override { ASTContext &Ctx = ImportD->getASTContext(); SourceManager &SM = Ctx.getSourceManager(); - unsigned Line = SM.getLineNumber(FID, Offset); - unsigned Col = SM.getColumnNumber(FID, Offset); + 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(getSymbolInfo(ImportD), OS); @@ -142,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 @@ -192,7 +233,7 @@ static bool printSourceSymbols(ArrayRef<const char *> Args, if (auto Reader = Unit->getASTReader()) { Reader->getModuleManager().visit([&](serialization::ModuleFile &Mod) -> bool { OS << "==== Module " << Mod.ModuleName << " ====\n"; - indexModuleFile(Mod, *Reader, DataConsumer, IndexOpts); + indexModuleFile(Mod, *Reader, *DataConsumer, IndexOpts); dumpModuleFileInputs(Mod, *Reader, OS); return true; // skip module dependencies. }); @@ -228,7 +269,7 @@ static bool printSourceSymbolsFromModule(StringRef modulePath, return true; } - auto DataConsumer = std::make_shared<PrintIndexDataConsumer>(outs()); + PrintIndexDataConsumer DataConsumer(outs()); IndexingOptions IndexOpts; indexASTUnit(*AU, DataConsumer, IndexOpts); |
