[cfe-dev] Transferring typers between ASTContexts
Douglas Gregor
dgregor at apple.com
Wed May 26 09:03:45 PDT 2010
On May 26, 2010, at 5:32 AM, Olaf Krzikalla wrote:
> Hi @clang,
>
> is there an easy way to reuse types (given by Type*) from a particular
> ASTContext in a different ASTContext?
Not directly. The uniquing that forms the underpinning of the canonical-types system means that a type from one ASTContext can't be used in another ASTContext.
> What I have here are multiple configuration files written in C++. I
> don't want to preserve the complete ASTContext for each file during the
> entire runtime of the program. I just need a way to represent types in a
> manner so that I can rebuild the actual Type pointer later in a
> different ASTContext (I have only simple types here not dependent on any
> expressions and yes, I know, that this constraint simplifies my problem
> quite a lot). Holding types on my own doesn't work due to the private
> constructors of a lot of types (which I don't like BTW).
> So one way could be to create and use a separate (dummy) ASTContext. Or
> I utilize the PCH stream but I'm completely unsure how to proceed then
> and if this is a feasible solution at all.
Check out the ASTImporter in include/clang/AST/ASTImporter. It's far from complete, but the idea is that it allows you to import specific types/declarations/etc. from one ASTContext into another, merging the imported declarations with those declarations already in the destination context (and trying to detect ODR violations along the way).
- Doug
More information about the cfe-dev
mailing list