<div dir="auto">Thanks you!<div dir="auto">So I've misunderstood the meaning of API. </div><div dir="auto">Here is also related discussion on stackoverflow : <a href="https://stackoverflow.com/questions/11083066/getting-the-source-behind-clangs-ast">https://stackoverflow.com/questions/11083066/getting-the-source-behind-clangs-ast</a></div><div dir="auto"><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Oct 22, 2017 7:41 AM, "Don Hinton" <<a href="mailto:hintonda@gmail.com">hintonda@gmail.com</a>> wrote:<br type="attribution"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>You're assuming that the length of the end token is 1, but you should use its actual length instead.</div><div><br></div><div>So, instead of getting the end location of the statement, you should get the end token, then use its location and length, e.g., <font face="monospace, monospace">tok.getLocation().<span style="font-size:12.8px">getLocWithOf<wbr>fset(tok.getLength())</span></font><span style="font-family:monospace,monospace;font-size:12.8px">.</span></div><div><br></div><div>hth...</div><div>don</div></div><div class="gmail_extra"><br><div class="gmail_quote"><div class="elided-text">On Sat, Oct 21, 2017 at 9:28 PM, Roman Popov via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>></span> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="elided-text"><div dir="ltr">Hello, <div>I want to emit some text after each if statement in source code. When testing a tool I've found that ifStmt->getSourceRange() sometimes returns wrong end location. </div><div><br></div><div>In RecursiveASTVisitor I have following code to insert "$" before and after each if:</div><div><font face="monospace, monospace"><br></font></div><div><div><font face="monospace, monospace">    bool VisitIfStmt(clang::IfStmt* ifStmt)</font></div><div><font face="monospace, monospace">    {</font></div><div><font face="monospace, monospace">        clang::tooling::Replacement rep0(compInst.getSourceManager<wbr>(), ifStmt->getLocStart(), 0, "$");</font></div><div><font face="monospace, monospace">        handleAllErrors ( replacements.add(rep0) );</font></div><div><font face="monospace, monospace">        clang::tooling::Replacement rep1(compInst.getSourceManager<wbr>(), ifStmt->getLocEnd().getLocWith<wbr>Offset(1), 0, "$");</font></div><div><font face="monospace, monospace">        handleAllErrors ( replacements.add(rep1) );</font></div><div><font face="monospace, monospace">        return true;</font></div><div><font face="monospace, monospace">    }</font></div></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace"><div>    Replacements &replacements;</div><div>    ASTContext *Context;</div><div>    clang::CompilerInstance &compInst;</div><div><br></div></font></div><div><div>When testing on following code:</div></div><div><br></div><div><font face="monospace, monospace">    int a;</font></div><div><font face="monospace, monospace">    if (a)<br></font></div><div><div><font face="monospace, monospace">       a--;</font></div></div><div><br></div><div><div>Result is:</div></div><div><font face="monospace, monospace"><br></font></div><div><div><font face="monospace, monospace">    $if (a)</font></div><div><font face="monospace, monospace">       a-$-;</font></div></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace"><br></font></div><div><div>So Clang thinks that if statement ends inside decrement operator. Is it a bug, or I misuse API?</div></div><div><br></div><div>Thanks,</div><div>-Roman</div></div>
<br></div>______________________________<wbr>_________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div><br></div>
</blockquote></div><br></div>