[cfe-dev] When Parsing AST,include file not found
Manuel Klimek
klimek at google.com
Tue Apr 28 02:01:00 PDT 2015
To make this easier we have created a library called libTooling in clang:
http://clang.llvm.org/docs/LibTooling.html
On Tue, Apr 28, 2015 at 2:56 AM %绝对冰儿 <511736596 at qq.com> wrote:
> Hi:
> I'm using clang3.6, first time I use compilerInstance+ParseAST to
> operate AST.When the sourcefile have an fatal error:'stdio.h' file not
> found. Second time I use compilerInvocation+ASTUnit to operate AST.It have
> the same problem.
> the source of compilerInvocation+ASTUnit( parse the ast of c)
> int main(int argc, char** argv)
> {
> shared_ptr<ASTUnit> AST;
> clang::DiagnosticOptions diagOpts;
> llvm::IntrusiveRefCntPtr<clang::DiagnosticsEngine> diags =
> clang::CompilerInstance::createDiagnostics(&diagOpts, 0, 0);
> clang::LangOptions lopt;
> vector<const char*> argvec;
> argvec.push_back("clang");
> argvec.push_back("-fsyntax-only");
> argvec.push_back(argv[1]); //it's the filename
> ArrayRef<const char *> args(argvec);
> CompilerInvocation *ci = new clang::CompilerInvocation();
>
> CompilerInvocation::CreateFromArgs(*ci,&argvec[0],&argvec[0]+1,*diags);
> ci->setLangDefaults(lopt,InputKind::IK_C);
> llvm::outs()<<"createinvocationfromcommandline"<<"\n";
> ci->getPreprocessorOutputOpts().ShowComments = 1;
> ci->getPreprocessorOutputOpts().ShowLineMarkers = 1;
> llvm::outs()<<"preprocessor init "<<"\n";
> AST = clang::ASTUnit::LoadFromCompilerInvocation(ci, diags);
> llvm::outs()<<"createAST"<<"\n";
> MyASTVisitor myvis;
> myvis.TraverseDecl(AST->getASTContext().getTranslationUnitDecl());
> }
> what i miss? I don't know how to correctly create object of
> CompilerInvocation,I think it's because i don't correctly new the
> compilerinvocation.
> Thank you so much!
>
> by YingLi
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150428/0901f4e9/attachment.html>
More information about the cfe-dev
mailing list