[cfe-dev] Fetching typedef details via libclang
Abramo Bagnara
abramo.bagnara at gmail.com
Mon Apr 11 23:18:39 PDT 2011
Il 12/04/2011 02:15, Douglas Gregor ha scritto:
>
> On Mar 28, 2011, at 1:55 PM, Stefan Seefeld wrote:
>
>> I'm looking for a way to query the libclang AST whether a typedef's
>> referree type was constructed in-place, such as in
>>
>> typedef struct { ... } CXString;
>>
>>
>> Such constructs are rather common in C APIs, and I'd like to fold the
>> two types (the anonymous struct with the 'CXString' alias) into one, to
>> reduce the noise in the generated API documentation.
>>
>> Is this possible, using libclang ?
>
> Not currently.
>
>> If not, any ideas how best to
>> implement that ?
>
>
> It's a little tricky, because Clang's AST doesn't really hold on to this information well. In this specific case, where the tag is anonymous, you can query TagDecl::getTypedefForAnonDecl() to see if it's a typedef of an anonymous declaration. But in a similar case like
>
> typedef struct CXString { ... } CXString;
>
> the AST doesn't have the information you seek. Perhaps this information could be added into ElaboratedType or ElaboratedTypeLoc.
You always forget isEmbeddedInDeclarator ;-)
More information about the cfe-dev
mailing list