<div dir="ltr">Adding Richard,<div><br></div><div>this is indeed a good question.</div><div>Looking at the dumps, it seems like match 2-4 have InitListExpr nodes that do not show up in the larger InitListExpr.</div><div>Richard, is that intentional in the AST?</div><div><br></div><div>clang-query> set output dump</div><div><div>clang-query> m initListExpr()</div><div><br></div><div><font face="monospace">Match #1:</font></div><div><font face="monospace"><br></font></div><div><font face="monospace">Binding for "root":</font></div><div><font face="monospace">InitListExpr 0x7f351d96d558 </tmp/t.cc:3:27, col:50> 'int [3][2]'</font></div><div><font face="monospace">|-InitListExpr 0x7f351d96d5b0 <col:28, col:33> 'int [2]'</font></div><div><font face="monospace">| |-IntegerLiteral 0x7f351d96d350 <col:29> 'int' 2</font></div><div><font face="monospace">| `-IntegerLiteral 0x7f351d96d370 <col:32> 'int' 3</font></div><div><font face="monospace">|-InitListExpr 0x7f351d96d600 <col:36, col:41> 'int [2]'</font></div><div><font face="monospace">| |-IntegerLiteral 0x7f351d96d3e0 <col:37> 'int' 4</font></div><div><font face="monospace">| `-IntegerLiteral 0x7f351d96d400 <col:40> 'int' 5</font></div><div><font face="monospace">`-InitListExpr 0x7f351d96d650 <col:44, col:49> 'int [2]'</font></div><div><font face="monospace"> |-IntegerLiteral 0x7f351d96d470 <col:45> 'int' 6</font></div><div><font face="monospace"> `-IntegerLiteral 0x7f351d96d490 <col:48> 'int' 7</font></div><div><font face="monospace"><br></font></div><div><font face="monospace"><br></font></div><div><font face="monospace">Match #2:</font></div><div><font face="monospace"><br></font></div><div><font face="monospace">Binding for "root":</font></div><div><font face="monospace">InitListExpr 0x7f351d96d390 </tmp/t.cc:3:28, col:33> 'int [2]'</font></div><div><font face="monospace">|-IntegerLiteral 0x7f351d96d350 <col:29> 'int' 2</font></div><div><font face="monospace">`-IntegerLiteral 0x7f351d96d370 <col:32> 'int' 3</font></div><div><font face="monospace"><br></font></div><div><font face="monospace"><br></font></div><div><font face="monospace">Match #3:</font></div><div><font face="monospace"><br></font></div><div><font face="monospace">Binding for "root":</font></div><div><font face="monospace">InitListExpr 0x7f351d96d420 </tmp/t.cc:3:36, col:41> 'int [2]'</font></div><div><font face="monospace">|-IntegerLiteral 0x7f351d96d3e0 <col:37> 'int' 4</font></div><div><font face="monospace">`-IntegerLiteral 0x7f351d96d400 <col:40> 'int' 5</font></div><div><font face="monospace"><br></font></div><div><font face="monospace"><br></font></div><div><font face="monospace">Match #4:</font></div><div><font face="monospace"><br></font></div><div><font face="monospace">Binding for "root":</font></div><div><font face="monospace">InitListExpr 0x7f351d96d4b0 </tmp/t.cc:3:44, col:49> 'int [2]'</font></div><div><font face="monospace">|-IntegerLiteral 0x7f351d96d470 <col:45> 'int' 6</font></div><div><font face="monospace">`-IntegerLiteral 0x7f351d96d490 <col:48> 'int' 7</font></div><div><font face="monospace"><br></font></div><div><font face="monospace"><br></font></div><div><font face="monospace">Match #5:</font></div><div><font face="monospace"><br></font></div><div><font face="monospace">Binding for "root":</font></div><div><font face="monospace">InitListExpr 0x7f351d96d5b0 </tmp/t.cc:3:28, col:33> 'int [2]'</font></div><div><font face="monospace">|-IntegerLiteral 0x7f351d96d350 <col:29> 'int' 2</font></div><div><font face="monospace">`-IntegerLiteral 0x7f351d96d370 <col:32> 'int' 3</font></div><div><font face="monospace"><br></font></div><div><font face="monospace"><br></font></div><div><font face="monospace">Match #6:</font></div><div><font face="monospace"><br></font></div><div><font face="monospace">Binding for "root":</font></div><div><font face="monospace">InitListExpr 0x7f351d96d600 </tmp/t.cc:3:36, col:41> 'int [2]'</font></div><div><font face="monospace">|-IntegerLiteral 0x7f351d96d3e0 <col:37> 'int' 4</font></div><div><font face="monospace">`-IntegerLiteral 0x7f351d96d400 <col:40> 'int' 5</font></div><div><font face="monospace"><br></font></div><div><font face="monospace"><br></font></div><div><font face="monospace">Match #7:</font></div><div><font face="monospace"><br></font></div><div><font face="monospace">Binding for "root":</font></div><div><font face="monospace">InitListExpr 0x7f351d96d650 </tmp/t.cc:3:44, col:49> 'int [2]'</font></div><div><font face="monospace">|-IntegerLiteral 0x7f351d96d470 <col:45> 'int' 6</font></div><div><font face="monospace">`-IntegerLiteral 0x7f351d96d490 <col:48> 'int' 7</font></div><div><font face="monospace"><br></font></div><br><div class="gmail_quote"><div dir="ltr">On Tue, Nov 22, 2016 at 11:52 PM Farzad Sadeghi 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">Given the code provided below, why do i match each inner InitListExpr twice?<br class="gmail_msg">
Here's the sample code:<br class="gmail_msg">
void test14 (void)<br class="gmail_msg">
{<br class="gmail_msg">
int arr[3][2] = {{2, 3}, {4, 5}, {6, 7}};<br class="gmail_msg">
}<br class="gmail_msg">
This is the AST:<br class="gmail_msg">
`-FunctionDecl 0x59c09b0 <line:792:1, line:806:1> line:792:6 test14<br class="gmail_msg">
'void (void)'<br class="gmail_msg">
`-CompoundStmt 0x59c2768 <line:793:1, line:806:1><br class="gmail_msg">
|-DeclStmt 0x59c2330 <line:794:2, col:42><br class="gmail_msg">
| `-VarDecl 0x59c1f80 <col:2, col:41> col:6 arr 'int [3][2]' cinit<br class="gmail_msg">
| `-InitListExpr 0x59c21e8 <col:18, col:41> 'int [3][2]'<br class="gmail_msg">
| |-InitListExpr 0x59c2240 <col:19, col:24> 'int [2]'<br class="gmail_msg">
| | |-IntegerLiteral 0x59c1fe0 <col:20> 'int' 2<br class="gmail_msg">
| | `-IntegerLiteral 0x59c2000 <col:23> 'int' 3<br class="gmail_msg">
| |-InitListExpr 0x59c2290 <col:27, col:32> 'int [2]'<br class="gmail_msg">
| | |-IntegerLiteral 0x59c2070 <col:28> 'int' 4<br class="gmail_msg">
| | `-IntegerLiteral 0x59c2090 <col:31> 'int' 5<br class="gmail_msg">
| `-InitListExpr 0x59c22e0 <col:35, col:40> 'int [2]'<br class="gmail_msg">
| |-IntegerLiteral 0x59c2100 <col:36> 'int' 6<br class="gmail_msg">
| `-IntegerLiteral 0x59c2120 <col:39> 'int' 7<br class="gmail_msg">
This is the matcher im running on clang-query:<br class="gmail_msg">
match initListExpr()<br class="gmail_msg">
And this is the result i get:<br class="gmail_msg">
Match #1:<br class="gmail_msg">
<br class="gmail_msg">
/home/bloodstalker/devi/hell2/test/testFuncs1.c:794:18: note: "root" binds here<br class="gmail_msg">
int arr[3][2] = {{2, 3}, {4, 5}, {6, 7}};<br class="gmail_msg">
^~~~~~~~~~~~~~~~~~~~~~~~<br class="gmail_msg">
<br class="gmail_msg">
Match #2:<br class="gmail_msg">
<br class="gmail_msg">
/home/bloodstalker/devi/hell2/test/testFuncs1.c:794:19: note: "root" binds here<br class="gmail_msg">
int arr[3][2] = {{2, 3}, {4, 5}, {6, 7}};<br class="gmail_msg">
^~~~~~<br class="gmail_msg">
<br class="gmail_msg">
Match #3:<br class="gmail_msg">
<br class="gmail_msg">
/home/bloodstalker/devi/hell2/test/testFuncs1.c:794:27: note: "root" binds here<br class="gmail_msg">
int arr[3][2] = {{2, 3}, {4, 5}, {6, 7}};<br class="gmail_msg">
^~~~~~<br class="gmail_msg">
<br class="gmail_msg">
Match #4:<br class="gmail_msg">
<br class="gmail_msg">
/home/bloodstalker/devi/hell2/test/testFuncs1.c:794:35: note: "root" binds here<br class="gmail_msg">
int arr[3][2] = {{2, 3}, {4, 5}, {6, 7}};<br class="gmail_msg">
^~~~~~<br class="gmail_msg">
<br class="gmail_msg">
Match #5:<br class="gmail_msg">
<br class="gmail_msg">
/home/bloodstalker/devi/hell2/test/testFuncs1.c:794:19: note: "root" binds here<br class="gmail_msg">
int arr[3][2] = {{2, 3}, {4, 5}, {6, 7}};<br class="gmail_msg">
^~~~~~<br class="gmail_msg">
<br class="gmail_msg">
Match #6:<br class="gmail_msg">
<br class="gmail_msg">
/home/bloodstalker/devi/hell2/test/testFuncs1.c:794:27: note: "root" binds here<br class="gmail_msg">
int arr[3][2] = {{2, 3}, {4, 5}, {6, 7}};<br class="gmail_msg">
^~~~~~<br class="gmail_msg">
<br class="gmail_msg">
Match #7:<br class="gmail_msg">
<br class="gmail_msg">
/home/bloodstalker/devi/hell2/test/testFuncs1.c:794:35: note: "root" binds here<br class="gmail_msg">
int arr[3][2] = {{2, 3}, {4, 5}, {6, 7}};<br class="gmail_msg">
^~~~~~<br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
--<br class="gmail_msg">
Farzad Sadeghi<br class="gmail_msg">
_______________________________________________<br class="gmail_msg">
cfe-dev mailing list<br class="gmail_msg">
<a href="mailto:cfe-dev@lists.llvm.org" class="gmail_msg" target="_blank">cfe-dev@lists.llvm.org</a><br class="gmail_msg">
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" class="gmail_msg" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br class="gmail_msg">
</blockquote></div></div></div>