Skip to content

Commit

Permalink
[Expr] Add Expr.Post.Subscript (microsoft#139)
Browse files Browse the repository at this point in the history
This adds definitions for HLSL array subscripting. HLSL deviates from
C/C++ in part because of the lack of pointers.
  • Loading branch information
llvm-beanz authored Dec 13, 2023
1 parent 1315feb commit e64a254
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
27 changes: 27 additions & 0 deletions specs/language/expressions.tex
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,30 @@
nested-name-specifier \opt{\keyword{template}} simple-template-id \terminal{::}
\end{grammar}

\Sec{Postfix Expressions}{Expr.Post}

\begin{grammar}
\define{postfix-expression}\br
primary-expression\br
postfix-expression \terminal{[} expression \terminal{]}\br
postfix-expression \terminal{[} braced-init-list \terminal{]}\br
postfix-expression \terminal{(} \opt{expression-list} \terminal{)}\br
simple-type-specifier \terminal{(} \opt{expression-list} \terminal{)}\br
typename-specifier \terminal{(} \opt{expression} \terminal{)}\br
simple-type-specifier braced-init-list\br
typename-specifier braced-init-list\br
postfix-expression \terminal{.} \opt{\terminal{template}} id-expression\br
postfix-expression \terminal{->} \opt{\terminal{template}} id-expression\br
postfix-expression \terminal{++}\br
postfix-expression \terminal{--}
\end{grammar}

\Sec{Subscript}{Expr.Post.Subscript}

\p A \textit{postfix-expression} followed by an expression in square brackets
(\texttt{[ ]}) is a subscript expression. In an array subscript expression of
the form \texttt{E1[E2]}, \texttt{E1} must either be a variable of array of
\texttt{T[]}, or an object of type \texttt{T} where \texttt{T} provides an
overloaded implementation of \texttt{operator[]} (\ref{Overload}).\footnote{HLSL
does not support the base address of a subscript operator being the expression
inside the braces, which is valid in C and C++.}
1 change: 1 addition & 0 deletions specs/language/placeholders.tex
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
\Ch{Declarations}{Decl}
\Sec{Attributes}{Decl.Attr}
\Sub{Entry Attributes}{Decl.Attr.Entry}
\Ch{Overloading}{Overload}
\Ch{Runtime}{Runtime}

0 comments on commit e64a254

Please sign in to comment.