org.logicalcobwebs.cglib.core
Class CodeEmitter

java.lang.Object
  extended by org.logicalcobwebs.asm.CodeAdapter
      extended by org.logicalcobwebs.cglib.core.RemappingCodeVisitor
          extended by org.logicalcobwebs.cglib.core.CodeEmitter
All Implemented Interfaces:
CodeVisitor

public class CodeEmitter
extends RemappingCodeVisitor

Author:
Juozas Baliuka, Chris Nokleberg

Nested Class Summary
private static class CodeEmitter.State
           
 
Field Summary
static int ADD
           
static int AND
           
private static Signature BOOLEAN_VALUE
           
private  ClassEmitter ce
           
private static Signature CHAR_VALUE
           
private static Signature CSTRUCT_NULL
           
private static Signature CSTRUCT_STRING
           
static int DIV
           
private static Signature DOUBLE_VALUE
           
static int EQ
           
private static Signature FLOAT_VALUE
           
static int GE
           
static int GT
           
private static Signature INT_VALUE
           
static int LE
           
private static Signature LONG_VALUE
           
static int LT
           
static int MUL
           
static int NE
           
static int NEG
           
static int OR
           
static int REM
           
private  CodeEmitter.State state
           
static int SUB
           
static int USHR
           
static int XOR
           
 
Fields inherited from class org.logicalcobwebs.asm.CodeAdapter
cv
 
Constructor Summary
CodeEmitter(ClassEmitter ce, CodeVisitor cv, int access, Signature sig, Type[] exceptionTypes)
           
CodeEmitter(CodeEmitter wrap)
           
 
Method Summary
 void aaload()
           
 void aaload(int index)
           
 void aastore()
           
 void aconst_null()
           
 void array_load(Type type)
           
 void array_store(Type type)
           
 void arraylength()
           
 void athrow()
           
 Block begin_block()
           
 void box(Type type)
          If the argument is a primitive class, replaces the primitive value on the top of the stack with the wrapped (Object) equivalent.
 void cast_numeric(Type from, Type to)
          Casts from one primitive numeric type to another
 void catch_exception(Block block, Type exception)
           
 void checkcast_this()
           
 void checkcast(Type type)
           
 void create_arg_array()
          Allocates and fills an Object[] array with the arguments to the current method.
 void define_attribute(Attribute attrs)
           
 void dup_x1()
           
 void dup_x2()
           
 void dup()
           
 void dup2_x1()
           
 void dup2_x2()
           
 void dup2()
           
(package private)  void emit_field(int opcode, Type ctype, java.lang.String name, Type ftype)
           
private  void emit_invoke(int opcode, Type type, Signature sig)
           
private  void emit_type(int opcode, Type type)
           
 void end_method()
           
 ClassEmitter getClassEmitter()
           
 void getfield(java.lang.String name)
           
 void getfield(Type owner, java.lang.String name, Type type)
           
 Type getReturnType()
           
 Signature getSignature()
           
 void getstatic(Type owner, java.lang.String name, Type type)
           
 void goTo(Label label)
           
 void if_cmp(Type type, int mode, Label label)
           
 void if_icmp(int mode, Label label)
           
 void if_jump(int mode, Label label)
           
 void ifnonnull(Label label)
           
 void ifnull(Label label)
           
 void iinc(Local local, int amount)
           
 void instance_of_this()
           
 void instance_of(Type type)
           
 void invoke_constructor_this()
           
 void invoke_constructor_this(Signature sig)
           
 void invoke_constructor(Type type)
           
 void invoke_constructor(Type type, Signature sig)
           
 void invoke_interface(Type owner, Signature sig)
           
 void invoke_static_this(Signature sig)
           
 void invoke_static(Type owner, Signature sig)
           
 void invoke_virtual_this(Signature sig)
           
 void invoke_virtual(Type owner, Signature sig)
           
 void invoke(java.lang.reflect.Method method)
           
private static boolean isSorted(int[] keys)
           
 boolean isStaticHook()
           
 void load_arg(int index)
          Pushes the specified argument of the current method onto the stack.
 void load_args()
          Pushes all of the arguments of the current method onto the stack.
 void load_args(int fromArg, int count)
           
 void load_local(Local local)
           
private  void load_local(Type t, int pos)
           
 void load_this()
           
 Label make_label()
           
 Local make_local()
           
 Local make_local(Type type)
           
(package private)  Label mark()
           
 void mark(Label label)
           
 void math(int op, Type type)
           
 void monitorenter()
           
 void monitorexit()
           
 void new_instance_this()
           
 void new_instance(Type type)
           
 void newarray()
           
 void newarray(Type type)
           
 void not()
          Toggles the integer on the top of the stack from 1 to 0 or vice versa
 void pop()
           
 void pop2()
           
 void process_switch(int[] keys, ProcessSwitchCallback callback)
           
 void process_switch(int[] keys, ProcessSwitchCallback callback, boolean useTable)
           
 void push(boolean value)
           
 void push(double value)
           
 void push(float value)
           
 void push(int i)
           
 void push(long value)
           
 void push(java.lang.String value)
           
 void putfield(java.lang.String name)
           
 void putfield(Type owner, java.lang.String name, Type type)
           
 void putstatic(Type owner, java.lang.String name, Type type)
           
 void return_value()
           
private  int skipArgs(int numArgs)
           
 void store_local(Local local)
           
private  void store_local(Type t, int pos)
           
 void super_getfield(java.lang.String name, Type type)
           
 void super_getstatic(java.lang.String name, Type type)
           
 void super_invoke_constructor()
           
 void super_invoke_constructor(Signature sig)
           
 void super_invoke()
           
 void super_invoke(Signature sig)
           
 void super_putfield(java.lang.String name, Type type)
           
 void super_putstatic(java.lang.String name, Type type)
           
 void swap()
           
 void swap(Type prev, Type type)
           
 void throw_exception(Type type, java.lang.String msg)
           
 void unbox_or_zero(Type type)
          Unboxes the object on the top of the stack.
 void unbox(Type type)
          If the argument is a primitive class, replaces the object on the top of the stack with the unwrapped (primitive) equivalent.
 void visitMaxs(int maxStack, int maxLocals)
          Visits the maximum stack size and the maximum number of local variables of the method.
 void zero_or_null(Type type)
          Pushes a zero onto the stack if the argument is a primitive class, or a null otherwise.
 
Methods inherited from class org.logicalcobwebs.cglib.core.RemappingCodeVisitor
nextLocal, visitIincInsn, visitLocalVariable, visitVarInsn
 
Methods inherited from class org.logicalcobwebs.asm.CodeAdapter
visitAttribute, visitFieldInsn, visitInsn, visitIntInsn, visitJumpInsn, visitLabel, visitLdcInsn, visitLineNumber, visitLookupSwitchInsn, visitMethodInsn, visitMultiANewArrayInsn, visitTableSwitchInsn, visitTryCatchBlock, visitTypeInsn
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BOOLEAN_VALUE

private static final Signature BOOLEAN_VALUE

CHAR_VALUE

private static final Signature CHAR_VALUE

LONG_VALUE

private static final Signature LONG_VALUE

DOUBLE_VALUE

private static final Signature DOUBLE_VALUE

FLOAT_VALUE

private static final Signature FLOAT_VALUE

INT_VALUE

private static final Signature INT_VALUE

CSTRUCT_NULL

private static final Signature CSTRUCT_NULL

CSTRUCT_STRING

private static final Signature CSTRUCT_STRING

ADD

public static final int ADD
See Also:
Constant Field Values

MUL

public static final int MUL
See Also:
Constant Field Values

XOR

public static final int XOR
See Also:
Constant Field Values

USHR

public static final int USHR
See Also:
Constant Field Values

SUB

public static final int SUB
See Also:
Constant Field Values

DIV

public static final int DIV
See Also:
Constant Field Values

NEG

public static final int NEG
See Also:
Constant Field Values

REM

public static final int REM
See Also:
Constant Field Values

AND

public static final int AND
See Also:
Constant Field Values

OR

public static final int OR
See Also:
Constant Field Values

GT

public static final int GT
See Also:
Constant Field Values

LT

public static final int LT
See Also:
Constant Field Values

GE

public static final int GE
See Also:
Constant Field Values

LE

public static final int LE
See Also:
Constant Field Values

NE

public static final int NE
See Also:
Constant Field Values

EQ

public static final int EQ
See Also:
Constant Field Values

ce

private ClassEmitter ce

state

private CodeEmitter.State state
Constructor Detail

CodeEmitter

CodeEmitter(ClassEmitter ce,
            CodeVisitor cv,
            int access,
            Signature sig,
            Type[] exceptionTypes)

CodeEmitter

public CodeEmitter(CodeEmitter wrap)
Method Detail

isStaticHook

public boolean isStaticHook()

getSignature

public Signature getSignature()

getReturnType

public Type getReturnType()

getClassEmitter

public ClassEmitter getClassEmitter()

end_method

public void end_method()

begin_block

public Block begin_block()

catch_exception

public void catch_exception(Block block,
                            Type exception)

goTo

public void goTo(Label label)

ifnull

public void ifnull(Label label)

ifnonnull

public void ifnonnull(Label label)

if_jump

public void if_jump(int mode,
                    Label label)

if_icmp

public void if_icmp(int mode,
                    Label label)

if_cmp

public void if_cmp(Type type,
                   int mode,
                   Label label)

pop

public void pop()

pop2

public void pop2()

dup

public void dup()

dup2

public void dup2()

dup_x1

public void dup_x1()

dup_x2

public void dup_x2()

dup2_x1

public void dup2_x1()

dup2_x2

public void dup2_x2()

swap

public void swap()

aconst_null

public void aconst_null()

swap

public void swap(Type prev,
                 Type type)

monitorenter

public void monitorenter()

monitorexit

public void monitorexit()

math

public void math(int op,
                 Type type)

array_load

public void array_load(Type type)

array_store

public void array_store(Type type)

cast_numeric

public void cast_numeric(Type from,
                         Type to)
Casts from one primitive numeric type to another


push

public void push(int i)

push

public void push(long value)

push

public void push(float value)

push

public void push(double value)

push

public void push(java.lang.String value)

newarray

public void newarray()

newarray

public void newarray(Type type)

arraylength

public void arraylength()

load_this

public void load_this()

load_args

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


load_arg

public 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

public void load_args(int fromArg,
                      int count)

skipArgs

private int skipArgs(int numArgs)

load_local

private void load_local(Type t,
                        int pos)

store_local

private void store_local(Type t,
                         int pos)

iinc

public void iinc(Local local,
                 int amount)

store_local

public void store_local(Local local)

load_local

public void load_local(Local local)

return_value

public void return_value()

getfield

public void getfield(java.lang.String name)

putfield

public void putfield(java.lang.String name)

super_getfield

public void super_getfield(java.lang.String name,
                           Type type)

super_putfield

public void super_putfield(java.lang.String name,
                           Type type)

super_getstatic

public void super_getstatic(java.lang.String name,
                            Type type)

super_putstatic

public void super_putstatic(java.lang.String name,
                            Type type)

getfield

public void getfield(Type owner,
                     java.lang.String name,
                     Type type)

putfield

public void putfield(Type owner,
                     java.lang.String name,
                     Type type)

getstatic

public void getstatic(Type owner,
                      java.lang.String name,
                      Type type)

putstatic

public void putstatic(Type owner,
                      java.lang.String name,
                      Type type)

emit_field

void emit_field(int opcode,
                Type ctype,
                java.lang.String name,
                Type ftype)

super_invoke

public void super_invoke()

super_invoke

public void super_invoke(Signature sig)

invoke_constructor

public void invoke_constructor(Type type)

super_invoke_constructor

public void super_invoke_constructor()

invoke_constructor_this

public void invoke_constructor_this()

emit_invoke

private void emit_invoke(int opcode,
                         Type type,
                         Signature sig)

invoke_interface

public void invoke_interface(Type owner,
                             Signature sig)

invoke_virtual

public void invoke_virtual(Type owner,
                           Signature sig)

invoke_static

public void invoke_static(Type owner,
                          Signature sig)

invoke_virtual_this

public void invoke_virtual_this(Signature sig)

invoke_static_this

public void invoke_static_this(Signature sig)

invoke_constructor

public void invoke_constructor(Type type,
                               Signature sig)

invoke_constructor_this

public void invoke_constructor_this(Signature sig)

super_invoke_constructor

public void super_invoke_constructor(Signature sig)

new_instance_this

public void new_instance_this()

new_instance

public void new_instance(Type type)

emit_type

private void emit_type(int opcode,
                       Type type)

aaload

public void aaload(int index)

aaload

public void aaload()

aastore

public void aastore()

athrow

public void athrow()

make_label

public Label make_label()

make_local

public Local make_local()

make_local

public Local make_local(Type type)

checkcast_this

public void checkcast_this()

checkcast

public void checkcast(Type type)

instance_of

public void instance_of(Type type)

instance_of_this

public void instance_of_this()

process_switch

public void process_switch(int[] keys,
                           ProcessSwitchCallback callback)

process_switch

public void process_switch(int[] keys,
                           ProcessSwitchCallback callback,
                           boolean useTable)

isSorted

private static boolean isSorted(int[] keys)

mark

public void mark(Label label)

mark

Label mark()

push

public void push(boolean value)

not

public void not()
Toggles the integer on the top of the stack from 1 to 0 or vice versa


throw_exception

public void throw_exception(Type type,
                            java.lang.String msg)

box

public void box(Type type)
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:
type - the class indicating the current type of the top stack value

unbox

public void unbox(Type type)
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:
type - the class indicating the desired type of the top stack value

create_arg_array

public 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.


zero_or_null

public void zero_or_null(Type type)
Pushes a zero onto the stack if the argument is a primitive class, or a null otherwise.


unbox_or_zero

public void unbox_or_zero(Type type)
Unboxes the object on the top of the stack. If the object is null, the unboxed primitive value becomes zero.


visitMaxs

public void visitMaxs(int maxStack,
                      int maxLocals)
Description copied from interface: CodeVisitor
Visits the maximum stack size and the maximum number of local variables of the method.

Specified by:
visitMaxs in interface CodeVisitor
Overrides:
visitMaxs in class RemappingCodeVisitor
Parameters:
maxStack - maximum stack size of the method.
maxLocals - maximum number of local variables for the method.

invoke

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

define_attribute

public void define_attribute(Attribute attrs)