[cfe-dev] End SourceLocation for multi-line Tokens?

Chris Lattner clattner at apple.com
Thu Apr 24 09:13:24 PDT 2008


On Apr 24, 2008, at 8:53 AM, Emerson Murphy-Hill wrote:
> How would one get the end of a Token if it spans several lines, such
> as a BCPL comment?  I can clearly get the start position and length,
> but the token may contain any number of line breaks. I suppose I could
> use the preprocessor to get the text of the token, count the number of
> line breaks, and calculate the end line number and column, but is
> there an easier way?

Are you asking about something like:


foo\
bar??/
baz

?  If so, the source location for the token will point to the start of  
foo.  Lexer::getTokenLength will return the full extent of the token.   
Adding it to the start location will give you a location that points  
to the space after the 'z'.

-Chris



More information about the cfe-dev mailing list