[cfe-dev] hasAncestor() hasDescendant() matchers scope
Manuel Klimek via cfe-dev
cfe-dev at lists.llvm.org
Fri Jul 6 01:04:52 PDT 2018
On Wed, 4 Jul 2018, 17:24 Michael Jabbour via cfe-dev, <
cfe-dev at lists.llvm.org> wrote:
> Hello all,
>
> I am new to clang and I am trying to write a check to familiarize myself
> with AST matchers. I am just looking for a confirmation here. When I
> bind a node within a hasAncestor() matcher, am I guaranteed to get the
> most direct (nearest) ancestor from the current node?
>
> Consider the following example:
>
> class MyClass {
> public:
> void myClassOp() { //<-- another parent CXXMemberDecl
> class NestedClass {
> void nestedClassOp() { //<-- parent CXXMemberDecl
> (void) this; //<-- CXXThisExpr
> }
> };
> }
> };
>
> I get the most direct ancestor (the desired behavior) when using a
> matcher like:
>
> cxxThisExpr(hasAncestor(cxxMethodDecl().bind("method"))).bind("this")
>
> My question is: Is this behavior always guaranteed? or am I just being
> lucky here?
>
It's guaranteed if there is a single line of ancestry, but keep in mind
that nodes can have multiple parents :)
>
> Thanks,
>
> Mike
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20180706/f79870fd/attachment.html>
More information about the cfe-dev
mailing list