[cfe-dev] Getting the class name for a category in libclang

Ted Kremenek kremenek at apple.com
Fri Oct 29 13:19:18 PDT 2010


On Oct 29, 2010, at 12:46 PM, David Chisnall wrote:

>> When visiting the children of that cursor, I believe you should see a class reference to the @interface for 'Foo'.  You should be able to query the class name that way.  Does this work?  It's a little indirect, and possibly worthy of a wrapper API.
> 
> 
> This sometimes works.  If there is an @implementation decl for the class visible, then there is an ObjCClassRef child.  If there is not, however, then the only children are the methods.  In the underlying APIs, it would simply be a call to ->getClassInterface() to get the interface.

I'm not seeing this.  This is what I see using c-index-test:

$ cat t.m
@interface Foo @end
@protocol Bar @end
@interface Foo (Bar) @end

$ c-index-test -test-load-source all t.m | grep -v invalid
// CHECK: t.m:1:12: ObjCInterfaceDecl=Foo:1:12 Extent=[1:1 - 1:20]
// CHECK: t.m:2:1: ObjCProtocolDecl=Bar:2:1 (Definition) Extent=[2:1 - 2:19]
// CHECK: t.m:3:12: ObjCCategoryDecl=Bar:3:12 Extent=[3:1 - 3:26]
// CHECK: t.m:3:12: ObjCClassRef=Foo:1:12 Extent=[3:12 - 3:15]

The last part of the reference from the category to the @interface.



More information about the cfe-dev mailing list