<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 30 Jul 2016, at 22:34, Himanshu <<a href="mailto:himanshu@utexas.edu" class="">himanshu@utexas.edu</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Hi Kirill, <div class=""><br class=""></div><div class="">I am not interested only in assignments within if condition, but just want to treat them differently.</div></div></div></blockquote>That was exactly my point…</div><div><br class=""></div><div>Just see some clang-tidy checks for examples.<br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""> Specifically, I want to add a function/macro </div><div class="">after each assignment to an instance of a certain struct type. </div><div class="">Hence, I want an approach that can identify all the '=' assignments to that type, and if they are within if conditions then use a function call to <function_for_if_assign>(.... ) otherwise call <function_for_stmt_assign>(...). </div></div><div class="gmail_extra"><br clear="all" class=""><div class=""><div class="gmail_signature" data-smartmail="gmail_signature">--<div class="">Himanshu</div></div></div>
<br class=""><div class="gmail_quote">On Sat, Jul 30, 2016 at 1:10 PM, Kirill Bobyrev via cfe-dev <span dir="ltr" class=""><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank" class="">cfe-dev@lists.llvm.org</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><div class="">Treating nodes of a single type differently depending on their specifics might be much easier with AST Matchers.</div><div class=""><br class=""></div><div class="">What you’re looking for is <i class="">hasConditionVariableStatement</i> [<a href="http://clang.llvm.org/docs/LibASTMatchersReference.html#hasConditionVariableStatement0Anchor" target="_blank" class="">http://clang.llvm.org/docs/LibASTMatchersReference.html#hasConditionVariableStatement0Anchor</a>].</div><div class=""><br class=""></div><div class="">Generally, try to use RecursiveASTVisitor when what you want is exactly node traversal, i.e. almost no dispatching. Otherwise, use AST Matchers. They’re easy to use and yet very powerful.</div><div class=""><br class=""></div><div class="">—</div><span class="HOEnZb"><font color="#888888" class=""><div class="">Kirill Bobyrev </div><br class=""></font></span><div class=""><blockquote type="cite" class=""><div class=""><div class="h5"><div class="">On 30 Jul 2016, at 19:45, Himanshu via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" target="_blank" class="">cfe-dev@lists.llvm.org</a>> wrote:</div><br class=""></div></div><div class=""><div class=""><div class="h5"><div dir="ltr" class="">Hi All, <div class=""><br class=""></div><div class="">In my VisitBinaryOperator I want to treat assignments in IfStmt's predicate check part differently </div><div class="">than the assignments in its body. For example: </div><div class=""><br class=""></div><div class="">if( (*ptrI = malloc(sizeof(int) * 10)) == NULL)  // => this assignment is within predicate </div><div class="">        msg = "success"; // assignment in body (treat it differently than the above)</div><div class="">else</div><div class="">        msg = "fail"; // assignment in body</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Here, I would like to handle the ptrI = malloc assignment differently than the other two assignments of 'msg'. I tries setting a flag in VisitIfStmt, but that can't distinguish between the two different kind of assignments. </div><div class=""><br class=""></div><div class="">Thanks!</div></div></div></div><span class="">
_______________________________________________<br class="">cfe-dev mailing list<br class=""><a href="mailto:cfe-dev@lists.llvm.org" target="_blank" class="">cfe-dev@lists.llvm.org</a><br class=""><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" target="_blank" class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br class=""></span></div></blockquote></div><br class=""></div><br class="">_______________________________________________<br class="">
cfe-dev mailing list<br class="">
<a href="mailto:cfe-dev@lists.llvm.org" class="">cfe-dev@lists.llvm.org</a><br class="">
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank" class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br class="">
<br class=""></blockquote></div><br class=""></div>
</div></blockquote></div><br class=""></body></html>