[AST] Can ASTContext share data between translation units?

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[AST] Can ASTContext share data between translation units?

Hubert Tong via cfe-dev
It seems that AST data in different translation units seems not sharing, for example:

A.h:
struct A {}

B.cpp:
struct B : public A {}

C.cpp:
struct C : public A {}

Let's say I have a tool using ast matcher, I passed both B.cpp and C.cpp to my tool, and I found that neither the pointer to clang::CXXRecordDecl of A or the pointer to clang::Type of A are the same. (That's saying, the pointer of A's type when parsing B.cpp is not the same as parsing C.cpp), and so does the ASTContext, two different translation units have totally different ASTContext instances.

So I got a few questions:
1. Any way I can make different translation units share the same ASTContext instance?
2. If not, how can I compare if two declarations have the same type? Currently my solution is to save the full name (with namespace), but this is not very effective (get namespace from a declaration needs recursive searching for parents)

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev