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