Changeset 2f9956b for doc/refrat


Ignore:
Timestamp:
Sep 18, 2015, 10:04:03 AM (6 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, ctor, deferred_resn, demangler, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, resolv-new, string, with_gc
Children:
8cbf8cd, ce6c57c
Parents:
971ae89
Message:

add control-structure extensions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/refrat/refrat.tex

    r971ae89 r2f9956b  
    40414041
    40424042
    4043 \setcounter{subsection}{2}
     4043\subsection{Labeled statements}
     4044
     4045\begin{syntax}
     4046\oldlhs{labeled-statement}
     4047\rhs \lstinline$case$ \nonterm{case-value-list} : \nonterm{statement}
     4048\lhs{case-value-list}
     4049\rhs \nonterm{case-value}
     4050\rhs \nonterm{case-value-list} \lstinline$,$ \nonterm{case-value}
     4051\lhs{case-value}
     4052\rhs \nonterm{constant-expression}
     4053\rhs \nonterm{subrange}
     4054\lhs{subrange}
     4055\rhs \nonterm{constant-expression} \lstinline$~$ \nonterm{constant-expression}
     4056\end{syntax}
     4057
     4058The following have identical meaning:
     4059\begin{lstlisting}
     4060case 1:@\ \ @case 2:@\ \ @case 3:@\ \ @case 4:@\ \ @case 5:
     4061case 1, 2, 3, 4, 5:
     4062case 1~5:
     4063\end{lstlisting}
     4064The multiple subranges are allowed:
     4065\begin{lstlisting}
     4066case 1~4, 9~14, 27~32:
     4067\end{lstlisting}
     4068
     4069The \lstinline$case$ and \lstinline$default$ clauses are restricted within the \lstinline$switch$ and \lstinline$choose$ statements, precluding Duff's device.
     4070
     4071
    40444072\subsection{Expression and null statements}
    40454073
     
    40494077\subsection{Selection statements}
    40504078
    4051 The controlling expression \lstinline$E$ in the switch statement
     4079\begin{syntax}
     4080\oldlhs{selection-statement}
     4081\rhs \lstinline$choose$ \lstinline$($ \nonterm{expression} \lstinline$)$ \nonterm{statement}
     4082\end{syntax}
     4083
     4084The controlling expression \lstinline$E$ in the \lstinline$switch$ and \lstinline$choose$ statement:
    40524085\begin{lstlisting}
    40534086switch ( E ) ...
     4087choose ( E ) ...
    40544088\end{lstlisting}
    40554089may have more than one interpretation, but it shall have only one interpretation with an integral
     
    40584092
    40594093
     4094\setcounter{subsubsection}{3}
     4095\subsubsection{The \lstinline$choose$ statement}
     4096
     4097The \lstinline$choose$ statement is the same as the \lstinline$switch$ statement except control transfers to the end of the \lstinline$choose$ statement at a \lstinline$case$ or \lstinline$default$ labeled statement.
     4098The \lstinline$fallthru$ statement is used to fall through to the next \lstinline$case$ or \lstinline$default$ labeled statement.
     4099
     4100The following have identical meaning:
     4101\begin{flushleft}
     4102\begin{tabular}{@{\hspace{2em}}l@{\hspace{2em}}l@{}}
     4103\begin{lstlisting}
     4104switch (...) {
     4105  case 1: ... ; break;
     4106  case 2: ... ; break;
     4107  case 3: ... ; // fall through
     4108  case 4: ... ; // fall through
     4109  default: ... break;
     4110}
     4111\end{lstlisting}
     4112&
     4113\begin{lstlisting}
     4114choose (...) {
     4115  case 1: ... ; // exit
     4116  case 2: ... ; // exit
     4117  case 3: ... ; fallthru;
     4118  case 4: ... ; fallthru;
     4119  default: ... ; // exit
     4120}
     4121\end{lstlisting}
     4122\end{tabular}
     4123\end{flushleft}
     4124The \lstinline$choose$ statement addresses the problem of accidental fall-through associated with \lstinline$switch$ statement.
     4125
     4126
    40604127\subsection{Iteration statements}
    40614128
     
    40744141is treated as
    40754142\begin{lstlisting}
    4076 for ( ( void )( a ); ( int )(( b )!=0); ( void )( c ) ) @\ldots@
     4143for ( ( void )( a ); ( int )(( b )!=0); ( void )( c ) ) ...
    40774144\end{lstlisting}
    40784145
     
    40804147\subsection{Jump statements}
    40814148
    4082 An expression in a \lstinline$return$ statement is treated as being
    4083 cast to the result type of the function.
     4149\begin{syntax}
     4150\oldlhs{jump-statement}
     4151\rhs \lstinline$continue$ \nonterm{identifier}\opt
     4152\rhs \lstinline$break$ \nonterm{identifier}\opt
     4153\end{syntax}
     4154
     4155Labeled \lstinline$continue$ and \lstinline$break$ allow useful but restricted control-flow that reduces the need for the \lstinline$goto$ statement for exiting multiple nested control-structures.
     4156\begin{lstlisting}
     4157L1: {                                                   // compound
     4158  L2: switch ( ... ) {                  // switch
     4159    case ...:
     4160          L3: for ( ;; ) {                      // outer for
     4161                L4: for ( ;; ) {                // inner for
     4162                                continue L1;    // error: not enclosing iteration
     4163                                continue L2;    // error: not enclosing iteration
     4164                                continue L3;    // next iteration of outer for
     4165                                continue L4;    // next iteration of inner for
     4166                                break L1;               // exit compound
     4167                                break L2;               // exit switch
     4168                                break L3;               // exit outer for
     4169                                break L4;               // exit inner for
     4170                        } // for
     4171                } // for
     4172                break;                                  // exit switch
     4173          default:
     4174                break L1;                               // exit compound
     4175        } // switch
     4176        ...
     4177} // compound
     4178\end{lstlisting}
     4179
     4180
     4181\setcounter{subsubsection}{1}
     4182\subsubsection{The \lstinline$continue$ statement}
     4183
     4184The identifier in a \lstinline$continue$ statement shall name a label located on an enclosing iteration statement.
     4185
     4186
     4187\subsubsection{The \lstinline$break$ statement}
     4188
     4189The identifier in a \lstinline$break$ statement shall name a label located on an enclosing compound, selection or iteration statement.
     4190
     4191
     4192\subsubsection{The \lstinline$return$ statement}
     4193
     4194An expression in a \lstinline$return$ statement is treated as being cast to the result type of the
     4195function.
    40844196
    40854197
Note: See TracChangeset for help on using the changeset viewer.