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