<div dir="auto"><div><br><br><div class="gmail_quote"><div dir="ltr">On Wed, 4 Jul 2018, 17:24 Michael Jabbour via cfe-dev, <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello all,<br>
<br>
I am new to clang and I am trying to write a check to familiarize myself<br>
with AST matchers. I am just looking for a confirmation here. When I<br>
bind a node within a hasAncestor() matcher, am I guaranteed to get the<br>
most direct (nearest) ancestor from the current node?<br>
<br>
Consider the following example:<br>
<br>
class MyClass {<br>
public:<br>
void myClassOp() { //<-- another parent CXXMemberDecl<br>
class NestedClass {<br>
void nestedClassOp() { //<-- parent CXXMemberDecl<br>
(void) this; //<-- CXXThisExpr<br>
}<br>
};<br>
}<br>
};<br>
<br>
I get the most direct ancestor (the desired behavior) when using a<br>
matcher like:<br>
<br>
cxxThisExpr(hasAncestor(cxxMethodDecl().bind("method"))).bind("this")<br>
<br>
My question is: Is this behavior always guaranteed? or am I just being<br>
lucky here?<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">It's guaranteed if there is a single line of ancestry, but keep in mind that nodes can have multiple parents :)</div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
<br>
Thanks,<br>
<br>
Mike<br>
<br>
<br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank" rel="noreferrer">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
</blockquote></div></div></div>