FileDocCategorySizeDatePackage
PUSH.javaAPI DocJava SE 6 API6644Tue Jun 10 00:22:22 BST 2008com.sun.org.apache.bcel.internal.generic

PUSH

public final class PUSH extends Object implements CompoundInstruction, VariableLengthInstruction, InstructionConstants
Wrapper class for push operations, which are implemented either as BIPUSH, LDC or xCONST_n instructions.
version
$Id: PUSH.java,v 1.1.2.1 2005/07/31 23:44:54 jeffsuttor Exp $
author
M. Dahm

Fields Summary
private Instruction
instruction
Constructors Summary
public PUSH(ConstantPoolGen cp, int value)
This constructor also applies for values of type short, char, byte

param
cp Constant pool
param
value to be pushed

    if((value >= -1) && (value <= 5)) // Use ICONST_n
      instruction = INSTRUCTIONS[Constants.ICONST_0 + value];
    else if((value >= -128) && (value <= 127)) // Use BIPUSH
      instruction = new BIPUSH((byte)value);
    else if((value >= -32768) && (value <= 32767)) // Use SIPUSH
      instruction = new SIPUSH((short)value);
    else // If everything fails create a Constant pool entry
      instruction = new LDC(cp.addInteger(value));
  
public PUSH(ConstantPoolGen cp, boolean value)

param
cp Constant pool
param
value to be pushed

    instruction = INSTRUCTIONS[Constants.ICONST_0 + (value? 1 : 0)];
  
public PUSH(ConstantPoolGen cp, float value)

param
cp Constant pool
param
value to be pushed

    if(value == 0.0)
      instruction = FCONST_0;
    else if(value == 1.0)
      instruction = FCONST_1;
    else if(value == 2.0)
      instruction = FCONST_2;
    else // Create a Constant pool entry
      instruction = new LDC(cp.addFloat(value));
  
public PUSH(ConstantPoolGen cp, long value)

param
cp Constant pool
param
value to be pushed

    if(value == 0)
      instruction = LCONST_0;
    else if(value == 1)
      instruction = LCONST_1;
    else // Create a Constant pool entry
      instruction = new LDC2_W(cp.addLong(value));
  
public PUSH(ConstantPoolGen cp, double value)

param
cp Constant pool
param
value to be pushed

    if(value == 0.0)
      instruction = DCONST_0;
    else if(value == 1.0)
      instruction = DCONST_1;
    else // Create a Constant pool entry
      instruction = new LDC2_W(cp.addDouble(value));
  
public PUSH(ConstantPoolGen cp, String value)

param
cp Constant pool
param
value to be pushed

    if(value == null)
      instruction = ACONST_NULL;
    else // Create a Constant pool entry
      instruction = new LDC(cp.addString(value));
  
public PUSH(ConstantPoolGen cp, Number value)

param
cp Constant pool
param
value to be pushed

    if((value instanceof Integer) || (value instanceof Short) || (value instanceof Byte))
      instruction = new PUSH(cp, value.intValue()).instruction;
    else if(value instanceof Double)
      instruction = new PUSH(cp, value.doubleValue()).instruction;
    else if(value instanceof Float)
      instruction = new PUSH(cp, value.floatValue()).instruction;
    else if(value instanceof Long)
      instruction = new PUSH(cp, value.longValue()).instruction;
    else
      throw new ClassGenException("What's this: " + value);
  
public PUSH(ConstantPoolGen cp, Character value)

param
cp Constant pool
param
value to be pushed

    this(cp, (int)value.charValue());
  
public PUSH(ConstantPoolGen cp, Boolean value)

param
cp Constant pool
param
value to be pushed

    this(cp, value.booleanValue());
  
Methods Summary
public final com.sun.org.apache.bcel.internal.generic.InstructiongetInstruction()

    return instruction;
  
public final com.sun.org.apache.bcel.internal.generic.InstructionListgetInstructionList()

    return new InstructionList(instruction);
  
public java.lang.StringtoString()

return
mnemonic for instruction

    return instruction.toString() + " (PUSH)";