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