next up previous contents index
Next: Field declarations Up: Applying the simplify algorithm Previous: Statement expressions   Contents   Index


Local variable declarations

Consider a local variable declaration of the form

\begin{displaymath}
\mbox{\it m} \verb$ $ T \verb$ $ V_0 \verb$ $ I_0 \verb$, $ \ldots \verb$, $
V_{n-1} \verb$ $ I_{n-1} \verb$ ;$
\end{displaymath}

where $\mbox{\it m}$ is an optional final modifier, $T$ is a type, each term $V_i$ is a simple identifier, $v_i$, followed by zero or more bracket pairs, [], and each optional initializer clause $I_i$ is either empty, or a term ``= $h_i$'', where $h_i$ is an expression or an array initializer. We must have $n \ge 1$.

For each variable declarator

\begin{displaymath}
\begin{minipage}[t]{\linewidth}\begin{tabbing}
$V_i$\verb$ = $$h_i$\end{tabbing}\end{minipage}\end{displaymath}

with a non-empty initializer, apply the simplify algorithm to $h_i$, yielding results $\mbox{\it INITS}_i$ and $h'_i$.

If $T$ is a multiarray type we unconditionally break the declaration into a series of transformed, single-variable declarations, $D_i$:

\begin{displaymath}
\begin{minipage}[t]{\linewidth}\begin{tabbing}
$D_0$ \\
\verb$...$ \\
$D_{n-1}$\end{tabbing}\end{minipage}\end{displaymath}

where the form of $D_i$ will be described below.

If $T$ is not a multiarray type, and all $\mbox{\it INITS}_i$ are empty, the whole declaration is unchanged in the transformed code.

In any other case, suppose $h_r$ is the first variable initializer for which $\mbox{\it INITS}_i$ is not empty. We will take the transformed declaration to be:

\begin{displaymath}
\begin{minipage}[t]{\linewidth}\begin{tabbing}
$\mbox{\it m}...
...
$D_r$ \\
\verb$...$ \\
$D_{n-1}$\end{tabbing}\end{minipage}\end{displaymath}

with the $D_i$ defined as follows.

If $\mbox{\it INITS}_i$ is empty and $h_i$ is not a composite expression, then $D_i$ is just:

\begin{displaymath}
\begin{minipage}[t]{\linewidth}\begin{tabbing}
$\mbox{\it m}...
...\verb$ $$V_i$\verb$ $$I_i$\verb$ ;$
\end{tabbing}\end{minipage}\end{displaymath}

Otherwise $D_i$ is:

\begin{displaymath}
\begin{minipage}[t]{\linewidth}\begin{tabbing}
$\mbox{\it m}...
...INITS}_i$ \\
$v_i$\verb$ = $$e'_i$\end{tabbing}\end{minipage}\end{displaymath}

Here, if $h'_i$ is not an array initializer,$e'_i$ is just equal to $h'_i$. If $h'_i$ is an array initializer, $e'_i$ is the array creation expression:

\begin{displaymath}
\begin{minipage}[t]{\linewidth}\begin{tabbing}
\verb$new $$U_i$\verb$ $$h'_i$\end{tabbing}\end{minipage}\end{displaymath}

where $U_i$ is the array type of $v_i$.

If $h_i$ is composite expression $e_i$, one may anticipate this transformation, and arrange to have the simplify algorithm treat $e_i$ as if it was originally on the right-hand side of a top-level assignment. This will avoid the introduction of an unnecessary temporary.

The case of a local variable declaration appearing in the initialization section of a for-loop header may need some special treatment--see page [*].


next up previous contents index
Next: Field declarations Up: Applying the simplify algorithm Previous: Statement expressions   Contents   Index
Bryan Carpenter 2003-04-15