[cfe-dev] matcher acting wierd,imho
Aaron Ballman via cfe-dev
cfe-dev at lists.llvm.org
Mon Nov 7 12:59:00 PST 2016
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
More information about the cfe-dev
mailing list