[cfe-dev] from source location to token?
Paolo Bolzoni
bolzoni at cs.unipr.it
Wed Dec 10 06:03:55 PST 2008
On Mon, 24 Nov 2008 10:23:12 -0800
Chris Lattner <clattner at apple.com> wrote:
> The way it gets the end of the fp literal is to relex the token with
> code in Lexer::MeasureTokenLength.
>
> Given a SourceLocation and the length of the token (as returned by
> MeasureTokenLength) you can get the exact original spelling (including
> trigraphs and escaped newlines, beware). The pointer to the start of
> the string is obtained with:
>
> const char *StrData = SourceMgr.getCharacterData(Loc);
I have still a problem. Consider the following program:
#define N_OF_ELEM 037;
int a = N_OF_ELEM;
Using the method you suggest I have that the textual representation of the
integer literal in the right hand side of the assignment is `N_OF_ELEM'.
It seems Lexer::MeasureTokenLength() automatically changes the SourceLocation
using clang::SourceManager::getLogicalLoc() . In my case it shouldn't.
What is the best way to obtain the token text after preprocessing?
thanks
pb
More information about the cfe-dev
mailing list