[cfe-dev] Finding out if an assignment is within If statement's predicate

Kirill Bobyrev via cfe-dev cfe-dev at lists.llvm.org
Sat Jul 30 13:10:05 PDT 2016


Treating nodes of a single type differently depending on their specifics might be much easier with AST Matchers.

What you’re looking for is hasConditionVariableStatement [http://clang.llvm.org/docs/LibASTMatchersReference.html#hasConditionVariableStatement0Anchor].

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.

—
Kirill Bobyrev 

> On 30 Jul 2016, at 19:45, Himanshu via cfe-dev <cfe-dev at lists.llvm.org> wrote:
> 
> Hi All, 
> 
> In my VisitBinaryOperator I want to treat assignments in IfStmt's predicate check part differently 
> than the assignments in its body. For example: 
> 
> if( (*ptrI = malloc(sizeof(int) * 10)) == NULL)  // => this assignment is within predicate 
>         msg = "success"; // assignment in body (treat it differently than the above)
> else
>         msg = "fail"; // assignment in body
> 
> 
> 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. 
> 
> Thanks!
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20160730/711c2660/attachment.html>


More information about the cfe-dev mailing list