diff options
Diffstat (limited to 'gnu/llvm/clang/tools/c-index-test/core_main.cpp')
-rw-r--r-- | gnu/llvm/clang/tools/c-index-test/core_main.cpp | 39 |
1 files changed, 33 insertions, 6 deletions
diff --git a/gnu/llvm/clang/tools/c-index-test/core_main.cpp b/gnu/llvm/clang/tools/c-index-test/core_main.cpp index b03783b7e04..7037252ffa0 100644 --- a/gnu/llvm/clang/tools/c-index-test/core_main.cpp +++ b/gnu/llvm/clang/tools/c-index-test/core_main.cpp @@ -13,22 +13,25 @@ #include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/CompilerInvocation.h" #include "clang/Frontend/FrontendAction.h" -#include "clang/Index/IndexingAction.h" #include "clang/Index/IndexDataConsumer.h" +#include "clang/Index/IndexingAction.h" #include "clang/Index/USRGeneration.h" #include "clang/Lex/Preprocessor.h" #include "clang/Serialization/ASTReader.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/FileSystem.h" +#include "llvm/Support/PrettyStackTrace.h" +#include "llvm/Support/Program.h" #include "llvm/Support/Signals.h" +#include "llvm/Support/StringSaver.h" #include "llvm/Support/raw_ostream.h" -#include "llvm/Support/PrettyStackTrace.h" using namespace clang; using namespace clang::index; using namespace llvm; extern "C" int indextest_core_main(int argc, const char **argv); +extern "C" int indextest_perform_shell_execution(const char *command_line); namespace { @@ -60,6 +63,9 @@ DumpModuleImports("dump-imported-module-files", static cl::opt<bool> IncludeLocals("include-locals", cl::desc("Print local symbols")); +static cl::opt<bool> IgnoreMacros("ignore-macros", + cl::desc("Skip indexing macros")); + static cl::opt<std::string> ModuleFilePath("module-file", cl::desc("Path to module file to print symbols from")); @@ -207,7 +213,8 @@ static void dumpModuleFileInputs(serialization::ModuleFile &Mod, static bool printSourceSymbols(const char *Executable, ArrayRef<const char *> Args, - bool dumpModuleImports, bool indexLocals) { + bool dumpModuleImports, bool indexLocals, + bool ignoreMacros) { SmallVector<const char *, 4> ArgsWithProgName; ArgsWithProgName.push_back(Executable); ArgsWithProgName.append(Args.begin(), Args.end()); @@ -221,6 +228,8 @@ static bool printSourceSymbols(const char *Executable, auto DataConsumer = std::make_shared<PrintIndexDataConsumer>(OS); IndexingOptions IndexOpts; IndexOpts.IndexFunctionLocals = indexLocals; + IndexOpts.IndexMacros = !ignoreMacros; + IndexOpts.IndexMacrosInPreprocessor = !ignoreMacros; std::unique_ptr<FrontendAction> IndexAction = createIndexingAction(DataConsumer, IndexOpts); @@ -262,8 +271,8 @@ static bool printSourceSymbolsFromModule(StringRef modulePath, std::unique_ptr<ASTUnit> AU = ASTUnit::LoadFromASTFile( std::string(modulePath), *pchRdr, ASTUnit::LoadASTOnly, Diags, FileSystemOpts, /*UseDebugInfo=*/false, - /*OnlyLocalDecls=*/true, None, CaptureDiagsKind::None, - /*AllowPCHWithCompilerErrors=*/true, + /*OnlyLocalDecls=*/true, CaptureDiagsKind::None, + /*AllowASTWithCompilerErrors=*/true, /*UserFilesAreVolatile=*/false); if (!AU) { errs() << "failed to create TU for: " << modulePath << '\n'; @@ -354,8 +363,26 @@ int indextest_core_main(int argc, const char **argv) { } return printSourceSymbols(Executable.c_str(), CompArgs, options::DumpModuleImports, - options::IncludeLocals); + options::IncludeLocals, options::IgnoreMacros); } return 0; } + +//===----------------------------------------------------------------------===// +// Utility functions +//===----------------------------------------------------------------------===// + +int indextest_perform_shell_execution(const char *command_line) { + BumpPtrAllocator Alloc; + llvm::StringSaver Saver(Alloc); + SmallVector<const char *, 4> Args; + llvm::cl::TokenizeGNUCommandLine(command_line, Saver, Args); + auto Program = llvm::sys::findProgramByName(Args[0]); + if (std::error_code ec = Program.getError()) { + llvm::errs() << "command not found: " << Args[0] << "\n"; + return ec.value(); + } + SmallVector<StringRef, 8> execArgs(Args.begin(), Args.end()); + return llvm::sys::ExecuteAndWait(*Program, execArgs); +} |