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

David Chisnall csdavec at swan.ac.uk
Fri Oct 29 12:16:02 PDT 2010


On 29 Oct 2010, at 20:05, Ted Kremenek wrote:

> 
> On Oct 29, 2010, at 11:48 AM, David Chisnall wrote:
> 
>> Hi,
>> 
>> I'm trying to build an index using libclang, but there doesn't appear to be any way of getting the class name for a cursor representing an Objective-C category, other than to generate and then parse the USR.  Am I missing something, or is this missing functionality?  
> 
> Hi David,
> 
> Is clang_getCursorSpelling() not sufficient for this case?

Nope, this returns the name of the category.  For example, in the case of:

@implementation Foo (Bar)

This returns Bar.  I see no API for accessing Foo.

> FYI, the USRs should be viewed as opaque strings.  You should never parse them.  They are designed to be changed at any time for purposes of efficiency, etc.  They are really designed to just be unique keys.

Fair enough.

>> If it's missing, does anyone have any thoughts about the correct way to expose this?  My initial expectation was that the semantic parent for a category should be the class, but there are a number of cases where this quickly becomes nonintuitive.  Should there be a dedicated function for getting the class name from a category declaration?
> 
> I don't believe we need a special API for this.  I believe that all of the information is there.  If you find that it is cumbersome, however, we can evaluate whether it makes sense to add additional APIs.


Presumably something similar is required for navigating class hierarchies, in both C++ and Objective-C; for example, I don't see an API for getting the superclass of either.  I would expect something similar to the semantic parent API.

David

-- Sent from my PDP-11



More information about the cfe-dev mailing list