KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > libraries > asm > CodeVisitor


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;
32
33 /**
34  * A visitor to visit the bytecode instructions of a Java method. The methods
35  * of this visitor must be called in the sequential order of the bytecode
36  * instructions of the visited code. The {@link #visitMaxs visitMaxs} method
37  * must be called after all the instructions have been visited. The {@link
38  * #visitTryCatchBlock visitTryCatchBlock}, {@link #visitLocalVariable
39  * visitLocalVariable} and {@link #visitLineNumber visitLineNumber} methods may
40  * be called in any order, at any time (provided the labels passed as arguments
41  * have already been visited with {@link #visitLabel visitLabel}).
42  *
43  * @author Eric Bruneton
44  */

45
46 public interface CodeVisitor {
47
48   /**
49    * Visits a zero operand instruction.
50    *
51    * @param opcode the opcode of the instruction to be visited. This opcode is
52    * either NOP, ACONST_NULL, ICONST_M1, ICONST_0, ICONST_1, ICONST_2,
53    * ICONST_3, ICONST_4, ICONST_5, LCONST_0, LCONST_1, FCONST_0, FCONST_1,
54    * FCONST_2, DCONST_0, DCONST_1,
55    *
56    * IALOAD, LALOAD, FALOAD, DALOAD, AALOAD, BALOAD, CALOAD, SALOAD,
57    * IASTORE, LASTORE, FASTORE, DASTORE, AASTORE, BASTORE, CASTORE,
58    * SASTORE,
59    *
60    * POP, POP2, DUP, DUP_X1, DUP_X2, DUP2, DUP2_X1, DUP2_X2, SWAP,
61    *
62    * IADD, LADD, FADD, DADD, ISUB, LSUB, FSUB, DSUB, IMUL, LMUL, FMUL,
63    * DMUL, IDIV, LDIV, FDIV, DDIV, IREM, LREM, FREM, DREM, INEG, LNEG,
64    * FNEG, DNEG, ISHL, LSHL, ISHR, LSHR, IUSHR, LUSHR, IAND, LAND, IOR,
65    * LOR, IXOR, LXOR,
66    *
67    * I2L, I2F, I2D, L2I, L2F, L2D, F2I, F2L, F2D, D2I, D2L, D2F, I2B, I2C,
68    * I2S,
69    *
70    * LCMP, FCMPL, FCMPG, DCMPL, DCMPG,
71    *
72    * IRETURN, LRETURN, FRETURN, DRETURN, ARETURN, RETURN,
73    *
74    * ARRAYLENGTH,
75    *
76    * ATHROW,
77    *
78    * MONITORENTER, or MONITOREXIT.
79    */

80
81   void visitInsn (int opcode);
82
83   /**
84    * Visits an instruction with a single int operand.
85    *
86    * @param opcode the opcode of the instruction to be visited. This opcode is
87    * either BIPUSH, SIPUSH or NEWARRAY.
88    * @param operand the operand of the instruction to be visited.
89    */

90
91   void visitIntInsn (int opcode, int operand);
92
93   /**
94    * Visits a local variable instruction. A local variable instruction is an
95    * instruction that loads or stores the value of a local variable.
96    *
97    * @param opcode the opcode of the local variable instruction to be visited.
98    * This opcode is either ILOAD, LLOAD, FLOAD, DLOAD, ALOAD, ISTORE,
99    * LSTORE, FSTORE, DSTORE, ASTORE or RET.
100    * @param var the operand of the instruction to be visited. This operand is
101    * the index of a local variable.
102    */

103
104   void visitVarInsn (int opcode, int var);
105
106   /**
107    * Visits a type instruction. A type instruction is an instruction that
108    * takes a type descriptor as parameter.
109    *
110    * @param opcode the opcode of the type instruction to be visited. This opcode
111    * is either NEW, ANEWARRAY, CHECKCAST or INSTANCEOF.
112    * @param desc the operand of the instruction to be visited. This operand is
113    * must be a fully qualified class name in internal form, or the type
114    * descriptor of an array type (see {@link Type Type}).
115    */

116
117   void visitTypeInsn (int opcode, String JavaDoc desc);
118
119   /**
120    * Visits a field instruction. A field instruction is an instruction that
121    * loads or stores the value of a field of an object.
122    *
123    * @param opcode the opcode of the type instruction to be visited. This opcode
124    * is either GETSTATIC, PUTSTATIC, GETFIELD or PUTFIELD.
125    * @param owner the internal name of the field's owner class (see {@link
126    * Type#getInternalName() getInternalName}).
127    * @param name the field's name.
128    * @param desc the field's descriptor (see {@link Type Type}).
129    */

130
131   void visitFieldInsn (int opcode, String JavaDoc owner, String JavaDoc name, String JavaDoc desc);
132
133   /**
134    * Visits a method instruction. A method instruction is an instruction that
135    * invokes a method.
136    *
137    * @param opcode the opcode of the type instruction to be visited. This opcode
138    * is either INVOKEVIRTUAL, INVOKESPECIAL, INVOKESTATIC or
139    * INVOKEINTERFACE.
140    * @param owner the internal name of the method's owner class (see {@link
141    * Type#getInternalName() getInternalName}).
142    * @param name the method's name.
143    * @param desc the method's descriptor (see {@link Type Type}).
144    */

145
146   void visitMethodInsn (int opcode, String JavaDoc owner, String JavaDoc name, String JavaDoc desc);
147
148   /**
149    * Visits a jump instruction. A jump instruction is an instruction that may
150    * jump to another instruction.
151    *
152    * @param opcode the opcode of the type instruction to be visited. This opcode
153    * is either IFEQ, IFNE, IFLT, IFGE, IFGT, IFLE, IF_ICMPEQ, IF_ICMPNE,
154    * IF_ICMPLT, IF_ICMPGE, IF_ICMPGT, IF_ICMPLE, IF_ACMPEQ, IF_ACMPNE,
155    * GOTO, JSR, IFNULL or IFNONNULL.
156    * @param label the operand of the instruction to be visited. This operand is
157    * a label that designates the instruction to which the jump instruction
158    * may jump.
159    */

160
161   void visitJumpInsn (int opcode, Label label);
162
163   /**
164    * Visits a label. A label designates the instruction that will be visited
165    * just after it.
166    *
167    * @param label a {@link Label Label} object.
168    */

169
170   void visitLabel (Label label);
171
172   // -------------------------------------------------------------------------
173
// Special instructions
174
// -------------------------------------------------------------------------
175

176   /**
177    * Visits a LDC instruction.
178    *
179    * @param cst the constant to be loaded on the stack. This parameter must be
180    * a non null {@link java.lang.Integer Integer}, a {@link java.lang.Float
181    * Float}, a {@link java.lang.Long Long}, a {@link java.lang.Double
182    * Double} a {@link String String} (or a {@link Type Type} for
183    * <tt>.class</tt> constants, for classes whose version is 49.0 or more).
184    */

185
186   void visitLdcInsn (Object JavaDoc cst);
187
188   /**
189    * Visits an IINC instruction.
190    *
191    * @param var index of the local variable to be incremented.
192    * @param increment amount to increment the local variable by.
193    */

194
195   void visitIincInsn (int var, int increment);
196
197   /**
198    * Visits a TABLESWITCH instruction.
199    *
200    * @param min the minimum key value.
201    * @param max the maximum key value.
202    * @param dflt beginning of the default handler block.
203    * @param labels beginnings of the handler blocks. <tt>labels[i]</tt> is the
204    * beginning of the handler block for the <tt>min + i</tt> key.
205    */

206
207   void visitTableSwitchInsn (int min, int max, Label dflt, Label labels[]);
208
209   /**
210    * Visits a LOOKUPSWITCH instruction.
211    *
212    * @param dflt beginning of the default handler block.
213    * @param keys the values of the keys.
214    * @param labels beginnings of the handler blocks. <tt>labels[i]</tt> is the
215    * beginning of the handler block for the <tt>keys[i]</tt> key.
216    */

217
218   void visitLookupSwitchInsn (Label dflt, int keys[], Label labels[]);
219
220   /**
221    * Visits a MULTIANEWARRAY instruction.
222    *
223    * @param desc an array type descriptor (see {@link Type Type}).
224    * @param dims number of dimensions of the array to allocate.
225    */

226
227   void visitMultiANewArrayInsn (String JavaDoc desc, int dims);
228
229   // -------------------------------------------------------------------------
230
// Exceptions table entries, max stack size and max locals
231
// -------------------------------------------------------------------------
232

233   /**
234    * Visits a try catch block.
235    *
236    * @param start beginning of the exception handler's scope (inclusive).
237    * @param end end of the exception handler's scope (exclusive).
238    * @param handler beginning of the exception handler's code.
239    * @param type internal name of the type of exceptions handled by the handler,
240    * or <tt>null</tt> to catch any exceptions (for "finally" blocks).
241    * @throws IllegalArgumentException if one of the labels has not already been
242    * visited by this visitor (by the {@link #visitLabel visitLabel}
243    * method).
244    */

245
246   void visitTryCatchBlock (Label start, Label end, Label handler, String JavaDoc type);
247
248   /**
249    * Visits the maximum stack size and the maximum number of local variables of
250    * the method.
251    *
252    * @param maxStack maximum stack size of the method.
253    * @param maxLocals maximum number of local variables for the method.
254    */

255
256   void visitMaxs (int maxStack, int maxLocals);
257
258   // -------------------------------------------------------------------------
259
// Debug information
260
// -------------------------------------------------------------------------
261

262   /**
263    * Visits a local variable declaration.
264    *
265    * @param name the name of a local variable.
266    * @param desc the type descriptor of this local variable.
267    * @param start the first instruction corresponding to the scope of this
268    * local variable (inclusive).
269    * @param end the last instruction corresponding to the scope of this
270    * local variable (exclusive).
271    * @param index the local variable's index.
272    * @throws IllegalArgumentException if one of the labels has not already been
273    * visited by this visitor (by the {@link #visitLabel visitLabel}
274    * method).
275    */

276
277   void visitLocalVariable (
278     String JavaDoc name,
279     String JavaDoc desc,
280     Label start,
281     Label end,
282     int index);
283
284   /**
285    * Visits a line number declaration.
286    *
287    * @param line a line number. This number refers to the source file
288    * from which the class was compiled.
289    * @param start the first instruction corresponding to this line number.
290    * @throws IllegalArgumentException if <tt>start</tt> has not already been
291    * visited by this visitor (by the {@link #visitLabel visitLabel}
292    * method).
293    */

294
295   void visitLineNumber (int line, Label start);
296
297   // -------------------------------------------------------------------------
298
// Non standard attributes
299
// -------------------------------------------------------------------------
300

301   /**
302    * Visits a non standard attribute of the code. This method must visit only
303    * the first attribute in the given attribute list.
304    *
305    * @param attr a non standard code attribute. Must not be <tt>null</tt>.
306    */

307
308   void visitAttribute (Attribute attr);
309 }
310
Popular Tags