[cfe-dev] Howto get from a TypedefDecl an unterlying EnumDecl

Frank Redeker f.redeker at razorcat.de
Mon Jul 13 09:14:25 PDT 2015


Hi All,

not sure if this is the right place to ask my question.

I'm writing an analyzer tool using the clang ASTConsumer. When I'm
analyzing the following piece I don't know how to get back from the
TypedefDeclto the unterlying EnumDecl

typedef enum {
	Illegal = -1,
	Init = 0,
	Run,
	Stop
} T_ENUM;


In my ast consumer

void IDB_ASTConsumer::handleDecl (Decl * decl) {
.
.
else if (EnumDecl * enumDecl = llvm::dyn_cast<EnumDecl>(decl)) {
   enumDecl->dump();
EnumDecl 0x1da43360
<T:\Projects\3.3\CLANG\source\001-005\001-One-Dimension.c:25:9,
line:30:1> line:25:9
|-EnumConstantDecl 0x1da433f0 <line:26:2, col:9> col:2 Init 'T_ENUM'
| `-IntegerLiteral 0x1da433d0 <col:9> 'int' 0
|-EnumConstantDecl 0x1da43460 <line:27:2, col:13> col:2 Illegal 'T_ENUM'
| `-UnaryOperator 0x1da43448 <col:12, col:13> 'int' prefix '-'
|   `-IntegerLiteral 0x1da43430 <col:13> 'int' 1
|-EnumConstantDecl 0x1da434a0 <line:28:2> col:2 Run 'T_ENUM'
`-EnumConstantDecl 0x1da434e0 <line:29:2> col:2 Stop 'T_ENUM'
}
else if (TypedefDecl * typedefDecl = llvm::dyn_cast<TypedefDecl>(decl)) {
   typedefDecl->getTypeForDecl()->dump();
NULL TYPE

   typedefDecl->dump();
TypedefDecl 0x1da43550
<T:\Projects\3.3\CLANG\source\001-005\001-One-Dimension.c:25:1,
line:30:3> col:3 T_ENUM 'enum T_ENUM':'T_ENUM'
}

Is there a way to access the EnumDecl from the TypdefDecl


Thanks
Frank



More information about the cfe-dev mailing list