KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > logicalcobwebs > 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  * Contact: Eric.Bruneton@rd.francetelecom.com
31  *
32  * Author: Eric Bruneton
33  */

34
35 package org.logicalcobwebs.asm;
36
37 /**
38  * A visitor to visit the bytecode instructions of a Java method. The methods
39  * of this visitor must be called in the sequential order of the bytecode
40  * instructions of the visited code. The {@link #visitMaxs visitMaxs} method
41  * must be called after all the instructions have been visited. The {@link
42  * #visitTryCatchBlock visitTryCatchBlock}, {@link #visitLocalVariable
43  * visitLocalVariable} and {@link #visitLineNumber visitLineNumber} methods may
44  * be called in any order, at any time (provided the labels passed as arguments
45  * have already been visited with {@link #visitLabel visitLabel}).
46  */

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

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

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

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

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

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

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

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

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

178   /**
179    * Visits a LDC instruction.
180    *
181    * @param cst the constant to be loaded on the stack. This parameter must be
182    * a non null {@link java.lang.Integer Integer}, a {@link java.lang.Float
183    * Float}, a {@link java.lang.Long Long}, a {@link java.lang.Double
184    * Double} or a {@link String String}.
185    */

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

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

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

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

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

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

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

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

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

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

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

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

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