[cfe-dev] get identifier end SourceLocation of CXXRecordDecl

Douglas Gregor dgregor at apple.com
Mon Mar 8 06:09:58 PST 2010


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



More information about the cfe-dev mailing list