Getting the location of the identifier in TagDecl and RecordDecl

Hi,

How can one get the location of the identifier of a TagDecl or RecordDecl?

For example, if I have "enum Foo { ... }" and have a TagDecl *T. T->getLocStart() returns the beginning location of the token "enum". I tried to use Lexer::findLocationAfterToken with that location and tok::kw_enum but that gives me an invalid location. Preprocessor::getLocForEndOfToken() with that start location returns the location right after the token "enum", but not the start of "Foo". The reason I'm not using getName() or type information is that I want to replace "Foo" with some other things, hence the need for source locations.

Thanks!

Lukhnos

You may want to use getLocation().

Also, in your example, seems using tok::identifier with getLocForEndOfToken is more appropriate?

- Yang

I actually tried that, but it also gave me an invalid location. Is there any possible cause for that?

getLocation() works -- thanks!

Lukhnos