<div dir="ltr">To make this easier we have created a library called libTooling in clang:<br><a href="http://clang.llvm.org/docs/LibTooling.html">http://clang.llvm.org/docs/LibTooling.html</a><br><div><br></div></div><br><div class="gmail_quote">On Tue, Apr 28, 2015 at 2:56 AM %绝对冰儿 <<a href="mailto:511736596@qq.com">511736596@qq.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi:<br>   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.<br>the source of compilerInvocation+ASTUnit( parse the ast of c)<br>  int main(int argc, char** argv)<br>{<br>    shared_ptr<ASTUnit> AST;<br>        clang::DiagnosticOptions diagOpts;<br>        llvm::IntrusiveRefCntPtr<clang::DiagnosticsEngine> diags = clang::CompilerInstance::createDiagnostics(&diagOpts, 0, 0);<br>        clang::LangOptions lopt;<br>        vector<const char*> argvec;<br>        argvec.push_back("clang");<br>        argvec.push_back("-fsyntax-only");<br>        argvec.push_back(argv[1]);    //it's the filename<br>        ArrayRef<const char *> args(argvec);<br>        CompilerInvocation *ci = new clang::CompilerInvocation();<br>        CompilerInvocation::CreateFromArgs(*ci,&argvec[0],&argvec[0]+1,*diags);<br>        ci->setLangDefaults(lopt,InputKind::IK_C);<br>        llvm::outs()<<"createinvocationfromcommandline"<<"\n";<br>        ci->getPreprocessorOutputOpts().ShowComments = 1;<br>        ci->getPreprocessorOutputOpts().ShowLineMarkers = 1;<br>        llvm::outs()<<"preprocessor init "<<"\n";<br>        AST = clang::ASTUnit::LoadFromCompilerInvocation(ci, diags);<br>        llvm::outs()<<"createAST"<<"\n";<br>        MyASTVisitor myvis;<br>        myvis.TraverseDecl(AST->getASTContext().getTranslationUnitDecl());<br>}<br>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.<br>Thank you so much!<br><br>by YingLi<br>_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu" target="_blank">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
</blockquote></div>