[cfe-dev] using ASTWriter::WriteAST() in ASTConsumer

Argyrios Kyrtzidis kyrtzidis at apple.com
Mon Sep 12 15:18:09 PDT 2011


On Sep 12, 2011, at 12:40 PM, Mark Brown wrote:

> I wrote a plugin which in inherits both the ASTConsumer and RecursiveASTVisitor classes. Before the plugin is over I would like it to write out my modified AST. 
> 
> Currently this code does nothing. No errors, not output. As there are no return values or error checking function I'm not even sure how I'm supposed to debug it. Does anyone happen to see whats wrong?
> 
> Thank you
> 
> virtual void HandleTranslationUnit(ASTContext &ctx) {
>                 TraverseDecl(ctx.getTranslationUnitDecl());
>                 
>                 std::vector<unsigned char> buf;
>                 BitstreamWriter stream_writer(buf);
>                 ASTWriter ast_writer(stream_writer);
>                 ast_writer.WriteAST(ci->getSema(), NULL, string("test.ast"), StringRef("wtf"));
> }

It wrote the AST data into the vector buf, you want to write the vector into a file I assume ?
Check out the ASTUnit::Save function.

> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev




More information about the cfe-dev mailing list