View Javadoc

1   /*
2    * Copyright 2005 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at 
7    * 
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software 
11   * distributed under the License is distributed on an "AS IS" BASIS, 
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
13   * See the License for the specific language governing permissions and 
14   * limitations under the License.
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      /* The number of arguments to the interface method */
28      private int nArgsOp;
29  
30      /* public accessors */
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      //@olsen: added method
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">/* package local methods *//package-summary.html">class="comment"> package local methods */
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(); // eat reserved arg
144         return new InsnInterfaceInvoke(iface, nArgs, myPC);
145     }
146 }