KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > bsh > org > objectweb > asm > CodeVisitor


1 /***
2  * ASM: a very small and fast Java bytecode manipulation framework
3  * Copyright (C) 2000 INRIA, France Telecom
4  * Copyright (C) 2002 France Telecom
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  *
20  * Contact: Eric.Bruneton@rd.francetelecom.com
21  *
22  * Author: Eric Bruneton
23  */

24
25 package bsh.org.objectweb.asm;
26
27 /**
28  * A visitor to visit the bytecode instructions of a Java method. The methods
29  * of this visitor must be called in the sequential order of the bytecode
30  * instructions of the visited code. The {@link #visitMaxs visitMaxs} method
31  * must be called after all the instructions have been visited. The {@link
32  * #visitTryCatchBlock visitTryCatchBlock}, {@link #visitLocalVariable
33  * visitLocalVariable} and {@link #visitLineNumber visitLineNumber} methods may
34  * be called in any order, at any time (provided the labels passed as arguments
35  * have already been visited with {@link #visitLabel visitLabel}).
36  */

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

72
73   void visitInsn (int opcode);
74
75   /**
76    * Visits an instruction with a single int operand.
77    *
78    * @param opcode the opcode of the instruction to be visited. This opcode is
79    * either BIPUSH, SIPUSH or NEWARRAY.
80    * @param operand the operand of the instruction to be visited.
81    */

82
83   void visitIntInsn (int opcode, int operand);
84
85   /**
86    * Visits a local variable instruction. A local variable instruction is an
87    * instruction that loads or stores the value of a local variable.
88    *
89    * @param opcode the opcode of the local variable instruction to be visited.
90    * This opcode is either ILOAD, LLOAD, FLOAD, DLOAD, ALOAD, ISTORE,
91    * LSTORE, FSTORE, DSTORE, ASTORE or RET.
92    * @param var the operand of the instruction to be visited. This operand is
93    * the index of a local variable.
94    */

95
96   void visitVarInsn (int opcode, int var);
97
98   /**
99    * Visits a type instruction. A type instruction is an instruction that
100    * takes a type descriptor as parameter.
101    *
102    * @param opcode the opcode of the type instruction to be visited. This opcode
103    * is either NEW, ANEWARRAY, CHECKCAST or INSTANCEOF.
104    * @param desc the operand of the instruction to be visited. This operand is
105    * must be a fully qualified class name in internal form, or the type
106    * descriptor of an array type (see {@link Type Type}).
107    */

108
109   void visitTypeInsn (int opcode, String JavaDoc desc);
110
111   /**
112    * Visits a field instruction. A field instruction is an instruction that
113    * loads or stores the value of a field of an object.
114    *
115    * @param opcode the opcode of the type instruction to be visited. This opcode
116    * is either GETSTATIC, PUTSTATIC, GETFIELD or PUTFIELD.
117    * @param owner the internal name of the field's owner class (see {@link
118    * Type#getInternalName getInternalName}).
119    * @param name the field's name.
120    * @param desc the field's descriptor (see {@link Type Type}).
121    */

122
123   void visitFieldInsn (int opcode, String JavaDoc owner, String JavaDoc name, String JavaDoc desc);
124
125   /**
126    * Visits a method instruction. A method instruction is an instruction that
127    * invokes a method.
128    *
129    * @param opcode the opcode of the type instruction to be visited. This opcode
130    * is either INVOKEVIRTUAL, INVOKESPECIAL, INVOKESTATIC or
131    * INVOKEINTERFACE.
132    * @param owner the internal name of the method's owner class (see {@link
133    * Type#getInternalName getInternalName}).
134    * @param name the method's name.
135    * @param desc the method's descriptor (see {@link Type Type}).
136    */

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

152
153   void visitJumpInsn (int opcode, Label label);
154
155   /**
156    * Visits a label. A label designates the instruction that will be visited
157    * just after it.
158    *
159    * @param label a {@link Label Label} object.
160    */

161
162   void visitLabel (Label label);
163
164   // -------------------------------------------------------------------------
165
// Special instructions
166
// -------------------------------------------------------------------------
167

168   /**
169    * Visits a LDC instruction.
170    *
171    * @param cst the constant to be loaded on the stack. This parameter must be
172    * a non null {@link java.lang.Integer Integer}, a {@link java.lang.Float
173    * Float}, a {@link java.lang.Long Long}, a {@link java.lang.Double
174    * Double} or a {@link String String}.
175    */

176
177   void visitLdcInsn (Object JavaDoc cst);
178
179   /**
180    * Visits an IINC instruction.
181    *
182    * @param var index of the local variable to be incremented.
183    * @param increment amount to increment the local variable by.
184    */

185
186   void visitIincInsn (int var, int increment);
187
188   /**
189    * Visits a TABLESWITCH instruction.
190    *
191    * @param min the minimum key value.
192    * @param max the maximum key value.
193    * @param dflt beginning of the default handler block.
194    * @param labels beginnings of the handler blocks. <tt>labels[i]</tt> is the
195    * beginning of the handler block for the <tt>min + i</tt> key.
196    */

197
198   void visitTableSwitchInsn (int min, int max, Label dflt, Label labels[]);
199
200   /**
201    * Visits a LOOKUPSWITCH instruction.
202    *
203    * @param dflt beginning of the default handler block.
204    * @param keys the values of the keys.
205    * @param labels beginnings of the handler blocks. <tt>labels[i]</tt> is the
206    * beginning of the handler block for the <tt>keys[i]</tt> key.
207    */

208
209   void visitLookupSwitchInsn (Label dflt, int keys[], Label labels[]);
210
211   /**
212    * Visits a MULTIANEWARRAY instruction.
213    *
214    * @param desc an array type descriptor (see {@link Type Type}).
215    * @param dims number of dimensions of the array to allocate.
216    */

217
218   void visitMultiANewArrayInsn (String JavaDoc desc, int dims);
219
220   // -------------------------------------------------------------------------
221
// Exceptions table entries, max stack size and max locals
222
// -------------------------------------------------------------------------
223

224   /**
225    * Visits a try catch block.
226    *
227    * @param start beginning of the exception handler's scope (inclusive).
228    * @param end end of the exception handler's scope (exclusive).
229    * @param handler beginning of the exception handler's code.
230    * @param type internal name of the type of exceptions handled by the handler,
231    * or <tt>null</tt> to catch any exceptions (for "finally" blocks).
232    * @throws IllegalArgumentException if one of the labels has not already been
233    * visited by this visitor (by the {@link #visitLabel visitLabel}
234    * method).
235    */

236
237   void visitTryCatchBlock (Label start, Label end, Label handler, String JavaDoc type);
238
239   /**
240    * Visits the maximum stack size and the maximum number of local variables of
241    * the method.
242    *
243    * @param maxStack maximum stack size of the method.
244    * @param maxLocals maximum number of local variables for the method.
245    */

246
247   void visitMaxs (int maxStack, int maxLocals);
248
249   // -------------------------------------------------------------------------
250
// Debug information
251
// -------------------------------------------------------------------------
252

253   /**
254    * Visits a local variable declaration.
255    *
256    * @param name the name of a local variable.
257    * @param desc the type descriptor of this local variable.
258    * @param start the first instruction corresponding to the scope of this
259    * local variable (inclusive).
260    * @param end the last instruction corresponding to the scope of this
261    * local variable (exclusive).
262    * @param index the local variable's index.
263    * @throws IllegalArgumentException if one of the labels has not already been
264    * visited by this visitor (by the {@link #visitLabel visitLabel}
265    * method).
266    */

267
268   void visitLocalVariable (
269     String JavaDoc name,
270     String JavaDoc desc,
271     Label start,
272     Label end,
273     int index);
274
275   /**
276    * Visits a line number declaration.
277    *
278    * @param line a line number. This number refers to the source file
279    * from which the class was compiled.
280    * @param start the first instruction corresponding to this line number.
281    * @throws IllegalArgumentException if <tt>start</tt> has not already been
282    * visited by this visitor (by the {@link #visitLabel visitLabel}
283    * method).
284    */

285
286   void visitLineNumber (int line, Label start);
287 }
288
Popular Tags