Value (text) of a token

Is there any way to get the text of a token, regardless of its kind? Like ‘>’ or ‘=’, or ‘Foo’ if Foo is an identifier.

Andrew Sutton
andrew.n.sutton@gmail.com

Hi Andrew,

I believe Token::getName() or tok::getTokenName() is what you are looking for…

snaroff

Andrew Sutton a écrit :

Is there any way to get the text of a token, regardless of its kind? Like '>' or '=', or 'Foo' if Foo is an identifier.

Andrew Sutton
andrew.n.sutton@gmail.com <mailto:andrew.n.sutton@gmail.com>

I think you need:
Preprocesseur::getSpelling or SourceManager::getCharacterData

Hi Andrew,

I believe Token::getName() or tok::getTokenName() is what you are looking for…

I think that will return “lparen” for ‘(’ etc.

Tokens can have multiple spellings for each token, for example an identifier could be ‘foo’ or ‘bar’, but even simple things like && can be spelled “&&” or “and” (in C++). There are also a variety of digraphs etc. If you want to get the original spelling from the source code (minus escaped newlines, trigraphs etc), use Preprocessor::getSpelling(token)

-Chris

Ah yes. Now I remember…

Thanks for the clarification,

snaroff