import net.sourceforge.phpdt.internal.compiler.lookup.BlockScope;
import net.sourceforge.phpdt.internal.compiler.lookup.TypeBinding;
-
public class ArrayAllocationExpression extends Expression {
public TypeReference type;
- //dimensions.length gives the number of dimensions, but the
+ // dimensions.length gives the number of dimensions, but the
// last ones may be nulled as in new int[4][5][][]
public Expression[] dimensions;
+
public ArrayInitializer initializer;
/**
super();
}
- public FlowInfo analyseCode(
- BlockScope currentScope,
- FlowContext flowContext,
- FlowInfo flowInfo) {
+ public FlowInfo analyseCode(BlockScope currentScope,
+ FlowContext flowContext, FlowInfo flowInfo) {
for (int i = 0, max = dimensions.length; i < max; i++) {
Expression dim;
if ((dim = dimensions[i]) != null) {
/**
* Code generation for a array allocation expression
*/
-// public void generateCode(
-// BlockScope currentScope,
-// CodeStream codeStream,
-// boolean valueRequired) {
-//
-// int pc = codeStream.position;
-//
-// if (initializer != null) {
-// initializer.generateCode(currentScope, codeStream, valueRequired);
-// return;
-// }
-//
-// int nonNullDimensionsLength = 0;
-// for (int i = 0, max = dimensions.length; i < max; i++)
-// if (dimensions[i] != null) {
-// dimensions[i].generateCode(currentScope, codeStream, true);
-// nonNullDimensionsLength++;
-// }
-//
-// // Generate a sequence of bytecodes corresponding to an array allocation
-// if (this.resolvedType.dimensions() == 1) {
-// // Mono-dimensional array
-// codeStream.newArray(currentScope, (ArrayBinding)this.resolvedType);
-// } else {
-// // Multi-dimensional array
-// codeStream.multianewarray(this.resolvedType, nonNullDimensionsLength);
-// }
-//
-// if (valueRequired) {
-// codeStream.generateImplicitConversion(implicitConversion);
-// } else {
-// codeStream.pop();
-// }
-//
-// codeStream.recordPositionsFrom(pc, this.sourceStart);
-// }
+ // public void generateCode(
+ // BlockScope currentScope,
+ // CodeStream codeStream,
+ // boolean valueRequired) {
+ //
+ // int pc = codeStream.position;
+ //
+ // if (initializer != null) {
+ // initializer.generateCode(currentScope, codeStream, valueRequired);
+ // return;
+ // }
+ //
+ // int nonNullDimensionsLength = 0;
+ // for (int i = 0, max = dimensions.length; i < max; i++)
+ // if (dimensions[i] != null) {
+ // dimensions[i].generateCode(currentScope, codeStream, true);
+ // nonNullDimensionsLength++;
+ // }
+ //
+ // // Generate a sequence of bytecodes corresponding to an array allocation
+ // if (this.resolvedType.dimensions() == 1) {
+ // // Mono-dimensional array
+ // codeStream.newArray(currentScope, (ArrayBinding)this.resolvedType);
+ // } else {
+ // // Multi-dimensional array
+ // codeStream.multianewarray(this.resolvedType, nonNullDimensionsLength);
+ // }
+ //
+ // if (valueRequired) {
+ // codeStream.generateImplicitConversion(implicitConversion);
+ // } else {
+ // codeStream.pop();
+ // }
+ //
+ // codeStream.recordPositionsFrom(pc, this.sourceStart);
+ // }
public StringBuffer printExpression(int indent, StringBuffer output) {
output.append("new "); //$NON-NLS-1$
- type.print(0, output);
+ type.print(0, output);
for (int i = 0; i < dimensions.length; i++) {
if (dimensions[i] == null)
output.append("[]"); //$NON-NLS-1$
dimensions[i].printExpression(0, output);
output.append(']');
}
- }
- if (initializer != null) initializer.printExpression(0, output);
+ }
+ if (initializer != null)
+ initializer.printExpression(0, output);
return output;
}
+
public TypeBinding resolveType(BlockScope scope) {
// Build an array type reference using the current dimensions
// The parser does not check for the fact that dimension may be null
- // only at the -end- like new int [4][][]. The parser allows new int[][4][]
- // so this must be checked here......(this comes from a reduction to LL1 grammar)
+ // only at the -end- like new int [4][][]. The parser allows new
+ // int[][4][]
+ // so this must be checked here......(this comes from a reduction to LL1
+ // grammar)
TypeBinding referenceType = type.resolveType(scope);
-
+
// will check for null after dimensions are checked
constant = Constant.NotAConstant;
if (referenceType == VoidBinding) {
referenceType = null;
}
- // check the validity of the dimension syntax (and test for all null dimensions)
+ // check the validity of the dimension syntax (and test for all null
+ // dimensions)
int explicitDimIndex = -1;
for (int i = dimensions.length; --i >= 0;) {
if (dimensions[i] != null) {
- if (explicitDimIndex < 0) explicitDimIndex = i;
- } else if (explicitDimIndex> 0) {
+ if (explicitDimIndex < 0)
+ explicitDimIndex = i;
+ } else if (explicitDimIndex > 0) {
// should not have an empty dimension before an non-empty one
- scope.problemReporter().incorrectLocationForEmptyDimension(this, i);
+ scope.problemReporter().incorrectLocationForEmptyDimension(
+ this, i);
}
}
scope.problemReporter().cannotDefineDimensionsAndInitializer(this);
}
- // dimensions resolution
+ // dimensions resolution
for (int i = 0; i <= explicitDimIndex; i++) {
if (dimensions[i] != null) {
- TypeBinding dimensionType = dimensions[i].resolveTypeExpecting(scope, IntBinding);
+ TypeBinding dimensionType = dimensions[i].resolveTypeExpecting(
+ scope, IntBinding);
if (dimensionType != null) {
dimensions[i].implicitWidening(IntBinding, dimensionType);
}
if (dimensions.length > 255) {
scope.problemReporter().tooManyDimensions(this);
}
- this.resolvedType = scope.createArray(referenceType, dimensions.length);
+ this.resolvedType = scope.createArray(referenceType,
+ dimensions.length);
// check the initializer
if (initializer != null) {
if ((initializer.resolveTypeExpecting(scope, this.resolvedType)) != null)
- initializer.binding = (ArrayBinding)this.resolvedType;
+ initializer.binding = (ArrayBinding) this.resolvedType;
}
}
return this.resolvedType;
s = s + "[]"; //$NON-NLS-1$
else
s = s + "[" + dimensions[i].toStringExpression() + "]"; //$NON-NLS-2$ //$NON-NLS-1$
- }
+ }
if (initializer != null)
s = s + initializer.toStringExpression();
return s;