[cfe-users] AST matcher behavior question

Rémi Cohen-Scali via cfe-users cfe-users at lists.llvm.org
Tue Oct 10 13:41:30 PDT 2017


Hi

I encounter a weird behavior on AST matchers and I'd like to ear what U
think of it.
Let get a test file

void f()
{
   int a, b, c, d;
   a = 1;
  b = 2;
  c = 3;
  d = 4;
}

Then query the decl matcher:
functionDecl(hasName("f"),hasBody(hasDescendant(binaryOperator(hasOperatorName("=")).bind("binop"))))

I got only the first assignmen
​t (was expecting to get all of them).​
​
​
​
​

I tried to add the findAll matcher but got an error.

functionDecl(hasName("f"),hasBody(hasDescendant(findAll(binaryOperator(hasOperatorName("=")).bind("binop")))))

Here is the clang-query output:

clang-query> match
functionDecl(hasName("f"),hasBody(hasDescendant(binaryOperator(hasOperatorName("=")).bind("binop"))))

Match #1:

/tmp/test.c:5:3: note: "binop" binds here
  a = 1;
  ^~~~~
/tmp/test.c:1:1: note: "root" binds here
void f()
^~~~~~~~
1 match.
clang-query> match
functionDecl(hasName("f"),hasBody(hasDescendant(findAll(binaryOperator(hasOperatorName("=")).bind("binop")))))
1:2: Error parsing argument 2 for matcher functionDecl.
1:28: Error parsing argument 1 for matcher hasBody.
1:36: Error parsing argument 1 for matcher hasDescendant.
1:50: Matcher not found: findAll
clang-query>

​Thanks for any help​

​Rémi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-users/attachments/20171010/f924032f/attachment.html>


More information about the cfe-users mailing list