View Javadoc

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