C# Class Org.Mozilla.Classfile.ClassFileWriter

ClassFileWriter A ClassFileWriter is used to write a Java class file.
ClassFileWriter A ClassFileWriter is used to write a Java class file. Methods are provided to create fields and methods, and within methods to write Java bytecodes.
ファイルを表示 Open project: hazzik/Rhino.Net Class Usage Examples

Public Methods

Method Description
AcquireLabel ( ) : int
Add ( int theOpCode ) : void

Add the single-byte opcode to the current method.

Add the single-byte opcode to the current method.

Add ( int theOpCode, int theOperand ) : void

Add a single-operand opcode to the current method.

Add a single-operand opcode to the current method.

Add ( int theOpCode, int theOperand1, int theOperand2 ) : void

Add the given two-operand bytecode to the current method.

Add the given two-operand bytecode to the current method.

Add ( int theOpCode, string className ) : void
Add ( int theOpCode, string className, string fieldName, string fieldType ) : void
AddALoad ( int local ) : void

Load object from the given local into stack.

Load object from the given local into stack.

AddAStore ( int local ) : void

Store object from stack top into the given local.

Store object from stack top into the given local.

AddDLoad ( int local ) : void

Load double from the given local into stack.

Load double from the given local into stack.

AddDStore ( int local ) : void

Store double from stack top into the given local.

Store double from stack top into the given local.

AddExceptionHandler ( int startLabel, int endLabel, int handlerLabel, string catchClassName ) : void
AddFLoad ( int local ) : void

Load float from the given local into stack.

Load float from the given local into stack.

AddFStore ( int local ) : void

Store float from stack top into the given local.

Store float from stack top into the given local.

AddField ( string fieldName, string type, short flags ) : void

Add a field to the class.

Add a field to the class.

AddField ( string fieldName, string type, short flags, double value ) : void

Add a field to the class.

Add a field to the class.

AddField ( string fieldName, string type, short flags, int value ) : void

Add a field to the class.

Add a field to the class.

AddField ( string fieldName, string type, short flags, long value ) : void

Add a field to the class.

Add a field to the class.

AddILoad ( int local ) : void

Load integer from the given local into stack.

Load integer from the given local into stack.

AddIStore ( int local ) : void

Store integer from stack top into the given local.

Store integer from stack top into the given local.

AddInterface ( string interfaceName ) : void

Add an interface implemented by this class.

Add an interface implemented by this class. This method may be called multiple times for classes that implement multiple interfaces.

AddInvoke ( int theOpCode, string className, string methodName, string methodType ) : void
AddLLoad ( int local ) : void

Load long from the given local into stack.

Load long from the given local into stack.

AddLStore ( int local ) : void

Store long from stack top into the given local.

Store long from stack top into the given local.

AddLineNumberEntry ( short lineNumber ) : void
AddLoadConstant ( double k ) : void

Generate the load constant bytecode for the given double.

Generate the load constant bytecode for the given double.

AddLoadConstant ( float k ) : void

Generate the load constant bytecode for the given float.

Generate the load constant bytecode for the given float.

AddLoadConstant ( int k ) : void

Generate the load constant bytecode for the given integer.

Generate the load constant bytecode for the given integer.

AddLoadConstant ( long k ) : void

Generate the load constant bytecode for the given long.

Generate the load constant bytecode for the given long.

AddLoadConstant ( string k ) : void

Generate the load constant bytecode for the given string.

Generate the load constant bytecode for the given string.

AddLoadThis ( ) : void

Load "this" into stack.

Load "this" into stack.

AddPush ( bool k ) : void
AddPush ( double k ) : void

Generate code to load the given double on stack.

Generate code to load the given double on stack.

AddPush ( int k ) : void

Generate code to load the given integer on stack.

Generate code to load the given integer on stack.

AddPush ( long k ) : void

Generate code to load the given long on stack.

Generate code to load the given long on stack.

AddPush ( string k ) : void

Generate the code to leave on stack the given string even if the string encoding exeeds the class file limit for single string constant

AddTableSwitch ( int low, int high ) : int
AddVariableDescriptor ( string name, string type, int startPC, int register ) : void

Add Information about java variable to use when generating the local variable table.

Add Information about java variable to use when generating the local variable table.

AdjustStackTop ( int delta ) : void
ClassFileWriter ( string className, string superClassName, string sourceFileName ) : System

Construct a ClassFileWriter for a class.

Construct a ClassFileWriter for a class.

ClassNameToSignature ( string name ) : string

Convert Java class name in dot notation into "Lname-with-dots-replaced-by-slashes;" form suitable for use as JVM type signatures.

Convert Java class name in dot notation into "Lname-with-dots-replaced-by-slashes;" form suitable for use as JVM type signatures.

GetClassName ( ) : string
GetCurrentCodeOffset ( ) : int

Get the current offset into the code of the current method.

Get the current offset into the code of the current method.

GetLabelPC ( int label ) : int
GetStackTop ( ) : short
IsUnderStringSizeLimit ( string k ) : bool

Check if k fits limit on string constant size imposed by class file format.

Check if k fits limit on string constant size imposed by class file format.

MarkHandler ( int theLabel ) : void
MarkLabel ( int label ) : void
MarkLabel ( int label, short stackTop ) : void
MarkTableSwitchCase ( int switchStart, int caseIndex ) : void
MarkTableSwitchCase ( int switchStart, int caseIndex, int stackTop ) : void
MarkTableSwitchDefault ( int switchStart ) : void
SetFlags ( short flags ) : void

Set the class's flags.

Set the class's flags. Flags must be a set of the following flags, bitwise or'd together: ACC_PUBLIC ACC_PRIVATE ACC_PROTECTED ACC_FINAL ACC_ABSTRACT TODO: check that this is the appropriate set

SetStackTop ( short n ) : void
SetTableSwitchJump ( int switchStart, int caseIndex, int jumpTarget ) : void

Set a jump case for a tableswitch instruction.

Set a jump case for a tableswitch instruction. The jump target should be marked as a super block start for stack map generation.

StartMethod ( string methodName, string type, short flags ) : void

Add a method and begin adding code.

Add a method and begin adding code. This method must be called before other methods for adding code, exception tables, etc. can be invoked.

StopMethod ( short maxLocals ) : void

Complete generation of the method.

Complete generation of the method. After this method is called, no more code can be added to the method begun with startMethod.

ToByteArray ( ) : byte[]

Get the class file as array of bytesto the OutputStream.

Get the class file as array of bytesto the OutputStream.

Write ( Stream oStream ) : void

Write the class file to the OutputStream.

Write the class file to the OutputStream.

Private Methods

Method Description
AddLabelFixup ( int label, int fixupSite ) : void
AddReservedCodeSpace ( int size ) : int
AddSuperBlockStart ( int pc ) : void

Add a pc as the start of super block.

Add a pc as the start of super block. A pc is the beginning of a super block if: - pc == 0 - it is the target of a branch instruction - it is the beginning of an exception handler - it is directly after an unconditional jump

AddToCodeBuffer ( int b ) : void
AddToCodeInt16 ( int value ) : void
ArrayTypeToName ( int type ) : char

Convert a newarray operand into an internal type.

Convert a newarray operand into an internal type.

BadStack ( int value ) : void
BytecodeStr ( int code ) : string
ClassDescriptorToInternalName ( string descriptor ) : string

Convert a class descriptor into an internal name.

Convert a class descriptor into an internal name. For example, descriptor Ljava/lang/Object; becomes java/lang/Object.

ClassFileWriter ( ) : System
CreateInitialLocals ( ) : int[]

Compute the initial local variable array for the current method.

Compute the initial local variable array for the current method. Creates an array of the size of the method's max locals, regardless of the number of parameters in the method.

DescriptorToInternalName ( string descriptor ) : string

Convert a non-method type descriptor into an internal type.

Convert a non-method type descriptor into an internal type.

FinalizeSuperBlockStarts ( ) : void

Sort the list of recorded super block starts and remove duplicates.

Sort the list of recorded super block starts and remove duplicates. Also adds exception handling blocks as block starts, since there is no explicit control flow to these. Used for stack map table generation.

FixLabelGotos ( ) : void
GetCharBuffer ( int minimalSize ) : char[]
GetSlashedForm ( string name ) : string
GetWriteSize ( ) : int
OpcodeCount ( int opcode ) : int

Number of operands accompanying the opcode.

Number of operands accompanying the opcode.

OpcodeLength ( int opcode, bool wide ) : int

Size of a bytecode instruction, counting the opcode and its operands.

Size of a bytecode instruction, counting the opcode and its operands. This is different from opcodeCount, since opcodeCount counts logical operands.

PutInt16 ( int value, byte array, int offset ) : int
PutInt32 ( int value, byte array, int offset ) : int
PutInt64 ( long value, byte array, int offset ) : int
SizeOfParameters ( string pString ) : int
StackChange ( int opcode ) : int

The effect on the operand stack of a given opcode.

The effect on the operand stack of a given opcode.

Xop ( int shortOp, int op, int local ) : void

Method Details

AcquireLabel() public method

public AcquireLabel ( ) : int
return int

Add() public method

Add the single-byte opcode to the current method.
Add the single-byte opcode to the current method.
public Add ( int theOpCode ) : void
theOpCode int the opcode of the bytecode
return void

Add() public method

Add a single-operand opcode to the current method.
Add a single-operand opcode to the current method.
public Add ( int theOpCode, int theOperand ) : void
theOpCode int the opcode of the bytecode
theOperand int the operand of the bytecode
return void

Add() public method

Add the given two-operand bytecode to the current method.
Add the given two-operand bytecode to the current method.
public Add ( int theOpCode, int theOperand1, int theOperand2 ) : void
theOpCode int the opcode of the bytecode
theOperand1 int the first operand of the bytecode
theOperand2 int the second operand of the bytecode
return void

Add() public method

public Add ( int theOpCode, string className ) : void
theOpCode int
className string
return void

Add() public method

public Add ( int theOpCode, string className, string fieldName, string fieldType ) : void
theOpCode int
className string
fieldName string
fieldType string
return void

AddALoad() public method

Load object from the given local into stack.
Load object from the given local into stack.
public AddALoad ( int local ) : void
local int number of local register
return void

AddAStore() public method

Store object from stack top into the given local.
Store object from stack top into the given local.
public AddAStore ( int local ) : void
local int number of local register
return void

AddDLoad() public method

Load double from the given local into stack.
Load double from the given local into stack.
public AddDLoad ( int local ) : void
local int number of local register
return void

AddDStore() public method

Store double from stack top into the given local.
Store double from stack top into the given local.
public AddDStore ( int local ) : void
local int number of local register
return void

AddExceptionHandler() public method

public AddExceptionHandler ( int startLabel, int endLabel, int handlerLabel, string catchClassName ) : void
startLabel int
endLabel int
handlerLabel int
catchClassName string
return void

AddFLoad() public method

Load float from the given local into stack.
Load float from the given local into stack.
public AddFLoad ( int local ) : void
local int number of local register
return void

AddFStore() public method

Store float from stack top into the given local.
Store float from stack top into the given local.
public AddFStore ( int local ) : void
local int number of local register
return void

AddField() public method

Add a field to the class.
Add a field to the class.
public AddField ( string fieldName, string type, short flags ) : void
fieldName string the name of the field
type string the type of the field using ...
flags short /// the attributes of the field, such as ACC_PUBLIC, etc. /// bitwise or'd together ///
return void

AddField() public method

Add a field to the class.
Add a field to the class.
public AddField ( string fieldName, string type, short flags, double value ) : void
fieldName string the name of the field
type string the type of the field using ...
flags short /// the attributes of the field, such as ACC_PUBLIC, etc. /// bitwise or'd together ///
value double an initial double value
return void

AddField() public method

Add a field to the class.
Add a field to the class.
public AddField ( string fieldName, string type, short flags, int value ) : void
fieldName string the name of the field
type string the type of the field using ...
flags short /// the attributes of the field, such as ACC_PUBLIC, etc. /// bitwise or'd together ///
value int an initial integral value
return void

AddField() public method

Add a field to the class.
Add a field to the class.
public AddField ( string fieldName, string type, short flags, long value ) : void
fieldName string the name of the field
type string the type of the field using ...
flags short /// the attributes of the field, such as ACC_PUBLIC, etc. /// bitwise or'd together ///
value long an initial long value
return void

AddILoad() public method

Load integer from the given local into stack.
Load integer from the given local into stack.
public AddILoad ( int local ) : void
local int number of local register
return void

AddIStore() public method

Store integer from stack top into the given local.
Store integer from stack top into the given local.
public AddIStore ( int local ) : void
local int number of local register
return void

AddInterface() public method

Add an interface implemented by this class.
Add an interface implemented by this class. This method may be called multiple times for classes that implement multiple interfaces.
public AddInterface ( string interfaceName ) : void
interfaceName string /// a name of an interface implemented /// by the class being written, including full package /// qualification. ///
return void

AddInvoke() public method

public AddInvoke ( int theOpCode, string className, string methodName, string methodType ) : void
theOpCode int
className string
methodName string
methodType string
return void

AddLLoad() public method

Load long from the given local into stack.
Load long from the given local into stack.
public AddLLoad ( int local ) : void
local int number of local register
return void

AddLStore() public method

Store long from stack top into the given local.
Store long from stack top into the given local.
public AddLStore ( int local ) : void
local int number of local register
return void

AddLineNumberEntry() public method

public AddLineNumberEntry ( short lineNumber ) : void
lineNumber short
return void

AddLoadConstant() public method

Generate the load constant bytecode for the given double.
Generate the load constant bytecode for the given double.
public AddLoadConstant ( double k ) : void
k double the constant
return void

AddLoadConstant() public method

Generate the load constant bytecode for the given float.
Generate the load constant bytecode for the given float.
public AddLoadConstant ( float k ) : void
k float the constant
return void

AddLoadConstant() public method

Generate the load constant bytecode for the given integer.
Generate the load constant bytecode for the given integer.
public AddLoadConstant ( int k ) : void
k int the constant
return void

AddLoadConstant() public method

Generate the load constant bytecode for the given long.
Generate the load constant bytecode for the given long.
public AddLoadConstant ( long k ) : void
k long the constant
return void

AddLoadConstant() public method

Generate the load constant bytecode for the given string.
Generate the load constant bytecode for the given string.
public AddLoadConstant ( string k ) : void
k string the constant
return void

AddLoadThis() public method

Load "this" into stack.
Load "this" into stack.
public AddLoadThis ( ) : void
return void

AddPush() public method

public AddPush ( bool k ) : void
k bool
return void

AddPush() public method

Generate code to load the given double on stack.
Generate code to load the given double on stack.
public AddPush ( double k ) : void
k double the constant
return void

AddPush() public method

Generate code to load the given integer on stack.
Generate code to load the given integer on stack.
public AddPush ( int k ) : void
k int the constant
return void

AddPush() public method

Generate code to load the given long on stack.
Generate code to load the given long on stack.
public AddPush ( long k ) : void
k long the constant
return void

AddPush() public method

Generate the code to leave on stack the given string even if the string encoding exeeds the class file limit for single string constant
public AddPush ( string k ) : void
k string the constant
return void

AddTableSwitch() public method

public AddTableSwitch ( int low, int high ) : int
low int
high int
return int

AddVariableDescriptor() public method

Add Information about java variable to use when generating the local variable table.
Add Information about java variable to use when generating the local variable table.
public AddVariableDescriptor ( string name, string type, int startPC, int register ) : void
name string variable name.
type string variable type as bytecode descriptor string.
startPC int /// the starting bytecode PC where this variable is live, /// or -1 if it does not have a Java register. ///
register int /// the Java register number of variable /// or -1 if it does not have a Java register. ///
return void

AdjustStackTop() public method

public AdjustStackTop ( int delta ) : void
delta int
return void

ClassFileWriter() public method

Construct a ClassFileWriter for a class.
Construct a ClassFileWriter for a class.
public ClassFileWriter ( string className, string superClassName, string sourceFileName ) : System
className string /// the name of the class to write, including /// full package qualification. ///
superClassName string /// the name of the superclass of the class /// to write, including full package qualification. ///
sourceFileName string /// the name of the source file to use for /// producing debug information, or null if debug information /// is not desired ///
return System

ClassNameToSignature() public static method

Convert Java class name in dot notation into "Lname-with-dots-replaced-by-slashes;" form suitable for use as JVM type signatures.
Convert Java class name in dot notation into "Lname-with-dots-replaced-by-slashes;" form suitable for use as JVM type signatures.
public static ClassNameToSignature ( string name ) : string
name string
return string

GetClassName() public method

public GetClassName ( ) : string
return string

GetCurrentCodeOffset() public method

Get the current offset into the code of the current method.
Get the current offset into the code of the current method.
public GetCurrentCodeOffset ( ) : int
return int

GetLabelPC() public method

public GetLabelPC ( int label ) : int
label int
return int

GetStackTop() public method

public GetStackTop ( ) : short
return short

IsUnderStringSizeLimit() public method

Check if k fits limit on string constant size imposed by class file format.
Check if k fits limit on string constant size imposed by class file format.
public IsUnderStringSizeLimit ( string k ) : bool
k string the string constant
return bool

MarkHandler() public method

public MarkHandler ( int theLabel ) : void
theLabel int
return void

MarkLabel() public method

public MarkLabel ( int label ) : void
label int
return void

MarkLabel() public method

public MarkLabel ( int label, short stackTop ) : void
label int
stackTop short
return void

MarkTableSwitchCase() public method

public MarkTableSwitchCase ( int switchStart, int caseIndex ) : void
switchStart int
caseIndex int
return void

MarkTableSwitchCase() public method

public MarkTableSwitchCase ( int switchStart, int caseIndex, int stackTop ) : void
switchStart int
caseIndex int
stackTop int
return void

MarkTableSwitchDefault() public method

public MarkTableSwitchDefault ( int switchStart ) : void
switchStart int
return void

SetFlags() public method

Set the class's flags.
Set the class's flags. Flags must be a set of the following flags, bitwise or'd together: ACC_PUBLIC ACC_PRIVATE ACC_PROTECTED ACC_FINAL ACC_ABSTRACT TODO: check that this is the appropriate set
public SetFlags ( short flags ) : void
flags short the set of class flags to set
return void

SetStackTop() public method

public SetStackTop ( short n ) : void
n short
return void

SetTableSwitchJump() public method

Set a jump case for a tableswitch instruction.
Set a jump case for a tableswitch instruction. The jump target should be marked as a super block start for stack map generation.
public SetTableSwitchJump ( int switchStart, int caseIndex, int jumpTarget ) : void
switchStart int
caseIndex int
jumpTarget int
return void

StartMethod() public method

Add a method and begin adding code.
Add a method and begin adding code. This method must be called before other methods for adding code, exception tables, etc. can be invoked.
public StartMethod ( string methodName, string type, short flags ) : void
methodName string the name of the method
type string a string representing the type
flags short /// the attributes of the field, such as ACC_PUBLIC, etc. /// bitwise or'd together ///
return void

StopMethod() public method

Complete generation of the method.
Complete generation of the method. After this method is called, no more code can be added to the method begun with startMethod.
public StopMethod ( short maxLocals ) : void
maxLocals short /// the maximum number of local variable slots /// (a.k.a. Java registers) used by the method ///
return void

ToByteArray() public method

Get the class file as array of bytesto the OutputStream.
Get the class file as array of bytesto the OutputStream.
public ToByteArray ( ) : byte[]
return byte[]

Write() public method

Write the class file to the OutputStream.
Write the class file to the OutputStream.
if writing to the stream produces an exception
public Write ( Stream oStream ) : void
oStream Stream the stream to write to
return void