int return_type = type != null ? addClassName(type.getName(cx)) : 0;
IntList param_types = null;
IntList param_values = null;
ByteList param_kinds = null;
{
ObjectValue obj = cx.scope();
Slots slots = obj.slots;
if (slots != null)
{
param_types = new IntList(slots.size());
param_values = new IntList(slots.size()); // default values
param_kinds = new ByteList(slots.size());
Iterator<Slot> it = slots.iterator();
//it.next(); // first one is this
boolean value_required = false;
for (int i = 1; it.hasNext() && i < max_params; ++i)
{
Slot slot = it.next();
int type_index = addClassName(slot.getType().getName(cx));
param_types.add(type_index);
int value_index = 0;
byte value_kind = 0;
ObjectValue iv = slot.getInitializerValue();
if (iv != null)
{
value_required = true;
String value = iv.toString();
NumberUsage numberUsage = iv.getNumberUsage();
TypeValue defaultValueType = slot.getInitializerValue().type != null ? slot.getInitializerValue().type.getTypeValue() : null;
if (defaultValueType == cx.booleanType())
{
// The index doesn't matter, as long as its non 0
// there are no boolean values in any cpool, instead the value will be determined by the kind byte
value_index = value.equals("true")?CONSTANT_True:CONSTANT_False;
value_kind = value.equals("true")?CONSTANT_True:CONSTANT_False;
}
else if (defaultValueType == cx.stringType())
{
value_index = ab.addUtf8Constant(bytecodeFactory.ConstantUtf8Info(value));
value_kind = CONSTANT_Utf8;
}
else if (defaultValueType == cx.intType())
{
value_index = ab.addIntConstant(bytecodeFactory.ConstantIntegerInfo(getValueOfNumberLiteral(value,new TypeValue[1], numberUsage).intValue()));
value_kind = CONSTANT_Integer;
}
else if ((defaultValueType == cx.doubleType()) || (cx.abcVersion(Features.TARGET_AVM1) && (defaultValueType == cx.uintType())))
{
value_index = ab.addDoubleConstant(bytecodeFactory.ConstantDoubleInfo(getValueOfNumberLiteral(value,new TypeValue[1], numberUsage).doubleValue()));
value_kind = CONSTANT_Double;
}
else if (defaultValueType == cx.uintType())
{
value_index = ab.addUintConstant(bytecodeFactory.ConstantUintInfo(getValueOfNumberLiteral(value,new TypeValue[1], numberUsage).uintValue()));
value_kind = CONSTANT_UInteger;
}
else if (cx.statics.es4_numerics && (defaultValueType == cx.decimalType()))
{
value_index = ab.addDecimalConstant(bytecodeFactory.ConstantDecimalInfo(getValueOfNumberLiteral(value,new TypeValue[1], numberUsage).decimalValue()));
value_kind = CONSTANT_Decimal;
}
else if (defaultValueType == cx.nullType())
{
// Similar to boolean above, the value will be determined by the kind byte (there is only 1 possible value for null)
value_index = CONSTANT_Null;
value_kind = CONSTANT_Null;
}
else if (defaultValueType == cx.voidType())
{
value_index = 0; // will be undefined at runtime
value_kind = 0;
}
else if (slot.getInitializerValue() instanceof NamespaceValue )
{
value_index = addNamespace(slot.getInitializerValue());
value_kind = CONSTANT_Namespace;
}
}
if (value_required)
{
param_values.add(value_index);
param_kinds.add(value_kind);
}
}
if (value_required)
{
flags |= METHOD_HasOptional;