[cfe-users] AST matcher behavior question

2017-10-10 Thread Rémi Cohen-Scali via cfe-users
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
___
cfe-users mailing list
cfe-users@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


Re: [cfe-users] AST matcher behavior question

2017-10-10 Thread Rémi Cohen-Scali via cfe-users
​Ok got it! I found my error.

However the findAll matcher is not recognized then is it possible to use
it, Is there some restrictions (that are not in AST Matchers ref) ?

For the little story, the correct matcher for getting all results is
something as:

​binaryOperator(hasAncestor(functionDecl(hasName("f"))),hasOperatorName("=")).bind("binop")

With it I got all binary ops, actually what the matcher is looking for :)

Thanks


*-=-=-=-=-*
Rémi COHEN-SCALI* - Direction Technique *Jayacode 
+33 665 964 182  | Skype: remi.cohen-scali

  

2017-10-10 22:41 GMT+02:00 Rémi Cohen-Scali :

> 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
>
___
cfe-users mailing list
cfe-users@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users


Re: [cfe-users] AST matcher behavior question

2017-10-10 Thread Rémi Cohen-Scali via cfe-users
I checked in the AST Matcher Ref doc I generated from my build tree, then
either there is a doc problem, or I don't understand how to use findAll
(however Matcher Matcher actually mean any matcher, then any place).

Thanks

PS.: Perhaps I'll create a doc bug for it ...??

*-=-=-=-=-*
Rémi COHEN-SCALI* - Direction Technique *Jayacode 
+33 665 964 182  | Skype: remi.cohen-scali

  

2017-10-11 8:26 GMT+02:00 Rémi Cohen-Scali :

> ​Ok got it! I found my error.
>
> However the findAll matcher is not recognized then is it possible to use
> it, Is there some restrictions (that are not in AST Matchers ref) ?
>
> For the little story, the correct matcher for getting all results is
> something as:
>
> ​binaryOperator(hasAncestor(functionDecl(hasName("f"))),
> hasOperatorName("=")).bind("binop")
>
> With it I got all binary ops, actually what the matcher is looking for :)
>
> Thanks
>
>
> *-=-=-=-=-*
> Rémi COHEN-SCALI* - Direction Technique *Jayacode 
> +33 665 964 182  | Skype:
> remi.cohen-scali
> 
> 
> 
>
> 2017-10-10 22:41 GMT+02:00 Rémi Cohen-Scali :
>
>> 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(binaryOperat
>> or(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(bina
>> ryOperator(hasOperatorName("=")).bind("binop")
>>
>> Here is the clang-query output:
>>
>> clang-query> match functionDecl(hasName("f"),hasB
>> ody(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"),hasB
>> ody(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
>>
>
>
___
cfe-users mailing list
cfe-users@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users