[cfe-dev] libclang: Getting interface from CXCursor_ObjCCategoryDecl

Jacob Carlborg doob at me.com
Mon Nov 17 06:09:03 PST 2014

On 2014-11-17 13:01, Allan Odgaard wrote:
> I am parsing Objective-C code and have a construct like:
>      @interface SomeClass (MyCategory)
>>      @end
> When visiting the AST I see a `CXCursor_ObjCCategoryDecl` cursor.
> I would like to get the interface name of the cursor (i.e. `SomeClass`).
> Using `clang_getCursorSpelling` I get back `MyCategory`.
> Using `clang_getCursorType` I get a type of `CXType_Invalid`.
> How can I get the interface that the category is associated with?

I'm not sure if there's a better way, but this is what I did:

Visit the CXCursor_ObjCCategoryDecl cursor's children and pick the first 
cursor that has the CXCursor_ObjCClassRef kind.



/Jacob Carlborg

More information about the cfe-dev mailing list