[cfe-dev] interface name SourceLocation?
Emerson Murphy-Hill
emerson at apple.com
Fri Apr 11 10:29:59 PDT 2008
Thanks Steve, this worked. Although I had to use a slightly different
endBuf, because the Lexer was complaining:
const char *endBuf = SM->getBufferData(LocStart.getFileID()).second;
So that solution works for now, but it's on my wish list for having in
clang. Relatedly, one other thing for the wish list: the
SourceLocation for the superclass name. For example, the location of
token between the ':' and the '{' here:
@interface MyClass : MySuperClass {
Thanks again,
e
On Apr 10, 2008, at 3:11 PM, Steve Naroff wrote:
>
> On Apr 10, 2008, at 2:46 PM, Emerson Murphy-Hill wrote:
>
>> Howdy Steve,
>>
>> I asked Ted this question, but he suggested you might have a better
>> way to do this. I have an ObjCInterfaceDecl and I need the
>> location of the name of the interface. That is:
>>
>> @interface MyClass
>> ^ ^
>> Here to Here
>>
>> There's no AST node for that, as far as I know. Ted suggested
>> using the Lexer, like TextDiagnosticPrinter does, but also thought
>> there might be an easier way. Is there?
>>
>
> As you noticed, we don't have location info for all interface
> components. Currently, we only store a SourceLocation for the
> beginning/middle/end. We could certainly add more SourceLocations if
> necessary (since I'm not too concerned about the size of an
> ObjCInterfaceDecl).
>
> That said, at the moment, here is the idiom for obtaining a pointer
> to the characters (I do this in the rewriter).
>
> SourceLocation LocStart = CDecl->getLocStart(); // beginning
> SourceLocation LocEnd = CDecl->getLocEnd(); // marks the '>', '}',
> or identifier
> SourceLocation LocAtEnd = CDecl->getAtEndLoc(); // @end
>
> SourceManager *SM; // set elsewhere, obviously
> const char *startBuf = SM->getCharacterData(LocStart);
> const char *endBuf = SM->getCharacterData(LocEnd);
>
> At this point, you can use a Lexer to "formally" tokenize the buffer
> or you can do adhoc string manipulation (it's your call).
>
> Let me know if this works for you.
>
> snaroff
>
>> Thanks,
>>
>> Emerson
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20080411/9b810958/attachment.html>
More information about the cfe-dev
mailing list