Quick Questions: DeclRefExpr, TypedefDecl, TypedefType, and TemplateTypeParmDecl.

1 - The documentation for DeclRefExpr says the following:
A reference to a declared variable, function, enum, etc.”
Does this mean that DeclRefExprs also refer to types such as a concept’s associated type
(declared with the typename keyword, as a TemplateTypeParmDecl) ?

2 - How are TypedefTypes related to TypedefDecls, and possibly TemplateTypeParmDecl as well?

3- I ran into this confusion when I was trying to modify the transformations on calls to concept’s associated
functions and types. I can’t decide which one of these methods would be the most appropriate or general
place for the change: TransformDeclRefExpr, or TransformDecl and TransformType (and/or even
TransformNestedNameSpecifier).
Basically, I’m trying to say: if the referred type or function (or variable) we are trying to transform is
declared within a concept defn context, then match it to the appropriate concept map, and change
the type or expression so that it now refers to the corresponding type or function (or variable) as defined
within the map context…
This is part of my implementation for concept lookup. I can see it working for associated functions, when
my changes are at the beginning of TransformDeclRef, but I’m not sure if that would work well for types as well.

Thanks,

– Larisse.

1 - The documentation for DeclRefExpr says the following:
A reference to a declared variable, function, enum, etc.”
Does this mean that DeclRefExprs also refer to types such as a concept’s associated type
(declared with the typename keyword, as a TemplateTypeParmDecl) ?

No. Look at the declaration hierarchy: DeclRefExpr stores a value (ValueDecl), but types are TypeDecls. Plus, a type reference is never an expression in the C family of languages.

2 - How are TypedefTypes related to TypedefDecls, and possibly TemplateTypeParmDecl as well?

TypedefType it’s a reference to a TypedefDecl that occurs in the source. You can create a small file that has a typedef and refers to it, then look at the generated AST, to see how it works.

TemplateTypeParmDecl is a bit messier, since the corresponding TemplateTypeParmType refers to depth/index rather than a specific declaration. We’d like it to refer to the declaration at some point in the future, but we’re not there yet.

3- I ran into this confusion when I was trying to modify the transformations on calls to concept’s associated
functions and types. I can’t decide which one of these methods would be the most appropriate or general
place for the change: TransformDeclRefExpr, or TransformDecl and TransformType (and/or even
TransformNestedNameSpecifier).
Basically, I’m trying to say: if the referred type or function (or variable) we are trying to transform is
declared within a concept defn context, then match it to the appropriate concept map, and change
the type or expression so that it now refers to the corresponding type or function (or variable) as defined
within the map context…

The cleanest approach is probably just to create a new Type for references to associated types; then you can transform that associated type reference specifically.

  • Doug

Cool! Thanks! – Larisse.