[cfe-dev] from source location to token?

Paolo Bolzoni bolzoni at cs.unipr.it
Fri Jan 16 01:33:12 PST 2009


On Wed, 10 Dec 2008 10:31:01 -0800
Chris Lattner <clattner at apple.com> wrote:

> 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  
> >> (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?
> 
> Use "Loc = SourceManager.getPhysicalLoc(Loc)" before calling that code,
> 
> -Chris
> 

I did that, and it worked well until the last update of clang.
But after updating to release 62317 I get this error:
‘class clang::SourceManager’ has no member named ‘getPhysicalLoc’

what is the correct solution now?

pb




More information about the cfe-dev mailing list