1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.jdo.impl.enhancer.classfile;
20
21
22 import java.io.PrintStream;
23 import java.util.Stack;
24
25 /***
26 * Special instruction form for the opc_iinc instruction
27 */
28 public class InsnIInc extends Insn {
29
30
31 private int localVarIndex;
32
33
34 private int value;
35
36
37
38 public int nStackArgs() {
39 return 0;
40 }
41
42 public int nStackResults() {
43 return 0;
44 }
45
46 /***
47 * What are the types of the stack operands ?
48 */
49 public String argTypes() {
50 return "";
51 }
52
53 /***
54 * What are the types of the stack results?
55 */
56 public String resultTypes() {
57 return "";
58 }
59
60 public boolean branches() {
61 return false;
62 }
63
64 /***
65 * The local variable slot to be incremented
66 */
67 public int varIndex() {
68 return localVarIndex;
69 }
70
71 /***
72 * The amount by which the slot is to be incremented
73 */
74 public int incrValue() {
75 return value;
76 }
77
78 /***
79 * Constructor for opc_iinc instruction
80 */
81 public InsnIInc (int localVarIndex, int value) {
82 this(localVarIndex, value, NO_OFFSET);
83 }
84
85 /***
86 * Compares this instance with another for structural equality.
87 */
88
89 public boolean isEqual(Stack msg, Object obj) {
90 if (!(obj instanceof InsnIInc)) {
91 msg.push("obj/obj.getClass() = "
92 + (obj == null ? null : obj.getClass()));
93 msg.push("this.getClass() = "
94 + this.getClass());
95 return false;
96 }
97 InsnIInc other = (InsnIInc)obj;
98
99 if (!super.isEqual(msg, other)) {
100 return false;
101 }
102
103 if (this.localVarIndex != other.localVarIndex) {
104 msg.push(String.valueOf("localVarIndex = "
105 + other.localVarIndex));
106 msg.push(String.valueOf("localVarIndex = "
107 + this.localVarIndex));
108 return false;
109 }
110 if (this.value != other.value) {
111 msg.push(String.valueOf("value = "
112 + other.value));
113 msg.push(String.valueOf("value = "
114 + this.value));
115 return false;
116 }
117 return true;
118 }
119
120 /* package local methods *//package-summary/html">class="comment"> package local methods *//package-summary.html">
121
122 InsnIInc (int localVarIndex, int value, int pc) {
123 super(opc_iinc, pc);
124
125 this.localVarIndex = localVarIndex;
126 this.value =value;
127 }
128
129 void print (PrintStream out, int indent) {
130 ClassPrint.spaces(out, indent);
131 out.println(offset() + " opc_iinc " +
132 localVarIndex + "," + value);
133 }
134
135 int store(byte[] buf, int index) {
136 if (isWide())
137 buf[index++] = (byte) opc_wide;
138 buf[index++] = (byte) opcode();
139 if (isWide()) {
140 index = storeShort(buf, index, (short) localVarIndex);
141 index = storeShort(buf, index, (short) value);
142 } else {
143 buf[index++] = (byte)localVarIndex;
144 buf[index++] = (byte)value;
145 }
146 return index;
147 }
148
149 int size() {
150 return isWide() ? 6 : 3;
151 }
152
153 private boolean isWide() {
154 return (value > 127 || value < -128 || localVarIndex > 255);
155 }
156
157 }