[cfe-dev] Type of enum constants
Phil King
phil_king at rocketmail.com
Fri Feb 24 15:17:45 PST 2012
On 24 Feb 2012, at 22:50, Eli Friedman <eli.friedman at gmail.com> wrote:
> On Fri, Feb 24, 2012 at 2:35 PM, Phil King <phil_king at rocketmail.com> wrote:
>> On 24 Feb 2012, at 21:46, Eli Friedman <eli.friedman at gmail.com> wrote:
>>
>>> On Fri, Feb 24, 2012 at 1:23 PM, Phil King <phil_king at rocketmail.com> wrote:
>>>> If I have:
>>>>
>>>> typedef enum { E } e_t;
>>>>
>>>> and then an expression:
>>>>
>>>> a = E;
>>>>
>>>> is it possible to get back to the typedef name from the DeclRefExpr node for 'E' ?
>>>>
>>>> EnumConstantDecl * EC = dyn_cast< EnumConstantDecl >( DeclRefExpr->getDecl() );
>>>>
>>>> QualType = AC->getASTContext().getEnumType( dyn_cast< EnumDecl >( EC->getDeclContext() ) );
>>>>
>>>> gets me to enum { E } e_t, but not the typedef itself.
>>>
>>> Try TagDecl::getTypedefNameForAnonDecl .
>>
>> That does the job. Thanks.
>>
>> How do I do the same if there is a tag name?
>
> Are you talking about "typedef enum A { B } A;"? If you really need
> to find the typedef in that case, I think you're stuck with traversing
> the AST to try and find it.
Yes, that's what I was after. However, for this case I can get away with knowing if I'm in a declarator, so isEmbeddedInDeclarator() will do.
Phil
More information about the cfe-dev
mailing list