Clang AST如何匹配一元运算符调用(decltype中的调用除外)?

Clang AST如何匹配一元运算符调用(decltype中的调用除外)?,clang,llvm,Clang,Llvm,我可以轻松地将一元运算符调用与以下查询匹配: m unaryOperator(unless(isExpansionInSystemHeader())) 但是,我想排除如下匹配: decltype(&Func) 是否有一个查询可以用来排除这些调用,或者我应该以某种方式将它们从代码中排除?是的,请使用。比如说, // test.cpp int foo(); int main() { int i=0; i++; int *k = &i; decltype(&a

我可以轻松地将一元运算符调用与以下查询匹配:

m unaryOperator(unless(isExpansionInSystemHeader()))
但是,我想排除如下匹配:

decltype(&Func)
是否有一个查询可以用来排除这些调用,或者我应该以某种方式将它们从代码中排除?

是的,请使用。比如说,

// test.cpp
int foo();

int main() {
  int i=0;
  i++;

  int *k = &i;

  decltype(&foo) j;
  return 0;
}
使用
clangquerytest.cpp--

要匹配所有一元运算符,请执行以下操作:

clang-query> m unaryOperator()

Match #1:

/.../test.cpp:6:3: note: "root" binds here
  i++;
  ^~~

Match #2:

/.../test.cpp:8:12: note: "root" binds here
  int *k = &i;
           ^~

Match #3:

/.../test.cpp:10:12: note: "root" binds here
  decltype(&foo) j;
           ^~~~
3 matches.
要排除

clang-query> m unaryOperator(unless(hasOperatorName("&")))

Match #1:

/.../test.cpp:6:3: note: "root" binds here
  i++;
  ^~~
1 match.

要排除
decltype

clang-query> m unaryOperator(unless(hasAncestor(varDecl(hasType(decltypeType())))))

Match #1:

/.../test.cpp:6:3: note: "root" binds here
  i++;
  ^~~

Match #2:

/.../test.cpp:8:12: note: "root" binds here
  int *k = &i;
           ^~
2 matches.