[cfe-dev] Fetching typedef details via libclang
Douglas Gregor
dgregor at apple.com
Tue Apr 12 07:11:41 PDT 2011
On Apr 11, 2011, at 11:18 PM, Abramo Bagnara wrote:
> 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 ;-)
You're right, I did completely forget about this!
So, this information is *obviously* available in the AST ;), but hasn't been exposed in libclang.
- Doug
More information about the cfe-dev
mailing list