/** * Ensures the specific preconditions of the said instruction. */ public void visitMULTIANEWARRAY(MULTIANEWARRAY o){ int dimensions = o.getDimensions(); // Dimensions argument is okay: see Pass 3a. for (int i=0; i<dimensions; i++){ if (stack().peek(i) != Type.INT){ constraintViolated(o, "The '"+dimensions+"' upper stack types should be 'int' but aren't."); } } // The runtime constant pool item at that index must be a symbolic reference to a class, // array, or interface type. See Pass 3a. }
/** * Ensures the specific preconditions of the said instruction. */ @Override public void visitMULTIANEWARRAY(final MULTIANEWARRAY o) { final int dimensions = o.getDimensions(); // Dimensions argument is okay: see Pass 3a. for (int i=0; i<dimensions; i++) { if (stack().peek(i) != Type.INT) { constraintViolated(o, "The '"+dimensions+"' upper stack types should be 'int' but aren't."); } } // The runtime constant pool item at that index must be a symbolic reference to a class, // array, or interface type. See Pass 3a. }
public void visitAllocationInstruction(AllocationInstruction i) { Type type; if(i instanceof CPInstruction) { type = ((CPInstruction)i).getType(_cp); } else { type = ((NEWARRAY)i).getType(); } short opcode = ((Instruction)i).getOpcode(); int dim = 1; switch(opcode) { case Constants.NEW: _out.println("il.append(_factory.createNew(\"" + ((ObjectType)type).getClassName() + "\"));"); break; case Constants.MULTIANEWARRAY: dim = ((MULTIANEWARRAY)i).getDimensions(); case Constants.ANEWARRAY: case Constants.NEWARRAY: _out.println("il.append(_factory.createNewArray(" + BCELifier.printType(type) + ", (short) " + dim + "));"); break; default: throw new RuntimeException("Oops: " + opcode); } }
/** Symbolically executes the corresponding Java Virtual Machine instruction. */ public void visitMULTIANEWARRAY(MULTIANEWARRAY o){ for (int i=0; i<o.getDimensions(); i++){ stack().pop(); } stack().push(o.getType(cpg)); } /** Symbolically executes the corresponding Java Virtual Machine instruction. */
/** Symbolically executes the corresponding Java Virtual Machine instruction. */ @Override public void visitMULTIANEWARRAY(final MULTIANEWARRAY o) { for (int i=0; i<o.getDimensions(); i++) { stack().pop(); } stack().push(o.getType(cpg)); } /** Symbolically executes the corresponding Java Virtual Machine instruction. */
@Override public void visitAllocationInstruction( final AllocationInstruction i ) { Type type; if (i instanceof CPInstruction) { type = ((CPInstruction) i).getType(_cp); } else { type = ((NEWARRAY) i).getType(); } final short opcode = ((Instruction) i).getOpcode(); int dim = 1; switch (opcode) { case Const.NEW: _out.println("il.append(_factory.createNew(\"" + ((ObjectType) type).getClassName() + "\"));"); break; case Const.MULTIANEWARRAY: dim = ((MULTIANEWARRAY) i).getDimensions(); //$FALL-THROUGH$ case Const.ANEWARRAY: case Const.NEWARRAY: if (type instanceof ArrayType) { type = ((ArrayType) type).getBasicType(); } _out.println("il.append(_factory.createNewArray(" + BCELifier.printType(type) + ", (short) " + dim + "));"); break; default: throw new RuntimeException("Oops: " + opcode); } }
/** Checks if the constraints of operands of the said instruction(s) are satisfied. */ public void visitMULTIANEWARRAY(MULTIANEWARRAY o){ indexValid(o, o.getIndex()); Constant c = cpg.getConstant(o.getIndex()); if (! (c instanceof ConstantClass)){ constraintViolated(o, "Expecting a CONSTANT_Class operand, but found a '"+c+"'."); } int dimensions2create = o.getDimensions(); if (dimensions2create < 1){ constraintViolated(o, "Number of dimensions to create must be greater than zero."); } Type t = o.getType(cpg); if (t instanceof ArrayType){ int dimensions = ((ArrayType) t).getDimensions(); if (dimensions < dimensions2create){ constraintViolated(o, "Not allowed to create array with more dimensions ('+dimensions2create+') than the one referenced by the CONSTANT_Class '"+t+"'."); } } else{ constraintViolated(o, "Expecting a CONSTANT_Class referencing an array type. [Constraint not found in The Java Virtual Machine Specification, Second Edition, 4.8.1]"); } }
/** Checks if the constraints of operands of the said instruction(s) are satisfied. */ @Override public void visitMULTIANEWARRAY(final MULTIANEWARRAY o) { indexValid(o, o.getIndex()); final Constant c = cpg.getConstant(o.getIndex()); if (! (c instanceof ConstantClass)) { constraintViolated(o, "Expecting a CONSTANT_Class operand, but found a '"+c+"'."); } final int dimensions2create = o.getDimensions(); if (dimensions2create < 1) { constraintViolated(o, "Number of dimensions to create must be greater than zero."); } final Type t = o.getType(cpg); if (t instanceof ArrayType) { final int dimensions = ((ArrayType) t).getDimensions(); if (dimensions < dimensions2create) { constraintViolated(o, "Not allowed to create array with more dimensions ('"+dimensions2create+ "') than the one referenced by the CONSTANT_Class '"+t+"'."); } } else{ constraintViolated(o, "Expecting a CONSTANT_Class referencing an array type."+ " [Constraint not found in The Java Virtual Machine Specification, Second Edition, 4.8.1]"); } }