[cfe-dev] from source location to token?
clattner at apple.com
Wed Dec 10 12:31:01 CST 2008
On Dec 10, 2008, at 6:03 AM, Paolo Bolzoni wrote:
> 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
>> 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
> It seems Lexer::MeasureTokenLength() automatically changes the
> using clang::SourceManager::getLogicalLoc() . In my case it shouldn't.
> What is the best way to obtain the token text after preprocessing?
Use "Loc = SourceManager.getPhysicalLoc(Loc)" before calling that code,
More information about the cfe-dev