Clang IfStmt with shortcut binary operator in condition

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Clang IfStmt with shortcut binary operator in condition

mustakimur
This post has NOT been accepted by the mailing list yet.

0
down vote
favorite
I am trying to detect if there is a function call inside an if statement as part of condition; like following:

if (cmp(a, b)){
  \\do something
}
I have found I could do this with AST matcher in following manner:
Matcher.addMatcher(ifStmt(hasCondition(callExpr().bind("call_expr")))
                           .bind("call_if_stmt"),&handleMatch);
But the problem is condition could have shortcuts like &&, ||; like following:

if(a != b && cmp(a,b) || c == 10){
\\ do something
}
Now this condition has binaryoperator && and ||; also have a call expression as part of it. Now how I could detect that there is a call expression inside this if statement? Definitely I don't know how many binary operator as shortcuts will be there, so I am looking for a generalize solution for this, possibly using clange AST matcher.
Loading...