[cfe-dev] Getting the class name for a category in libclang
David Chisnall
csdavec at swan.ac.uk
Fri Oct 29 13:45:17 PDT 2010
On 29 Oct 2010, at 21:38, Ted Kremenek wrote:
> On Oct 29, 2010, at 12:46 PM, David Chisnall wrote:
>
>> There also doesn't seem to be a way of walking the class hierarchy; I was expecting to be able to find the superclass for a class interface decl, but the only way I can see for doing this is to find the token and then parse the source code myself, which rather defeats the point of using libclang...
>
> I can be done using the current APIs. Tools have been built on this API that care very much about the Objective-C type hierarchy.
Hints welcome - I'd certainly be very happy to use the existing APIs if you felt like documenting how to walk the hierarchy without adding new APIs...
>> I'm happy to spend some time implementing these, but we should probably agree on what the interfaces should look like first. I would propose something like this:
>>
>> // Returns the cursor for the class @interface when passed a category @interface or @implementation cursor, invalid cursor otherwise.
>>
>> CXCursor clang_getObjCCategoryClassInterface(CXCursor);
>
> This seems reasonable, although I'm not certain it is strictly necessary. That said, I don't have strong feelings either way. It certainly is clear on what it does.
Again, if there's a way that actually works of doing this without a new API, I'd be happy to use it.
>> // Returns the number of superclasses of the given class (always returns 0 or 1 for ObjC classes, may return more for C++). Returns 0 if the cursor is not a valid ObjC or C++ class interface or implementation decl
>>
>> unsigned clang_getNumberOfSuperclasses(CXCursor);
>>
>> // Returns a cursor for the interface to the nth superclass of the cursor indicated by the first argument.
>>
>> CXCursor clang_getSuperclass(CXCursor, unsigned);
>
> Since these APIs are specific to Objective-C cursors, I'd prefer to include 'ObjC' in the class names. How about:
>
> unsigned clang_getNumObjCSuperClasses(CXCursor C);
> CXCursor clang_getObjCSuperClass(CXCursor C, unsigned idx);
>
> That matches the current coding style.
>
> I think this is a succinct API; the only thing I'm mixed on is that this really isn't exposing more raw functionality in the library. We've been trying to keep the API surface parsimonious.
For ObjC, there is never more than one superclass, so simply clang_getObjCSuperClass(CXCursor) would be sufficient. I was intending to support C++ classes via the same API, so users only needed one code path to build C++ and ObjC class hierarchies (the same cursor will never be both a valid C++ and ObjC class, so the hierarchies will be distinct).
David
-- Sent from my brain
More information about the cfe-dev
mailing list