next up previous contents index
Next: Translating constructor declarations Up: Translating method declarations Previous: Translating method declarations   Contents   Index

Methods that return multiarrays

The scheme for translating a multiarray-valued method declaration is illustrated in Figure A.15.

The macro TRANS_ID encodes the dimension signature of the returned array and is defined in section A.4.2. The macro TRANS_PARAMS was defined earlier in this section.

Instances of the class DAD (the initials stand for Distributed Array Descriptor) contain a reference to an ArrayBase object, and a vector of $R$ instances of ArrayDim. These values are stored in fields base and dimensions, respectively. The DAD object will be created in the calling program and passed to the translated method. Before the method returns, it will store the parameters describing the layout of the multiarray result in these fields (see sections A.4.15 and A.4.15).

An alternative--in some ways more obvious--translation would place the element array in a field in the DAD, and have the method return a DAD. However this would require either we create a separate DAD class for every possible element type--which is hard because HPJava supports multiarrays with arbitrary Java types, including user-defined class and interface types, or the element array field in our extended DAD has the universal Object type. In the latter case one would cast the object back to the appropriate element-array type on return from the call. There is a fatal problem with this approach however: it does not encode the element type of the multiarray in the class file generated by compiling the translated code. So the return type of the method cannot be determined by HPJava programs that load the declaring class from a class file.

Figure A.16: Translation of constructor declaration.
SOURCE:

\begin{displaymath}
\begin{minipage}[t]{\linewidth}\begin{tabbing}
$T$\verb$($$U...
...rb$ $$v_{N-1}$\verb$) {$$S$\verb$}$
\end{tabbing}\end{minipage}\end{displaymath}

TRANSLATION:

\begin{displaymath}
\begin{minipage}[t]{\linewidth}\begin{tabbing}
$T$\verb$($\=...
...ert{p}\right.\right]$ \\
\verb$}$
\end{tabbing}\end{minipage}\end{displaymath}

where:

\begin{displaymath}
\begin{array}{l}
\mbox{$T$ is a Java type, the name of the ...
... macro {\it TRANS\_PARAMS} is defined in the text.}
\end{array}\end{displaymath}


next up previous contents index
Next: Translating constructor declarations Up: Translating method declarations Previous: Translating method declarations   Contents   Index
Bryan Carpenter 2003-04-15