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

Mark Brown mbrowncu98 at gmail.com
Tue Sep 13 08:08:01 PDT 2011


The 2nd argument to its create() method is llvm::IntrusiveRefCntPtr<
Diagnostic <http://clang.llvm.org/doxygen/classclang_1_1Diagnostic.html> >
Diags

Can I safely take this from CompilerInstance::getDiagnostics() and use it
something like(but fixed... somehow):
        llvm::IntrusiveRefCntPtr<clang::Diagnostic>
diag(ci->getDiagnostics());

and pass it to the create() method?

Thank you again

On Mon, Sep 12, 2011 at 6:42 PM, Argyrios Kyrtzidis <kyrtzidis at apple.com>wrote:

> 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/20110913/d0cee884/attachment.html>


More information about the cfe-dev mailing list