C# Class Monobjc.Generators.CodeGenerator

Base class for .NET code generator.
ファイルを表示 Open project: Monobjc/monobjc

Protected Methods

Method Description
CodeGenerator ( DynamicAssembly assembly, bool is64Bits )

Initializes a new instance of the CodeGenerator class.

CreateLocalBuilderForInvocationResult ( ILGenerator generator, Type returnType, Type nativeReturnType ) : LocalBuilder

Creates a local builder to store the result of the invocation.

CreateLocalVariableForByRefParameters ( ILGenerator generator, ParameterInfo parameterInfos ) : ByRefParameter[]

Emit local variable for each by-ref parameters. These variables will hold the result until the marshalling occurs.

EmitLoadArgument ( ILGenerator generator, int index ) : void
EmitManagedToNativeMarshallingForByRefParameters ( ILGenerator generator, Type nativeParameterTypes, ByRefParameter byRefLocalVariables ) : void

Emit the code needed to marshal back the local variables to by-ref parameters.

EmitNativeToManagedMarshallingForByRefParameters ( ILGenerator generator, Type nativeParameterTypes, ByRefParameter byRefLocalVariables ) : void

For by-ref parameters passed as reference (without [out] attribute), we first set the value of local variables

EmitParametersLoadingOnStack ( ILGenerator generator, Type parameterTypes, Type nativeParameterTypes, ByRefParameter byRefLocalVariables, int parameterOffset ) : void

Genenerate optimized IL for stacking parameters : - For the third or fourth parameter, use the short OpCode - For all the parameters left, use the long OpCode

GetReturnType ( MethodBase methodBase ) : Type

Gets the return type of the method base.

GetUniqueName ( MethodBase methodBase ) : String

Gets a unique name of the method base.

UnwrapResultOfInvocation ( ILGenerator generator, LocalBuilder result, Type returnType, Type nativeReturnType, bool hasByRef ) : void

Unwraps the result of invocation.

Private Methods

Method Description
DefineProxyDelegateFieldInfo ( TypeBuilder typeBuilder, MethodTuple methodTuple ) : FieldInfo

Defines the proxy delegate field info.

DefineStaticConstructor ( TypeBuilder typeBuilder, IEnumerable methodTuples ) : void

Defines a static constructor.

EmitManagedToNativeMarshallingCast ( ILGenerator generator, LocalBuilder local, Type localType, int i ) : void
EmitNativeToManagedMarshallingCast ( ILGenerator generator, Type localType ) : void

Emits the native to managed marshalling cast.

Method Details

CodeGenerator() protected method

Initializes a new instance of the CodeGenerator class.
protected CodeGenerator ( DynamicAssembly assembly, bool is64Bits )
assembly DynamicAssembly The assembly.
is64Bits bool

CreateLocalBuilderForInvocationResult() protected static method

Creates a local builder to store the result of the invocation.
protected static CreateLocalBuilderForInvocationResult ( ILGenerator generator, Type returnType, Type nativeReturnType ) : LocalBuilder
generator ILGenerator The IL generator.
returnType Type The return type.
nativeReturnType Type The native return type.
return LocalBuilder

CreateLocalVariableForByRefParameters() protected static method

Emit local variable for each by-ref parameters. These variables will hold the result until the marshalling occurs.
protected static CreateLocalVariableForByRefParameters ( ILGenerator generator, ParameterInfo parameterInfos ) : ByRefParameter[]
generator ILGenerator
parameterInfos ParameterInfo
return ByRefParameter[]

EmitLoadArgument() protected static method

protected static EmitLoadArgument ( ILGenerator generator, int index ) : void
generator ILGenerator
index int
return void

EmitManagedToNativeMarshallingForByRefParameters() protected method

Emit the code needed to marshal back the local variables to by-ref parameters.
protected EmitManagedToNativeMarshallingForByRefParameters ( ILGenerator generator, Type nativeParameterTypes, ByRefParameter byRefLocalVariables ) : void
generator ILGenerator
nativeParameterTypes Type
byRefLocalVariables ByRefParameter
return void

EmitNativeToManagedMarshallingForByRefParameters() protected method

For by-ref parameters passed as reference (without [out] attribute), we first set the value of local variables
protected EmitNativeToManagedMarshallingForByRefParameters ( ILGenerator generator, Type nativeParameterTypes, ByRefParameter byRefLocalVariables ) : void
generator ILGenerator
nativeParameterTypes Type
byRefLocalVariables ByRefParameter
return void

EmitParametersLoadingOnStack() protected static method

Genenerate optimized IL for stacking parameters : - For the third or fourth parameter, use the short OpCode - For all the parameters left, use the long OpCode
protected static EmitParametersLoadingOnStack ( ILGenerator generator, Type parameterTypes, Type nativeParameterTypes, ByRefParameter byRefLocalVariables, int parameterOffset ) : void
generator ILGenerator
parameterTypes Type
nativeParameterTypes Type
byRefLocalVariables ByRefParameter
parameterOffset int
return void

GetReturnType() protected static method

Gets the return type of the method base.
protected static GetReturnType ( MethodBase methodBase ) : Type
methodBase MethodBase
return Type

GetUniqueName() protected static method

Gets a unique name of the method base.
protected static GetUniqueName ( MethodBase methodBase ) : String
methodBase MethodBase
return String

UnwrapResultOfInvocation() protected static method

Unwraps the result of invocation.
protected static UnwrapResultOfInvocation ( ILGenerator generator, LocalBuilder result, Type returnType, Type nativeReturnType, bool hasByRef ) : void
generator ILGenerator Generator.
result LocalBuilder Result.
returnType Type Return type.
nativeReturnType Type Native return type.
hasByRef bool If set to true has by reference.
return void