[cfe-dev] A question on initListExpr() matcher

Manuel Klimek via cfe-dev cfe-dev at lists.llvm.org
Tue Nov 22 23:34:02 PST 2016


Adding Richard,

this is indeed a good question.
Looking at the dumps, it seems like match 2-4 have InitListExpr nodes that
do not show up in the larger InitListExpr.
Richard, is that intentional in the AST?

clang-query> set output dump
clang-query> m initListExpr()

Match #1:

Binding for "root":
InitListExpr 0x7f351d96d558 </tmp/t.cc:3:27, col:50> 'int [3][2]'
|-InitListExpr 0x7f351d96d5b0 <col:28, col:33> 'int [2]'
| |-IntegerLiteral 0x7f351d96d350 <col:29> 'int' 2
| `-IntegerLiteral 0x7f351d96d370 <col:32> 'int' 3
|-InitListExpr 0x7f351d96d600 <col:36, col:41> 'int [2]'
| |-IntegerLiteral 0x7f351d96d3e0 <col:37> 'int' 4
| `-IntegerLiteral 0x7f351d96d400 <col:40> 'int' 5
`-InitListExpr 0x7f351d96d650 <col:44, col:49> 'int [2]'
  |-IntegerLiteral 0x7f351d96d470 <col:45> 'int' 6
  `-IntegerLiteral 0x7f351d96d490 <col:48> 'int' 7


Match #2:

Binding for "root":
InitListExpr 0x7f351d96d390 </tmp/t.cc:3:28, col:33> 'int [2]'
|-IntegerLiteral 0x7f351d96d350 <col:29> 'int' 2
`-IntegerLiteral 0x7f351d96d370 <col:32> 'int' 3


Match #3:

Binding for "root":
InitListExpr 0x7f351d96d420 </tmp/t.cc:3:36, col:41> 'int [2]'
|-IntegerLiteral 0x7f351d96d3e0 <col:37> 'int' 4
`-IntegerLiteral 0x7f351d96d400 <col:40> 'int' 5


Match #4:

Binding for "root":
InitListExpr 0x7f351d96d4b0 </tmp/t.cc:3:44, col:49> 'int [2]'
|-IntegerLiteral 0x7f351d96d470 <col:45> 'int' 6
`-IntegerLiteral 0x7f351d96d490 <col:48> 'int' 7


Match #5:

Binding for "root":
InitListExpr 0x7f351d96d5b0 </tmp/t.cc:3:28, col:33> 'int [2]'
|-IntegerLiteral 0x7f351d96d350 <col:29> 'int' 2
`-IntegerLiteral 0x7f351d96d370 <col:32> 'int' 3


Match #6:

Binding for "root":
InitListExpr 0x7f351d96d600 </tmp/t.cc:3:36, col:41> 'int [2]'
|-IntegerLiteral 0x7f351d96d3e0 <col:37> 'int' 4
`-IntegerLiteral 0x7f351d96d400 <col:40> 'int' 5


Match #7:

Binding for "root":
InitListExpr 0x7f351d96d650 </tmp/t.cc:3:44, col:49> 'int [2]'
|-IntegerLiteral 0x7f351d96d470 <col:45> 'int' 6
`-IntegerLiteral 0x7f351d96d490 <col:48> 'int' 7


On Tue, Nov 22, 2016 at 11:52 PM Farzad Sadeghi via cfe-dev <
cfe-dev at lists.llvm.org> wrote:

> Given the code provided below, why do i match each inner InitListExpr
> twice?
> Here's the sample code:
> void test14 (void)
> {
>         int arr[3][2] = {{2, 3}, {4, 5}, {6, 7}};
> }
> This is the AST:
> `-FunctionDecl 0x59c09b0 <line:792:1, line:806:1> line:792:6 test14
> 'void (void)'
>   `-CompoundStmt 0x59c2768 <line:793:1, line:806:1>
>     |-DeclStmt 0x59c2330 <line:794:2, col:42>
>     | `-VarDecl 0x59c1f80 <col:2, col:41> col:6 arr 'int [3][2]' cinit
>     |   `-InitListExpr 0x59c21e8 <col:18, col:41> 'int [3][2]'
>     |     |-InitListExpr 0x59c2240 <col:19, col:24> 'int [2]'
>     |     | |-IntegerLiteral 0x59c1fe0 <col:20> 'int' 2
>     |     | `-IntegerLiteral 0x59c2000 <col:23> 'int' 3
>     |     |-InitListExpr 0x59c2290 <col:27, col:32> 'int [2]'
>     |     | |-IntegerLiteral 0x59c2070 <col:28> 'int' 4
>     |     | `-IntegerLiteral 0x59c2090 <col:31> 'int' 5
>     |     `-InitListExpr 0x59c22e0 <col:35, col:40> 'int [2]'
>     |       |-IntegerLiteral 0x59c2100 <col:36> 'int' 6
>     |       `-IntegerLiteral 0x59c2120 <col:39> 'int' 7
> This is the matcher im running on clang-query:
> match initListExpr()
> And this is the result i get:
> Match #1:
>
> /home/bloodstalker/devi/hell2/test/testFuncs1.c:794:18: note: "root" binds
> here
>         int arr[3][2] = {{2, 3}, {4, 5}, {6, 7}};
>                         ^~~~~~~~~~~~~~~~~~~~~~~~
>
> Match #2:
>
> /home/bloodstalker/devi/hell2/test/testFuncs1.c:794:19: note: "root" binds
> here
>         int arr[3][2] = {{2, 3}, {4, 5}, {6, 7}};
>                          ^~~~~~
>
> Match #3:
>
> /home/bloodstalker/devi/hell2/test/testFuncs1.c:794:27: note: "root" binds
> here
>         int arr[3][2] = {{2, 3}, {4, 5}, {6, 7}};
>                                  ^~~~~~
>
> Match #4:
>
> /home/bloodstalker/devi/hell2/test/testFuncs1.c:794:35: note: "root" binds
> here
>         int arr[3][2] = {{2, 3}, {4, 5}, {6, 7}};
>                                          ^~~~~~
>
> Match #5:
>
> /home/bloodstalker/devi/hell2/test/testFuncs1.c:794:19: note: "root" binds
> here
>         int arr[3][2] = {{2, 3}, {4, 5}, {6, 7}};
>                          ^~~~~~
>
> Match #6:
>
> /home/bloodstalker/devi/hell2/test/testFuncs1.c:794:27: note: "root" binds
> here
>         int arr[3][2] = {{2, 3}, {4, 5}, {6, 7}};
>                                  ^~~~~~
>
> Match #7:
>
> /home/bloodstalker/devi/hell2/test/testFuncs1.c:794:35: note: "root" binds
> here
>         int arr[3][2] = {{2, 3}, {4, 5}, {6, 7}};
>                                          ^~~~~~
>
>
> --
> Farzad Sadeghi
> _______________________________________________
> 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/20161123/22fe9c35/attachment.html>


More information about the cfe-dev mailing list