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

Argyrios Kyrtzidis kyrtzidis at apple.com
Mon Sep 12 15:42:46 PDT 2011


On Sep 12, 2011, at 3:35 PM, Mark Brown wrote:

> I will try using it,

I mentioned ASTUnit::Save mainly for you to see (along with ASTUnit::serialize) a working example of using ASTWriter to write the AST to a file.

> but it makes me wonder what th point of ASTWriter is. And why it even takes in a filename.

The filename is kept in the AST data as metadata.

> 
> On Mon, Sep 12, 2011 at 6:18 PM, Argyrios Kyrtzidis <kyrtzidis at apple.com> wrote:
> 
> 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
> 
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20110912/dc93f514/attachment.html>


More information about the cfe-dev mailing list