All Packages Class Hierarchy This Package Previous Next Index
Class espresso.classfile.classgen.MethodGen
java.lang.Object
|
+----espresso.classfile.classgen.MethodGen
- public final class MethodGen
- extends Object
- implements Constants
Template class for building up a method. This is done by defining exception
handlers, adding thrown exceptions, local variables and attributes, whereas
the `LocalVariableTable' attribute will be set automatically for the code.
While generating code it may be necessary to insert NOP operations. You can
use the `removeNOPs' method to get rid off them.
The resulting method object can be obtained via the `getMethod()' method.
- See Also:
- Instruction, Method
-
access_flags
-
-
arg_names
-
-
arg_types
-
-
attribute_vec
-
-
class_name
-
-
cp
-
-
exception_vec
-
-
il
-
-
method_name
-
-
return_type
-
-
slot
-
-
throws_vec
-
-
variable_vec
-
-
MethodGen(int, ClassGenType, ClassGenType[], String[], String, String, InstructionList, ConstantPoolGen)
- Declare method.
-
addAttribute(Attribute)
- Add an attribute to this method.
-
addException(String)
- Add an exception thrown by this method.
-
addExceptionAttribute()
- Add `Exceptions' attribute if there are any exceptions thrown by this method.
-
addExceptionHandler(InstructionHandle, InstructionHandle, InstructionHandle, int)
- Add an exception handler, i.e.
-
addExceptionHandler(InstructionHandle, InstructionHandle, InstructionHandle, String)
- Add an exception handler, i.e.
-
addLocalVariable(String, ClassGenType, InstructionHandle, InstructionHandle)
- Add a local variable to this method.
-
checkTarget(Vector, InstructionHandle)
- Checks an instruction handle whether it contains a NOP instruction.
-
getAccessFlags()
-
-
getArgTypes()
-
-
getAttributes()
-
-
getClassName()
-
-
getInstructionList()
-
-
getLocalVariables()
-
-
getLocalVariableTable()
- Convert `LocalVariableGen's to `LocalVariable's
-
getMethod(int)
- Get method object.
-
getMethodName()
-
-
getReturnType()
-
-
lookupLocal(String)
-
-
removeNOPs()
- Remove all NOPs from the instruction list (if possible) and update every
object refering to them, i.e.
-
setAccessFlags(short)
-
-
setArgTypes(ClassGenType[])
-
-
setMethodName(String)
-
-
setReturnType(ClassGenType)
-
method_name
private String method_name
class_name
private String class_name
return_type
private ClassGenType return_type
arg_types
private ClassGenType arg_types[]
arg_names
private String arg_names[]
access_flags
private int access_flags
slot
private int slot
il
private InstructionList il
cp
private ConstantPoolGen cp
variable_vec
private Vector variable_vec
attribute_vec
private Vector attribute_vec
exception_vec
private Vector exception_vec
throws_vec
private Vector throws_vec
MethodGen
public MethodGen(int access_flags,
ClassGenType return_type,
ClassGenType arg_types[],
String arg_names[],
String method_name,
String class_name,
InstructionList il,
ConstantPoolGen cp)
- Declare method. If the method is non-static the constructor automatically
declares a local variable `$this' in slot 0.
- Parameters:
- access_flags - access qualifiers
- return_type - method type
- arg_types - argument types
- arg_names - argument names (may be null)
- method_name - name of method
- class_name - class name containing this method
- il - instruction list associated with this method, may be empty initially
- cp - constant pool
lookupLocal
public LocalVariableGen lookupLocal(String name)
addLocalVariable
public LocalVariableGen addLocalVariable(String name,
ClassGenType type,
InstructionHandle start,
InstructionHandle end)
- Add a local variable to this method.
- Parameters:
- name - variable name
- type - variable type
- start - from where the variable is valid, if this is null,
it is valid from the start
- end - until where the variable is valid, if this is null,
it is valid to the end
- Returns:
- new local variable
- See Also:
- LocalVariable
addExceptionHandler
public void addExceptionHandler(InstructionHandle start_pc,
InstructionHandle end_pc,
InstructionHandle handler_pc,
int catch_type)
- Add an exception handler, i.e. specify region where a handler is active and an
instruction where the actual handling is done.
- Parameters:
- start_pc - Start of region
- end_pc - End of region
- handler_pc - Where handling is done
- catch_type - which exception is handled (reference to class in constant pool)
addExceptionHandler
public void addExceptionHandler(InstructionHandle start_pc,
InstructionHandle end_pc,
InstructionHandle handler_pc,
String catch_type)
- Add an exception handler, i.e. specify region where a handler is active and an
instruction where the actual handling is done.
- Parameters:
- start_pc - Start of region
- end_pc - End of region
- handler_pc - Where handling is done
- catch_type - which exception is handled (fully qualified class name)
addException
public void addException(String class_name)
- Add an exception thrown by this method. This is actually an attribute of the
method and thus is being added to the attribute list.
- Parameters:
- class_name - name of exception
addAttribute
public void addAttribute(Attribute attr)
- Add an attribute to this method. Currently, the JVM knows about the `Code' and
`Exceptions' attribute, others will be ignored.
- Parameters:
- attr - Attribute to be added
addExceptionAttribute
private final void addExceptionAttribute()
- Add `Exceptions' attribute if there are any exceptions thrown by this method.
- See Also:
- ExceptionTable
getInstructionList
public final InstructionList getInstructionList()
- Returns:
- InstructionList (geter for il )
getAttributes
public final Attribute[] getAttributes()
- Returns:
- all attributes of this method.
getLocalVariableTable
private final LocalVariable[] getLocalVariableTable()
- Convert `LocalVariableGen's to `LocalVariable's
getLocalVariables
public final LocalVariableGen[] getLocalVariables()
getMethod
public Method getMethod(int max_stack)
- Get method object.
The maximum stack size has to be supplied by the user, since it is hard
to determine statically with just the byte code at hands. I.e. you'd have to
identify loops and such.
The stack size can be computed much easier on the fly when creating the code.
- Parameters:
- max_stack - maximum stack size of this method
- il - instructions (byte code)
- cp - constant pool
- Returns:
- method object
checkTarget
private static final InstructionHandle checkTarget(Vector nop_vec,
InstructionHandle target)
- Checks an instruction handle whether it contains a NOP instruction. If so,
update the instruction and add the NOP instruction to a given vector, if
it is not already in there. If we reach the end of the list without finding
a non-NOP instruction a pointer to the last NOP is returned. (Santiago)
- Parameters:
- nop_vec - Vector containing NOP instruction handles
- target - Target instruction handle being referenced
removeNOPs
public final void removeNOPs()
- Remove all NOPs from the instruction list (if possible) and update every
object refering to them, i.e. branch instructions, local variables and
exception handlers.
setMethodName
public void setMethodName(String method_name)
getMethodName
public String getMethodName()
getClassName
public String getClassName()
setReturnType
public void setReturnType(ClassGenType return_type)
getReturnType
public ClassGenType getReturnType()
setArgTypes
public void setArgTypes(ClassGenType arg_types[])
getArgTypes
public ClassGenType[] getArgTypes()
setAccessFlags
public void setAccessFlags(short access_flags)
getAccessFlags
public int getAccessFlags()
All Packages Class Hierarchy This Package Previous Next Index