001: /***
002: * ASM: a very small and fast Java bytecode manipulation framework
003: * Copyright (C) 2000 INRIA, France Telecom
004: * Copyright (C) 2002 France Telecom
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: * Contact: Eric.Bruneton@rd.francetelecom.com
021: *
022: * Author: Eric Bruneton
023: */package bsh.org.objectweb.asm;
024:
025: /**
026: * A visitor to visit the bytecode instructions of a Java method. The methods
027: * of this visitor must be called in the sequential order of the bytecode
028: * instructions of the visited code. The {@link #visitMaxs visitMaxs} method
029: * must be called after all the instructions have been visited. The {@link
030: * #visitTryCatchBlock visitTryCatchBlock}, {@link #visitLocalVariable
031: * visitLocalVariable} and {@link #visitLineNumber visitLineNumber} methods may
032: * be called in any order, at any time (provided the labels passed as arguments
033: * have already been visited with {@link #visitLabel visitLabel}).
034: */
035:
036: public interface CodeVisitor {
037:
038: /**
039: * Visits a zero operand instruction.
040: *
041: * @param opcode the opcode of the instruction to be visited. This opcode is
042: * either NOP, ACONST_NULL, ICONST_M1, ICONST_0, ICONST_1, ICONST_2,
043: * ICONST_3, ICONST_4, ICONST_5, LCONST_0, LCONST_1, FCONST_0, FCONST_1,
044: * FCONST_2, DCONST_0, DCONST_1,
045: *
046: * IALOAD, LALOAD, FALOAD, DALOAD, AALOAD, BALOAD, CALOAD, SALOAD,
047: * IASTORE, LASTORE, FASTORE, DASTORE, AASTORE, BASTORE, CASTORE,
048: * SASTORE,
049: *
050: * POP, POP2, DUP, DUP_X1, DUP_X2, DUP2, DUP2_X1, DUP2_X2, SWAP,
051: *
052: * IADD, LADD, FADD, DADD, ISUB, LSUB, FSUB, DSUB, IMUL, LMUL, FMUL,
053: * DMUL, IDIV, LDIV, FDIV, DDIV, IREM, LREM, FREM, DREM, INEG, LNEG,
054: * FNEG, DNEG, ISHL, LSHL, ISHR, LSHR, IUSHR, LUSHR, IAND, LAND, IOR,
055: * LOR, IXOR, LXOR,
056: *
057: * I2L, I2F, I2D, L2I, L2F, L2D, F2I, F2L, F2D, D2I, D2L, D2F, I2B, I2C,
058: * I2S,
059: *
060: * LCMP, FCMPL, FCMPG, DCMPL, DCMPG,
061: *
062: * IRETURN, LRETURN, FRETURN, DRETURN, ARETURN, RETURN,
063: *
064: * ARRAYLENGTH,
065: *
066: * ATHROW,
067: *
068: * MONITORENTER, or MONITOREXIT.
069: */
070:
071: void visitInsn(int opcode);
072:
073: /**
074: * Visits an instruction with a single int operand.
075: *
076: * @param opcode the opcode of the instruction to be visited. This opcode is
077: * either BIPUSH, SIPUSH or NEWARRAY.
078: * @param operand the operand of the instruction to be visited.
079: */
080:
081: void visitIntInsn(int opcode, int operand);
082:
083: /**
084: * Visits a local variable instruction. A local variable instruction is an
085: * instruction that loads or stores the value of a local variable.
086: *
087: * @param opcode the opcode of the local variable instruction to be visited.
088: * This opcode is either ILOAD, LLOAD, FLOAD, DLOAD, ALOAD, ISTORE,
089: * LSTORE, FSTORE, DSTORE, ASTORE or RET.
090: * @param var the operand of the instruction to be visited. This operand is
091: * the index of a local variable.
092: */
093:
094: void visitVarInsn(int opcode, int var);
095:
096: /**
097: * Visits a type instruction. A type instruction is an instruction that
098: * takes a type descriptor as parameter.
099: *
100: * @param opcode the opcode of the type instruction to be visited. This opcode
101: * is either NEW, ANEWARRAY, CHECKCAST or INSTANCEOF.
102: * @param desc the operand of the instruction to be visited. This operand is
103: * must be a fully qualified class name in internal form, or the type
104: * descriptor of an array type (see {@link Type Type}).
105: */
106:
107: void visitTypeInsn(int opcode, String desc);
108:
109: /**
110: * Visits a field instruction. A field instruction is an instruction that
111: * loads or stores the value of a field of an object.
112: *
113: * @param opcode the opcode of the type instruction to be visited. This opcode
114: * is either GETSTATIC, PUTSTATIC, GETFIELD or PUTFIELD.
115: * @param owner the internal name of the field's owner class (see {@link
116: * Type#getInternalName getInternalName}).
117: * @param name the field's name.
118: * @param desc the field's descriptor (see {@link Type Type}).
119: */
120:
121: void visitFieldInsn(int opcode, String owner, String name,
122: String desc);
123:
124: /**
125: * Visits a method instruction. A method instruction is an instruction that
126: * invokes a method.
127: *
128: * @param opcode the opcode of the type instruction to be visited. This opcode
129: * is either INVOKEVIRTUAL, INVOKESPECIAL, INVOKESTATIC or
130: * INVOKEINTERFACE.
131: * @param owner the internal name of the method's owner class (see {@link
132: * Type#getInternalName getInternalName}).
133: * @param name the method's name.
134: * @param desc the method's descriptor (see {@link Type Type}).
135: */
136:
137: void visitMethodInsn(int opcode, String owner, String name,
138: String 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 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,
199: Label labels[]);
200:
201: /**
202: * Visits a LOOKUPSWITCH instruction.
203: *
204: * @param dflt beginning of the default handler block.
205: * @param keys the values of the keys.
206: * @param labels beginnings of the handler blocks. <tt>labels[i]</tt> is the
207: * beginning of the handler block for the <tt>keys[i]</tt> key.
208: */
209:
210: void visitLookupSwitchInsn(Label dflt, int keys[], Label labels[]);
211:
212: /**
213: * Visits a MULTIANEWARRAY instruction.
214: *
215: * @param desc an array type descriptor (see {@link Type Type}).
216: * @param dims number of dimensions of the array to allocate.
217: */
218:
219: void visitMultiANewArrayInsn(String desc, int dims);
220:
221: // -------------------------------------------------------------------------
222: // Exceptions table entries, max stack size and max locals
223: // -------------------------------------------------------------------------
224:
225: /**
226: * Visits a try catch block.
227: *
228: * @param start beginning of the exception handler's scope (inclusive).
229: * @param end end of the exception handler's scope (exclusive).
230: * @param handler beginning of the exception handler's code.
231: * @param type internal name of the type of exceptions handled by the handler,
232: * or <tt>null</tt> to catch any exceptions (for "finally" blocks).
233: * @throws IllegalArgumentException if one of the labels has not already been
234: * visited by this visitor (by the {@link #visitLabel visitLabel}
235: * method).
236: */
237:
238: void visitTryCatchBlock(Label start, Label end, Label handler,
239: String type);
240:
241: /**
242: * Visits the maximum stack size and the maximum number of local variables of
243: * the method.
244: *
245: * @param maxStack maximum stack size of the method.
246: * @param maxLocals maximum number of local variables for the method.
247: */
248:
249: void visitMaxs(int maxStack, int maxLocals);
250:
251: // -------------------------------------------------------------------------
252: // Debug information
253: // -------------------------------------------------------------------------
254:
255: /**
256: * Visits a local variable declaration.
257: *
258: * @param name the name of a local variable.
259: * @param desc the type descriptor of this local variable.
260: * @param start the first instruction corresponding to the scope of this
261: * local variable (inclusive).
262: * @param end the last instruction corresponding to the scope of this
263: * local variable (exclusive).
264: * @param index the local variable's index.
265: * @throws IllegalArgumentException if one of the labels has not already been
266: * visited by this visitor (by the {@link #visitLabel visitLabel}
267: * method).
268: */
269:
270: void visitLocalVariable(String name, String desc, Label start,
271: Label end, int index);
272:
273: /**
274: * Visits a line number declaration.
275: *
276: * @param line a line number. This number refers to the source file
277: * from which the class was compiled.
278: * @param start the first instruction corresponding to this line number.
279: * @throws IllegalArgumentException if <tt>start</tt> has not already been
280: * visited by this visitor (by the {@link #visitLabel visitLabel}
281: * method).
282: */
283:
284: void visitLineNumber(int line, Label start);
285: }
|