错误:未找到匹配器:等于

时间:2018-03-19 22:22:07

标签: clang abstract-syntax-tree llvm-clang clang-ast-matchers

我正在尝试使用clang ASTMatcher来查找具有RHS条件的整数值为0或0.0f的状态。为此,我能够编写如下查询:

clang-query> match ifStmt(hasCondition(binaryOperator(hasRHS(integerLiteral(equals(0)))))

当我使用上述查询时,我得到如下错误:

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

但是,当我在http://clang.llvm.org/docs/LibASTMatchersReference.html引用在线指南时,它表示Matcher等于可用:

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>

我在Ubuntu 16.04LTS上使用llvm-4.0和clang 3.8。

我将不胜感激。

1 个答案:

答案 0 :(得分:0)

好吧,我也在探讨AST Matchers。我也遇到了与clang-query相同的问题,但是当我在一个小的cpp文件中使用相同的matcher表达式时(例如可以在这里找到https://clang.llvm.org/docs/LibASTMatchersTutorial.html)并将其编译为可执行文件并传递文件,如果我想要检查“if statements”,它会正确显示结果。

由于某些原因,clang-query中没有equals()。