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.