001: /***
002: * ASM: a very small and fast Java bytecode manipulation framework
003: * Copyright (c) 2000-2005 INRIA, France Telecom
004: * All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions
008: * are met:
009: * 1. Redistributions of source code must retain the above copyright
010: * notice, this list of conditions and the following disclaimer.
011: * 2. Redistributions in binary form must reproduce the above copyright
012: * notice, this list of conditions and the following disclaimer in the
013: * documentation and/or other materials provided with the distribution.
014: * 3. Neither the name of the copyright holders nor the names of its
015: * contributors may be used to endorse or promote products derived from
016: * this software without specific prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
020: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
021: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
022: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
023: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
024: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
025: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
026: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
027: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
028: * THE POSSIBILITY OF SUCH DAMAGE.
029: */package org.objectweb.asm;
030:
031: /**
032: * A visitor to visit a Java method. The methods of this interface must be
033: * called in the following order: [ <tt>visitAnnotationDefault</tt> ] (
034: * <tt>visitAnnotation</tt> | <tt>visitParameterAnnotation</tt> |
035: * <tt>visitAttribute</tt> )* [ <tt>visitCode</tt> ( <tt>visitFrame</tt> |
036: * <tt>visit</tt><i>X</i>Insn</tt> | <tt>visitLabel</tt> | <tt>visitTryCatchBlock</tt> |
037: * <tt>visitLocalVariable</tt> | <tt>visitLineNumber</tt>)* <tt>visitMaxs</tt> ]
038: * <tt>visitEnd</tt>. In addition, the <tt>visit</tt><i>X</i>Insn</tt>
039: * and <tt>visitLabel</tt> methods must be called in the sequential order of
040: * the bytecode instructions of the visited code, <tt>visitTryCatchBlock</tt>
041: * must be called <i>before</i> the labels passed as arguments have been
042: * visited, and the <tt>visitLocalVariable</tt> and <tt>visitLineNumber</tt>
043: * methods must be called <i>after</i> the labels passed as arguments have been
044: * visited.
045: *
046: * @author Eric Bruneton
047: */
048: public interface MethodVisitor {
049:
050: // -------------------------------------------------------------------------
051: // Annotations and non standard attributes
052: // -------------------------------------------------------------------------
053:
054: /**
055: * Visits the default value of this annotation interface method.
056: *
057: * @return a non null visitor to the visit the actual default value of this
058: * annotation interface method. The 'name' parameters passed to the
059: * methods of this annotation visitor are ignored. Moreover, exacly
060: * one visit method must be called on this annotation visitor,
061: * followed by visitEnd.
062: */
063: AnnotationVisitor visitAnnotationDefault();
064:
065: /**
066: * Visits an annotation of this method.
067: *
068: * @param desc the class descriptor of the annotation class.
069: * @param visible <tt>true</tt> if the annotation is visible at runtime.
070: * @return a non null visitor to visit the annotation values.
071: */
072: AnnotationVisitor visitAnnotation(String desc, boolean visible);
073:
074: /**
075: * Visits an annotation of a parameter this method.
076: *
077: * @param parameter the parameter index.
078: * @param desc the class descriptor of the annotation class.
079: * @param visible <tt>true</tt> if the annotation is visible at runtime.
080: * @return a non null visitor to visit the annotation values.
081: */
082: AnnotationVisitor visitParameterAnnotation(int parameter,
083: String desc, boolean visible);
084:
085: /**
086: * Visits a non standard attribute of this method.
087: *
088: * @param attr an attribute.
089: */
090: void visitAttribute(Attribute attr);
091:
092: /**
093: * Starts the visit of the method's code, if any (i.e. non abstract method).
094: */
095: void visitCode();
096:
097: /**
098: * Visits the current state of the local variables and operand stack
099: * elements. This method must(*) be called <i>just before</i> any
100: * instruction <b>i</b> that follows an unconditionnal branch instruction
101: * such as GOTO or THROW, that is the target of a jump instruction, or that
102: * starts an exception handler block. The visited types must describe the
103: * values of the local variables and of the operand stack elements <i>just
104: * before</i> <b>i</b> is executed. <br> <br> (*) this is mandatory only
105: * for classes whose version is greater than or equal to
106: * {@link Opcodes#V1_6 V1_6}. <br> <br> Packed frames are basically
107: * "deltas" from the state of the previous frame (very first frame is
108: * implicitly defined by the method's parameters and access flags): <ul>
109: * <li>{@link Opcodes#F_SAME} representing frame with exactly the same
110: * locals as the previous frame and with the empty stack.</li> <li>{@link Opcodes#F_SAME1}
111: * representing frame with exactly the same locals as the previous frame and
112: * with single value on the stack (<code>nStack</code> is 1 and
113: * <code>stack[0]</code> contains value for the type of the stack item).</li>
114: * <li>{@link Opcodes#F_APPEND} representing frame with current locals are
115: * the same as the locals in the previous frame, except that additional
116: * locals are defined (<code>nLocal</code> is 1, 2 or 3 and
117: * <code>local</code> elements contains values representing added types).</li>
118: * <li>{@link Opcodes#F_CHOP} representing frame with current locals are
119: * the same as the locals in the previous frame, except that the last 1-3
120: * locals are absent and with the empty stack (<code>nLocals</code> is 1,
121: * 2 or 3). </li> <li>{@link Opcodes#F_FULL} representing complete frame
122: * data.</li> </li> </ul>
123: *
124: * @param type the type of this stack map frame. Must be
125: * {@link Opcodes#F_NEW} for expanded frames, or
126: * {@link Opcodes#F_FULL}, {@link Opcodes#F_APPEND},
127: * {@link Opcodes#F_CHOP}, {@link Opcodes#F_SAME} or
128: * {@link Opcodes#F_APPEND}, {@link Opcodes#F_SAME1} for compressed
129: * frames.
130: * @param nLocal the number of local variables in the visited frame.
131: * @param local the local variable types in this frame. This array must not
132: * be modified. Primitive types are represented by
133: * {@link Opcodes#TOP}, {@link Opcodes#INTEGER},
134: * {@link Opcodes#FLOAT}, {@link Opcodes#LONG},
135: * {@link Opcodes#DOUBLE},{@link Opcodes#NULL} or
136: * {@link Opcodes#UNINITIALIZED_THIS} (long and double are
137: * represented by a single element). Reference types are represented
138: * by String objects (representing internal names, or type
139: * descriptors for array types), and uninitialized types by Label
140: * objects (this label designates the NEW instruction that created
141: * this uninitialized value).
142: * @param nStack the number of operand stack elements in the visited frame.
143: * @param stack the operand stack types in this frame. This array must not
144: * be modified. Its content has the same format as the "local" array.
145: */
146: void visitFrame(int type, int nLocal, Object[] local, int nStack,
147: Object[] stack);
148:
149: // -------------------------------------------------------------------------
150: // Normal instructions
151: // -------------------------------------------------------------------------
152:
153: /**
154: * Visits a zero operand instruction.
155: *
156: * @param opcode the opcode of the instruction to be visited. This opcode is
157: * either NOP, ACONST_NULL, ICONST_M1, ICONST_0, ICONST_1, ICONST_2,
158: * ICONST_3, ICONST_4, ICONST_5, LCONST_0, LCONST_1, FCONST_0,
159: * FCONST_1, FCONST_2, DCONST_0, DCONST_1, IALOAD, LALOAD, FALOAD,
160: * DALOAD, AALOAD, BALOAD, CALOAD, SALOAD, IASTORE, LASTORE, FASTORE,
161: * DASTORE, AASTORE, BASTORE, CASTORE, SASTORE, POP, POP2, DUP,
162: * DUP_X1, DUP_X2, DUP2, DUP2_X1, DUP2_X2, SWAP, IADD, LADD, FADD,
163: * DADD, ISUB, LSUB, FSUB, DSUB, IMUL, LMUL, FMUL, DMUL, IDIV, LDIV,
164: * FDIV, DDIV, IREM, LREM, FREM, DREM, INEG, LNEG, FNEG, DNEG, ISHL,
165: * LSHL, ISHR, LSHR, IUSHR, LUSHR, IAND, LAND, IOR, LOR, IXOR, LXOR,
166: * I2L, I2F, I2D, L2I, L2F, L2D, F2I, F2L, F2D, D2I, D2L, D2F, I2B,
167: * I2C, I2S, LCMP, FCMPL, FCMPG, DCMPL, DCMPG, IRETURN, LRETURN,
168: * FRETURN, DRETURN, ARETURN, RETURN, ARRAYLENGTH, ATHROW,
169: * MONITORENTER, or MONITOREXIT.
170: */
171: void visitInsn(int opcode);
172:
173: /**
174: * Visits an instruction with a single int operand.
175: *
176: * @param opcode the opcode of the instruction to be visited. This opcode is
177: * either BIPUSH, SIPUSH or NEWARRAY.
178: * @param operand the operand of the instruction to be visited.<br> When
179: * opcode is BIPUSH, operand value should be between Byte.MIN_VALUE
180: * and Byte.MAX_VALUE.<br> When opcode is SIPUSH, operand value
181: * should be between Short.MIN_VALUE and Short.MAX_VALUE.<br> When
182: * opcode is NEWARRAY, operand value should be one of
183: * {@link Opcodes#T_BOOLEAN}, {@link Opcodes#T_CHAR},
184: * {@link Opcodes#T_FLOAT}, {@link Opcodes#T_DOUBLE},
185: * {@link Opcodes#T_BYTE}, {@link Opcodes#T_SHORT},
186: * {@link Opcodes#T_INT} or {@link Opcodes#T_LONG}.
187: */
188: void visitIntInsn(int opcode, int operand);
189:
190: /**
191: * Visits a local variable instruction. A local variable instruction is an
192: * instruction that loads or stores the value of a local variable.
193: *
194: * @param opcode the opcode of the local variable instruction to be visited.
195: * This opcode is either ILOAD, LLOAD, FLOAD, DLOAD, ALOAD, ISTORE,
196: * LSTORE, FSTORE, DSTORE, ASTORE or RET.
197: * @param var the operand of the instruction to be visited. This operand is
198: * the index of a local variable.
199: */
200: void visitVarInsn(int opcode, int var);
201:
202: /**
203: * Visits a type instruction. A type instruction is an instruction that
204: * takes a type descriptor as parameter.
205: *
206: * @param opcode the opcode of the type instruction to be visited. This
207: * opcode is either NEW, ANEWARRAY, CHECKCAST or INSTANCEOF.
208: * @param desc the operand of the instruction to be visited. This operand is
209: * must be a fully qualified class name in internal form, or the type
210: * descriptor of an array type (see {@link Type Type}).
211: */
212: void visitTypeInsn(int opcode, String desc);
213:
214: /**
215: * Visits a field instruction. A field instruction is an instruction that
216: * loads or stores the value of a field of an object.
217: *
218: * @param opcode the opcode of the type instruction to be visited. This
219: * opcode is either GETSTATIC, PUTSTATIC, GETFIELD or PUTFIELD.
220: * @param owner the internal name of the field's owner class (see {@link
221: * Type#getInternalName() getInternalName}).
222: * @param name the field's name.
223: * @param desc the field's descriptor (see {@link Type Type}).
224: */
225: void visitFieldInsn(int opcode, String owner, String name,
226: String desc);
227:
228: /**
229: * Visits a method instruction. A method instruction is an instruction that
230: * invokes a method.
231: *
232: * @param opcode the opcode of the type instruction to be visited. This
233: * opcode is either INVOKEVIRTUAL, INVOKESPECIAL, INVOKESTATIC or
234: * INVOKEINTERFACE.
235: * @param owner the internal name of the method's owner class (see {@link
236: * Type#getInternalName() getInternalName}).
237: * @param name the method's name.
238: * @param desc the method's descriptor (see {@link Type Type}).
239: */
240: void visitMethodInsn(int opcode, String owner, String name,
241: String desc);
242:
243: /**
244: * Visits a jump instruction. A jump instruction is an instruction that may
245: * jump to another instruction.
246: *
247: * @param opcode the opcode of the type instruction to be visited. This
248: * opcode is either IFEQ, IFNE, IFLT, IFGE, IFGT, IFLE, IF_ICMPEQ,
249: * IF_ICMPNE, IF_ICMPLT, IF_ICMPGE, IF_ICMPGT, IF_ICMPLE, IF_ACMPEQ,
250: * IF_ACMPNE, GOTO, JSR, IFNULL or IFNONNULL.
251: * @param label the operand of the instruction to be visited. This operand
252: * is a label that designates the instruction to which the jump
253: * instruction may jump.
254: */
255: void visitJumpInsn(int opcode, Label label);
256:
257: /**
258: * Visits a label. A label designates the instruction that will be visited
259: * just after it.
260: *
261: * @param label a {@link Label Label} object.
262: */
263: void visitLabel(Label label);
264:
265: // -------------------------------------------------------------------------
266: // Special instructions
267: // -------------------------------------------------------------------------
268:
269: /**
270: * Visits a LDC instruction.
271: *
272: * @param cst the constant to be loaded on the stack. This parameter must be
273: * a non null {@link Integer}, a {@link Float}, a {@link Long}, a
274: * {@link Double} a {@link String} (or a {@link Type} for
275: * <tt>.class</tt> constants, for classes whose version is 49.0 or
276: * more).
277: */
278: void visitLdcInsn(Object cst);
279:
280: /**
281: * Visits an IINC instruction.
282: *
283: * @param var index of the local variable to be incremented.
284: * @param increment amount to increment the local variable by.
285: */
286: void visitIincInsn(int var, int increment);
287:
288: /**
289: * Visits a TABLESWITCH instruction.
290: *
291: * @param min the minimum key value.
292: * @param max the maximum key value.
293: * @param dflt beginning of the default handler block.
294: * @param labels beginnings of the handler blocks. <tt>labels[i]</tt> is
295: * the beginning of the handler block for the <tt>min + i</tt> key.
296: */
297: void visitTableSwitchInsn(int min, int max, Label dflt,
298: Label labels[]);
299:
300: /**
301: * Visits a LOOKUPSWITCH instruction.
302: *
303: * @param dflt beginning of the default handler block.
304: * @param keys the values of the keys.
305: * @param labels beginnings of the handler blocks. <tt>labels[i]</tt> is
306: * the beginning of the handler block for the <tt>keys[i]</tt> key.
307: */
308: void visitLookupSwitchInsn(Label dflt, int keys[], Label labels[]);
309:
310: /**
311: * Visits a MULTIANEWARRAY instruction.
312: *
313: * @param desc an array type descriptor (see {@link Type Type}).
314: * @param dims number of dimensions of the array to allocate.
315: */
316: void visitMultiANewArrayInsn(String desc, int dims);
317:
318: // -------------------------------------------------------------------------
319: // Exceptions table entries, debug information, max stack and max locals
320: // -------------------------------------------------------------------------
321:
322: /**
323: * Visits a try catch block.
324: *
325: * @param start beginning of the exception handler's scope (inclusive).
326: * @param end end of the exception handler's scope (exclusive).
327: * @param handler beginning of the exception handler's code.
328: * @param type internal name of the type of exceptions handled by the
329: * handler, or <tt>null</tt> to catch any exceptions (for "finally"
330: * blocks).
331: * @throws IllegalArgumentException if one of the labels has already been
332: * visited by this visitor (by the {@link #visitLabel visitLabel}
333: * method).
334: */
335: void visitTryCatchBlock(Label start, Label end, Label handler,
336: String type);
337:
338: /**
339: * Visits a local variable declaration.
340: *
341: * @param name the name of a local variable.
342: * @param desc the type descriptor of this local variable.
343: * @param signature the type signature of this local variable. May be
344: * <tt>null</tt> if the local variable type does not use generic
345: * types.
346: * @param start the first instruction corresponding to the scope of this
347: * local variable (inclusive).
348: * @param end the last instruction corresponding to the scope of this local
349: * variable (exclusive).
350: * @param index the local variable's index.
351: * @throws IllegalArgumentException if one of the labels has not already
352: * been visited by this visitor (by the
353: * {@link #visitLabel visitLabel} method).
354: */
355: void visitLocalVariable(String name, String desc, String signature,
356: Label start, Label end, int index);
357:
358: /**
359: * Visits a line number declaration.
360: *
361: * @param line a line number. This number refers to the source file from
362: * which the class was compiled.
363: * @param start the first instruction corresponding to this line number.
364: * @throws IllegalArgumentException if <tt>start</tt> has not already been
365: * visited by this visitor (by the {@link #visitLabel visitLabel}
366: * method).
367: */
368: void visitLineNumber(int line, Label start);
369:
370: /**
371: * Visits the maximum stack size and the maximum number of local variables
372: * of the method.
373: *
374: * @param maxStack maximum stack size of the method.
375: * @param maxLocals maximum number of local variables for the method.
376: */
377: void visitMaxs(int maxStack, int maxLocals);
378:
379: /**
380: * Visits the end of the method. This method, which is the last one to be
381: * called, is used to inform the visitor that all the annotations and
382: * attributes of the method have been visited.
383: */
384: void visitEnd();
385: }
|