1 package com.sun.org.apache.bcel.internal.generic; 2 3 56 import java.io.*; 57 import com.sun.org.apache.bcel.internal.util.ByteSequence; 58 59 65 public class IINC extends LocalVariableInstruction { 66 private boolean wide; 67 private int c; 68 69 73 IINC() {} 74 75 public IINC(int n, int c) { 76 super(); 78 this.opcode = com.sun.org.apache.bcel.internal.Constants.IINC; 79 this.length = (short)3; 80 81 setIndex(n); setIncrement(c); 83 } 84 85 89 public void dump(DataOutputStream out) throws IOException { 90 if(wide) out.writeByte(com.sun.org.apache.bcel.internal.Constants.WIDE); 92 93 out.writeByte(opcode); 94 95 if(wide) { 96 out.writeShort(n); 97 out.writeShort(c); 98 } else { 99 out.writeByte(n); 100 out.writeByte(c); 101 } 102 } 103 104 private final void setWide() { 105 if(wide = ((n > com.sun.org.apache.bcel.internal.Constants.MAX_SHORT) || 106 (Math.abs(c) > Byte.MAX_VALUE))) 107 length = 6; else 109 length = 3; 110 } 111 112 115 protected void initFromFile(ByteSequence bytes, boolean wide) throws IOException 116 { 117 this.wide = wide; 118 119 if(wide) { 120 length = 6; 121 n = bytes.readUnsignedShort(); 122 c = bytes.readShort(); 123 } else { 124 length = 3; 125 n = bytes.readUnsignedByte(); 126 c = bytes.readByte(); 127 } 128 } 129 130 133 public String toString(boolean verbose) { 134 return super.toString(verbose) + " " + c; 135 } 136 137 140 public final void setIndex(int n) { 141 if(n < 0) 142 throw new ClassGenException("Negative index value: " + n); 143 144 this.n = n; 145 setWide(); 146 } 147 148 151 public final int getIncrement() { return c; } 152 153 156 public final void setIncrement(int c) { 157 this.c = c; 158 setWide(); 159 } 160 161 163 public Type getType(ConstantPoolGen cp) { 164 return Type.INT; 165 } 166 167 175 public void accept(Visitor v) { 176 v.visitLocalVariableInstruction(this); 177 v.visitIINC(this); 178 } 179 } 180 | Popular Tags |