private boolean compatibleType(TypeDesc a, TypeDesc b) { if (a == b || (!a.isPrimitive() && !b.isPrimitive())) { return true; } if (isIntType(a) && isIntType(b)) { return true; } return false; }
private String getClassName(TypeDesc classDesc) throws IllegalArgumentException { if (classDesc.isPrimitive()) { throw new IllegalArgumentException("Primitive type not allowed"); } if (classDesc.isArray()) { throw new IllegalArgumentException("Array type not allowed"); } return classDesc.getRootName(); }
if (type.isPrimitive()) { name = "TypeDesc.".concat(type.getRootName().toUpperCase()); mTypeDescNames.put(type, name);
public void loadConstant(TypeDesc type) throws IllegalStateException { if (type == null) { loadNull(); return; } if (type.isPrimitive()) { if (mTarget < 0x00010001) { throw new IllegalStateException ("Loading constant primitive classes not supported below target version 1.1"); } loadStaticField(type.toObjectType(), "TYPE", TypeDesc.forClass(Class.class)); } else { if (mTarget < 0x00010005) { throw new IllegalStateException ("Loading constant object classes not supported below target version 1.5"); } ConstantInfo info = mCp.addConstantClass(type); mInstructions.new LoadConstantInstruction(1, TypeDesc.forClass(Class.class), info); } }
if (fromType.isPrimitive()) { toType = fromType.toObjectType(); } else { if (!toType.isPrimitive()) { Class fromClass = fromType.toClass(); if (fromClass != null) { case TypeDesc.FLOAT_CODE: case TypeDesc.DOUBLE_CODE: if (fromType.isPrimitive()) { toType = fromType.toObjectType(); } else { break; case TypeDesc.BOOLEAN_CODE: if (!fromType.isPrimitive()) { if (!toType.isPrimitive()) { nullConvert(end); toBoolean(!toType.isPrimitive()); break doConversion; default: break; case TypeDesc.BOOLEAN_CODE: if (!fromType.isPrimitive()) { if (!toType.isPrimitive()) { nullConvert(end);
private void print(TypeDesc type) { if (type == null || type == TypeDesc.VOID) { print("null"); return; } if (type.isPrimitive()) { print("TypeDesc.".concat(type.getFullName().toUpperCase())); return; } else if (type == TypeDesc.OBJECT) { print("TypeDesc.OBJECT"); return; } else if (type == TypeDesc.STRING) { print("TypeDesc.STRING"); return; } TypeDesc componentType = type.getComponentType(); if (componentType != null) { print(componentType); print(".toArrayType()"); } else { print("TypeDesc.forClass(\""); print(escape(type.getRootName())); print("\")"); } }
public void newObject(TypeDesc type, int dimensions) { if (dimensions <= 0) { // If type refers to an array, then this code is bogus. mInstructions.new NewObjectInstruction(mCp.addConstantClass(type)); return; } TypeDesc componentType = type.getComponentType(); if (dimensions == 1) { if (componentType.isPrimitive()) { addInstruction(0, type, Opcode.NEWARRAY, (byte)componentType.getTypeCode()); return; } addInstruction(0, type, Opcode.ANEWARRAY, mCp.addConstantClass(componentType)); return; } int stackAdjust = -(dimensions - 1); ConstantInfo info = mCp.addConstantClass(type); byte[] bytes = new byte[4]; bytes[0] = Opcode.MULTIANEWARRAY; //bytes[1] = (byte)0; //bytes[2] = (byte)0; bytes[3] = (byte)dimensions; mInstructions.new ConstantOperandInstruction(stackAdjust, type, bytes, info); }
private boolean compatibleType(TypeDesc a, TypeDesc b) { if (a == b || (!a.isPrimitive() && !b.isPrimitive())) { return true; } if (isIntType(a) && isIntType(b)) { return true; } return false; }
private String getClassName(TypeDesc classDesc) throws IllegalArgumentException { if (classDesc.isPrimitive()) { throw new IllegalArgumentException("Primitive type not allowed"); } if (classDesc.isArray()) { throw new IllegalArgumentException("Array type not allowed"); } return classDesc.getRootName(); }
private void branchIfNull(CodeBuilder b, LocalVariable value, Label isNull) { if (!value.getType().isPrimitive()) { b.loadLocal(value); b.ifNullBranch(isNull, true); } }
/** * Returns the actual field type used to store the given property * type. Floating point values are represented in their "bit" form, in * order to compare against NaN. */ private static TypeDesc actualFieldType(TypeDesc type) { if (type.toPrimitiveType() == FLOAT) { if (type.isPrimitive()) { type = INT; } else { type = INT.toObjectType(); } } else if (type.toPrimitiveType() == DOUBLE) { if (type.isPrimitive()) { type = LONG; } else { type = LONG.toObjectType(); } } return type; }
/** * Returns the actual field type used to store the given property * type. Floating point values are represented in their "bit" form, in * order to compare against NaN. */ private static TypeDesc actualFieldType(TypeDesc type) { if (type.toPrimitiveType() == FLOAT) { if (type.isPrimitive()) { type = INT; } else { type = INT.toObjectType(); } } else if (type.toPrimitiveType() == DOUBLE) { if (type.isPrimitive()) { type = LONG; } else { type = LONG.toObjectType(); } } return type; }
static boolean isKnownType(ClassLoader loader, TypeDesc type) { if (type == null) { // Assume void return type. return true; } if (type.isArray()) { type = type.getRootComponentType(); } if (type.isPrimitive()) { return true; } String name = type.getRootName(); try { if (loader == null) { Class.forName(name); } else { loader.loadClass(name); } } catch (ClassNotFoundException e) { return false; } return true; }
private void branchIfNull(CodeBuilder b, LocalVariable value, Label isNull) { if (!value.getType().isPrimitive()) { b.loadLocal(value); b.ifNullBranch(isNull, true); } }
public void loadConstant(TypeDesc type) throws IllegalStateException { if (type == null) { loadNull(); return; } if (type.isPrimitive()) { if (mTarget < 0x00010001) { throw new IllegalStateException ("Loading constant primitive classes not supported below target version 1.1"); } loadStaticField(type.toObjectType(), "TYPE", TypeDesc.forClass(Class.class)); } else { if (mTarget < 0x00010005) { throw new IllegalStateException ("Loading constant object classes not supported below target version 1.5"); } ConstantInfo info = mCp.addConstantClass(type); mInstructions.new LoadConstantInstruction(1, TypeDesc.forClass(Class.class), info); } }
private static void addValueHashCodeCallTo(CodeBuilder b, TypeDesc valueType) { if (valueType.isArray()) { if (!valueType.getComponentType().isPrimitive()) { b.invokeStatic("java.util.Arrays", "deepHashCode", TypeDesc.INT, new TypeDesc[] {TypeDesc.forClass(Object[].class)}); } else { b.invokeStatic("java.util.Arrays", "hashCode", TypeDesc.INT, new TypeDesc[] {valueType}); } } else { b.invokeVirtual(TypeDesc.OBJECT, "hashCode", TypeDesc.INT, null); } }
private static void addValueHashCodeCallTo(CodeBuilder b, TypeDesc valueType) { if (valueType.isArray()) { if (!valueType.getComponentType().isPrimitive()) { b.invokeStatic("java.util.Arrays", "deepHashCode", TypeDesc.INT, new TypeDesc[] {TypeDesc.forClass(Object[].class)}); } else { b.invokeStatic("java.util.Arrays", "hashCode", TypeDesc.INT, new TypeDesc[] {valueType}); } } else { b.invokeVirtual(TypeDesc.OBJECT, "hashCode", TypeDesc.INT, null); } }
private void print(TypeDesc type) { if (type == null || type == TypeDesc.VOID) { print("null"); return; } if (type.isPrimitive()) { print("TypeDesc.".concat(type.getFullName().toUpperCase())); return; } else if (type == TypeDesc.OBJECT) { print("TypeDesc.OBJECT"); return; } else if (type == TypeDesc.STRING) { print("TypeDesc.STRING"); return; } TypeDesc componentType = type.getComponentType(); if (componentType != null) { print(componentType); print(".toArrayType()"); } else { print("TypeDesc.forClass(\""); print(escape(type.getRootName())); print("\")"); } }
private void addPropertyAppendCall(CodeBuilder b, StorableProperty property) { b.loadConstant(property.getName()); invokeAppend(b, TypeDesc.STRING); b.loadConstant('='); invokeAppend(b, TypeDesc.CHAR); loadThisProperty(b, property); TypeDesc type = TypeDesc.forClass(property.getType()); if (type.isPrimitive()) { if (type == TypeDesc.BYTE || type == TypeDesc.SHORT) { type = TypeDesc.INT; } } else { if (type != TypeDesc.STRING) { if (type.isArray()) { if (!type.getComponentType().isPrimitive()) { b.invokeStatic("java.util.Arrays", "deepToString", TypeDesc.STRING, new TypeDesc[] {TypeDesc.OBJECT.toArrayType()}); } else { b.invokeStatic("java.util.Arrays", TO_STRING_METHOD_NAME, TypeDesc.STRING, new TypeDesc[] {type}); } } type = TypeDesc.OBJECT; } } invokeAppend(b, type); }
public void newObject(TypeDesc type, int dimensions) { if (dimensions <= 0) { // If type refers to an array, then this code is bogus. mInstructions.new NewObjectInstruction(mCp.addConstantClass(type)); return; } TypeDesc componentType = type.getComponentType(); if (dimensions == 1) { if (componentType.isPrimitive()) { addInstruction(0, type, Opcode.NEWARRAY, (byte)componentType.getTypeCode()); return; } addInstruction(0, type, Opcode.ANEWARRAY, mCp.addConstantClass(componentType)); return; } int stackAdjust = -(dimensions - 1); ConstantInfo info = mCp.addConstantClass(type); byte[] bytes = new byte[4]; bytes[0] = Opcode.MULTIANEWARRAY; //bytes[1] = (byte)0; //bytes[2] = (byte)0; bytes[3] = (byte)dimensions; mInstructions.new ConstantOperandInstruction(stackAdjust, type, bytes, info); }