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

Manuel Klimek klimek at google.com
Mon Jul 13 10:11:49 PDT 2015


Does getUnderlyingType work for you?
http://clang.llvm.org/doxygen/classclang_1_1TypedefNameDecl.html

On Mon, Jul 13, 2015 at 6:33 PM Frank Redeker <f.redeker at razorcat.de> wrote:

> 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
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150713/caa1f6ca/attachment.html>


More information about the cfe-dev mailing list