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 public class IINC extends Instruction {
00013 private boolean wide;
00014 private int n, c;
00015
00016
00017
00018
00019
00020 IINC() {}
00021 public IINC(int n, int c) {
00022 super(IINC, (short)3);
00023
00024 setIndex(n);
00025 setIncrement(c);
00026
00027 this.n = n;
00028 this.c = c;
00029 }
00030
00031
00032
00033
00034 public void dump(DataOutputStream out) throws IOException {
00035 if(wide)
00036 out.writeByte(WIDE);
00037
00038 out.writeByte(tag);
00039
00040 if(wide) {
00041 out.writeShort(n);
00042 out.writeShort(c);
00043 }
00044 else {
00045 out.writeByte(n);
00046 out.writeByte(c);
00047 }
00048 }
00049
00050
00051
00052 public final int getIncrement() { return c; }
00053
00054
00055
00056 public final int getIndex() { return n; }
00057
00058
00059
00060 protected void initFromFile(ByteSequence bytes, boolean wide) throws IOException
00061 {
00062 this.wide = wide;
00063
00064 if(wide) {
00065 length = 6;
00066 n = bytes.readUnsignedShort();
00067 c = bytes.readShort();
00068 }
00069 else {
00070 length = 3;
00071 n = bytes.readUnsignedByte();
00072 c = bytes.readByte();
00073 }
00074 }
00075
00076
00077
00078 public final void setIncrement(int c) {
00079 this.c = c;
00080 setWide();
00081 }
00082
00083
00084
00085 public final void setIndex(int n) {
00086 if(n < 0)
00087 throw new ClassGenException("Negative index value: " + n);
00088
00089 this.n = n;
00090 setWide();
00091 }
00092 private final void setWide() {
00093 if(wide = ((n > MAX_SHORT) || (Math.abs(c) > Byte.MAX_VALUE)))
00094 length = 6;
00095 else
00096 length = 3;
00097 }
00098
00099
00100
00101 public String toString(boolean verbose) {
00102 return super.toString(verbose) + " " + n + " " + c;
00103 }
00104 }