diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2017-01-30 06:05:58 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2017-01-30 06:05:58 +0000 |
commit | 5625df6660329b7b3e1eb8cd4ce96622b02efdf1 (patch) | |
tree | 69e5e9cb5833a2e1e6297587f74f8f95ed747ab3 /tools/c-index-test | |
parent | 90cf9c5b40b2cae287de472daa6f4a9d7415d592 (diff) |
[c-index-test] Provide capability to index module file imports and dump their input files.
This ensures the capability to index a module file using an existing ASTReader from a compiler instance or ASTUnit.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@293461 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/c-index-test')
-rw-r--r-- | tools/c-index-test/core_main.cpp | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/tools/c-index-test/core_main.cpp b/tools/c-index-test/core_main.cpp index 33653e0b6d..f371870117 100644 --- a/tools/c-index-test/core_main.cpp +++ b/tools/c-index-test/core_main.cpp @@ -16,6 +16,7 @@ #include "clang/Index/IndexDataConsumer.h" #include "clang/Index/USRGeneration.h" #include "clang/Index/CodegenNameGenerator.h" +#include "clang/Serialization/ASTReader.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Signals.h" #include "llvm/Support/raw_ostream.h" @@ -50,6 +51,10 @@ static cl::extrahelp MoreHelp( "invocation\n" ); +static cl::opt<bool> +DumpModuleImports("dump-imported-module-files", + cl::desc("Print symbols and input files from imported modules")); + static cl::opt<std::string> ModuleFilePath("module-file", cl::desc("Path to module file to print symbols from")); @@ -142,7 +147,19 @@ public: // Print Source Symbols //===----------------------------------------------------------------------===// -static bool printSourceSymbols(ArrayRef<const char *> Args) { +static void dumpModuleFileInputs(serialization::ModuleFile &Mod, + ASTReader &Reader, + raw_ostream &OS) { + OS << "---- Module Inputs ----\n"; + Reader.visitInputFiles(Mod, /*IncludeSystem=*/true, /*Complain=*/false, + [&](const serialization::InputFile &IF, bool isSystem) { + OS << (isSystem ? "system" : "user") << " | "; + OS << IF.getFile()->getName() << '\n'; + }); +} + +static bool printSourceSymbols(ArrayRef<const char *> Args, + bool dumpModuleImports) { SmallVector<const char *, 4> ArgsWithProgName; ArgsWithProgName.push_back("clang"); ArgsWithProgName.append(Args.begin(), Args.end()); @@ -152,7 +169,8 @@ static bool printSourceSymbols(ArrayRef<const char *> Args) { if (!CInvok) return true; - auto DataConsumer = std::make_shared<PrintIndexDataConsumer>(outs()); + raw_ostream &OS = outs(); + auto DataConsumer = std::make_shared<PrintIndexDataConsumer>(OS); IndexingOptions IndexOpts; std::unique_ptr<FrontendAction> IndexAction; IndexAction = createIndexingAction(DataConsumer, IndexOpts, @@ -165,6 +183,17 @@ static bool printSourceSymbols(ArrayRef<const char *> Args) { if (!Unit) return true; + if (dumpModuleImports) { + if (auto Reader = Unit->getASTReader()) { + Reader->getModuleManager().visit([&](serialization::ModuleFile &Mod) -> bool { + OS << "==== Module " << Mod.ModuleName << " ====\n"; + indexModuleFile(Mod, *Reader, DataConsumer, IndexOpts); + dumpModuleFileInputs(Mod, *Reader, OS); + return true; // skip module dependencies. + }); + } + } + return false; } @@ -268,7 +297,7 @@ int indextest_core_main(int argc, const char **argv) { errs() << "error: missing compiler args; pass '-- <compiler arguments>'\n"; return 1; } - return printSourceSymbols(CompArgs); + return printSourceSymbols(CompArgs, options::DumpModuleImports); } return 0; |