view src/clojure/asm/MethodVisitor.java @ 10:ef7dbbd6452c

added clojure source goodness
author Robert McIntyre <rlm@mit.edu>
date Sat, 21 Aug 2010 06:25:44 -0400
parents
children
line wrap: on
line source
1 /***
2 * ASM: a very small and fast Java bytecode manipulation framework
3 * Copyright (c) 2000-2005 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 package clojure.asm;
32 /**
33 * A visitor to visit a Java method. The methods of this interface must be
34 * called in the following order: [ <tt>visitAnnotationDefault</tt> ] (
35 * <tt>visitAnnotation</tt> | <tt>visitParameterAnnotation</tt> |
36 * <tt>visitAttribute</tt> )* [ <tt>visitCode</tt> ( <tt>visitFrame</tt> |
37 * <tt>visit</tt><i>X</i>Insn</tt> | <tt>visitLabel</tt> | <tt>visitTryCatchBlock</tt> |
38 * <tt>visitLocalVariable</tt> | <tt>visitLineNumber</tt>)* <tt>visitMaxs</tt> ]
39 * <tt>visitEnd</tt>. In addition, the <tt>visit</tt><i>X</i>Insn</tt>
40 * and <tt>visitLabel</tt> methods must be called in the sequential order of
41 * the bytecode instructions of the visited code, <tt>visitTryCatchBlock</tt>
42 * must be called <i>before</i> the labels passed as arguments have been
43 * visited, and the <tt>visitLocalVariable</tt> and <tt>visitLineNumber</tt>
44 * methods must be called <i>after</i> the labels passed as arguments have been
45 * visited.
46 *
47 * @author Eric Bruneton
48 */
49 public interface MethodVisitor{
51 // -------------------------------------------------------------------------
52 // Annotations and non standard attributes
53 // -------------------------------------------------------------------------
55 /**
56 * Visits the default value of this annotation interface method.
57 *
58 * @return a visitor to the visit the actual default value of this
59 * annotation interface method, or <tt>null</tt> if this visitor
60 * is not interested in visiting this default value. The 'name'
61 * parameters passed to the methods of this annotation visitor are
62 * ignored. Moreover, exacly one visit method must be called on this
63 * annotation visitor, followed by visitEnd.
64 */
65 AnnotationVisitor visitAnnotationDefault();
67 /**
68 * Visits an annotation of this method.
69 *
70 * @param desc the class descriptor of the annotation class.
71 * @param visible <tt>true</tt> if the annotation is visible at runtime.
72 * @return a visitor to visit the annotation values, or <tt>null</tt> if
73 * this visitor is not interested in visiting this annotation.
74 */
75 AnnotationVisitor visitAnnotation(String desc, boolean visible);
77 /**
78 * Visits an annotation of a parameter this method.
79 *
80 * @param parameter the parameter index.
81 * @param desc the class descriptor of the annotation class.
82 * @param visible <tt>true</tt> if the annotation is visible at runtime.
83 * @return a visitor to visit the annotation values, or <tt>null</tt> if
84 * this visitor is not interested in visiting this annotation.
85 */
86 AnnotationVisitor visitParameterAnnotation(
87 int parameter,
88 String desc,
89 boolean visible);
91 /**
92 * Visits a non standard attribute of this method.
93 *
94 * @param attr an attribute.
95 */
96 void visitAttribute(Attribute attr);
98 /**
99 * Starts the visit of the method's code, if any (i.e. non abstract method).
100 */
101 void visitCode();
103 /**
104 * Visits the current state of the local variables and operand stack
105 * elements. This method must(*) be called <i>just before</i> any
106 * instruction <b>i</b> that follows an unconditionnal branch instruction
107 * such as GOTO or THROW, that is the target of a jump instruction, or that
108 * starts an exception handler block. The visited types must describe the
109 * values of the local variables and of the operand stack elements <i>just
110 * before</i> <b>i</b> is executed. <br> <br> (*) this is mandatory only
111 * for classes whose version is greater than or equal to
112 * {@link Opcodes#V1_6 V1_6}. <br> <br> Packed frames are basically
113 * "deltas" from the state of the previous frame (very first frame is
114 * implicitly defined by the method's parameters and access flags): <ul>
115 * <li>{@link Opcodes#F_SAME} representing frame with exactly the same
116 * locals as the previous frame and with the empty stack.</li> <li>{@link Opcodes#F_SAME1}
117 * representing frame with exactly the same locals as the previous frame and
118 * with single value on the stack (<code>nStack</code> is 1 and
119 * <code>stack[0]</code> contains value for the type of the stack item).</li>
120 * <li>{@link Opcodes#F_APPEND} representing frame with current locals are
121 * the same as the locals in the previous frame, except that additional
122 * locals are defined (<code>nLocal</code> is 1, 2 or 3 and
123 * <code>local</code> elements contains values representing added types).</li>
124 * <li>{@link Opcodes#F_CHOP} representing frame with current locals are
125 * the same as the locals in the previous frame, except that the last 1-3
126 * locals are absent and with the empty stack (<code>nLocals</code> is 1,
127 * 2 or 3). </li> <li>{@link Opcodes#F_FULL} representing complete frame
128 * data.</li> </li> </ul>
129 *
130 * @param type the type of this stack map frame. Must be
131 * {@link Opcodes#F_NEW} for expanded frames, or
132 * {@link Opcodes#F_FULL}, {@link Opcodes#F_APPEND},
133 * {@link Opcodes#F_CHOP}, {@link Opcodes#F_SAME} or
134 * {@link Opcodes#F_APPEND}, {@link Opcodes#F_SAME1} for compressed
135 * frames.
136 * @param nLocal the number of local variables in the visited frame.
137 * @param local the local variable types in this frame. This array must not
138 * be modified. Primitive types are represented by
139 * {@link Opcodes#TOP}, {@link Opcodes#INTEGER},
140 * {@link Opcodes#FLOAT}, {@link Opcodes#LONG},
141 * {@link Opcodes#DOUBLE},{@link Opcodes#NULL} or
142 * {@link Opcodes#UNINITIALIZED_THIS} (long and double are
143 * represented by a single element). Reference types are represented
144 * by String objects (representing internal names, or type
145 * descriptors for array types), and uninitialized types by Label
146 * objects (this label designates the NEW instruction that created
147 * this uninitialized value).
148 * @param nStack the number of operand stack elements in the visited frame.
149 * @param stack the operand stack types in this frame. This array must not
150 * be modified. Its content has the same format as the "local" array.
151 */
152 void visitFrame(
153 int type,
154 int nLocal,
155 Object[] local,
156 int nStack,
157 Object[] stack);
159 // -------------------------------------------------------------------------
160 // Normal instructions
161 // -------------------------------------------------------------------------
163 /**
164 * Visits a zero operand instruction.
165 *
166 * @param opcode the opcode of the instruction to be visited. This opcode is
167 * either NOP, ACONST_NULL, ICONST_M1, ICONST_0, ICONST_1, ICONST_2,
168 * ICONST_3, ICONST_4, ICONST_5, LCONST_0, LCONST_1, FCONST_0,
169 * FCONST_1, FCONST_2, DCONST_0, DCONST_1, IALOAD, LALOAD, FALOAD,
170 * DALOAD, AALOAD, BALOAD, CALOAD, SALOAD, IASTORE, LASTORE, FASTORE,
171 * DASTORE, AASTORE, BASTORE, CASTORE, SASTORE, POP, POP2, DUP,
172 * DUP_X1, DUP_X2, DUP2, DUP2_X1, DUP2_X2, SWAP, IADD, LADD, FADD,
173 * DADD, ISUB, LSUB, FSUB, DSUB, IMUL, LMUL, FMUL, DMUL, IDIV, LDIV,
174 * FDIV, DDIV, IREM, LREM, FREM, DREM, INEG, LNEG, FNEG, DNEG, ISHL,
175 * LSHL, ISHR, LSHR, IUSHR, LUSHR, IAND, LAND, IOR, LOR, IXOR, LXOR,
176 * I2L, I2F, I2D, L2I, L2F, L2D, F2I, F2L, F2D, D2I, D2L, D2F, I2B,
177 * I2C, I2S, LCMP, FCMPL, FCMPG, DCMPL, DCMPG, IRETURN, LRETURN,
178 * FRETURN, DRETURN, ARETURN, RETURN, ARRAYLENGTH, ATHROW,
179 * MONITORENTER, or MONITOREXIT.
180 */
181 void visitInsn(int opcode);
183 /**
184 * Visits an instruction with a single int operand.
185 *
186 * @param opcode the opcode of the instruction to be visited. This opcode is
187 * either BIPUSH, SIPUSH or NEWARRAY.
188 * @param operand the operand of the instruction to be visited.<br> When
189 * opcode is BIPUSH, operand value should be between Byte.MIN_VALUE
190 * and Byte.MAX_VALUE.<br> When opcode is SIPUSH, operand value
191 * should be between Short.MIN_VALUE and Short.MAX_VALUE.<br> When
192 * opcode is NEWARRAY, operand value should be one of
193 * {@link Opcodes#T_BOOLEAN}, {@link Opcodes#T_CHAR},
194 * {@link Opcodes#T_FLOAT}, {@link Opcodes#T_DOUBLE},
195 * {@link Opcodes#T_BYTE}, {@link Opcodes#T_SHORT},
196 * {@link Opcodes#T_INT} or {@link Opcodes#T_LONG}.
197 */
198 void visitIntInsn(int opcode, int operand);
200 /**
201 * Visits a local variable instruction. A local variable instruction is an
202 * instruction that loads or stores the value of a local variable.
203 *
204 * @param opcode the opcode of the local variable instruction to be visited.
205 * This opcode is either ILOAD, LLOAD, FLOAD, DLOAD, ALOAD, ISTORE,
206 * LSTORE, FSTORE, DSTORE, ASTORE or RET.
207 * @param var the operand of the instruction to be visited. This operand is
208 * the index of a local variable.
209 */
210 void visitVarInsn(int opcode, int var);
212 /**
213 * Visits a type instruction. A type instruction is an instruction that
214 * takes a type descriptor as parameter.
215 *
216 * @param opcode the opcode of the type instruction to be visited. This
217 * opcode is either NEW, ANEWARRAY, CHECKCAST or INSTANCEOF.
218 * @param desc the operand of the instruction to be visited. This operand is
219 * must be a fully qualified class name in internal form, or the type
220 * descriptor of an array type (see {@link Type Type}).
221 */
222 void visitTypeInsn(int opcode, String desc);
224 /**
225 * Visits a field instruction. A field instruction is an instruction that
226 * loads or stores the value of a field of an object.
227 *
228 * @param opcode the opcode of the type instruction to be visited. This
229 * opcode is either GETSTATIC, PUTSTATIC, GETFIELD or PUTFIELD.
230 * @param owner the internal name of the field's owner class (see {@link
231 * Type#getInternalName() getInternalName}).
232 * @param name the field's name.
233 * @param desc the field's descriptor (see {@link Type Type}).
234 */
235 void visitFieldInsn(int opcode, String owner, String name, String desc);
237 /**
238 * Visits a method instruction. A method instruction is an instruction that
239 * invokes a method.
240 *
241 * @param opcode the opcode of the type instruction to be visited. This
242 * opcode is either INVOKEVIRTUAL, INVOKESPECIAL, INVOKESTATIC or
243 * INVOKEINTERFACE.
244 * @param owner the internal name of the method's owner class (see {@link
245 * Type#getInternalName() getInternalName}).
246 * @param name the method's name.
247 * @param desc the method's descriptor (see {@link Type Type}).
248 */
249 void visitMethodInsn(int opcode, String owner, String name, String desc);
251 /**
252 * Visits a jump instruction. A jump instruction is an instruction that may
253 * jump to another instruction.
254 *
255 * @param opcode the opcode of the type instruction to be visited. This
256 * opcode is either IFEQ, IFNE, IFLT, IFGE, IFGT, IFLE, IF_ICMPEQ,
257 * IF_ICMPNE, IF_ICMPLT, IF_ICMPGE, IF_ICMPGT, IF_ICMPLE, IF_ACMPEQ,
258 * IF_ACMPNE, GOTO, JSR, IFNULL or IFNONNULL.
259 * @param label the operand of the instruction to be visited. This operand
260 * is a label that designates the instruction to which the jump
261 * instruction may jump.
262 */
263 void visitJumpInsn(int opcode, Label label);
265 /**
266 * Visits a label. A label designates the instruction that will be visited
267 * just after it.
268 *
269 * @param label a {@link Label Label} object.
270 */
271 void visitLabel(Label label);
273 // -------------------------------------------------------------------------
274 // Special instructions
275 // -------------------------------------------------------------------------
277 /**
278 * Visits a LDC instruction.
279 *
280 * @param cst the constant to be loaded on the stack. This parameter must be
281 * a non null {@link Integer}, a {@link Float}, a {@link Long}, a
282 * {@link Double} a {@link String} (or a {@link Type} for
283 * <tt>.class</tt> constants, for classes whose version is 49.0 or
284 * more).
285 */
286 void visitLdcInsn(Object cst);
288 /**
289 * Visits an IINC instruction.
290 *
291 * @param var index of the local variable to be incremented.
292 * @param increment amount to increment the local variable by.
293 */
294 void visitIincInsn(int var, int increment);
296 /**
297 * Visits a TABLESWITCH instruction.
298 *
299 * @param min the minimum key value.
300 * @param max the maximum key value.
301 * @param dflt beginning of the default handler block.
302 * @param labels beginnings of the handler blocks. <tt>labels[i]</tt> is
303 * the beginning of the handler block for the <tt>min + i</tt> key.
304 */
305 void visitTableSwitchInsn(int min, int max, Label dflt, Label labels[]);
307 /**
308 * Visits a LOOKUPSWITCH instruction.
309 *
310 * @param dflt beginning of the default handler block.
311 * @param keys the values of the keys.
312 * @param labels beginnings of the handler blocks. <tt>labels[i]</tt> is
313 * the beginning of the handler block for the <tt>keys[i]</tt> key.
314 */
315 void visitLookupSwitchInsn(Label dflt, int keys[], Label labels[]);
317 /**
318 * Visits a MULTIANEWARRAY instruction.
319 *
320 * @param desc an array type descriptor (see {@link Type Type}).
321 * @param dims number of dimensions of the array to allocate.
322 */
323 void visitMultiANewArrayInsn(String desc, int dims);
325 // -------------------------------------------------------------------------
326 // Exceptions table entries, debug information, max stack and max locals
327 // -------------------------------------------------------------------------
329 /**
330 * Visits a try catch block.
331 *
332 * @param start beginning of the exception handler's scope (inclusive).
333 * @param end end of the exception handler's scope (exclusive).
334 * @param handler beginning of the exception handler's code.
335 * @param type internal name of the type of exceptions handled by the
336 * handler, or <tt>null</tt> to catch any exceptions (for "finally"
337 * blocks).
338 * @throws IllegalArgumentException if one of the labels has already been
339 * visited by this visitor (by the {@link #visitLabel visitLabel}
340 * method).
341 */
342 void visitTryCatchBlock(Label start, Label end, Label handler, String type);
344 /**
345 * Visits a local variable declaration.
346 *
347 * @param name the name of a local variable.
348 * @param desc the type descriptor of this local variable.
349 * @param signature the type signature of this local variable. May be
350 * <tt>null</tt> if the local variable type does not use generic
351 * types.
352 * @param start the first instruction corresponding to the scope of this
353 * local variable (inclusive).
354 * @param end the last instruction corresponding to the scope of this local
355 * variable (exclusive).
356 * @param index the local variable's index.
357 * @throws IllegalArgumentException if one of the labels has not already
358 * been visited by this visitor (by the
359 * {@link #visitLabel visitLabel} method).
360 */
361 void visitLocalVariable(
362 String name,
363 String desc,
364 String signature,
365 Label start,
366 Label end,
367 int index);
369 /**
370 * Visits a line number declaration.
371 *
372 * @param line a line number. This number refers to the source file from
373 * which the class was compiled.
374 * @param start the first instruction corresponding to this line number.
375 * @throws IllegalArgumentException if <tt>start</tt> has not already been
376 * visited by this visitor (by the {@link #visitLabel visitLabel}
377 * method).
378 */
379 void visitLineNumber(int line, Label start);
381 /**
382 * Visits the maximum stack size and the maximum number of local variables
383 * of the method.
384 *
385 * @param maxStack maximum stack size of the method.
386 * @param maxLocals maximum number of local variables for the method.
387 */
388 void visitMaxs(int maxStack, int maxLocals);
390 /**
391 * Visits the end of the method. This method, which is the last one to be
392 * called, is used to inform the visitor that all the annotations and
393 * attributes of the method have been visited.
394 */
395 void visitEnd();
396 }