get identifier end SourceLocation of CXXRecordDecl

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

get identifier end SourceLocation of CXXRecordDecl

Ivan Sorokin
Hello!

I have a bit stupid question about getting SourceLocation from clang ast.

CXXRecordDecl has getLocation() member function that returns
SourceLocation of first character of identifier. That is for code

struct test {};

getLocation() points to first letter of "test" identifier. CXXRecordDecl
also has getLocStart() and getLocEnd() that return SourceLocation of
first letter of "struct" keyword and closing bracket "}" correspondingly.

But how can I get position of last letter of "test" identifier, position
of last letter of "struct" keyword and position of open bracket "{". I
can use SourceManager::getCharacterData() and skip over letters and
digits until I find end of "test" identifier, but this is silly. What is
canonical way to do this?

docs/InternalsManual.html did not help me.
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: get identifier end SourceLocation of CXXRecordDecl

Douglas Gregor

On Mar 8, 2010, at 7:25 AM, Ivan Sorokin wrote:

> Hello!
>
> I have a bit stupid question about getting SourceLocation from clang ast.
>
> CXXRecordDecl has getLocation() member function that returns
> SourceLocation of first character of identifier. That is for code
>
> struct test {};
>
> getLocation() points to first letter of "test" identifier. CXXRecordDecl
> also has getLocStart() and getLocEnd() that return SourceLocation of
> first letter of "struct" keyword and closing bracket "}" correspondingly.
>
> But how can I get position of last letter of "test" identifier, position
> of last letter of "struct" keyword and position of open bracket "{". I
> can use SourceManager::getCharacterData() and skip over letters and
> digits until I find end of "test" identifier, but this is silly. What is
> canonical way to do this?

Preprocessor::getLocForEndOfToken() returns a location one character past the end of the source location it is given.

        - Doug
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev