I am trying to use clang ASTMatcher to find if statments that has a condition with RHS as integer value 0 or 0.0f. For this purpose, I was able to write a query as follows:
clang-query> match ifStmt(hasCondition(binaryOperator(hasRHS(integerLiteral(equals(0)))))
When I am using the above query I get the error as follows:
1:2: Error parsing argument 1 for matcher ifStmt.
1:9: Error parsing argument 1 for matcher hasCondition.
1:22: Error parsing argument 1 for matcher binaryOperator.
1:37: Error parsing argument 1 for matcher hasRHS.
1:44: Error parsing argument 1 for matcher integerLiteral.
1:59: Matcher not found: equals
But, when I refer the online guide at http://clang.llvm.org/docs/LibASTMatchersReference.html, it says that Matcher equals is available:
Matcher<IntegerLiteral> equals const ValueT Value
Matches literals that are equal to the given value of type ValueT.
Given
f('false, 3.14, 42);
characterLiteral(equals(0))
matches 'cxxBoolLiteral(equals(false)) and cxxBoolLiteral(equals(0))
match false
floatLiteral(equals(3.14)) and floatLiteral(equals(314e-2))
match 3.14
integerLiteral(equals(42))
matches 42
Note that you cannot directly match a negative numeric literal because the
minus sign is not part of the literal: It is a unary operator whose operand
is the positive numeric literal. Instead, you must use a unaryOperator()
matcher to match the minus sign:
unaryOperator(hasOperatorName("-"),
hasUnaryOperand(integerLiteral(equals(13))))
Usable as: Matcher<CharacterLiteral>, Matcher<CXXBoolLiteralExpr>,
Matcher<FloatingLiteral>, Matcher<IntegerLiteral>
I am using llvm-4.0 and clang 3.8 on Ubuntu 16.04LTS.
I would appreciate any help.