[PATCH] D128687: [pseudo] Allow mixed designated/undesignated init lists.
Sam McCall via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 28 06:46:22 PDT 2022
This revision was automatically updated to reflect the committed changes.
sammccall marked an inline comment as done.
Closed by commit rG8cf28585a403: [pseudo] Allow mixed designated/undesignated init lists. (authored by sammccall).
Changed prior to commit:
https://reviews.llvm.org/D128687?vs=440426&id=440599#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D128687/new/
https://reviews.llvm.org/D128687
Files:
clang-tools-extra/pseudo/lib/cxx.bnf
clang-tools-extra/pseudo/test/cxx/mixed-designator.cpp
Index: clang-tools-extra/pseudo/test/cxx/mixed-designator.cpp
===================================================================
--- /dev/null
+++ clang-tools-extra/pseudo/test/cxx/mixed-designator.cpp
@@ -0,0 +1,27 @@
+// RUN: clang-pseudo -grammar=%cxx-bnf-file -source=%s --print-forest | FileCheck %s
+// FIXME: tighten CHECK to CHECK-NEXT once numeric literals are unambiguous.
+auto x = { 1, .f = 2, [c]{3} };
+// CHECK: initializer-clause~braced-init-list
+// CHECK-NEXT: ├─{ := tok[3]
+// CHECK-NEXT: ├─initializer-list
+// CHECK-NEXT: │ ├─initializer-list
+// CHECK-NEXT: │ │ ├─initializer-list~literal
+// CHECK: │ │ ├─, := tok[5]
+// CHECK-NEXT: │ │ └─initializer-list-item
+// CHECK-NEXT: │ │ ├─designator
+// CHECK-NEXT: │ │ │ ├─. := tok[6]
+// CHECK-NEXT: │ │ │ └─IDENTIFIER := tok[7]
+// CHECK-NEXT: │ │ └─brace-or-equal-initializer
+// CHECK-NEXT: │ │ ├─= := tok[8]
+// CHECK-NEXT: │ │ └─initializer-clause~literal
+// CHECK: │ ├─, := tok[10]
+// CHECK-NEXT: │ └─initializer-list-item
+// CHECK-NEXT: │ ├─designator
+// CHECK-NEXT: │ │ ├─[ := tok[11]
+// CHECK-NEXT: │ │ ├─expression~IDENTIFIER := tok[12]
+// CHECK-NEXT: │ │ └─] := tok[13]
+// CHECK-NEXT: │ └─brace-or-equal-initializer~braced-init-list
+// CHECK-NEXT: │ ├─{ := tok[14]
+// CHECK-NEXT: │ ├─initializer-list~literal
+// CHECK: │ └─} := tok[16]
+// CHECK-NEXT: └─} := tok[17]
Index: clang-tools-extra/pseudo/lib/cxx.bnf
===================================================================
--- clang-tools-extra/pseudo/lib/cxx.bnf
+++ clang-tools-extra/pseudo/lib/cxx.bnf
@@ -158,7 +158,10 @@
postfix-expression := CONST_CAST < type-id > ( expression )
postfix-expression := TYPEID ( expression )
postfix-expression := TYPEID ( type-id )
-expression-list := initializer-list
+#! Standard defines expression-list in terms of initializer-list, but our
+# initializer-list allows designators.
+expression-list := initializer-clause ..._opt
+expression-list := expression-list , initializer-clause ..._opt
# expr.unary
unary-expression := postfix-expression
unary-expression := unary-operator cast-expression
@@ -453,15 +456,17 @@
brace-or-equal-initializer := braced-init-list
initializer-clause := assignment-expression
initializer-clause := braced-init-list
+#! Allow mixed designated/non-designated init-list.
+# This is standard C, and accepted by clang and others as an extension.
braced-init-list := { initializer-list ,_opt }
-braced-init-list := { designated-initializer-list ,_opt }
braced-init-list := { }
-initializer-list := initializer-clause ..._opt
-initializer-list := initializer-list , initializer-clause ..._opt
-designated-initializer-list := designated-initializer-clause
-designated-initializer-list := designated-initializer-list , designated-initializer-clause
-designated-initializer-clause := designator brace-or-equal-initializer
+initializer-list := initializer-list-item ..._opt
+initializer-list := initializer-list , initializer-list-item ..._opt
+initializer-list-item := initializer-clause
+initializer-list-item := designator brace-or-equal-initializer
designator := . IDENTIFIER
+#! Array designators are legal in C, and a common extension in C++.
+designator := [ expression ]
expr-or-braced-init-list := expression
expr-or-braced-init-list := braced-init-list
# dcl.fct
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D128687.440599.patch
Type: text/x-patch
Size: 3519 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220628/3b8f8d31/attachment.bin>
More information about the cfe-commits
mailing list