<div dir="ltr">I think this question is basically not about equalsBoundNodes() at all.<div><br></div><div>The questions that needs answering are:</div><div style>- What should stmt(forEachDescendant(varDecl().bind("var")), forEachDescendant(declRefExpr().bind("decl"))) do?</div>
<div style>- What should stmt(forEachDescendant(varDecl().bind("var")), has(declRefExpr().bind("decl"))) do?</div><div style><br></div><div style>I think the first should call the callback for each pair (VarDecl, DeclRefExpr) under each Stmt. And the second should call the callback once for each VarDecl under a Stmt that has a DeclRefExpr-child.</div>
<div style><br></div><div style>The matchers themselves match, if the callback was invoked at least once.</div><div style><br></div><div style>I think we need to answer these questions first and then the behavior of equalsBoundNodes() will follow naturally.</div>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, May 23, 2013 at 3:01 PM, Vane, Edwin <span dir="ltr"><<a href="mailto:edwin.vane@intel.com" target="_blank">edwin.vane@intel.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">To help stimulate discussion, let me present the two ways this matcher has been interpreted:<br>
<br>
1) An "all or nothing" matcher. equalsBoundNode("X") returns true if there exists any previously bound node called "X" and that node satisfies an identity relationship with the node passed to equalsBoundNode. If no such node exists, the matcher just returns false and the match fails, much like any other matcher.<br>

2) As a filter. Consider the matches found by forEach*() as the set of matches. Then the has() matcher containing equalsBoundNode() is used as a filter over this set. Whenever equalsBoundNode() locates a previously bound node with the correct name and satisfying the identity condition, it's really referring to a node in the match set. If the has() matcher fails, the node gets removed from the match set.<br>

<br>
The difference can be seen by looking at what matches get returned from either interpretation. With #1, as long as a functionDecl has at least one call statement to a function returning a type that matches any of the varDecls found within ifStmt's, the function will match and the set of bound nodes will be *every* varDecl found within ifStmts.<br>

<br>
With #2, the matcher will match (When? Same as #1? Only if the set of bound nodes is non-empty?) and the set of bound nodes will be only those varDecls whose type matches the return type of a function called somewhere in the function.<br>

<br>
I have my thoughts on both but don't want to influence anybody before hearing opinions first.<br>
<div class="im HOEnZb"><br>
> -----Original Message-----<br>
> From: Manuel Klimek [mailto:<a href="mailto:klimek@google.com">klimek@google.com</a>]<br>
> Sent: Thursday, May 23, 2013 5:42 AM<br>
> To: Gábor Kozár<br>
> Cc: Vane, Edwin; Clang Dev List (<a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a>)<br>
> Subject: Re: [cfe-dev] RFC: What does this matcher mean to you?<br>
><br>
</div><div class="HOEnZb"><div class="h5">> For clarification: the problem is less "whether it matches", but for which<br>
> matches you get callbacks with what bound nodes.<br>
><br>
> The forEachDescendant(... .bind("declType")) part in the matcher on its own will<br>
> result in a callback for each found declType child, with the node bound to<br>
> "declType".<br>
><br>
> The question is: given that there are multiple matches for forEachDescendant,<br>
> what is the behavior of the has(... equalsBoundNode("declType")) part:<br>
> How many callbacks with which bound nodes do you expect?<br>
><br>
> Cheers,<br>
> /Manuel<br>
><br>
><br>
><br>
> On Tue, May 21, 2013 at 7:35 PM, Gábor Kozár <<a href="mailto:kozargabor@gmail.com">kozargabor@gmail.com</a>><br>
> wrote:<br>
><br>
><br>
>       I would expect it the equalsBoundNode("declType") to either:<br>
><br>
>        - raise an error (assertion failure or exception) or<br>
>        - check all nodes bound to "declType", and return true if any of them is<br>
> equal<br>
><br>
>       Perhaps different variants could be introduced with both behaviors? For<br>
> example, equalsBoundNode(string) would only work if there is exactly one node<br>
> bound to the specified name, while equalsAnyBoundNode(string) would look for<br>
> equality in any node bound to the specified name.<br>
><br>
><br>
>       2013/5/21 Vane, Edwin <<a href="mailto:edwin.vane@intel.com">edwin.vane@intel.com</a>><br>
><br>
><br>
>               We're trying to determine the semantics of the proposed new<br>
> 'equalsBoundNode()' matcher. Before I present the aforementioned matcher<br>
> expression let me illustrate what this new matcher does. Given that you've<br>
> bound a node earlier in a matcher expression with a name "X",<br>
> equalsBoundNode("X") allows you to refer back to that bound node and test for<br>
> identity. For example, here's a matcher finding VarDecl's where the type<br>
> matches the initializer type:<br>
><br>
>               varDecl(hasType(qualType().bind("type")),<br>
><br>
> hasInitializer(ignoringParenImpCasts(hasType(qualType(equalsBoundNode("type<br>
> "))))))));<br>
><br>
>               Semantics get more interesting where forEach*() matchers are<br>
> concerned. So this is where I ask: What would you expect the following matcher<br>
> to do? How would you expect it to behave?<br>
><br>
>                   functionDecl(<br>
>                     forEachDescendant(<br>
>                       ifStmt(<br>
>                         forEachDescendant(<br>
>                           varDecl(hasType(qualType().bind("declType")))<br>
>                         )<br>
>                       )<br>
>                     ),<br>
>                     has(compoundStmt(has(<br>
>                       callExpr(<br>
>                         callee(<br>
>                           functionDecl(<br>
>                             returns(qualType(equalsBoundNode("declType")))<br>
>                           )<br>
>                         )<br>
>                       )<br>
>                     )))<br>
>                   );<br>
><br>
><br>
>               --<br>
>               Edwin Vane<br>
>                 Software Developer<br>
>                 Intel of Canada, Inc.<br>
><br>
><br>
>               _______________________________________________<br>
>               cfe-dev mailing list<br>
>               <a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
>               <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
><br>
><br>
><br>
><br>
>       _______________________________________________<br>
>       cfe-dev mailing list<br>
>       <a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
>       <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
><br>
><br>
><br>
<br>
<br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
</div></div></blockquote></div><br></div>