net.sf.cglib
Class CodeGenerator

java.lang.Object
  |
  +--net.sf.cglib.CodeGenerator
All Implemented Interfaces:
org.apache.bcel.Constants, Constants

public abstract class CodeGenerator
extends java.lang.Object
implements Constants

Abstract base class for code generators

Author:
baliuka

Inner Class Summary
protected static interface CodeGenerator.ProcessArrayCallback
           
 
Field Summary
protected  boolean debug
           
 
Fields inherited from interface net.sf.cglib.Constants
TYPE_OBJECT, TYPES_EMPTY, TYPES_OBJECT, TYPES_OBJECT_ARRAY, TYPES_STRING, TYPES_THROWABLE
 
Fields inherited from interface org.apache.bcel.Constants
AALOAD, AASTORE, ACC_ABSTRACT, ACC_FINAL, ACC_INTERFACE, ACC_NATIVE, ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC, ACC_SYNCHRONIZED, ACC_STATIC, ACC_STRICT, ACC_SUPER, ACC_TRANSIENT, ACC_VOLATILE, ACCESS_NAMES, ACONST_NULL, ALOAD, ALOAD_0, ALOAD_1, ALOAD_2, ALOAD_3, ANEWARRAY, ANEWARRAY_QUICK, ARETURN, ARRAYLENGTH, ASTORE, ASTORE_0, ASTORE_1, ASTORE_2, ASTORE_3, ATHROW, ATTR_CODE, ATTR_CONSTANT_VALUE, ATTR_DEPRECATED, ATTR_EXCEPTIONS, ATTR_INNER_CLASSES, ATTR_LINE_NUMBER_TABLE, ATTR_LOCAL_VARIABLE_TABLE, ATTR_PMG, ATTR_SIGNATURE, ATTR_SYNTHETIC, ATTR_SOURCE_FILE, ATTR_STACK_MAP, ATTR_UNKNOWN, ATTRIBUTE_NAMES, BALOAD, BASTORE, BIPUSH, BREAKPOINT, CALOAD, CASTORE, CHECKCAST, CHECKCAST_QUICK, CONSTANT_Class, CONSTANT_Double, CONSTANT_Fieldref, CONSTANT_Float, CONSTANT_Integer, CONSTANT_InterfaceMethodref, CONSTANT_Long, CONSTANT_Methodref, CONSTANT_NameAndType, CONSTANT_NAMES, CONSTANT_String, CONSTANT_Utf8, CONSTRUCTOR_NAME, CONSUME_STACK, D2F, D2I, D2L, DADD, DALOAD, DASTORE, DCMPG, DCMPL, DCONST_0, DCONST_1, DDIV, DLOAD, DLOAD_0, DLOAD_1, DLOAD_2, DLOAD_3, DMUL, DNEG, DREM, DRETURN, DSTORE, DSTORE_0, DSTORE_1, DSTORE_2, DSTORE_3, DSUB, DUP, DUP_X1, DUP_X2, DUP2, DUP2_X1, DUP2_X2, F2D, F2I, F2L, FADD, FALOAD, FASTORE, FCMPG, FCMPL, FCONST_0, FCONST_1, FCONST_2, FDIV, FLOAD, FLOAD_0, FLOAD_1, FLOAD_2, FLOAD_3, FMUL, FNEG, FREM, FRETURN, FSTORE, FSTORE_0, FSTORE_1, FSTORE_2, FSTORE_3, FSUB, GETFIELD, GETFIELD_QUICK, GETFIELD_QUICK_W, GETFIELD2_QUICK, GETSTATIC, GETSTATIC_QUICK, GETSTATIC2_QUICK, GOTO, GOTO_W, 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, ILLEGAL_OPCODE, ILLEGAL_TYPE, ILOAD, ILOAD_0, ILOAD_1, ILOAD_2, ILOAD_3, IMPDEP1, IMPDEP2, IMUL, INEG, INSTANCEOF, INSTANCEOF_QUICK, INT2BYTE, INT2CHAR, INT2SHORT, INTERFACES_IMPLEMENTED_BY_ARRAYS, INVOKEINTERFACE, INVOKEINTERFACE_QUICK, INVOKENONVIRTUAL, INVOKENONVIRTUAL_QUICK, INVOKESPECIAL, INVOKESTATIC, INVOKESTATIC_QUICK, INVOKESUPER_QUICK, INVOKEVIRTUAL, INVOKEVIRTUAL_QUICK, INVOKEVIRTUAL_QUICK_W, INVOKEVIRTUALOBJECT_QUICK, IOR, IREM, IRETURN, ISHL, ISHR, ISTORE, ISTORE_0, ISTORE_1, ISTORE_2, ISTORE_3, ISUB, ITEM_Bogus, ITEM_Double, ITEM_Float, ITEM_InitObject, ITEM_Integer, ITEM_Long, ITEM_NAMES, ITEM_NewObject, ITEM_Null, ITEM_Object, IUSHR, IXOR, JSR, JSR_W, KNOWN_ATTRIBUTES, L2D, L2F, L2I, LADD, LALOAD, LAND, LASTORE, LCMP, LCONST_0, LCONST_1, LDC, LDC_QUICK, LDC_W, LDC_W_QUICK, LDC2_W, LDC2_W_QUICK, LDIV, LLOAD, LLOAD_0, LLOAD_1, LLOAD_2, LLOAD_3, LMUL, LNEG, LOOKUPSWITCH, LOR, LREM, LRETURN, LSHL, LSHR, LSTORE, LSTORE_0, LSTORE_1, LSTORE_2, LSTORE_3, LSUB, LUSHR, LXOR, MAJOR, MAJOR_1_1, MAJOR_1_2, MAJOR_1_3, MAX_ACC_FLAG, MAX_BYTE, MAX_CODE_SIZE, MAX_CP_ENTRIES, MAX_SHORT, MINOR, MINOR_1_1, MINOR_1_2, MINOR_1_3, MONITORENTER, MONITOREXIT, MULTIANEWARRAY, MULTIANEWARRAY_QUICK, NEW, NEW_QUICK, NEWARRAY, NO_OF_OPERANDS, NOP, OPCODE_NAMES, POP, POP2, PRODUCE_STACK, PUSH, PUTFIELD, PUTFIELD_QUICK, PUTFIELD_QUICK_W, PUTFIELD2_QUICK, PUTSTATIC, PUTSTATIC_QUICK, PUTSTATIC2_QUICK, RESERVED, RET, RETURN, SALOAD, SASTORE, SHORT_TYPE_NAMES, SIPUSH, STATIC_INITIALIZER_NAME, SWAP, SWITCH, T_ADDRESS, T_ARRAY, T_BYTE, T_BOOLEAN, T_CHAR, T_DOUBLE, T_FLOAT, T_INT, T_LONG, T_OBJECT, T_REFERENCE, T_SHORT, T_UNKNOWN, T_VOID, TABLESWITCH, TYPE_NAMES, TYPE_OF_OPERANDS, UNDEFINED, UNPREDICTABLE, WIDE
 
Constructor Summary
protected CodeGenerator(java.lang.String className, java.lang.Class superclass, java.lang.ClassLoader loader)
           
 
Method Summary
protected  void aaload()
           
protected  void aaload(int index)
           
protected  void aastore()
           
protected  void aconst_null()
           
protected  void array_load(java.lang.Class clazz)
           
protected  void array_store(java.lang.Class clazz)
           
protected  void arraylength()
           
protected  void athrow()
           
protected  void athrow(java.lang.String label)
           
protected  void begin_constructor()
           
protected  void begin_constructor(java.lang.Class[] parameterTypes)
           
protected  void begin_constructor(java.lang.reflect.Constructor constructor)
           
protected  int begin_handler()
           
protected  void begin_method(int modifiers, java.lang.Class returnType, java.lang.String methodName, java.lang.Class[] parameterTypes, java.lang.Class[] exceptionTypes)
           
protected  void begin_method(java.lang.reflect.Method method)
           
protected  void begin_method(java.lang.reflect.Method method, int modifiers)
           
protected  void begin_static()
           
protected  void box(java.lang.Class clazz)
          If the argument is a primitive class, replaces the primitive value on the top of the stack with the wrapped (Object) equivalent.
protected  void checkcast_this()
           
protected  void checkcast(java.lang.Class clazz)
           
protected  void create_arg_array()
          Allocates and fills an Object[] array with the arguments to the current method.
protected  void dcmpg()
           
protected  void declare_field(int modifiers, java.lang.Class typeClass, java.lang.String name)
           
protected  void declare_interface(java.lang.Class iface)
           
protected  void declare_interfaces(java.lang.Class[] interfaces)
           
 java.lang.Class define()
           
protected  void dup_x1()
           
protected  void dup_x2()
           
protected  void dup()
           
protected  void dup(java.lang.String label)
           
protected  void dup2()
           
protected  void end_constructor()
           
protected  void end_handler()
           
protected  void end_method()
           
protected  void end_static()
           
protected  void fcmpg()
           
protected abstract  void generate()
          method used to generate code
protected  void generateNullConstructor()
           
protected  java.lang.String getClassName()
           
protected  int getDefaultModifiers(java.lang.reflect.Method method)
           
protected  void getfield(java.lang.reflect.Field field)
           
protected  void getfield(java.lang.String name)
           
protected static java.lang.String getMethodSignature(java.lang.reflect.Method method)
           
protected  void getstatic(java.lang.String name)
           
protected  java.lang.Class getSuperclass()
           
static org.apache.bcel.generic.Type getType(java.lang.Class cl)
           
protected  void goTo(java.lang.String label)
           
protected  void handle_exception(int ref, java.lang.Class exceptionType)
           
protected  void iadd()
           
protected  void if_icmpeq(java.lang.String label)
           
protected  void if_icmplt(java.lang.String label)
           
protected  void if_icmpne(java.lang.String label)
           
protected  void ifeq(java.lang.String label)
           
protected  void ifge(java.lang.String label)
           
protected  void ifgt(java.lang.String label)
           
protected  void ifle(java.lang.String label)
           
protected  void iflt(java.lang.String label)
           
protected  void ifne(java.lang.String label)
           
protected  void ifnonnull(java.lang.String label)
           
protected  void ifnull(java.lang.String label)
           
protected  void iinc(java.lang.String local, int amount)
           
protected  void imul()
           
protected  void instance_of_this()
           
protected  void instance_of(java.lang.Class clazz)
           
protected  void invoke_constructor_this()
           
protected  void invoke_constructor_this(java.lang.Class[] parameterTypes)
           
protected  void invoke_constructor(java.lang.Class type)
           
protected  void invoke_constructor(java.lang.Class type, java.lang.Class[] parameterTypes)
           
protected  void invoke_static_this(java.lang.String methodName, java.lang.Class returnType, java.lang.Class[] parameterTypes)
           
protected  void invoke_virtual_this(java.lang.String methodName, java.lang.Class returnType, java.lang.Class[] parameterTypes)
           
protected  void invoke_virtual(java.lang.reflect.Method method)
           
protected  void invoke(java.lang.reflect.Method method)
           
protected  void ixor()
           
protected  void jsr(java.lang.String label)
           
protected  void l2i()
           
protected  void lcmp()
           
protected  void load_arg(int index)
          Pushes the specified argument of the current method onto the stack.
protected  void load_args()
          Pushes all of the arguments of the current method onto the stack.
protected  void load_args(int fromArg, int count)
           
protected  void load_class_this()
           
protected  void load_class(java.lang.Class clazz)
           
protected  void load_local(java.lang.String name)
           
protected  void load_this()
           
protected  void local_type(java.lang.String name, java.lang.Class type)
           
protected  void lushr()
           
protected  void lxor()
           
protected  void new_instance_this()
           
protected  void new_instance(java.lang.Class clazz)
           
protected  void newarray()
           
protected  void newarray(java.lang.Class clazz)
           
protected  java.lang.String newLabel()
           
protected  java.lang.String newLocal()
           
protected  void nop()
           
protected  void nop(java.lang.String label)
           
protected  void not_equals(java.lang.Class clazz, java.lang.String notEquals)
          Branches to the specified label if the top two items on the stack are not equal.
protected  void nullcmp(java.lang.String oneNull, java.lang.String bothNull)
          If both objects on the top of the stack are non-null, does nothing.
protected  void pop()
           
protected  void pop(java.lang.String label)
           
protected  void pop2()
           
protected  void process_array(java.lang.Class type, CodeGenerator.ProcessArrayCallback callback)
          Process an array on the stack.
protected  void process_arrays(java.lang.Class clazz, CodeGenerator.ProcessArrayCallback callback)
          Process two arrays on the stack in parallel.
protected  void push_object(java.lang.Object obj)
           
protected  void push(double value)
           
protected  void push(float value)
           
protected  void push(int i)
           
protected  void push(long value)
           
protected  void push(java.lang.Object[] array)
           
protected  void push(java.lang.String value)
           
protected  void putfield(java.lang.reflect.Field field)
           
protected  void putfield(java.lang.String name)
           
protected  void putstatic(java.lang.String name)
           
protected  void return_value()
           
static void setDebugLocation(java.lang.String debugLocation)
           
protected  void store_local(java.lang.String name)
           
protected  void super_getfield(java.lang.String name)
           
protected  void super_invoke_constructor()
           
protected  void super_invoke_constructor(java.lang.Class[] parameterTypes)
           
protected  void super_invoke_constructor(java.lang.reflect.Constructor constructor)
           
protected  void super_invoke()
           
protected  void super_invoke(java.lang.reflect.Method method)
           
protected  void super_putfield(java.lang.String name)
           
protected  void swap()
           
protected  void swap(java.lang.String label)
           
protected  void throwException(java.lang.Class type, java.lang.String msg)
           
protected  void unbox_or_zero(java.lang.Class type)
          Unboxes the object on the top of the stack.
protected  void unbox(java.lang.Class clazz)
          If the argument is a primitive class, replaces the object on the top of the stack with the unwrapped (primitive) equivalent.
protected  void zero_or_null(java.lang.Class type)
          Pushes a zero onto the stack if the argument is a primitive class, or a null otherwise.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

debug

protected boolean debug
Constructor Detail

CodeGenerator

protected CodeGenerator(java.lang.String className,
                        java.lang.Class superclass,
                        java.lang.ClassLoader loader)
Method Detail

getClassName

protected java.lang.String getClassName()

getSuperclass

protected java.lang.Class getSuperclass()

setDebugLocation

public static void setDebugLocation(java.lang.String debugLocation)

generate

protected abstract void generate()
                          throws java.lang.Exception
method used to generate code

define

public java.lang.Class define()

declare_interfaces

protected void declare_interfaces(java.lang.Class[] interfaces)

declare_interface

protected void declare_interface(java.lang.Class iface)

declare_field

protected void declare_field(int modifiers,
                             java.lang.Class typeClass,
                             java.lang.String name)

begin_method

protected void begin_method(int modifiers,
                            java.lang.Class returnType,
                            java.lang.String methodName,
                            java.lang.Class[] parameterTypes,
                            java.lang.Class[] exceptionTypes)

getDefaultModifiers

protected int getDefaultModifiers(java.lang.reflect.Method method)

begin_method

protected void begin_method(java.lang.reflect.Method method)

begin_method

protected void begin_method(java.lang.reflect.Method method,
                            int modifiers)

begin_constructor

protected void begin_constructor(java.lang.reflect.Constructor constructor)

begin_constructor

protected void begin_constructor()

begin_constructor

protected void begin_constructor(java.lang.Class[] parameterTypes)

begin_static

protected void begin_static()

end_constructor

protected void end_constructor()

end_static

protected void end_static()

end_method

protected void end_method()

create_arg_array

protected void create_arg_array()
Allocates and fills an Object[] array with the arguments to the current method. Primitive values are inserted as their boxed (Object) equivalents.

begin_handler

protected int begin_handler()

end_handler

protected void end_handler()

handle_exception

protected void handle_exception(int ref,
                                java.lang.Class exceptionType)

ifeq

protected void ifeq(java.lang.String label)

ifne

protected void ifne(java.lang.String label)

iflt

protected void iflt(java.lang.String label)

ifge

protected void ifge(java.lang.String label)

ifgt

protected void ifgt(java.lang.String label)

ifle

protected void ifle(java.lang.String label)

goTo

protected void goTo(java.lang.String label)

jsr

protected void jsr(java.lang.String label)

ifnull

protected void ifnull(java.lang.String label)

ifnonnull

protected void ifnonnull(java.lang.String label)

if_icmplt

protected void if_icmplt(java.lang.String label)

if_icmpne

protected void if_icmpne(java.lang.String label)

if_icmpeq

protected void if_icmpeq(java.lang.String label)

imul

protected void imul()

iadd

protected void iadd()

lushr

protected void lushr()

lxor

protected void lxor()

ixor

protected void ixor()

l2i

protected void l2i()

dcmpg

protected void dcmpg()

fcmpg

protected void fcmpg()

lcmp

protected void lcmp()

nop

protected void nop()

nop

protected void nop(java.lang.String label)

aconst_null

protected void aconst_null()

push

protected void push(int i)

push

protected void push(long value)

push

protected void push(float value)

push

protected void push(double value)

push

protected void push(java.lang.String value)

push

protected void push(java.lang.Object[] array)

push_object

protected void push_object(java.lang.Object obj)

newarray

protected void newarray()

newarray

protected void newarray(java.lang.Class clazz)

arraylength

protected void arraylength()

array_load

protected void array_load(java.lang.Class clazz)

array_store

protected void array_store(java.lang.Class clazz)

load_this

protected void load_this()

load_class_this

protected void load_class_this()

load_class

protected void load_class(java.lang.Class clazz)

load_args

protected void load_args()
Pushes all of the arguments of the current method onto the stack.

load_arg

protected void load_arg(int index)
Pushes the specified argument of the current method onto the stack.
Parameters:
index - the zero-based index into the argument list

load_args

protected void load_args(int fromArg,
                         int count)

iinc

protected void iinc(java.lang.String local,
                    int amount)

local_type

protected void local_type(java.lang.String name,
                          java.lang.Class type)

store_local

protected void store_local(java.lang.String name)

load_local

protected void load_local(java.lang.String name)

pop

protected void pop()

pop2

protected void pop2()

dup

protected void dup()

dup2

protected void dup2()

dup_x1

protected void dup_x1()

dup_x2

protected void dup_x2()

swap

protected void swap()

pop

protected void pop(java.lang.String label)

dup

protected void dup(java.lang.String label)

swap

protected void swap(java.lang.String label)

return_value

protected void return_value()

getfield

protected void getfield(java.lang.String name)

putfield

protected void putfield(java.lang.String name)

getstatic

protected void getstatic(java.lang.String name)

putstatic

protected void putstatic(java.lang.String name)

super_getfield

protected void super_getfield(java.lang.String name)
                       throws java.lang.NoSuchFieldException

super_putfield

protected void super_putfield(java.lang.String name)
                       throws java.lang.NoSuchFieldException

getfield

protected void getfield(java.lang.reflect.Field field)

putfield

protected void putfield(java.lang.reflect.Field field)

invoke

protected void invoke(java.lang.reflect.Method method)

super_invoke

protected void super_invoke(java.lang.reflect.Method method)

invoke_virtual_this

protected void invoke_virtual_this(java.lang.String methodName,
                                   java.lang.Class returnType,
                                   java.lang.Class[] parameterTypes)

invoke_static_this

protected void invoke_static_this(java.lang.String methodName,
                                  java.lang.Class returnType,
                                  java.lang.Class[] parameterTypes)

super_invoke

protected void super_invoke()

invoke_constructor

protected void invoke_constructor(java.lang.Class type)

invoke_constructor

protected void invoke_constructor(java.lang.Class type,
                                  java.lang.Class[] parameterTypes)

getType

public static org.apache.bcel.generic.Type getType(java.lang.Class cl)

getMethodSignature

protected static java.lang.String getMethodSignature(java.lang.reflect.Method method)

invoke_virtual

protected void invoke_virtual(java.lang.reflect.Method method)

super_invoke_constructor

protected void super_invoke_constructor(java.lang.reflect.Constructor constructor)

super_invoke_constructor

protected void super_invoke_constructor()

super_invoke_constructor

protected void super_invoke_constructor(java.lang.Class[] parameterTypes)

invoke_constructor_this

protected void invoke_constructor_this()

invoke_constructor_this

protected void invoke_constructor_this(java.lang.Class[] parameterTypes)

new_instance_this

protected void new_instance_this()

new_instance

protected void new_instance(java.lang.Class clazz)

aaload

protected void aaload(int index)

aaload

protected void aaload()

aastore

protected void aastore()

athrow

protected void athrow()

athrow

protected void athrow(java.lang.String label)

newLabel

protected java.lang.String newLabel()

newLocal

protected java.lang.String newLocal()

zero_or_null

protected void zero_or_null(java.lang.Class type)
Pushes a zero onto the stack if the argument is a primitive class, or a null otherwise.

unbox_or_zero

protected void unbox_or_zero(java.lang.Class type)
Unboxes the object on the top of the stack. If the object is null, the unboxed primitive value becomes zero.

box

protected void box(java.lang.Class clazz)
If the argument is a primitive class, replaces the primitive value on the top of the stack with the wrapped (Object) equivalent. For example, char -> Character. If the class is Void, a null is pushed onto the stack instead.
Parameters:
clazz - the class indicating the current type of the top stack value

unbox

protected void unbox(java.lang.Class clazz)
If the argument is a primitive class, replaces the object on the top of the stack with the unwrapped (primitive) equivalent. For example, Character -> char.
Parameters:
clazz - the class indicating the desired type of the top stack value
Returns:
true if the value was unboxed

checkcast_this

protected void checkcast_this()

checkcast

protected void checkcast(java.lang.Class clazz)

instance_of

protected void instance_of(java.lang.Class clazz)

instance_of_this

protected void instance_of_this()

generateNullConstructor

protected void generateNullConstructor()

process_array

protected void process_array(java.lang.Class type,
                             CodeGenerator.ProcessArrayCallback callback)
Process an array on the stack. Assumes the top item on the stack is an array of the specified type. For each element in the array, puts the element on the stack and triggers the callback.
Parameters:
type - the type of the array (type.isArray() must be true)
callback - the callback triggered for each element

process_arrays

protected void process_arrays(java.lang.Class clazz,
                              CodeGenerator.ProcessArrayCallback callback)
Process two arrays on the stack in parallel. Assumes the top two items on the stack are arrays of the specified class. The arrays must be the same length. For each pair of elements in the arrays, puts the pair on the stack and triggers the callback.
Parameters:
clazz - the type of the arrays (clazz.isArray() must be true)
callback - the callback triggered for each pair of elements

not_equals

protected void not_equals(java.lang.Class clazz,
                          java.lang.String notEquals)
Branches to the specified label if the top two items on the stack are not equal. The items must both be of the specified class. Equality is determined by comparing primitive values directly and by invoking the equals method for Objects. Arrays are recursively processed in the same manner.

throwException

protected void throwException(java.lang.Class type,
                              java.lang.String msg)

nullcmp

protected void nullcmp(java.lang.String oneNull,
                       java.lang.String bothNull)
If both objects on the top of the stack are non-null, does nothing. If one is null, or both are null, both are popped off and execution branches to the respective label.
Parameters:
oneNull - label to branch to if only one of the objects is null
bothNull - label to branch to if both of the objects are null


Copyright © 2002-2003 cglib. All Rights Reserved.