[cfe-dev] Get template parameter for Type

Frank Redeker via cfe-dev cfe-dev at lists.llvm.org
Fri Apr 13 12:57:11 PDT 2018

Hello List,

Given the following AST

ClassTemplateDecl 0x3fc1dd0 <.idbbuild/debug.c:13:1, line:20:1> line:13:43 T
|-TemplateTypeParmDecl 0x3f220c8 <col:11, col:20> col:20 referenced
typename depth 0 index 0 P1
|-TemplateTypeParmDecl 0x3f22168 <col:24, col:33> col:33 referenced
typename depth 0 index 1 P2
|-CXXRecordDecl 0x3fc1d30 <col:37, line:20:1> line:13:43 class T definition
| |-CXXMethodDecl 0x3fc2280 <line:15:2, col:15> col:5 Method 'P1 (P2)'
| | `-ParmVarDecl 0x3fc2148 <col:13> col:15 'P2'
| |-CXXRecordDecl 0x3fc2330 <line:16:2, line:19:2> line:16:2 struct
| | |-FieldDecl 0x3fc2468 <line:17:3, col:6> col:6 M1 'P1'
| | `-FieldDecl 0x3fc24c8 <line:18:3, col:6> col:6 M2 'P2'
| `-FieldDecl 0x3fc2590 <line:16:2, line:19:4> col:4 M 'struct
(anonymous struct at .idbbuild/debug.c:16:2)':'T::(anonymous struct at
`-ClassTemplateSpecializationDecl 0x3fc2640 <line:13:1, line:20:1>
line:13:43 class T definition
  |-TemplateArgument type 'int'
  |-TemplateArgument type 'char'
  |-CXXMethodDecl 0x3fc2bb0 <line:15:2, col:15> col:5 Method 'int (char)'
  | `-ParmVarDecl 0x3fc2aa8 <col:13> col:15 'char':'char'
  |-CXXRecordDecl 0x3fc2c70 <line:16:2, line:19:2> line:16:2 struct
  | |-FieldDecl 0x3fc3e28 <line:17:3, col:6> col:6 referenced M1 'int':'int'
  | |-FieldDecl 0x3fc3e88 <line:18:3, col:6> col:6 M2 'char':'char'

Is it possible to get the TemplateArgument (or even better the
TemplateTypeParmDecl) when visiting a FieldDecl or ParmVarDecl inside a

FieldDecl * f; <-- FieldDecl 0x3fc3e28 in AST
Type *      t = f->getType()->split().Ty;

And now for this Type t find the TemplateArgument or TemplateTypeParmDecl


More information about the cfe-dev mailing list