00001 package de.fub.bytecode.generic;
00002
00003 import java.io.*;
00004 import de.fub.bytecode.util.ByteSequence;
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 public class LDC extends CPInstruction implements PushInstruction, ExceptionThrower {
00015
00016
00017
00018
00019 LDC() {}
00020 public LDC(int index) {
00021 super(LDC_W, index);
00022 setSize();
00023 }
00024
00025
00026
00027
00028 public void dump(DataOutputStream out) throws IOException {
00029 out.writeByte(tag);
00030
00031 if(length == 2)
00032 out.writeByte(index);
00033 else
00034 out.writeShort(index);
00035 }
00036 public Class[] getExceptions() { return EXCS_STRING_RESOLUTION; }
00037 public Type getType(ConstantPoolGen cpg) {
00038 switch(cpg.getConstantPool().getConstant(index).getTag()) {
00039 case CONSTANT_String: return Type.STRING;
00040 case CONSTANT_Float: return Type.FLOAT;
00041 case CONSTANT_Integer: return Type.INT;
00042 default:
00043 throw new RuntimeException("Unknown constant type " + tag);
00044 }
00045 }
00046
00047
00048
00049 protected void initFromFile(ByteSequence bytes, boolean wide)
00050 throws IOException
00051 {
00052 length = 2;
00053 index = bytes.readUnsignedByte();
00054 }
00055
00056
00057
00058 public final void setIndex(int index) {
00059 super.setIndex(index);
00060 setSize();
00061 }
00062
00063 protected final void setSize() {
00064 if(index <= MAX_BYTE) {
00065 tag = LDC;
00066 length = 2;
00067 } else {
00068 tag = LDC_W;
00069 length = 3;
00070 }
00071 }
00072 }