[cfe-dev] wrong getLocEnd() returns
Jordan Rose
jordan_rose at apple.com
Mon Nov 4 09:26:54 PST 2013
For the most part, Clang's SourceLocations are token-granular; therefore, the "end location" is the location of the last token in a statement. To actually get the location after the last character, you'll need to use Lexer::getLocForEndOfToken.
Hope that helps,
Jordan
On Nov 4, 2013, at 2:33 , nicolas normand <doomyster at gmail.com> wrote:
> Hi clang devs,
>
> Using clang 3.3, I noticed that some classes (clang::FloatingLiteral
> for exemple) lacks the End Location information, returning the Start
> Location instead.
>
> As an example, these sources
> void function() {
> float f = 0.0;
> }
>
> gives an AST like (I just keep the interesting part):
> CompoundStmt 0x5457228 <test1.c:1:17, line:3:1>
> `-DeclStmt 0x5457210 <line:2:1, col:14> // Ok this that
> `-VarDecl 0x5457180 <col:1, col:11> f 'float' // It should end at 13
> `-ImplicitCastExpr 0x54571f8 <col:11> 'float' <FloatingCast>
> // Same here
> `-FloatingLiteral 0x54571d8 <col:11> 'double' 0.000000e+00 // Same here
>
> It is problematic for me, because I can't trust the return of
> getLocEnd() methods (I want to rewrite sources and need precise
> locations).
> Patching this seemed not hard to me, so I gave it a try and succeeded
> for FloatingLiteral.
>
> I was wondering if there were good reasons NOT doing this patch for
> all objects ?
> Would you be interested in such patches ?
> Are there other ways to retrieve precise end locations ?
>
> Thanks,
> Nicolas
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
More information about the cfe-dev
mailing list