diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/clojure/asm/MethodVisitor.java	Sat Aug 21 06:25:44 2010 -0400
     1.3 @@ -0,0 +1,396 @@
     1.4 +/***
     1.5 + * ASM: a very small and fast Java bytecode manipulation framework
     1.6 + * Copyright (c) 2000-2005 INRIA, France Telecom
     1.7 + * All rights reserved.
     1.8 + *
     1.9 + * Redistribution and use in source and binary forms, with or without
    1.10 + * modification, are permitted provided that the following conditions
    1.11 + * are met:
    1.12 + * 1. Redistributions of source code must retain the above copyright
    1.13 + *    notice, this list of conditions and the following disclaimer.
    1.14 + * 2. Redistributions in binary form must reproduce the above copyright
    1.15 + *    notice, this list of conditions and the following disclaimer in the
    1.16 + *    documentation and/or other materials provided with the distribution.
    1.17 + * 3. Neither the name of the copyright holders nor the names of its
    1.18 + *    contributors may be used to endorse or promote products derived from
    1.19 + *    this software without specific prior written permission.
    1.20 + *
    1.21 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    1.22 + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    1.23 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    1.24 + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
    1.25 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
    1.26 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
    1.27 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
    1.28 + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
    1.29 + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    1.30 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
    1.31 + * THE POSSIBILITY OF SUCH DAMAGE.
    1.32 + */
    1.33 +package clojure.asm;
    1.34 +
    1.35 +/**
    1.36 + * A visitor to visit a Java method. The methods of this interface must be
    1.37 + * called in the following order: [ <tt>visitAnnotationDefault</tt> ] (
    1.38 + * <tt>visitAnnotation</tt> | <tt>visitParameterAnnotation</tt> |
    1.39 + * <tt>visitAttribute</tt> )* [ <tt>visitCode</tt> ( <tt>visitFrame</tt> |
    1.40 + * <tt>visit</tt><i>X</i>Insn</tt> | <tt>visitLabel</tt> | <tt>visitTryCatchBlock</tt> |
    1.41 + * <tt>visitLocalVariable</tt> | <tt>visitLineNumber</tt>)* <tt>visitMaxs</tt> ]
    1.42 + * <tt>visitEnd</tt>. In addition, the <tt>visit</tt><i>X</i>Insn</tt>
    1.43 + * and <tt>visitLabel</tt> methods must be called in the sequential order of
    1.44 + * the bytecode instructions of the visited code, <tt>visitTryCatchBlock</tt>
    1.45 + * must be called <i>before</i> the labels passed as arguments have been
    1.46 + * visited, and the <tt>visitLocalVariable</tt> and <tt>visitLineNumber</tt>
    1.47 + * methods must be called <i>after</i> the labels passed as arguments have been
    1.48 + * visited.
    1.49 + *
    1.50 + * @author Eric Bruneton
    1.51 + */
    1.52 +public interface MethodVisitor{
    1.53 +
    1.54 +// -------------------------------------------------------------------------
    1.55 +// Annotations and non standard attributes
    1.56 +// -------------------------------------------------------------------------
    1.57 +
    1.58 +/**
    1.59 + * Visits the default value of this annotation interface method.
    1.60 + *
    1.61 + * @return a visitor to the visit the actual default value of this
    1.62 + *         annotation interface method, or <tt>null</tt> if this visitor
    1.63 + *         is not interested in visiting this default value. The 'name'
    1.64 + *         parameters passed to the methods of this annotation visitor are
    1.65 + *         ignored. Moreover, exacly one visit method must be called on this
    1.66 + *         annotation visitor, followed by visitEnd.
    1.67 + */
    1.68 +AnnotationVisitor visitAnnotationDefault();
    1.69 +
    1.70 +/**
    1.71 + * Visits an annotation of this method.
    1.72 + *
    1.73 + * @param desc    the class descriptor of the annotation class.
    1.74 + * @param visible <tt>true</tt> if the annotation is visible at runtime.
    1.75 + * @return a visitor to visit the annotation values, or <tt>null</tt> if
    1.76 + *         this visitor is not interested in visiting this annotation.
    1.77 + */
    1.78 +AnnotationVisitor visitAnnotation(String desc, boolean visible);
    1.79 +
    1.80 +/**
    1.81 + * Visits an annotation of a parameter this method.
    1.82 + *
    1.83 + * @param parameter the parameter index.
    1.84 + * @param desc      the class descriptor of the annotation class.
    1.85 + * @param visible   <tt>true</tt> if the annotation is visible at runtime.
    1.86 + * @return a visitor to visit the annotation values, or <tt>null</tt> if
    1.87 + *         this visitor is not interested in visiting this annotation.
    1.88 + */
    1.89 +AnnotationVisitor visitParameterAnnotation(
    1.90 +		int parameter,
    1.91 +		String desc,
    1.92 +		boolean visible);
    1.93 +
    1.94 +/**
    1.95 + * Visits a non standard attribute of this method.
    1.96 + *
    1.97 + * @param attr an attribute.
    1.98 + */
    1.99 +void visitAttribute(Attribute attr);
   1.100 +
   1.101 +/**
   1.102 + * Starts the visit of the method's code, if any (i.e. non abstract method).
   1.103 + */
   1.104 +void visitCode();
   1.105 +
   1.106 +/**
   1.107 + * Visits the current state of the local variables and operand stack
   1.108 + * elements. This method must(*) be called <i>just before</i> any
   1.109 + * instruction <b>i</b> that follows an unconditionnal branch instruction
   1.110 + * such as GOTO or THROW, that is the target of a jump instruction, or that
   1.111 + * starts an exception handler block. The visited types must describe the
   1.112 + * values of the local variables and of the operand stack elements <i>just
   1.113 + * before</i> <b>i</b> is executed. <br> <br> (*) this is mandatory only
   1.114 + * for classes whose version is greater than or equal to
   1.115 + * {@link Opcodes#V1_6 V1_6}. <br> <br> Packed frames are basically
   1.116 + * "deltas" from the state of the previous frame (very first frame is
   1.117 + * implicitly defined by the method's parameters and access flags): <ul>
   1.118 + * <li>{@link Opcodes#F_SAME} representing frame with exactly the same
   1.119 + * locals as the previous frame and with the empty stack.</li> <li>{@link Opcodes#F_SAME1}
   1.120 + * representing frame with exactly the same locals as the previous frame and
   1.121 + * with single value on the stack (<code>nStack</code> is 1 and
   1.122 + * <code>stack[0]</code> contains value for the type of the stack item).</li>
   1.123 + * <li>{@link Opcodes#F_APPEND} representing frame with current locals are
   1.124 + * the same as the locals in the previous frame, except that additional
   1.125 + * locals are defined (<code>nLocal</code> is 1, 2 or 3 and
   1.126 + * <code>local</code> elements contains values representing added types).</li>
   1.127 + * <li>{@link Opcodes#F_CHOP} representing frame with current locals are
   1.128 + * the same as the locals in the previous frame, except that the last 1-3
   1.129 + * locals are absent and with the empty stack (<code>nLocals</code> is 1,
   1.130 + * 2 or 3). </li> <li>{@link Opcodes#F_FULL} representing complete frame
   1.131 + * data.</li> </li> </ul>
   1.132 + *
   1.133 + * @param type   the type of this stack map frame. Must be
   1.134 + *               {@link Opcodes#F_NEW} for expanded frames, or
   1.135 + *               {@link Opcodes#F_FULL}, {@link Opcodes#F_APPEND},
   1.136 + *               {@link Opcodes#F_CHOP}, {@link Opcodes#F_SAME} or
   1.137 + *               {@link Opcodes#F_APPEND}, {@link Opcodes#F_SAME1} for compressed
   1.138 + *               frames.
   1.139 + * @param nLocal the number of local variables in the visited frame.
   1.140 + * @param local  the local variable types in this frame. This array must not
   1.141 + *               be modified. Primitive types are represented by
   1.142 + *               {@link Opcodes#TOP}, {@link Opcodes#INTEGER},
   1.143 + *               {@link Opcodes#FLOAT}, {@link Opcodes#LONG},
   1.144 + *               {@link Opcodes#DOUBLE},{@link Opcodes#NULL} or
   1.145 + *               {@link Opcodes#UNINITIALIZED_THIS} (long and double are
   1.146 + *               represented by a single element). Reference types are represented
   1.147 + *               by String objects (representing internal names, or type
   1.148 + *               descriptors for array types), and uninitialized types by Label
   1.149 + *               objects (this label designates the NEW instruction that created
   1.150 + *               this uninitialized value).
   1.151 + * @param nStack the number of operand stack elements in the visited frame.
   1.152 + * @param stack  the operand stack types in this frame. This array must not
   1.153 + *               be modified. Its content has the same format as the "local" array.
   1.154 + */
   1.155 +void visitFrame(
   1.156 +		int type,
   1.157 +		int nLocal,
   1.158 +		Object[] local,
   1.159 +		int nStack,
   1.160 +		Object[] stack);
   1.161 +
   1.162 +// -------------------------------------------------------------------------
   1.163 +// Normal instructions
   1.164 +// -------------------------------------------------------------------------
   1.165 +
   1.166 +/**
   1.167 + * Visits a zero operand instruction.
   1.168 + *
   1.169 + * @param opcode the opcode of the instruction to be visited. This opcode is
   1.170 + *               either NOP, ACONST_NULL, ICONST_M1, ICONST_0, ICONST_1, ICONST_2,
   1.171 + *               ICONST_3, ICONST_4, ICONST_5, LCONST_0, LCONST_1, FCONST_0,
   1.172 + *               FCONST_1, FCONST_2, DCONST_0, DCONST_1, IALOAD, LALOAD, FALOAD,
   1.173 + *               DALOAD, AALOAD, BALOAD, CALOAD, SALOAD, IASTORE, LASTORE, FASTORE,
   1.174 + *               DASTORE, AASTORE, BASTORE, CASTORE, SASTORE, POP, POP2, DUP,
   1.175 + *               DUP_X1, DUP_X2, DUP2, DUP2_X1, DUP2_X2, SWAP, IADD, LADD, FADD,
   1.176 + *               DADD, ISUB, LSUB, FSUB, DSUB, IMUL, LMUL, FMUL, DMUL, IDIV, LDIV,
   1.177 + *               FDIV, DDIV, IREM, LREM, FREM, DREM, INEG, LNEG, FNEG, DNEG, ISHL,
   1.178 + *               LSHL, ISHR, LSHR, IUSHR, LUSHR, IAND, LAND, IOR, LOR, IXOR, LXOR,
   1.179 + *               I2L, I2F, I2D, L2I, L2F, L2D, F2I, F2L, F2D, D2I, D2L, D2F, I2B,
   1.180 + *               I2C, I2S, LCMP, FCMPL, FCMPG, DCMPL, DCMPG, IRETURN, LRETURN,
   1.181 + *               FRETURN, DRETURN, ARETURN, RETURN, ARRAYLENGTH, ATHROW,
   1.182 + *               MONITORENTER, or MONITOREXIT.
   1.183 + */
   1.184 +void visitInsn(int opcode);
   1.185 +
   1.186 +/**
   1.187 + * Visits an instruction with a single int operand.
   1.188 + *
   1.189 + * @param opcode  the opcode of the instruction to be visited. This opcode is
   1.190 + *                either BIPUSH, SIPUSH or NEWARRAY.
   1.191 + * @param operand the operand of the instruction to be visited.<br> When
   1.192 + *                opcode is BIPUSH, operand value should be between Byte.MIN_VALUE
   1.193 + *                and Byte.MAX_VALUE.<br> When opcode is SIPUSH, operand value
   1.194 + *                should be between Short.MIN_VALUE and Short.MAX_VALUE.<br> When
   1.195 + *                opcode is NEWARRAY, operand value should be one of
   1.196 + *                {@link Opcodes#T_BOOLEAN}, {@link Opcodes#T_CHAR},
   1.197 + *                {@link Opcodes#T_FLOAT}, {@link Opcodes#T_DOUBLE},
   1.198 + *                {@link Opcodes#T_BYTE}, {@link Opcodes#T_SHORT},
   1.199 + *                {@link Opcodes#T_INT} or {@link Opcodes#T_LONG}.
   1.200 + */
   1.201 +void visitIntInsn(int opcode, int operand);
   1.202 +
   1.203 +/**
   1.204 + * Visits a local variable instruction. A local variable instruction is an
   1.205 + * instruction that loads or stores the value of a local variable.
   1.206 + *
   1.207 + * @param opcode the opcode of the local variable instruction to be visited.
   1.208 + *               This opcode is either ILOAD, LLOAD, FLOAD, DLOAD, ALOAD, ISTORE,
   1.209 + *               LSTORE, FSTORE, DSTORE, ASTORE or RET.
   1.210 + * @param var    the operand of the instruction to be visited. This operand is
   1.211 + *               the index of a local variable.
   1.212 + */
   1.213 +void visitVarInsn(int opcode, int var);
   1.214 +
   1.215 +/**
   1.216 + * Visits a type instruction. A type instruction is an instruction that
   1.217 + * takes a type descriptor as parameter.
   1.218 + *
   1.219 + * @param opcode the opcode of the type instruction to be visited. This
   1.220 + *               opcode is either NEW, ANEWARRAY, CHECKCAST or INSTANCEOF.
   1.221 + * @param desc   the operand of the instruction to be visited. This operand is
   1.222 + *               must be a fully qualified class name in internal form, or the type
   1.223 + *               descriptor of an array type (see {@link Type Type}).
   1.224 + */
   1.225 +void visitTypeInsn(int opcode, String desc);
   1.226 +
   1.227 +/**
   1.228 + * Visits a field instruction. A field instruction is an instruction that
   1.229 + * loads or stores the value of a field of an object.
   1.230 + *
   1.231 + * @param opcode the opcode of the type instruction to be visited. This
   1.232 + *               opcode is either GETSTATIC, PUTSTATIC, GETFIELD or PUTFIELD.
   1.233 + * @param owner  the internal name of the field's owner class (see {@link
   1.234 + *               Type#getInternalName() getInternalName}).
   1.235 + * @param name   the field's name.
   1.236 + * @param desc   the field's descriptor (see {@link Type Type}).
   1.237 + */
   1.238 +void visitFieldInsn(int opcode, String owner, String name, String desc);
   1.239 +
   1.240 +/**
   1.241 + * Visits a method instruction. A method instruction is an instruction that
   1.242 + * invokes a method.
   1.243 + *
   1.244 + * @param opcode the opcode of the type instruction to be visited. This
   1.245 + *               opcode is either INVOKEVIRTUAL, INVOKESPECIAL, INVOKESTATIC or
   1.246 + *               INVOKEINTERFACE.
   1.247 + * @param owner  the internal name of the method's owner class (see {@link
   1.248 + *               Type#getInternalName() getInternalName}).
   1.249 + * @param name   the method's name.
   1.250 + * @param desc   the method's descriptor (see {@link Type Type}).
   1.251 + */
   1.252 +void visitMethodInsn(int opcode, String owner, String name, String desc);
   1.253 +
   1.254 +/**
   1.255 + * Visits a jump instruction. A jump instruction is an instruction that may
   1.256 + * jump to another instruction.
   1.257 + *
   1.258 + * @param opcode the opcode of the type instruction to be visited. This
   1.259 + *               opcode is either IFEQ, IFNE, IFLT, IFGE, IFGT, IFLE, IF_ICMPEQ,
   1.260 + *               IF_ICMPNE, IF_ICMPLT, IF_ICMPGE, IF_ICMPGT, IF_ICMPLE, IF_ACMPEQ,
   1.261 + *               IF_ACMPNE, GOTO, JSR, IFNULL or IFNONNULL.
   1.262 + * @param label  the operand of the instruction to be visited. This operand
   1.263 + *               is a label that designates the instruction to which the jump
   1.264 + *               instruction may jump.
   1.265 + */
   1.266 +void visitJumpInsn(int opcode, Label label);
   1.267 +
   1.268 +/**
   1.269 + * Visits a label. A label designates the instruction that will be visited
   1.270 + * just after it.
   1.271 + *
   1.272 + * @param label a {@link Label Label} object.
   1.273 + */
   1.274 +void visitLabel(Label label);
   1.275 +
   1.276 +// -------------------------------------------------------------------------
   1.277 +// Special instructions
   1.278 +// -------------------------------------------------------------------------
   1.279 +
   1.280 +/**
   1.281 + * Visits a LDC instruction.
   1.282 + *
   1.283 + * @param cst the constant to be loaded on the stack. This parameter must be
   1.284 + *            a non null {@link Integer}, a {@link Float}, a {@link Long}, a
   1.285 + *            {@link Double} a {@link String} (or a {@link Type} for
   1.286 + *            <tt>.class</tt> constants, for classes whose version is 49.0 or
   1.287 + *            more).
   1.288 + */
   1.289 +void visitLdcInsn(Object cst);
   1.290 +
   1.291 +/**
   1.292 + * Visits an IINC instruction.
   1.293 + *
   1.294 + * @param var       index of the local variable to be incremented.
   1.295 + * @param increment amount to increment the local variable by.
   1.296 + */
   1.297 +void visitIincInsn(int var, int increment);
   1.298 +
   1.299 +/**
   1.300 + * Visits a TABLESWITCH instruction.
   1.301 + *
   1.302 + * @param min    the minimum key value.
   1.303 + * @param max    the maximum key value.
   1.304 + * @param dflt   beginning of the default handler block.
   1.305 + * @param labels beginnings of the handler blocks. <tt>labels[i]</tt> is
   1.306 + *               the beginning of the handler block for the <tt>min + i</tt> key.
   1.307 + */
   1.308 +void visitTableSwitchInsn(int min, int max, Label dflt, Label labels[]);
   1.309 +
   1.310 +/**
   1.311 + * Visits a LOOKUPSWITCH instruction.
   1.312 + *
   1.313 + * @param dflt   beginning of the default handler block.
   1.314 + * @param keys   the values of the keys.
   1.315 + * @param labels beginnings of the handler blocks. <tt>labels[i]</tt> is
   1.316 + *               the beginning of the handler block for the <tt>keys[i]</tt> key.
   1.317 + */
   1.318 +void visitLookupSwitchInsn(Label dflt, int keys[], Label labels[]);
   1.319 +
   1.320 +/**
   1.321 + * Visits a MULTIANEWARRAY instruction.
   1.322 + *
   1.323 + * @param desc an array type descriptor (see {@link Type Type}).
   1.324 + * @param dims number of dimensions of the array to allocate.
   1.325 + */
   1.326 +void visitMultiANewArrayInsn(String desc, int dims);
   1.327 +
   1.328 +// -------------------------------------------------------------------------
   1.329 +// Exceptions table entries, debug information, max stack and max locals
   1.330 +// -------------------------------------------------------------------------
   1.331 +
   1.332 +/**
   1.333 + * Visits a try catch block.
   1.334 + *
   1.335 + * @param start   beginning of the exception handler's scope (inclusive).
   1.336 + * @param end     end of the exception handler's scope (exclusive).
   1.337 + * @param handler beginning of the exception handler's code.
   1.338 + * @param type    internal name of the type of exceptions handled by the
   1.339 + *                handler, or <tt>null</tt> to catch any exceptions (for "finally"
   1.340 + *                blocks).
   1.341 + * @throws IllegalArgumentException if one of the labels has already been
   1.342 + *                                  visited by this visitor (by the {@link #visitLabel visitLabel}
   1.343 + *                                  method).
   1.344 + */
   1.345 +void visitTryCatchBlock(Label start, Label end, Label handler, String type);
   1.346 +
   1.347 +/**
   1.348 + * Visits a local variable declaration.
   1.349 + *
   1.350 + * @param name      the name of a local variable.
   1.351 + * @param desc      the type descriptor of this local variable.
   1.352 + * @param signature the type signature of this local variable. May be
   1.353 + *                  <tt>null</tt> if the local variable type does not use generic
   1.354 + *                  types.
   1.355 + * @param start     the first instruction corresponding to the scope of this
   1.356 + *                  local variable (inclusive).
   1.357 + * @param end       the last instruction corresponding to the scope of this local
   1.358 + *                  variable (exclusive).
   1.359 + * @param index     the local variable's index.
   1.360 + * @throws IllegalArgumentException if one of the labels has not already
   1.361 + *                                  been visited by this visitor (by the
   1.362 + *                                  {@link #visitLabel visitLabel} method).
   1.363 + */
   1.364 +void visitLocalVariable(
   1.365 +		String name,
   1.366 +		String desc,
   1.367 +		String signature,
   1.368 +		Label start,
   1.369 +		Label end,
   1.370 +		int index);
   1.371 +
   1.372 +/**
   1.373 + * Visits a line number declaration.
   1.374 + *
   1.375 + * @param line  a line number. This number refers to the source file from
   1.376 + *              which the class was compiled.
   1.377 + * @param start the first instruction corresponding to this line number.
   1.378 + * @throws IllegalArgumentException if <tt>start</tt> has not already been
   1.379 + *                                  visited by this visitor (by the {@link #visitLabel visitLabel}
   1.380 + *                                  method).
   1.381 + */
   1.382 +void visitLineNumber(int line, Label start);
   1.383 +
   1.384 +/**
   1.385 + * Visits the maximum stack size and the maximum number of local variables
   1.386 + * of the method.
   1.387 + *
   1.388 + * @param maxStack  maximum stack size of the method.
   1.389 + * @param maxLocals maximum number of local variables for the method.
   1.390 + */
   1.391 +void visitMaxs(int maxStack, int maxLocals);
   1.392 +
   1.393 +/**
   1.394 + * Visits the end of the method. This method, which is the last one to be
   1.395 + * called, is used to inform the visitor that all the annotations and
   1.396 + * attributes of the method have been visited.
   1.397 + */
   1.398 +void visitEnd();
   1.399 +}