1 package com.sun.org.apache.bcel.internal.generic; 2 3 56 import com.sun.org.apache.bcel.internal.Constants; 57 import java.io.*; 58 59 66 public final class PUSH 67 implements CompoundInstruction, VariableLengthInstruction, InstructionConstants 68 { 69 private Instruction instruction; 70 71 77 public PUSH(ConstantPoolGen cp, int value) { 78 if((value >= -1) && (value <= 5)) instruction = INSTRUCTIONS[Constants.ICONST_0 + value]; 80 else if((value >= -128) && (value <= 127)) instruction = new BIPUSH((byte)value); 82 else if((value >= -32768) && (value <= 32767)) instruction = new SIPUSH((short)value); 84 else instruction = new LDC(cp.addInteger(value)); 86 } 87 88 92 public PUSH(ConstantPoolGen cp, boolean value) { 93 instruction = INSTRUCTIONS[Constants.ICONST_0 + (value? 1 : 0)]; 94 } 95 96 100 public PUSH(ConstantPoolGen cp, float value) { 101 if(value == 0.0) 102 instruction = FCONST_0; 103 else if(value == 1.0) 104 instruction = FCONST_1; 105 else if(value == 2.0) 106 instruction = FCONST_2; 107 else instruction = new LDC(cp.addFloat(value)); 109 } 110 111 115 public PUSH(ConstantPoolGen cp, long value) { 116 if(value == 0) 117 instruction = LCONST_0; 118 else if(value == 1) 119 instruction = LCONST_1; 120 else instruction = new LDC2_W(cp.addLong(value)); 122 } 123 124 128 public PUSH(ConstantPoolGen cp, double value) { 129 if(value == 0.0) 130 instruction = DCONST_0; 131 else if(value == 1.0) 132 instruction = DCONST_1; 133 else instruction = new LDC2_W(cp.addDouble(value)); 135 } 136 137 141 public PUSH(ConstantPoolGen cp, String value) { 142 if(value == null) 143 instruction = ACONST_NULL; 144 else instruction = new LDC(cp.addString(value)); 146 } 147 148 152 public PUSH(ConstantPoolGen cp, Number value) { 153 if((value instanceof Integer ) || (value instanceof Short ) || (value instanceof Byte )) 154 instruction = new PUSH(cp, value.intValue()).instruction; 155 else if(value instanceof Double ) 156 instruction = new PUSH(cp, value.doubleValue()).instruction; 157 else if(value instanceof Float ) 158 instruction = new PUSH(cp, value.floatValue()).instruction; 159 else if(value instanceof Long ) 160 instruction = new PUSH(cp, value.longValue()).instruction; 161 else 162 throw new ClassGenException("What's this: " + value); 163 } 164 165 169 public PUSH(ConstantPoolGen cp, Character value) { 170 this(cp, (int)value.charValue()); 171 } 172 173 177 public PUSH(ConstantPoolGen cp, Boolean value) { 178 this(cp, value.booleanValue()); 179 } 180 181 public final InstructionList getInstructionList() { 182 return new InstructionList(instruction); 183 } 184 185 public final Instruction getInstruction() { 186 return instruction; 187 } 188 189 192 public String toString() { 193 return instruction.toString() + " (PUSH)"; 194 } 195 } 196 197 | Popular Tags |