KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > libraries > asm > tree > analysis > Interpreter


1 /***
2  * ASM: a very small and fast Java bytecode manipulation framework
3  * Copyright (c) 2000,2002,2003 INRIA, France Telecom
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  * 3. Neither the name of the copyright holders nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28  * THE POSSIBILITY OF SUCH DAMAGE.
29  */

30
31 package oracle.toplink.libraries.asm.tree.analysis;
32
33 import java.util.List JavaDoc;
34
35 import oracle.toplink.libraries.asm.Type;
36 import oracle.toplink.libraries.asm.tree.AbstractInsnNode;
37
38 /**
39  * A semantic bytecode interpreter. More precisely, this interpreter only
40  * manages the computation of values from other values: it does not manage the
41  * transfer of values to or from the stack, and to or from the local variables.
42  * This separation allows a generic bytecode {@link Analyzer} to work with
43  * various semantic interpreters, without needing to duplicate the code to
44  * simulate the transfer of values.
45  *
46  * @author Eric Bruneton
47  */

48
49 public interface Interpreter {
50   
51   /**
52    * Creates a new value that represents the given type.
53    *
54    * @param type a primitive or reference type, or <tt>null</tt> to represent an
55    * uninitialized value.
56    * @return a value that represents the given type. The size of the returned
57    * value must be equal to the size of the given type.
58    */

59   
60   Value newValue (Type type);
61   
62   /**
63    * Interprets a bytecode instruction without arguments. This method is called
64    * for the following opcodes:
65    *
66    * ACONST_NULL,
67    * ICONST_M1, ICONST_0, ICONST_1, ICONST_2, ICONST_3, ICONST_4, ICONST_5,
68    * LCONST_0, LCONST_1, FCONST_0, FCONST_1, FCONST_2, DCONST_0, DCONST_1,
69    * BIPUSH, SIPUSH, LDC,
70    * JSR,
71    * GETSTATIC,
72    * NEW
73    *
74    * @param insn the bytecode instruction to be interpreted.
75    * @return the result of the interpretation of the given instruction.
76    * @throws AnalyzerException if an error occured during the interpretation.
77    */

78   
79   Value newOperation (AbstractInsnNode insn) throws AnalyzerException;
80   
81   /**
82    * Interprets a bytecode instruction that moves a value on the stack or to or
83    * from local variables. This method is called for the following opcodes:
84    *
85    * ILOAD, LLOAD, FLOAD, DLOAD, ALOAD, ISTORE, LSTORE, FSTORE, DSTORE, ASTORE,
86    * DUP, DUP_X1, DUP_X2, DUP2, DUP2_X1, DUP2_X2,
87    * SWAP
88    *
89    * @param insn the bytecode instruction to be interpreted.
90    * @param value the value that must be moved by the instruction.
91    * @return the result of the interpretation of the given instruction. The
92    * returned value must be {@link Value#equals(Value) equal} to the given
93    * value.
94    * @throws AnalyzerException if an error occured during the interpretation.
95    */

96   
97   Value copyOperation (AbstractInsnNode insn, Value value)
98     throws AnalyzerException;
99   
100   /**
101    * Interprets a bytecode instruction with a single argument. This method is
102    * called for the following opcodes:
103    *
104    * INEG, LNEG, FNEG, DNEG,
105    * IINC,
106    * I2L, I2F, I2D, L2I, L2F, L2D, F2I, F2L, F2D, D2I, D2L, D2F, I2B, I2C, I2S,
107    * IFEQ, IFNE, IFLT, IFGE, IFGT, IFLE,
108    * TABLESWITCH,
109    * LOOKUPSWITCH,
110    * IRETURN, LRETURN, FRETURN, DRETURN, ARETURN,
111    * PUTSTATIC,
112    * GETFIELD,
113    * NEWARRAY, ANEWARRAY,
114    * ARRAYLENGTH,
115    * ATHROW,
116    * CHECKCAST, INSTANCEOF,
117    * MONITORENTER, MONITOREXIT,
118    * IFNULL, IFNONNULL
119    *
120    * @param insn the bytecode instruction to be interpreted.
121    * @param value the argument of the instruction to be interpreted.
122    * @return the result of the interpretation of the given instruction.
123    * @throws AnalyzerException if an error occured during the interpretation.
124    */

125   
126   Value unaryOperation (AbstractInsnNode insn, Value value)
127     throws AnalyzerException;
128   
129   /**
130    * Interprets a bytecode instruction with two arguments. This method is
131    * called for the following opcodes:
132    *
133    * IALOAD, LALOAD, FALOAD, DALOAD, AALOAD, BALOAD, CALOAD, SALOAD,
134    * IADD, LADD, FADD, DADD, ISUB, LSUB, FSUB, DSUB, IMUL, LMUL, FMUL, DMUL,
135    * IDIV, LDIV, FDIV, DDIV, IREM, LREM, FREM, DREM,
136    * ISHL, LSHL, ISHR, LSHR, IUSHR, LUSHR,
137    * IAND, LAND, IOR, LOR, IXOR, LXOR,
138    * LCMP, FCMPL, FCMPG, DCMPL, DCMPG,
139    * IF_ICMPEQ, IF_ICMPNE, IF_ICMPLT, IF_ICMPGE, IF_ICMPGT, IF_ICMPLE,
140    * IF_ACMPEQ, IF_ACMPNE,
141    * PUTFIELD
142    *
143    * @param insn the bytecode instruction to be interpreted.
144    * @param value1 the first argument of the instruction to be interpreted.
145    * @param value2 the second argument of the instruction to be interpreted.
146    * @return the result of the interpretation of the given instruction.
147    * @throws AnalyzerException if an error occured during the interpretation.
148    */

149   
150   Value binaryOperation (AbstractInsnNode insn, Value value1, Value value2)
151     throws AnalyzerException;
152   
153   /**
154    * Interprets a bytecode instruction with three arguments. This method is
155    * called for the following opcodes:
156    *
157    * IASTORE, LASTORE, FASTORE, DASTORE, AASTORE, BASTORE, CASTORE, SASTORE
158    *
159    * @param insn the bytecode instruction to be interpreted.
160    * @param value1 the first argument of the instruction to be interpreted.
161    * @param value2 the second argument of the instruction to be interpreted.
162    * @param value3 the third argument of the instruction to be interpreted.
163    * @return the result of the interpretation of the given instruction.
164    * @throws AnalyzerException if an error occured during the interpretation.
165    */

166   
167   Value ternaryOperation (AbstractInsnNode insn, Value value1, Value value2, Value value3)
168     throws AnalyzerException;
169
170   /**
171    * Interprets a bytecode instruction with a variable number of arguments.
172    * This method is called for the following opcodes:
173    *
174    * INVOKEVIRTUAL, INVOKESPECIAL, INVOKESTATIC, INVOKEINTERFACE,
175    * MULTIANEWARRAY
176    *
177    * @param insn the bytecode instruction to be interpreted.
178    * @param values the arguments of the instruction to be interpreted.
179    * @return the result of the interpretation of the given instruction.
180    * @throws AnalyzerException if an error occured during the interpretation.
181    */

182   
183   Value naryOperation (AbstractInsnNode insn, List JavaDoc values)
184     throws AnalyzerException;
185   
186   /**
187    * Merges two values. The merge operation must return a value that represents
188    * both values (for instance, if the two values are two types, the merged
189    * value must be a common super type of the two types. If the two values are
190    * integer intervals, the merged value must be an interval that contains the
191    * previous ones. Likewise for other types of values).
192    *
193    * @param v a value.
194    * @param w another value.
195    * @return the merged value. If the merged value is equal to <tt>v</tt>, this
196    * method <i>must</i> return <tt>v</tt>.
197    */

198   
199   Value merge (Value v, Value w);
200 }
201
Popular Tags