<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 11 September 2017 at 09:25, Won Tae Joo 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><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div>Hi, thanks for the reply!<br><br></div>AFAICS there seem to be
statments which does not match the case. Does it mean that I have to
handle every special cases(such as the 'int mul = 2;' declstmt in the example
seems to have an endloc which actually points the end) in my code?</div></div></blockquote><div><br></div><div>Unfortunately, yes, if you care where the semicolons are, you need to be aware that some Stmt subclasses include the semicolon (at least DeclStmt and possibly others), some have an implied semicolon (at least all the Expr subclasses and possibly others), and some don't have a trailing semicolon at all (CompoundStmt, C++ try/catch have none, IfStmt etc don't have one "of their own" but might have one as part of their substatement).</div><div><br></div><div>If you were interested in fixing this, we have been considering the addition of an ExprStmt node to represent an expression-statement (a statement of the form "expression;"), which would hold the location of the trailing semicolon of the expression. We'd need to analyse the memory cost of adding such AST nodes, but if it's reasonably small, we'd accept a patch to add that.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Or
can I assume that Lexer::getLocForEndOfToken will be a unified way to
handle every statments? I'm looking for a way to look up for the SourceRange of a statement whether it containes a ; or not. (such as a compound statement/ for loops)<span class="HOEnZb"><font color="#888888"><br></font></span></div><span class="HOEnZb"><font color="#888888"><div></div><div><br></div>Won-Tae</font></span><div><div class="h5"><br><div><div><div class="gmail_extra"><div class="gmail_quote">2017-09-11 18:04 GMT+02:00 Alex L <span dir="ltr"><<a href="mailto:arphaman@gmail.com" target="_blank">arphaman@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi,<div class="gmail_extra"><br></div><div class="gmail_extra">Stmt::getLocEnd() typically returns a location that points to the start of the last token. You have to call Lexer::getLocForEndOfToken with the location of the last token to compute the true end location of a statement (Please note that ';' won't be included).<br></div><div class="gmail_extra"><br></div><div class="gmail_extra">I hope this helps,</div><div class="gmail_extra">Alex</div><div class="gmail_extra"><br></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="m_-612108433991896073m_-5035132811157503334gmail-m_1306645077504205626gmail-m_-8677126354456048566h5">On 11 September 2017 at 17:00, Won Tae Joo 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></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div class="m_-612108433991896073m_-5035132811157503334gmail-m_1306645077504205626gmail-m_-8677126354456048566h5"><div dir="ltr"><div><div><div><div><div><div><div>Hello, <br></div><br>I was using llvm/clang 3.9 for developement, and something did not work as I intended.<br><br></div>Given a code like below, when I do ./clang -cc1 -ast-dump test.cpp, <br><br>#include <stdio.h><br>int main(int argc, char ** argv) <br>{<br> int mul = 2;<br> mul = 4 * mul;<br> return 0;<br>}<br><br></div>it prints an AST like..<br><br>`-FunctionDecl 0xd128d48 </home/joo/test.cpp:2:1, line:7:1> line:2:5 main 'int (int, char **)'<br> |-ParmVarDecl 0xd128bd0 <col:10, col:14> col:14 argc 'int'<br> |-ParmVarDecl 0xd128c70 <col:20, col:28> col:28 argv 'char **'<br> `-CompoundStmt 0xd128ff0 <line:3:1, line:7:1><br> |-DeclStmt 0xd128ec8 <line:4:3, col:14><br> | `-VarDecl 0xd128e48 <col:3, col:13> col:7 used mul 'int' cinit<br> | `-IntegerLiteral 0xd128ea8 <col:13> 'int' 2<br> |-BinaryOperator 0xd128f90 <line:5:3, col:13> 'int' lvalue '='<br> | |-DeclRefExpr 0xd128ee0 <col:3> 'int' lvalue Var 0xd128e48 'mul' 'int'<br> | `-BinaryOperator 0xd128f68 <col:9, col:13> 'int' '*'<br> | |-IntegerLiteral 0xd128f08 <col:9> 'int' 4<br> | `-ImplicitCastExpr 0xd128f50 <col:13> 'int' <LValueToRValue><br> | `-DeclRefExpr 0xd128f28 <col:13> 'int' lvalue Var 0xd128e48 'mul' 'int'<br> `-ReturnStmt 0xd128fd8 <line:6:3, col:10><br> `-IntegerLiteral 0xd128fb8 <col:10> 'int' 0<br></div>Please note where the end of the BinaryOperator, and the ReturnStmt is pointing.<br></div>Either cases was not pointing to the end of the statements but rather pointing to the beginning of second 'mul' and the beginning of '0' respectively. I've checked in 6.0 for the same thing and happens to point to the same location. So I'd assume that I was misunderstanding the usage of Stmt::getLocEnd(). May I ask what's the proper way to retrieve the end location of a statement?<br><br></div>Thanks,<br></div>Won-Tae<br></div>
<br></div></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></div>
</blockquote></div><br></div></div></div></div></div></div>
<br>______________________________<wbr>_________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org">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></div>