<div dir="ltr">Hi Kirill, <div><br></div><div>I am not interested only in assignments within if condition, but just want to treat them differently. Specifically, I want to add a function/macro </div><div>after each assignment to an instance of a certain struct type. </div><div>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"><div><div class="gmail_signature" data-smartmail="gmail_signature">--<div>Himanshu</div></div></div>
<br><div class="gmail_quote">On Sat, Jul 30, 2016 at 1:10 PM, Kirill Bobyrev 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 style="word-wrap:break-word"><div>Treating nodes of a single type differently depending on their specifics might be much easier with AST Matchers.</div><div><br></div><div>What you’re looking for is <i>hasConditionVariableStatement</i> [<a href="http://clang.llvm.org/docs/LibASTMatchersReference.html#hasConditionVariableStatement0Anchor" target="_blank">http://clang.llvm.org/docs/LibASTMatchersReference.html#hasConditionVariableStatement0Anchor</a>].</div><div><br></div><div>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><br></div><div>—</div><span class="HOEnZb"><font color="#888888"><div>Kirill Bobyrev </div><br></font></span><div><blockquote type="cite"><div><div class="h5"><div>On 30 Jul 2016, at 19:45, Himanshu via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>> wrote:</div><br></div></div><div><div><div class="h5"><div dir="ltr">Hi All, <div><br></div><div>In my VisitBinaryOperator I want to treat assignments in IfStmt's predicate check part differently </div><div>than the assignments in its body. For example: </div><div><br></div><div>if( (*ptrI = malloc(sizeof(int) * 10)) == NULL)  // => this assignment is within predicate </div><div>        msg = "success"; // assignment in body (treat it differently than the above)</div><div>else</div><div>        msg = "fail"; // assignment in body</div><div><br></div><div><br></div><div>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><br></div><div>Thanks!</div></div></div></div><span class="">
_______________________________________________<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" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br></span></div></blockquote></div><br></div><br>_______________________________________________<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/mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div><br></div>