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

Ted Kremenek kremenek at apple.com
Fri Oct 29 13:58:46 PDT 2010


On Oct 29, 2010, at 1:24 PM, David Chisnall wrote:

> That is not the same as what I said.  I have:
> 
> @interface Foo @end
> @implementation Foo (Bar)
> - (void)bar {}
> @end
> 
> Here, I am only able to get from the category implementation to the class interface if I also have a class implementation in the same compilation unit.  If I add this, then it works:
> 
> @implementation Foo @end
> 
> David

Hmm.  I'm seeing:

$ cat test.m
@interface Foo @end
@implementation Foo (Bar)
- (void)bar {}
@end

$ ~/llvm-cmake/bin/c-index-test -test-load-source all test.m | grep -v invalid
// CHECK: test.m:1:12: ObjCInterfaceDecl=Foo:1:12 Extent=[1:1 - 1:20]
// CHECK: test.m:2:1: ObjCCategoryImplDecl=Bar:2:1 (Definition) Extent=[2:1 - 4:2]
// CHECK: test.m:2:1: ObjCClassRef=Foo:1:12 Extent=[2:1 - 2:2]
// CHECK: test.m:3:1: ObjCInstanceMethodDecl=bar:3:1 (Definition) Extent=[3:1 - 3:15]
// CHECK: test.m:3:13: UnexposedStmt= Extent=[3:13 - 3:15]

The third line is the class reference, which we can get to from the ObjCCategoryImplDecl.  Unless I'm completely confused, basically you are trying to get from '@implementation Foo (Bar)' to the cursor for '@interface Foo'?



More information about the cfe-dev mailing list