[cfe-dev] Adding support for Cloning in the AST

Sebastian Redl sebastian.redl at getdesigned.at
Sat May 23 06:46:46 PDT 2009


Douglas Gregor wrote:
>
> On May 19, 2009, at 7:18 PM, moataz ragab wrote:
>
>> Whether it might be useful or not to clone a declaration, it might be
>> useful if you want to create a new variable declaration similar to
>> another declaration and only change the name.
>
>
> Hmmm, interesting. It seems to me like we really want to give the
> expression's Clone method some information that tells it what to do
> with declarations. For your loop-unrolling rewriter, we want to
> replace some variable declarations with other, similar variables
> (e.g., when the original variable was declared in the loop) or reuse
> the same variable declaration (if the variable is declared outside the
> loop). For my purposes, where I need to build a canonical expression,
> we replace types with their canonical types and replace some
> declarations (e.g., for non-type template parameters) with their
> "canonical" declarations. This tells me that we need to think about
> some kind of policy argument for Clone() that permits these changes.
A callback to handle all sub-objects, instead of just cloning
recursively? It would be very tricky to do as a "policy" that is
anything less than a fully generic callback, given that cloning is deep.
The callback has to handle everything in that part of the AST somehow.
You can't stop at a single level.

Sebastian



More information about the cfe-dev mailing list