Keep in mind that the body of a for statement can be not only a CompoundStmt ending in tok::r_brace, but any statement, including another "for" statement, which in turn could end in either a semicolon or brace.  As I recall, getLocEnd in any of these cases will point to the token before either the ";" or the "}", but you might want to check that.  And you can probably check the result of loc = Lexer::findLocationAfterToken(...) for loc.isValid() to see if the token was indeed found there.<br>
<br>It seems like some generic Stmt call such as getLocForEndOfStmt() would really be useful.<br><br>Robert<br><br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

><br>
> On Feb 4, 2013, at 17:37 , Antoine Trouve <<a href="mailto:trouve@isit.or.jp">trouve@isit.or.jp</a>> wrote:<br>
><br>
>> My bad, I was using the function the wrong way.<br>
>><br>
>> But I noticed that I couldn't go through a semicolon using "Lexer::getLocForEndOfToken" if there is a space before the semicolon.<br>
>><br>
>> For instance, let's consider this code:<br>
>><br>
>>      for(i=0; i<mand(N,N); i++) res ++ ;<br>
>><br>
>> Initially, the SourceLocation retreieved with "getLocEnd()" is before the "++":<br>
>><br>
>>      for(i=0; i<mand(N,N); i++) res /*HERE*/++ ;<br>
>><br>
>> If I call "Lexer::getLocForEndOfToken", it will point to after "++": nice:<br>
>><br>
>>      for(i=0; i<mand(N,N); i++) res ++/*HERE*/ ;<br>
>><br>
>> Then if I call again getLocForEndOfToken, the result will point to the exact same location (I need to call "getLocWithOffset")<br>
>><br>
>>      for(i=0; i<mand(N,N); i++) res ++/*STILL HERE*/ ;<br>
>><br>
>> In the case I don't have any space before the semicolon, the return value of the second call to getLocForEndOfToken will point to after it:<br>
>><br>
>>      for(i=0; i<mand(N,N); i++) res ++;/*HERE*/<br>
>>      (no space before the ";")<br>
>><br>
>> Is that the expected behaviour ? I find it pretty annoying in my very situation because I have no choice but looping with "SourceLocation::getLocWithOffset" until I find a ";".<br>
><br>
> Hm. It's expected behavior because an Expr can be nested inside other Exprs, in which case you only want the beginning and end of the Expr to include the expression itself. Consider "a + b * c;" The semicolon is not part of "b * c"; you could argue it's part of "a + b * c", but that's not consistent. On the other hand, we otherwise don't track the location of the semicolon anywhere.<br>

><br>
> I can see this being an actual deficiency we want to fix; if you're interested in pursuing this, please file a bug report at <a href="http://llvm.org/bugs/" target="_blank">http://llvm.org/bugs/</a>. Meanwhile, Lexer::findLocationAfterToken will probably be a more resilient way to find the semicolon.<br>

<br>
Yes, the behaviour is not consistent to my point of view. I'll file a bug report.<br>
Anyway, I'm using "findLocationAfterToken" as you suggested and it works like a charm: thank you for your help !<br>
<br>
- Antoine<br>
<br></blockquote></div>