Could you post a bit more context (a minimal example) of what you are precisely looking at? I could not reproduce the error for the cases 1-4. If I put them outside of a method, they don't lead to a DeclStmt, but a CXXRecordDec. If I put them into a method, e.g.:<div>
<br></div><div>void f() {<br> union { int a; };</div><div>}</div><div><br></div><div>I get the DeclStmt but it seems to have the right code range (column 2 to 19).</div><div><div><br></div><div>In general, the code location handling is quite inconsistent and we are currently looking into how to improve this.</div>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Jul 12, 2012 at 6:45 AM, Sergejs Belajevs <span dir="ltr"><<a href="mailto:sergejs.belajevs@gmail.com" target="_blank">sergejs.belajevs@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
I am working on source-to-source transformation tool and want to get<br>
the original source code for a statement token by token. I am using<br>
statement's getLocStart/getLocEnd, SourceLocation's getLocWithOffset,<br>
SourceManager's getCharacterData and Lexer::MeasureTokenLength. My<br>
code worked fine until I ran into some DeclStmts:<br>
<br>
1) struct A { int a; } s;<br>
2) struct A { int a; };<br>
3) union A { int a; };<br>
4) union { int a; };<br>
<br>
For 1) getLocEnd() works fine.<br>
For 2) my code doesn't work because getLocEnd() is smaller than<br>
getLocStart(). End's getRawEncoding() returns 0. I found a workaround<br>
for this case by calling getLocEnd() of DeclStmt's getSingleDecl().<br>
Case 3) has the same problem as 2), same workaround works fine.<br>
Case 4) has the same problem as 2), but this time after applying my<br>
workaround the resulting SourceLocation is the same as getLocStart(),<br>
that is points to token "union".<br>
<br>
So I guess the questions are:<br>
* Is this expected behavior? If yes, then what exactly getLocEnd() returns?<br>
* How could I get the end location for case 4)?<br>
* Is there a better way to get statement as token strings?<br>
* As an alternative to previous question, can I somehow find the total<br>
character length of statement in the original source code?<br>
<br>
<br>
Thanks,<br>
Sergejs<br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
</blockquote></div><br></div>