Block methodBodyBlock = new Block();
int nReturnedFields = 0;
// Check that this is an instance of the expected data constructor.
MethodInvocation checkDC =
new MethodInvocation.Instance(
null,
"checkDCOrdinalForFieldSelection",
new JavaExpression[]{new MethodVariable("dcOrdinal"), new MethodVariable("errorInfo")},
new JavaTypeName[]{JavaTypeName.INT, JavaTypeName.ERRORINFO},
JavaTypeName.VOID,
MethodInvocation.InvocationType.VIRTUAL);
methodBodyBlock.addStatement(new ExpressionStatement(checkDC));
SwitchStatement sw = new SwitchStatement(METHODVAR_FIELDINDEX);
for (int i = 0; i < javaFieldNames.length; ++i) {
if (forType != null) {
// If field is not strict or not primitive can't return unboxed form.
if (!fieldStrictness[i] || !SCJavaDefn.canTypeBeUnboxed(fieldTypes[i])) {
continue;
}
JavaTypeName ftn = SCJavaDefn.typeExprToTypeName(fieldTypes[i]);
if (!forType.equals(ftn)) {
// Check to see if we're doing return type 'Object' on a foreign type.
if (!forType.equals(JavaTypeName.OBJECT) || ftn instanceof JavaTypeName.Primitive) {
continue;
}
}
}
JavaExpression jf;
if (fieldStrictness[i] && SCJavaDefn.canTypeBeUnboxed(fieldTypes[i])) {
jf = new JavaField.Instance (null, javaFieldNames[i], SCJavaDefn.typeExprToTypeName(fieldTypes[i]));
if (forType == null) {
jf = SCJavaDefn.boxExpression(fieldTypes[i], jf);
}
} else {
// We have a non-strict field of type RTValue. In order to reduce space usage
// we want to update the field value to be the result of the original suspension.
// We do this by using the field accessor function get_fieldName().
jf = new MethodInvocation.Instance(null, "get" + javaFieldNames[i], JavaTypeNames.RTVALUE, MethodInvocation.InvocationType.VIRTUAL);
if (forType != null) {
jf = SCJavaDefn.unboxValue(forType, jf);
}
}
SwitchStatement.IntCaseGroup iCase = new SwitchStatement.IntCaseGroup(i, new ReturnStatement (jf));
sw.addCase(iCase);
nReturnedFields++;
}
methodBodyBlock.addStatement (sw);
MethodInvocation error =
new MethodInvocation.Instance(
null,
"badFieldIndexInGetFieldByIndex",
METHODVAR_FIELDINDEX,
JavaTypeName.INT,