1 17 package org.apache.bcel.generic; 18 19 import java.io.DataOutputStream ; 20 import java.io.IOException ; 21 import org.apache.bcel.util.ByteSequence; 22 23 29 public class IINC extends LocalVariableInstruction { 30 31 private boolean wide; 32 private int c; 33 34 35 39 IINC() { 40 } 41 42 43 47 public IINC(int n, int c) { 48 super(); this.opcode = org.apache.bcel.Constants.IINC; 50 this.length = (short) 3; 51 setIndex(n); setIncrement(c); 53 } 54 55 56 60 public void dump( DataOutputStream out ) throws IOException { 61 if (wide) { 62 out.writeByte(org.apache.bcel.Constants.WIDE); 63 } 64 out.writeByte(opcode); 65 if (wide) { 66 out.writeShort(n); 67 out.writeShort(c); 68 } else { 69 out.writeByte(n); 70 out.writeByte(c); 71 } 72 } 73 74 75 private final void setWide() { 76 wide = (n > org.apache.bcel.Constants.MAX_BYTE) || (Math.abs(c) > Byte.MAX_VALUE); 77 if (wide) { 78 length = 6; } else { 80 length = 3; 81 } 82 } 83 84 85 88 protected void initFromFile( ByteSequence bytes, boolean wide ) throws IOException { 89 this.wide = wide; 90 if (wide) { 91 length = 6; 92 n = bytes.readUnsignedShort(); 93 c = bytes.readShort(); 94 } else { 95 length = 3; 96 n = bytes.readUnsignedByte(); 97 c = bytes.readByte(); 98 } 99 } 100 101 102 105 public String toString( boolean verbose ) { 106 return super.toString(verbose) + " " + c; 107 } 108 109 110 113 public final void setIndex( int n ) { 114 if (n < 0) { 115 throw new ClassGenException("Negative index value: " + n); 116 } 117 this.n = n; 118 setWide(); 119 } 120 121 122 125 public final int getIncrement() { 126 return c; 127 } 128 129 130 133 public final void setIncrement( int c ) { 134 this.c = c; 135 setWide(); 136 } 137 138 139 141 public Type getType( ConstantPoolGen cp ) { 142 return Type.INT; 143 } 144 145 146 154 public void accept( Visitor v ) { 155 v.visitLocalVariableInstruction(this); 156 v.visitIINC(this); 157 } 158 } 159 | Popular Tags |