[cfe-dev] CallGraph and TranslationUnits

Zhongxing Xu xuzhongxing at gmail.com
Sun Oct 25 18:37:56 PDT 2009


Hi Simone,

I wrote the current implementation of callgraph months ago as an
experimentation. It's not meant to be a stable interface. If you have
more general interface or better implementation, patches are welcome.

- Zhongxing Xu

2009/10/25 Simone Pellegrini <spellegrini at dps.uibk.ac.at>:
> Dear all,
> the clang::CallGraph class allows to build call graphs, by using the
> method addTU(ASTUnit&), starting from clang::ASTUnit object which (as
> far as I understand from the API) are normally generated from PCH files .
> However, someone ( like me for example :) ) would like to build
> CallGraphs starting from instances of clang::idx::TranslationUnit class
> and the current API doesn't allow that. :(
>
> If you look to the implementation of the addTU(ASTUnit&) method there is
> no reason why it couldn't be possible to built a CallGraph starting from
> a TranslationUnit object. What the method does is looking for the
> ASTContext, and TranslationUnit objects have the same getASTContext()
> method.
>
> I think there is a little bit of confusion about the API. Right now it
> seems to be that there are two kinds of TranslationUnits (1 coming from
> PCH files and another used by the Indexer for indexing entities) and
> there is no homogeneous way to handle this 2 objects as they have no
> common ancestors. Why the getASTContext() method both in ASTUnit and
> TranslationUnit is not factorized into an interface? this will make
> CallGraph.addTU() more generic. Or, if possible, having ASTUnit
> implementing the TranslationUnit interface (I don't know whether there
> is any conceptual reason that prevent ASTUnit to be a TranslationUnit).
>
> For the moment I was able to solve the problem by slightly changing the
> CallGraph interface by introducing the add(clang::ids::TranslationUnit&)
> method and by factorizing the implementations with a call to a private
> method addAST(ASTContext&). I think things will be even easier if the
> CallGraph is built starting from ASTContext.
>
> Am I missing something?
>
> regards, Simone P.
>
>
> _______________________________________________
> 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