[cfe-dev] [AST] Can ASTContext share data between translation units?

Yafei Liu via cfe-dev cfe-dev at lists.llvm.org
Mon Aug 17 20:32:31 PDT 2020

It seems that AST data in different translation units seems not sharing,
for example:

struct A {}

struct B : public A {}

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
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)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20200818/ad357927/attachment.html>

More information about the cfe-dev mailing list