[cfe-dev] matcher acting wierd,imho
Farzad Sadeghi via cfe-dev
cfe-dev at lists.llvm.org
Mon Nov 7 13:02:35 PST 2016
thank you. that actually solves my problem but still doesnt explain
why the matcher i wrote wasnt matching anything at all.
hasDescendant(ifStmt()) is true for the first "if".
hasElse(anything()) is also true and unless(hasAncestor(ifStmt())) is
also true. and theyre all arguments to a "allOf()" so technically the
first "if" should be matched and binded by root. am i mistaken
somewhere?
On 11/7/16, Aaron Ballman <aaron at aaronballman.com> wrote:
> On Mon, Nov 7, 2016 at 4:03 AM, Farzad Sadeghi via cfe-dev
> <cfe-dev at lists.llvm.org> wrote:
>> I have a simple `if-else if` code I'm trying to match but clang-query
>> or clang itself match nothing.
>> here's the C code:
>> void myfunc (void)
>> {
>> int a = 0U;
>> int b = 10U;
>>
>> if (a == b)
>> {
>> a++;
>> }
>> else if (a > b )
>> {
>> b++;
>> }
>>
>> }
>>
>> and this is my matcher:
>> ifStmt( allOf( hasDescendant(ifStmt()), hasElse(anything()) ,
>> unless(hasAncestor(ifStmt())) ) )
>>
>> clang-query and clang don't match anything. Am i assuming wrong that I
>> should get one match or I'm misunderstanding something here?
>
> I think the matcher you may want is:
>
> clang-query> m ifStmt(hasElse(ifStmt().bind("else if")))
>
> Match #1:
>
> E:\Desktop\test.c:10:14: note: "else if" binds here
> else if (a > b )
> ^~~~~~~~~~~
> E:\Desktop\test.c:6:9: note: "root" binds here
> if (a == b)
> ^~~~~~~~~~~
> 1 match.
>
> However, it depends on what code pattern you're trying to match. This
> matcher assumes you're looking for else if statements (which "else if"
> binds to, while "root" binds to the if statement that the else
> statement matches).
>
> ~Aaron
>
>>
>> --
>> Farzad Sadeghi
>> _______________________________________________
>> cfe-dev mailing list
>> cfe-dev at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
--
Farzad Sadeghi
More information about the cfe-dev
mailing list