[cfe-dev] matcher acting wierd,imho

Aaron Ballman via cfe-dev cfe-dev at lists.llvm.org
Tue Nov 8 07:48:20 PST 2016


On Tue, Nov 8, 2016 at 5:28 AM, Malcolm Parsons
<malcolm.parsons at gmail.com> wrote:
> On 7 November 2016 at 21:11, Aaron Ballman via cfe-dev
> <cfe-dev at lists.llvm.org> wrote:
>> ifStmt( allOf( hasDescendant(ifStmt()), hasElse(anything()),
>> unless(hasAncestor(ifStmt())) ) )
>>
>> I think that this does not match the top-level if statement because
>> hasDescendant(ifStmt()) will not be satisfied -- the top-level if
>> statement has no sub statements that are also an if statement.
>
> hasDescendant != hasChild.
>
> It's the hasAncestor that is behaving strangely:
>
> clang-query> match ifStmt(hasDescendant(ifStmt()), hasAncestor(ifStmt()))
>
> Match #1:
>
> ifstmt.c:5:3: note: "root" binds here
>   if (a == b) {
>   ^~~~~~~~~~~~~
> 1 match.
> clang-query> match ifStmt(hasDescendant(ifStmt()),
> hasAncestor(ifStmt().bind("ancestor")))
> 0 matches.

Okay, that is really strange. Adding a .bind() should not alter the
matches, as far as I'm aware. Manuel or Samuel, can you shed some
light on this? I think it's a bug.

~Aaron

>
> --
> Malcolm Parsons



More information about the cfe-dev mailing list