diff options
author | Daniel Dunbar <daniel@zuster.org> | 2009-12-01 09:51:01 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2009-12-01 09:51:01 +0000 |
commit | 764c082027ed7ca40de332ac588d3e61fcf34e21 (patch) | |
tree | 12133c2688c77a0551bb3666d429d327e8cd08ad /clang/tools/index-test/index-test.cpp | |
parent | 35c55912863fd11f38249c195879fbece5861f65 (diff) | |
download | bcm5719-llvm-764c082027ed7ca40de332ac588d3e61fcf34e21.tar.gz bcm5719-llvm-764c082027ed7ca40de332ac588d3e61fcf34e21.zip |
Add ASTUnit::LoadFromCompilerInvocation, which does what it says.
Also, add an -ast-from-source option to index-test which allows index-test to
run on source files directly.
llvm-svn: 90223
Diffstat (limited to 'clang/tools/index-test/index-test.cpp')
-rw-r--r-- | clang/tools/index-test/index-test.cpp | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/clang/tools/index-test/index-test.cpp b/clang/tools/index-test/index-test.cpp index fce48edf26e..dd7cbb21642 100644 --- a/clang/tools/index-test/index-test.cpp +++ b/clang/tools/index-test/index-test.cpp @@ -43,6 +43,10 @@ #include "clang/Index/Analyzer.h" #include "clang/Index/Utils.h" #include "clang/Frontend/ASTUnit.h" +#include "clang/Frontend/CompilerInstance.h" +#include "clang/Frontend/CompilerInvocation.h" +#include "clang/Frontend/DiagnosticOptions.h" +#include "clang/Frontend/TextDiagnosticPrinter.h" #include "clang/Frontend/CommandLineSourceLoc.h" #include "clang/AST/DeclObjC.h" #include "clang/AST/ExprObjC.h" @@ -202,9 +206,24 @@ static void ProcessASTLocation(ASTLocation ASTLoc, Indexer &Idxer) { } } +static llvm::cl::opt<bool> +ASTFromSource("ast-from-source", + llvm::cl::desc("Treat the inputs as source files to parse.")); + static llvm::cl::list<std::string> InputFilenames(llvm::cl::Positional, llvm::cl::desc("<input AST files>")); +void CreateCompilerInvocation(const std::string &Filename, + CompilerInvocation &CI, Diagnostic &Diags, + const char *argv0) { + llvm::SmallVector<const char *, 16> Args; + Args.push_back(Filename.c_str()); + + void *MainAddr = (void*) (intptr_t) CreateCompilerInvocation; + CompilerInvocation::CreateFromArgs(CI, Args.data(), Args.data() + Args.size(), + argv0, MainAddr, Diags); +} + int main(int argc, char **argv) { llvm::sys::PrintStackTraceOnErrorSignal(); llvm::PrettyStackTraceProgram X(argc, argv); @@ -215,6 +234,10 @@ int main(int argc, char **argv) { Indexer Idxer(Prog); llvm::SmallVector<TUnit*, 4> TUnits; + TextDiagnosticPrinter DiagClient(llvm::errs(), DiagnosticOptions(), false); + llvm::OwningPtr<Diagnostic> Diags( + CompilerInstance::createDiagnostics(DiagnosticOptions(), argc, argv)); + // If no input was specified, read from stdin. if (InputFilenames.empty()) InputFilenames.push_back("-"); @@ -225,7 +248,15 @@ int main(int argc, char **argv) { std::string ErrMsg; llvm::OwningPtr<ASTUnit> AST; - AST.reset(ASTUnit::LoadFromPCHFile(InFile, &ErrMsg)); + if (ASTFromSource) { + CompilerInvocation CI; + CreateCompilerInvocation(InFile, CI, *Diags, argv[0]); + AST.reset(ASTUnit::LoadFromCompilerInvocation(CI, *Diags)); + if (!AST) + ErrMsg = "unable to create AST"; + } else + AST.reset(ASTUnit::LoadFromPCHFile(InFile, &ErrMsg)); + if (!AST) { llvm::errs() << "[" << InFile << "] Error: " << ErrMsg << '\n'; return 1; |