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

Variable Index

 o access_flags
 o arg_names
 o arg_types
 o attribute_vec
 o class_name
 o cp
 o exception_vec
 o il
 o method_name
 o return_type
 o slot
 o throws_vec
 o variable_vec

Constructor Index

 o MethodGen(int, ClassGenType, ClassGenType[], String[], String, String, InstructionList, ConstantPoolGen)
Declare method.

Method Index

 o addAttribute(Attribute)
Add an attribute to this method.
 o addException(String)
Add an exception thrown by this method.
 o addExceptionAttribute()
Add `Exceptions' attribute if there are any exceptions thrown by this method.
 o addExceptionHandler(InstructionHandle, InstructionHandle, InstructionHandle, int)
Add an exception handler, i.e.
 o addExceptionHandler(InstructionHandle, InstructionHandle, InstructionHandle, String)
Add an exception handler, i.e.
 o addLocalVariable(String, ClassGenType, InstructionHandle, InstructionHandle)
Add a local variable to this method.
 o checkTarget(Vector, InstructionHandle)
Checks an instruction handle whether it contains a NOP instruction.
 o getAccessFlags()
 o getArgTypes()
 o getAttributes()
 o getClassName()
 o getInstructionList()
 o getLocalVariables()
 o getLocalVariableTable()
Convert `LocalVariableGen's to `LocalVariable's
 o getMethod(int)
Get method object.
 o getMethodName()
 o getReturnType()
 o lookupLocal(String)
 o removeNOPs()
Remove all NOPs from the instruction list (if possible) and update every object refering to them, i.e.
 o setAccessFlags(short)
 o setArgTypes(ClassGenType[])
 o setMethodName(String)
 o setReturnType(ClassGenType)

Variables

 o method_name
 private String method_name
 o class_name
 private String class_name
 o return_type
 private ClassGenType return_type
 o arg_types
 private ClassGenType arg_types[]
 o arg_names
 private String arg_names[]
 o access_flags
 private int access_flags
 o slot
 private int slot
 o il
 private InstructionList il
 o cp
 private ConstantPoolGen cp
 o variable_vec
 private Vector variable_vec
 o attribute_vec
 private Vector attribute_vec
 o exception_vec
 private Vector exception_vec
 o throws_vec
 private Vector throws_vec

Constructors

 o 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

Methods

 o lookupLocal
 public LocalVariableGen lookupLocal(String name)
 o 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
 o 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)
 o 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)
 o 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
 o 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
 o addExceptionAttribute
 private final void addExceptionAttribute()
Add `Exceptions' attribute if there are any exceptions thrown by this method.

See Also:
ExceptionTable
 o getInstructionList
 public final InstructionList getInstructionList()
Returns:
InstructionList (geter for il )
 o getAttributes
 public final Attribute[] getAttributes()
Returns:
all attributes of this method.
 o getLocalVariableTable
 private final LocalVariable[] getLocalVariableTable()
Convert `LocalVariableGen's to `LocalVariable's

 o getLocalVariables
 public final LocalVariableGen[] getLocalVariables()
 o 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
 o 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
 o 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.

 o setMethodName
 public void setMethodName(String method_name)
 o getMethodName
 public String getMethodName()
 o getClassName
 public String getClassName()
 o setReturnType
 public void setReturnType(ClassGenType return_type)
 o getReturnType
 public ClassGenType getReturnType()
 o setArgTypes
 public void setArgTypes(ClassGenType arg_types[])
 o getArgTypes
 public ClassGenType[] getArgTypes()
 o setAccessFlags
 public void setAccessFlags(short access_flags)
 o getAccessFlags
 public int getAccessFlags()

All Packages  Class Hierarchy  This Package  Previous  Next  Index