[cfe-dev] How to use ASTWriter/ASTreader or ASTUnit to do serialization on AST?

Manuel Klimek klimek at google.com
Mon Mar 24 03:22:29 PDT 2014


On Mon, Mar 24, 2014 at 10:12 AM, Barry Pan <barry1451 at gmail.com> wrote:

> Hello guys.
> Here’s my problem:
> I tried to manipulate on multiple ASTs to make a  call graph on multiple
> src files
>

If you want to create a call graph, why do you need to mutate the AST at
all?
For call graph analysis, I'd look into clang's libTooling (
http://clang.llvm.org/docs/LibTooling.html)

Cheers,
/Manuel


> ,so far I only got this idea :using the serialization/deserialization
> way.First saving the ASTs,then recovering them from the saved files and do
> sth on the AST's data structure(e.g. Decls).
> I have readed clang’code and some tips from the mailing list,and  now I
> get a way from the ASTUnit::Save to use ASTWriter to write an AST to a
> file,but still can’t figure out how to use ASTReader.
> My question is:
> 1.How can i create an ASTUnit object to use the existing code to
> manipulate ASTWrite,Or I have to copy these codes to do so…
> 2.Then,after I write the AST to a file,how can I use the ASTReader or some
> other things to recover the AST to get it’s data.Its constructor requires
> an ASTContext and some other things,So should I create a new Context to
> pass over?
>
> I found it difficult to do such things. So can anybody tell me how to do
> so?If there exits a tutorial or example,I will be so-o-o-o-o-o-o grateful !
> Or can you guys give me some other ideas to manipulate on multiple ASTs?
>
> Thank you for your reading!
> (This is my first time to ask questions on this mailing list,so please
> forgive me if I ask questions in a stupid way and forgive my poor
> English...)
>
>
>
> --
> View this message in context:
> http://clang-developers.42468.n3.nabble.com/How-to-use-ASTWriter-ASTreader-or-ASTUnit-to-do-serialization-on-AST-tp4038574.html
> Sent from the Clang Developers mailing list archive at Nabble.com.
>
> _______________________________________________
> 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/20140324/7cea8d1a/attachment.html>


More information about the cfe-dev mailing list