argNames[argNames.length - 1] = SCJavaDefn.EXECUTION_CONTEXT_NAME;
}
// Build up the arguments to the superclass constructor.
JavaExpression superClassConstructorArgValues[] = new JavaExpression [commonFields.size()];
JavaTypeName superClassConstructorArgTypes[] = new JavaTypeName [commonFields.size()];
int j = 0;
for (final FieldName fn : commonFields) {
int fieldIndex = dc.getFieldIndex(fn);
superClassConstructorArgValues[j] = argVars[fieldIndex];
superClassConstructorArgTypes[j] = argTypes[fieldIndex];
j++;
}
// Add the method to the class.
JavaConstructor javaConstructor = new JavaConstructor(modifiers, argNames, argTypes, CALToJavaNames.createInnerClassNameFromDC(dc, module), superClassConstructorArgValues, superClassConstructorArgTypes);
javaClassRep.addConstructor(javaConstructor);
if (LECCMachineConfiguration.generateDebugCode()) {
javaConstructor.addStatement(generateDebugCode(argNames, argTypes));
}
// Assert that object arguments are non-null.
JavaExpression check = null;
for (int i = 0, n = dc.getArity(); i < n; ++i) {
// We only check fields of type RTValue. It is valid to have an unboxed object value of null.
if (argTypes[i].equals(JavaTypeNames.RTVALUE)) {
JavaExpression newCheck = new OperatorExpression.Binary(JavaOperator.NOT_EQUALS_OBJECT, argVars[i], LiteralWrapper.NULL);
if (check == null) {
check = newCheck;
} else {
check = new OperatorExpression.Binary(JavaOperator.CONDITIONAL_AND, check, newCheck);
}
}
}
if (check != null) {
javaConstructor.addStatement(new AssertStatement(check, LiteralWrapper.make("Invalid constructor argument for " + dc.getName().getQualifiedName()), JavaTypeName.STRING));
}
// Add the body..
// We want to assign any of the fields in this class.
for (int i = 0, n = dc.getArity(); i < n; i++) {
if (commonFields.contains(dc.getNthFieldName(i))) {
// This field is in the containing class so we don't
// assign here.
continue;
}
JavaTypeName fieldType = JavaTypeNames.RTVALUE;
if (fieldStrictness[i] && SCJavaDefn.canTypeBeUnboxed(fieldTypes[i])) {
fieldType = SCJavaDefn.typeExprToTypeName(fieldTypes[i]);
}
JavaField field = new JavaField.Instance(null, javaFieldNames[i], fieldType);