Modifier and Type | Field and Description |
---|---|
private java.util.Stack<java.util.ArrayList<java.lang.String>> |
compilationScopes
Record the type of what is on top of the bytecode stack (i.e.
|
AALOAD, AASTORE, ACC_ABSTRACT, ACC_ANNOTATION, ACC_BRIDGE, ACC_DEPRECATED, ACC_ENUM, ACC_FINAL, ACC_INTERFACE, ACC_MANDATED, ACC_NATIVE, ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC, ACC_STATIC, ACC_STRICT, ACC_SUPER, ACC_SYNCHRONIZED, ACC_SYNTHETIC, ACC_TRANSIENT, ACC_VARARGS, ACC_VOLATILE, ACONST_NULL, ALOAD, ANEWARRAY, ARETURN, ARRAYLENGTH, ASM4, ASM5, ASTORE, ATHROW, BALOAD, BASTORE, BIPUSH, CALOAD, CASTORE, CHECKCAST, D2F, D2I, D2L, DADD, DALOAD, DASTORE, DCMPG, DCMPL, DCONST_0, DCONST_1, DDIV, DLOAD, DMUL, DNEG, DOUBLE, DREM, DRETURN, DSTORE, DSUB, DUP, DUP_X1, DUP_X2, DUP2, DUP2_X1, DUP2_X2, F_APPEND, F_CHOP, F_FULL, F_NEW, F_SAME, F_SAME1, F2D, F2I, F2L, FADD, FALOAD, FASTORE, FCMPG, FCMPL, FCONST_0, FCONST_1, FCONST_2, FDIV, FLOAD, FLOAT, FMUL, FNEG, FREM, FRETURN, FSTORE, FSUB, GETFIELD, GETSTATIC, GOTO, H_GETFIELD, H_GETSTATIC, H_INVOKEINTERFACE, H_INVOKESPECIAL, H_INVOKESTATIC, H_INVOKEVIRTUAL, H_NEWINVOKESPECIAL, H_PUTFIELD, H_PUTSTATIC, I2B, I2C, I2D, I2F, I2L, I2S, IADD, IALOAD, IAND, IASTORE, ICONST_0, ICONST_1, ICONST_2, ICONST_3, ICONST_4, ICONST_5, ICONST_M1, IDIV, IF_ACMPEQ, IF_ACMPNE, IF_ICMPEQ, IF_ICMPGE, IF_ICMPGT, IF_ICMPLE, IF_ICMPLT, IF_ICMPNE, IFEQ, IFGE, IFGT, IFLE, IFLT, IFNE, IFNONNULL, IFNULL, IINC, ILOAD, IMUL, INEG, INSTANCEOF, INTEGER, INVOKEDYNAMIC, INVOKEINTERFACE, INVOKESPECIAL, INVOKESTATIC, INVOKEVIRTUAL, IOR, IREM, IRETURN, ISHL, ISHR, ISTORE, ISUB, IUSHR, IXOR, JSR, L2D, L2F, L2I, LADD, LALOAD, LAND, LASTORE, LCMP, LCONST_0, LCONST_1, LDC, LDIV, LLOAD, LMUL, LNEG, LONG, LOOKUPSWITCH, LOR, LREM, LRETURN, LSHL, LSHR, LSTORE, LSUB, LUSHR, LXOR, MONITORENTER, MONITOREXIT, MULTIANEWARRAY, NEW, NEWARRAY, NOP, NULL, POP, POP2, PUTFIELD, PUTSTATIC, RET, RETURN, SALOAD, SASTORE, SIPUSH, SWAP, T_BOOLEAN, T_BYTE, T_CHAR, T_DOUBLE, T_FLOAT, T_INT, T_LONG, T_SHORT, TABLESWITCH, TOP, UNINITIALIZED_THIS, V1_1, V1_2, V1_3, V1_4, V1_5, V1_6, V1_7, V1_8
Constructor and Description |
---|
CodeFlow() |
Modifier and Type | Method and Description |
---|---|
static boolean |
areBoxingCompatible(java.lang.String desc1,
java.lang.String desc2)
Determine if boxing/unboxing can get from one type to the other.
|
static java.lang.String |
createSignatureDescriptor(java.lang.reflect.Constructor<?> ctor)
Create the JVM signature descriptor for a constructor.
|
static java.lang.String |
createSignatureDescriptor(java.lang.reflect.Method method)
Create the JVM signature descriptor for a method.
|
void |
enterCompilationScope()
Enter a new compilation scope, usually due to nested expression evaluation.
|
void |
exitCompilationScope()
Exit a compilation scope, usually after a nested expression has been evaluated.
|
static void |
insertBoxIfNecessary(MethodVisitor mv,
char ch)
Determine the appropriate boxing instruction for a specific type (if it needs
boxing) and insert the instruction into the supplied visitor.
|
static void |
insertBoxIfNecessary(MethodVisitor mv,
java.lang.String descriptor)
Determine the appropriate boxing instruction for a specific type (if it needs
boxing) and insert the instruction into the supplied visitor.
|
static void |
insertCheckCast(MethodVisitor mv,
java.lang.String descriptor)
Insert the appropriate CHECKCAST instruction for the supplied descriptor.
|
static void |
insertUnboxInsns(MethodVisitor mv,
char ch,
boolean isObject)
Insert any necessary cast and value call to convert from a boxed type to a
primitive value
|
static boolean |
isBooleanCompatible(java.lang.String descriptor) |
static boolean |
isPrimitive(java.lang.String descriptor) |
static boolean |
isPrimitiveArray(java.lang.String descriptor) |
static boolean |
isPrimitiveOrUnboxableSupportedNumber(java.lang.String descriptor)
Determine if the supplied descriptor is for a supported number.
|
static boolean |
isPrimitiveOrUnboxableSupportedNumberOrBoolean(java.lang.String descriptor)
Determine if the supplied descriptor is for a supported number type or boolean.
|
java.lang.String |
lastDescriptor() |
void |
loadTarget(MethodVisitor mv)
Push the byte code to load the target (i.e.
|
void |
pushDescriptor(java.lang.String descriptor)
Record the descriptor for the most recently evaluated expression element.
|
static java.lang.String |
toDescriptor(java.lang.Class<?> type)
Deduce the descriptor for a type.
|
static java.lang.String |
toDescriptorFromObject(java.lang.Object value)
Determine the descriptor for an object instance (or
null ). |
private static java.lang.String[] |
toDescriptors(java.lang.Class<?>[] types) |
static java.lang.String |
toJVMDescriptor(java.lang.Class<?> clazz)
Determine the JVM descriptor for a specified class.
|
static java.lang.String[] |
toParamDescriptors(java.lang.reflect.Constructor<?> ctor)
Create an array of descriptors representing the parameter types for the supplied
constructor.
|
static java.lang.String[] |
toParamDescriptors(java.lang.reflect.Method method)
Create an array of descriptors representing the parameter types for the supplied
method.
|
static char |
toPrimitiveTargetDesc(java.lang.String descriptor) |
void |
unboxBooleanIfNecessary(MethodVisitor mv)
If the codeflow shows the last expression evaluated to java.lang.Boolean then
insert the necessary instructions to unbox that to a boolean primitive.
|
private final java.util.Stack<java.util.ArrayList<java.lang.String>> compilationScopes
public void loadTarget(MethodVisitor mv)
mv
- the visitor into which the load instruction should be insertedpublic void pushDescriptor(java.lang.String descriptor)
descriptor
- type descriptor for most recently evaluated elementpublic void enterCompilationScope()
public void exitCompilationScope()
public java.lang.String lastDescriptor()
public void unboxBooleanIfNecessary(MethodVisitor mv)
mv
- the visitor into which new instructions should be insertedpublic static void insertUnboxInsns(MethodVisitor mv, char ch, boolean isObject)
mv
- the method visitor into which instructions should be insertedch
- the primitive type desired as outputisObject
- indicates whether the type on the stack is being thought of
as Object (and so requires a cast)public static java.lang.String createSignatureDescriptor(java.lang.reflect.Method method)
method
- the methodpublic static java.lang.String createSignatureDescriptor(java.lang.reflect.Constructor<?> ctor)
ctor
- the constructorpublic static java.lang.String toJVMDescriptor(java.lang.Class<?> clazz)
clazz
- a classpublic static java.lang.String toDescriptorFromObject(java.lang.Object value)
null
).value
- an object (possibly null
)null
value)public static boolean isBooleanCompatible(java.lang.String descriptor)
descriptor
- type descriptortrue
if the descriptor is for a boolean primitive or boolean reference typepublic static boolean isPrimitive(java.lang.String descriptor)
descriptor
- type descriptortrue
if the descriptor is for a primitive typepublic static boolean isPrimitiveArray(java.lang.String descriptor)
descriptor
- the descriptor for a possible primitive arraytrue
if the descriptor is for a primitive array (e.g. "[[I")public static boolean areBoxingCompatible(java.lang.String desc1, java.lang.String desc2)
true
if it is possible to get (via boxing) from one descriptor to the otherpublic static boolean isPrimitiveOrUnboxableSupportedNumberOrBoolean(java.lang.String descriptor)
descriptor
- the descriptor for a typetrue
if the descriptor is for a supported numeric type or booleanpublic static boolean isPrimitiveOrUnboxableSupportedNumber(java.lang.String descriptor)
descriptor
- the descriptor for a typetrue
if the descriptor is for a supported numeric typepublic static char toPrimitiveTargetDesc(java.lang.String descriptor)
descriptor
- a descriptor for a type that should have a primitive representationpublic static void insertCheckCast(MethodVisitor mv, java.lang.String descriptor)
mv
- the target visitor into which the instruction should be inserteddescriptor
- the descriptor of the type to cast topublic static void insertBoxIfNecessary(MethodVisitor mv, java.lang.String descriptor)
mv
- the target visitor for the new instructionsdescriptor
- the descriptor of a type that may or may not need boxingpublic static void insertBoxIfNecessary(MethodVisitor mv, char ch)
mv
- the target visitor for the new instructionsch
- the descriptor of the type that might need boxingpublic static java.lang.String toDescriptor(java.lang.Class<?> type)
type
- the type (may be primitive) for which to determine the descriptorpublic static java.lang.String[] toParamDescriptors(java.lang.reflect.Method method)
method
- a Methodpublic static java.lang.String[] toParamDescriptors(java.lang.reflect.Constructor<?> ctor)
ctor
- a Constructorprivate static java.lang.String[] toDescriptors(java.lang.Class<?>[] types)