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_invokeinterface instruction
25 */
26 public class InsnInterfaceInvoke extends InsnConstOp {
27
28 private int nArgsOp;
29
30
31
32 public int nStackArgs() {
33 return super.nStackArgs();
34 }
35
36 public int nStackResults() {
37 return super.nStackResults();
38 }
39
40 /***
41 * What are the types of the stack operands ?
42 */
43 public String argTypes() {
44 return super.argTypes();
45 }
46
47 /***
48 * What are the types of the stack results?
49 */
50 public String resultTypes() {
51 return super.resultTypes();
52 }
53
54 public boolean branches() {
55 return false;
56 }
57
58 /***
59 * Return the interface to be invoked
60 */
61 public ConstInterfaceMethodRef method() {
62 return (ConstInterfaceMethodRef) value();
63 }
64
65 /***
66 * Return the number of arguments to the interface
67 */
68 public int nArgs() {
69 return nArgsOp;
70 }
71
72 /***
73 * constructor for opc_invokeinterface
74 */
75 public InsnInterfaceInvoke (ConstInterfaceMethodRef methodRefOp,
76 int nArgsOp) {
77 this(methodRefOp, nArgsOp, NO_OFFSET);
78 }
79
80 /***
81 * Compares this instance with another for structural equality.
82 */
83
84 public boolean isEqual(Stack msg, Object obj) {
85 if (!(obj instanceof InsnInterfaceInvoke)) {
86 msg.push("obj/obj.getClass() = "
87 + (obj == null ? null : obj.getClass()));
88 msg.push("this.getClass() = "
89 + this.getClass());
90 return false;
91 }
92 InsnInterfaceInvoke other = (InsnInterfaceInvoke)obj;
93
94 if (!super.isEqual(msg, other)) {
95 return false;
96 }
97
98 if (this.nArgsOp != other.nArgsOp) {
99 msg.push(String.valueOf("nArgsOp = "
100 + other.nArgsOp));
101 msg.push(String.valueOf("nArgsOp = "
102 + this.nArgsOp));
103 return false;
104 }
105 return true;
106 }
107
108 /* package local methods *//package-summary/html">class="comment"> package local methods *//package-summary.html">
109
110 InsnInterfaceInvoke (ConstInterfaceMethodRef methodRefOp, int nArgsOp,
111 int offset) {
112 super(opc_invokeinterface, methodRefOp, offset);
113
114 this.nArgsOp = nArgsOp;
115
116 if (methodRefOp == null || nArgsOp < 0)
117 throw new InsnError ("attempt to create an opc_invokeinterface" +
118 " with invalid operands");
119 }
120
121 void print (PrintStream out, int indent) {
122 ClassPrint.spaces(out, indent);
123 out.println(offset() + " opc_invokeinterface " +
124 "pool(" + method().getIndex() + ")," + nArgsOp);
125 }
126
127 int store(byte[] buf, int index) {
128 buf[index++] = (byte) opcode();
129 index = storeShort(buf, index, (short)method().getIndex());
130 buf[index++] = (byte) nArgsOp;
131 buf[index++] = (byte) 0;
132 return index;
133 }
134
135 int size() {
136 return 5;
137 }
138
139 static InsnInterfaceInvoke read(InsnReadEnv insnEnv, int myPC) {
140 ConstInterfaceMethodRef iface = (ConstInterfaceMethodRef)
141 insnEnv.pool().constantAt(insnEnv.getUShort());
142 int nArgs = insnEnv.getUByte();
143 insnEnv.getByte();
144 return new InsnInterfaceInvoke(iface, nArgs, myPC);
145 }
146 }