* This method must be called after all the method that is being built has
* been visited. In particular, the {@link Label Label} objects used to
* construct the method are no longer valid after this method has been called.
*
* @param indexes current positions of the instructions to be resized. Each
* instruction must be designated by the index of its last byte,
* plus one (or, in other words, by the index of the first byte of
* the next instruction).
* @param sizes the number of bytes to be added to the above
* instructions. More precisely, for each i < len,
* sizes[i] bytes will be added at the end of the instruction
* designated by indexes[i] or, if sizes[i] is
* negative, the last |sizes[i]| bytes of the instruction
* will be removed (the instruction size must not become negative
* or null). The gaps introduced by this method must be filled in
* "manually" in the array returned by the {@link #getCode getCode}
* method.
* @param len the number of instruction to be resized. Must be smaller than or
* equal to indexes.length and sizes.length.
* @return the indexes array, which now contains the new positions of
* the resized instructions (designated as above).
*/
protected int[] resizeInstructions (
final int[] indexes,
final int[] sizes,
final int len)
{
byte[] b = code.data; // bytecode of the method
int u, v, label; // indexes in b
int i, j; // loop indexes
// 1st step:
// As explained above, resizing an instruction may require to resize another
// one, which may require to resize yet another one, and so on. The first
// step of the algorithm consists in finding all the instructions that
// need to be resized, without modifying the code. This is done by the
// following "fix point" algorithm:
// - parse the code to find the jump instructions whose offset will need
// more than 2 bytes to be stored (the future offset is computed from the
// current offset and from the number of bytes that will be inserted or
// removed between the source and target instructions). For each such
// instruction, adds an entry in (a copy of) the indexes and sizes arrays
// (if this has not already been done in a previous iteration!)
// - if at least one entry has been added during the previous step, go back
// to the beginning, otherwise stop.
// In fact the real algorithm is complicated by the fact that the size of
// TABLESWITCH and LOOKUPSWITCH instructions depends on their position in
// the bytecode (because of padding). In order to ensure the convergence of
// the algorithm, the number of bytes to be added or removed from these
// instructions is over estimated during the previous loop, and computed
// exactly only after the loop is finished (this requires another pass to
// parse the bytecode of the method).
int[] allIndexes = new int[len]; // copy of indexes
int[] allSizes = new int[len]; // copy of sizes
boolean[] resize; // instructions to be resized
int newOffset; // future offset of a jump instruction
System.arraycopy(indexes, 0, allIndexes, 0, len);
System.arraycopy(sizes, 0, allSizes, 0, len);
resize = new boolean[code.length];
int state = 3; // 3 = loop again, 2 = loop ended, 1 = last pass, 0 = done
do {
if (state == 3) {
state = 2;
}
u = 0;
while (u < b.length) {
int opcode = b[u] & 0xFF; // opcode of current instruction
int insert = 0; // bytes to be added after this instruction
switch (ClassWriter.TYPE[opcode]) {
case ClassWriter.NOARG_INSN:
case ClassWriter.IMPLVAR_INSN:
u += 1;
break;
case ClassWriter.LABEL_INSN:
if (opcode > 201) {
// converts temporary opcodes 202 to 217 (inclusive), 218 and 219
// to IFEQ ... JSR (inclusive), IFNULL and IFNONNULL
opcode = opcode < 218 ? opcode - 49 : opcode - 20;
label = u + readUnsignedShort(b, u + 1);
} else {
label = u + readShort(b, u + 1);
}
newOffset = getNewOffset(allIndexes, allSizes, u, label);
if (newOffset < Short.MIN_VALUE || newOffset > Short.MAX_VALUE) {
if (!resize[u]) {
if (opcode == Constants.GOTO || opcode == Constants.JSR) {
// two additional bytes will be required to replace this
// GOTO or JSR instruction with a GOTO_W or a JSR_W
insert = 2;
} else {
// five additional bytes will be required to replace this
// IFxxx
* Note: it is possible to have several entries for the same instruction
* in the indexes and sizes: two entries (index=a,size=b)
* and (index=a,size=b') are equivalent to a single entry (index=a,size=b+b').
*
* @param indexes current positions of the instructions to be resized. Each
* instruction must be designated by the index of its last byte,
* plus one (or, in other words, by the index of the first byte of
* the next instruction).
* @param sizes the number of bytes to be added to the above
* instructions. More precisely, for each i < len,
* sizes[i] bytes will be added at the end of the instruction
* designated by indexes[i] or, if sizes[i] is
* negative, the last |sizes[i]| bytes of the instruction
* will be removed (the instruction size must not become negative
* or null).
* @param begin index of the first byte of the source instruction.
* @param end index of the first byte of the target instruction.
* @return the future value of the given bytecode offset.
*/
static int getNewOffset (
final int[] indexes,
final int[] sizes,
final int begin,
final int end)
{
int offset = end - begin;
for (int i = 0; i < indexes.length; ++i) {
if (begin < indexes[i] && indexes[i] <= end) { // forward jump
offset += sizes[i];
} else if (end < indexes[i] && indexes[i] <= begin) { // backward jump
offset -= sizes[i];
}
}
return offset;
}
/**
* Returns the current size of the bytecode of this method. This size just
* includes the size of the bytecode instructions: it does not include the
* size of the Exceptions, LocalVariableTable, LineNumberTable, Synthetic
* and Deprecated attributes, if present.
*
* @return the current size of the bytecode of this method.
*/
public int getCodeSize () {
return code.length;
}
/**
* Returns the current bytecode of this method. This bytecode only contains
* the instructions: it does not include the Exceptions, LocalVariableTable,
* LineNumberTable, Synthetic and Deprecated attributes, if present.
*
* @return the current bytecode of this method. The bytecode is contained
* between the index 0 (inclusive) and the index {@link #getCodeSize
* getCodeSize} (exclusive).
*/
public byte[] getCode () {
return code.data;
}
}
asm-1.5.3/src/org/objectweb/asm/Constants.java 100644 0 0 26204 10121522035 16363 0 ustar 0 0 /***
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000,2002,2003 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.objectweb.asm;
/**
* Defines the JVM opcodes, access flags and array type codes. This interface
* does not define all the JVM opcodes because some opcodes are automatically
* handled. For example, the xLOAD and xSTORE opcodes are automatically replaced
* by xLOAD_n and xSTORE_n opcodes when possible. The xLOAD_n and xSTORE_n
* opcodes are therefore not defined in this interface. Likewise for LDC,
* automatically replaced by LDC_W or LDC2_W when necessary, WIDE, GOTO_W and
* JSR_W.
*
* @author Eric Bruneton, Eugene Kuleshov
*/
public interface Constants {
// versions
int V1_1 = 3 << 16 | 45;
int V1_2 = 0 << 16 | 46;
int V1_3 = 0 << 16 | 47;
int V1_4 = 0 << 16 | 48;
int V1_5 = 0 << 16 | 49;
// access flags
int ACC_PUBLIC = 0x0001; // class, field, method
int ACC_PRIVATE = 0x0002; // class, field, method
int ACC_PROTECTED = 0x0004; // class, field, method
int ACC_STATIC = 0x0008; // field, method
int ACC_FINAL = 0x0010; // class, field, method
int ACC_SUPER = 0x0020; // class
int ACC_SYNCHRONIZED = 0x0020; // method
int ACC_VOLATILE = 0x0040; // field
int ACC_BRIDGE = 0x0040; // method
int ACC_VARARGS = 0x0080; // method
int ACC_TRANSIENT = 0x0080; // field
int ACC_NATIVE = 0x0100; // method
int ACC_INTERFACE = 0x0200; // class
int ACC_ABSTRACT = 0x0400; // class, method
int ACC_STRICT = 0x0800; // method
int ACC_SYNTHETIC = 0x1000; // class, field, method
int ACC_ANNOTATION = 0x2000; // class
int ACC_ENUM = 0x4000; // class(?) field inner
// ASM specific pseudo access flags
int ACC_DEPRECATED = 131072; // class, field, method
// types for NEWARRAY
int T_BOOLEAN = 4;
int T_CHAR = 5;
int T_FLOAT = 6;
int T_DOUBLE = 7;
int T_BYTE = 8;
int T_SHORT = 9;
int T_INT = 10;
int T_LONG = 11;
// opcodes // visit method (- = idem)
int NOP = 0; // visitInsn
int ACONST_NULL = 1; // -
int ICONST_M1 = 2; // -
int ICONST_0 = 3; // -
int ICONST_1 = 4; // -
int ICONST_2 = 5; // -
int ICONST_3 = 6; // -
int ICONST_4 = 7; // -
int ICONST_5 = 8; // -
int LCONST_0 = 9; // -
int LCONST_1 = 10; // -
int FCONST_0 = 11; // -
int FCONST_1 = 12; // -
int FCONST_2 = 13; // -
int DCONST_0 = 14; // -
int DCONST_1 = 15; // -
int BIPUSH = 16; // visitIntInsn
int SIPUSH = 17; // -
int LDC = 18; // visitLdcInsn
//int LDC_W = 19; // -
//int LDC2_W = 20; // -
int ILOAD = 21; // visitVarInsn
int LLOAD = 22; // -
int FLOAD = 23; // -
int DLOAD = 24; // -
int ALOAD = 25; // -
//int ILOAD_0 = 26; // -
//int ILOAD_1 = 27; // -
//int ILOAD_2 = 28; // -
//int ILOAD_3 = 29; // -
//int LLOAD_0 = 30; // -
//int LLOAD_1 = 31; // -
//int LLOAD_2 = 32; // -
//int LLOAD_3 = 33; // -
//int FLOAD_0 = 34; // -
//int FLOAD_1 = 35; // -
//int FLOAD_2 = 36; // -
//int FLOAD_3 = 37; // -
//int DLOAD_0 = 38; // -
//int DLOAD_1 = 39; // -
//int DLOAD_2 = 40; // -
//int DLOAD_3 = 41; // -
//int ALOAD_0 = 42; // -
//int ALOAD_1 = 43; // -
//int ALOAD_2 = 44; // -
//int ALOAD_3 = 45; // -
int IALOAD = 46; // visitInsn
int LALOAD = 47; // -
int FALOAD = 48; // -
int DALOAD = 49; // -
int AALOAD = 50; // -
int BALOAD = 51; // -
int CALOAD = 52; // -
int SALOAD = 53; // -
int ISTORE = 54; // visitVarInsn
int LSTORE = 55; // -
int FSTORE = 56; // -
int DSTORE = 57; // -
int ASTORE = 58; // -
//int ISTORE_0 = 59; // -
//int ISTORE_1 = 60; // -
//int ISTORE_2 = 61; // -
//int ISTORE_3 = 62; // -
//int LSTORE_0 = 63; // -
//int LSTORE_1 = 64; // -
//int LSTORE_2 = 65; // -
//int LSTORE_3 = 66; // -
//int FSTORE_0 = 67; // -
//int FSTORE_1 = 68; // -
//int FSTORE_2 = 69; // -
//int FSTORE_3 = 70; // -
//int DSTORE_0 = 71; // -
//int DSTORE_1 = 72; // -
//int DSTORE_2 = 73; // -
//int DSTORE_3 = 74; // -
//int ASTORE_0 = 75; // -
//int ASTORE_1 = 76; // -
//int ASTORE_2 = 77; // -
//int ASTORE_3 = 78; // -
int IASTORE = 79; // visitInsn
int LASTORE = 80; // -
int FASTORE = 81; // -
int DASTORE = 82; // -
int AASTORE = 83; // -
int BASTORE = 84; // -
int CASTORE = 85; // -
int SASTORE = 86; // -
int POP = 87; // -
int POP2 = 88; // -
int DUP = 89; // -
int DUP_X1 = 90; // -
int DUP_X2 = 91; // -
int DUP2 = 92; // -
int DUP2_X1 = 93; // -
int DUP2_X2 = 94; // -
int SWAP = 95; // -
int IADD = 96; // -
int LADD = 97; // -
int FADD = 98; // -
int DADD = 99; // -
int ISUB = 100; // -
int LSUB = 101; // -
int FSUB = 102; // -
int DSUB = 103; // -
int IMUL = 104; // -
int LMUL = 105; // -
int FMUL = 106; // -
int DMUL = 107; // -
int IDIV = 108; // -
int LDIV = 109; // -
int FDIV = 110; // -
int DDIV = 111; // -
int IREM = 112; // -
int LREM = 113; // -
int FREM = 114; // -
int DREM = 115; // -
int INEG = 116; // -
int LNEG = 117; // -
int FNEG = 118; // -
int DNEG = 119; // -
int ISHL = 120; // -
int LSHL = 121; // -
int ISHR = 122; // -
int LSHR = 123; // -
int IUSHR = 124; // -
int LUSHR = 125; // -
int IAND = 126; // -
int LAND = 127; // -
int IOR = 128; // -
int LOR = 129; // -
int IXOR = 130; // -
int LXOR = 131; // -
int IINC = 132; // visitIincInsn
int I2L = 133; // visitInsn
int I2F = 134; // -
int I2D = 135; // -
int L2I = 136; // -
int L2F = 137; // -
int L2D = 138; // -
int F2I = 139; // -
int F2L = 140; // -
int F2D = 141; // -
int D2I = 142; // -
int D2L = 143; // -
int D2F = 144; // -
int I2B = 145; // -
int I2C = 146; // -
int I2S = 147; // -
int LCMP = 148; // -
int FCMPL = 149; // -
int FCMPG = 150; // -
int DCMPL = 151; // -
int DCMPG = 152; // -
int IFEQ = 153; // visitJumpInsn
int IFNE = 154; // -
int IFLT = 155; // -
int IFGE = 156; // -
int IFGT = 157; // -
int IFLE = 158; // -
int IF_ICMPEQ = 159; // -
int IF_ICMPNE = 160; // -
int IF_ICMPLT = 161; // -
int IF_ICMPGE = 162; // -
int IF_ICMPGT = 163; // -
int IF_ICMPLE = 164; // -
int IF_ACMPEQ = 165; // -
int IF_ACMPNE = 166; // -
int GOTO = 167; // -
int JSR = 168; // -
int RET = 169; // visitVarInsn
int TABLESWITCH = 170; // visiTableSwitchInsn
int LOOKUPSWITCH = 171; // visitLookupSwitch
int IRETURN = 172; // visitInsn
int LRETURN = 173; // -
int FRETURN = 174; // -
int DRETURN = 175; // -
int ARETURN = 176; // -
int RETURN = 177; // -
int GETSTATIC = 178; // visitFieldInsn
int PUTSTATIC = 179; // -
int GETFIELD = 180; // -
int PUTFIELD = 181; // -
int INVOKEVIRTUAL = 182; // visitMethodInsn
int INVOKESPECIAL = 183; // -
int INVOKESTATIC = 184; // -
int INVOKEINTERFACE = 185; // -
//int UNUSED = 186; // NOT VISITED
int NEW = 187; // visitTypeInsn
int NEWARRAY = 188; // visitIntInsn
int ANEWARRAY = 189; // visitTypeInsn
int ARRAYLENGTH = 190; // visitInsn
int ATHROW = 191; // -
int CHECKCAST = 192; // visitTypeInsn
int INSTANCEOF = 193; // -
int MONITORENTER = 194; // visitInsn
int MONITOREXIT = 195; // -
//int WIDE = 196; // NOT VISITED
int MULTIANEWARRAY = 197; // visitMultiANewArrayInsn
int IFNULL = 198; // visitJumpInsn
int IFNONNULL = 199; // -
//int GOTO_W = 200; // -
//int JSR_W = 201; // -
}
asm-1.5.3/src/org/objectweb/asm/Edge.java 100644 0 0 4772 10070745646 15263 0 ustar 0 0 /***
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000,2002,2003 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.objectweb.asm;
/**
* An edge in the control flow graph of a method body. See {@link Label Label}.
*
* @author Eric Bruneton
*/
class Edge {
/**
* The (relative) stack size in the basic block from which this edge
* originates. This size is equal to the stack size at the "jump" instruction
* to which this edge corresponds, relatively to the stack size at the
* beginning of the originating basic block.
*/
int stackSize;
/**
* The successor block of the basic block from which this edge originates.
*/
Label successor;
/**
* The next edge in the list of successors of the originating basic block.
* See {@link Label#successors successors}.
*/
Edge next;
/**
* The next available edge in the pool. See {@link CodeWriter}.
*/
Edge poolNext;
}
asm-1.5.3/src/org/objectweb/asm/Item.java 100644 0 0 16415 10026564546 15331 0 ustar 0 0 /***
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000,2002,2003 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.objectweb.asm;
/**
* A constant pool item. Constant pool items can be created with the 'newXXX'
* methods in the {@link ClassWriter} class.
*
* @author Eric Bruneton
*/
final class Item {
/**
* Index of this item in the constant pool.
*/
short index;
/**
* Type of this constant pool item. A single class is used to represent all
* constant pool item types, in order to minimize the bytecode size of this
* package. The value of this field is one of the constants defined in the
* {@link ClassWriter ClassWriter} class.
*/
int type;
/**
* Value of this item, for a {@link ClassWriter#INT INT} item.
*/
int intVal;
/**
* Value of this item, for a {@link ClassWriter#LONG LONG} item.
*/
long longVal;
/**
* Value of this item, for a {@link ClassWriter#FLOAT FLOAT} item.
*/
float floatVal;
/**
* Value of this item, for a {@link ClassWriter#DOUBLE DOUBLE} item.
*/
double doubleVal;
/**
* First part of the value of this item, for items that do not hold a
* primitive value.
*/
String strVal1;
/**
* Second part of the value of this item, for items that do not hold a
* primitive value.
*/
String strVal2;
/**
* Third part of the value of this item, for items that do not hold a
* primitive value.
*/
String strVal3;
/**
* The hash code value of this constant pool item.
*/
int hashCode;
/**
* Link to another constant pool item, used for collision lists in the
* constant pool's hash table.
*/
Item next;
/**
* Constructs an uninitialized {@link Item Item} object.
*/
Item () {
}
/**
* Constructs a copy of the given item.
*
* @param index index of the item to be constructed.
* @param i the item that must be copied into the item to be constructed.
*/
Item (final short index, final Item i) {
this.index = index;
type = i.type;
intVal = i.intVal;
longVal = i.longVal;
floatVal = i.floatVal;
doubleVal = i.doubleVal;
strVal1 = i.strVal1;
strVal2 = i.strVal2;
strVal3 = i.strVal3;
hashCode = i.hashCode;
}
/**
* Sets this item to an {@link ClassWriter#INT INT} item.
*
* @param intVal the value of this item.
*/
void set (final int intVal) {
this.type = ClassWriter.INT;
this.intVal = intVal;
this.hashCode = 0x7FFFFFFF & (type + intVal);
}
/**
* Sets this item to a {@link ClassWriter#LONG LONG} item.
*
* @param longVal the value of this item.
*/
void set (final long longVal) {
this.type = ClassWriter.LONG;
this.longVal = longVal;
this.hashCode = 0x7FFFFFFF & (type + (int)longVal);
}
/**
* Sets this item to a {@link ClassWriter#FLOAT FLOAT} item.
*
* @param floatVal the value of this item.
*/
void set (final float floatVal) {
this.type = ClassWriter.FLOAT;
this.floatVal = floatVal;
this.hashCode = 0x7FFFFFFF & (type + (int)floatVal);
}
/**
* Sets this item to a {@link ClassWriter#DOUBLE DOUBLE} item.
*
* @param doubleVal the value of this item.
*/
void set (final double doubleVal) {
this.type = ClassWriter.DOUBLE;
this.doubleVal = doubleVal;
this.hashCode = 0x7FFFFFFF & (type + (int)doubleVal);
}
/**
* Sets this item to an item that do not hold a primitive value.
*
* @param type the type of this item.
* @param strVal1 first part of the value of this item.
* @param strVal2 second part of the value of this item.
* @param strVal3 third part of the value of this item.
*/
void set (
final int type,
final String strVal1,
final String strVal2,
final String strVal3)
{
this.type = type;
this.strVal1 = strVal1;
this.strVal2 = strVal2;
this.strVal3 = strVal3;
switch (type) {
case ClassWriter.UTF8:
case ClassWriter.STR:
case ClassWriter.CLASS:
hashCode = 0x7FFFFFFF & (type + strVal1.hashCode());
return;
case ClassWriter.NAME_TYPE:
hashCode = 0x7FFFFFFF & (type + strVal1.hashCode()*strVal2.hashCode());
return;
//case ClassWriter.FIELD:
//case ClassWriter.METH:
//case ClassWriter.IMETH:
default:
hashCode = 0x7FFFFFFF & (type +
strVal1.hashCode()*strVal2.hashCode()*strVal3.hashCode());
}
}
/**
* Indicates if the given item is equal to this one.
*
* @param i the item to be compared to this one.
* @return true if the given item if equal to this one,
* false otherwise.
*/
boolean isEqualTo (final Item i) {
if (i.type == type) {
switch (type) {
case ClassWriter.INT:
return i.intVal == intVal;
case ClassWriter.LONG:
return i.longVal == longVal;
case ClassWriter.FLOAT:
return i.floatVal == floatVal;
case ClassWriter.DOUBLE:
return i.doubleVal == doubleVal;
case ClassWriter.UTF8:
case ClassWriter.STR:
case ClassWriter.CLASS:
return i.strVal1.equals(strVal1);
case ClassWriter.NAME_TYPE:
return i.strVal1.equals(strVal1) &&
i.strVal2.equals(strVal2);
//case ClassWriter.FIELD:
//case ClassWriter.METH:
//case ClassWriter.IMETH:
default:
return i.strVal1.equals(strVal1) &&
i.strVal2.equals(strVal2) &&
i.strVal3.equals(strVal3);
}
}
return false;
}
}
asm-1.5.3/src/org/objectweb/asm/Label.java 100644 0 0 27434 10147414513 15445 0 ustar 0 0 /***
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000,2002,2003 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.objectweb.asm;
/**
* A label represents a position in the bytecode of a method. Labels are used
* for jump, goto, and switch instructions, and for try catch blocks.
*
* @author Eric Bruneton
*/
public class Label {
/**
* The code writer to which this label belongs, or null if unknown.
*/
CodeWriter owner;
/**
* The line number corresponding to this label, if known.
*/
int line;
/**
* Indicates if the position of this label is known.
*/
boolean resolved;
/**
* The position of this label in the code, if known.
*/
int position;
/**
* If the label position has been updated, after instruction resizing.
*/
boolean resized;
/**
* Number of forward references to this label, times two.
*/
private int referenceCount;
/**
* Informations about forward references. Each forward reference is described
* by two consecutive integers in this array: the first one is the position
* of the first byte of the bytecode instruction that contains the forward
* reference, while the second is the position of the first byte of the
* forward reference itself. In fact the sign of the first integer indicates
* if this reference uses 2 or 4 bytes, and its absolute value gives the
* position of the bytecode instruction.
*/
private int[] srcAndRefPositions;
// --------------------------------------------------------------------------
// Fields for the control flow graph analysis algorithm (used to compute the
// maximum stack size). A control flow graph contains one node per "basic
// block", and one edge per "jump" from one basic block to another. Each node
// (i.e., each basic block) is represented by the Label object that
// corresponds to the first instruction of this basic block. Each node also
// stores the list of it successors in the graph, as a linked list of Edge
// objects.
// --------------------------------------------------------------------------
/**
* The stack size at the beginning of this basic block.
* This size is initially unknown. It is computed by the control flow
* analysis algorithm (see {@link CodeWriter#visitMaxs visitMaxs}).
*/
int beginStackSize;
/**
* The (relative) maximum stack size corresponding to this basic block. This
* size is relative to the stack size at the beginning of the basic block,
* i.e., the true maximum stack size is equal to {@link #beginStackSize
* beginStackSize} + {@link #maxStackSize maxStackSize}.
*/
int maxStackSize;
/**
* The successors of this node in the control flow graph. These successors
* are stored in a linked list of {@link Edge Edge} objects, linked to each
* other by their {@link Edge#next} field.
*/
Edge successors;
/**
* The next basic block in the basic block stack.
* See {@link CodeWriter#visitMaxs visitMaxs}.
*/
Label next;
/**
* true if this basic block has been pushed in the basic block stack.
* See {@link CodeWriter#visitMaxs visitMaxs}.
*/
boolean pushed;
// --------------------------------------------------------------------------
// Constructor
// --------------------------------------------------------------------------
/**
* Constructs a new label.
*/
public Label () {
}
// --------------------------------------------------------------------------
// Methods to compute offsets and to manage forward references
// --------------------------------------------------------------------------
/**
* Returns the offset corresponding to this label. This offset is computed
* from the start of the method's bytecode. This method is intended for
* {@link Attribute} sub classes, and is normally not needed by class
* generators or adapters.
*
* @return the offset corresponding to this label.
* @throws IllegalStateException if this label is not resolved yet.
*/
public int getOffset () {
if (!resolved) {
throw new IllegalStateException(
"Label offset position has not been resolved yet");
}
return position;
}
/**
* Puts a reference to this label in the bytecode of a method. If the position
* of the label is known, the offset is computed and written directly.
* Otherwise, a null offset is written and a new forward reference is declared
* for this label.
*
* @param owner the code writer that calls this method.
* @param out the bytecode of the method.
* @param source the position of first byte of the bytecode instruction that
* contains this label.
* @param wideOffset true if the reference must be stored in 4 bytes,
* or false if it must be stored with 2 bytes.
* @throws IllegalArgumentException if this label has not been created by the
* given code writer.
*/
void put (
final CodeWriter owner,
final ByteVector out,
final int source,
final boolean wideOffset)
{
if (CodeWriter.CHECK) {
if (this.owner == null) {
this.owner = owner;
} else if (this.owner != owner) {
throw new IllegalArgumentException();
}
}
if (resolved) {
if (wideOffset) {
out.putInt(position - source);
} else {
out.putShort(position - source);
}
} else {
if (wideOffset) {
addReference(-1 - source, out.length);
out.putInt(-1);
} else {
addReference(source, out.length);
out.putShort(-1);
}
}
}
/**
* Adds a forward reference to this label. This method must be called only for
* a true forward reference, i.e. only if this label is not resolved yet. For
* backward references, the offset of the reference can be, and must be,
* computed and stored directly.
*
* @param sourcePosition the position of the referencing instruction. This
* position will be used to compute the offset of this forward reference.
* @param referencePosition the position where the offset for this forward
* reference must be stored.
*/
private void addReference (
final int sourcePosition,
final int referencePosition)
{
if (srcAndRefPositions == null) {
srcAndRefPositions = new int[6];
}
if (referenceCount >= srcAndRefPositions.length) {
int[] a = new int[srcAndRefPositions.length + 6];
System.arraycopy(srcAndRefPositions, 0, a, 0, srcAndRefPositions.length);
srcAndRefPositions = a;
}
srcAndRefPositions[referenceCount++] = sourcePosition;
srcAndRefPositions[referenceCount++] = referencePosition;
}
/**
* Resolves all forward references to this label. This method must be called
* when this label is added to the bytecode of the method, i.e. when its
* position becomes known. This method fills in the blanks that where left in
* the bytecode by each forward reference previously added to this label.
*
* @param owner the code writer that calls this method.
* @param position the position of this label in the bytecode.
* @param data the bytecode of the method.
* @return true if a blank that was left for this label was to small
* to store the offset. In such a case the corresponding jump instruction
* is replaced with a pseudo instruction (using unused opcodes) using an
* unsigned two bytes offset. These pseudo instructions will need to be
* replaced with true instructions with wider offsets (4 bytes instead of
* 2). This is done in {@link CodeWriter#resizeInstructions}.
* @throws IllegalArgumentException if this label has already been resolved,
* or if it has not been created by the given code writer.
*/
boolean resolve (
final CodeWriter owner,
final int position,
final byte[] data)
{
if (CodeWriter.CHECK) {
if (this.owner == null) {
this.owner = owner;
}
if (resolved || this.owner != owner) {
throw new IllegalArgumentException();
}
}
boolean needUpdate = false;
this.resolved = true;
this.position = position;
int i = 0;
while (i < referenceCount) {
int source = srcAndRefPositions[i++];
int reference = srcAndRefPositions[i++];
int offset;
if (source >= 0) {
offset = position - source;
if (offset < Short.MIN_VALUE || offset > Short.MAX_VALUE) {
// changes the opcode of the jump instruction, in order to be able to
// find it later (see resizeInstructions in CodeWriter). These
// temporary opcodes are similar to jump instruction opcodes, except
// that the 2 bytes offset is unsigned (and can therefore represent
// values from 0 to 65535, which is sufficient since the size of a
// method is limited to 65535 bytes).
int opcode = data[reference - 1] & 0xFF;
if (opcode <= Constants.JSR) {
// changes IFEQ ... JSR to opcodes 202 to 217 (inclusive)
data[reference - 1] = (byte)(opcode + 49);
} else {
// changes IFNULL and IFNONNULL to opcodes 218 and 219 (inclusive)
data[reference - 1] = (byte)(opcode + 20);
}
needUpdate = true;
}
data[reference++] = (byte)(offset >>> 8);
data[reference] = (byte)offset;
} else {
offset = position + source + 1;
data[reference++] = (byte)(offset >>> 24);
data[reference++] = (byte)(offset >>> 16);
data[reference++] = (byte)(offset >>> 8);
data[reference] = (byte)offset;
}
}
return needUpdate;
}
// --------------------------------------------------------------------------
// Overriden Object methods
// --------------------------------------------------------------------------
/**
* Returns a string representation of this label.
*
* @return a string representation of this label.
*/
public String toString () {
return "L" + System.identityHashCode(this);
}
}
asm-1.5.3/src/org/objectweb/asm/Type.java 100644 0 0 52242 10026564546 15352 0 ustar 0 0 /***
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000,2002,2003 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.objectweb.asm;
import java.lang.reflect.Method;
/**
* A Java type. This class can be used to make it easier to manipulate type
* and method descriptors.
*
* @author Eric Bruneton, Chris Nokleberg
*/
public class Type {
/**
* The sort of the void type. See {@link #getSort getSort}.
*/
public final static int VOID = 0;
/**
* The sort of the boolean type. See {@link #getSort getSort}.
*/
public final static int BOOLEAN = 1;
/**
* The sort of the char type. See {@link #getSort getSort}.
*/
public final static int CHAR = 2;
/**
* The sort of the byte type. See {@link #getSort getSort}.
*/
public final static int BYTE = 3;
/**
* The sort of the short type. See {@link #getSort getSort}.
*/
public final static int SHORT = 4;
/**
* The sort of the int type. See {@link #getSort getSort}.
*/
public final static int INT = 5;
/**
* The sort of the float type. See {@link #getSort getSort}.
*/
public final static int FLOAT = 6;
/**
* The sort of the long type. See {@link #getSort getSort}.
*/
public final static int LONG = 7;
/**
* The sort of the double type. See {@link #getSort getSort}.
*/
public final static int DOUBLE = 8;
/**
* The sort of array reference types. See {@link #getSort getSort}.
*/
public final static int ARRAY = 9;
/**
* The sort of object reference type. See {@link #getSort getSort}.
*/
public final static int OBJECT = 10;
/**
* The void type.
*/
public final static Type VOID_TYPE = new Type(VOID);
/**
* The boolean type.
*/
public final static Type BOOLEAN_TYPE = new Type(BOOLEAN);
/**
* The char type.
*/
public final static Type CHAR_TYPE = new Type(CHAR);
/**
* The byte type.
*/
public final static Type BYTE_TYPE = new Type(BYTE);
/**
* The short type.
*/
public final static Type SHORT_TYPE = new Type(SHORT);
/**
* The int type.
*/
public final static Type INT_TYPE = new Type(INT);
/**
* The float type.
*/
public final static Type FLOAT_TYPE = new Type(FLOAT);
/**
* The long type.
*/
public final static Type LONG_TYPE = new Type(LONG);
/**
* The double type.
*/
public final static Type DOUBLE_TYPE = new Type(DOUBLE);
// --------------------------------------------------------------------------
// Fields
// --------------------------------------------------------------------------
/**
* The sort of this Java type.
*/
private final int sort;
/**
* A buffer containing the descriptor of this Java type.
* This field is only used for reference types.
*/
private char[] buf;
/**
* The offset of the descriptor of this Java type in {@link #buf buf}.
* This field is only used for reference types.
*/
private int off;
/**
* The length of the descriptor of this Java type.
*/
private int len;
// --------------------------------------------------------------------------
// Constructors
// --------------------------------------------------------------------------
/**
* Constructs a primitive type.
*
* @param sort the sort of the primitive type to be constructed.
*/
private Type (final int sort) {
this.sort = sort;
this.len = 1;
}
/**
* Constructs a reference type.
*
* @param sort the sort of the reference type to be constructed.
* @param buf a buffer containing the descriptor of the previous type.
* @param off the offset of this descriptor in the previous buffer.
* @param len the length of this descriptor.
*/
private Type (
final int sort,
final char[] buf,
final int off,
final int len)
{
this.sort = sort;
this.buf = buf;
this.off = off;
this.len = len;
}
/**
* Returns the Java type corresponding to the given type descriptor.
*
* @param typeDescriptor a type descriptor.
* @return the Java type corresponding to the given type descriptor.
*/
public static Type getType (final String typeDescriptor) {
return getType(typeDescriptor.toCharArray(), 0);
}
/**
* Returns the Java type corresponding to the given class.
*
* @param c a class.
* @return the Java type corresponding to the given class.
*/
public static Type getType (final Class c) {
if (c.isPrimitive()) {
if (c == Integer.TYPE) {
return INT_TYPE;
} else if (c == Void.TYPE) {
return VOID_TYPE;
} else if (c == Boolean.TYPE) {
return BOOLEAN_TYPE;
} else if (c == Byte.TYPE) {
return BYTE_TYPE;
} else if (c == Character.TYPE) {
return CHAR_TYPE;
} else if (c == Short.TYPE) {
return SHORT_TYPE;
} else if (c == Double.TYPE) {
return DOUBLE_TYPE;
} else if (c == Float.TYPE) {
return FLOAT_TYPE;
} else /*if (c == Long.TYPE)*/ {
return LONG_TYPE;
}
} else {
return getType(getDescriptor(c));
}
}
/**
* Returns the Java types corresponding to the argument types of the given
* method descriptor.
*
* @param methodDescriptor a method descriptor.
* @return the Java types corresponding to the argument types of the given
* method descriptor.
*/
public static Type[] getArgumentTypes (final String methodDescriptor) {
char[] buf = methodDescriptor.toCharArray();
int off = 1;
int size = 0;
while (true) {
char car = buf[off++];
if (car == ')') {
break;
} else if (car == 'L') {
while (buf[off++] != ';') {
}
++size;
} else if (car != '[') {
++size;
}
}
Type[] args = new Type[size];
off = 1;
size = 0;
while (buf[off] != ')') {
args[size] = getType(buf, off);
off += args[size].len;
size += 1;
}
return args;
}
/**
* Returns the Java types corresponding to the argument types of the given
* method.
*
* @param method a method.
* @return the Java types corresponding to the argument types of the given
* method.
*/
public static Type[] getArgumentTypes (final Method method) {
Class[] classes = method.getParameterTypes();
Type[] types = new Type[classes.length];
for (int i = classes.length - 1; i >= 0; --i) {
types[i] = getType(classes[i]);
}
return types;
}
/**
* Returns the Java type corresponding to the return type of the given
* method descriptor.
*
* @param methodDescriptor a method descriptor.
* @return the Java type corresponding to the return type of the given
* method descriptor.
*/
public static Type getReturnType (final String methodDescriptor) {
char[] buf = methodDescriptor.toCharArray();
return getType(buf, methodDescriptor.indexOf(')') + 1);
}
/**
* Returns the Java type corresponding to the return type of the given
* method.
*
* @param method a method.
* @return the Java type corresponding to the return type of the given
* method.
*/
public static Type getReturnType (final Method method) {
return getType(method.getReturnType());
}
/**
* Returns the Java type corresponding to the given type descriptor.
*
* @param buf a buffer containing a type descriptor.
* @param off the offset of this descriptor in the previous buffer.
* @return the Java type corresponding to the given type descriptor.
*/
private static Type getType (final char[] buf, final int off) {
int len;
switch (buf[off]) {
case 'V': return VOID_TYPE;
case 'Z': return BOOLEAN_TYPE;
case 'C': return CHAR_TYPE;
case 'B': return BYTE_TYPE;
case 'S': return SHORT_TYPE;
case 'I': return INT_TYPE;
case 'F': return FLOAT_TYPE;
case 'J': return LONG_TYPE;
case 'D': return DOUBLE_TYPE;
case '[':
len = 1;
while (buf[off + len] == '[') {
++len;
}
if (buf[off + len] == 'L') {
++len;
while (buf[off + len] != ';') {
++len;
}
}
return new Type(ARRAY, buf, off, len + 1);
//case 'L':
default:
len = 1;
while (buf[off + len] != ';') {
++len;
}
return new Type(OBJECT, buf, off, len + 1);
}
}
// --------------------------------------------------------------------------
// Accessors
// --------------------------------------------------------------------------
/**
* Returns the sort of this Java type.
*
* @return {@link #VOID VOID}, {@link #BOOLEAN BOOLEAN}, {@link #CHAR CHAR},
* {@link #BYTE BYTE}, {@link #SHORT SHORT}, {@link #INT INT}, {@link
* #FLOAT FLOAT}, {@link #LONG LONG}, {@link #DOUBLE DOUBLE}, {@link
* #ARRAY ARRAY} or {@link #OBJECT OBJECT}.
*/
public int getSort () {
return sort;
}
/**
* Returns the number of dimensions of this array type.
* This method should only be used for an array type.
*
* @return the number of dimensions of this array type.
*/
public int getDimensions () {
int i = 1;
while (buf[off + i] == '[') {
++i;
}
return i;
}
/**
* Returns the type of the elements of this array type.
* This method should only be used for an array type.
*
* @return Returns the type of the elements of this array type.
*/
public Type getElementType () {
return getType(buf, off + getDimensions());
}
/**
* Returns the name of the class corresponding to this type.
*
* @return the fully qualified name of the class corresponding to this type.
*/
public String getClassName () {
switch (sort) {
case VOID: return "void";
case BOOLEAN: return "boolean";
case CHAR: return "char";
case BYTE: return "byte";
case SHORT: return "short";
case INT: return "int";
case FLOAT: return "float";
case LONG: return "long";
case DOUBLE: return "double";
case ARRAY:
StringBuffer b = new StringBuffer(getElementType().getClassName());
for (int i = getDimensions(); i > 0; --i) {
b.append("[]");
}
return b.toString();
//case OBJECT:
default:
return new String(buf, off + 1, len - 2).replace('/', '.');
}
}
/**
* Returns the internal name of the class corresponding to this object type.
* The internal name of a class is its fully qualified name, where '.' are
* replaced by '/'. This method should only be used for an object type.
*
* @return the internal name of the class corresponding to this object type.
*/
public String getInternalName () {
return new String(buf, off + 1, len - 2);
}
// --------------------------------------------------------------------------
// Conversion to type descriptors
// --------------------------------------------------------------------------
/**
* Returns the descriptor corresponding to this Java type.
*
* @return the descriptor corresponding to this Java type.
*/
public String getDescriptor () {
StringBuffer buf = new StringBuffer();
getDescriptor(buf);
return buf.toString();
}
/**
* Returns the descriptor corresponding to the given argument and return
* types.
*
* @param returnType the return type of the method.
* @param argumentTypes the argument types of the method.
* @return the descriptor corresponding to the given argument and return
* types.
*/
public static String getMethodDescriptor (
final Type returnType,
final Type[] argumentTypes)
{
StringBuffer buf = new StringBuffer();
buf.append('(');
for (int i = 0; i < argumentTypes.length; ++i) {
argumentTypes[i].getDescriptor(buf);
}
buf.append(')');
returnType.getDescriptor(buf);
return buf.toString();
}
/**
* Appends the descriptor corresponding to this Java type to the given string
* buffer.
*
* @param buf the string buffer to which the descriptor must be appended.
*/
private void getDescriptor (final StringBuffer buf) {
switch (sort) {
case VOID: buf.append('V'); return;
case BOOLEAN: buf.append('Z'); return;
case CHAR: buf.append('C'); return;
case BYTE: buf.append('B'); return;
case SHORT: buf.append('S'); return;
case INT: buf.append('I'); return;
case FLOAT: buf.append('F'); return;
case LONG: buf.append('J'); return;
case DOUBLE: buf.append('D'); return;
//case ARRAY:
//case OBJECT:
default: buf.append(this.buf, off, len);
}
}
// --------------------------------------------------------------------------
// Direct conversion from classes to type descriptors,
// without intermediate Type objects
// --------------------------------------------------------------------------
/**
* Returns the internal name of the given class. The internal name of a class
* is its fully qualified name, where '.' are replaced by '/'.
*
* @param c an object class.
* @return the internal name of the given class.
*/
public static String getInternalName (final Class c) {
return c.getName().replace('.', '/');
}
/**
* Returns the descriptor corresponding to the given Java type.
*
* @param c an object class, a primitive class or an array class.
* @return the descriptor corresponding to the given class.
*/
public static String getDescriptor (final Class c) {
StringBuffer buf = new StringBuffer();
getDescriptor(buf, c);
return buf.toString();
}
/**
* Returns the descriptor corresponding to the given method.
*
* @param m a {@link Method Method} object.
* @return the descriptor of the given method.
*/
public static String getMethodDescriptor (final Method m) {
Class[] parameters = m.getParameterTypes();
StringBuffer buf = new StringBuffer();
buf.append('(');
for (int i = 0; i < parameters.length; ++i) {
getDescriptor(buf, parameters[i]);
}
buf.append(')');
getDescriptor(buf, m.getReturnType());
return buf.toString();
}
/**
* Appends the descriptor of the given class to the given string buffer.
*
* @param buf the string buffer to which the descriptor must be appended.
* @param c the class whose descriptor must be computed.
*/
private static void getDescriptor (final StringBuffer buf, final Class c) {
Class d = c;
while (true) {
if (d.isPrimitive()) {
char car;
if (d == Integer.TYPE) {
car = 'I';
} else if (d == Void.TYPE) {
car = 'V';
} else if (d == Boolean.TYPE) {
car = 'Z';
} else if (d == Byte.TYPE) {
car = 'B';
} else if (d == Character.TYPE) {
car = 'C';
} else if (d == Short.TYPE) {
car = 'S';
} else if (d == Double.TYPE) {
car = 'D';
} else if (d == Float.TYPE) {
car = 'F';
} else /*if (d == Long.TYPE)*/ {
car = 'J';
}
buf.append(car);
return;
} else if (d.isArray()) {
buf.append('[');
d = d.getComponentType();
} else {
buf.append('L');
String name = d.getName();
int len = name.length();
for (int i = 0; i < len; ++i) {
char car = name.charAt(i);
buf.append(car == '.' ? '/' : car);
}
buf.append(';');
return;
}
}
}
// --------------------------------------------------------------------------
// Corresponding size and opcodes
// --------------------------------------------------------------------------
/**
* Returns the size of values of this type.
*
* @return the size of values of this type, i.e., 2 for long and
* double, and 1 otherwise.
*/
public int getSize () {
return (sort == LONG || sort == DOUBLE ? 2 : 1);
}
/**
* Returns a JVM instruction opcode adapted to this Java type.
*
* @param opcode a JVM instruction opcode. This opcode must be one of ILOAD,
* ISTORE, IALOAD, IASTORE, IADD, ISUB, IMUL, IDIV, IREM, INEG, ISHL,
* ISHR, IUSHR, IAND, IOR, IXOR and IRETURN.
* @return an opcode that is similar to the given opcode, but adapted to this
* Java type. For example, if this type is float and
* opcode is IRETURN, this method returns FRETURN.
*/
public int getOpcode (final int opcode) {
if (opcode == Constants.IALOAD || opcode == Constants.IASTORE) {
switch (sort) {
case BOOLEAN:
case BYTE:
return opcode + 5;
case CHAR:
return opcode + 6;
case SHORT:
return opcode + 7;
case INT:
return opcode;
case FLOAT:
return opcode + 2;
case LONG:
return opcode + 1;
case DOUBLE:
return opcode + 3;
//case ARRAY:
//case OBJECT:
default:
return opcode + 4;
}
} else {
switch (sort) {
case VOID:
return opcode + 5;
case BOOLEAN:
case CHAR:
case BYTE:
case SHORT:
case INT:
return opcode;
case FLOAT:
return opcode + 2;
case LONG:
return opcode + 1;
case DOUBLE:
return opcode + 3;
//case ARRAY:
//case OBJECT:
default:
return opcode + 4;
}
}
}
// --------------------------------------------------------------------------
// Equals, hashCode and toString
// --------------------------------------------------------------------------
/**
* Tests if the given object is equal to this type.
*
* @param o the object to be compared to this type.
* @return true if the given object is equal to this type.
*/
public boolean equals (final Object o) {
if (this == o) {
return true;
}
if (o == null || !(o instanceof Type)) {
return false;
}
Type t = (Type)o;
if (sort != t.sort) {
return false;
}
if (sort == Type.OBJECT || sort == Type.ARRAY) {
if (len != t.len) {
return false;
}
for (int i = off, j = t.off, end = i + len; i < end; i++, j++) {
if (buf[i] != t.buf[j]) {
return false;
}
}
}
return true;
}
/**
* Returns a hash code value for this type.
*
* @return a hash code value for this type.
*/
public int hashCode () {
int hc = 13 * sort;
if (sort == Type.OBJECT || sort == Type.ARRAY) {
for (int i = off, end = i + len; i < end; i++) {
hc = 17 * (hc + buf[i]);
}
}
return hc;
}
/**
* Returns a string representation of this type.
*
* @return the descriptor of this type.
*/
public String toString () {
return getDescriptor();
}
}
asm-1.5.3/src/org/objectweb/asm/attrs/Annotation.java 100644 0 0 65357 10140372437 17704 0 ustar 0 0 /**
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000,2002,2003 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.objectweb.asm.attrs;
import java.util.ArrayList;
import java.util.List;
import org.objectweb.asm.ByteVector;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Type;
/**
* Annotation data contains an annotated type and its array of the element-value
* pairs. Structure is in the following format:
*
* The element_value structure has the following format:
*
* The AnnotationDefault attribute has the following format:
*
* The LocalVariableTypeTable attribute has the following format:
*
* The value of the signature_index item must be a valid index
* into the constant_pool table. The constant_pool entry at that index
* must contain a CONSTANT_Utf8_info structure
* representing a field type signature encoding the type
* of a local variable in the source program.
*
*
* The RuntimeInvisibleAnnotations attribute is a variable length attribute in the
* attributes table of the ClassFile, field_info, and method_info structures. The
* RuntimeInvisibleAnnotations attribute records runtime-invisible Java
* programming language annotations on the corresponding class, method, or field.
* Each ClassFile, field_info, and method_info structure may contain at most one
* RuntimeInvisibleAnnotations attribute, which records all the runtime-invisible
* Java programming language annotations on the corresponding program element.
*
* The RuntimeInvisibleAnnotations attribute has the following format:
*
* The RuntimeInvisibleParameterAnnotations attribute is a variable length
* attribute in the attributes table of the method_info structure. The
* RuntimeInvisibleParameterAnnotations attribute records runtime-invisible Java
* programming language annotations on the parameters of the corresponding method.
* Each method_info structure may contain at most one
* RuntimeInvisibleParameterAnnotations attribute, which records all the
* runtime-invisible Java programming language annotations on the parameters of
* the corresponding method.
*
* The RuntimeInvisibleParameterAnnotations attribute has the following format:
*
* The RuntimeVisibleAnnotations attribute has the following format:
*
* The RuntimeVisibleParameterAnnotations attribute has the following format:
*
* Classfiles need to carry generic type information in a backwards
* compatible way. This is accomplished by introducing a new "Signature"
* attribute for classes, methods and fields. The structure of this
* attribute is as follows:
*
* The type syntax in signatures is extended to parameterized types and
* type variables. There is also a new signature syntax for formal type
* parameters. The syntax extensions for signature strings are as follows:
*
* Note that this implementation does not calculate StackMapFrame structures
* from the method bytecode. If method code is changed or generated from scratch,
* then developer is responsible to prepare a correct StackMapFrame structures.
*
* The format of the stack map in the class file is given below. In the following,
*
By default ASM strips optional attributes, in order to keep them in
the bytecode that is being readed should pass an array of required attribute
instances to {@link org.objectweb.asm.ClassReader#accept(org.objectweb.asm.ClassVisitor, org.objectweb.asm.Attribute[], boolean) ClassReader.accept()} method.
In order to add custom attributes to the manually constructed bytecode concrete
subclasses of the {@link org.objectweb.asm.Attribute Attribute} can be passed to the correspond
visit methods of the {@link org.objectweb.asm.ClassVisitor ClassVisitor} and
{@link org.objectweb.asm.CodeVisitor CodeVisitor}.
@since ASM 1.4.1
asm-1.5.3/src/org/objectweb/asm/package.html 100644 0 0 11143 10026564546 16042 0 ustar 0 0
The ASM framework is organized
around the {@link org.objectweb.asm.ClassVisitor ClassVisitor} and {@link
org.objectweb.asm.CodeVisitor CodeVisitor} interfaces, which allows one to
visit the fields and methods of a class, including the bytecode instructions of
each method.
In addition to these two main interfaces, ASM provides a {@link
org.objectweb.asm.ClassReader ClassReader} class, that can parse an
existing class and make a given visitor visit it. ASM also provides
a {@link org.objectweb.asm.ClassWriter ClassWriter} class, which is
a visitor that generates Java class files.
In order to generate a class from scratch, only the {@link
org.objectweb.asm.ClassWriter ClassWriter} class is necessary. Indeed,
in order to generate a class, one must just call its visitXXX
methods with the appropriate arguments to generate the desired fields
and methods. See the "helloworld" example in the ASM distribution for
more details about class generation.
In order to modify existing classes, one must use a {@link
org.objectweb.asm.ClassReader ClassReader} class to analyse
the original class, a class modifier, and a {@link org.objectweb.asm.ClassWriter
ClassWriter} to construct the modified class. The class modifier
is just a {@link org.objectweb.asm.ClassVisitor ClassVisitor}
that delegates most of the work to another {@link org.objectweb.asm.ClassVisitor
ClassVisitor}, but that sometimes changes some parameter values,
or call additional methods, in order to implement the desired
modification process. In order to make it easier to implement such
class modifiers, ASM provides the {@link org.objectweb.asm.ClassAdapter
ClassAdapter} and {@link org.objectweb.asm.CodeAdapter CodeAdapter}
classes, which implement the {@link org.objectweb.asm.ClassVisitor ClassVisitor} and
{@link org.objectweb.asm.CodeVisitor CodeVisitor} interfaces by delegating
all work to other visitors. See the "adapt" example in the ASM distribution
for more details about class modification.
The size of the core ASM library, asm.jar, is only 25KB, which is much
more smaller than
the size of the BCEL library (350KB
without the class verifier), and than the size of the
SERP library (150KB). ASM is also
much more faster than these tools. Indeed the overhead of a load time class
transformation process is of the order of 60% with ASM, 700% or more with BCEL,
and 1100% or more with SERP (see the test/perf directory in the ASM
distribution)! kASM is a subset of ASM, for class generation only (it includes
the {@link org.objectweb.asm.ClassWriter ClassWriter}, but not the {@link
org.objectweb.asm.ClassReader ClassReader}). The size of this library,
kasm.jar, is only 16KB.
@since ASM 1.3
asm-1.5.3/src/org/objectweb/asm/tree/AbstractInsnNode.java 100644 0 0 5025 10026564546 20546 0 ustar 0 0 /***
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000,2002,2003 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.objectweb.asm.tree;
import org.objectweb.asm.CodeVisitor;
/**
* A node that represents a bytecode instruction.
*
* @author Eric Bruneton
*/
public abstract class AbstractInsnNode {
/**
* The opcode of this instruction.
*/
protected int opcode;
/**
* Constructs a new {@link AbstractInsnNode AbstractInsnNode} object.
*
* @param opcode the opcode of the instruction to be constructed.
*/
protected AbstractInsnNode (final int opcode) {
this.opcode = opcode;
}
/**
* Returns the opcode of this instruction.
*
* @return the opcode of this instruction.
*/
public int getOpcode () {
return opcode;
}
/**
* Makes the given code visitor visit this instruction.
*
* @param cv a code visitor.
*/
public abstract void accept (final CodeVisitor cv);
}
asm-1.5.3/src/org/objectweb/asm/tree/ClassNode.java 100644 0 0 14001 10112601423 17210 0 ustar 0 0 /***
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000,2002,2003 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.objectweb.asm.tree;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.Attribute;
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
/**
* A node that represents a class.
*
* @author Eric Bruneton
*/
public class ClassNode {
/**
* The class version.
*/
public int version;
/**
* The class's access flags (see {@link org.objectweb.asm.Constants}). This
* field also indicates if the class is deprecated.
*/
public int access;
/**
* The internal name of the class (see {@link
* org.objectweb.asm.Type#getInternalName() getInternalName}).
*/
public String name;
/**
* The internal of name of the super class (see {@link
* org.objectweb.asm.Type#getInternalName() getInternalName}). For interfaces,
* the super class is {@link Object}. May be null, but only for the
* {@link Object java.lang.Object} class.
*/
public String superName;
/**
* The internal names of the class's interfaces (see {@link
* org.objectweb.asm.Type#getInternalName() getInternalName}). This list is a
* list of {@link String} objects.
*/
public final List interfaces;
/**
* The name of the source file from which this class was compiled. May be
* null.
*/
public String sourceFile;
/**
* Informations about the inner classes of this class. This list is a list of
* {@link InnerClassNode InnerClassNode} objects.
*/
public final List innerClasses;
/**
* The fields of this class. This list is a list of {@link FieldNode
* FieldNode} objects.
*/
public final List fields;
/**
* The methods of this class. This list is a list of {@link MethodNode
* MethodNode} objects.
*/
public final List methods;
/**
* The non standard attributes of the class.
*/
public Attribute attrs;
/**
* Constructs a new {@link ClassNode ClassNode} object.
*
* @param version the class version.
* @param access the class's access flags (see {@link
* org.objectweb.asm.Constants}). This parameter also indicates if the
* class is deprecated.
* @param name the internal name of the class (see {@link
* org.objectweb.asm.Type#getInternalName() getInternalName}).
* @param superName the internal of name of the super class (see {@link
* org.objectweb.asm.Type#getInternalName() getInternalName}). For
* interfaces, the super class is {@link Object}.
* @param interfaces the internal names of the class's interfaces (see {@link
* org.objectweb.asm.Type#getInternalName() getInternalName}). May be
* null.
* @param sourceFile the name of the source file from which this class was
* compiled. May be null.
*/
public ClassNode (
final int version,
final int access,
final String name,
final String superName,
final String[] interfaces,
final String sourceFile)
{
this.version = version;
this.access = access;
this.name = name;
this.superName = superName;
this.interfaces = new ArrayList();
this.sourceFile = sourceFile;
this.innerClasses = new ArrayList();
this.fields = new ArrayList();
this.methods = new ArrayList();
if (interfaces != null) {
this.interfaces.addAll(Arrays.asList(interfaces));
}
}
/**
* Makes the given class visitor visit this class.
*
* @param cv a class visitor.
*/
public void accept (final ClassVisitor cv) {
// visits header
String[] interfaces = new String[this.interfaces.size()];
this.interfaces.toArray(interfaces);
cv.visit(version, access, name, superName, interfaces, sourceFile);
// visits inner classes
int i;
for (i = 0; i < innerClasses.size(); ++i) {
((InnerClassNode)innerClasses.get(i)).accept(cv);
}
// visits fields
for (i = 0; i < fields.size(); ++i) {
((FieldNode)fields.get(i)).accept(cv);
}
// visits methods
for (i = 0; i < methods.size(); ++i) {
((MethodNode)methods.get(i)).accept(cv);
}
// visits attributes
Attribute attrs = this.attrs;
while (attrs != null) {
cv.visitAttribute(attrs);
attrs = attrs.next;
}
// visits end
cv.visitEnd();
}
}
asm-1.5.3/src/org/objectweb/asm/tree/FieldInsnNode.java 100644 0 0 6632 10070745646 20034 0 ustar 0 0 /***
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000,2002,2003 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.objectweb.asm.tree;
import org.objectweb.asm.CodeVisitor;
/**
* A node that represents a field instruction. A field instruction is an
* instruction that loads or stores the value of a field of an object.
*
* @author Eric Bruneton
*/
public class FieldInsnNode extends AbstractInsnNode {
/**
* The internal name of the field's owner class (see {@link
* org.objectweb.asm.Type#getInternalName() getInternalName}).
*/
public String owner;
/**
* The field's name.
*/
public String name;
/**
* The field's descriptor (see {@link org.objectweb.asm.Type Type}).
*/
public String desc;
/**
* Constructs a new {@link FieldInsnNode FieldInsnNode} object.
*
* @param opcode the opcode of the type instruction to be constructed. This
* opcode must be GETSTATIC, PUTSTATIC, GETFIELD or PUTFIELD.
* @param owner the internal name of the field's owner class (see {@link
* org.objectweb.asm.Type#getInternalName() getInternalName}).
* @param name the field's name.
* @param desc the field's descriptor (see {@link org.objectweb.asm.Type
* Type}).
*/
public FieldInsnNode (
final int opcode,
final String owner,
final String name,
final String desc)
{
super(opcode);
this.owner = owner;
this.name = name;
this.desc = desc;
}
/**
* Sets the opcode of this instruction.
*
* @param opcode the new instruction opcode. This opcode must be GETSTATIC,
* PUTSTATIC, GETFIELD or PUTFIELD.
*/
public void setOpcode (final int opcode) {
this.opcode = opcode;
}
public void accept (final CodeVisitor cv) {
cv.visitFieldInsn(opcode, owner, name, desc);
}
}
asm-1.5.3/src/org/objectweb/asm/tree/FieldNode.java 100644 0 0 7704 10026564546 17204 0 ustar 0 0 /***
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000,2002,2003 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.objectweb.asm.tree;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.Attribute;
/**
* A node that represents a field.
*
* @author Eric Bruneton
*/
public class FieldNode {
/**
* The field's access flags (see {@link org.objectweb.asm.Constants}). This
* field also indicates if the field is synthetic and/or deprecated.
*/
public int access;
/**
* The field's name.
*/
public String name;
/**
* The field's descriptor (see {@link org.objectweb.asm.Type Type}).
*/
public String desc;
/**
* The field's initial value. This field, which may be null if the
* field does not have an initial value, must be an {@link java.lang.Integer
* Integer}, a {@link java.lang.Float Float}, a {@link java.lang.Long Long},
* a {@link java.lang.Double Double} or a {@link String String}.
*/
public Object value;
/**
* The non standard attributes of the field.
*/
public Attribute attrs;
/**
* Constructs a new {@link FieldNode FieldNode} object.
*
* @param access the field's access flags (see {@link
* org.objectweb.asm.Constants}). This parameter also indicates if the
* field is synthetic and/or deprecated.
* @param name the field's name.
* @param desc the field's descriptor (see {@link org.objectweb.asm.Type
* Type}).
* @param value the field's initial value. This parameter, which may be
* null if the field does not have an initial value, must be an
* {@link java.lang.Integer Integer}, a {@link java.lang.Float Float}, a
* {@link java.lang.Long Long}, a {@link java.lang.Double Double} or a
* {@link String String}.
* @param attrs the non standard attributes of the field.
*/
public FieldNode (
final int access,
final String name,
final String desc,
final Object value,
final Attribute attrs)
{
this.access = access;
this.name = name;
this.desc = desc;
this.value = value;
this.attrs = attrs;
}
/**
* Makes the given class visitor visit this field.
*
* @param cv a class visitor.
*/
public void accept (final ClassVisitor cv) {
cv.visitField(access, name, desc, value, attrs);
}
}
asm-1.5.3/src/org/objectweb/asm/tree/IincInsnNode.java 100644 0 0 5022 10026564546 17662 0 ustar 0 0 /***
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000,2002,2003 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.objectweb.asm.tree;
import org.objectweb.asm.CodeVisitor;
import org.objectweb.asm.Constants;
/**
* A node that represents an IINC instruction.
*
* @author Eric Bruneton
*/
public class IincInsnNode extends AbstractInsnNode {
/**
* Index of the local variable to be incremented.
*/
public int var;
/**
* Amount to increment the local variable by.
*/
public int incr;
/**
* Constructs a new {@link IincInsnNode IincInsnNode} node.
*
* @param var index of the local variable to be incremented.
* @param incr increment amount to increment the local variable by.
*/
public IincInsnNode (final int var, final int incr) {
super(Constants.IINC);
this.var = var;
this.incr = incr;
}
public void accept (final CodeVisitor cv) {
cv.visitIincInsn(var, incr);
}
}
asm-1.5.3/src/org/objectweb/asm/tree/InnerClassNode.java 100644 0 0 7271 10070745646 20222 0 ustar 0 0 /***
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000,2002,2003 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.objectweb.asm.tree;
import org.objectweb.asm.ClassVisitor;
/**
* A node that represents an inner class.
*
* @author Eric Bruneton
*/
public class InnerClassNode {
/**
* The internal name of an inner class (see {@link
* org.objectweb.asm.Type#getInternalName() getInternalName}).
*/
public String name;
/**
* The internal name of the class to which the inner class belongs (see
* {@link org.objectweb.asm.Type#getInternalName() getInternalName}). May be
* null.
*/
public String outerName;
/**
* The (simple) name of the inner class inside its enclosing class. May be
* null for anonymous inner classes.
*/
public String innerName;
/**
* The access flags of the inner class as originally declared in the enclosing
* class.
*/
public int access;
/**
* Constructs a new {@link InnerClassNode InnerClassNode} object.
*
* @param name the internal name of an inner class (see {@link
* org.objectweb.asm.Type#getInternalName() getInternalName}).
* @param outerName the internal name of the class to which the inner class
* belongs (see {@link org.objectweb.asm.Type#getInternalName()
* getInternalName}). May be null.
* @param innerName the (simple) name of the inner class inside its enclosing
* class. May be null for anonymous inner classes.
* @param access the access flags of the inner class as originally declared
* in the enclosing class.
*/
public InnerClassNode (
final String name,
final String outerName,
final String innerName,
final int access)
{
this.name = name;
this.outerName = outerName;
this.innerName = innerName;
this.access = access;
}
/**
* Makes the given class visitor visit this inner class.
*
* @param cv a class visitor.
*/
public void accept (final ClassVisitor cv) {
cv.visitInnerClass(name, outerName, innerName, access);
}
}
asm-1.5.3/src/org/objectweb/asm/tree/InsnNode.java 100644 0 0 11043 10040710637 17065 0 ustar 0 0 /***
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000,2002,2003 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.objectweb.asm.tree;
import org.objectweb.asm.CodeVisitor;
/**
* A node that represents a zero operand instruction.
*
* @author Eric Bruneton
*/
public class InsnNode extends AbstractInsnNode {
/**
* Constructs a new {@link InsnNode InsnNode} object.
*
* @param opcode the opcode of the instruction to be constructed. This opcode
* must be NOP, ACONST_NULL, ICONST_M1, ICONST_0, ICONST_1, ICONST_2,
* ICONST_3, ICONST_4, ICONST_5, LCONST_0, LCONST_1, FCONST_0, FCONST_1,
* FCONST_2, DCONST_0, DCONST_1,
*
* IALOAD, LALOAD, FALOAD, DALOAD, AALOAD, BALOAD, CALOAD, SALOAD,
* IASTORE, LASTORE, FASTORE, DASTORE, AASTORE, BASTORE, CASTORE,
* SASTORE,
*
* POP, POP2, DUP, DUP_X1, DUP_X2, DUP2, DUP2_X1, DUP2_X2, SWAP,
*
* IADD, LADD, FADD, DADD, ISUB, LSUB, FSUB, DSUB, IMUL, LMUL, FMUL,
* DMUL, IDIV, LDIV, FDIV, DDIV, IREM, LREM, FREM, DREM, INEG, LNEG,
* FNEG, DNEG, ISHL, LSHL, ISHR, LSHR, IUSHR, LUSHR, IAND, LAND, IOR,
* LOR, IXOR, LXOR,
*
* I2L, I2F, I2D, L2I, L2F, L2D, F2I, F2L, F2D, D2I, D2L, D2F, I2B, I2C,
* I2S,
*
* LCMP, FCMPL, FCMPG, DCMPL, DCMPG,
*
* IRETURN, LRETURN, FRETURN, DRETURN, ARETURN, RETURN,
*
* ARRAYLENGTH,
*
* ATHROW,
*
* MONITORENTER, or MONITOREXIT.
*/
public InsnNode (final int opcode) {
super(opcode);
}
/**
* Sets the opcode of this instruction.
*
* @param opcode the new instruction opcode. This opcode must be NOP,
* ACONST_NULL, ICONST_M1, ICONST_0, ICONST_1, ICONST_2,
* ICONST_3, ICONST_4, ICONST_5, LCONST_0, LCONST_1, FCONST_0, FCONST_1,
* FCONST_2, DCONST_0, DCONST_1,
*
* IALOAD, LALOAD, FALOAD, DALOAD, AALOAD, BALOAD, CALOAD, SALOAD,
* IASTORE, LASTORE, FASTORE, DASTORE, AASTORE, BASTORE, CASTORE,
* SASTORE,
*
* POP, POP2, DUP, DUP_X1, DUP_X2, DUP2, DUP2_X1, DUP2_X2, SWAP,
*
* IADD, LADD, FADD, DADD, ISUB, LSUB, FSUB, DSUB, IMUL, LMUL, FMUL,
* DMUL, IDIV, LDIV, FDIV, DDIV, IREM, LREM, FREM, DREM, INEG, LNEG,
* FNEG, DNEG, ISHL, LSHL, ISHR, LSHR, IUSHR, LUSHR, IAND, LAND, IOR,
* LOR, IXOR, LXOR,
*
* I2L, I2F, I2D, L2I, L2F, L2D, F2I, F2L, F2D, D2I, D2L, D2F, I2B, I2C,
* I2S,
*
* LCMP, FCMPL, FCMPG, DCMPL, DCMPG,
*
* IRETURN, LRETURN, FRETURN, DRETURN, ARETURN, RETURN,
*
* ARRAYLENGTH,
*
* ATHROW,
*
* MONITORENTER, or MONITOREXIT.
*/
public void setOpcode (final int opcode) {
this.opcode = opcode;
}
/**
* Makes the given code visitor visit this instruction.
*
* @param cv a code visitor.
*/
public void accept (final CodeVisitor cv) {
cv.visitInsn(opcode);
}
}
asm-1.5.3/src/org/objectweb/asm/tree/IntInsnNode.java 100644 0 0 5317 10026564546 17541 0 ustar 0 0 /***
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000,2002,2003 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.objectweb.asm.tree;
import org.objectweb.asm.CodeVisitor;
/**
* A node that represents an instruction with a single int operand.
*
* @author Eric Bruneton
*/
public class IntInsnNode extends AbstractInsnNode {
/**
* The operand of this instruction.
*/
public int operand;
/**
* Constructs a new {@link IntInsnNode IntInsnNode} object.
*
* @param opcode the opcode of the instruction to be constructed. This opcode
* must be BIPUSH, SIPUSH or NEWARRAY.
* @param operand the operand of the instruction to be constructed.
*/
public IntInsnNode (final int opcode, final int operand) {
super(opcode);
this.operand = operand;
}
/**
* Sets the opcode of this instruction.
*
* @param opcode the new instruction opcode. This opcode must be BIPUSH,
* SIPUSH or NEWARRAY.
*/
public void setOpcode (final int opcode) {
this.opcode = opcode;
}
public void accept (final CodeVisitor cv) {
cv.visitIntInsn(opcode, operand);
}
}
asm-1.5.3/src/org/objectweb/asm/tree/JumpInsnNode.java 100644 0 0 6457 10026564546 17730 0 ustar 0 0 /***
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000,2002,2003 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.objectweb.asm.tree;
import org.objectweb.asm.Label;
import org.objectweb.asm.CodeVisitor;
/**
* A node that represents a jump instruction. A jump instruction is an
* instruction that may jump to another instruction.
*
* @author Eric Bruneton
*/
public class JumpInsnNode extends AbstractInsnNode {
/**
* The operand of this instruction. This operand is a label that designates
* the instruction to which this instruction may jump.
*/
public Label label;
/**
* Constructs a new {@link JumpInsnNode JumpInsnNode} object.
*
* @param opcode the opcode of the type instruction to be constructed. This
* opcode must be IFEQ, IFNE, IFLT, IFGE, IFGT, IFLE, IF_ICMPEQ,
* IF_ICMPNE, IF_ICMPLT, IF_ICMPGE, IF_ICMPGT, IF_ICMPLE, IF_ACMPEQ,
* IF_ACMPNE, GOTO, JSR, IFNULL or IFNONNULL.
* @param label the operand of the instruction to be constructed. This operand
* is a label that designates the instruction to which the jump
* instruction may jump.
*/
public JumpInsnNode (final int opcode, final Label label) {
super(opcode);
this.label = label;
}
/**
* Sets the opcode of this instruction.
*
* @param opcode the new instruction opcode. This opcode must be
* IFEQ, IFNE, IFLT, IFGE, IFGT, IFLE, IF_ICMPEQ, IF_ICMPNE,
* IF_ICMPLT, IF_ICMPGE, IF_ICMPGT, IF_ICMPLE, IF_ACMPEQ, IF_ACMPNE,
* GOTO, JSR, IFNULL or IFNONNULL.
*/
public void setOpcode (final int opcode) {
this.opcode = opcode;
}
public void accept (final CodeVisitor cv) {
cv.visitJumpInsn(opcode, label);
}
}
asm-1.5.3/src/org/objectweb/asm/tree/LdcInsnNode.java 100644 0 0 5431 10026573776 17513 0 ustar 0 0 /***
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000,2002,2003 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.objectweb.asm.tree;
import org.objectweb.asm.CodeVisitor;
import org.objectweb.asm.Constants;
/**
* A node that represents an LDC instruction.
*
* @author Eric Bruneton
*/
public class LdcInsnNode extends AbstractInsnNode {
/**
* The constant to be loaded on the stack. This parameter must be a non null
* {@link java.lang.Integer Integer}, a {@link java.lang.Float Float}, a
* {@link java.lang.Long Long}, a {@link java.lang.Double Double} a {@link
* String String} or a {@link org.objectweb.asm.Type Type}.
*/
public Object cst;
/**
* Constructs a new {@link LdcInsnNode LdcInsnNode} object.
*
* @param cst the constant to be loaded on the stack. This parameter must be
* a non null {@link java.lang.Integer Integer}, a {@link java.lang.Float
* Float}, a {@link java.lang.Long Long}, a {@link java.lang.Double
* Double} or a {@link String String}.
*/
public LdcInsnNode (final Object cst) {
super(Constants.LDC);
this.cst = cst;
}
public void accept (final CodeVisitor cv) {
cv.visitLdcInsn(cst);
}
}
asm-1.5.3/src/org/objectweb/asm/tree/LineNumberNode.java 100644 0 0 5355 10026564546 20221 0 ustar 0 0 /***
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000,2002,2003 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.objectweb.asm.tree;
import org.objectweb.asm.Label;
import org.objectweb.asm.CodeVisitor;
/**
* A node that represents a line number declaration.
*
* @author Eric Bruneton
*/
public class LineNumberNode {
/**
* A line number. This number refers to the source file from which the class
* was compiled.
*/
public int line;
/**
* The first instruction corresponding to this line number.
*/
public Label start;
/**
* Constructs a new {@link LineNumberNode LineNumberNode} object.
*
* @param line a line number. This number refers to the source file
* from which the class was compiled.
* @param start the first instruction corresponding to this line number.
*/
public LineNumberNode (final int line, final Label start) {
this.line = line;
this.start = start;
}
/**
* Makes the given code visitor visit this line number declaration.
*
* @param cv a code visitor.
*/
public void accept (final CodeVisitor cv) {
cv.visitLineNumber(line, start);
}
}
asm-1.5.3/src/org/objectweb/asm/tree/LocalVariableNode.java 100644 0 0 6575 10026564546 20666 0 ustar 0 0 /***
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000,2002,2003 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.objectweb.asm.tree;
import org.objectweb.asm.CodeVisitor;
import org.objectweb.asm.Label;
/**
* A node that represents a local variable declaration.
*
* @author Eric Bruneton
*/
public class LocalVariableNode {
/**
* The name of a local variable.
*/
public String name;
/**
* The type descriptor of this local variable.
*/
public String desc;
/**
* The first instruction corresponding to the scope of this local variable
* (inclusive).
*/
public Label start;
/**
* The last instruction corresponding to the scope of this local variable
* (exclusive).
*/
public Label end;
/**
* The local variable's index.
*/
public int index;
/**
* Constructs a new {@link LocalVariableNode LocalVariableNode} object.
*
* @param name the name of a local variable.
* @param desc the type descriptor of this local variable.
* @param start the first instruction corresponding to the scope of this
* local variable (inclusive).
* @param end the last instruction corresponding to the scope of this
* local variable (exclusive).
* @param index the local variable's index.
*/
public LocalVariableNode (
final String name,
final String desc,
final Label start,
final Label end,
final int index)
{
this.name = name;
this.desc = desc;
this.start = start;
this.end = end;
this.index = index;
}
/**
* Makes the given code visitor visit this local variable declaration.
*
* @param cv a code visitor.
*/
public void accept (final CodeVisitor cv) {
cv.visitLocalVariable(name, desc, start, end, index);
}
}
asm-1.5.3/src/org/objectweb/asm/tree/LookupSwitchInsnNode.java 100644 0 0 7055 10026564546 21443 0 ustar 0 0 /***
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000,2002,2003 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.objectweb.asm.tree;
import org.objectweb.asm.Label;
import org.objectweb.asm.Constants;
import org.objectweb.asm.CodeVisitor;
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
/**
* A node that represents a LOOKUPSWITCH instruction.
*
* @author Eric Bruneton
*/
public class LookupSwitchInsnNode extends AbstractInsnNode {
/**
* Beginning of the default handler block.
*/
public Label dflt;
/**
* The values of the keys. This list is a list a {@link java.lang.Integer
* Integer} objects.
*/
public final List keys;
/**
* Beginnings of the handler blocks. This list is a list of {@link Label
* Label} objects.
*/
public final List labels;
/**
* Constructs a new {@link LookupSwitchInsnNode LookupSwitchInsnNode} object.
*
* @param dflt beginning of the default handler block.
* @param keys the values of the keys.
* @param labels beginnings of the handler blocks. labels[i] is the
* beginning of the handler block for the keys[i] key.
*/
public LookupSwitchInsnNode (
final Label dflt,
final int[] keys,
final Label[] labels)
{
super(Constants.LOOKUPSWITCH);
this.dflt = dflt;
this.keys = new ArrayList();
this.labels = new ArrayList();
if (keys != null) {
for (int i = 0; i < keys.length; ++i) {
this.keys.add(new Integer(keys[i]));
}
}
if (labels != null) {
this.labels.addAll(Arrays.asList(labels));
}
}
public void accept (final CodeVisitor cv) {
int[] keys = new int[this.keys.size()];
for (int i = 0; i < keys.length; ++i) {
keys[i] = ((Integer)this.keys.get(i)).intValue();
}
Label[] labels = new Label[this.labels.size()];
this.labels.toArray(labels);
cv.visitLookupSwitchInsn(dflt, keys, labels);
}
}
asm-1.5.3/src/org/objectweb/asm/tree/MethodInsnNode.java 100644 0 0 6666 10070745646 20240 0 ustar 0 0 /***
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000,2002,2003 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.objectweb.asm.tree;
import org.objectweb.asm.CodeVisitor;
/**
* A node that represents a method instruction. A method instruction is an
* instruction that invokes a method.
*
* @author Eric Bruneton
*/
public class MethodInsnNode extends AbstractInsnNode {
/**
* The internal name of the method's owner class (see {@link
* org.objectweb.asm.Type#getInternalName() getInternalName}).
*/
public String owner;
/**
* The method's name.
*/
public String name;
/**
* The method's descriptor (see {@link org.objectweb.asm.Type Type}).
*/
public String desc;
/**
* Constructs a new {@link MethodInsnNode MethodInsnNode} object.
*
* @param opcode the opcode of the type instruction to be constructed. This
* opcode must be INVOKEVIRTUAL, INVOKESPECIAL, INVOKESTATIC or
* INVOKEINTERFACE.
* @param owner the internal name of the method's owner class (see {@link
* org.objectweb.asm.Type#getInternalName() getInternalName}).
* @param name the method's name.
* @param desc the method's descriptor (see {@link org.objectweb.asm.Type
* Type}).
*/
public MethodInsnNode (
final int opcode,
final String owner,
final String name,
final String desc)
{
super(opcode);
this.owner = owner;
this.name = name;
this.desc = desc;
}
/**
* Sets the opcode of this instruction.
*
* @param opcode the new instruction opcode. This opcode must be
* INVOKEVIRTUAL, INVOKESPECIAL, INVOKESTATIC or INVOKEINTERFACE.
*/
public void setOpcode (final int opcode) {
this.opcode = opcode;
}
public void accept (final CodeVisitor cv) {
cv.visitMethodInsn(opcode, owner, name, desc);
}
}
asm-1.5.3/src/org/objectweb/asm/tree/MethodNode.java 100644 0 0 14450 10070745646 17416 0 ustar 0 0 /***
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000,2002,2003 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.objectweb.asm.tree;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.CodeVisitor;
import org.objectweb.asm.Label;
import org.objectweb.asm.Attribute;
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
/**
* A node that represents a method.
*
* @author Eric Bruneton
*/
public class MethodNode {
/**
* The method's access flags (see {@link org.objectweb.asm.Constants}). This
* field also indicates if the method is synthetic and/or deprecated.
*/
public int access;
/**
* The method's name.
*/
public String name;
/**
* The method's descriptor (see {@link org.objectweb.asm.Type Type}).
*/
public String desc;
/**
* The internal names of the method's exception classes (see {@link
* org.objectweb.asm.Type#getInternalName() getInternalName}). This list is a
* list of {@link String} objects.
*/
public final List exceptions;
/**
* The non standard attributes of the method.
*/
public Attribute attrs;
/**
* The instructions of this method. This list is a list of {@link
* AbstractInsnNode AbstractInsnNode} and {@link Label Label} objects.
*/
public final List instructions;
/**
* The try catch blocks of this method. This list is a list of {@link
* TryCatchBlockNode TryCatchBlockNode} objects.
*/
public final List tryCatchBlocks;
/**
* The maximum stack size of this method.
*/
public int maxStack;
/**
* The maximum number of local variables of this method.
*/
public int maxLocals;
/**
* The local variables of this method. This list is a list of {@link
* LocalVariableNode LocalVariableNode} objects.
*/
public final List localVariables;
/**
* The line numbers of this method. This list is a list of {@link
* LineNumberNode LineNumberNode} objects.
*/
public final List lineNumbers;
/**
* The non standard attributes of the method's code.
*/
public Attribute codeAttrs;
/**
* Constructs a new {@link MethodNode MethodNode} object.
*
* @param access the method's access flags (see {@link
* org.objectweb.asm.Constants}). This parameter also indicates if the
* method is synthetic and/or deprecated.
* @param name the method's name.
* @param desc the method's descriptor (see {@link org.objectweb.asm.Type
* Type}).
* @param exceptions the internal names of the method's exception
* classes (see {@link org.objectweb.asm.Type#getInternalName()
* getInternalName}). May be null.
* @param attrs the non standard attributes of the method.
*/
public MethodNode (
final int access,
final String name,
final String desc,
final String[] exceptions,
final Attribute attrs)
{
this.access = access;
this.name = name;
this.desc = desc;
this.exceptions = new ArrayList();
this.instructions = new ArrayList();
this.tryCatchBlocks = new ArrayList();
this.localVariables = new ArrayList();
this.lineNumbers = new ArrayList();
if (exceptions != null) {
this.exceptions.addAll(Arrays.asList(exceptions));
}
this.attrs = attrs;
}
/**
* Makes the given class visitor visit this method.
*
* @param cv a class visitor.
*/
public void accept (final ClassVisitor cv) {
String[] exceptions = new String[this.exceptions.size()];
this.exceptions.toArray(exceptions);
CodeVisitor mv = cv.visitMethod(access, name, desc, exceptions, attrs);
if (mv != null && instructions.size() > 0) {
int i;
// visits instructions
for (i = 0; i < instructions.size(); ++i) {
Object insn = instructions.get(i);
if (insn instanceof Label) {
mv.visitLabel((Label)insn);
} else {
((AbstractInsnNode)insn).accept(mv);
}
}
// visits try catch blocks
for (i = 0; i < tryCatchBlocks.size(); ++i) {
((TryCatchBlockNode)tryCatchBlocks.get(i)).accept(mv);
}
// visits maxs
mv.visitMaxs(maxStack, maxLocals);
// visits local variables
for (i = 0; i < localVariables.size(); ++i) {
((LocalVariableNode)localVariables.get(i)).accept(mv);
}
// visits line numbers
for (i = 0; i < lineNumbers.size(); ++i) {
((LineNumberNode)lineNumbers.get(i)).accept(mv);
}
// visits the code attributes
Attribute attrs = codeAttrs;
while (attrs != null) {
mv.visitAttribute(attrs);
attrs = attrs.next;
}
}
}
}
asm-1.5.3/src/org/objectweb/asm/tree/MultiANewArrayInsnNode.java 100644 0 0 5236 10026564546 21653 0 ustar 0 0 /***
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000,2002,2003 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.objectweb.asm.tree;
import org.objectweb.asm.Constants;
import org.objectweb.asm.CodeVisitor;
/**
* A node that represents a MULTIANEWARRAY instruction.
*
* @author Eric Bruneton
*/
public class MultiANewArrayInsnNode extends AbstractInsnNode {
/**
* An array type descriptor (see {@link org.objectweb.asm.Type Type}).
*/
public String desc;
/**
* Number of dimensions of the array to allocate.
*/
public int dims;
/**
* Constructs a new {@link MultiANewArrayInsnNode MultiANewArrayInsnNode}
* object.
*
* @param desc an array type descriptor (see {@link org.objectweb.asm.Type
* Type}).
* @param dims number of dimensions of the array to allocate.
*/
public MultiANewArrayInsnNode (final String desc, final int dims) {
super(Constants.MULTIANEWARRAY);
this.desc = desc;
this.dims = dims;
}
public void accept (final CodeVisitor cv) {
cv.visitMultiANewArrayInsn(desc, dims);
}
}
asm-1.5.3/src/org/objectweb/asm/tree/TableSwitchInsnNode.java 100644 0 0 6464 10026564546 21224 0 ustar 0 0 /***
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000,2002,2003 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.objectweb.asm.tree;
import org.objectweb.asm.Label;
import org.objectweb.asm.Constants;
import org.objectweb.asm.CodeVisitor;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* A node that represents a TABLESWITCH instruction.
*
* @author Eric Bruneton
*/
public class TableSwitchInsnNode extends AbstractInsnNode {
/**
* The minimum key value.
*/
public int min;
/**
* The maximum key value.
*/
public int max;
/**
* Beginning of the default handler block.
*/
public Label dflt;
/**
* Beginnings of the handler blocks. This list is a list of {@link Label
* Label} objects.
*/
public final List labels;
/**
* Constructs a new {@link TableSwitchInsnNode TableSwitchInsnNode}.
*
* @param min the minimum key value.
* @param max the maximum key value.
* @param dflt beginning of the default handler block.
* @param labels beginnings of the handler blocks. labels[i] is the
* beginning of the handler block for the min + i key.
*/
public TableSwitchInsnNode (
final int min,
final int max,
final Label dflt,
final Label[] labels)
{
super(Constants.TABLESWITCH);
this.min = min;
this.max = max;
this.dflt = dflt;
this.labels = new ArrayList();
if (labels != null) {
this.labels.addAll(Arrays.asList(labels));
}
}
public void accept (final CodeVisitor cv) {
Label[] labels = new Label[this.labels.size()];
this.labels.toArray(labels);
cv.visitTableSwitchInsn(min, max, dflt, labels);
}
}
asm-1.5.3/src/org/objectweb/asm/tree/TreeClassAdapter.java 100644 0 0 10752 10112601423 20534 0 ustar 0 0 /***
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000,2002,2003 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.objectweb.asm.tree;
import org.objectweb.asm.ClassAdapter;
import org.objectweb.asm.CodeVisitor;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.Attribute;
/**
* A {@link ClassAdapter ClassAdapter} that constructs a tree representation of
* the classes it vists. Each visitXXX method of this class
* constructs an XXXNode and adds it to the {@link #classNode
* classNode} node (except the {@link #visitEnd visitEnd} method, which just
* makes the {@link #cv cv} class visitor visit the tree that has just been
* constructed).
*
* In order to implement a usefull class adapter based on a tree representation
* of classes, one just need to override the {@link #visitEnd visitEnd} method
* with a method of the following form:
*
However, this class adapter has a cost: it makes ASM bigger and slower. Indeed
it requires more than twenty new classes, and multiplies the time needed to
transform a class by almost two (it is almost two times faster to read, "modify"
and write a class with a ClassAdapter than with a TreeClassAdapter). This is why
this class adapter is bundled in an optional asm-tree.jar library that
is separated from (but requires) the asm.jar library, which contains
the core ASM framework. This is also why it is recommanded
not to use this class adapter when it is possible.
@since ASM 1.3.3
asm-1.5.3/src/org/objectweb/asm/util/ASMifierClassVisitor.java 100644 0 0 42643 10124264652 21411 0 ustar 0 0 /***
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000,2002,2003 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.objectweb.asm.util;
import java.io.FileInputStream;
import java.io.PrintWriter;
import org.objectweb.asm.Attribute;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.CodeVisitor;
import org.objectweb.asm.Constants;
import org.objectweb.asm.Type;
import org.objectweb.asm.util.attrs.ASMifiable;
/**
* A {@link PrintClassVisitor PrintClassVisitor} that prints the ASM code that
* generates the classes it visits. This class visitor can be used to quickly
* write ASM code to generate some given bytecode:
*
*
*
* Usage: ASMifierClassVisitor [-debug]
* <fully qualified class name or class file name>
*
* @param args the command line arguments.
*
* @throws Exception if the class cannot be found, or if an IO exception
* occurs.
*/
public static void main (final String[] args) throws Exception {
if (args.length < 1 || args.length > 2) {
printUsage();
}
int i = 0;
boolean skipDebug = true;
if (args[0].equals("-debug")) {
i = 1;
skipDebug = false;
if (args.length != 2) {
printUsage();
}
}
ClassReader cr;
if (args[i].endsWith(".class")) {
cr = new ClassReader(new FileInputStream(args[i]));
} else {
cr = new ClassReader(args[i]);
}
cr.accept(new ASMifierClassVisitor(
new PrintWriter(System.out)), getDefaultAttributes(), skipDebug);
}
private static void printUsage () {
System.err.println("Prints the ASM code to generate the given class.");
System.err.println("Usage: ASMifierClassVisitor [-debug] " +
"
* Usage: CheckClassAdapter
* <fully qualified class name or class file name>
*
* @param args the command line arguments.
*
* @throws Exception if the class cannot be found, or if an IO exception
* occurs.
*/
public static void main (final String[] args) throws Exception {
if (args.length != 1) {
printUsage();
}
ClassReader cr;
if (args[0].endsWith(".class")) {
cr = new ClassReader(new FileInputStream(args[0]));
} else {
cr = new ClassReader(args[0]);
}
TreeClassAdapter ca = new TreeClassAdapter(null);
cr.accept(new CheckClassAdapter(ca), true);
List methods = ca.classNode.methods;
for (int i = 0; i < methods.size(); ++i) {
MethodNode method = (MethodNode)methods.get(i);
if (method.instructions.size() > 0) {
Analyzer a = new Analyzer(new SimpleVerifier());
try {
a.analyze(ca.classNode, method);
continue;
} catch (Exception e) {
e.printStackTrace();
}
final Frame[] frames = a.getFrames();
System.out.println(method.name + method.desc);
TraceCodeVisitor cv = new TraceCodeVisitor(null) {
public void visitMaxs (int maxStack, int maxLocals) {
for (int i = 0; i < text.size(); ++i) {
String s = frames[i] == null ? "null" : frames[i].toString();
while (s.length() < maxStack+maxLocals+1) {
s += " ";
}
System.out.print(
Integer.toString(i + 100000).substring(1) + " " + s + " : "
+ text.get(i));
}
System.out.println();
}
};
for (int j = 0; j < method.instructions.size(); ++j) {
Object insn = method.instructions.get(j);
if (insn instanceof AbstractInsnNode) {
((AbstractInsnNode)insn).accept(cv);
} else {
cv.visitLabel((Label)insn);
}
}
cv.visitMaxs(method.maxStack, method.maxLocals);
}
}
}
private static void printUsage () {
System.err.println("TODO.");
System.err.println("Usage: CheckClassAdapter " +
"
* The trace printed when visiting the Hello class is the following:
*
*
*
* Usage: TraceClassVisitor [-debug]
* <fully qualified class name or class file name >
*
* @param args the command line arguments.
*
* @throws Exception if the class cannot be found, or if an IO exception
* occurs.
*/
public static void main (final String[] args) throws Exception {
if (args.length < 1 || args.length > 2) {
printUsage();
}
int i = 0;
boolean skipDebug = true;
if (args[0].equals("-debug")) {
i = 1;
skipDebug = false;
if (args.length != 2) {
printUsage();
}
}
ClassReader cr;
if (args[i].endsWith(".class")) {
cr = new ClassReader(new FileInputStream(args[i]));
} else {
cr = new ClassReader(args[i]);
}
cr.accept(new TraceClassVisitor(
null, new PrintWriter(System.out)), getDefaultAttributes(), skipDebug);
}
private static void printUsage () {
System.err.println("Prints a disassembled view of the given class.");
System.err.println("Usage: TraceClassVisitor [-debug] " +
"
* In order to use a concrete XSLT engine, system property
* javax.xml.transform.TransformerFactory must be set to
* one of the following values.
*
*
* annotation {
* u2 type_index;
* u2 num_element_value_pairs;
* {
* u2 element_name_index;
* element_value value;
* } element_value_pairs[num_element_value_pairs];
* }
*
* The items of the annotation structure are as follows:
*
*
*
*
*
* The element_value structure is a discriminated union representing the value of a
* element-value pair. It is used to represent values in all class file attributes
* that describe annotations ( RuntimeVisibleAnnotations, RuntimeInvisibleAnnotations,
* RuntimeVisibleParameterAnnotations, and RuntimeInvisibleParameterAnnotations).
*
* element_value {
* u1 tag;
* union {
* u2 const_value_index;
* {
* u2 type_name_index;
* u2 const_name_index;
* } enum_const_value;
* u2 class_info_index;
* annotation annotation_value;
* {
* u2 num_values;
* element_value values[num_values];
* } array_value;
* } value;
* }
*
* The items of the element_value structure are as follows:
*
*
*
* @see JSR 175 : A Metadata
* Facility for the Java Programming Language
*
* @author Eugene Kuleshov
*/
public class Annotation {
/**
* A fully qualified class name in internal form (see {@link Type Type}).
*/
public String type;
/**
*
* tag value Element Type
* 's' String
* 'e' enum constant
* 'c' class
* '@' annotation type
* '[' array
*
*
*
*
*
*
*
* List
of Object[]{name, value}
pairs.
* Where name is String
and value is one of
* Byte
, Character
, Double
,
* Float
, Integer
, Long
, Short
,
* Boolean
, String
,
* Annotation.EnumConstValue
, Type
,
* Annotation
or Object[]
.
*/
public List elementValues = new ArrayList();
public Annotation() {
}
public Annotation( String type) {
this.type = type;
}
public void add (String name, Object value) {
elementValues.add(new Object[]{name, value});
}
/**
* Reads annotation data structures.
*
* @param cr the class that contains the attribute to be read.
* @param off index of the first byte of the data structure.
* @param buf buffer to be used to call {@link ClassReader#readUTF8 readUTF8},
* {@link ClassReader#readClass(int,char[]) readClass} or {@link
* ClassReader#readConst readConst}.
*
* @return offset position in bytecode after reading annotation
*/
public int read (ClassReader cr, int off, char[] buf) {
type = cr.readUTF8(off, buf);
int numElementValuePairs = cr.readUnsignedShort(off + 2);
off += 4;
int[] aoff = new int[] { off};
for (int i = 0; i < numElementValuePairs; i++) {
String elementName = cr.readUTF8(aoff[ 0], buf);
aoff[ 0] += 2;
elementValues.add(new Object[]{elementName, readValue(cr, aoff, buf)});
}
return aoff[ 0];
}
/**
* Writes annotation data structures.
*
* @param bv the byte array form to store data structures.
* @param cw the class to which this attribute must be added. This parameter
* can be used to add to the constant pool of this class the items that
* corresponds to this attribute.
*/
public void write (ByteVector bv, ClassWriter cw) {
bv.putShort(cw.newUTF8(type));
bv.putShort(elementValues.size());
for (int i = 0; i < elementValues.size(); i++) {
Object[] value = (Object[])elementValues.get(i);
bv.putShort(cw.newUTF8((String)value[0]));
writeValue(bv, value[1], cw);
}
}
/**
* Utility method to read List of annotations. Each element of annotations
* List will have Annotation instance.
*
* @param annotations the List to store parameters annotations.
* @param cr the class that contains the attribute to be read.
* @param off index of the first byte of the data structure.
* @param buf buffer to be used to call {@link ClassReader#readUTF8 readUTF8},
* {@link ClassReader#readClass(int,char[]) readClass} or {@link
* ClassReader#readConst readConst}.
*
* @return offset position in bytecode after reading annotations
*/
public static int readAnnotations (
List annotations, ClassReader cr, int off, char[] buf) {
int size = cr.readUnsignedShort(off);
off += 2;
for (int i = 0; i < size; i++) {
Annotation ann = new Annotation();
off = ann.read(cr, off, buf);
annotations.add(ann);
}
return off;
}
/**
* Utility method to read List of parameters annotations.
*
* @param parameters the List to store parameters annotations.
* Each element of the parameters List will have List of Annotation
* instances.
* @param cr the class that contains the attribute to be read.
* @param off index of the first byte of the data structure.
* @param buf buffer to be used to call {@link ClassReader#readUTF8 readUTF8},
* {@link ClassReader#readClass(int,char[]) readClass} or {@link
* ClassReader#readConst readConst}.
*/
public static void readParameterAnnotations (
List parameters, ClassReader cr, int off, char[] buf) {
int numParameters = cr.b[off++] & 0xff;
for (int i = 0; i < numParameters; i++) {
List annotations = new ArrayList();
off = Annotation.readAnnotations(annotations, cr, off, buf);
parameters.add(annotations);
}
}
/**
* Utility method to write List of annotations.
*
* @param bv the byte array form to store data structures.
* @param annotations the List of annotations to write.
* Elements should be instances of the Annotation class.
* @param cw the class to which this attribute must be added. This parameter
* can be used to add to the constant pool of this class the items that
* corresponds to this attribute.
*
* @return the byte array form with saved annotations.
*/
public static ByteVector writeAnnotations (ByteVector bv,
List annotations, ClassWriter cw) {
bv.putShort(annotations.size());
for (int i = 0; i < annotations.size(); i++) {
((Annotation)annotations.get(i)).write(bv, cw);
}
return bv;
}
/**
* Utility method to write List of parameters annotations.
*
* @param bv the byte array form to store data structures.
* @param parameters the List of parametars to write. Elements should be
* instances of the List that contains instances of the Annotation class.
* @param cw the class to which this attribute must be added. This parameter
* can be used to add to the constant pool of this class the items that
* corresponds to this attribute.
*
* @return the byte array form with saved annotations.
*/
public static ByteVector writeParametersAnnotations (ByteVector bv,
List parameters,
ClassWriter cw) {
bv.putByte(parameters.size());
for (int i = 0; i < parameters.size(); i++) {
writeAnnotations(bv, (List)parameters.get(i), cw);
}
return bv;
}
/**
* Returns annotation values in the format described in JSR-175 for Java
* source code.
*
* @param annotations a list of annotations.
* @return annotation values in the format described in JSR-175 for Java
* source code.
*/
public static String stringAnnotations (List annotations) {
StringBuffer sb = new StringBuffer();
if (annotations.size() > 0) {
for (int i = 0; i < annotations.size(); i++) {
sb.append('\n').append(annotations.get(i));
}
} else {
sb.append( "
* AnnotationDefault_attribute {
* u2 attribute_name_index;
* u4 attribute_length;
* element_value default_value;
* }
*
* The items of the AnnotationDefault structure are as follows:
*
*
*
* @see JSR 175 : A Metadata
* Facility for the Java Programming Language
*
* @author Eugene Kuleshov
*/
public class AnnotationDefaultAttribute extends Attribute {
/**
* Default value for annotation. Could be one of
* Byte
, Character
, Double
,
* Float
, Integer
, Long
, Short
,
* Boolean
, String
,
* Annotation.EnumConstValue
, Type
,
* Annotation
or Object[]
.
*/
public Object defaultValue;
public AnnotationDefaultAttribute () {
super("AnnotationDefault");
}
public AnnotationDefaultAttribute ( Object defaultValue) {
this();
this.defaultValue = defaultValue;
}
protected Attribute read (ClassReader cr, int off,
int len, char[] buf, int codeOff, Label[] labels) {
return new AnnotationDefaultAttribute( Annotation.readValue(cr, new int[] {off}, buf));
}
protected ByteVector write (ClassWriter cw, byte[] code,
int len, int maxStack, int maxLocals) {
return Annotation.writeValue( new ByteVector(), defaultValue, cw);
}
/**
* Returns value in the format described in JSR-175 for Java source code.
*
* @return value in the format described in JSR-175 for Java source code.
*/
public String toString () {
return "default " + defaultValue;
}
}
asm-1.5.3/src/org/objectweb/asm/attrs/Attributes.java 100644 0 0 5246 10113326522 17661 0 ustar 0 0 /**
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000,2002,2003 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.objectweb.asm.attrs;
import org.objectweb.asm.Attribute;
/**
* Provides static utility methods for attributes.
*
* @author Eric Bruneton
*/
public class Attributes {
/**
* Uninstantiable class.
*/
private Attributes () {
}
/**
* Returns an instance of each {@link Attribute} class defined in this
* package.
*
* @return an array containing one instance of each {@link Attribute} class
* defined in this package.
*/
public static Attribute[] getDefaultAttributes () {
return new Attribute[] {
new AnnotationDefaultAttribute(),
new RuntimeInvisibleAnnotations(),
new RuntimeInvisibleParameterAnnotations(),
new RuntimeVisibleAnnotations(),
new RuntimeVisibleParameterAnnotations(),
new StackMapAttribute(),
new SourceDebugExtensionAttribute(),
new SignatureAttribute(),
new EnclosingMethodAttribute(),
new LocalVariableTypeTableAttribute()
};
}
}
asm-1.5.3/src/org/objectweb/asm/attrs/EnclosingMethodAttribute.java 100644 0 0 12346 10121236565 22526 0 ustar 0 0 /**
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000,2002,2003 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.objectweb.asm.attrs;
import org.objectweb.asm.Attribute;
import org.objectweb.asm.ByteVector;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Label;
/**
* The EnclosingMethod attribute is an optional fixed-length attribute in
* the attributes table of the ClassFile structure. A class must have an
* EnclosingMethod attribute if and only if it is a local class or an
* anonymous class. A class may have no more than one EnclosingMethod attribute.
*
* The EnclosingMethod attribute has the following format:
*
* EnclosingMethod_attribute {
* u2 attribute_name_index;
* u4 attribute_length;
* u2 class_index
* u2 method_index;
* }
*
* The items of the EnclosingMethod_attribute structure are as follows:
*
*
*
* @author Eugene Kuleshov
*/
public class EnclosingMethodAttribute extends Attribute {
public String owner;
public String name;
public String desc;
public EnclosingMethodAttribute () {
super("EnclosingMethod");
}
public EnclosingMethodAttribute (String owner, String name, String desc) {
this();
this.owner = owner;
this.name = name;
this.desc = desc;
}
protected Attribute read (ClassReader cr, int off,
int len, char[] buf, int codeOff, Label[] labels) {
// CONSTANT_Class_info
String o = cr.readClass( off, buf);
// CONSTANT_NameAndType_info (skip CONSTANT_NameAndType tag)
int index = cr.getItem(cr.readUnsignedShort(off + 2));
String n = null;
String d = null;
if( index!=0) {
n = cr.readUTF8(index, buf);
d = cr.readUTF8(index + 2, buf);
}
return new EnclosingMethodAttribute( o, n, d);
}
protected ByteVector write (ClassWriter cw, byte[] code,
int len, int maxStack, int maxLocals) {
return new ByteVector().putShort(cw.newClass(owner))
.putShort( name==null || desc==null ? 0 : cw.newNameType(name, desc));
}
public String toString () {
return new StringBuffer("owner:").append( owner)
.append(" name:").append(name)
.append(" desc:").append(desc).toString();
}
}
asm-1.5.3/src/org/objectweb/asm/attrs/LocalVariableType.java 100644 0 0 5133 10073404742 21076 0 ustar 0 0 /**
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000,2002,2003 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.objectweb.asm.attrs;
import org.objectweb.asm.Label;
/**
* Container type info used by {@link LocalVariableTypeTableAttribute}.
*
* @author Eugene Kuleshov
*/
public class LocalVariableType {
public int index;
public String name;
public String signature;
public Label start;
public Label end;
public int getIndex() {
return index;
}
public String getName() {
return name;
}
public String getSignature() {
return signature;
}
public Label getStart() {
return start;
}
public Label getEnd() {
return end;
}
public String toString() {
StringBuffer sb = new StringBuffer( index).append( " : ")
.append( name).append( " ").append( signature)
.append( "[L").append( System.identityHashCode(start))
.append( " - L").append( System.identityHashCode(end)).append( "]");
return sb.toString();
}
}
asm-1.5.3/src/org/objectweb/asm/attrs/LocalVariableTypeTableAttribute.java 100644 0 0 20515 10075652265 23762 0 ustar 0 0 /**
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000,2002,2003 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.objectweb.asm.attrs;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import org.objectweb.asm.Attribute;
import org.objectweb.asm.ByteVector;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Label;
/**
* The LocalVariableTypeTable attribute is an optional variable-length attribute of a Code
* attribute. It may be used by debuggers to determine the value of a given
* local variable during the execution of a method. If LocalVariableTypeTable attributes
* are present in the attributes table of a given Code attribute, then they may appear in
* any order. There may be no more than one LocalVariableTypeTable attribute per local
* variable in the Code attribute.
*
* The LocalVariableTypeTable attribute differs from the LocalVariableTable attribute in that
* it provides signature information rather than descriptor information. This difference
* is only significant for variables whose type is a generic reference type. Such
* variables will appear in both tables, while variables of other types will appear only
* in LocalVariableTable.
*
* LocalVariableTypeTable_attribute {
* u2 attribute_name_index;
* u4 attribute_length;
* u2 local_variable_type_table_length;
* {
* u2 start_pc;
* u2 length;
* u2 name_index;
* u2 signature_index;
* u2 index;
* } local_variable_type_table[local_variable_type_table_length];
* }
*
*
* The items of the LocalVariableTypeTable_attribute structure are as follows:
*
*
*
* @author Eugene Kuleshov
*/
public class LocalVariableTypeTableAttribute extends Attribute {
protected List types = new ArrayList();
public LocalVariableTypeTableAttribute() {
super( "LocalVariableTypeTable");
}
public List getTypes() {
return types;
}
protected Label[] getLabels() {
HashSet labels = new HashSet();
for (int i = 0; i < types.size(); i++) {
LocalVariableType t = (LocalVariableType)types.get(i);
labels.add( t.getStart());
labels.add( t.getEnd());
}
return ( Label[]) labels.toArray( new Label[ labels.size()]);
}
protected Attribute read( ClassReader cr, int off, int len, char[] buf, int codeOff, Label[] labels) {
int localVariableTypeTableLength = cr.readUnsignedShort(off);
off += 2;
LocalVariableTypeTableAttribute attr = new LocalVariableTypeTableAttribute();
for( int i = 0; i < localVariableTypeTableLength; i++) {
LocalVariableType t = new LocalVariableType();
int start = cr.readUnsignedShort( off);
int length = cr.readUnsignedShort( off + 2);
t.start = getLabel( labels, start);
t.end = getLabel( labels, start + length);
t.name = cr.readUTF8( off + 4, buf);
t.signature = cr.readUTF8( off + 6, buf);
t.index = cr.readUnsignedShort( off + 8);
off += 10;
types.add(t);
}
return attr;
}
protected ByteVector write( ClassWriter cw, byte[] code, int len, int maxStack, int maxLocals) {
ByteVector bv = new ByteVector();
bv.putShort( types.size());
for( int i = 0; i < types.size(); i++) {
LocalVariableType t = ( LocalVariableType) types.get(i);
int startOffset = t.getStart().getOffset();
bv.putShort( startOffset);
bv.putShort( t.getEnd().getOffset()-startOffset);
bv.putUTF8( t.getName());
bv.putUTF8( t.getSignature());
bv.putShort( t.getIndex());
}
return bv;
}
private Label getLabel( Label[] labels, int offset) {
Label label = labels[ offset];
if( label==null) {
label = new Label();
labels[ offset] = label;
}
return label;
}
public String toString() {
StringBuffer sb = new StringBuffer("LocalVariableTypeTable[");
for (int i = 0; i < types.size(); i++) {
sb.append('\n').append('[').append(types.get(i)).append(']');
}
sb.append("\n]");
return sb.toString();
}
}
asm-1.5.3/src/org/objectweb/asm/attrs/RuntimeInvisibleAnnotations.java 100644 0 0 13351 10121236755 23264 0 ustar 0 0 /**
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000,2002,2003 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.objectweb.asm.attrs;
import java.util.ArrayList;
import java.util.List;
import org.objectweb.asm.Attribute;
import org.objectweb.asm.ByteVector;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Label;
/**
* The RuntimeInvisibleAnnotations attribute is similar to the
* RuntimeVisibleAnnotations attribute, except that the annotations represented by
* a RuntimeInvisibleAnnotations attribute must not be made available for return
* by reflective APIs, unless the JVM has been instructed to retain these
* annotations via some implementation-specific mechanism such as a command line
* flag. In the absence of such instructions, the JVM ignores this attribute.
*
*
*
* RuntimeInvisibleAnnotations_attribute {
* u2 attribute_name_index;
* u4 attribute_length;
* u2 num_annotations;
* annotation annotations[num_annotations];
* }
*
* The items of the RuntimeInvisibleAnnotations structure are as follows:
*
*
*
* @see JSR 175 : A Metadata
* Facility for the Java Programming Language
*
* @author Eugene Kuleshov
*/
public class RuntimeInvisibleAnnotations extends Attribute {
/**
* List
of Annotation
.
*
* @associates <{org.objectweb.asm.attrs.Annotation}>
* @label annotations
*/
public List annotations = new ArrayList();
public RuntimeInvisibleAnnotations () {
super("RuntimeInvisibleAnnotations");
}
protected Attribute read (ClassReader cr, int off,
int len, char[] buf, int codeOff, Label[] labels) {
RuntimeInvisibleAnnotations atr = new RuntimeInvisibleAnnotations();
Annotation.readAnnotations(atr.annotations, cr, off, buf);
return atr;
}
protected ByteVector write (ClassWriter cw, byte[] code,
int len, int maxStack, int maxLocals) {
return Annotation.writeAnnotations(new ByteVector(), annotations, cw);
}
/**
* Returns value in the format described in JSR-175 for Java source code.
*
* @return value in the format described in JSR-175 for Java source code.
*/
public String toString () {
return Annotation.stringAnnotations(annotations);
}
}
asm-1.5.3/src/org/objectweb/asm/attrs/RuntimeInvisibleParameterAnnotations.java 100644 0 0 15141 10121236755 25124 0 ustar 0 0 /**
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000,2002,2003 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.objectweb.asm.attrs;
import java.util.ArrayList;
import java.util.List;
import org.objectweb.asm.Attribute;
import org.objectweb.asm.ByteVector;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Label;
/**
* The RuntimeInvisibleParameterAnnotations attribute is similar to the
* RuntimeVisibleParameterAnnotations attribute, except that the annotations
* represented by a RuntimeInvisibleParameterAnnotations attribute must not be
* made available for return by reflective APIs, unless the JVM has specifically
* been instructed to retain these annotations via some implementation-specific
* mechanism such as a command line flag. In the absence of such instructions, the
* JVM ignores this attribute.
*
* RuntimeInvisibleParameterAnnotations_attribute {
* u2 attribute_name_index;
* u4 attribute_length;
* u1 num_parameters;
* {
* u2 num_annotations;
* annotation annotations[num_annotations];
* } parameter_annotations[num_parameters];
* }
*
* The items of the RuntimeInvisibleParameterAnnotations structure are as follows:
*
*
*
* @see JSR 175 : A Metadata
* Facility for the Java Programming Language
*
* @author Eugene Kuleshov
*/
public class RuntimeInvisibleParameterAnnotations extends Attribute {
/**
*
*
* List
of List
s that
* contains Annotation
for each method parameter.
*
* @associates <{org.objectweb.asm.attrs.Annotation}>
* @label parameters
* @associationAsClass List
*/
public List parameters = new ArrayList();
public RuntimeInvisibleParameterAnnotations () {
super("RuntimeInvisibleParameterAnnotations");
}
protected Attribute read (ClassReader cr, int off,
int len, char[] buf, int codeOff, Label[] labels) {
RuntimeInvisibleParameterAnnotations atr =
new RuntimeInvisibleParameterAnnotations();
Annotation.readParameterAnnotations(atr.parameters, cr, off, buf);
return atr;
}
protected ByteVector write (ClassWriter cw, byte[] code,
int len, int maxStack, int maxLocals) {
return Annotation.writeParametersAnnotations(
new ByteVector(), parameters, cw);
}
public String toString () {
return Annotation.stringParameterAnnotations(parameters);
}
}
asm-1.5.3/src/org/objectweb/asm/attrs/RuntimeVisibleAnnotations.java 100644 0 0 12507 10121236755 22737 0 ustar 0 0 /**
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000,2002,2003 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.objectweb.asm.attrs;
import java.util.ArrayList;
import java.util.List;
import org.objectweb.asm.Attribute;
import org.objectweb.asm.ByteVector;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Label;
/**
* The RuntimeVisibleAnnotations attribute is a variable length attribute in the
* attributes table of the ClassFile, field_info, and method_info structures. The
* RuntimeVisibleAnnotations attribute records runtime-visible Java programming
* language annotations on the corresponding class, method, or field. Each
* ClassFile, field_info, and method_info structure may contain at most one
* RuntimeVisibleAnnotations attribute, which records all the runtime-visible Java
* programming language annotations on the corresponding program element. The JVM
* must make these annotations available so they can be returned by the
* appropriate reflective APIs.
*
* RuntimeVisibleAnnotations_attribute {
* u2 attribute_name_index;
* u4 attribute_length;
* u2 num_annotations;
* annotation annotations[num_annotations];
* }
*
* The items of the RuntimeVisibleAnnotations structure are as follows:
*
*
*
* @see JSR 175 : A Metadata
* Facility for the Java Programming Language
*
* @author Eugene Kuleshov
*/
public class RuntimeVisibleAnnotations extends Attribute {
/**
* List
of Annotation
.
*
* @associates <{org.objectweb.asm.attrs.Annotation}>
* @label annotations
*/
public List annotations = new ArrayList();
public RuntimeVisibleAnnotations () {
super("RuntimeVisibleAnnotations");
}
protected Attribute read (ClassReader cr, int off,
int len, char[] buf, int codeOff, Label[] labels) {
RuntimeVisibleAnnotations atr = new RuntimeVisibleAnnotations();
Annotation.readAnnotations(atr.annotations, cr, off, buf);
return atr;
}
protected ByteVector write (ClassWriter cw, byte[] code,
int len, int maxStack, int maxLocals) {
return Annotation.writeAnnotations(new ByteVector(), annotations, cw);
}
/**
* Returns value in the format described in JSR-175 for Java source code.
*
* @return value in the format described in JSR-175 for Java source code.
*/
public String toString () {
return Annotation.stringAnnotations(annotations);
}
}
asm-1.5.3/src/org/objectweb/asm/attrs/RuntimeVisibleParameterAnnotations.java 100644 0 0 14301 10121236755 24572 0 ustar 0 0 /**
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000,2002,2003 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.objectweb.asm.attrs;
import java.util.ArrayList;
import java.util.List;
import org.objectweb.asm.Attribute;
import org.objectweb.asm.ByteVector;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Label;
/**
* The RuntimeVisibleParameterAnnotations attribute is a variable length attribute
* in the attributes table of the method_info structure. The
* RuntimeVisibleParameterAnnotations attribute records runtime-visible Java
* programming language annotations on the parameters of the corresponding method.
* Each method_info structure may contain at most one
* RuntimeVisibleParameterAnnotations attribute, which records all the
* runtime-visible Java programming language annotations on the parameters of the
* corresponding method. The JVM must make these annotations available so they can
* be returned by the appropriate reflective APIs.
*
* RuntimeVisibleParameterAnnotations_attribute {
* u2 attribute_name_index;
* u4 attribute_length;
* u1 num_parameters;
* {
* u2 num_annotations;
* annotation annotations[num_annotations];
* } parameter_annotations[num_parameters];
* }
*
* The items of the RuntimeVisibleParameterAnnotations structure are as follows:
*
*
*
* @see JSR 175 : A Metadata
* Facility for the Java Programming Language
*
* @author Eugene Kuleshov
*/
public class RuntimeVisibleParameterAnnotations extends Attribute {
/**
*
*
*
* List
of List
s that
* contains Annotation
for each method parameter.
*
* @associates <{org.objectweb.asm.attrs.Annotation}>
* @label parameters
* @associationAsClass List
*/
public List parameters = new ArrayList();
public RuntimeVisibleParameterAnnotations () {
super("RuntimeVisibleParameterAnnotations");
}
protected Attribute read (ClassReader cr, int off,
int len, char[] buf, int codeOff, Label[] labels) {
RuntimeVisibleParameterAnnotations atr =
new RuntimeVisibleParameterAnnotations();
Annotation.readParameterAnnotations(atr.parameters, cr, off, buf);
return atr;
}
protected ByteVector write (ClassWriter cw, byte[] code,
int len, int maxStack, int maxLocals) {
return Annotation.writeParametersAnnotations(
new ByteVector(), parameters, cw);
}
public String toString () {
return Annotation.stringParameterAnnotations(parameters);
}
}
asm-1.5.3/src/org/objectweb/asm/attrs/SignatureAttribute.java 100644 0 0 12066 10043701604 21376 0 ustar 0 0 /**
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000,2002,2003 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.objectweb.asm.attrs;
import org.objectweb.asm.Attribute;
import org.objectweb.asm.ByteVector;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Label;
/**
* The Signature Attribute introduced in JSR-14 (Adding Generics to the
* Java Programming Language) and also defined in the Java Virtual Machine
* Specification, 3rd edition draft. This atribute is used for classes,
* fields and methods.
*
* "Signature" (u4 attr-length, u2 signature-index)
*
* When used as an attribute of a method or field, a signature gives the
* full (possibly generic) type of that method or field.
* When used as a class attribute, a signature indicates the type
* parameters of the class, followed by its supertype, followed by
* all its interfaces.
*
* MethodOrFieldSignature ::= TypeSignature
* ClassSignature ::= ParameterPartOpt super_TypeSignature interface_TypeSignatures
* TypeSignatures ::= TypeSignatures TypeSignature
* |
* TypeSignature ::= ...
* | ClassTypeSignature
* | MethodTypeSignature
* | TypeVariableSignature
* ClassTypeSignature ::= 'L' Ident TypeArgumentsOpt ';'
* | ClassTypeSignature '.' Ident ';' TypeArgumentsOpt
* MethodTypeSignature ::= TypeArgumentsOpt '(' TypeSignatures ')'
* TypeSignature ThrowsSignatureListOpt
* ThrowsSignatureList ::= ThrowsSignature ThrowsSignatureList
* | ThrowsSignature
* ThrowsSignature ::= '^' TypeSignature
* TypeVariableSignature ::= 'T' Ident ';'
* TypeArguments ::= '<' TypeSignature TypeSignatures '>'
* ParameterPart ::= '<' ParameterSignature ParameterSignatures '>'
* ParameterSignatures ::= ParameterSignatures ParameterSignature
* |
* ParameterSignature ::= Ident ':' bound_TypeSignature
*
*
* @see JSR 14 : Add Generic
* Types To The JavaTM Programming Language
*
* @author Eugene Kuleshov
*/
public class SignatureAttribute extends Attribute {
public String signature;
public SignatureAttribute () {
super("Signature");
}
public SignatureAttribute (String signature) {
this();
this.signature = signature;
}
protected Attribute read (ClassReader cr, int off,
int len, char[] buf, int codeOff, Label[] labels) {
return new SignatureAttribute(cr.readUTF8(off, buf));
}
protected ByteVector write (ClassWriter cw, byte[] code,
int len, int maxStack, int maxLocals) {
return new ByteVector().putShort(cw.newUTF8(signature));
}
public String toString () {
return signature;
}
}
asm-1.5.3/src/org/objectweb/asm/attrs/SourceDebugExtensionAttribute.java 100644 0 0 14326 10043701604 23542 0 ustar 0 0 /**
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000,2002,2003 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.objectweb.asm.attrs;
import org.objectweb.asm.Attribute;
import org.objectweb.asm.ByteVector;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Label;
/**
* The SourceDebugExtension attribute is an optional attribute defined in JSR-045
* in the attributes table of the ClassFile structure. There can be no more than one
* SourceDebugExtension attribute in the attributes table of a given ClassFile
* structure. The SourceDebugExtension attribute has the following format:
*
* SourceDebugExtension_attribute {
* u2 attribute_name_index;
* u4 attribute_length;
* u1 debug_extension[attribute_length];
* }
*
* The items of the SourceDebugExtension_attribute structure are as follows:
*
*
*
* @see JSR-045: Debugging
* Support for Other Languages
*
* @author Eugene Kuleshov
*/
public class SourceDebugExtensionAttribute extends Attribute {
public String debugExtension;
public SourceDebugExtensionAttribute () {
super("SourceDebugExtension");
}
public SourceDebugExtensionAttribute (String debugExtension) {
this();
this.debugExtension = debugExtension;
}
protected Attribute read (ClassReader cr, int off,
int len, char[] buf, int codeOff, Label[] labels) {
return new SourceDebugExtensionAttribute(readUTF8(cr, off, len));
}
protected ByteVector write (ClassWriter cw, byte[] code,
int len, int maxStack, int maxLocals) {
byte[] b = putUTF8(debugExtension);
return new ByteVector().putByteArray(b, 0, b.length);
}
private String readUTF8 (ClassReader cr, int index, int utfLen) {
int endIndex = index + utfLen;
byte[] b = cr.b;
char[] buf = new char[utfLen];
int strLen = 0;
int c, d, e;
while (index < endIndex) {
c = b[index++] & 0xFF;
switch (c >> 4) {
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
// 0xxxxxxx
buf[strLen++] = (char)c;
break;
case 12:
case 13:
// 110x xxxx 10xx xxxx
d = b[index++];
buf[strLen++] = (char)(((c & 0x1F) << 6) | (d & 0x3F));
break;
default:
// 1110 xxxx 10xx xxxx 10xx xxxx
d = b[index++];
e = b[index++];
buf[strLen++] = (char)(((c & 0x0F) << 12) | ((d & 0x3F) << 6) | (e & 0x3F));
break;
}
}
return new String(buf, 0, strLen);
}
private byte[] putUTF8 (String s) {
int charLength = s.length();
int byteLength = 0;
for (int i = 0; i < charLength; ++i) {
char c = s.charAt(i);
if (c >= '\001' && c <= '\177') {
byteLength++;
} else if (c > '\u07FF') {
byteLength += 3;
} else {
byteLength += 2;
}
}
/*if (byteLength > 65535) {
throw new IllegalArgumentException();
}*/
byte[] data = new byte[byteLength];
for (int i = 0; i < charLength;) {
char c = s.charAt(i);
if (c >= '\001' && c <= '\177') {
data[i++] = (byte)c;
} else if (c > '\u07FF') {
data[i++] = (byte)(0xE0 | c >> 12 & 0xF);
data[i++] = (byte)(0x80 | c >> 6 & 0x3F);
data[i++] = (byte)(0x80 | c & 0x3F);
} else {
data[i++] = (byte)(0xC0 | c >> 6 & 0x1F);
data[i++] = (byte)(0x80 | c & 0x3F);
}
}
return data;
}
public String toString () {
return debugExtension;
}
}
asm-1.5.3/src/org/objectweb/asm/attrs/StackMapAttribute.java 100644 0 0 16171 10043701604 21141 0 ustar 0 0 /**
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000,2002,2003 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.objectweb.asm.attrs;
import java.util.ArrayList;
import java.util.HashSet;
import org.objectweb.asm.Attribute;
import org.objectweb.asm.ByteVector;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Label;
/**
* StackMapAttribute is used by CDLC preverifier and also by javac compiller
* starting from J2SE 1.5. Definition is given in appendix "CLDC Byte Code
* Typechecker Specification" from CDLC 1.1 specification.
*
*
*
*
* stack_map { // attribute StackMap
* u2 attribute_name_index;
* u4 attribute_length
* uoffset number_of_entries;
* stack_map_frame entries[number_of_entries];
* }
*
* Each stack map frame has the following format:
*
* stack_map_frame {
* uoffset offset;
* ulocalvar number_of_locals;
* verification_type_info locals[number_of_locals];
* ustack number_of_stack_items;
* verification_type_info stack[number_of_stack_items];
* }
*
* The verification_type_info structure consists of a one-byte tag
* followed by zero or more bytes, giving more information about the tag.
* Each verification_type_info structure specifies the verification
* type of one or two locations.
*
* union verification_type_info {
* Top_variable_info;
* Integer_variable_info;
* Float_variable_info;
* Long_variable_info;
* Double_variable_info;
* Null_variable_info;
* UninitializedThis_variable_info;
* Object_variable_info;
* Uninitialized_variable_info;
* }
*
* Top_variable_info {
* u1 tag = ITEM_Top; // 0
* }
*
* Integer_variable_info {
* u1 tag = ITEM_Integer; // 1
* }
*
* Float_variable_info {
* u1 tag = ITEM_Float; // 2
* }
*
* Long_variable_info {
* u1 tag = ITEM_Long; // 4
* }
*
* Double_variable_info {
* u1 tag = ITEM_Double; // 3
* }
*
* Null_variable_info {
* u1 tag = ITEM_Null; // 5
* }
*
* UninitializedThis_variable_info {
* u1 tag = ITEM_UninitializedThis; // 6
* }
*
* Object_variable_info {
* u1 tag = ITEM_Object; // 7
* u2 cpool_index;
* }
*
* Uninitialized_variable_info {
* u1 tag = ITEM_Uninitialized // 8
* uoffset offset;
* }
*
*
* @see JSR 139 : Connected
* Limited Device Configuration 1.1
*
* @author Eugene Kuleshov
*/
public class StackMapAttribute extends Attribute {
static final int MAX_SIZE = 65535;
public ArrayList frames = new ArrayList();
public StackMapAttribute () {
super("StackMap");
}
public StackMapFrame getFrame (Label label) {
for (int i = 0; i < frames.size(); i++) {
StackMapFrame frame = (StackMapFrame)frames.get(i);
if (frame.label == label) {
return frame;
}
}
return null;
}
protected Attribute read (ClassReader cr, int off, int len,
char[] buf, int codeOff, Label[] labels) {
StackMapAttribute attr = new StackMapAttribute();
// note that this is not the size of Code attribute
int codeSize = cr.readInt(codeOff + 4);
int size = 0;
if (codeSize > MAX_SIZE) {
size = cr.readInt(off);
off += 4;
} else {
size = cr.readShort(off);
off += 2;
}
for (int i = 0; i < size; i++) {
StackMapFrame frame = new StackMapFrame();
off = frame.read(cr, off, buf, codeOff, labels);
attr.frames.add(frame);
}
return attr;
}
protected ByteVector write (ClassWriter cw, byte[] code,
int len, int maxStack, int maxLocals) {
ByteVector bv = new ByteVector();
if ( code!=null && code.length > MAX_SIZE) {
bv.putInt(frames.size());
} else {
bv.putShort(frames.size());
}
for (int i = 0; i < frames.size(); i++) {
((StackMapFrame)frames.get(i)).write(cw, maxStack, maxLocals, bv);
}
return bv;
}
protected Label[] getLabels () {
HashSet labels = new HashSet();
for (int i = 0; i < frames.size(); i++) {
((StackMapFrame)frames.get(i)).getLabels(labels);
}
return (Label[])labels.toArray(new Label[labels.size()]);
}
public String toString () {
StringBuffer sb = new StringBuffer("StackMap[");
for (int i = 0; i < frames.size(); i++) {
sb.append('\n').append('[').append(frames.get(i)).append(']');
}
sb.append("\n]");
return sb.toString();
}
}
asm-1.5.3/src/org/objectweb/asm/attrs/StackMapFrame.java 100644 0 0 13433 10043701604 20226 0 ustar 0 0 /**
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000,2002,2003 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.objectweb.asm.attrs;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.objectweb.asm.ByteVector;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.Label;
/**
* StackMapFrame is used by {@link StackMapAttribute} to hold state of the stack
* and local variables for a single execution branch.
*
* Note that Long and Double types are represented by two entries in locals
* and stack. Second entry sohould be always of type Top.
*
* @see JSR 139 : Connected
* Limited Device Configuration 1.1
*
* @author Eugene Kuleshov
*/
public class StackMapFrame {
public Label label;
public List locals = new ArrayList();
public List stack = new ArrayList();
public int read (ClassReader cr,
int off, char[] buf, int codeOff, Label[] labels) {
int n = cr.readUnsignedShort(off);
off += 2;
if (labels[n] == null) {
labels[n] = new Label();
}
label = labels[n];
off = readTypeInfo(cr, off, locals, labels, buf,
cr.readUnsignedShort(codeOff + 2)); // maxLocals
off = readTypeInfo(cr, off, stack, labels, buf,
cr.readUnsignedShort(codeOff)); // maxStack
return off;
}
public void write (ClassWriter cw,
int maxStack, int maxLocals, ByteVector bv) {
bv.putShort(label.getOffset());
writeTypeInfo(bv, cw, locals, maxLocals);
writeTypeInfo(bv, cw, stack, maxStack);
}
public void getLabels (Set labels) {
labels.add(label);
getTypeInfoLabels(labels, locals);
getTypeInfoLabels(labels, stack);
}
private void getTypeInfoLabels (Set labels, List info) {
for (Iterator it = info.iterator(); it.hasNext();) {
StackMapType typeInfo = (StackMapType)it.next();
if (typeInfo.getType() == StackMapType.ITEM_Uninitialized) {
labels.add(typeInfo.getLabel());
}
}
}
private int readTypeInfo (ClassReader cr, int off,
List info, Label[] labels, char[] buf, int max) {
int n = 0;
if (max > StackMapAttribute.MAX_SIZE) {
n = cr.readInt(off);
off += 4;
} else {
n = cr.readUnsignedShort(off);
off += 2;
}
for (int j = 0; j < n; j++) {
int itemType = cr.readByte(off++);
StackMapType typeInfo = StackMapType.getTypeInfo(itemType);
info.add(typeInfo);
switch (itemType) {
// case StackMapType.ITEM_Long: //
// case StackMapType.ITEM_Double: //
// info.add(StackMapType.getTypeInfo(StackMapType.ITEM_Top));
// break;
case StackMapType.ITEM_Object: //
typeInfo.setObject(cr.readClass(off, buf));
off += 2;
break;
case StackMapType.ITEM_Uninitialized: //
int o = cr.readUnsignedShort(off);
off += 2;
if (labels[o] == null) {
labels[o] = new Label();
}
typeInfo.setLabel(labels[o]);
break;
}
}
return off;
}
private void writeTypeInfo (ByteVector bv,
ClassWriter cw, List info, int max) {
if (max > StackMapAttribute.MAX_SIZE) {
bv.putInt(info.size());
} else {
bv.putShort(info.size());
}
for (int j = 0; j < info.size(); j++) {
StackMapType typeInfo = (StackMapType)info.get(j);
bv.putByte(typeInfo.getType());
switch (typeInfo.getType()) {
case StackMapType.ITEM_Object: //
bv.putShort(cw.newClass(typeInfo.getObject()));
break;
case StackMapType.ITEM_Uninitialized: //
bv.putShort(typeInfo.getLabel().getOffset());
break;
}
}
}
public String toString () {
StringBuffer sb = new StringBuffer("Frame:L");
sb.append(System.identityHashCode(label));
sb.append(" locals").append(locals);
sb.append(" stack").append(stack);
return sb.toString();
}
}
asm-1.5.3/src/org/objectweb/asm/attrs/StackMapType.java 100644 0 0 6717 10026564546 20121 0 ustar 0 0 /**
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000,2002,2003 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.objectweb.asm.attrs;
import org.objectweb.asm.Label;
/**
* Verification type info used by {@link StackMapAttribute}.
*
* @see JSR 139 : Connected
* Limited Device Configuration 1.1
*
* @author Eugene Kuleshov
*/
public class StackMapType {
public static final int ITEM_Top = 0;
public static final int ITEM_Integer = 1;
public static final int ITEM_Float = 2;
public static final int ITEM_Double = 3;
public static final int ITEM_Long = 4;
public static final int ITEM_Null = 5;
public static final int ITEM_UninitializedThis = 6;
public static final int ITEM_Object = 7;
public static final int ITEM_Uninitialized = 8;
public static final String[] ITEM_NAMES = {
"Top",
"Integer",
"Float",
"Double",
"Long",
"Null",
"UninitializedThis",
"Object",
"Uninitialized"
};
private int type;
private Label offset;
private String object;
private StackMapType (int type) {
this.type = type;
}
public int getType () {
return type;
}
public static StackMapType getTypeInfo (int itemType) {
return new StackMapType(itemType);
}
public void setLabel (Label offset) {
this.offset = offset;
}
public void setObject (String object) {
this.object = object;
}
public Label getLabel () {
return offset;
}
public String getObject () {
return object;
}
public String toString () {
StringBuffer sb = new StringBuffer(ITEM_NAMES[type]);
if (type == ITEM_Object) {
sb.append(":").append(object);
}
if (type == ITEM_Uninitialized) {
sb.append(":L").append(System.identityHashCode(offset));
}
return sb.toString();
}
}
asm-1.5.3/src/org/objectweb/asm/attrs/package.html 100644 0 0 5341 10026564546 17162 0 ustar 0 0
Provides an implementation for various optional class, field, method and bytecode
attributes.
* public void visitEnd () {
* // ...
* // code to modify the classNode tree, can be arbitrary complex
* // ...
* // makes the cv visitor visit this modified class:
* classNode.accept(cv);
* }
*
*
* @author Eric Bruneton
*/
public class TreeClassAdapter extends ClassAdapter {
/**
* A tree representation of the class that is being visited by this visitor.
*/
public ClassNode classNode;
/**
* Constructs a new {@link TreeClassAdapter TreeClassAdapter} object.
*
* @param cv the class visitor to which this adapter must delegate calls.
*/
public TreeClassAdapter (final ClassVisitor cv) {
super(cv);
}
public void visit (
final int version,
final int access,
final String name,
final String superName,
final String[] interfaces,
final String sourceFile)
{
classNode = new ClassNode(version, access, name, superName, interfaces, sourceFile);
}
public void visitInnerClass (
final String name,
final String outerName,
final String innerName,
final int access)
{
InnerClassNode icn = new InnerClassNode(name, outerName, innerName, access);
classNode.innerClasses.add(icn);
}
public void visitField (
final int access,
final String name,
final String desc,
final Object value,
final Attribute attrs)
{
FieldNode fn = new FieldNode(access, name, desc, value, attrs);
classNode.fields.add(fn);
}
public CodeVisitor visitMethod (
final int access,
final String name,
final String desc,
final String[] exceptions,
final Attribute attrs)
{
MethodNode mn = new MethodNode(access, name, desc, exceptions, attrs);
classNode.methods.add(mn);
return new TreeCodeAdapter(mn);
}
public void visitAttribute (final Attribute attr) {
attr.next = classNode.attrs;
classNode.attrs = attr;
}
public void visitEnd () {
if( cv!=null) {
classNode.accept(cv);
}
}
}
asm-1.5.3/src/org/objectweb/asm/tree/TreeCodeAdapter.java 100644 0 0 13664 10026564546 20370 0 ustar 0 0 /***
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000,2002,2003 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.objectweb.asm.tree;
import org.objectweb.asm.CodeAdapter;
import org.objectweb.asm.Label;
import org.objectweb.asm.Attribute;
/**
* A {@link CodeAdapter CodeAdapter} that constructs a tree representation of
* the methods it vists. Each visitXXX method of this class
* constructs an XXXNode and adds it to the {@link #methodNode
* methodNode} node.
*
* @author Eric Bruneton
*/
public class TreeCodeAdapter extends CodeAdapter {
/**
* A tree representation of the method that is being visited by this visitor.
*/
public MethodNode methodNode;
/**
* Constructs a new {@link TreeCodeAdapter TreeCodeAdapter} object.
*
* @param methodNode the method node to be used to store the tree
* representation constructed by this code visitor.
*/
public TreeCodeAdapter (final MethodNode methodNode) {
super(null);
this.methodNode = methodNode;
}
public void visitInsn (final int opcode) {
AbstractInsnNode n = new InsnNode(opcode);
methodNode.instructions.add(n);
}
public void visitIntInsn (final int opcode, final int operand) {
AbstractInsnNode n = new IntInsnNode(opcode, operand);
methodNode.instructions.add(n);
}
public void visitVarInsn (final int opcode, final int var) {
AbstractInsnNode n = new VarInsnNode(opcode, var);
methodNode.instructions.add(n);
}
public void visitTypeInsn (final int opcode, final String desc) {
AbstractInsnNode n = new TypeInsnNode(opcode, desc);
methodNode.instructions.add(n);
}
public void visitFieldInsn (
final int opcode,
final String owner,
final String name,
final String desc)
{
AbstractInsnNode n = new FieldInsnNode(opcode, owner, name, desc);
methodNode.instructions.add(n);
}
public void visitMethodInsn (
final int opcode,
final String owner,
final String name,
final String desc)
{
AbstractInsnNode n = new MethodInsnNode(opcode, owner, name, desc);
methodNode.instructions.add(n);
}
public void visitJumpInsn (final int opcode, final Label label) {
AbstractInsnNode n = new JumpInsnNode(opcode, label);
methodNode.instructions.add(n);
}
public void visitLabel (final Label label) {
methodNode.instructions.add(label);
}
public void visitLdcInsn (final Object cst) {
AbstractInsnNode n = new LdcInsnNode(cst);
methodNode.instructions.add(n);
}
public void visitIincInsn (final int var, final int increment) {
AbstractInsnNode n = new IincInsnNode(var, increment);
methodNode.instructions.add(n);
}
public void visitTableSwitchInsn (
final int min,
final int max,
final Label dflt,
final Label labels[])
{
AbstractInsnNode n = new TableSwitchInsnNode(min, max, dflt, labels);
methodNode.instructions.add(n);
}
public void visitLookupSwitchInsn (
final Label dflt,
final int keys[],
final Label labels[])
{
AbstractInsnNode n = new LookupSwitchInsnNode(dflt, keys, labels);
methodNode.instructions.add(n);
}
public void visitMultiANewArrayInsn (final String desc, final int dims) {
AbstractInsnNode n = new MultiANewArrayInsnNode(desc, dims);
methodNode.instructions.add(n);
}
public void visitTryCatchBlock (
final Label start,
final Label end,
final Label handler,
final String type)
{
TryCatchBlockNode n = new TryCatchBlockNode(start, end, handler, type);
methodNode.tryCatchBlocks.add(n);
}
public void visitMaxs (final int maxStack, final int maxLocals) {
methodNode.maxStack = maxStack;
methodNode.maxLocals = maxLocals;
}
public void visitLocalVariable (
final String name,
final String desc,
final Label start,
final Label end,
final int index)
{
LocalVariableNode n = new LocalVariableNode(name, desc, start, end, index);
methodNode.localVariables.add(n);
}
public void visitLineNumber (final int line, final Label start) {
LineNumberNode n = new LineNumberNode(line, start);
methodNode.lineNumbers.add(n);
}
public void visitAttribute (final Attribute attr) {
attr.next = methodNode.codeAttrs;
methodNode.codeAttrs = attr;
}
}
asm-1.5.3/src/org/objectweb/asm/tree/TryCatchBlockNode.java 100644 0 0 6402 10026564546 20647 0 ustar 0 0 /***
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000,2002,2003 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.objectweb.asm.tree;
import org.objectweb.asm.Label;
import org.objectweb.asm.CodeVisitor;
/**
* A node that represents a try catch block.
*
* @author Eric Bruneton
*/
public class TryCatchBlockNode {
/**
* Beginning of the exception handler's scope (inclusive).
*/
public Label start;
/**
* End of the exception handler's scope (exclusive).
*/
public Label end;
/**
* Beginning of the exception handler's code.
*/
public Label handler;
/**
* Internal name of the type of exceptions handled by the handler. May be
* null to catch any exceptions (for "finally" blocks).
*/
public String type;
/**
* Constructs a new {@link TryCatchBlockNode TryCatchBlockNode} object.
*
* @param start beginning of the exception handler's scope (inclusive).
* @param end end of the exception handler's scope (exclusive).
* @param handler beginning of the exception handler's code.
* @param type internal name of the type of exceptions handled by the handler,
* or null to catch any exceptions (for "finally" blocks).
*/
public TryCatchBlockNode (
final Label start,
final Label end,
final Label handler,
final String type)
{
this.start = start;
this.end = end;
this.handler = handler;
this.type = type;
}
/**
* Makes the given code visitor visit this try catch block.
*
* @param cv a code visitor.
*/
public void accept (final CodeVisitor cv) {
cv.visitTryCatchBlock(start, end, handler, type);
}
}
asm-1.5.3/src/org/objectweb/asm/tree/TypeInsnNode.java 100644 0 0 5720 10026564546 17726 0 ustar 0 0 /***
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000,2002,2003 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.objectweb.asm.tree;
import org.objectweb.asm.CodeVisitor;
/**
* A node that represents a type instruction. A type instruction is an
* instruction that takes a type descriptor as parameter.
*
* @author Eric Bruneton
*/
public class TypeInsnNode extends AbstractInsnNode {
/**
* The operand of this instruction. This operand is a type descriptor (see
* {@link org.objectweb.asm.Type Type}).
*/
public String desc;
/**
* Constructs a new {@link TypeInsnNode TypeInsnNode} object.
*
* @param opcode the opcode of the type instruction to be constructed. This
* opcode must be NEW, ANEWARRAY, CHECKCAST or INSTANCEOF.
* @param desc the operand of the instruction to be constructed. This operand
* is a type descriptor (see {@link org.objectweb.asm.Type Type}).
*/
public TypeInsnNode (final int opcode, final String desc) {
super(opcode);
this.desc = desc;
}
/**
* Sets the opcode of this instruction.
*
* @param opcode the new instruction opcode. This opcode must be
* NEW, ANEWARRAY, CHECKCAST or INSTANCEOF.
*/
public void setOpcode (final int opcode) {
this.opcode = opcode;
}
public void accept (final CodeVisitor cv) {
cv.visitTypeInsn(opcode, desc);
}
}
asm-1.5.3/src/org/objectweb/asm/tree/VarInsnNode.java 100644 0 0 6140 10026564546 17532 0 ustar 0 0 /***
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000,2002,2003 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.objectweb.asm.tree;
import org.objectweb.asm.CodeVisitor;
/**
* A node that represents a local variable instruction. A local variable
* instruction is an instruction that loads or stores the value of a local
* variable.
*
* @author Eric Bruneton
*/
public class VarInsnNode extends AbstractInsnNode {
/**
* The operand of this instruction. This operand is the index of a local
* variable.
*/
public int var;
/**
* Visits a local variable instruction. A local variable instruction is an
* instruction that loads or stores the value of a local variable.
*
* @param opcode the opcode of the local variable instruction to be
* constructed. This opcode must be ILOAD, LLOAD, FLOAD, DLOAD, ALOAD,
* ISTORE, LSTORE, FSTORE, DSTORE, ASTORE or RET.
* @param var the operand of the instruction to be constructed. This operand
* is the index of a local variable.
*/
public VarInsnNode (final int opcode, final int var) {
super(opcode);
this.var = var;
}
/**
* Sets the opcode of this instruction.
*
* @param opcode the new instruction opcode. This opcode must be ILOAD, LLOAD,
* FLOAD, DLOAD, ALOAD, ISTORE, LSTORE, FSTORE, DSTORE, ASTORE or RET.
*/
public void setOpcode (final int opcode) {
this.opcode = opcode;
}
public void accept (final CodeVisitor cv) {
cv.visitVarInsn(opcode, var);
}
}
asm-1.5.3/src/org/objectweb/asm/tree/analysis/Analyzer.java 100644 0 0 36572 10075731026 21001 0 ustar 0 0 /***
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000,2002,2003 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.objectweb.asm.tree.analysis;
import java.util.ArrayList;
import java.util.List;
import org.objectweb.asm.Constants;
import org.objectweb.asm.Label;
import org.objectweb.asm.Type;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.IincInsnNode;
import org.objectweb.asm.tree.JumpInsnNode;
import org.objectweb.asm.tree.LookupSwitchInsnNode;
import org.objectweb.asm.tree.MethodNode;
import org.objectweb.asm.tree.TableSwitchInsnNode;
import org.objectweb.asm.tree.TryCatchBlockNode;
import org.objectweb.asm.tree.VarInsnNode;
/**
* A semantic bytecode analyzer.
*
* @author Eric Bruneton
*/
public class Analyzer implements Constants {
private Interpreter interpreter;
private int n;
private IntMap indexes;
private List[] handlers;
private Frame[] frames;
private Subroutine[] subroutines;
private boolean[] queued;
private int[] queue;
private int top;
/**
* Constructs a new {@link Analyzer}.
*
* @param interpreter the interpreter to be used to symbolically interpret
* the bytecode instructions.
*/
public Analyzer (final Interpreter interpreter) {
this.interpreter = interpreter;
}
/**
* Analyzes the given method.
*
* @param c the class to which the method belongs.
* @param m the method to be analyzed.
* @return the symbolic state of the execution stack frame at each bytecode
* instruction of the method. The size of the returned array is equal to
* the number of instructions (and labels) of the method. A given frame is
* null if and only if the corresponding instruction cannot be
* reached (dead code).
* @throws AnalyzerException if a problem occurs during the analysis.
*/
public Frame[] analyze (final ClassNode c, final MethodNode m)
throws AnalyzerException
{
n = m.instructions.size();
indexes = new IntMap(2*n);
handlers = new List[n];
frames = new Frame[n];
subroutines = new Subroutine[n];
queued = new boolean[n];
queue = new int[n];
top = 0;
// computes instruction indexes
for (int i = 0; i < n; ++i) {
indexes.put(m.instructions.get(i), i);
}
// computes exception handlers for each instruction
for (int i = 0; i < m.tryCatchBlocks.size(); ++i) {
TryCatchBlockNode tcb = (TryCatchBlockNode)m.tryCatchBlocks.get(i);
int begin = indexes.get(tcb.start);
int end = indexes.get(tcb.end);
for (int j = begin; j < end; ++j) {
List insnHandlers = handlers[j];
if (insnHandlers == null) {
insnHandlers = new ArrayList();
handlers[j] = insnHandlers;
}
insnHandlers.add(tcb);
}
}
// initializes the data structures for the control flow analysis algorithm
Frame current = newFrame(m.maxLocals, m.maxStack);
Frame handler = newFrame(m.maxLocals, m.maxStack);
Type[] args = Type.getArgumentTypes(m.desc);
int local = 0;
if ((m.access & ACC_STATIC) == 0) {
Type ctype = Type.getType("L" + c.name + ";");
current.setLocal(local++, interpreter.newValue(ctype));
}
for (int i = 0; i < args.length; ++i) {
current.setLocal(local++, interpreter.newValue(args[i]));
if (args[i].getSize() == 2) {
current.setLocal(local++, interpreter.newValue(null));
}
}
while (local < m.maxLocals) {
current.setLocal(local++, interpreter.newValue(null));
}
merge(0, current, null);
// control flow analysis
while (top > 0) {
int insn = queue[--top];
Frame f = frames[insn];
Subroutine subroutine = subroutines[insn];
queued[insn] = false;
try {
Object o = m.instructions.get(insn);
if (o instanceof Label) {
merge(insn + 1, f, subroutine);
} else {
AbstractInsnNode insnNode = (AbstractInsnNode)o;
int insnOpcode = insnNode.getOpcode();
current.init(f).execute(insnNode, interpreter);
subroutine = subroutine == null ? null : subroutine.copy();
if (insnNode instanceof JumpInsnNode) {
JumpInsnNode j = (JumpInsnNode)insnNode;
if (insnOpcode != GOTO && insnOpcode != JSR) {
merge(insn + 1, current, subroutine);
}
if (insnOpcode == JSR) {
subroutine = new Subroutine(j.label, m.maxLocals, j);
}
merge(indexes.get(j.label), current, subroutine);
} else if (insnNode instanceof LookupSwitchInsnNode) {
LookupSwitchInsnNode lsi = (LookupSwitchInsnNode)insnNode;
merge(indexes.get(lsi.dflt), current, subroutine);
for (int j = 0; j < lsi.labels.size(); ++j) {
Label label = (Label)lsi.labels.get(j);
merge(indexes.get(label), current, subroutine);
}
} else if (insnNode instanceof TableSwitchInsnNode) {
TableSwitchInsnNode tsi = (TableSwitchInsnNode)insnNode;
merge(indexes.get(tsi.dflt), current, subroutine);
for (int j = 0; j < tsi.labels.size(); ++j) {
Label label = (Label)tsi.labels.get(j);
merge(indexes.get(label), current, subroutine);
}
} else if (insnOpcode == RET) {
if (subroutine == null) {
throw new AnalyzerException(
"RET instruction outside of a sub routine");
} else {
for (int i = 0; i < subroutine.callers.size(); ++i) {
int caller = indexes.get(subroutine.callers.get(i));
merge(caller + 1, frames[caller], current, subroutine.access);
}
}
} else if (insnOpcode != ATHROW && (insnOpcode < IRETURN || insnOpcode > RETURN)) {
if (subroutine != null) {
if (insnNode instanceof VarInsnNode) {
int var = ((VarInsnNode)insnNode).var;
subroutine.access[var] = true;
if (insnOpcode == LLOAD ||
insnOpcode == DLOAD ||
insnOpcode == LSTORE ||
insnOpcode == DSTORE)
{
subroutine.access[var + 1] = true;
}
} else if (insnNode instanceof IincInsnNode) {
int var = ((IincInsnNode)insnNode).var;
subroutine.access[var] = true;
}
}
merge(insn + 1, current, subroutine);
}
}
List insnHandlers = handlers[insn];
if (insnHandlers != null) {
for (int i = 0; i < insnHandlers.size(); ++i) {
TryCatchBlockNode tcb = (TryCatchBlockNode)insnHandlers.get(i);
Type type;
if (tcb.type == null) {
type = Type.getType("Ljava/lang/Throwable;");
} else {
type = Type.getType("L" + tcb.type + ";");
}
handler.init(f);
handler.clearStack();
handler.push(interpreter.newValue(type));
merge(indexes.get(tcb.handler), handler, subroutine);
}
}
} catch (Exception e) {
throw new AnalyzerException(
"Error at instruction " + insn + ": " + e.getMessage());
}
}
return frames;
}
/**
* Returns the symbolic stack frame for each instruction of the last recently
* analyzed method.
*
* @return the symbolic state of the execution stack frame at each bytecode
* instruction of the method. The size of the returned array is equal to
* the number of instructions (and labels) of the method. A given frame is
* null if the corresponding instruction cannot be reached, or if
* an error occured during the analysis of the method.
*/
public Frame[] getFrames () {
return frames;
}
/**
* Returns the index of the given instruction.
*
* @param insn a {@link Label} or {@link AbstractInsnNode} of the last
* recently analyzed method.
* @return the index of the given instruction of the last recently analyzed
* method.
*/
public int getIndex (final Object insn) {
return indexes.get(insn);
}
/**
* Returns the exception handlers for the given instruction.
*
* @param insn the index of an instruction of the last recently analyzed
* method.
* @return a list of {@link TryCatchBlockNode} objects.
*/
public List getHandlers (final int insn) {
return handlers[insn];
}
/**
* Constructs a new frame with the given size.
*
* @param nLocals the maximum number of local variables of the frame.
* @param nStack the maximum stack size of the frame.
* @return the created frame.
*/
protected Frame newFrame (final int nLocals, final int nStack) {
return new Frame(nLocals, nStack);
}
/**
* Constructs a new frame that is identical to the given frame.
*
* @param src a frame.
* @return the created frame.
*/
protected Frame newFrame (final Frame src) {
return new Frame(src);
}
/**
* Creates a control flow graph edge. The default implementation of this
* method does nothing. It can be overriden in order to construct the control
* flow graph of a method (this method is called by the
* {@link #analyze analyze} method during its visit of the method's code).
*
* @param frame the frame corresponding to an instruction.
* @param successor the frame corresponding to a successor instruction.
*/
protected void newControlFlowEdge (final Frame frame, final Frame successor) {
}
// -------------------------------------------------------------------------
private void merge (
final int insn,
final Frame frame,
final Subroutine subroutine) throws AnalyzerException
{
if (insn > n - 1) {
throw new AnalyzerException("Execution can fall off end of the code");
} else {
Frame oldFrame = frames[insn];
Subroutine oldSubroutine = subroutines[insn];
boolean changes = false;
if (oldFrame == null) {
frames[insn] = newFrame(frame);
changes = true;
} else {
changes |= oldFrame.merge(frame, interpreter);
}
newControlFlowEdge(frame, oldFrame);
if (oldSubroutine == null) {
if (subroutine != null) {
subroutines[insn] = subroutine.copy();
changes = true;
}
} else {
if (subroutine != null) {
changes |= oldSubroutine.merge(subroutine);
}
}
if (changes && !queued[insn]) {
queued[insn] = true;
queue[top++] = insn;
}
}
}
private void merge (
final int insn,
final Frame beforeJSR,
final Frame afterRET,
final boolean[] access) throws AnalyzerException
{
if (insn > n - 1) {
throw new AnalyzerException("Execution can fall off end of the code");
} else {
Frame oldFrame = frames[insn];
boolean changes = false;
afterRET.merge(beforeJSR, access);
if (oldFrame == null) {
frames[insn] = newFrame(afterRET);
changes = true;
} else {
changes |= oldFrame.merge(afterRET, access);
}
newControlFlowEdge(afterRET, oldFrame);
if (changes && !queued[insn]) {
queued[insn] = true;
queue[top++] = insn;
}
}
}
private static class IntMap {
private int size;
private Object[] keys;
private int[] values;
private IntMap (final int size) {
this.size = size;
this.keys = new Object[size];
this.values = new int[size];
}
public int get (final Object key) {
int n = size;
int i = (key.hashCode() & 0x7FFFFFFF)%n;
while (keys[i] != key) {
i = (i+1)%n;
}
return values[i];
}
public void put (final Object key, final int value) {
int n = size;
int i = (key.hashCode() & 0x7FFFFFFF)%n;
while (keys[i] != null) {
i = (i+1)%n;
}
keys[i] = key;
values[i] = value;
}
}
private static class Subroutine {
Label start;
boolean[] access;
List callers;
private Subroutine () {
}
public Subroutine (final Label start, final int maxLocals, final JumpInsnNode caller) {
this.start = start;
this.access = new boolean[maxLocals];
this.callers = new ArrayList();
callers.add(caller);
}
public Subroutine copy () {
Subroutine result = new Subroutine();
result.start = start;
result.access = new boolean[access.length];
System.arraycopy(access, 0, result.access, 0, access.length);
result.callers = new ArrayList(callers);
return result;
}
public boolean merge (final Subroutine subroutine) throws AnalyzerException {
if (subroutine.start != start) {
throw new AnalyzerException("Overlapping sub routines");
}
boolean changes = false;
for (int i = 0; i < access.length; ++i) {
if (subroutine.access[i] && !access[i]) {
access[i] = true;
changes = true;
}
}
for (int i = 0; i < subroutine.callers.size(); ++i) {
Object caller = subroutine.callers.get(i);
if (!callers.contains(caller)) {
callers.add(caller);
changes = true;
}
}
return changes;
}
}
}
asm-1.5.3/src/org/objectweb/asm/tree/analysis/AnalyzerException.java 100644 0 0 4300 10075731026 22620 0 ustar 0 0 /***
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000,2002,2003 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.objectweb.asm.tree.analysis;
/**
* Thrown if a problem occurs during the analysis of a method.
*
* @author Bing Ran
* @author Eric Bruneton
*/
public class AnalyzerException extends Exception {
public AnalyzerException (final String msg) {
super(msg);
}
public AnalyzerException (
final String msg,
final Object expected,
final Value encountered)
{
super((msg == null ? "Expected " : msg + ": expected ")
+ expected + ", but found " + encountered);
}
}
asm-1.5.3/src/org/objectweb/asm/tree/analysis/BasicInterpreter.java 100644 0 0 22741 10075731026 22452 0 ustar 0 0 /***
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000,2002,2003 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.objectweb.asm.tree.analysis;
import java.util.List;
import org.objectweb.asm.Constants;
import org.objectweb.asm.Type;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.FieldInsnNode;
import org.objectweb.asm.tree.IntInsnNode;
import org.objectweb.asm.tree.LdcInsnNode;
import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.MultiANewArrayInsnNode;
import org.objectweb.asm.tree.TypeInsnNode;
/**
* An {@link Interpreter} for {@link BasicValue} values.
*
* @author Eric Bruneton
* @author Bing Ran
*/
public class BasicInterpreter implements Constants, Interpreter {
public Value newValue (final Type type) {
if (type == null) {
return BasicValue.UNINITIALIZED_VALUE;
}
switch (type.getSort()) {
case Type.VOID:
return null;
case Type.BOOLEAN:
case Type.CHAR:
case Type.BYTE:
case Type.SHORT:
case Type.INT:
return BasicValue.INT_VALUE;
case Type.FLOAT:
return BasicValue.FLOAT_VALUE;
case Type.LONG:
return BasicValue.LONG_VALUE;
case Type.DOUBLE:
return BasicValue.DOUBLE_VALUE;
case Type.ARRAY:
case Type.OBJECT:
return BasicValue.REFERENCE_VALUE;
default:
throw new RuntimeException("Internal error.");
}
}
public Value newOperation (final AbstractInsnNode insn) {
switch (insn.getOpcode()) {
case ACONST_NULL:
return newValue(Type.getType("Lnull;"));
case ICONST_M1:
case ICONST_0:
case ICONST_1:
case ICONST_2:
case ICONST_3:
case ICONST_4:
case ICONST_5:
return BasicValue.INT_VALUE;
case LCONST_0:
case LCONST_1:
return BasicValue.LONG_VALUE;
case FCONST_0:
case FCONST_1:
case FCONST_2:
return BasicValue.FLOAT_VALUE;
case DCONST_0:
case DCONST_1:
return BasicValue.DOUBLE_VALUE;
case BIPUSH:
case SIPUSH:
return BasicValue.INT_VALUE;
case LDC:
Object cst = ((LdcInsnNode)insn).cst;
if (cst instanceof Integer) {
return BasicValue.INT_VALUE;
} else if (cst instanceof Float) {
return BasicValue.FLOAT_VALUE;
} else if (cst instanceof Long) {
return BasicValue.LONG_VALUE;
} else if (cst instanceof Double) {
return BasicValue.DOUBLE_VALUE;
} else {
return newValue(Type.getType(cst.getClass()));
}
case JSR:
return BasicValue.RETURNADDRESS_VALUE;
case GETSTATIC:
return newValue(Type.getType(((FieldInsnNode)insn).desc));
case NEW:
return newValue(Type.getType("L" + ((TypeInsnNode)insn).desc + ";"));
default:
throw new RuntimeException("Internal error.");
}
}
public Value copyOperation (final AbstractInsnNode insn, final Value value)
throws AnalyzerException
{
return value;
}
public Value unaryOperation (final AbstractInsnNode insn, final Value value)
throws AnalyzerException
{
switch (insn.getOpcode()) {
case INEG:
case IINC:
case L2I:
case F2I:
case D2I:
case I2B:
case I2C:
case I2S:
return BasicValue.INT_VALUE;
case FNEG:
case I2F:
case L2F:
case D2F:
return BasicValue.FLOAT_VALUE;
case LNEG:
case I2L:
case F2L:
case D2L:
return BasicValue.LONG_VALUE;
case DNEG:
case I2D:
case L2D:
case F2D:
return BasicValue.DOUBLE_VALUE;
case IFEQ:
case IFNE:
case IFLT:
case IFGE:
case IFGT:
case IFLE:
case TABLESWITCH:
case LOOKUPSWITCH:
case IRETURN:
case LRETURN:
case FRETURN:
case DRETURN:
case ARETURN:
case PUTSTATIC:
return null;
case GETFIELD:
return newValue(Type.getType(((FieldInsnNode)insn).desc));
case NEWARRAY:
switch (((IntInsnNode)insn).operand) {
case T_BOOLEAN:
case T_CHAR:
case T_BYTE:
case T_SHORT:
case T_INT:
return newValue(Type.getType("[I"));
case T_FLOAT:
return newValue(Type.getType("[F"));
case T_DOUBLE:
return newValue(Type.getType("[D"));
case T_LONG:
return newValue(Type.getType("[J"));
default:
throw new AnalyzerException("Invalid array type");
}
case ANEWARRAY:
String desc = ((TypeInsnNode)insn).desc;
if (desc.charAt(0) == '[') {
return newValue(Type.getType("[" + desc));
} else {
return newValue(Type.getType("[L" + desc + ";"));
}
case ARRAYLENGTH:
return BasicValue.INT_VALUE;
case ATHROW:
return null;
case CHECKCAST:
desc = ((TypeInsnNode)insn).desc;
if (desc.charAt(0) == '[') {
return newValue(Type.getType(desc));
} else {
return newValue(Type.getType("L" + desc + ";"));
}
case INSTANCEOF:
return BasicValue.INT_VALUE;
case MONITORENTER:
case MONITOREXIT:
case IFNULL:
case IFNONNULL:
return null;
default:
throw new RuntimeException("Internal error.");
}
}
public Value binaryOperation (
final AbstractInsnNode insn,
final Value value1,
final Value value2) throws AnalyzerException
{
switch (insn.getOpcode()) {
case IALOAD:
case BALOAD:
case CALOAD:
case SALOAD:
case IADD:
case ISUB:
case IMUL:
case IDIV:
case IREM:
case ISHL:
case ISHR:
case IUSHR:
case IAND:
case IOR:
case IXOR:
return BasicValue.INT_VALUE;
case FALOAD:
case FADD:
case FSUB:
case FMUL:
case FDIV:
case FREM:
return BasicValue.FLOAT_VALUE;
case LALOAD:
case LADD:
case LSUB:
case LMUL:
case LDIV:
case LREM:
case LSHL:
case LSHR:
case LUSHR:
case LAND:
case LOR:
case LXOR:
return BasicValue.LONG_VALUE;
case DALOAD:
case DADD:
case DSUB:
case DMUL:
case DDIV:
case DREM:
return BasicValue.DOUBLE_VALUE;
case AALOAD:
Type t = ((BasicValue)value1).getType();
if (t != null && t.getSort() == Type.ARRAY) {
return newValue(t.getElementType());
} else {
return BasicValue.REFERENCE_VALUE;
}
case LCMP:
case FCMPL:
case FCMPG:
case DCMPL:
case DCMPG:
return BasicValue.INT_VALUE;
case IF_ICMPEQ:
case IF_ICMPNE:
case IF_ICMPLT:
case IF_ICMPGE:
case IF_ICMPGT:
case IF_ICMPLE:
case IF_ACMPEQ:
case IF_ACMPNE:
case PUTFIELD:
return null;
default:
throw new RuntimeException("Internal error.");
}
}
public Value ternaryOperation (
final AbstractInsnNode insn,
final Value value1,
final Value value2,
final Value value3) throws AnalyzerException
{
return null;
}
public Value naryOperation (final AbstractInsnNode insn, final List values)
throws AnalyzerException
{
if (insn.getOpcode() == MULTIANEWARRAY) {
return newValue(Type.getType(((MultiANewArrayInsnNode)insn).desc));
} else {
return newValue(Type.getReturnType(((MethodInsnNode)insn).desc));
}
}
public Value merge (final Value v, final Value w) {
if (!v.equals(w)) {
return BasicValue.UNINITIALIZED_VALUE;
}
return v;
}
}
asm-1.5.3/src/org/objectweb/asm/tree/analysis/BasicValue.java 100644 0 0 7120 10075731026 21175 0 ustar 0 0 /***
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000,2002,2003 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.objectweb.asm.tree.analysis;
import org.objectweb.asm.Type;
/**
* A {@link Value} that is represented by its type in a seven types type sytem.
* This type system distinguishes the UNINITIALZED, INT, FLOAT, LONG, DOUBLE,
* REFERENCE and RETURNADDRESS types.
*
* @author Eric Bruneton
*/
public class BasicValue implements Value {
public final static Value UNINITIALIZED_VALUE = new BasicValue(null);
public final static Value INT_VALUE = new BasicValue(Type.INT_TYPE);
public final static Value FLOAT_VALUE = new BasicValue(Type.FLOAT_TYPE);
public final static Value LONG_VALUE = new BasicValue(Type.LONG_TYPE);
public final static Value DOUBLE_VALUE = new BasicValue(Type.DOUBLE_TYPE);
public final static Value REFERENCE_VALUE = new BasicValue(Type.getType("Ljava/lang/Object;"));
public final static Value RETURNADDRESS_VALUE = new BasicValue(null);
private Type type;
public BasicValue (final Type type) {
this.type = type;
}
public Type getType () {
return type;
}
public int getSize () {
return type == Type.LONG_TYPE || type == Type.DOUBLE_TYPE ? 2 : 1;
}
public boolean isReference () {
return type != null && (type.getSort() == Type.OBJECT || type.getSort() == Type.ARRAY);
}
public boolean equals (final Value value) {
if (value == this) {
return true;
} else if (value instanceof BasicValue) {
if (type == null) {
return ((BasicValue)value).type == null;
} else {
return type.equals(((BasicValue)value).type);
}
} else {
return false;
}
}
public String toString () {
if (this == UNINITIALIZED_VALUE) {
return ".";
} else if (this == RETURNADDRESS_VALUE) {
return "A";
} else if (this == REFERENCE_VALUE) {
return "R";
} else {
return type.getDescriptor();
}
}
} asm-1.5.3/src/org/objectweb/asm/tree/analysis/BasicVerifier.java 100644 0 0 27311 10075731026 21720 0 ustar 0 0 /***
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000,2002,2003 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.objectweb.asm.tree.analysis;
import java.util.List;
import org.objectweb.asm.Type;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.FieldInsnNode;
import org.objectweb.asm.tree.MethodInsnNode;
/**
* An extended {@link BasicInterpreter} that checks that bytecode instructions
* are correctly used.
*
* @author Eric Bruneton
* @author Bing Ran
*/
public class BasicVerifier extends BasicInterpreter {
public Value copyOperation (final AbstractInsnNode insn, final Value value)
throws AnalyzerException
{
Value expected;
switch (insn.getOpcode()) {
case ILOAD:
case ISTORE:
expected = BasicValue.INT_VALUE;
break;
case FLOAD:
case FSTORE:
expected = BasicValue.FLOAT_VALUE;
break;
case LLOAD:
case LSTORE:
expected = BasicValue.LONG_VALUE;
break;
case DLOAD:
case DSTORE:
expected = BasicValue.DOUBLE_VALUE;
break;
case ALOAD:
if (!((BasicValue)value).isReference()) {
throw new AnalyzerException(null, "an object reference", value);
}
return value;
case ASTORE:
if (!((BasicValue)value).isReference() &&
value != BasicValue.RETURNADDRESS_VALUE)
{
throw new AnalyzerException(
null, "an object reference or a return address", value);
}
return value;
default:
return value;
}
// type is necessarily a primitive type here,
// so value must be == to expected value
if (value != expected) {
throw new AnalyzerException(null, expected, value);
}
return value;
}
public Value unaryOperation (final AbstractInsnNode insn, Value value)
throws AnalyzerException
{
Value expected;
switch (insn.getOpcode()) {
case INEG:
case IINC:
case I2F:
case I2L:
case I2D:
case I2B:
case I2C:
case I2S:
case IFEQ:
case IFNE:
case IFLT:
case IFGE:
case IFGT:
case IFLE:
case TABLESWITCH:
case LOOKUPSWITCH:
case IRETURN:
case NEWARRAY:
case ANEWARRAY:
expected = BasicValue.INT_VALUE;
break;
case FNEG:
case F2I:
case F2L:
case F2D:
case FRETURN:
expected = BasicValue.FLOAT_VALUE;
break;
case LNEG:
case L2I:
case L2F:
case L2D:
case LRETURN:
expected = BasicValue.LONG_VALUE;
break;
case DNEG:
case D2I:
case D2F:
case D2L:
case DRETURN:
expected = BasicValue.DOUBLE_VALUE;
break;
case GETFIELD:
expected = newValue(Type.getType("L" + ((FieldInsnNode)insn).owner + ";"));
break;
case CHECKCAST:
if (!((BasicValue)value).isReference()) {
throw new AnalyzerException(null, "an object reference", value);
}
return super.unaryOperation(insn, value);
case ARRAYLENGTH:
if (!isArrayValue(value)) {
throw new AnalyzerException(null, "an array reference", value);
}
return super.unaryOperation(insn, value);
case ARETURN:
case ATHROW:
case INSTANCEOF:
case MONITORENTER:
case MONITOREXIT:
case IFNULL:
case IFNONNULL:
if (!((BasicValue)value).isReference()) {
throw new AnalyzerException(null, "an object reference", value);
}
return super.unaryOperation(insn, value);
case PUTSTATIC:
expected = newValue(Type.getType(((FieldInsnNode)insn).desc));
break;
default:
throw new RuntimeException("Internal error.");
}
if (!isSubTypeOf(value, expected)) {
throw new AnalyzerException(null, expected, value);
}
return super.unaryOperation(insn, value);
}
public Value binaryOperation (
final AbstractInsnNode insn,
final Value value1,
final Value value2) throws AnalyzerException
{
Value expected1;
Value expected2;
switch (insn.getOpcode()) {
case IALOAD:
case BALOAD:
case CALOAD:
case SALOAD:
expected1 = newValue(Type.getType("[I"));
expected2 = BasicValue.INT_VALUE;
break;
case LALOAD:
expected1 = newValue(Type.getType("[J"));
expected2 = BasicValue.INT_VALUE;
break;
case FALOAD:
expected1 = newValue(Type.getType("[F"));
expected2 = BasicValue.INT_VALUE;
break;
case DALOAD:
expected1 = newValue(Type.getType("[D"));
expected2 = BasicValue.INT_VALUE;
break;
case AALOAD:
expected1 = newValue(Type.getType("[Ljava/lang/Object;"));
expected2 = BasicValue.INT_VALUE;
break;
case IADD:
case ISUB:
case IMUL:
case IDIV:
case IREM:
case ISHL:
case ISHR:
case IUSHR:
case IAND:
case IOR:
case IXOR:
case IF_ICMPEQ:
case IF_ICMPNE:
case IF_ICMPLT:
case IF_ICMPGE:
case IF_ICMPGT:
case IF_ICMPLE:
expected1 = BasicValue.INT_VALUE;
expected2 = BasicValue.INT_VALUE;
break;
case FADD:
case FSUB:
case FMUL:
case FDIV:
case FREM:
case FCMPL:
case FCMPG:
expected1 = BasicValue.FLOAT_VALUE;
expected2 = BasicValue.FLOAT_VALUE;
break;
case LADD:
case LSUB:
case LMUL:
case LDIV:
case LREM:
case LAND:
case LOR:
case LXOR:
case LCMP:
expected1 = BasicValue.LONG_VALUE;
expected2 = BasicValue.LONG_VALUE;
break;
case LSHL:
case LSHR:
case LUSHR:
expected1 = BasicValue.LONG_VALUE;
expected2 = BasicValue.INT_VALUE;
break;
case DADD:
case DSUB:
case DMUL:
case DDIV:
case DREM:
case DCMPL:
case DCMPG:
expected1 = BasicValue.DOUBLE_VALUE;
expected2 = BasicValue.DOUBLE_VALUE;
break;
case IF_ACMPEQ:
case IF_ACMPNE:
expected1 = BasicValue.REFERENCE_VALUE;
expected2 = BasicValue.REFERENCE_VALUE;
break;
case PUTFIELD:
FieldInsnNode fin = (FieldInsnNode)insn;
expected1 = newValue(Type.getType("L" + fin.owner + ";"));
expected2 = newValue(Type.getType(fin.desc));
break;
default:
throw new RuntimeException("Internal error.");
}
if (!isSubTypeOf(value1, expected1)) {
throw new AnalyzerException("First argument", expected1, value1);
} else if (!isSubTypeOf(value2, expected2)) {
throw new AnalyzerException("Second argument", expected2, value2);
}
if (insn.getOpcode() == AALOAD) {
return getElementValue(value1);
} else {
return super.binaryOperation(insn, value1, value2);
}
}
public Value ternaryOperation (
final AbstractInsnNode insn,
final Value value1,
final Value value2,
final Value value3) throws AnalyzerException
{
Value expected1;
Value expected3;
switch (insn.getOpcode()) {
case IASTORE:
case BASTORE:
case CASTORE:
case SASTORE:
expected1 = newValue(Type.getType("[I"));
expected3 = BasicValue.INT_VALUE;
break;
case LASTORE:
expected1 = newValue(Type.getType("[J"));
expected3 = BasicValue.LONG_VALUE;
break;
case FASTORE:
expected1 = newValue(Type.getType("[F"));
expected3 = BasicValue.FLOAT_VALUE;
break;
case DASTORE:
expected1 = newValue(Type.getType("[D"));
expected3 = BasicValue.DOUBLE_VALUE;
break;
case AASTORE:
expected1 = value1;
expected3 = getElementValue(value1);
break;
default:
throw new RuntimeException("Internal error.");
}
if (!isSubTypeOf(value1, expected1)) {
throw new AnalyzerException(
"First argument", "a " + expected1 + " array reference", value1);
} else if (value2 != BasicValue.INT_VALUE) {
throw new AnalyzerException(
"Second argument", BasicValue.INT_VALUE, value2);
} else if (!isSubTypeOf(value3, expected3)) {
throw new AnalyzerException("Third argument", expected3, value3);
}
return null;
}
public Value naryOperation (final AbstractInsnNode insn, final List values)
throws AnalyzerException
{
int opcode = insn.getOpcode();
if (opcode == MULTIANEWARRAY) {
for (int i = 0; i < values.size(); ++i) {
if (values.get(i) != BasicValue.INT_VALUE) {
throw new AnalyzerException(
null, BasicValue.INT_VALUE, (Value)values.get(i));
}
}
} else {
int i = 0;
int j = 0;
if (opcode != INVOKESTATIC) {
Type owner = Type.getType("L" + ((MethodInsnNode)insn).owner + ";");
if (!isSubTypeOf((Value)values.get(i++), newValue(owner))) {
throw new AnalyzerException(
"Method owner", newValue(owner), (Value)values.get(0));
}
}
Type[] args = Type.getArgumentTypes(((MethodInsnNode)insn).desc);
while (i < values.size()) {
Value expected = newValue(args[j++]);
Value encountered = (Value)values.get(i++);
if (!isSubTypeOf(encountered, expected)) {
throw new AnalyzerException("Argument " + j, expected, encountered);
}
}
}
return super.naryOperation(insn, values);
}
protected boolean isArrayValue (final Value value) {
return ((BasicValue)value).isReference();
}
protected Value getElementValue (final Value objectArrayValue)
throws AnalyzerException
{
return BasicValue.REFERENCE_VALUE;
}
protected boolean isSubTypeOf (final Value value, final Value expected) {
return value == expected;
}
}
asm-1.5.3/src/org/objectweb/asm/tree/analysis/DataflowInterpreter.java 100644 0 0 11757 10075731026 23177 0 ustar 0 0 /***
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000,2002,2003 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.objectweb.asm.tree.analysis;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.objectweb.asm.Constants;
import org.objectweb.asm.Type;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.FieldInsnNode;
import org.objectweb.asm.tree.LdcInsnNode;
import org.objectweb.asm.tree.MethodInsnNode;
/**
* An {@link Interpreter} for {@link DataflowValue} values.
*
* @author Eric Bruneton
*/
public class DataflowInterpreter implements Constants, Interpreter {
public Value newValue (final Type type) {
return new DataflowValue(type == null ? 1 : type.getSize());
}
public Value newOperation (final AbstractInsnNode insn) {
int size;
switch (insn.getOpcode()) {
case LCONST_0:
case LCONST_1:
case DCONST_0:
case DCONST_1:
size = 2;
break;
case LDC:
Object cst = ((LdcInsnNode)insn).cst;
size = cst instanceof Long || cst instanceof Double ? 2 : 1;
break;
case GETSTATIC:
size = Type.getType(((FieldInsnNode)insn).desc).getSize();
break;
default:
size = 1;
}
return new DataflowValue(size, insn);
}
public Value copyOperation (final AbstractInsnNode insn, final Value value) {
return new DataflowValue(value.getSize(), insn);
}
public Value unaryOperation (final AbstractInsnNode insn, final Value value) {
int size;
switch (insn.getOpcode()) {
case LNEG:
case DNEG:
case I2L:
case I2D:
case L2D:
case F2L:
case F2D:
case D2L:
size = 2;
break;
case GETFIELD:
size = Type.getType(((FieldInsnNode)insn).desc).getSize();
break;
default:
size = 1;
}
return new DataflowValue(size, insn);
}
public Value binaryOperation (
final AbstractInsnNode insn,
final Value value1,
final Value value2)
{
int size;
switch (insn.getOpcode()) {
case LALOAD:
case DALOAD:
case LADD:
case DADD:
case LSUB:
case DSUB:
case LMUL:
case DMUL:
case LDIV:
case DDIV:
case LREM:
case DREM:
case LSHL:
case LSHR:
case LUSHR:
case LAND:
case LOR:
case LXOR:
size = 2;
break;
default:
size = 1;
}
return new DataflowValue(size, insn);
}
public Value ternaryOperation (
final AbstractInsnNode insn,
final Value value1,
final Value value2,
final Value value3)
{
return new DataflowValue(1, insn);
}
public Value naryOperation (final AbstractInsnNode insn, final List values) {
int size;
if (insn.getOpcode() == MULTIANEWARRAY) {
size = 1;
} else {
size = Type.getReturnType(((MethodInsnNode)insn).desc).getSize();
}
return new DataflowValue(size, insn);
}
public Value merge (final Value v, final Value w) {
DataflowValue dv = (DataflowValue)v;
DataflowValue dw = (DataflowValue)w;
if (dv.size != dw.size || !dv.insns.equals(dw.insns)) {
Set s = new HashSet();
s.addAll(dv.insns);
s.addAll(dw.insns);
return new DataflowValue(Math.min(dv.size, dw.size), s);
}
return v;
}
}
asm-1.5.3/src/org/objectweb/asm/tree/analysis/DataflowValue.java 100644 0 0 6213 10075731026 21717 0 ustar 0 0 /***
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000,2002,2003 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.objectweb.asm.tree.analysis;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import org.objectweb.asm.tree.AbstractInsnNode;
/**
* A {@link Value} that is represented by its type in a two types type system.
* This type system distinguishes the ONEWORD and TWOWORDS types.
*
* @author Eric Bruneton
*/
public class DataflowValue implements Value {
/**
* The size of this value.
*/
public final int size;
/**
* The instructions that can produce this value. For example, for the Java
* code below, the instructions that can produce the value of i
* at line 5 are the txo ISTORE instructions at line 1 and 3:
*
* 1: i = 0;
* 2: if (...) {
* 3: i = 1;
* 4: }
* 5: return i;
*
* This field is a set of {@link AbstractInsnNode} objects.
*/
public final Set insns;
public DataflowValue (final int size) {
this(size, Collections.EMPTY_SET);
}
public DataflowValue (final int size, final AbstractInsnNode insn) {
this.size = size;
this.insns = new HashSet();
this.insns.add(insn);
}
public DataflowValue (final int size, final Set insns) {
this.size = size;
this.insns = insns;
}
public int getSize () {
return size;
}
public boolean equals (final Value value) {
DataflowValue v = (DataflowValue)value;
return size == v.size && insns.equals(v.insns);
}
}
asm-1.5.3/src/org/objectweb/asm/tree/analysis/Frame.java 100644 0 0 53664 10075731026 20247 0 ustar 0 0 /***
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000,2002,2003 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.objectweb.asm.tree.analysis;
import java.util.ArrayList;
import java.util.List;
import org.objectweb.asm.Constants;
import org.objectweb.asm.Type;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.IincInsnNode;
import org.objectweb.asm.tree.MethodInsnNode;
import org.objectweb.asm.tree.MultiANewArrayInsnNode;
import org.objectweb.asm.tree.VarInsnNode;
/**
* A symbolic execution stack frame. A stack frame contains a set of local
* variable slots, and an operand stack. Warning: long and double values are
* represented by two slots in local variables, and by one slot
* in the operand stack.
*
* @author Eric Bruneton
*/
public class Frame {
/**
* The local variables of this frame.
*/
private Value[] locals;
/**
* The operand stack of this frame.
*/
private Value[] stack;
/**
* The number of elements in the operand stack.
*/
private int top;
/**
* Constructs a new frame with the given size.
*
* @param nLocals the maximum number of local variables of the frame.
* @param nStack the maximum stack size of the frame.
*/
public Frame (final int nLocals, final int nStack) {
this.locals = new Value[nLocals];
this.stack = new Value[nStack];
}
/**
* Constructs a new frame that is identical to the given frame.
*
* @param src a frame.
*/
public Frame (final Frame src) {
this(src.locals.length, src.stack.length);
init(src);
}
/**
* Copies the state of the given frame into this frame.
*
* @param src a frame.
* @return this frame.
*/
public Frame init (final Frame src) {
System.arraycopy(src.locals, 0, locals, 0, locals.length);
System.arraycopy(src.stack, 0, stack, 0, src.top);
top = src.top;
return this;
}
/**
* Returns the maximum number of local variables of this frame.
*
* @return the maximum number of local variables of this frame.
*/
public int getLocals () {
return locals.length;
}
/**
* Returns the value of the given local variable.
*
* @param i a local variable index.
* @return the value of the given local variable.
* @throws AnalyzerException if the variable does not exist.
*/
public Value getLocal (final int i) throws AnalyzerException {
if (i >= locals.length) {
throw new AnalyzerException("Trying to access an inexistant local variable");
}
return locals[i];
}
/**
* Sets the value of the given local variable.
*
* @param i a local variable index.
* @param value the new value of this local variable.
* @throws AnalyzerException if the variable does not exist.
*/
public void setLocal (final int i, final Value value) throws AnalyzerException {
if (i >= locals.length) {
throw new AnalyzerException("Trying to access an inexistant local variable");
}
locals[i] = value;
}
/**
* Returns the number of values in the operand stack of this frame. Long and
* double values are treated as single values.
*
* @return the number of values in the operand stack of this frame.
*/
public int getStackSize () {
return top;
}
/**
* Returns the value of the given operand stack slot.
*
* @param i the index of an operand stack slot.
* @return the value of the given operand stack slot.
* @throws AnalyzerException if the operand stack slot does not exist.
*/
public Value getStack (final int i) throws AnalyzerException {
if (i >= top) {
throw new AnalyzerException("Trying to access an inexistant stack element");
}
return stack[i];
}
/**
* Clears the operand stack of this frame.
*/
public void clearStack () {
top = 0;
}
/**
* Pops a value from the operand stack of this frame.
*
* @return the value that has been popped from the stack.
* @throws AnalyzerException if the operand stack is empty.
*/
public Value pop () throws AnalyzerException {
if (top == 0) {
throw new AnalyzerException("Cannot pop operand off an empty stack.");
}
return stack[--top];
}
/**
* Pushes a value into the operand stack of this frame.
*
* @param value the value that must be pushed into the stack.
* @throws AnalyzerException if the operand stack is full.
*/
public void push (final Value value) throws AnalyzerException {
if (top >= stack.length) {
throw new AnalyzerException("Insufficient maximum stack size.");
}
stack[top++] = value;
}
public void execute (
final AbstractInsnNode insn,
final Interpreter interpreter) throws AnalyzerException
{
Value value1, value2, value3, value4;
List values;
int var;
switch (insn.getOpcode()) {
case Constants.NOP:
break;
case Constants.ACONST_NULL:
case Constants.ICONST_M1:
case Constants.ICONST_0:
case Constants.ICONST_1:
case Constants.ICONST_2:
case Constants.ICONST_3:
case Constants.ICONST_4:
case Constants.ICONST_5:
case Constants.LCONST_0:
case Constants.LCONST_1:
case Constants.FCONST_0:
case Constants.FCONST_1:
case Constants.FCONST_2:
case Constants.DCONST_0:
case Constants.DCONST_1:
case Constants.BIPUSH:
case Constants.SIPUSH:
case Constants.LDC:
push(interpreter.newOperation(insn));
break;
case Constants.ILOAD:
case Constants.LLOAD:
case Constants.FLOAD:
case Constants.DLOAD:
case Constants.ALOAD:
push(interpreter.copyOperation(insn, getLocal(((VarInsnNode)insn).var)));
break;
case Constants.IALOAD:
case Constants.LALOAD:
case Constants.FALOAD:
case Constants.DALOAD:
case Constants.AALOAD:
case Constants.BALOAD:
case Constants.CALOAD:
case Constants.SALOAD:
value2 = pop();
value1 = pop();
push(interpreter.binaryOperation(insn, value1, value2));
break;
case Constants.ISTORE:
case Constants.LSTORE:
case Constants.FSTORE:
case Constants.DSTORE:
case Constants.ASTORE:
value1 = interpreter.copyOperation(insn, pop());
var = ((VarInsnNode)insn).var;
setLocal(var, value1);
if (value1.getSize() == 2) {
setLocal(var + 1, interpreter.newValue(null));
}
if (var > 0 && getLocal(var - 1).getSize() == 2) {
setLocal(var - 1, interpreter.newValue(null));
}
break;
case Constants.IASTORE:
case Constants.LASTORE:
case Constants.FASTORE:
case Constants.DASTORE:
case Constants.AASTORE:
case Constants.BASTORE:
case Constants.CASTORE:
case Constants.SASTORE:
value3 = pop();
value2 = pop();
value1 = pop();
interpreter.ternaryOperation(insn, value1, value2, value3);
break;
case Constants.POP:
if (pop().getSize() == 2) {
throw new AnalyzerException("Illegal use of POP");
}
break;
case Constants.POP2:
if (pop().getSize() == 1) {
if (pop().getSize() != 1) {
throw new AnalyzerException("Illegal use of POP2");
}
}
break;
case Constants.DUP:
value1 = pop();
if (value1.getSize() != 1) {
throw new AnalyzerException("Illegal use of DUP");
}
push(interpreter.copyOperation(insn, value1));
push(interpreter.copyOperation(insn, value1));
break;
case Constants.DUP_X1:
value1 = pop();
value2 = pop();
if (value1.getSize() != 1 || value2.getSize() != 1) {
throw new AnalyzerException("Illegal use of DUP_X1");
}
push(interpreter.copyOperation(insn, value1));
push(interpreter.copyOperation(insn, value2));
push(interpreter.copyOperation(insn, value1));
break;
case Constants.DUP_X2:
value1 = pop();
if (value1.getSize() == 1) {
value2 = pop();
if (value2.getSize() == 1) {
value3 = pop();
if (value3.getSize() == 1) {
push(interpreter.copyOperation(insn, value1));
push(interpreter.copyOperation(insn, value3));
push(interpreter.copyOperation(insn, value2));
push(interpreter.copyOperation(insn, value1));
break;
}
} else {
push(interpreter.copyOperation(insn, value1));
push(interpreter.copyOperation(insn, value2));
push(interpreter.copyOperation(insn, value1));
break;
}
}
throw new AnalyzerException("Illegal use of DUP_X2");
case Constants.DUP2:
value1 = pop();
if (value1.getSize() == 1) {
value2 = pop();
if (value2.getSize() == 1) {
push(interpreter.copyOperation(insn, value2));
push(interpreter.copyOperation(insn, value1));
push(interpreter.copyOperation(insn, value2));
push(interpreter.copyOperation(insn, value1));
break;
}
} else {
push(interpreter.copyOperation(insn, value1));
push(interpreter.copyOperation(insn, value1));
break;
}
throw new AnalyzerException("Illegal use of DUP2");
case Constants.DUP2_X1:
value1 = pop();
if (value1.getSize() == 1) {
value2 = pop();
if (value2.getSize() == 1) {
value3 = pop();
if (value3.getSize() == 1) {
push(interpreter.copyOperation(insn, value2));
push(interpreter.copyOperation(insn, value1));
push(interpreter.copyOperation(insn, value3));
push(interpreter.copyOperation(insn, value2));
push(interpreter.copyOperation(insn, value1));
break;
}
}
} else {
value2 = pop();
if (value2.getSize() == 1) {
push(interpreter.copyOperation(insn, value1));
push(interpreter.copyOperation(insn, value2));
push(interpreter.copyOperation(insn, value1));
break;
}
}
throw new AnalyzerException("Illegal use of DUP2_X1");
case Constants.DUP2_X2:
value1 = pop();
if (value1.getSize() == 1) {
value2 = pop();
if (value2.getSize() == 1) {
value3 = pop();
if (value3.getSize() == 1) {
value4 = pop();
if (value4.getSize() == 1) {
push(interpreter.copyOperation(insn, value2));
push(interpreter.copyOperation(insn, value1));
push(interpreter.copyOperation(insn, value4));
push(interpreter.copyOperation(insn, value3));
push(interpreter.copyOperation(insn, value2));
push(interpreter.copyOperation(insn, value1));
break;
}
} else {
push(interpreter.copyOperation(insn, value2));
push(interpreter.copyOperation(insn, value1));
push(interpreter.copyOperation(insn, value3));
push(interpreter.copyOperation(insn, value2));
push(interpreter.copyOperation(insn, value1));
break;
}
}
} else {
value2 = pop();
if (value2.getSize() == 1) {
value3 = pop();
if (value3.getSize() == 1) {
push(interpreter.copyOperation(insn, value1));
push(interpreter.copyOperation(insn, value3));
push(interpreter.copyOperation(insn, value2));
push(interpreter.copyOperation(insn, value1));
break;
}
} else {
push(interpreter.copyOperation(insn, value1));
push(interpreter.copyOperation(insn, value2));
push(interpreter.copyOperation(insn, value1));
break;
}
}
throw new AnalyzerException("Illegal use of DUP2_X2");
case Constants.SWAP:
value2 = pop();
value1 = pop();
if (value1.getSize() != 1 || value2.getSize() != 1) {
throw new AnalyzerException("Illegal use of SWAP");
}
push(interpreter.copyOperation(insn, value2));
push(interpreter.copyOperation(insn, value1));
break;
case Constants.IADD:
case Constants.LADD:
case Constants.FADD:
case Constants.DADD:
case Constants.ISUB:
case Constants.LSUB:
case Constants.FSUB:
case Constants.DSUB:
case Constants.IMUL:
case Constants.LMUL:
case Constants.FMUL:
case Constants.DMUL:
case Constants.IDIV:
case Constants.LDIV:
case Constants.FDIV:
case Constants.DDIV:
case Constants.IREM:
case Constants.LREM:
case Constants.FREM:
case Constants.DREM:
value2 = pop();
value1 = pop();
push(interpreter.binaryOperation(insn, value1, value2));
break;
case Constants.INEG:
case Constants.LNEG:
case Constants.FNEG:
case Constants.DNEG:
push(interpreter.unaryOperation(insn, pop()));
break;
case Constants.ISHL:
case Constants.LSHL:
case Constants.ISHR:
case Constants.LSHR:
case Constants.IUSHR:
case Constants.LUSHR:
case Constants.IAND:
case Constants.LAND:
case Constants.IOR:
case Constants.LOR:
case Constants.IXOR:
case Constants.LXOR:
value2 = pop();
value1 = pop();
push(interpreter.binaryOperation(insn, value1, value2));
break;
case Constants.IINC:
var = ((IincInsnNode)insn).var;
setLocal(var, interpreter.unaryOperation(insn, getLocal(var)));
break;
case Constants.I2L:
case Constants.I2F:
case Constants.I2D:
case Constants.L2I:
case Constants.L2F:
case Constants.L2D:
case Constants.F2I:
case Constants.F2L:
case Constants.F2D:
case Constants.D2I:
case Constants.D2L:
case Constants.D2F:
case Constants.I2B:
case Constants.I2C:
case Constants.I2S:
push(interpreter.unaryOperation(insn, pop()));
break;
case Constants.LCMP:
case Constants.FCMPL:
case Constants.FCMPG:
case Constants.DCMPL:
case Constants.DCMPG:
value2 = pop();
value1 = pop();
push(interpreter.binaryOperation(insn, value1, value2));
break;
case Constants.IFEQ:
case Constants.IFNE:
case Constants.IFLT:
case Constants.IFGE:
case Constants.IFGT:
case Constants.IFLE:
interpreter.unaryOperation(insn, pop());
break;
case Constants.IF_ICMPEQ:
case Constants.IF_ICMPNE:
case Constants.IF_ICMPLT:
case Constants.IF_ICMPGE:
case Constants.IF_ICMPGT:
case Constants.IF_ICMPLE:
case Constants.IF_ACMPEQ:
case Constants.IF_ACMPNE:
value2 = pop();
value1 = pop();
interpreter.binaryOperation(insn, value1, value2);
break;
case Constants.GOTO:
break;
case Constants.JSR:
push(interpreter.newOperation(insn));
break;
case Constants.RET:
break;
case Constants.TABLESWITCH:
case Constants.LOOKUPSWITCH:
case Constants.IRETURN:
case Constants.LRETURN:
case Constants.FRETURN:
case Constants.DRETURN:
case Constants.ARETURN:
interpreter.unaryOperation(insn, pop());
break;
case Constants.RETURN:
break;
case Constants.GETSTATIC:
push(interpreter.newOperation(insn));
break;
case Constants.PUTSTATIC:
interpreter.unaryOperation(insn, pop());
break;
case Constants.GETFIELD:
push(interpreter.unaryOperation(insn, pop()));
break;
case Constants.PUTFIELD:
value2 = pop();
value1 = pop();
interpreter.binaryOperation(insn, value1, value2);
break;
case Constants.INVOKEVIRTUAL:
case Constants.INVOKESPECIAL:
case Constants.INVOKESTATIC:
case Constants.INVOKEINTERFACE:
values = new ArrayList();
String desc = ((MethodInsnNode)insn).desc;
for (int i = Type.getArgumentTypes(desc).length; i > 0; --i) {
values.add(0, pop());
}
if (insn.getOpcode() != Constants.INVOKESTATIC) {
values.add(0, pop());
}
if (Type.getReturnType(desc) == Type.VOID_TYPE) {
interpreter.naryOperation(insn, values);
} else {
push(interpreter.naryOperation(insn, values));
}
break;
case Constants.NEW:
push(interpreter.newOperation(insn));
break;
case Constants.NEWARRAY:
case Constants.ANEWARRAY:
case Constants.ARRAYLENGTH:
push(interpreter.unaryOperation(insn, pop()));
break;
case Constants.ATHROW:
interpreter.unaryOperation(insn, pop());
break;
case Constants.CHECKCAST:
case Constants.INSTANCEOF:
push(interpreter.unaryOperation(insn, pop()));
break;
case Constants.MONITORENTER:
case Constants.MONITOREXIT:
interpreter.unaryOperation(insn, pop());
break;
case Constants.MULTIANEWARRAY:
values = new ArrayList();
for (int i = ((MultiANewArrayInsnNode)insn).dims; i > 0; --i) {
values.add(0, pop());
}
push(interpreter.naryOperation(insn, values));
break;
case Constants.IFNULL:
case Constants.IFNONNULL:
interpreter.unaryOperation(insn, pop());
break;
default:
throw new RuntimeException("Illegal opcode");
}
}
/**
* Merges this frame with the given frame.
*
* @param frame a frame.
* @param interpreter the interpreter used to merge values.
* @return true if this frame has been changed as a result of the
* merge operation, or false otherwise.
* @throws AnalyzerException if the frames have incompatible sizes.
*/
public boolean merge (final Frame frame, final Interpreter interpreter)
throws AnalyzerException
{
if (top != frame.top) {
throw new AnalyzerException("Incompatible stack heights");
}
boolean changes = false;
for (int i = 0; i < locals.length; ++i) {
Value v = interpreter.merge(locals[i], frame.locals[i]);
if (v != locals[i]) {
locals[i] = v;
changes |= true;
}
}
for (int i = 0; i < top; ++i) {
Value v = interpreter.merge(stack[i], frame.stack[i]);
if (v != stack[i]) {
stack[i] = v;
changes |= true;
}
}
return changes;
}
/**
* Merges this frame with the given frame (case of a RET instruction).
* @param frame a frame
* @param access the local variables that have been accessed by the
* subroutine to which the RET instruction corresponds.
* @return true if this frame has been changed as a result of the
* merge operation, or false otherwise.
*/
public boolean merge (final Frame frame, final boolean[] access) {
boolean changes = false;
for (int i = 0; i < locals.length; ++i) {
if (!access[i] && !locals[i].equals(frame.locals[i])) {
locals[i] = frame.locals[i];
changes = true;
}
}
return changes;
}
/**
* Returns a string representation of this frame.
*
* @return a string representation of this frame.
*/
public String toString () {
StringBuffer b = new StringBuffer();
for (int i = 0; i < locals.length; ++i) {
b.append(locals[i]);
}
b.append(' ');
for (int i = 0; i < top; ++i) {
b.append(stack[i].toString());
}
return b.toString();
}
}
asm-1.5.3/src/org/objectweb/asm/tree/analysis/Interpreter.java 100644 0 0 20206 10075731026 21502 0 ustar 0 0 /***
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000,2002,2003 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.objectweb.asm.tree.analysis;
import java.util.List;
import org.objectweb.asm.Type;
import org.objectweb.asm.tree.AbstractInsnNode;
/**
* A semantic bytecode interpreter. More precisely, this interpreter only
* manages the computation of values from other values: it does not manage the
* transfer of values to or from the stack, and to or from the local variables.
* This separation allows a generic bytecode {@link Analyzer} to work with
* various semantic interpreters, without needing to duplicate the code to
* simulate the transfer of values.
*
* @author Eric Bruneton
*/
public interface Interpreter {
/**
* Creates a new value that represents the given type.
*
* @param type a primitive or reference type, or null to represent an
* uninitialized value.
* @return a value that represents the given type. The size of the returned
* value must be equal to the size of the given type.
*/
Value newValue (Type type);
/**
* Interprets a bytecode instruction without arguments. This method is called
* for the following opcodes:
*
* ACONST_NULL,
* ICONST_M1, ICONST_0, ICONST_1, ICONST_2, ICONST_3, ICONST_4, ICONST_5,
* LCONST_0, LCONST_1, FCONST_0, FCONST_1, FCONST_2, DCONST_0, DCONST_1,
* BIPUSH, SIPUSH, LDC,
* JSR,
* GETSTATIC,
* NEW
*
* @param insn the bytecode instruction to be interpreted.
* @return the result of the interpretation of the given instruction.
* @throws AnalyzerException if an error occured during the interpretation.
*/
Value newOperation (AbstractInsnNode insn) throws AnalyzerException;
/**
* Interprets a bytecode instruction that moves a value on the stack or to or
* from local variables. This method is called for the following opcodes:
*
* ILOAD, LLOAD, FLOAD, DLOAD, ALOAD, ISTORE, LSTORE, FSTORE, DSTORE, ASTORE,
* DUP, DUP_X1, DUP_X2, DUP2, DUP2_X1, DUP2_X2,
* SWAP
*
* @param insn the bytecode instruction to be interpreted.
* @param value the value that must be moved by the instruction.
* @return the result of the interpretation of the given instruction. The
* returned value must be {@link Value#equals(Value) equal} to the given
* value.
* @throws AnalyzerException if an error occured during the interpretation.
*/
Value copyOperation (AbstractInsnNode insn, Value value)
throws AnalyzerException;
/**
* Interprets a bytecode instruction with a single argument. This method is
* called for the following opcodes:
*
* INEG, LNEG, FNEG, DNEG,
* IINC,
* I2L, I2F, I2D, L2I, L2F, L2D, F2I, F2L, F2D, D2I, D2L, D2F, I2B, I2C, I2S,
* IFEQ, IFNE, IFLT, IFGE, IFGT, IFLE,
* TABLESWITCH,
* LOOKUPSWITCH,
* IRETURN, LRETURN, FRETURN, DRETURN, ARETURN,
* PUTSTATIC,
* GETFIELD,
* NEWARRAY, ANEWARRAY,
* ARRAYLENGTH,
* ATHROW,
* CHECKCAST, INSTANCEOF,
* MONITORENTER, MONITOREXIT,
* IFNULL, IFNONNULL
*
* @param insn the bytecode instruction to be interpreted.
* @param value the argument of the instruction to be interpreted.
* @return the result of the interpretation of the given instruction.
* @throws AnalyzerException if an error occured during the interpretation.
*/
Value unaryOperation (AbstractInsnNode insn, Value value)
throws AnalyzerException;
/**
* Interprets a bytecode instruction with two arguments. This method is
* called for the following opcodes:
*
* IALOAD, LALOAD, FALOAD, DALOAD, AALOAD, BALOAD, CALOAD, SALOAD,
* IADD, LADD, FADD, DADD, ISUB, LSUB, FSUB, DSUB, IMUL, LMUL, FMUL, DMUL,
* IDIV, LDIV, FDIV, DDIV, IREM, LREM, FREM, DREM,
* ISHL, LSHL, ISHR, LSHR, IUSHR, LUSHR,
* IAND, LAND, IOR, LOR, IXOR, LXOR,
* LCMP, FCMPL, FCMPG, DCMPL, DCMPG,
* IF_ICMPEQ, IF_ICMPNE, IF_ICMPLT, IF_ICMPGE, IF_ICMPGT, IF_ICMPLE,
* IF_ACMPEQ, IF_ACMPNE,
* PUTFIELD
*
* @param insn the bytecode instruction to be interpreted.
* @param value1 the first argument of the instruction to be interpreted.
* @param value2 the second argument of the instruction to be interpreted.
* @return the result of the interpretation of the given instruction.
* @throws AnalyzerException if an error occured during the interpretation.
*/
Value binaryOperation (AbstractInsnNode insn, Value value1, Value value2)
throws AnalyzerException;
/**
* Interprets a bytecode instruction with three arguments. This method is
* called for the following opcodes:
*
* IASTORE, LASTORE, FASTORE, DASTORE, AASTORE, BASTORE, CASTORE, SASTORE
*
* @param insn the bytecode instruction to be interpreted.
* @param value1 the first argument of the instruction to be interpreted.
* @param value2 the second argument of the instruction to be interpreted.
* @param value3 the third argument of the instruction to be interpreted.
* @return the result of the interpretation of the given instruction.
* @throws AnalyzerException if an error occured during the interpretation.
*/
Value ternaryOperation (AbstractInsnNode insn, Value value1, Value value2, Value value3)
throws AnalyzerException;
/**
* Interprets a bytecode instruction with a variable number of arguments.
* This method is called for the following opcodes:
*
* INVOKEVIRTUAL, INVOKESPECIAL, INVOKESTATIC, INVOKEINTERFACE,
* MULTIANEWARRAY
*
* @param insn the bytecode instruction to be interpreted.
* @param values the arguments of the instruction to be interpreted.
* @return the result of the interpretation of the given instruction.
* @throws AnalyzerException if an error occured during the interpretation.
*/
Value naryOperation (AbstractInsnNode insn, List values)
throws AnalyzerException;
/**
* Merges two values. The merge operation must return a value that represents
* both values (for instance, if the two values are two types, the merged
* value must be a common super type of the two types. If the two values are
* integer intervals, the merged value must be an interval that contains the
* previous ones. Likewise for other types of values).
*
* @param v a value.
* @param w another value.
* @return the merged value. If the merged value is equal to v, this
* method must return v.
*/
Value merge (Value v, Value w);
}
asm-1.5.3/src/org/objectweb/asm/tree/analysis/SimpleVerifier.java 100644 0 0 14200 10075754155 22131 0 ustar 0 0 /***
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000,2002,2003 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.objectweb.asm.tree.analysis;
import org.objectweb.asm.Type;
/**
* An extended {@link BasicVerifier} that performs more precise verifications.
* This verifier computes exact class types, instead of using a single
* "object reference" type (as done in the {@link BasicVerifier}).
*
* @author Eric Bruneton
* @author Bing Ran
*/
public class SimpleVerifier extends BasicVerifier {
public Value newValue (final Type type) {
Value v = super.newValue(type);
if (v == BasicValue.REFERENCE_VALUE) {
if (type.getSort() == Type.ARRAY) {
v = newValue(type.getElementType());
String desc = ((BasicValue)v).getType().getDescriptor();
for (int i = 0; i < type.getDimensions(); ++i) {
desc = "[" + desc;
}
v = new BasicValue(Type.getType(desc));
} else {
v = new BasicValue(type);
}
}
return v;
}
protected boolean isArrayValue (final Value value) {
Type t = ((BasicValue)value).getType();
if (t != null) {
return t.getDescriptor().equals("Lnull;") || t.getSort() == Type.ARRAY;
}
return false;
}
protected Value getElementValue (final Value objectArrayValue)
throws AnalyzerException
{
Type arrayType = ((BasicValue)objectArrayValue).getType();
if (arrayType != null) {
if (arrayType.getSort() == Type.ARRAY) {
return newValue(Type.getType(arrayType.getDescriptor().substring(1)));
} else if (arrayType.getDescriptor().equals("Lnull;")) {
return objectArrayValue;
}
}
throw new AnalyzerException("Not an array type");
}
protected boolean isSubTypeOf (final Value value, final Value expected) {
Type expectedType = ((BasicValue)expected).getType();
Type type = ((BasicValue)value).getType();
if (expectedType == null) {
return type == null;
} else {
switch (expectedType.getSort()) {
case Type.INT:
case Type.FLOAT:
case Type.LONG:
case Type.DOUBLE:
return type == expectedType;
case Type.ARRAY:
case Type.OBJECT:
if (expectedType.getDescriptor().equals("Lnull;")) {
return type.getSort() == Type.OBJECT || type.getSort() == Type.ARRAY;
}
Class expectedClass = getClass(expectedType);
if (type.getDescriptor().equals("Lnull;")) {
return !expectedClass.isPrimitive();
} else if (type.getSort() == Type.OBJECT || type.getSort() == Type.ARRAY) {
Class actualClass = getClass(type);
return expectedClass.isAssignableFrom(actualClass);
} else {
return false;
}
default:
throw new RuntimeException("Internal error");
}
}
}
public Value merge (final Value v, final Value w) {
if (!v.equals(w)) {
Type t = ((BasicValue)v).getType();
Type u = ((BasicValue)w).getType();
if (t != null && (t.getSort() == Type.OBJECT || t.getSort() == Type.ARRAY)) {
if (u != null && (u.getSort() == Type.OBJECT || u.getSort() == Type.ARRAY)) {
if (t.getDescriptor().equals("Lnull;")) {
return w;
}
if (u.getDescriptor().equals("Lnull;")) {
return v;
}
Class c = getClass(t);
Class d = getClass(u);
if (c.isAssignableFrom(d)) {
return v;
}
if (d.isAssignableFrom(c)) {
return w;
}
// TODO case of array classes of the same dimension
// TODO should we look also for a common super interface?
// problem: there may be several possible common super interfaces
do {
if (c == null || c.isInterface()) {
return BasicValue.REFERENCE_VALUE;
} else {
c = c.getSuperclass();
}
if (c.isAssignableFrom(d)) {
return newValue(Type.getType(c));
}
} while (true);
}
}
return BasicValue.UNINITIALIZED_VALUE;
}
return v;
}
protected Class getClass (final Type t) {
try {
if (t.getSort() == Type.ARRAY) {
return Class.forName(t.getDescriptor().replace('/', '.'));
} else {
return Class.forName(t.getClassName());
}
} catch (ClassNotFoundException e) {
throw new RuntimeException(e.toString());
}
}
}
asm-1.5.3/src/org/objectweb/asm/tree/analysis/Value.java 100644 0 0 4263 10075731026 20240 0 ustar 0 0 /***
* ASM: a very small and fast Java bytecode manipulation framework
* Copyright (c) 2000,2002,2003 INRIA, France Telecom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.objectweb.asm.tree.analysis;
/**
* An immutable symbolic value for semantic interpretation of bytecode.
*
* @author Eric Bruneton
*/
public interface Value {
/**
* Returns the size of this value in words.
*
* @return either 1 or 2.
*/
int getSize ();
/**
* Compares this value with the given value.
*
* @param value a value.
* @return true if the values are equals, false otherwise.
*/
boolean equals (Value value);
}
asm-1.5.3/src/org/objectweb/asm/tree/analysis/package.html 100644 0 0 3442 10034515240 20571 0 ustar 0 0
Provides a framework for static code analysis based on the asm.tree package.
@since ASM 1.4.3
asm-1.5.3/src/org/objectweb/asm/tree/package.html 100644 0 0 5247 10026564546 16771 0 ustar 0 0
Provides an ASM class adapter that constructs a tree representation of the
classes it visits. This class adapter can be useful to implement "complex"
class manipulation operations, i.e., operations that would be very hard to
implement without using a tree representation (such as optimizing the number
of local variables used by a method).
*
* The source code printed when visiting the Hello class is the
* following:
*
*
* where Hello is defined by:
*
* import org.objectweb.asm.*;
* import java.io.FileOutputStream;
*
* public class Dump implements Constants {
*
* public static void main (String[] args) throws Exception {
*
* ClassWriter cw = new ClassWriter(false);
* CodeVisitor cv;
*
* cw.visit(ACC_PUBLIC + ACC_SUPER, "Hello", "java/lang/Object", null, "Hello.java");
*
* {
* cv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "main", "([Ljava/lang/String;)V", null, null);
* cv.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;");
* cv.visitLdcInsn("hello");
* cv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V");
* cv.visitInsn(RETURN);
* cv.visitMaxs(2, 1);
* }
* {
* cv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
* cv.visitVarInsn(ALOAD, 0);
* cv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V");
* cv.visitInsn(RETURN);
* cv.visitMaxs(1, 1);
* }
* cw.visitEnd();
*
* FileOutputStream os = new FileOutputStream("Dumped.class");
* os.write(cw.toByteArray());
* os.close();
* }
* }
*
*
*
*
* @author Eric Bruneton, Eugene Kuleshov
*/
public class ASMifierClassVisitor extends PrintClassVisitor {
private static final int ACCESS_CLASS = 262144;
private static final int ACCESS_FIELD = 524288;
private static final int ACCESS_INNER = 1048576;
/**
* Prints the ASM source code to generate the given class to the standard
* output.
*
* public class Hello {
*
* public static void main (String[] args) {
* System.out.println("hello");
* }
* }
*
*
*
* where Hello is defined by:
*
* // compiled from Hello.java
* public class Hello {
*
* public static main ([Ljava/lang/String;)V
* GETSTATIC java/lang/System out Ljava/io/PrintStream;
* LDC "hello"
* INVOKEVIRTUAL java/io/PrintStream println (Ljava/lang/String;)V
* RETURN
* MAXSTACK = 2
* MAXLOCALS = 1
*
* public <init> ()V
* ALOAD 0
* INVOKESPECIAL java/lang/Object <init> ()V
* RETURN
* MAXSTACK = 1
* MAXLOCALS = 1
*
* }
*
*
*
*
* @author Eric Bruneton, Eugene Kuleshov
*/
public class TraceClassVisitor extends PrintClassVisitor {
/**
* The {@link ClassVisitor ClassVisitor} to which this visitor delegates
* calls. May be null.
*/
protected final ClassVisitor cv;
/**
* Prints a disassembled view of the given class to the standard output.
*
* public class Hello {
*
* public static void main (String[] args) {
* System.out.println("hello");
* }
* }
*
* null
.
*/
final Object peek() {
return stack.size()==0 ? null : stack.get( stack.size()-1);
}
/**
* Return the n'th object down the stack, where 0 is the top element
* and [getCount()-1] is the bottom element. If the specified index
* is out of range, return null
.
*
* @param n Index of the desired element, where 0 is the top of the stack,
* 1 is the next element down, and so on.
*/
final Object peek(int n) {
return stack.size()<( n+1) ? null : stack.get( n);
}
/**
* Pop the top object off of the stack, and return it. If there are
* no objects on the stack, return null
.
*/
final Object pop() {
return stack.size()==0 ? null : stack.remove( stack.size()-1);
}
/**
* Push a new object onto the top of the object stack.
*
* @param object The new object
*/
final void push(Object object) {
stack.add( object);
}
/**
* Rule
*/
private abstract class Rule {
protected String path;
public Rule( String path) {
this.path = path;
}
public final String getPath() {
return path;
}
public void begin( String name, Attributes attrs) {
}
public void end( String name) {
}
public boolean match( String match, String element) {
return path.equals( match);
}
protected final Object getValue( String desc, String val) {
Object value = null;
if( val!=null) {
if( desc.equals( "Ljava/lang/String;")) {
value = decode( val);
} else if( desc.equals( "Ljava/lang/Integer;") ||
desc.equals( "Z") || desc.equals( "B") || desc.equals( "C") || desc.equals( "I") || desc.equals( "S")) {
value = new Integer( val);
} else if( desc.equals( "Ljava/lang/Long;") || desc.equals( "J")) {
value = new Long( val);
} else if( desc.equals( "Ljava/lang/Float;") || desc.equals( "F")) {
value = new Float( val);
} else if( desc.equals( "Ljava/lang/Double;") || desc.equals( "D")) {
value = new Double( val);
} else {
throw new RuntimeException( "Invalid value:"+val+" desc:"+desc+" ctx:"+this);
}
}
return value;
}
private final String decode( String val) {
StringBuffer sb = new StringBuffer( val.length());
try {
int n = 0;
while( n < val.length()) {
char c = val.charAt( n);
if( c == '\\') {
n++;
c = val.charAt( n);
if( c == '\\') {
sb.append( '\\');
} else {
n++; // skip 'u'
sb.append( ( char) Integer.parseInt( val.substring( n, n + 4), 16));
n += 3;
}
} else {
sb.append( c);
}
n++;
}
} catch( RuntimeException ex) {
System.err.println( val+"\n"+ex.toString());
ex.printStackTrace();
throw ex;
}
return sb.toString();
}
protected final Label getLabel( Object label) {
Label lbl = ( Label) labels.get( label);
if( lbl==null) {
lbl = new Label();
labels.put( label, lbl);
}
return lbl;
}
public String toString() {
return path;
}
protected final CodeVisitor getCodeVisitor() {
if( mw==null) {
Map vals = ( Map) pop();
int access = Integer.parseInt(( String) vals.get( "access"), 16);
String name = ( String) vals.get( "name");
String desc = ( String) vals.get( "desc");
mw = cw.visitMethod( access, name, desc, null, null);
}
return mw;
}
protected final int getAccess( String s) {
int access = 0;
if( s.indexOf( "public")!=-1) access |= Constants.ACC_PUBLIC;
if( s.indexOf( "private")!=-1) access |= Constants.ACC_PRIVATE;
if( s.indexOf( "protected")!=-1) access |= Constants.ACC_PROTECTED;
if( s.indexOf( "static")!=-1) access |= Constants.ACC_STATIC;
if( s.indexOf( "final")!=-1) access |= Constants.ACC_FINAL;
if( s.indexOf( "super")!=-1) access |= Constants.ACC_SUPER;
if( s.indexOf( "synchronized")!=-1) access |= Constants.ACC_SYNCHRONIZED;
if( s.indexOf( "volatile")!=-1) access |= Constants.ACC_VOLATILE;
if( s.indexOf( "bridge")!=-1) access |= Constants.ACC_BRIDGE;
if( s.indexOf( "varargs")!=-1) access |= Constants.ACC_VARARGS;
if( s.indexOf( "transient")!=-1) access |= Constants.ACC_TRANSIENT;
if( s.indexOf( "native")!=-1) access |= Constants.ACC_NATIVE;
if( s.indexOf( "interface")!=-1) access |= Constants.ACC_INTERFACE;
if( s.indexOf( "abstract")!=-1) access |= Constants.ACC_ABSTRACT;
if( s.indexOf( "strict")!=-1) access |= Constants.ACC_STRICT;
if( s.indexOf( "synthetic")!=-1) access |= Constants.ACC_SYNTHETIC;
if( s.indexOf( "annotation")!=-1) access |= Constants.ACC_ANNOTATION;
if( s.indexOf( "enum")!=-1) access |= Constants.ACC_ENUM;
if( s.indexOf( "deprecated")!=-1) access |= Constants.ACC_DEPRECATED;
return access;
}
}
/**
* ClassRule
*/
private final class ClassRule extends Rule {
public ClassRule( String path) {
super( path);
}
public final void begin( String name, Attributes attrs) {
int major = Integer.parseInt( attrs.getValue( "major"));
int minor = Integer.parseInt( attrs.getValue( "minor"));
cw = new ClassWriter( computeMax);
Map vals = new HashMap();
vals.put( "version", new Integer(minor << 16 | major));
vals.put( "access", attrs.getValue( "access"));
vals.put( "name", attrs.getValue( "name"));
vals.put( "parent", attrs.getValue( "parent"));
vals.put( "source", attrs.getValue( "source"));
vals.put( "interfaces", new ArrayList());
push( vals);
// values will be extracted in InterfacesRule.end();
}
}
/**
* InterfaceRule
*/
private final class InterfaceRule extends Rule {
public InterfaceRule( String path) {
super( path);
}
public final void begin( String name, Attributes attrs) {
(( List) (( Map) peek()).get( "interfaces")).add( attrs.getValue( "name"));
}
}
/**
* InterfacesRule
*/
private final class InterfacesRule extends Rule {
public InterfacesRule( String path) {
super( path);
}
public final void end( String element) {
Map vals = ( Map) pop();
int version = (( Integer)vals.get( "version")).intValue();
int access = getAccess(( String) vals.get( "access"));
String name = ( String) vals.get( "name");
String parent = ( String) vals.get( "parent");
String source = ( String) vals.get( "source");
String[] interfaces = ( String[])(( List) vals.get( "interfaces")).toArray( new String[ 0]);
cw.visit( version, access, name, parent, interfaces, source);
}
}
/**
* FieldRule
*/
private final class FieldRule extends Rule {
public FieldRule( String path) {
super( path);
}
public final void begin( String element, Attributes attrs) {
int access = getAccess( attrs.getValue( "access"));
String name = attrs.getValue( "name");
String desc = attrs.getValue( "desc");
Object value = getValue( desc, attrs.getValue( "value"));
cw.visitField( access, name, desc, value, null);
}
}
/**
* MethodRule
*/
private final class MethodRule extends Rule {
public MethodRule( String path) {
super( path);
}
public final void begin( String name, Attributes attrs) {
labels = new HashMap();
Map vals = new HashMap();
vals.put( "access", attrs.getValue( "access"));
vals.put( "name", attrs.getValue( "name"));
vals.put( "desc", attrs.getValue( "desc"));
vals.put( "exceptions", new ArrayList());
push( vals);
// values will be extracted in ExceptionsRule.end();
}
public final void end( String name) {
mw = null;
labels = null;
}
}
/**
* MethodRule
*/
private final class InnerClassRule extends Rule {
public InnerClassRule( String path) {
super( path);
}
public final void begin( String element, Attributes attrs) {
int access = getAccess( attrs.getValue( "access"));
String name = attrs.getValue( "name");
String outerName = attrs.getValue( "outerName");
String innerName = attrs.getValue( "innerName");
cw.visitInnerClass( name, outerName, innerName, access);
}
public final void end( String name) {
mw = null;
labels = null;
}
}
/**
* ExceptionRule
*/
private final class ExceptionRule extends Rule {
public ExceptionRule( String path) {
super( path);
}
public final void begin( String name, Attributes attrs) {
(( List) (( Map) peek()).get( "exceptions")).add( attrs.getValue( "name"));
}
}
/**
* ExceptionsRule
*/
private final class ExceptionsRule extends Rule {
public ExceptionsRule( String path) {
super( path);
}
public final void end( String element) {
Map vals = ( Map) pop();
int access = getAccess(( String) vals.get( "access"));
String name = ( String) vals.get( "name");
String desc = ( String) vals.get( "desc");
String[] exceptions = ( String[])(( List) vals.get( "exceptions")).toArray( new String[ 0]);
mw = cw.visitMethod( access, name, desc, exceptions, null);
}
}
/**
* TableSwitchRule
*/
private class TableSwitchRule extends Rule {
public TableSwitchRule( String path) {
super( path);
}
public final void begin( String name, Attributes attrs) {
Map vals = new HashMap();
vals.put( "min", attrs.getValue( "min"));
vals.put( "max", attrs.getValue( "max"));
vals.put( "dflt", attrs.getValue( "dflt"));
vals.put( "labels", new ArrayList());
push( vals);
}
public final void end( String name) {
Map vals = ( Map) pop();
int min = Integer.parseInt(( String) vals.get( "min"));
int max = Integer.parseInt(( String) vals.get( "max"));
Label dflt = getLabel( vals.get( "dflt"));
Label[] lbls = ( Label[])(( List) vals.get( "labels")).toArray( new Label[ 0]);
getCodeVisitor().visitTableSwitchInsn( min, max, dflt, lbls);
}
}
/**
* TableSwitchLabelRule
*/
private final class TableSwitchLabelRule extends Rule {
public TableSwitchLabelRule( String path) {
super( path);
}
public final void begin( String name, Attributes attrs) {
(( List) (( Map) peek()).get( "labels")).add( getLabel( attrs.getValue( "name")));
}
}
/**
* LookupSwitchRule
*/
private final class LookupSwitchRule extends Rule {
public LookupSwitchRule( String path) {
super( path);
}
public final void begin( String name, Attributes attrs) {
Map vals = new HashMap();
vals.put( "dflt", attrs.getValue( "dflt"));
vals.put( "labels", new ArrayList());
vals.put( "keys", new ArrayList());
push( vals);
}
public final void end( String name) {
Map vals = ( Map) pop();
Label dflt = getLabel( vals.get( "dflt"));
List keyList = ( List) vals.get( "keys");
Label[] lbls = ( Label[])(( List) vals.get( "labels")).toArray( new Label[ 0]);
int[] keys = new int[ keyList.size()];
for( int i = 0; i < keys.length; i++) {
keys[ i] = Integer.parseInt(( String) keyList.get( i));
}
getCodeVisitor().visitLookupSwitchInsn( dflt, keys, lbls);
}
}
/**
* LookupSwitchLabelRule
*/
private final class LookupSwitchLabelRule extends Rule {
public LookupSwitchLabelRule( String path) {
super( path);
}
public final void begin( String name, Attributes attrs) {
Map vals = ( Map) peek();
(( List) vals.get( "labels")).add( getLabel( attrs.getValue( "name")));
(( List) vals.get( "keys")).add( attrs.getValue( "key"));
}
}
/**
* LabelRule
*/
private final class LabelRule extends Rule {
public LabelRule( String path) {
super( path);
}
public final void begin( String name, Attributes attrs) {
getCodeVisitor().visitLabel( getLabel( attrs.getValue( "name")));
}
}
/**
* TryCatchRule
*/
private final class TryCatchRule extends Rule {
public TryCatchRule( String path) {
super( path);
}
public final void begin( String name, Attributes attrs) {
Label start = getLabel( attrs.getValue( "start"));
Label end = getLabel( attrs.getValue( "end"));
Label handler = getLabel( attrs.getValue( "handler"));
String type = attrs.getValue( "type");
getCodeVisitor().visitTryCatchBlock( start, end, handler, type);
}
}
/**
* LineNumberRule
*/
private final class LineNumberRule extends Rule {
public LineNumberRule( String path) {
super( path);
}
public final void begin( String name, Attributes attrs) {
int line = Integer.parseInt( attrs.getValue( "line"));
Label start = getLabel( attrs.getValue( "start"));
getCodeVisitor().visitLineNumber( line, start);
}
}
/**
* LocalVarRule
*/
private final class LocalVarRule extends Rule {
public LocalVarRule( String path) {
super( path);
}
public final void begin( String element, Attributes attrs) {
String name = attrs.getValue( "name");
String desc = attrs.getValue( "desc");
Label start = getLabel( attrs.getValue( "start"));
Label end = getLabel( attrs.getValue( "end"));
int var = Integer.parseInt( attrs.getValue( "var"));
getCodeVisitor().visitLocalVariable( name, desc, start, end, var);
}
}
/**
* OpcodesRule
*/
private final class OpcodesRule extends Rule {
public OpcodesRule( String path) {
super( path);
}
public boolean match( String match, String element) {
return match.startsWith( path) && OPCODES.containsKey( element);
}
public final void begin( String element, Attributes attrs) {
Opcode o = (( Opcode) OPCODES.get( element));
if( o==null) return;
switch( o.type) {
case OpcodeGroup.INSN:
getCodeVisitor().visitInsn( o.opcode);
break;
case OpcodeGroup.INSN_FIELD:
getCodeVisitor().visitFieldInsn( o.opcode, attrs.getValue( "owner"), attrs.getValue( "name"), attrs.getValue( "desc"));
break;
case OpcodeGroup.INSN_INT:
getCodeVisitor().visitIntInsn( o.opcode, Integer.parseInt( attrs.getValue( "value")));
break;
case OpcodeGroup.INSN_JUMP:
getCodeVisitor().visitJumpInsn( o.opcode, getLabel( attrs.getValue( "label")));
break;
case OpcodeGroup.INSN_METHOD:
getCodeVisitor().visitMethodInsn( o.opcode, attrs.getValue( "owner"), attrs.getValue( "name"), attrs.getValue( "desc"));
break;
case OpcodeGroup.INSN_TYPE:
getCodeVisitor().visitTypeInsn( o.opcode, attrs.getValue( "desc"));
break;
case OpcodeGroup.INSN_VAR:
getCodeVisitor().visitVarInsn( o.opcode, Integer.parseInt( attrs.getValue( "var")));
break;
case OpcodeGroup.INSN_IINC:
getCodeVisitor().visitIincInsn( Integer.parseInt( attrs.getValue( "var")), Integer.parseInt( attrs.getValue( "inc")));
break;
case OpcodeGroup.INSN_LDC:
getCodeVisitor().visitLdcInsn( getValue( attrs.getValue( "desc"), attrs.getValue( "cst")));
break;
case OpcodeGroup.INSN_MULTIANEWARRAY:
getCodeVisitor().visitMultiANewArrayInsn( attrs.getValue( "desc"), Integer.parseInt( attrs.getValue( "dims")));
break;
default:
throw new RuntimeException( "Invalid element: "+element+" at "+match);
}
}
}
/**
* MaxRule
*/
private final class MaxRule extends Rule {
public MaxRule( String path) {
super( path);
}
public final void begin( String element, Attributes attrs) {
int maxStack = Integer.parseInt( attrs.getValue( "maxStack"));
int maxLocals = Integer.parseInt( attrs.getValue( "maxLocals"));
getCodeVisitor().visitMaxs( maxStack, maxLocals);
}
}
/**
* Opcode
*/
private final static class Opcode {
public int opcode;
public int type;
public Opcode( int opcode, int type) {
this.opcode = opcode;
this.type = type;
}
}
}
asm-1.5.3/src/org/objectweb/asm/xml/Processor.java 100644 0 0 72514 10112601423 17172 0 ustar 0 0 /***
* ASM XML Adapter
* Copyright (c) 2004, Eugene Kuleshov
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.objectweb.asm.xml;
import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
import javax.xml.transform.Source;
import javax.xml.transform.Templates;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.sax.SAXResult;
import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.sax.SAXTransformerFactory;
import javax.xml.transform.sax.TransformerHandler;
import javax.xml.transform.stream.StreamSource;
import org.objectweb.asm.ClassReader;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.ext.LexicalHandler;
import org.xml.sax.helpers.AttributesImpl;
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.helpers.XMLReaderFactory;
/**
* Processor is a command line tool that can be used for
* bytecode waving directed by XSL transformation.
*
*
*
* @author Eugene Kuleshov
*/
public class Processor {
public static final int BYTECODE = 1;
public static final int MULTI_XML = 2;
public static final int SINGLE_XML = 3;
private static final String SINGLE_XML_NAME = "classes.xml";
private int inRepresentation;
private int outRepresentation;
private InputStream input = null;
private OutputStream output = null;
private Source xslt = null;
private boolean computeMax;
private int n = 0;
public Processor( int inRepresenation, int outRepresentation,
InputStream input, OutputStream output, Source xslt) {
this.inRepresentation = inRepresenation;
this.outRepresentation = outRepresentation;
this.input = input;
this.output = output;
this.xslt = xslt;
this.computeMax = true;
}
public int process() throws TransformerException, IOException, SAXException {
ZipInputStream zis = new ZipInputStream( input);
final ZipOutputStream zos = new ZipOutputStream( output);
final OutputStreamWriter osw = new OutputStreamWriter( zos);
Thread.currentThread().setContextClassLoader( getClass().getClassLoader());
TransformerFactory tf = TransformerFactory.newInstance();
if( !tf.getFeature( SAXSource.FEATURE) || !tf.getFeature( SAXResult.FEATURE)) return 0;
SAXTransformerFactory saxtf = ( SAXTransformerFactory) tf;
Templates templates = null;
if( xslt!=null) {
templates = saxtf.newTemplates( xslt);
}
// configuring outHandlerFactory ///////////////////////////////////////////////////////
EntryElement entryElement = getEntryElement( zos);
ContentHandler outDocHandler = null;
switch( outRepresentation) {
case BYTECODE:
outDocHandler = new OutputSlicingHandler( new ASMContentHandlerFactory( zos, computeMax), entryElement, false);
break;
case MULTI_XML:
outDocHandler = new OutputSlicingHandler( new SAXWriterFactory( osw, true), entryElement, true);
break;
case SINGLE_XML:
ZipEntry outputEntry = new ZipEntry( SINGLE_XML_NAME);
zos.putNextEntry( outputEntry);
outDocHandler = new SAXWriter( osw, false);
break;
}
// configuring inputDocHandlerFactory /////////////////////////////////////////////////
ContentHandler inDocHandler = null;
if( templates==null) {
inDocHandler = outDocHandler;
} else {
inDocHandler = new InputSlicingHandler( "class", outDocHandler,
new TransformerHandlerFactory( saxtf, templates, outDocHandler));
}
ContentHandlerFactory inDocHandlerFactory = new SubdocumentHandlerFactory( inDocHandler);
if( inDocHandler!=null && inRepresentation!=SINGLE_XML) {
inDocHandler.startDocument();
inDocHandler.startElement( "", "classes", "classes", new AttributesImpl());
}
int n = 0;
ZipEntry ze = null;
while(( ze = zis.getNextEntry())!=null) {
if( isClassEntry( ze)) {
processEntry( zis, ze, inDocHandlerFactory);
} else {
OutputStream os = entryElement.openEntry( getName( ze));
copyEntry( zis, os);
entryElement.closeEntry();
}
n++;
update( ze.getName());
}
if( inDocHandler!=null && inRepresentation!=SINGLE_XML) {
inDocHandler.endElement( "", "classes", "classes");
inDocHandler.endDocument();
}
if( outRepresentation==SINGLE_XML) {
zos.closeEntry();
}
zos.flush();
zos.close();
return n;
}
private void copyEntry( InputStream is, OutputStream os) throws IOException {
if( outRepresentation==SINGLE_XML) return;
byte[] buff = new byte[2048];
int n;
while ((n = is.read(buff)) != -1) {
os.write(buff, 0, n);
}
}
private boolean isClassEntry( ZipEntry ze) {
String name = ze.getName();
return inRepresentation==SINGLE_XML && name.equals( SINGLE_XML_NAME) ||
name.endsWith( ".class") || name.endsWith( ".class.xml");
}
private void processEntry( final ZipInputStream zis, ZipEntry ze, ContentHandlerFactory handlerFactory) {
ContentHandler handler = handlerFactory.createContentHandler();
try {
/*
if( CODE2ASM.equals( command)) {
// read bytecode and process it with TraceClassVisitor
ClassReader cr = new ClassReader( readEntry( zis, ze));
cr.accept( new TraceClassVisitor( null, new PrintWriter( os)), false);
*/
boolean singleInputDocument = inRepresentation==SINGLE_XML;
if( inRepresentation==BYTECODE) { // read bytecode and process it with handler
ClassReader cr = new ClassReader( readEntry( zis, ze));
cr.accept( new SAXClassAdapter( handler, singleInputDocument), false);
} else { // read XML and process it with handler
XMLReader reader = XMLReaderFactory.createXMLReader();
reader.setContentHandler( handler);
reader.parse( new InputSource( singleInputDocument ?
( InputStream) new ProtectedInputStream( zis) : new ByteArrayInputStream( readEntry( zis, ze))));
}
} catch( Exception ex) {
update( ze.getName());
update( ex);
}
}
private EntryElement getEntryElement( ZipOutputStream zos) {
if( outRepresentation==SINGLE_XML) {
return new SingleDocElement( zos);
} else {
return new ZipEntryElement( zos);
}
}
/*
private ContentHandlerFactory getHandlerFactory( OutputStream os, SAXTransformerFactory saxtf, Templates templates) {
ContentHandlerFactory factory = null;
if( templates==null) {
if( outputRepresentation==BYTECODE) {
// factory used to write bytecode
factory = new ASMContentHandlerFactory( os, computeMax);
} else {
// factory used to write XML
factory = new SAXWriterFactory( os, true);
}
} else {
if( outputRepresentation==BYTECODE) {
// factory used to transform and then write bytecode
factory = new ASMTransformerHandlerFactory( saxtf, templates, os, computeMax);
} else {
// factory used to transform and then write XML
factory = new TransformerHandlerFactory( saxtf, templates, os, outputRepresentation==SINGLE_XML);
}
}
return factory;
}
*/
private String getName( ZipEntry ze) {
String name = ze.getName();
if( isClassEntry( ze)) {
if( inRepresentation!=BYTECODE && outRepresentation==BYTECODE) {
name = name.substring( 0, name.length()-4); // .class.xml to .class
} else if( inRepresentation==BYTECODE && outRepresentation!=BYTECODE) {
name = name.concat( ".xml"); // .class to .class.xml
}
// } else if( CODE2ASM.equals( command)) {
// name = name.substring( 0, name.length()-6).concat( ".asm");
}
return name;
}
private byte[] readEntry(ZipInputStream zis, ZipEntry ze) throws IOException {
long size = ze.getSize();
if (size > -1) {
byte[] buff = new byte[(int) size];
// int k = 0;
// while(( n = zis.read(buff, k, buff.length-k)) > 0) {
// k += n;
// }
zis.read(buff);
return buff;
} else {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] buff = new byte[4096];
int n;
while(( n = zis.read(buff)) != -1) {
bos.write(buff, 0, n);
}
return bos.toByteArray();
}
}
/*
* (non-Javadoc)
* @see java.util.Observer#update(java.util.Observable, java.lang.Object)
*/
public void update( Object arg) {
if( arg instanceof Throwable) {
(( Throwable) arg).printStackTrace();
} else {
if(( n % 100)==0) {
System.err.println( n+" "+arg);
}
}
n++;
}
public static void main( String[] args) throws Exception {
if( args.length<2) {
showUsage();
return;
}
int inRepresentation = getRepresentation( args[ 0]);
int outRepresentation = getRepresentation( args[ 1]);
InputStream is = null;
OutputStream os = null;
Source xslt = null;
// boolean computeMax = true;
for( int i = 2; i
*
*
*
*
* jd.xslt
* jd.xml.xslt.trax.TransformerFactoryImpl
*
*
*
* Saxon
* net.sf.saxon.TransformerFactoryImpl
*
*
*
* Caucho
* com.caucho.xsl.Xsl
*
*
*
* Xalan interpeter
* org.apache.xalan.processor.TransformerFactory
*
*
* Xalan xsltc
* org.apache.xalan.xsltc.trax.TransformerFactoryImpl
*