diff --git a/specs/language/expressions.tex b/specs/language/expressions.tex index 906944a0..12ff996e 100644 --- a/specs/language/expressions.tex +++ b/specs/language/expressions.tex @@ -153,6 +153,7 @@ typename-specifier braced-init-list\br postfix-expression \terminal{.} \opt{\terminal{template}} id-expression\br postfix-expression \terminal{.} vector-swizzle-component-sequence\br + postfix-expression \terminal{.} matrix-swizzle-component-sequence\br postfix-expression \terminal{++}\br postfix-expression \terminal{--} \end{grammar} @@ -173,7 +174,19 @@ elements in the vector, the program is ill-formed. If the value is outside the range at runtime, the behavior is undefined. -\Sec{Vector Swizzle}{Expr.Post.VectorSwizzle} +\Sec{Swizzle Expressions}{Expr.Post.Swizzle} +\p A \textit{postfix-expression} followed by a dot (\texttt{.}) and a sequence +of one or more \textit{swizzle components} is a postfix expression. The +postfix expression before the dot is evaluated and must be of vector or matrix type. +If the postfix expression before the dot is an lvalue, the swizzle expression may +produce either an lvalue or a prvalue; otherwise it produces a prvalue. + + +\p If the postfix expression before the dot is +an lvalue and the \textit{swizzle-component-sequence} contains no repeated +components, the swizzle expression is an lvalue; otherwise it is a prvalue. + +\Sub{Vector Swizzle}{Expr.Post.Swizzle.Vector} \begin{grammar} \define{vector-swizzle-component-sequence}\br @@ -195,23 +208,14 @@ \terminal{x y z w} \end{grammar} -\p A \textit{postfix-expression} followed by a dot (\texttt{.}) and a sequence -of one or more \textit{swizzle-components} is a postfix expression. The -postfix expression before the dot is evaluated and must be of vector type. If -the postfix expression before the dot is an lvalue, the swizzle expression may -produce either an lvalue or a prvalue; otherwise it produces a prvalue. - -\p A \textit{swizzle-component-sequence} is a sequence of one or more swizzle +\p A \textit{vector-swizzle-component-sequence} is a sequence of one or more swizzle components of either the \textit{swizzle-component-rgba} or \textit{swizzle-component-xyzw} forms; the two forms may not be mixed in the -same \textit{swizzle-component-sequence}. The type of a swizzle expression is a +same \textit{vector-swizzle-component-sequence}. The type of a swizzle expression is a vector of the same element type as the postfix expression before the dot, with a -number of elements equal to the number of components in the -\textit{swizzle-component-sequence}. If the postfix expression before the dot is -an lvalue and the \textit{swizzle-component-sequence} contains no repeated -components, the swizzle expression is an lvalue; otherwise it is a prvalue. +number of elements equal to the number of components in the \textit{vector-swizzle-component-sequence}. -\p Swizzle components map to elements of the vector in the following way: +\p Vector swizzle components map to elements of the vector in the following way: \begin{center} \begin{tabular}{|| c | c | c ||} @@ -230,6 +234,75 @@ refers to an element index that is out of range of the vector type of the postfix expression before the dot. +\Sub{Matrix Swizzle}{Expr.Post.Swizzle.Matrix} +\begin{grammar} + \define{matrix-swizzle-component-sequence}\br + matrix-zero-indexed-swizzle-sequence\br + matrix-one-indexed-swizzle-sequence\br + + \define{matrix-zero-indexed-swizzle-sequence}\br + matrix-zero-indexed-swizzle\br + matrix-zero-indexed-swizzle-sequence matrix-zero-indexed-swizzle\br + + \define{matrix-zero-indexed-swizzle}\br + \terminal{\_m} zero-index-value\br + + \define{zero-index-value} \textnormal{one of}\br + \terminal{0 1 2 3 }\br + + \define{matrix-one-indexed-swizzle-sequence}\br + matrix-one-indexed-swizzle\br + matrix-one-indexed-swizzle-sequence matrix-one-indexed-swizzle\br + + \define{matrix-one-indexed-swizzle}\br + \terminal{\_m} one-index-value\br + + \define{one-index-value} \textnormal{one of}\br + \terminal{1 2 3 4 }\br +\end{grammar} +\begin{itemize} +\item \textbf{.\_} (math-style): subsequent subscripts use \textbf{1-based} + indexing for both row and column. +\item \textbf{.\_m} (memory-style): subsequent subscripts use \textbf{0-based} + indexing for both row and column. +\end{itemize} + +\p A \textit{matrix-swizzle-component-sequence} is a sequence of one but less +than or equal to four swizzle components of either the +\textit{matrix-zero-indexed-swizzle} or \textit{matrix-one-indexed-swizzle} +forms; the two forms may not be mixed in the same +\textit{matrix-swizzle-component-sequence}. The type of a swizzle expression is +a vector of the same element type as the postfix expression before the dot, +with a number of elements equal to the number of components in the +\textit{matrix-swizzle-component-sequence}. + +\p Matrix swizzle components map to elements of the matrix in the following way: + +\begin{center} + \begin{tabular}{|| c | c | c ||} + \hline + Element Index & 0 indexed component & 1 indexed component \\ + \hline + 0,0 & \_m00 & \_11 \\ + 0,1 & \_m01 & \_12 \\ + 0,2 & \_m02 & \_13 \\ + 0,3 & \_m03 & \_14 \\ + 1,0 & \_m10 & \_21 \\ + 1,1 & \_m11 & \_22 \\ + 1,2 & \_m12 & \_23 \\ + 1,3 & \_m13 & \_24 \\ + 2,0 & \_m20 & \_31 \\ + 2,1 & \_m21 & \_32 \\ + 2,2 & \_m22 & \_33 \\ + 2,3 & \_m23 & \_34 \\ + 3,0 & \_m30 & \_41 \\ + 3,1 & \_m31 & \_42 \\ + 3,2 & \_m32 & \_43 \\ + 3,3 & \_m33 & \_44 \\ + \hline + \end{tabular} +\end{center} + \Sec{Function Calls}{Expr.Post.Call} \p A function call may be an \textit{ordinary function}, or a \textit{member