summaryrefslogtreecommitdiffstats
path: root/clang/tools/index-test/index-test.cpp
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-12-02 03:23:45 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-12-02 03:23:45 +0000
commit55a17b66cd66c86f2005eb065c78ebbae1f8fe27 (patch)
tree54de41988f90a3b023d5ebadb61a1aad3872c6fa /clang/tools/index-test/index-test.cpp
parent120c77e4e986725cdd76cd58943714294aa1a54b (diff)
downloadbcm5719-llvm-55a17b66cd66c86f2005eb065c78ebbae1f8fe27.tar.gz
bcm5719-llvm-55a17b66cd66c86f2005eb065c78ebbae1f8fe27.zip
Add ASTUnit::LoadFromCommandLine, which creates an ASTUnit out of a list of
(clang/driver) command line arguments (including the source file). - The arguments are expected to include the source file. - The idea is that even though this is a somewhat odd API, its the form which many tools can most easily use (for example, by interposing with the compiler). Also, switch index-test's -ast-from-source to use this entry point, and provide a -arg command line argument which can be used to test that the command line arguments are handled correctly. llvm-svn: 90288
Diffstat (limited to 'clang/tools/index-test/index-test.cpp')
-rw-r--r--clang/tools/index-test/index-test.cpp24
1 files changed, 13 insertions, 11 deletions
diff --git a/clang/tools/index-test/index-test.cpp b/clang/tools/index-test/index-test.cpp
index dd7cbb21642..fc8547b784c 100644
--- a/clang/tools/index-test/index-test.cpp
+++ b/clang/tools/index-test/index-test.cpp
@@ -208,20 +208,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."));
+ llvm::cl::desc("Treat the inputs as source files to parse"));
+
+static llvm::cl::list<std::string>
+CompilerArgs("arg", llvm::cl::desc("Extra arguments to use during parsing"));
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) {
+ASTUnit *CreateFromSource(const std::string &Filename, Diagnostic &Diags,
+ const char *Argv0) {
llvm::SmallVector<const char *, 16> Args;
Args.push_back(Filename.c_str());
+ for (unsigned i = 0, e = CompilerArgs.size(); i != e; ++i)
+ Args.push_back(CompilerArgs[i].c_str());
- void *MainAddr = (void*) (intptr_t) CreateCompilerInvocation;
- CompilerInvocation::CreateFromArgs(CI, Args.data(), Args.data() + Args.size(),
- argv0, MainAddr, Diags);
+ return ASTUnit::LoadFromCommandLine(Args.data(), Args.data() + Args.size(),
+ Diags, Argv0,
+ (void*) (intptr_t) CreateFromSource);
}
int main(int argc, char **argv) {
@@ -249,10 +253,8 @@ int main(int argc, char **argv) {
llvm::OwningPtr<ASTUnit> AST;
if (ASTFromSource) {
- CompilerInvocation CI;
- CreateCompilerInvocation(InFile, CI, *Diags, argv[0]);
- AST.reset(ASTUnit::LoadFromCompilerInvocation(CI, *Diags));
- if (!AST)
+ AST.reset(CreateFromSource(InFile, *Diags, argv[0]));
+ if (!AST || Diags->getNumErrors())
ErrMsg = "unable to create AST";
} else
AST.reset(ASTUnit::LoadFromPCHFile(InFile, &ErrMsg));
OpenPOWER on IntegriCloud