1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.jdo.impl.enhancer.classfile;
19
20 import java.io.PrintStream;
21 import java.util.Stack;
22
23 /***
24 * Special instruction form for the opc_multianewarray instruction
25 */
26 public class InsnMultiDimArrayNew extends Insn {
27
28 private ConstClass classOp;
29
30
31 private int nDimsOp;
32
33
34
35 public boolean isSimpleLoad() {
36 return false;
37 }
38
39 public int nStackArgs() {
40 return nDimsOp;
41 }
42
43 public int nStackResults() {
44 return 1;
45 }
46
47 /***
48 * What are the types of the stack operands ?
49 */
50 public String argTypes() {
51 StringBuffer buf = new StringBuffer();
52 for (int i=0; i<nDimsOp; i++) {
53 buf.append("I");
54 }
55 return buf.toString();
56 }
57
58 /***
59 * What are the types of the stack results?
60 */
61 public String resultTypes() {
62 return "A";
63 }
64
65 public boolean branches() {
66 return false;
67 }
68
69 /***
70 * Return the array class being created
71 */
72 public ConstClass arrayClass() {
73 return classOp;
74 }
75
76 /***
77 * Sets the array class being created
78 */
79 public void setArrayClass(ConstClass classOp) {
80 this.classOp = classOp;
81 }
82
83 /***
84 * Return the number of dimensions of the array class being created
85 */
86 public int nDims() {
87 return nDimsOp;
88 }
89
90 /***
91 * Constructor for opc_multianewarray.
92 * classOp must be an array class
93 * nDimsOp must be > 0 and <= number of array dimensions for classOp
94 */
95 public InsnMultiDimArrayNew (ConstClass classOp, int nDimsOp) {
96 this(classOp, nDimsOp, NO_OFFSET);
97 }
98
99 /***
100 * Compares this instance with another for structural equality.
101 */
102
103 public boolean isEqual(Stack msg, Object obj) {
104 if (!(obj instanceof InsnMultiDimArrayNew)) {
105 msg.push("obj/obj.getClass() = "
106 + (obj == null ? null : obj.getClass()));
107 msg.push("this.getClass() = "
108 + this.getClass());
109 return false;
110 }
111 InsnMultiDimArrayNew other = (InsnMultiDimArrayNew)obj;
112
113 if (!super.isEqual(msg, other)) {
114 return false;
115 }
116
117 if (!this.classOp.isEqual(msg, other.classOp)) {
118 msg.push(String.valueOf("classOp = "
119 + other.classOp));
120 msg.push(String.valueOf("classOp = "
121 + this.classOp));
122 return false;
123 }
124 if (this.nDimsOp != other.nDimsOp) {
125 msg.push(String.valueOf("nDimsOp = "
126 + other.nDimsOp));
127 msg.push(String.valueOf("nDimsOp = "
128 + this.nDimsOp));
129 return false;
130 }
131 return true;
132 }
133
134 /* package local methods *//package-summary/html">class="comment"> package local methods *//package-summary.html">
135
136 InsnMultiDimArrayNew (ConstClass classOp, int nDimsOp, int offset) {
137 super(opc_multianewarray, offset);
138
139 this.classOp = classOp;
140 this.nDimsOp = nDimsOp;
141
142 if (classOp == null || nDimsOp < 1)
143 throw new InsnError ("attempt to create an opc_multianewarray" +
144 " with invalid operands");
145 }
146
147 void print (PrintStream out, int indent) {
148 ClassPrint.spaces(out, indent);
149 out.println(offset() + " opc_multianewarray pool(" +
150 classOp.getIndex() + ")," + nDimsOp);
151 }
152
153 int store(byte[] buf, int index) {
154 buf[index++] = (byte) opcode();
155 index = storeShort(buf, index, (short) classOp.getIndex());
156 buf[index++] = (byte) nDimsOp;
157 return index;
158 }
159
160 int size() {
161 return 4;
162 }
163
164 static InsnMultiDimArrayNew read (InsnReadEnv insnEnv, int myPC) {
165 ConstClass classOp = (ConstClass)
166 insnEnv.pool().constantAt(insnEnv.getUShort());
167 int nDims = insnEnv.getUByte();
168 return new InsnMultiDimArrayNew(classOp, nDims, myPC);
169 }
170 }