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 implements IndexedInstruction {
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(de.fub.bytecode.Constants.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
00035
00036
00037
00038 public void accept(Visitor v) {
00039 v.visitIINC(this);
00040 }
00041
00042
00043
00044
00045 public void dump(DataOutputStream out) throws IOException {
00046 if(wide)
00047 out.writeByte(de.fub.bytecode.Constants.WIDE);
00048
00049 out.writeByte(tag);
00050
00051 if(wide) {
00052 out.writeShort(n);
00053 out.writeShort(c);
00054 }
00055 else {
00056 out.writeByte(n);
00057 out.writeByte(c);
00058 }
00059 }
00060
00061
00062
00063 public final int getIncrement() { return c; }
00064
00065
00066
00067 public final int getIndex() { return n; }
00068
00069
00070
00071 protected void initFromFile(ByteSequence bytes, boolean wide) throws IOException
00072 {
00073 this.wide = wide;
00074
00075 if(wide) {
00076 length = 6;
00077 n = bytes.readUnsignedShort();
00078 c = bytes.readShort();
00079 }
00080 else {
00081 length = 3;
00082 n = bytes.readUnsignedByte();
00083 c = bytes.readByte();
00084 }
00085 }
00086
00087
00088
00089 public final void setIncrement(int c) {
00090 this.c = c;
00091 setWide();
00092 }
00093
00094
00095
00096 public final void setIndex(int n) {
00097 if(n < 0)
00098 throw new ClassGenException("Negative index value: " + n);
00099
00100 this.n = n;
00101 setWide();
00102 }
00103 private final void setWide() {
00104 if(wide = ((n > de.fub.bytecode.Constants.MAX_SHORT) || (Math.abs(c) > Byte.MAX_VALUE)))
00105 length = 6;
00106 else
00107 length = 3;
00108 }
00109
00110
00111
00112 public String toString(boolean verbose) {
00113 return super.toString(verbose) + " " + n + " " + c;
00114 }
00115 }