00001 package de.fub.bytecode.generic;
00002
00003 import de.fub.bytecode.Constants;
00004 import java.io.*;
00005
00006
00007
00008
00009
00010
00011
00012
00013 public final class PUSH
00014 implements CompoundInstruction, VariableLengthInstruction, InstructionConstants
00015 {
00016 private Instruction instruction;
00017
00018
00019
00020
00021
00022 public PUSH(ConstantPoolGen cp, double value) {
00023 if(value == 0.0)
00024 instruction = DCONST_0;
00025 else if(value == 1.0)
00026 instruction = DCONST_1;
00027 else
00028 instruction = new LDC2_W(cp.addDouble(value));
00029 }
00030
00031
00032
00033
00034 public PUSH(ConstantPoolGen cp, float value) {
00035 if(value == 0.0)
00036 instruction = FCONST_0;
00037 else if(value == 1.0)
00038 instruction = FCONST_1;
00039 else if(value == 2.0)
00040 instruction = FCONST_2;
00041 else
00042 instruction = new LDC(cp.addFloat(value));
00043 }
00044
00045
00046
00047
00048
00049
00050 public PUSH(ConstantPoolGen cp, int value) {
00051 if((value >= -1) && (value <= 5))
00052 instruction = INSTRUCTIONS[Constants.ICONST_0 + value];
00053 else if((value >= -128) && (value <= 127))
00054 instruction = new BIPUSH((byte)value);
00055 else if((value >= -32768) && (value <= 32767))
00056 instruction = new SIPUSH((short)value);
00057 else
00058 instruction = new LDC(cp.addInteger(value));
00059 }
00060
00061
00062
00063
00064 public PUSH(ConstantPoolGen cp, long value) {
00065 if(value == 0)
00066 instruction = LCONST_0;
00067 else if(value == 1)
00068 instruction = LCONST_1;
00069 else
00070 instruction = new LDC2_W(cp.addLong(value));
00071 }
00072
00073
00074
00075
00076 public PUSH(ConstantPoolGen cp, Boolean value) {
00077 this(cp, value.booleanValue());
00078 }
00079
00080
00081
00082
00083 public PUSH(ConstantPoolGen cp, Character value) {
00084 this(cp, (int)value.charValue());
00085 }
00086
00087
00088
00089
00090 public PUSH(ConstantPoolGen cp, Number value) {
00091 if((value instanceof Integer) || (value instanceof Short) || (value instanceof Byte))
00092 instruction = new PUSH(cp, value.intValue()).instruction;
00093 else if(value instanceof Double)
00094 instruction = new PUSH(cp, value.doubleValue()).instruction;
00095 else if(value instanceof Float)
00096 instruction = new PUSH(cp, value.floatValue()).instruction;
00097 else if(value instanceof Long)
00098 instruction = new PUSH(cp, value.longValue()).instruction;
00099 else
00100 throw new ClassGenException("What's this: " + value);
00101 }
00102
00103
00104
00105
00106 public PUSH(ConstantPoolGen cp, String value) {
00107 if(value == null)
00108 instruction = ACONST_NULL;
00109 else
00110 instruction = new LDC(cp.addString(value));
00111 }
00112
00113
00114
00115
00116 public PUSH(ConstantPoolGen cp, boolean value) {
00117 instruction = INSTRUCTIONS[Constants.ICONST_0 + (value? 1 : 0)];
00118 }
00119 public final Instruction getInstruction() {
00120 return instruction;
00121 }
00122 public final InstructionList getInstructionList() {
00123 return new InstructionList(instruction);
00124 }
00125
00126
00127
00128 public String toString() {
00129 return instruction.toString() + " (PUSH)";
00130 }
00131 }