{
if (utils.isBuiltin(value_type, BuiltinType.NULL))
return initial_value;
addProblem(new IncompatibleInitializerTypeProblem(initial_value_location, value_type.getBaseName(), desired_type.getBaseName(), "null"));
// transform initial_value to null.
return new PooledValue(ABCConstants.NULL_VALUE);
}
else if (utils.isBuiltin(desired_type, BuiltinType.STRING))
{
assert !(utils.isBuiltin(value_type, BuiltinType.STRING));
if (utils.isBuiltin(value_type, BuiltinType.NULL))
return initial_value;
String initial_value_string = ECMASupport.toString(initial_value.getValue());
String initial_value_quoted = "\"" + initial_value_string + "\"";
addProblem(new IncompatibleInitializerTypeProblem(initial_value_location, value_type.getBaseName(), desired_type.getBaseName(), initial_value_quoted));
// transform initial_value to a string constant.
return new PooledValue(initial_value_string);
}
else if (utils.isBuiltin(desired_type, BuiltinType.BOOLEAN))
{
assert !(utils.isBuiltin(value_type, BuiltinType.BOOLEAN));
// transform initial_value to a boolean constant.
boolean initial_value_boolean = ECMASupport.toBoolean(initial_value.getValue());
// tell the programmer about the transformation we did.
addProblem(new IncompatibleInitializerTypeProblem(initial_value_location, value_type.getBaseName(), desired_type.getBaseName(), String.valueOf(initial_value_boolean)));
return new PooledValue(initial_value_boolean);
}
else if (utils.isBuiltin(desired_type, BuiltinType.NUMBER))
{
if (utils.isBuiltin(value_type, BuiltinType.INT) ||
utils.isBuiltin(value_type, BuiltinType.UINT) ||
utils.isBuiltin(value_type, BuiltinType.NUMBER))
return initial_value;
Number initial_value_numeric = ECMASupport.toNumeric(initial_value.getValue());
double initial_value_double = initial_value_numeric != null ? initial_value_numeric.doubleValue() : 0;
addProblem(new IncompatibleInitializerTypeProblem(initial_value_location, value_type.getBaseName(), desired_type.getBaseName(), String.valueOf(initial_value_double)));
return new PooledValue(initial_value_double);
}
else if (utils.isBuiltin(desired_type, BuiltinType.UINT))
{
return checkInitialUIntValue(initial_value_location, desired_type, initial_value, value_type);
}
else if (utils.isBuiltin(desired_type, BuiltinType.INT))
{
return checkInitialIntValue(initial_value_location, desired_type, initial_value, value_type);
}
addProblem(new IncompatibleInitializerTypeProblem(initial_value_location, value_type.getBaseName(), desired_type.getBaseName(), "null"));
return new PooledValue(ABCConstants.NULL_VALUE);
}