[cfe-dev] hasAncestor matching nothing

Manuel Klimek via cfe-dev cfe-dev at lists.llvm.org
Fri Nov 25 00:41:21 PST 2016


which declRefExpr do you expect to be a child of which other declRefExpr?

On Fri, Nov 25, 2016 at 9:40 AM Farzad Sadeghi <thabogre at gmail.com> wrote:

> thank you for the explanation. I do realize that, but that is clearly
> not the case here.
>
> On 11/25/16, Manuel Klimek <klimek at google.com> wrote:
> > On Fri, Nov 25, 2016 at 9:24 AM Farzad Sadeghi via cfe-dev <
> > cfe-dev at lists.llvm.org> wrote:
> >
> >> for the source code below:
> >> short int test16(int a, int b)
> >> {
> >>         short int sum;
> >>         short unsigned int sumus;
> >>         sum = a + b;
> >>         sumus = a + b;
> >>
> >>         return sum;
> >> }
> >> with AST:
> >> |-FunctionDecl 0x4e52920 <line:821:1, line:829:1> line:821:11 test16
> >> 'short (int, int)'
> >> | |-ParmVarDecl 0x4e527d8 <col:18, col:22> col:22 used a 'int'
> >> | |-ParmVarDecl 0x4e52848 <col:25, col:29> col:29 used b 'int'
> >> | `-CompoundStmt 0x4e52d60 <line:822:1, line:829:1>
> >> |   |-DeclStmt 0x4e52a48 <line:823:2, col:15>
> >> |   | `-VarDecl 0x4e529e8 <col:2, col:12> col:12 used sum 'short'
> >> |   |-DeclStmt 0x4e52ad0 <line:824:2, col:26>
> >> |   | `-VarDecl 0x4e52a70 <col:2, col:21> col:21 used sumus 'unsigned
> >> short'
> >> |   |-BinaryOperator 0x4e52bd0 <line:825:2, col:12> 'short' '='
> >> |   | |-DeclRefExpr 0x4e52ae8 <col:2> 'short' lvalue Var 0x4e529e8 'sum'
> >> 'short'
> >> |   | `-ImplicitCastExpr 0x4e52bb8 <col:8, col:12> 'short'
> <IntegralCast>
> >> |   |   `-BinaryOperator 0x4e52b90 <col:8, col:12> 'int' '+'
> >> |   |     |-ImplicitCastExpr 0x4e52b60 <col:8> 'int' <LValueToRValue>
> >> |   |     | `-DeclRefExpr 0x4e52b10 <col:8> 'int' lvalue ParmVar
> >> 0x4e527d8 'a' 'int'
> >> |   |     `-ImplicitCastExpr 0x4e52b78 <col:12> 'int' <LValueToRValue>
> >> |   |       `-DeclRefExpr 0x4e52b38 <col:12> 'int' lvalue ParmVar
> >> 0x4e52848 'b' 'int'
> >> |   |-BinaryOperator 0x4e52ce0 <line:826:2, col:14> 'unsigned short' '='
> >> |   | |-DeclRefExpr 0x4e52bf8 <col:2> 'unsigned short' lvalue Var
> >> 0x4e52a70 'sumus' 'unsigned short'
> >> |   | `-ImplicitCastExpr 0x4e52cc8 <col:10, col:14> 'unsigned short'
> >> <IntegralCast>
> >> |   |   `-BinaryOperator 0x4e52ca0 <col:10, col:14> 'int' '+'
> >> |   |     |-ImplicitCastExpr 0x4e52c70 <col:10> 'int' <LValueToRValue>
> >> |   |     | `-DeclRefExpr 0x4e52c20 <col:10> 'int' lvalue ParmVar
> >> 0x4e527d8 'a' 'int'
> >> |   |     `-ImplicitCastExpr 0x4e52c88 <col:14> 'int' <LValueToRValue>
> >> |   |       `-DeclRefExpr 0x4e52c48 <col:14> 'int' lvalue ParmVar
> >> 0x4e52848 'b' 'int'
> >> |   `-ReturnStmt 0x4e52d48 <line:828:2, col:9>
> >> |     `-ImplicitCastExpr 0x4e52d30 <col:9> 'short' <LValueToRValue>
> >> |       `-DeclRefExpr 0x4e52d08 <col:9> 'short' lvalue Var 0x4e529e8
> >> 'sum' 'short'
> >> when i run the below matcher on clang-query:
> >> match declRefExpr(hasAncestor(declRefExpr()))
> >> i get no matches, while in the AST it clearly says that there are such
> >
> > nodes. so I was wondering what could be causing this.
> >>
> >
> > Perhaps we can make the printing easier to read here:
> > -a
> > ||-b
> > |`-c
> > does not mean that c is a child of b, it means (if I'm not mistaken)
> that c
> > is the last child of a, but both b and a are equally children of a.
> >
> >
> >> --
> >> Farzad Sadeghi
> >> _______________________________________________
> >> cfe-dev mailing list
> >> cfe-dev at lists.llvm.org
> >> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
> >>
> >
>
>
> --
> Farzad Sadeghi
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20161125/2557b274/attachment.html>


More information about the cfe-dev mailing list