Skip to content

Commit

Permalink
Start working on HLSL initialization lists (#329)
Browse files Browse the repository at this point in the history
* 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 expressions.

Questions and suggestions on how to clarify are greatly appreciated!

Co-authored-by: Greg Roth <[email protected]>
  • Loading branch information
llvm-beanz and pow2clk authored Dec 13, 2024
1 parent 79140e3 commit 9a01d0c
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions specs/language/declarations.tex
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,66 @@

\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 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{braced initializer list} is comprised of zero or more
\textit{initializer-clause} expressions, which is either another braced
initializer list or an expression which generates a value that either is or can
be implicitly converted to an rvalue. 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
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}
\Sub{Semantic Annotations}{Decl.Attr.Semantic}
Expand Down

0 comments on commit 9a01d0c

Please sign in to comment.