On Tue, Oct 23, 2012 at 11:05 AM, Philip Craig <span dir="ltr"><<a href="mailto:philipjcraig@gmail.com" target="_blank">philipjcraig@gmail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5">On Tue, Oct 23, 2012 at 7:04 PM, Manuel Klimek <<a href="mailto:klimek@google.com">klimek@google.com</a>> wrote:<br>
> On Tue, Oct 23, 2012 at 11:00 AM, Philip Craig <<a href="mailto:philipjcraig@gmail.com">philipjcraig@gmail.com</a>><br>
> wrote:<br>
>><br>
>> On Tue, Oct 23, 2012 at 6:44 PM, Manuel Klimek <<a href="mailto:klimek@google.com">klimek@google.com</a>> wrote:<br>
>> > On Tue, Oct 23, 2012 at 10:37 AM, Philip Craig <<a href="mailto:philipjcraig@gmail.com">philipjcraig@gmail.com</a>><br>
>> > wrote:<br>
>> >><br>
>> >> In a MatchCallback, is there any way of determining the topmost node<br>
>> >> that was matched without needing to bind it? This would merely be a<br>
>> >> convenience, similar to the way that regular expressions always return<br>
>> >> the complete match, and you only have to gives names to parts of the<br>
>> >> regular expression if you want the subexpressions.<br>
>> ><br>
>> ><br>
>> > Currently not, as you can always write .bind("x") very easily. What name<br>
>> > would you propose?<br>
>><br>
>> My desire was to not need any name, so that I could just call<br>
>> Result.Nodes.getNodeAs<T>() without any argument.<br>
>><br>
>> For the situation that prompted my question see<br>
>> <a href="http://llvm-reviews.chandlerc.com/D72" target="_blank">http://llvm-reviews.chandlerc.com/D72</a>. Always having access to the top<br>
>> node would avoid the need for the NodeVerifier class in that patch.<br>
><br>
><br>
> You'd still need a callback where you pull it out of the results, wouldn't<br>
> you?<br>
<br>
</div></div>Yes, but I wouldn't need to tell the callback what name to use, and<br>
the callback wouldn't need to check whether a node with that name was<br>
bound, because the topmost node would always be bound.<br>
</blockquote></div><br></div><div class="gmail_extra">If you don't do the bind into the test code, but sink it into where you take the matcher (and make that the same class that does the verification, perhaps using an inner class), you can have the bind("id") call and the pulling out of the result into the same level of abstraction.</div>
<div class="gmail_extra"><br></div><div class="gmail_extra">Even with a default binding, you'd still need to check that the node is there, as the types might not match, right?</div><div class="gmail_extra"><br></div><div class="gmail_extra">
That said, I don't have a big problem with adding .bind("") to all addMatcher calls in the ASTMatchFinder; I don't see how it would interfere with anything - patch welcome :)</div><div class="gmail_extra">
<br></div><div class="gmail_extra">Cheers,</div><div class="gmail_extra">/Manuel</div><div class="gmail_extra"><br></div>