From 2da528eb69913ee40c837120d779bab5efcdb655 Mon Sep 17 00:00:00 2001 From: Chris Bieneman Date: Mon, 30 Sep 2024 19:12:15 -0500 Subject: [PATCH 1/3] Start working on HLSL initialization lists This one is a bit gnarly because it involves a lot of depth-first traversing of declarations, types, and initialization expresssions. Questions and suggestions on how to clarify are greatly appreciated! --- specs/language/declarations.tex | 59 +++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/specs/language/declarations.tex b/specs/language/declarations.tex index 67b62680..edb431e1 100644 --- a/specs/language/declarations.tex +++ b/specs/language/declarations.tex @@ -46,6 +46,65 @@ \Sec{Declarators}{Decl.Decl} \Sec{Initializers}{Decl.Init} + +\p The process of initialization described in this section applies to all +initializers regardless of the context. + +\begin{grammar} + \define{initializer}\br + brace-or-equal-initializer\br + \terminal{(} expression-list \terminal{)}\br + + \define{brace-or-equal-initializer}\br + \terminal{=} initializer-clause\br + braced-init-list\br + + \define{initializer-clause}\br + assignment-expression\br + braced-init-list\br + + \define{braced-init-list}\br + \terminal{\{} initializer-list \opt{\terminal{,}} \terminal{\}}\br + \terminal{\{} \terminal{\}}\br + + \define{initializer-list}\br + initializer-clause\br + initializer-list \terminal{,} initializer-clause\br +\end{grammar} + +\Sub{Aggregate Initialization}{Decl.Init.Agg} + +\p An \textit{aggregate} is a vector, matrix, array, or class. + +\p The subobjects of an aggregate have a defined order. For vectors and arrays +the order is increasing subscript order. For matrices it is increasing subscript +order with the with the subscript nesting such that in the notation +\texttt{Mat[M][N]}, the ordering is \(Mat[0][0]...Mat[0][N]... +Mat[M][0]...Mat[M][N]\). For classes the order is base class, followed by member +subobjects in declaration order. + +\p A \textit{flattened ordering} of subobjects can be produced by performing a +depth-first traversal of the subobjects of an object following the defined +subobject ordering. + +\p Each \textit{initializer-list} is comprised of zero or more +\textit{initializer-clause} expressions, which in turn may be another +initializer-list or an \textit{assignment-expression}. Each +assignment-expression is an object, which may be a scalar or aggregate type. A +\textit{flattened initializer sequence} is constructed by a depth-first +traversal over each assignment-expression in an initializer-list and performing +a depth-first traversal accessing each subobject of the assignment-expression. + +\p An initializer-list is a valid initializer if for each element \(E_n\) in the +target object's flattened ordering there is a corresponding initializer \(I_n\) +in the flattened initializer sequence which can be implicitly converted to the +element's type. + +\p An initializer-list is invalid if the flattened initializer sequence contains +less elements than the target object's flattened ordering, or if any initializer +\(I_n\) cannot be implicitly converted to the corresponding element \(E_n\)'s +type. + \Sec{Function Definitions}{Decl.Function} \Sec{Attributes}{Decl.Attr} \Sub{Semantic Annotations}{Decl.Attr.Semantic} From 6752f4343d979427f0e3b72560c027b7a66e9cc0 Mon Sep 17 00:00:00 2001 From: Chris B Date: Fri, 4 Oct 2024 15:10:03 -0500 Subject: [PATCH 2/3] Update specs/language/declarations.tex Co-authored-by: Greg Roth --- specs/language/declarations.tex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/specs/language/declarations.tex b/specs/language/declarations.tex index edb431e1..759d265a 100644 --- a/specs/language/declarations.tex +++ b/specs/language/declarations.tex @@ -78,7 +78,7 @@ \p The subobjects of an aggregate have a defined order. For vectors and arrays the order is increasing subscript order. For matrices it is increasing subscript -order with the with the subscript nesting such that in the notation +order with the subscript nesting such that in the notation \texttt{Mat[M][N]}, the ordering is \(Mat[0][0]...Mat[0][N]... Mat[M][0]...Mat[M][N]\). For classes the order is base class, followed by member subobjects in declaration order. From 6bfa2c3b9c259f66c0bae8cafba45274bc719778 Mon Sep 17 00:00:00 2001 From: Chris Bieneman Date: Thu, 17 Oct 2024 10:54:06 -0500 Subject: [PATCH 3/3] Updates based on PR feedback. --- specs/language/declarations.tex | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/specs/language/declarations.tex b/specs/language/declarations.tex index 759d265a..3431b03b 100644 --- a/specs/language/declarations.tex +++ b/specs/language/declarations.tex @@ -87,7 +87,7 @@ depth-first traversal of the subobjects of an object following the defined subobject ordering. -\p Each \textit{initializer-list} is comprised of zero or more +\p Each \textit{braced initializer list} is comprised of zero or more \textit{initializer-clause} expressions, which in turn may be another initializer-list or an \textit{assignment-expression}. Each assignment-expression is an object, which may be a scalar or aggregate type. A @@ -101,9 +101,9 @@ element's type. \p An initializer-list is invalid if the flattened initializer sequence contains -less elements than the target object's flattened ordering, or if any initializer -\(I_n\) cannot be implicitly converted to the corresponding element \(E_n\)'s -type. +more or fewer elements than the target object's flattened ordering, or if any +initializer \(I_n\) cannot be implicitly converted to the corresponding element +\(E_n\)'s type. \Sec{Function Definitions}{Decl.Function} \Sec{Attributes}{Decl.Attr}