public INSTANCEOF createInstanceOf(ReferenceType t) { if(t instanceof ArrayType) return new INSTANCEOF(cp.addArrayClass((ArrayType)t)); else return new INSTANCEOF(cp.addClass((ObjectType)t)); }
public CHECKCAST createCheckCast( final ReferenceType t ) { if (t instanceof ArrayType) { return new CHECKCAST(cp.addArrayClass((ArrayType) t)); } return new CHECKCAST(cp.addClass((ObjectType) t)); }
public INSTANCEOF createInstanceOf( final ReferenceType t ) { if (t instanceof ArrayType) { return new INSTANCEOF(cp.addArrayClass((ArrayType) t)); } return new INSTANCEOF(cp.addClass((ObjectType) t)); }
public CHECKCAST createCheckCast(ReferenceType t) { if(t instanceof ArrayType) return new CHECKCAST(cp.addArrayClass((ArrayType)t)); else return new CHECKCAST(cp.addClass((ObjectType)t)); }
/** Create conversion operation for two stack operands, this may be an I2C, instruction, e.g., * if the operands are basic types and CHECKCAST if they are reference types. */ public Instruction createCast( final Type src_type, final Type dest_type ) { if ((src_type instanceof BasicType) && (dest_type instanceof BasicType)) { final byte dest = dest_type.getType(); byte src = src_type.getType(); if (dest == Const.T_LONG && (src == Const.T_CHAR || src == Const.T_BYTE || src == Const.T_SHORT)) { src = Const.T_INT; } final String name = "org.apache.bcel.generic." + short_names[src - Const.T_CHAR] + "2" + short_names[dest - Const.T_CHAR]; Instruction i = null; try { i = (Instruction) java.lang.Class.forName(name).newInstance(); } catch (final Exception e) { throw new RuntimeException("Could not find instruction: " + name, e); } return i; } else if ((src_type instanceof ReferenceType) && (dest_type instanceof ReferenceType)) { if (dest_type instanceof ArrayType) { return new CHECKCAST(cp.addArrayClass((ArrayType) dest_type)); } return new CHECKCAST(cp.addClass(((ObjectType) dest_type).getClassName())); } else { throw new RuntimeException("Can not cast " + src_type + " to " + dest_type); } }
/** Create conversion operation for two stack operands, this may be an I2C, instruction, e.g., * if the operands are basic types and CHECKCAST if they are reference types. */ public Instruction createCast(Type src_type, Type dest_type) { if((src_type instanceof BasicType) && (dest_type instanceof BasicType)) { byte dest = dest_type.getType(); byte src = src_type.getType(); if(dest == Constants.T_LONG && (src == Constants.T_CHAR || src == Constants.T_BYTE || src == Constants.T_SHORT)) src = Constants.T_INT; String[] short_names = { "C", "F", "D", "B", "S", "I", "L" }; String name = "org.apache.bcel.generic." + short_names[src - Constants.T_CHAR] + "2" + short_names[dest - Constants.T_CHAR]; Instruction i = null; try { i = (Instruction)java.lang.Class.forName(name).newInstance(); } catch(Exception e) { throw new RuntimeException("Could not find instruction: " + name); } return i; } else if((src_type instanceof ReferenceType) && (dest_type instanceof ReferenceType)) { if(dest_type instanceof ArrayType) return new CHECKCAST(cp.addArrayClass((ArrayType)dest_type)); else return new CHECKCAST(cp.addClass(((ObjectType)dest_type).getClassName())); } else throw new RuntimeException("Can not cast " + src_type + " to " + dest_type); }
/** Create new array of given size and type. * @return an instruction that creates the corresponding array at runtime, i.e. is an AllocationInstruction */ public Instruction createNewArray( final Type t, final short dim ) { if (dim == 1) { if (t instanceof ObjectType) { return new ANEWARRAY(cp.addClass((ObjectType) t)); } else if (t instanceof ArrayType) { return new ANEWARRAY(cp.addArrayClass((ArrayType) t)); } else { return new NEWARRAY(t.getType()); } } ArrayType at; if (t instanceof ArrayType) { at = (ArrayType) t; } else { at = new ArrayType(t, dim); } return new MULTIANEWARRAY(cp.addArrayClass(at), dim); }
/** Create new array of given size and type. * @return an instruction that creates the corresponding array at runtime, i.e. is an AllocationInstruction */ public Instruction createNewArray(Type t, short dim) { if(dim == 1) { if(t instanceof ObjectType) return new ANEWARRAY(cp.addClass((ObjectType)t)); else if(t instanceof ArrayType) return new ANEWARRAY(cp.addArrayClass((ArrayType)t)); else return new NEWARRAY(((BasicType)t).getType()); } else { ArrayType at; if(t instanceof ArrayType) at = (ArrayType)t; else at = new ArrayType(t, dim); return new MULTIANEWARRAY(cp.addArrayClass(at), dim); } }