Get attributes of type declaration node having RecoveryExpr node of AST

9 Views Asked by At

Assume the following Clang AST:

TranslationUnitDecl 0x55d4d6150bc8 <<invalid sloc>> <invalid sloc>
|-TypedefDecl 0x55d4d61f4990 <kernel.cpp:4:27, col:41> col:41 referenced Mat2d 'int *'
| |-PointerType 0x55d4d61f4950 'int *'
| | `-BuiltinType 0x55d4d6150cd0 'int'
| `-AnnotateAttr 0x55d4d61f49e8 <col:3, col:23> "(100,100)"
`-FunctionDecl 0x55d4d61f4be8 <line:6:1, line:9:1> line:6:6 f0 'void (int *, int *)'
  |-ParmVarDecl 0x55d4d61f4a98 <col:9, col:14> col:14 a 'int *'
  |-ParmVarDecl 0x55d4d61f4b18 <col:17, col:22> col:22 b 'int *'
  `-CompoundStmt 0x55d4d61f5380 <col:25, line:9:1>
    |-DeclStmt 0x55d4d61f4e90 <line:7:3, col:17>
    | `-VarDecl 0x55d4d61f4e28 <col:3, col:16> col:9 used mat 'Mat2d[100]'
    `-BinaryOperator 0x55d4d61f5360 <line:8:3, col:15> '<dependent type>' contains-errors '='
      |-RecoveryExpr 0x55d4d61f5308 <col:3, col:11> '<dependent type>' contains-errors lvalue
      | |-DeclRefExpr 0x55d4d61f4ea8 <col:3> 'Mat2d[100]' lvalue Var 0x55d4d61f4e28 'mat' 'Mat2d[100]'
      | |-IntegerLiteral 0x55d4d61f4ec8 <col:7> 'int' 0
      | `-IntegerLiteral 0x55d4d61f4ee8 <col:10> 'int' 0
      `-IntegerLiteral 0x55d4d61f5340 <col:15> 'int' 0

I need to fetch annotate attribute from TypedefDecl having RecoveryExpr: actually Decl node with type declaration 'Mat2d' having ValueDecl 'mat'. Is it possible to get this info via nested ValueDecl that is inside RecoveryExpr without using matcher?

The matcher could work, however it is not scope aware and possible few results could be found and then somehow they should be filtered to choose correct one.

0

There are 0 best solutions below