Mercurial > lasercutter
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 framework3 * Copyright (c) 2000-2005 INRIA, France Telecom4 * All rights reserved.5 *6 * Redistribution and use in source and binary forms, with or without7 * modification, are permitted provided that the following conditions8 * are met:9 * 1. Redistributions of source code must retain the above copyright10 * notice, this list of conditions and the following disclaimer.11 * 2. Redistributions in binary form must reproduce the above copyright12 * notice, this list of conditions and the following disclaimer in the13 * documentation and/or other materials provided with the distribution.14 * 3. Neither the name of the copyright holders nor the names of its15 * contributors may be used to endorse or promote products derived from16 * 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, THE20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF28 * 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 be34 * 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 of41 * the bytecode instructions of the visited code, <tt>visitTryCatchBlock</tt>42 * must be called <i>before</i> the labels passed as arguments have been43 * visited, and the <tt>visitLocalVariable</tt> and <tt>visitLineNumber</tt>44 * methods must be called <i>after</i> the labels passed as arguments have been45 * visited.46 *47 * @author Eric Bruneton48 */49 public interface MethodVisitor{51 // -------------------------------------------------------------------------52 // Annotations and non standard attributes53 // -------------------------------------------------------------------------55 /**56 * Visits the default value of this annotation interface method.57 *58 * @return a visitor to the visit the actual default value of this59 * annotation interface method, or <tt>null</tt> if this visitor60 * is not interested in visiting this default value. The 'name'61 * parameters passed to the methods of this annotation visitor are62 * ignored. Moreover, exacly one visit method must be called on this63 * 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> if73 * 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> if84 * 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 stack105 * elements. This method must(*) be called <i>just before</i> any106 * instruction <b>i</b> that follows an unconditionnal branch instruction107 * such as GOTO or THROW, that is the target of a jump instruction, or that108 * starts an exception handler block. The visited types must describe the109 * values of the local variables and of the operand stack elements <i>just110 * before</i> <b>i</b> is executed. <br> <br> (*) this is mandatory only111 * for classes whose version is greater than or equal to112 * {@link Opcodes#V1_6 V1_6}. <br> <br> Packed frames are basically113 * "deltas" from the state of the previous frame (very first frame is114 * implicitly defined by the method's parameters and access flags): <ul>115 * <li>{@link Opcodes#F_SAME} representing frame with exactly the same116 * 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 and118 * with single value on the stack (<code>nStack</code> is 1 and119 * <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 are121 * the same as the locals in the previous frame, except that additional122 * locals are defined (<code>nLocal</code> is 1, 2 or 3 and123 * <code>local</code> elements contains values representing added types).</li>124 * <li>{@link Opcodes#F_CHOP} representing frame with current locals are125 * the same as the locals in the previous frame, except that the last 1-3126 * 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 frame128 * data.</li> </li> </ul>129 *130 * @param type the type of this stack map frame. Must be131 * {@link Opcodes#F_NEW} for expanded frames, or132 * {@link Opcodes#F_FULL}, {@link Opcodes#F_APPEND},133 * {@link Opcodes#F_CHOP}, {@link Opcodes#F_SAME} or134 * {@link Opcodes#F_APPEND}, {@link Opcodes#F_SAME1} for compressed135 * 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 not138 * be modified. Primitive types are represented by139 * {@link Opcodes#TOP}, {@link Opcodes#INTEGER},140 * {@link Opcodes#FLOAT}, {@link Opcodes#LONG},141 * {@link Opcodes#DOUBLE},{@link Opcodes#NULL} or142 * {@link Opcodes#UNINITIALIZED_THIS} (long and double are143 * represented by a single element). Reference types are represented144 * by String objects (representing internal names, or type145 * descriptors for array types), and uninitialized types by Label146 * objects (this label designates the NEW instruction that created147 * 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 not150 * 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 instructions161 // -------------------------------------------------------------------------163 /**164 * Visits a zero operand instruction.165 *166 * @param opcode the opcode of the instruction to be visited. This opcode is167 * 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 is187 * either BIPUSH, SIPUSH or NEWARRAY.188 * @param operand the operand of the instruction to be visited.<br> When189 * opcode is BIPUSH, operand value should be between Byte.MIN_VALUE190 * and Byte.MAX_VALUE.<br> When opcode is SIPUSH, operand value191 * should be between Short.MIN_VALUE and Short.MAX_VALUE.<br> When192 * opcode is NEWARRAY, operand value should be one of193 * {@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 an202 * 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 is208 * 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 that214 * takes a type descriptor as parameter.215 *216 * @param opcode the opcode of the type instruction to be visited. This217 * opcode is either NEW, ANEWARRAY, CHECKCAST or INSTANCEOF.218 * @param desc the operand of the instruction to be visited. This operand is219 * must be a fully qualified class name in internal form, or the type220 * 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 that226 * loads or stores the value of a field of an object.227 *228 * @param opcode the opcode of the type instruction to be visited. This229 * opcode is either GETSTATIC, PUTSTATIC, GETFIELD or PUTFIELD.230 * @param owner the internal name of the field's owner class (see {@link231 * 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 that239 * invokes a method.240 *241 * @param opcode the opcode of the type instruction to be visited. This242 * opcode is either INVOKEVIRTUAL, INVOKESPECIAL, INVOKESTATIC or243 * INVOKEINTERFACE.244 * @param owner the internal name of the method's owner class (see {@link245 * 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 may253 * jump to another instruction.254 *255 * @param opcode the opcode of the type instruction to be visited. This256 * 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 operand260 * is a label that designates the instruction to which the jump261 * instruction may jump.262 */263 void visitJumpInsn(int opcode, Label label);265 /**266 * Visits a label. A label designates the instruction that will be visited267 * just after it.268 *269 * @param label a {@link Label Label} object.270 */271 void visitLabel(Label label);273 // -------------------------------------------------------------------------274 // Special instructions275 // -------------------------------------------------------------------------277 /**278 * Visits a LDC instruction.279 *280 * @param cst the constant to be loaded on the stack. This parameter must be281 * a non null {@link Integer}, a {@link Float}, a {@link Long}, a282 * {@link Double} a {@link String} (or a {@link Type} for283 * <tt>.class</tt> constants, for classes whose version is 49.0 or284 * 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> is303 * 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> is313 * 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 locals327 // -------------------------------------------------------------------------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 the336 * handler, or <tt>null</tt> to catch any exceptions (for "finally"337 * blocks).338 * @throws IllegalArgumentException if one of the labels has already been339 * 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 be350 * <tt>null</tt> if the local variable type does not use generic351 * types.352 * @param start the first instruction corresponding to the scope of this353 * local variable (inclusive).354 * @param end the last instruction corresponding to the scope of this local355 * variable (exclusive).356 * @param index the local variable's index.357 * @throws IllegalArgumentException if one of the labels has not already358 * been visited by this visitor (by the359 * {@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 from373 * 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 been376 * 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 variables383 * 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 be392 * called, is used to inform the visitor that all the annotations and393 * attributes of the method have been visited.394 */395 void visitEnd();396 }