[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/Reflection/Emit Assemb
From: |
Rhys Weatherley <address@hidden> |
Subject: |
[Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/Reflection/Emit AssemblyBuilder.cs,1.4,1.5 ConstructorBuilder.cs,1.2,1.3 EnumBuilder.cs,1.2,1.3 FieldBuilder.cs,1.3,1.4 ILGenerator.cs,1.5,1.6 LocalBuilder.cs,1.3,1.4 MethodBuilder.cs,1.2,1.3 ModuleBuilder.cs,1.5,1.6 ParameterBuilder.cs,1.2,1.3 PropertyBuilder.cs,1.3,1.4 TypeBuilder.cs,1.4,1.5 |
Date: |
Fri, 21 Mar 2003 20:33:18 -0500 |
Update of /cvsroot/dotgnu-pnet/pnetlib/runtime/System/Reflection/Emit
In directory subversions:/tmp/cvs-serv13864/runtime/System/Reflection/Emit
Modified Files:
AssemblyBuilder.cs ConstructorBuilder.cs EnumBuilder.cs
FieldBuilder.cs ILGenerator.cs LocalBuilder.cs
MethodBuilder.cs ModuleBuilder.cs ParameterBuilder.cs
PropertyBuilder.cs TypeBuilder.cs
Log Message:
Continue implementation of Reflection.Emit; primarily methods
and IL code generation.
Index: AssemblyBuilder.cs
===================================================================
RCS file:
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Reflection/Emit/AssemblyBuilder.cs,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** AssemblyBuilder.cs 20 Mar 2003 06:22:59 -0000 1.4
--- AssemblyBuilder.cs 22 Mar 2003 01:33:16 -0000 1.5
***************
*** 30,33 ****
--- 30,34 ----
using System.Security;
using System.Security.Policy;
+ using System.Security.Permissions;
using System.Runtime.CompilerServices;
using System.Threading;
***************
*** 357,360 ****
--- 358,370 ----
}
+ // Add declarative security to a program item in this assembly.
+ [TODO]
+ internal void AddDeclarativeSecurity(IClrProgramItem item,
+
SecurityAction action,
+
PermissionSet pset)
+ {
+ throw new
NotImplementedException("AddDeclarativeSecurity");
+ }
+
// Create a new assembly.
[MethodImpl(MethodImplOptions.InternalCall)]
***************
*** 371,374 ****
--- 381,389 ----
[MethodImpl(MethodImplOptions.InternalCall)]
extern internal static int ClrGetItemToken(IntPtr item);
+
+ // Get the program item associated with a particular token.
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ extern internal static IntPtr ClrGetItemFromToken
+ (IntPtr assembly, int token);
}; // class AssemblyBuilder
Index: ConstructorBuilder.cs
===================================================================
RCS file:
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Reflection/Emit/ConstructorBuilder.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** ConstructorBuilder.cs 28 Feb 2003 14:52:04 -0000 1.2
--- ConstructorBuilder.cs 22 Mar 2003 01:33:16 -0000 1.3
***************
*** 32,225 ****
using System.Runtime.CompilerServices;
! [TODO]
! public sealed class ConstructorBuilder : ConstructorInfo
{
! [TODO]
public void AddDeclarativeSecurity(SecurityAction action,
PermissionSet pset)
! {
! throw new NotImplementedException("AddDeclarativeSecurity");
! }
! [TODO]
public ParameterBuilder DefineParameter(int iSequence,
ParameterAttributes attributes,
String strParamName)
! {
! throw new NotImplementedException("DefineParameter");
! }
! [TODO]
public override Object[] GetCustomAttributes(bool inherit)
! {
! throw new NotImplementedException("GetCustomAttributes");
! }
!
! [TODO]
public override Object[] GetCustomAttributes(Type attribute_type,
bool inherit)
! {
! throw new NotImplementedException("GetCustomAttributes");
! }
! [TODO]
public ILGenerator GetILGenerator()
! {
! throw new NotImplementedException("GetILGenerator");
! }
! [TODO]
public override MethodImplAttributes GetMethodImplementationFlags()
! {
! throw new
NotImplementedException("GetMethodImplementationFlags");
! }
! [TODO]
public Module GetModule()
! {
! throw new NotImplementedException("GetModule");
! }
! [TODO]
public override ParameterInfo[] GetParameters()
! {
! throw new NotImplementedException("GetParameters");
! }
! [TODO]
public MethodToken GetToken()
! {
! throw new NotImplementedException("GetToken");
! }
! [TODO]
public override Object Invoke(Object obj, BindingFlags invokeAttr,
Binder
binder, Object[] parameters,
CultureInfo
culture)
! {
! throw new NotImplementedException("Invoke");
! }
!
! [TODO]
public override Object Invoke(BindingFlags invokeAttr,
Binder
binder, Object[] parameters,
CultureInfo
culture)
! {
! throw new NotImplementedException("Invoke");
! }
! [TODO]
public override bool IsDefined(Type attribute_type, bool inherit)
! {
! throw new NotImplementedException("IsDefined");
! }
! [TODO]
public void SetCustomAttribute(CustomAttributeBuilder customBuilder)
! {
! throw new NotImplementedException("SetCustomAttribute");
! }
!
! [TODO]
public void SetCustomAttribute(ConstructorInfo con, byte[]
binaryAttribute)
! {
! throw new NotImplementedException("SetCustomAttribute");
! }
! [TODO]
public void SetImplementationFlags(MethodImplAttributes attributes)
! {
! throw new NotImplementedException("SetImplementationFlags");
! }
! [TODO]
public void SetSymCustomAttribute(String name, byte[] data)
! {
! throw new NotImplementedException("SetSymCustomAttribute");
! }
[TODO]
public override String ToString()
! {
! throw new NotImplementedException("ToString");
! }
! [TODO]
public override MethodAttributes Attributes
! {
! get
! {
! throw new NotImplementedException("Attributes");
! }
! }
! [TODO]
public override Type DeclaringType
! {
! get
! {
! throw new NotImplementedException("DeclaringType");
! }
! }
! [TODO]
public bool InitLocals
! {
! get
! {
! throw new NotImplementedException("InitLocals");
! }
! set
! {
! throw new NotImplementedException("InitLocals");
! }
! }
! [TODO]
public override RuntimeMethodHandle MethodHandle
! {
! get
! {
! throw new NotImplementedException("MethodHandle");
! }
! }
! [TODO]
public override String Name
! {
! get
! {
! throw new NotImplementedException("Name");
! }
! }
! [TODO]
public override Type ReflectedType
! {
! get
! {
! throw new NotImplementedException("ReflectedType");
! }
! }
! [TODO]
public Type ReturnType
! {
! get
! {
! return typeof(Void);
! }
! }
[TODO]
public String Signature
! {
! get
! {
! throw new NotImplementedException("Signature");
! }
! }
!
! // TODO
}; // class ConstructorBuilder
--- 32,328 ----
using System.Runtime.CompilerServices;
! public sealed class ConstructorBuilder : ConstructorInfo, IClrProgramItem
{
! // Internal state.
! internal TypeBuilder type;
! private IntPtr privateData;
! internal int numParams;
! private ILGenerator ilGenerator;
! private bool initLocals;
!
! // Constructor.
! internal ConstructorBuilder(TypeBuilder type, String name,
!
MethodAttributes attributes,
!
CallingConventions callingConvention,
! Type[]
parameterTypes)
! {
! // Set the internal state.
! this.type = type;
! this.numParams = (parameterTypes != null
! ?
parameterTypes.Length : 0);
! this.ilGenerator = null;
! this.initLocals = true;
!
! // Create the constructor method.
! this.privateData = MethodBuilder.ClrMethodCreate
! (((IClrProgramItem)type).ClrHandle,
name,
! attributes, callingConvention,
! typeof(void), parameterTypes);
!
! // Add the constructor to the type for
post-processing.
! type.AddMethod(this);
! }
!
! // Add declarative security to this constructor.
public void AddDeclarativeSecurity(SecurityAction action,
PermissionSet pset)
! {
! try
! {
! type.StartSync();
!
type.module.assembly.AddDeclarativeSecurity
! (this, action, pset);
! }
! finally
! {
! type.EndSync();
! }
! }
! // Define a parameter information block for this constructor.
public ParameterBuilder DefineParameter(int iSequence,
ParameterAttributes attributes,
String strParamName)
! {
! try
! {
! type.StartSync();
! if(iSequence <= 0 || iSequence >
numParams)
! {
! throw new
ArgumentOutOfRangeException
! ("iSequence",
_("Emit_InvalidParamNum"));
! }
! return new ParameterBuilder
! (this, iSequence, attributes,
strParamName);
! }
! finally
! {
! type.EndSync();
! }
! }
! // Get the custom attributes for this constructor.
public override Object[] GetCustomAttributes(bool inherit)
! {
! throw new
NotSupportedException(_("NotSupp_Builder"));
! }
public override Object[] GetCustomAttributes(Type attribute_type,
bool inherit)
! {
! throw new
NotSupportedException(_("NotSupp_Builder"));
! }
! // Get an IL code generator for this constructor.
public ILGenerator GetILGenerator()
! {
! if(ilGenerator == null)
! {
! ilGenerator = new
ILGenerator(type.module, 64);
! }
! return ilGenerator;
! }
! // Get the implementation attributes for this constructor.
public override MethodImplAttributes GetMethodImplementationFlags()
! {
! return ClrHelpers.GetImplAttrs(privateData);
! }
! // Get the method that contains this constructor.
public Module GetModule()
! {
! return type.module;
! }
! // Get the parameter information for this constructor.
public override ParameterInfo[] GetParameters()
! {
! int param;
! ParameterInfo[] parameters = new ParameterInfo
[numParams];
! for(param = 0; param < numParams; ++param)
! {
! parameters[param] =
!
ClrHelpers.GetParameterInfo(this, this, param + 1);
! }
! return parameters;
! }
! // Get the token for this constructor.
public MethodToken GetToken()
! {
! return new MethodToken
!
(AssemblyBuilder.ClrGetItemToken(privateData));
! }
! // Invoke this constructor.
public override Object Invoke(Object obj, BindingFlags invokeAttr,
Binder
binder, Object[] parameters,
CultureInfo
culture)
! {
! throw new
NotSupportedException(_("NotSupp_Builder"));
! }
public override Object Invoke(BindingFlags invokeAttr,
Binder
binder, Object[] parameters,
CultureInfo
culture)
! {
! throw new
NotSupportedException(_("NotSupp_Builder"));
! }
! // Determine if an attribute is defined on this constructor.
public override bool IsDefined(Type attribute_type, bool inherit)
! {
! throw new
NotSupportedException(_("NotSupp_Builder"));
! }
! // Set a custom attribute on this constructor.
public void SetCustomAttribute(CustomAttributeBuilder customBuilder)
! {
! try
! {
! type.StartSync();
! type.module.assembly.SetCustomAttribute
! (this, customBuilder);
! }
! finally
! {
! type.EndSync();
! }
! }
public void SetCustomAttribute(ConstructorInfo con, byte[]
binaryAttribute)
! {
! try
! {
! type.StartSync();
! type.module.assembly.SetCustomAttribute
! (this, con, binaryAttribute);
! }
! finally
! {
! type.EndSync();
! }
! }
! // Set the method implementation attributes for this constructor.
public void SetImplementationFlags(MethodImplAttributes attributes)
! {
! try
! {
! type.StartSync();
! MethodBuilder.ClrMethodSetImplAttrs
! (privateData, attributes);
! }
! finally
! {
! type.EndSync();
! }
! }
! // Set symbol attribute information for this constructor.
public void SetSymCustomAttribute(String name, byte[] data)
! {
! // We don't support symbols at present -
ignored.
! }
+ // Convert this constructor into a string.
[TODO]
public override String ToString()
! {
! // TODO
! return String.Empty;
! }
! // Get the attributes for this constructor.
public override MethodAttributes Attributes
! {
! get
! {
! return (MethodAttributes)
!
ClrHelpers.GetMemberAttrs(privateData);
! }
! }
! // Get the type that declares this constructor.
public override Type DeclaringType
! {
! get
! {
! return type;
! }
! }
! // Get or set the initalized locals state.
public bool InitLocals
! {
! get
! {
! return initLocals;
! }
! set
! {
! initLocals = value;
! }
! }
! // Get the method handle for this constructor.
public override RuntimeMethodHandle MethodHandle
! {
! get
! {
! throw new
NotSupportedException(_("NotSupp_Builder"));
! }
! }
! // Get the name of this constructor.
public override String Name
! {
! get
! {
! return ClrHelpers.GetName(this);
! }
! }
! // Get the reflected type that owns this constructor.
public override Type ReflectedType
! {
! get
! {
! return type;
! }
! }
! // Get the return type for this constructor.
public Type ReturnType
! {
! get
! {
! return typeof(void);
! }
! }
+ // Get the signature of this constructor as a string.
[TODO]
public String Signature
! {
! get
! {
! // TODO
! return String.Empty;
! }
! }
!
! // Get the CLR handle for this constructor.
! IntPtr IClrProgramItem.ClrHandle
! {
! get
! {
! return privateData;
! }
! }
!
! // Finalize this constructor by writing its code to the output image.
! internal void FinalizeConstructor()
! {
! // TODO
! }
}; // class ConstructorBuilder
Index: EnumBuilder.cs
===================================================================
RCS file:
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Reflection/Emit/EnumBuilder.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** EnumBuilder.cs 18 Mar 2003 09:54:50 -0000 1.2
--- EnumBuilder.cs 22 Mar 2003 01:33:16 -0000 1.3
***************
*** 33,37 ****
{
// Internal state.
! private TypeBuilder builder;
private Type underlyingType;
private FieldBuilder underlyingField;
--- 33,37 ----
{
// Internal state.
! internal TypeBuilder builder;
private Type underlyingType;
private FieldBuilder underlyingField;
Index: FieldBuilder.cs
===================================================================
RCS file:
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Reflection/Emit/FieldBuilder.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** FieldBuilder.cs 20 Mar 2003 06:22:59 -0000 1.3
--- FieldBuilder.cs 22 Mar 2003 01:33:16 -0000 1.4
***************
*** 33,37 ****
{
// Internal state.
! private TypeBuilder type;
private IntPtr privateData;
--- 33,37 ----
{
// Internal state.
! internal TypeBuilder type;
private IntPtr privateData;
Index: ILGenerator.cs
===================================================================
RCS file:
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Reflection/Emit/ILGenerator.cs,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -r1.5 -r1.6
*** ILGenerator.cs 18 Mar 2003 09:54:50 -0000 1.5
--- ILGenerator.cs 22 Mar 2003 01:33:16 -0000 1.6
***************
*** 23,26 ****
--- 23,28 ----
using System;
+ using System.IO;
+ using System.Collections;
using System.Diagnostics.SymbolStore;
***************
*** 40,43 ****
--- 42,50 ----
private LabelInfo[] labels;
private int numLabels;
+ private ArrayList locals;
+ private ExceptionTry exceptionStack;
+ private ExceptionTry exceptionList;
+ private ExceptionTry exceptionListEnd;
+ private TokenFixup tokenFixups;
// Information about a label in the current method.
***************
*** 59,67 ****
}; // class LabelRef
// Constructor.
! internal ILGenerator(ModuleBuilder module)
{
this.module = module;
! code = new byte [32];
offset = 0;
height = 0;
--- 66,116 ----
}; // class LabelRef
+ // Information about a token fixup.
+ private class TokenFixup
+ {
+ public TokenFixup next;
+ public int offset;
+ public IntPtr clrHandle;
+
+ }; // class TokenFixup
+
+ // Information about an exception try block.
+ private class ExceptionTry
+ {
+ public ExceptionTry next;
+ public int beginTry;
+ public int endTry;
+ public int endCatch;
+ public ExceptionClause clauses;
+ public Label endLabel;
+
+ }; // class ExceptionTry
+
+ // Clause types.
+ private const int Except_Catch = 0;
+ private const int Except_Filter = 1;
+ private const int Except_Finally = 2;
+ private const int Except_Fault = 3;
+
+ // Information about an exception clause.
+ private class ExceptionClause
+ {
+ public ExceptionClause prev;
+ public int clauseType;
+ public int beginClause;
+ public int endClause;
+ public Type classInfo;
+
+ }; // class ExceptionClause
+
// Constructor.
! internal ILGenerator(ModuleBuilder module, int size)
{
this.module = module;
! if(size < 16)
! {
! size = 16;
! }
! code = new byte [size];
offset = 0;
height = 0;
***************
*** 69,103 ****
labels = null;
numLabels = 0;
}
! [TODO]
! public virtual void BeginCatchBlock(System.Type exceptionType)
! {
! throw new NotImplementedException("BeginCatchBlock");
! }
! [TODO]
public virtual void BeginExceptFilterBlock()
! {
! throw new NotImplementedException("BeginExceptFilterBlock");
! }
! [TODO]
public virtual Label BeginExceptionBlock()
! {
! throw new NotImplementedException("BeginExceptionBlock");
! }
! [TODO]
public virtual void BeginFaultBlock()
! {
! throw new NotImplementedException("BeginFaultBlock");
! }
! [TODO]
public virtual void BeginFinallyBlock()
! {
! throw new NotImplementedException("BeginFinallyBlock");
! }
// Enter a lexical naming scope for debug information.
--- 118,328 ----
labels = null;
numLabels = 0;
+ locals = null;
+ exceptionStack = null;
+ exceptionList = null;
+ exceptionListEnd = null;
+ tokenFixups = null;
}
! // Terminate the previous exception clause.
! private void TerminateClause()
! {
! if(exceptionStack == null)
! {
! throw new NotSupportedException
! (_("Emit_NeedExceptionBlock"));
! }
! if(exceptionStack.clauses == null)
! {
! // No clauses yet, so terminate the
"try" part.
! Emit(OpCodes.Leave,
exceptionStack.endLabel);
! exceptionStack.endTry = offset;
! exceptionStack.endCatch = offset;
! }
! else
! {
! exceptionStack.clauses.endClause =
offset;
!
switch(exceptionStack.clauses.clauseType)
! {
! case Except_Catch:
! {
! Emit(OpCodes.Leave,
exceptionStack.endLabel);
! exceptionStack.endCatch
= offset;
! }
! break;
! case Except_Filter:
! {
! Emit(OpCodes.Endfilter);
! }
! break;
!
! case Except_Finally:
! case Except_Fault:
! {
!
Emit(OpCodes.Endfinally);
! }
! break;
! }
! }
! height = 0;
! }
!
! // Begin a catch block on the current exception.
! public virtual void BeginCatchBlock(Type exceptionType)
! {
! // Terminate the current clause.
! TerminateClause();
!
! // The operation is invalid if current is
finally or fault.
! if(exceptionStack.clauses != null)
! {
! if(exceptionStack.clauses.clauseType ==
Except_Finally ||
! exceptionStack.clauses.clauseType ==
Except_Fault)
! {
! throw new
InvalidOperationException
!
(_("Emit_CatchAfterFinally"));
! }
! }
!
! // Create a new clause information block.
! ExceptionClause clause = new ExceptionClause();
! clause.prev = exceptionStack.clauses;
! clause.clauseType = Except_Catch;
! clause.beginClause = offset;
! clause.endClause = -1;
! clause.classInfo = exceptionType;
! exceptionStack.clauses = clause;
! }
!
! // Begin a filter block on the current exception.
public virtual void BeginExceptFilterBlock()
! {
! // Terminate the current clause.
! TerminateClause();
! // Create a new clause information block.
! ExceptionClause clause = new ExceptionClause();
! clause.prev = exceptionStack.clauses;
! clause.clauseType = Except_Filter;
! clause.beginClause = offset;
! clause.endClause = -1;
! clause.classInfo = null;
! exceptionStack.clauses = clause;
! }
!
! // Begin the output of an exception block within the current method.
public virtual Label BeginExceptionBlock()
! {
! ExceptionTry tryBlock = new ExceptionTry();
! tryBlock.next = exceptionStack;
! tryBlock.beginTry = offset;
! tryBlock.endTry = -1;
! tryBlock.endCatch = -1;
! tryBlock.clauses = null;
! tryBlock.endLabel = DefineLabel();
! exceptionStack = tryBlock;
! return tryBlock.endLabel;
! }
! // Begin a fault block on the current exception.
public virtual void BeginFaultBlock()
! {
! // Terminate the current clause.
! TerminateClause();
! // The operation is invalid if current is
finally or fault.
! if(exceptionStack.clauses != null)
! {
! if(exceptionStack.clauses.clauseType ==
Except_Finally ||
! exceptionStack.clauses.clauseType ==
Except_Fault)
! {
! throw new
InvalidOperationException
!
(_("Emit_CatchAfterFinally"));
! }
! }
!
! // Create a new clause information block.
! ExceptionClause clause = new ExceptionClause();
! clause.prev = exceptionStack.clauses;
! clause.clauseType = Except_Fault;
! clause.beginClause = offset;
! clause.endClause = -1;
! clause.classInfo = null;
! exceptionStack.clauses = clause;
! height = 1; // Top of stack is the
exception object.
! if(height > maxHeight)
! {
! maxHeight = height;
! }
! }
!
! // Begin a finally block on the current exception.
public virtual void BeginFinallyBlock()
! {
! // Terminate the current clause.
! TerminateClause();
!
! // The operation is invalid if current is
finally or fault.
! if(exceptionStack.clauses != null)
! {
! if(exceptionStack.clauses.clauseType ==
Except_Finally ||
! exceptionStack.clauses.clauseType ==
Except_Fault)
! {
! throw new
InvalidOperationException
!
(_("Emit_CatchAfterFinally"));
! }
! }
!
! // Create a new clause information block.
! ExceptionClause clause = new ExceptionClause();
! clause.prev = exceptionStack.clauses;
! clause.clauseType = Except_Finally;
! clause.beginClause = offset;
! clause.endClause = -1;
! clause.classInfo = null;
! exceptionStack.clauses = clause;
! height = 1; // Top of stack is the
exception object.
! if(height > maxHeight)
! {
! maxHeight = height;
! }
! }
!
! // End the output of an exception block.
! public virtual void EndExceptionBlock()
! {
! // Make sure that the request is legal.
! ExceptionTry tryBlock = exceptionStack;
! if(tryBlock == null)
! {
! throw new NotSupportedException
! (_("Emit_NeedExceptionBlock"));
! }
! if(tryBlock.clauses == null)
! {
! throw new InvalidOperationException
! (_("Emit_NoExceptionClauses"));
! }
!
! // Terminate the last clause in the list.
! TerminateClause();
!
! // Mark the label for the end of the exception
block.
! MarkLabel(tryBlock.endLabel);
!
! // Add the exception to the end of the real
block list.
! exceptionStack = tryBlock.next;
! tryBlock.next = null;
! if(exceptionListEnd != null)
! {
! exceptionListEnd.next = tryBlock;
! }
! else
! {
! exceptionList = tryBlock;
! }
! exceptionListEnd = tryBlock;
! }
// Enter a lexical naming scope for debug information.
***************
*** 110,114 ****
public LocalBuilder DeclareLocal(Type localType)
{
! throw new
NotImplementedException("DeclareLocal");
}
--- 335,350 ----
public LocalBuilder DeclareLocal(Type localType)
{
! if(localType == null)
! {
! throw new
ArgumentNullException("localType");
! }
! if(locals == null)
! {
! locals = new ArrayList();
! }
! LocalBuilder builder = new LocalBuilder
! (module, localType,
locals.Count);
! locals.Add(builder);
! return builder;
}
***************
*** 154,158 ****
private void EmitTokenWithFixup(int token)
{
! // TODO: fixups
EmitByte(token);
EmitByte(token >> 8);
--- 390,399 ----
private void EmitTokenWithFixup(int token)
{
! TokenFixup fixup = new TokenFixup();
! fixup.next = tokenFixups;
! fixup.offset = offset;
! fixup.clrHandle =
AssemblyBuilder.ClrGetItemFromToken
! (module.assembly.privateData,
token);
! tokenFixups = fixup;
EmitByte(token);
EmitByte(token >> 8);
***************
*** 161,164 ****
--- 402,419 ----
}
+ // Emit a raw opcode with no stack adjustments.
+ private void EmitRawOpcode(int value)
+ {
+ if(value < 0x0100)
+ {
+ EmitByte(value);
+ }
+ else
+ {
+ EmitByte(value);
+ EmitByte(value & 0xFF);
+ }
+ }
+
// Emit an opcode value to the current method's code and then
// adjust the stack height information accordingly. We use a
***************
*** 241,244 ****
--- 496,503 ----
maxHeight = height;
}
+ else if(height < 0)
+ {
+ height = 0;
+ }
}
***************
*** 315,330 ****
}
!
! [TODO]
public virtual void Emit(OpCode opcode, ConstructorInfo constructor)
! {
! throw new NotImplementedException("Emit");
! }
! [TODO]
public virtual void Emit(OpCode opcode, FieldInfo field)
! {
! throw new NotImplementedException("Emit");
! }
// Emit code for a branch instruction. Note: unlike other
implementations,
--- 574,628 ----
}
! // Emit a call on a constructor.
public virtual void Emit(OpCode opcode, ConstructorInfo constructor)
! {
! // Bail out if "constructor" is null.
! if(constructor == null)
! {
! throw new
ArgumentNullException("constructor");
! }
! // Adjust the stack to account for the changes.
! if(opcode.stackPush ==
(int)(StackBehaviour.Varpush))
! {
! ++height;
! }
! if(opcode.stackPop ==
(int)(StackBehaviour.Varpop))
! {
! if(constructor is ConstructorBuilder)
! {
! height -=
((ConstructorBuilder)constructor).numParams;
! }
! else
! {
! ParameterInfo[] paramList =
constructor.GetParameters();
! if(paramList != null)
! {
! height -=
paramList.Length;
! }
! }
! }
! if(height > maxHeight)
! {
! maxHeight = height;
! }
! else if(height < 0)
! {
! height = 0;
! }
!
! // Output the instruction.
! MethodToken token =
module.GetConstructorToken(constructor);
! EmitRawOpcode(opcode.value);
! EmitTokenWithFixup(token.Token);
! }
!
! // Emit a reference to a field
public virtual void Emit(OpCode opcode, FieldInfo field)
! {
! FieldToken token = module.GetFieldToken(field);
! EmitOpcode(ref opcode);
! EmitTokenWithFixup(token.Token);
! }
// Emit code for a branch instruction. Note: unlike other
implementations,
***************
*** 421,441 ****
}
! [TODO]
public virtual void Emit(OpCode opcode, Label[] labels)
! {
! throw new NotImplementedException("Emit");
! }
! [TODO]
public virtual void Emit(OpCode opcode, LocalBuilder lbuilder)
! {
! throw new NotImplementedException("Emit");
! }
! [TODO]
public virtual void Emit(OpCode opcode, MethodInfo method)
! {
! throw new NotImplementedException("Emit");
! }
[TODO]
--- 719,895 ----
}
! // Emit a switch statement.
public virtual void Emit(OpCode opcode, Label[] labels)
! {
! // Determine where the switch statement ends.
! int switchEnd = offset + opcode.size +
labels.Length * 4;
! // Emit the opcode and the table length.
! EmitOpcode(ref opcode);
! EmitToken(labels.Length);
!
! // Output the table of switch labels.
! int posn;
! Label label;
! LabelInfo info;
! LabelRef newRef;
! for(posn = 0; posn < labels.Length; ++posn)
! {
! // Skip the label if it is invalid
(shouldn't happen).
! label = labels[posn];
! if(label.index < 0 || label.index >=
numLabels)
! {
! continue;
! }
!
! // Fetch the label information block.
! info = this.labels[label.index];
!
! // If it is already defined, output the
offset now.
! // Otherwise add a reference and output
a placeholder.
! if(info.offset != 0)
! {
! EmitToken(info.offset -
switchEnd);
! }
! else
! {
! newRef = new LabelRef();
! newRef.next =
this.labels[label.index].refs;
! newRef.address = offset;
! newRef.switchEnd = switchEnd;
! this.labels[label.index].refs =
newRef;
! EmitToken(0);
! }
! }
! }
!
! // Emit a reference to a local variable.
public virtual void Emit(OpCode opcode, LocalBuilder lbuilder)
! {
! // Validate the parameters.
! if(lbuilder == null)
! {
! throw new
ArgumentNullException("lbuilder");
! }
! // Determine if we can squash the instruction a
bit more.
! int index = lbuilder.index;
! if(opcode.value == 0xFE0C)
// "ldloc"
! {
! if(index == 0)
! {
! opcode = OpCodes.Ldloc_0;
! }
! else if(index == 1)
! {
! opcode = OpCodes.Ldloc_1;
! }
! else if(index == 2)
! {
! opcode = OpCodes.Ldloc_2;
! }
! else if(index == 3)
! {
! opcode = OpCodes.Ldloc_3;
! }
! else if(index < 0x0100)
! {
! opcode = OpCodes.Ldloc_S;
! }
! }
! else if(opcode.value == 0xFE0D) //
"ldloca"
! {
! if(index < 0x0100)
! {
! opcode = OpCodes.Ldloca_S;
! }
! }
! else if(opcode.value == 0xFE0E) //
"stloc"
! {
! if(index == 0)
! {
! opcode = OpCodes.Stloc_0;
! }
! else if(index == 1)
! {
! opcode = OpCodes.Stloc_1;
! }
! else if(index == 2)
! {
! opcode = OpCodes.Stloc_2;
! }
! else if(index == 3)
! {
! opcode = OpCodes.Stloc_3;
! }
! else if(index < 0x0100)
! {
! opcode = OpCodes.Stloc_S;
! }
! }
!
! // Output the instruction and its argument.
! EmitOpcode(ref opcode);
! if(opcode.operandType ==
(int)(OperandType.ShortInlineVar))
! {
! EmitByte(index);
! }
! else if(opcode.operandType ==
(int)(OperandType.InlineVar))
! {
! EmitByte(index);
! EmitByte(index >> 8);
! }
! }
!
! // Emit an instruction that refers to a method.
public virtual void Emit(OpCode opcode, MethodInfo method)
! {
! // Bail out if "method" is null.
! if(method == null)
! {
! throw new
ArgumentNullException("method");
! }
!
! // Adjust the stack to account for the changes.
! if(opcode.stackPush ==
(int)(StackBehaviour.Varpush))
! {
! if(method.ReturnType != typeof(void))
! {
! ++height;
! }
! }
! if(opcode.stackPop ==
(int)(StackBehaviour.Varpop))
! {
! if(method is MethodBuilder)
! {
! height -=
((MethodBuilder)method).numParams;
! }
! else
! {
! ParameterInfo[] paramList =
method.GetParameters();
! if(paramList != null)
! {
! height -=
paramList.Length;
! }
! }
! if(!method.IsStatic && opcode.value !=
0x73) // "newobj"
! {
! --height;
! }
! }
! if(height > maxHeight)
! {
! maxHeight = height;
! }
! else if(height < 0)
! {
! height = 0;
! }
!
! // Output the instruction.
! MethodToken token =
module.GetMethodToken(method);
! EmitRawOpcode(opcode.value);
! EmitTokenWithFixup(token.Token);
! }
[TODO]
***************
*** 445,453 ****
}
! [TODO]
public virtual void Emit(OpCode opcode, Type type)
! {
! throw new NotImplementedException("Emit");
! }
[TODO]
--- 899,909 ----
}
! // Emit an instruction that refers to a type.
public virtual void Emit(OpCode opcode, Type type)
! {
! TypeToken token = module.GetTypeToken(type);
! EmitOpcode(ref opcode);
! EmitTokenWithFixup(token.Token);
! }
[TODO]
***************
*** 463,472 ****
}
- [TODO]
- public virtual void EndExceptionBlock()
- {
- throw new NotImplementedException("EndExceptionBlock");
- }
-
// Exit a lexical naming scope for debug information.
public virtual void EndScope()
--- 919,922 ----
***************
*** 533,553 ****
public virtual void EmitWriteLine(FieldInfo field)
{
! throw new
NotImplementedException("EmitWriteLine");
}
public virtual void EmitWriteLine(LocalBuilder lbuilder)
{
! throw new
NotImplementedException("EmitWriteLine");
}
public virtual void EmitWriteLine(String val)
{
! throw new
NotImplementedException("EmitWriteLine");
}
public virtual void ThrowException(Type exceptionType)
{
! throw new
NotImplementedException("ThrowException");
}
public void UsingNamespace(String usingNamespace)
{
! throw new
NotImplementedException("UsingNamespace");
}
--- 983,1113 ----
public virtual void EmitWriteLine(FieldInfo field)
{
! Type fieldType;
! MethodInfo method;
! Type[] paramList;
!
! // Validate the parameter.
! if(field == null)
! {
! throw new
ArgumentNullException("field");
! }
! fieldType = field.FieldType;
! if(fieldType is TypeBuilder || fieldType is
EnumBuilder)
! {
! throw new
NotSupportedException(_("NotSupp_Builder"));
! }
!
! // Push the "Out" stream reference onto the
stack.
! method = typeof(Console).GetMethod("get_Out");
! Emit(OpCodes.Call, method);
!
! // Load the field value onto the stack.
! if(field.IsStatic)
! {
! Emit(OpCodes.Ldsfld, field);
! }
! else
! {
! Emit(OpCodes.Ldarg_0);
! Emit(OpCodes.Ldfld, field);
! }
!
! // Find and call the "WriteLine" method.
! paramList = new Type [1];
! paramList[0] = fieldType;
! method =
typeof(TextWriter).GetMethod("WriteLine", paramList);
! if(method == null)
! {
! throw new
ArgumentException(_("Emit_MissingWriteLine"));
! }
! Emit(OpCodes.Callvirt, method);
}
public virtual void EmitWriteLine(LocalBuilder lbuilder)
{
! Type localType;
! MethodInfo method;
! Type[] paramList;
!
! // Validate the parameter.
! if(lbuilder == null)
! {
! throw new
ArgumentNullException("lbuilder");
! }
! localType = lbuilder.LocalType;
! if(localType is TypeBuilder || localType is
EnumBuilder)
! {
! throw new
NotSupportedException(_("NotSupp_Builder"));
! }
!
! // Push the "Out" stream reference onto the
stack.
! method = typeof(Console).GetMethod("get_Out");
! Emit(OpCodes.Call, method);
!
! // Load the local variable's value onto the
stack.
! Emit(OpCodes.Ldloc, lbuilder);
!
! // Find and call the "WriteLine" method.
! paramList = new Type [1];
! paramList[0] = localType;
! method =
typeof(TextWriter).GetMethod("WriteLine", paramList);
! if(method == null)
! {
! throw new
ArgumentException(_("Emit_MissingWriteLine"));
! }
! Emit(OpCodes.Callvirt, method);
}
public virtual void EmitWriteLine(String val)
{
! Type[] paramList;
! MethodInfo method;
!
! // Locate the "Console.WriteLine(String)"
method.
! paramList = new Type [0];
! paramList[0] = typeof(String);
! method = typeof(Console).GetMethod("WriteLine",
paramList);
!
! // Output the code to call the method.
! Emit(OpCodes.Ldstr, val);
! Emit(OpCodes.Call, method);
}
public virtual void ThrowException(Type exceptionType)
{
! // Validate the parameter.
! if(exceptionType == null)
! {
! throw new
ArgumentNullException("exceptionType");
! }
! else
if(!exceptionType.IsSubclassOf(typeof(Exception)) &&
! exceptionType !=
typeof(Exception))
! {
! throw new ArgumentException
! (_("Emit_NotAnExceptionType"));
! }
!
! // Locate the zero-argument constructor.
! ConstructorInfo constructor;
! constructor =
exceptionType.GetConstructor(Type.EmptyTypes);
! if(constructor == null)
! {
! throw new ArgumentException
!
(_("Emit_NeedDefaultConstructor"));
! }
!
! // Create and throw the exception.
! Emit(OpCodes.Newobj, constructor);
! Emit(OpCodes.Throw);
}
public void UsingNamespace(String usingNamespace)
{
! // Namespace debug information not currently
used,
! // so simply validate the parameter and exit.
! if(usingNamespace == null)
! {
! throw new
ArgumentNullException("usingNamespace");
! }
! else if(usingNamespace.Length == 0)
! {
! throw new
ArgumentException(_("Emit_NameEmpty"));
! }
}
Index: LocalBuilder.cs
===================================================================
RCS file:
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Reflection/Emit/LocalBuilder.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** LocalBuilder.cs 17 Mar 2003 10:13:43 -0000 1.3
--- LocalBuilder.cs 22 Mar 2003 01:33:16 -0000 1.4
***************
*** 35,39 ****
private String name;
private Type type;
! private int index;
// Constructor.
--- 35,39 ----
private String name;
private Type type;
! internal int index;
// Constructor.
Index: MethodBuilder.cs
===================================================================
RCS file:
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Reflection/Emit/MethodBuilder.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** MethodBuilder.cs 28 Feb 2003 14:52:04 -0000 1.2
--- MethodBuilder.cs 22 Mar 2003 01:33:16 -0000 1.3
***************
*** 26,208 ****
using System;
using System.Reflection;
using System.Globalization;
using System.Runtime.CompilerServices;
! [TODO]
! public sealed class MethodBuilder : MethodInfo
{
! // TODO
! [TODO]
public void CreateMethodBody(byte[] il, int count)
! {
! throw new NotImplementedException("CreateMethodBody");
! }
! [TODO]
public ParameterBuilder DefineParameter(int position,
ParameterAttributes attributes,
String strParamName)
! {
! throw new NotImplementedException("DefineParameter");
! }
! [TODO]
public override MethodInfo GetBaseDefinition()
! {
! throw new NotImplementedException("GetBaseDefinition");
! }
! [TODO]
public override Object[] GetCustomAttributes(bool inherit)
! {
! throw new NotImplementedException("GetCustomAttributes");
! }
!
! [TODO]
public override Object[] GetCustomAttributes(Type attributeType,
!
bool inherit)
! {
! throw new NotImplementedException("GetCustomAttributes");
! }
! [TODO]
public ILGenerator GetILGenerator()
! {
! throw new NotImplementedException("GetILGenerator");
! }
!
! [TODO]
public ILGenerator GetILGenerator(int size)
! {
! throw new NotImplementedException("GetILGenerator");
! }
! [TODO]
public override MethodImplAttributes GetMethodImplementationFlags()
! {
! throw new
NotImplementedException("GetMethodImplementationFlags");
! }
! [TODO]
public override ParameterInfo[] GetParameters()
! {
! throw new NotImplementedException("GetParameters");
! }
! [TODO]
public MethodToken GetToken()
! {
! throw new NotImplementedException("GetToken");
! }
! [TODO]
public override Object Invoke(Object obj, BindingFlags invokeAttr,
Binder
binder, Object[] parameters,
CultureInfo
culture)
! {
! throw new NotImplementedException("Invoke");
! }
! [TODO]
public override bool IsDefined(Type attribute_type, bool inherit)
! {
! throw new NotImplementedException("IsDefined");
! }
! [TODO]
public void SetCustomAttribute(CustomAttributeBuilder customBuilder)
! {
! throw new NotImplementedException("SetCustomAttribute");
! }
!
! [TODO]
public void SetCustomAttribute(ConstructorInfo con, byte[]
binaryAttribute)
! {
! throw new NotImplementedException("SetCustomAttribute");
! }
! [TODO]
public void SetImplementationFlags(MethodImplAttributes attributes)
! {
! throw new NotImplementedException("SetImplementationFlags");
! }
! [TODO]
public override MethodAttributes Attributes
! {
! get
! {
! throw new NotImplementedException("Attributes");
! }
! }
! [TODO]
public override Type DeclaringType
! {
! get
! {
! throw new NotImplementedException("DeclaringType");
! }
! }
! [TODO]
public bool InitLocals
! {
! get
! {
! throw new NotImplementedException("InitLocals");
! }
! set
! {
! throw new NotImplementedException("InitLocals");
! }
! }
! [TODO]
public override RuntimeMethodHandle MethodHandle
! {
! get
! {
! throw new NotImplementedException("MethodHandle");
! }
! }
! [TODO]
public override String Name
! {
! get
! {
! throw new NotImplementedException("Name");
! }
! }
! [TODO]
public override Type ReflectedType
! {
! get
! {
! throw new NotImplementedException("ReflectedType");
! }
! }
! [TODO]
public override Type ReturnType
! {
! get
! {
! throw new NotImplementedException("ReturnType");
! }
! }
! [TODO]
public override ICustomAttributeProvider ReturnTypeCustomAttributes
! {
! get
! {
! throw new
NotImplementedException("ReturnTypeCustomAttributes");
! }
! }
}; // class MethodBuilder
--- 26,494 ----
using System;
+ using System.Security;
using System.Reflection;
using System.Globalization;
+ using System.Security.Permissions;
using System.Runtime.CompilerServices;
! public sealed class MethodBuilder : MethodInfo, IClrProgramItem
{
+ // Internal state.
+ internal TypeBuilder type;
+ private IntPtr privateData;
+ private bool bodySet;
+ private bool initLocals;
+ private byte[] explicitBody;
+ private ILGenerator ilGenerator;
+ private Type returnType;
+ private ParameterBuilder returnBuilder;
+ internal int numParams;
+
+ // Constructor.
+ internal MethodBuilder(TypeBuilder type, String name,
+ MethodAttributes attributes,
+ CallingConventions
callingConvention,
+ Type returnType, Type[]
parameterTypes)
+ {
+ // Validate the parameters.
+ if(name == null)
+ {
+ throw new ArgumentNullException("name");
+ }
+ else if(name == String.Empty)
+ {
+ throw new
ArgumentException(_("Emit_NameEmpty"));
+ }
+ if(returnType == null)
+ {
+ returnType = typeof(void);
+ }
+ // TODO
+
+ // Set the local state.
+ this.type = type;
+ this.bodySet = false;
+ this.initLocals = true;
+ this.explicitBody = null;
+ this.ilGenerator = null;
+ this.returnType = returnType;
+ this.returnBuilder = null;
+ this.numParams = (parameterTypes != null
+ ?
parameterTypes.Length : 0);
+
+ // Create the method.
+ this.privateData = ClrMethodCreate
+ (((IClrProgramItem)type).ClrHandle,
name,
+ attributes, callingConvention,
+ returnType, parameterTypes);
+
+ // Add the method to the type for
post-processing.
+ type.AddMethod(this);
+ }
+
+ // Add declarative security to this method.
+ public void AddDeclarativeSecurity(SecurityAction action,
+
PermissionSet pset)
+ {
+ try
+ {
+ type.StartSync();
+
type.module.assembly.AddDeclarativeSecurity
+ (this, action, pset);
+ }
+ finally
+ {
+ type.EndSync();
+ }
+ }
! // Create the method body from a literal array of IL instructions.
public void CreateMethodBody(byte[] il, int count)
! {
! try
! {
! type.StartSync();
! if(bodySet)
! {
! throw new
InvalidOperationException
!
(_("Emit_BodyAlreadySet"));
! }
! if(il == null)
! {
! explicitBody = null;
! }
! else if(count < 0 || count > il.Length)
! {
! throw new
ArgumentOutOfRangeException
! ("count",
_("ArgRange_Array"));
! }
! else
! {
! explicitBody = new byte [count];
! Array.Copy(il, explicitBody,
count);
! bodySet = true;
! }
! }
! finally
! {
! type.EndSync();
! }
! }
! // Define a parameter builder for a particular parameter.
public ParameterBuilder DefineParameter(int position,
ParameterAttributes attributes,
String strParamName)
! {
! try
! {
! type.StartSync();
! if(position <= 0 || position >
numParams)
! {
! throw new
ArgumentOutOfRangeException
! ("position",
_("Emit_InvalidParamNum"));
! }
! return new ParameterBuilder
! (this, position, attributes,
strParamName);
! }
! finally
! {
! type.EndSync();
! }
! }
! // Return the base definition for a method.
public override MethodInfo GetBaseDefinition()
! {
! return this;
! }
! // Get custom attributes for this method.
public override Object[] GetCustomAttributes(bool inherit)
! {
! throw new
NotSupportedException(_("NotSupp_Builder"));
! }
public override Object[] GetCustomAttributes(Type attributeType,
!
bool inherit)
! {
! throw new
NotSupportedException(_("NotSupp_Builder"));
! }
! // Get the IL generator to use for the method body.
public ILGenerator GetILGenerator()
! {
! return GetILGenerator(64);
! }
public ILGenerator GetILGenerator(int size)
! {
! MethodImplAttributes attrs =
GetMethodImplementationFlags();
! if((attrs & (MethodImplAttributes.PreserveSig |
!
MethodImplAttributes.Unmanaged)) != 0 ||
! (attrs & MethodImplAttributes.CodeTypeMask)
!=
! MethodImplAttributes.IL ||
! (Attributes & MethodAttributes.PinvokeImpl)
!= 0)
! {
! throw new InvalidOperationException
! (_("Emit_CannotHaveBody"));
! }
! if(ilGenerator == null)
! {
! ilGenerator = new
ILGenerator(type.module, size);
! }
! return ilGenerator;
! }
! // Get the method implementation attributes for this method.
public override MethodImplAttributes GetMethodImplementationFlags()
! {
! return ClrHelpers.GetImplAttrs(privateData);
! }
!
! // Get the module that owns this method.
! public Module GetModule()
! {
! return type.module;
! }
! // Get the parameters for this method.
public override ParameterInfo[] GetParameters()
! {
! int param;
! ParameterInfo[] parameters = new ParameterInfo
[numParams];
! for(param = 0; param < numParams; ++param)
! {
! parameters[param] =
!
ClrHelpers.GetParameterInfo(this, this, param + 1);
! }
! return parameters;
! }
! // Get the token code for this method.
public MethodToken GetToken()
! {
! return new MethodToken
!
(AssemblyBuilder.ClrGetItemToken(privateData));
! }
! // Invoke this method.
public override Object Invoke(Object obj, BindingFlags invokeAttr,
Binder
binder, Object[] parameters,
CultureInfo
culture)
! {
! throw new
NotSupportedException(_("NotSupp_Builder"));
! }
! // Determine if a particular attribute is defined on this method.
public override bool IsDefined(Type attribute_type, bool inherit)
! {
! throw new
NotSupportedException(_("NotSupp_Builder"));
! }
! // Set an attribute on this method.
public void SetCustomAttribute(CustomAttributeBuilder customBuilder)
! {
! try
! {
! type.StartSync();
! type.module.assembly.SetCustomAttribute
! (this, customBuilder);
! }
! finally
! {
! type.EndSync();
! }
! }
public void SetCustomAttribute(ConstructorInfo con, byte[]
binaryAttribute)
! {
! try
! {
! type.StartSync();
! type.module.assembly.SetCustomAttribute
! (this, con, binaryAttribute);
! }
! finally
! {
! type.EndSync();
! }
! }
! // Set the implementation flags for this method.
public void SetImplementationFlags(MethodImplAttributes attributes)
! {
! try
! {
! type.StartSync();
! ClrMethodSetImplAttrs(privateData,
attributes);
! }
! finally
! {
! type.EndSync();
! }
! }
!
! // Set the marshalling information for the return type.
! public void SetMarshal(UnmanagedMarshal unmanagedMarshal)
! {
! try
! {
! type.StartSync();
! if(returnBuilder != null)
! {
! returnBuilder = new
ParameterBuilder
! (this, 0,
ParameterAttributes.None, null);
! }
!
returnBuilder.SetMarshal(unmanagedMarshal);
! }
! finally
! {
! type.EndSync();
! }
! }
!
! // Determine if two method builders are equal.
! public override bool Equals(Object obj)
! {
! MethodBuilder mb = (obj as MethodBuilder);
! if(mb != null)
! {
! if(Name != mb.Name)
! {
! return false;
! }
! if(Attributes != mb.Attributes)
! {
! return false;
! }
! if(ReturnType != mb.ReturnType)
! {
! return false;
! }
! ParameterInfo[] params1 =
GetParameters();
! ParameterInfo[] params2 =
mb.GetParameters();
! if(params1.Length != params2.Length)
! {
! return false;
! }
! int index;
! for(index = 0; index < params1.Length;
++index)
! {
! if(params1[index].Attributes !=
! params2[index].Attributes)
! {
! return false;
! }
! if(params1[index].ParameterType
!=
! params2[index].ParameterType)
! {
! return false;
! }
! }
! return true;
! }
! else
! {
! return false;
! }
! }
!
! // Get the hash code for this method.
! public override int GetHashCode()
! {
! return Name.GetHashCode();
! }
!
! // Convert this method into a string.
! [TODO]
! public override String ToString()
! {
! // TODO
! return String.Empty;
! }
! // Get the attributes for this method.
public override MethodAttributes Attributes
! {
! get
! {
! return (MethodAttributes)
!
ClrHelpers.GetMemberAttrs(privateData);
! }
! }
!
! // Get the calling conventions for this method.
! public override CallingConventions CallingConvention
! {
! get
! {
! return
ClrHelpers.GetCallConv(privateData);
! }
! }
! // Get the type that declares this method.
public override Type DeclaringType
! {
! get
! {
! return type;
! }
! }
! // Get or set the "initialize locals" flag for this method.
public bool InitLocals
! {
! get
! {
! return initLocals;
! }
! set
! {
! initLocals = value;
! }
! }
! // Get the handle for this method.
public override RuntimeMethodHandle MethodHandle
! {
! get
! {
! throw new
NotSupportedException(_("NotSupp_Builder"));
! }
! }
! // Get the name of this method.
public override String Name
! {
! get
! {
! return ClrHelpers.GetName(this);
! }
! }
! // Get the reflected type that contains this method.
public override Type ReflectedType
! {
! get
! {
! return type;
! }
! }
! // Get the return type for this method.
public override Type ReturnType
! {
! get
! {
! return returnType;
! }
! }
!
! // Get the string form of the signature of this method.
! [TODO]
! public override String Signature
! {
! get
! {
! // TODO
! return String.Empty;
! }
! }
! // Get the custom attribute information for the return type.
public override ICustomAttributeProvider ReturnTypeCustomAttributes
! {
! get
! {
! // Nothing to do here.
! return null;
! }
! }
!
! // Get the CLR handle for this method.
! IntPtr IClrProgramItem.ClrHandle
! {
! get
! {
! return privateData;
! }
! }
!
! // Finalize this method by writing its code to the output image.
! internal void FinalizeMethod()
! {
! // TODO
! }
!
! // Create a new method and attach it to a particular class.
! [MethodImpl(MethodImplOptions.InternalCall)]
! extern internal static IntPtr ClrMethodCreate
! (IntPtr classInfo, String name,
! MethodAttributes attributes,
! CallingConventions callingConvention,
! Type returnType, Type[] parameterTypes);
!
! // Set the implementation attributes for a method item.
! [MethodImpl(MethodImplOptions.InternalCall)]
! extern internal static void ClrMethodSetImplAttrs
! (IntPtr item, MethodImplAttributes attributes);
}; // class MethodBuilder
Index: ModuleBuilder.cs
===================================================================
RCS file:
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Reflection/Emit/ModuleBuilder.cs,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -r1.5 -r1.6
*** ModuleBuilder.cs 20 Mar 2003 06:22:59 -0000 1.5
--- ModuleBuilder.cs 22 Mar 2003 01:33:16 -0000 1.6
***************
*** 61,64 ****
--- 61,65 ----
null, null,
PackingSize.Unspecified, 0, null);
+ moduleType.needsDefaultConstructor = false;
}
***************
*** 381,407 ****
// Get the token for a constructor within this module. Returns
// a member reference if the constructor is in another assembly.
- [TODO]
public MethodToken GetConstructorToken(ConstructorInfo con)
{
! // TODO
! return new MethodToken(0);
}
// Get the token for a field within this module. Returns
// a member reference if the constructor is in another assembly.
- [TODO]
public FieldToken GetFieldToken(FieldInfo field)
{
! // TODO
! return new FieldToken(0);
}
// Get the token for a method within this module. Returns
// a member reference if the constructor is in another assembly.
- [TODO]
public MethodToken GetMethodToken(MethodInfo method)
{
! // TODO
! return new MethodToken(0);
}
--- 382,456 ----
// Get the token for a constructor within this module. Returns
// a member reference if the constructor is in another assembly.
public MethodToken GetConstructorToken(ConstructorInfo con)
{
! if(con == null)
! {
! throw new ArgumentNullException("con");
! }
! else if(con is ConstructorBuilder)
! {
! ConstructorBuilder cb = (con as
ConstructorBuilder);
! if(cb.type.module == this)
! {
! return cb.GetToken();
! }
! }
! else if(con is ClrConstructor)
! {
! return new MethodToken
! (TypeBuilder.ClrTypeImportMember
! (privateData,
((ClrConstructor)con).ClrHandle));
! }
! throw new
InvalidOperationException(_("Emit_CannotImportItem"));
}
// Get the token for a field within this module. Returns
// a member reference if the constructor is in another assembly.
public FieldToken GetFieldToken(FieldInfo field)
{
! if(field == null)
! {
! throw new
ArgumentNullException("field");
! }
! else if(field is FieldBuilder)
! {
! FieldBuilder fb = (field as
FieldBuilder);
! if(fb.type.module == this)
! {
! return fb.GetToken();
! }
! }
! else if(field is ClrField)
! {
! return new FieldToken
! (TypeBuilder.ClrTypeImportMember
! (privateData,
((ClrField)field).ClrHandle));
! }
! throw new
InvalidOperationException(_("Emit_CannotImportItem"));
}
// Get the token for a method within this module. Returns
// a member reference if the constructor is in another assembly.
public MethodToken GetMethodToken(MethodInfo method)
{
! if(method == null)
! {
! throw new
ArgumentNullException("method");
! }
! else if(method is MethodBuilder)
! {
! MethodBuilder mb = (method as
MethodBuilder);
! if(mb.type.module == this)
! {
! return mb.GetToken();
! }
! }
! else if(method is ClrMethod)
! {
! return new MethodToken
! (TypeBuilder.ClrTypeImportMember
! (privateData,
((ClrMethod)method).ClrHandle));
! }
! throw new
InvalidOperationException(_("Emit_CannotImportItem"));
}
***************
*** 421,425 ****
// Get a token for a string constant within this module.
- [TODO]
public StringToken GetStringConstant(String str)
{
--- 470,473 ----
***************
*** 428,433 ****
throw new ArgumentNullException("str");
}
! // TODO
! return new StringToken(0);
}
--- 476,481 ----
throw new ArgumentNullException("str");
}
! return new StringToken
! (ClrModuleCreateString(privateData,
str));
}
***************
*** 501,517 ****
// Get a type token by name.
- [TODO]
public TypeToken GetTypeToken(String name)
{
! // TODO
! return new TypeToken(0);
}
// Get a type token by type.
- [TODO]
public TypeToken GetTypeToken(Type type)
{
! // TODO
! return new TypeToken(0);
}
--- 549,592 ----
// Get a type token by name.
public TypeToken GetTypeToken(String name)
{
! return GetTypeToken(GetType(name, true, false));
}
// Get a type token by type.
public TypeToken GetTypeToken(Type type)
{
! if(type == null)
! {
! throw new ArgumentNullException("type");
! }
! else if(type is TypeBuilder)
! {
! TypeBuilder tb = (type as TypeBuilder);
! if(tb.module == this)
! {
! return tb.TypeToken;
! }
! }
! else if(type is EnumBuilder)
! {
! EnumBuilder eb = (type as EnumBuilder);
! if(eb.builder.module == this)
! {
! return eb.builder.TypeToken;
! }
! }
! else if(type is ClrType)
! {
! if(type.IsByRef)
! {
! throw new ArgumentException
!
(_("Emit_CannotImportRefType"));
! }
! return new TypeToken
! (TypeBuilder.ClrTypeImport
! (privateData,
((ClrType)type).ClrHandle));
! }
! throw new
InvalidOperationException(_("Emit_CannotImportItem"));
}
***************
*** 584,587 ****
--- 659,666 ----
[MethodImpl(MethodImplOptions.InternalCall)]
extern private static IntPtr ClrModuleCreate(IntPtr assembly, String
name);
+
+ // Create a string token within this module.
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ extern private static int ClrModuleCreateString(IntPtr module, String
str);
}; // class ModuleBuilder
Index: ParameterBuilder.cs
===================================================================
RCS file:
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Reflection/Emit/ParameterBuilder.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** ParameterBuilder.cs 22 Dec 2002 10:50:17 -0000 1.2
--- ParameterBuilder.cs 22 Mar 2003 01:33:16 -0000 1.3
***************
*** 29,32 ****
--- 29,41 ----
public class ParameterBuilder
{
+
+ // Constructor.
+ internal ParameterBuilder(MethodBase method, int position,
+
ParameterAttributes attributes,
+ String
strParamName)
+ {
+ // TODO
+ }
+
[TODO]
public virtual ParameterToken GetToken()
Index: PropertyBuilder.cs
===================================================================
RCS file:
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Reflection/Emit/PropertyBuilder.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** PropertyBuilder.cs 20 Mar 2003 06:22:59 -0000 1.3
--- PropertyBuilder.cs 22 Mar 2003 01:33:16 -0000 1.4
***************
*** 356,360 ****
}
! // Create a new event and attach it to a particular class.
[MethodImpl(MethodImplOptions.InternalCall)]
extern private static IntPtr ClrPropertyCreate
--- 356,360 ----
}
! // Create a new property and attach it to a particular class.
[MethodImpl(MethodImplOptions.InternalCall)]
extern private static IntPtr ClrPropertyCreate
Index: TypeBuilder.cs
===================================================================
RCS file:
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Reflection/Emit/TypeBuilder.cs,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** TypeBuilder.cs 20 Mar 2003 06:22:59 -0000 1.4
--- TypeBuilder.cs 22 Mar 2003 01:33:16 -0000 1.5
***************
*** 30,33 ****
--- 30,34 ----
using System.Reflection;
using System.Runtime.InteropServices;
+ using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
***************
*** 43,53 ****
private Type parent;
private Type[] interfaces;
! private PackingSize packingSize;
! private int typeSize;
! private Type declaringType;
private ClrType type;
- private TypeToken token;
private Type underlyingSystemType;
private ArrayList methods;
// Constants.
--- 44,52 ----
private Type parent;
private Type[] interfaces;
! private TypeBuilder declaringType;
private ClrType type;
private Type underlyingSystemType;
private ArrayList methods;
+ internal bool needsDefaultConstructor;
// Constants.
***************
*** 58,62 ****
TypeAttributes attr, Type
parent, Type[] interfaces,
PackingSize packingSize, int
typeSize,
! Type declaringType)
{
// Validate the parameters.
--- 57,61 ----
TypeAttributes attr, Type
parent, Type[] interfaces,
PackingSize packingSize, int
typeSize,
! TypeBuilder declaringType)
{
// Validate the parameters.
***************
*** 84,95 ****
this.attr = attr;
this.parent = parent;
! this.interfaces = interfaces;
! this.packingSize = packingSize;
! this.typeSize = typeSize;
this.declaringType = declaringType;
this.type = null;
this.underlyingSystemType = null;
- this.token = new TypeToken(0); // TODO
this.methods = new ArrayList();
}
--- 83,116 ----
this.attr = attr;
this.parent = parent;
! this.interfaces = null;
this.declaringType = declaringType;
this.type = null;
this.underlyingSystemType = null;
this.methods = new ArrayList();
+ this.needsDefaultConstructor = true;
+
+ // Create the type.
+ privateData = ClrTypeCreate
+ (((IClrProgramItem)module).ClrHandle,
name,
+ (nspace == String.Empty ? null :
nspace), attr,
+ (parent == null ? new
System.Reflection.Emit.TypeToken(0)
+ :
module.GetTypeToken(parent)));
+ if(packingSize != PackingSize.Unspecified)
+ {
+ ClrTypeSetPackingSize(privateData,
(int)packingSize);
+ }
+ if(typeSize != UnspecifiedTypeSize)
+ {
+ ClrTypeSetClassSize(privateData,
typeSize);
+ }
+
+ // Add the interfaces to the type.
+ if(interfaces != null)
+ {
+ foreach(Type iface in interfaces)
+ {
+
AddInterfaceImplementation(iface);
+ }
+ }
}
***************
*** 198,202 ****
get
{
! return packingSize;
}
}
--- 219,223 ----
get
{
! return
(PackingSize)(ClrTypeGetPackingSize(privateData));
}
}
***************
*** 216,220 ****
get
{
! return typeSize;
}
}
--- 237,241 ----
get
{
! return ClrTypeGetClassSize(privateData);
}
}
***************
*** 234,238 ****
get
{
! return token;
}
}
--- 255,260 ----
get
{
! return new
System.Reflection.Emit.TypeToken
!
(AssemblyBuilder.ClrGetItemToken(privateData));
}
}
***************
*** 299,303 ****
// Add declarative security to this type.
- [TODO]
public void AddDeclarativeSecurity(SecurityAction action,
PermissionSet pset)
--- 321,324 ----
***************
*** 306,310 ****
{
StartSync();
! // TODO
}
finally
--- 327,332 ----
{
StartSync();
! module.assembly.AddDeclarativeSecurity
! (this, action, pset);
}
finally
***************
*** 355,358 ****
--- 377,384 ----
}
+ // Convert the interface into a token,
which may throw
+ // an exception if it cannot be
imported.
+ TypeToken token =
module.GetTypeToken(interfaceType);
+
// Add the interface to the list.
Type[] newInterfaces;
***************
*** 370,373 ****
--- 396,402 ----
}
interfaces = newInterfaces;
+
+ // Call the runtime engine to add the
interface.
+ ClrTypeAddInterface(privateData, token);
}
finally
***************
*** 378,390 ****
// Create this type.
- [TODO]
public Type CreateType()
{
! // TODO
! return null;
}
// Define a constructor for this class.
- [TODO]
public ConstructorBuilder DefineConstructor
(MethodAttributes attributes,
--- 407,468 ----
// Create this type.
public Type CreateType()
{
! try
! {
! // Synchronize access and make sure we
aren't created.
! StartSync();
!
! // If nested, the nesting parent must
be created first.
! if(declaringType != null)
! {
! if(declaringType.type == null)
! {
! throw new
InvalidOperationException
!
(_("Emit_NestingParentNotCreated"));
! }
! }
!
! // Define a default constructor if
necessary.
! if(needsDefaultConstructor &&
!IsInterface && !IsValueType)
! {
! if(IsAbstract)
! {
!
DefineDefaultConstructor(MethodAttributes.Family);
! }
! else
! {
!
DefineDefaultConstructor(MethodAttributes.Public);
! }
! }
!
! // Finalize the methods and
constructors.
! MethodBuilder mb;
! foreach(MethodBase method in methods)
! {
! mb = (method as MethodBuilder);
! if(mb != null)
! {
! mb.FinalizeMethod();
! }
! else
! {
!
((ConstructorBuilder)method).FinalizeConstructor();
! }
! }
!
! // Wrap "privateData" in a "ClrType"
object and return it.
! ClrType clrType = new ClrType();
! clrType.privateData = privateData;
! type = clrType;
! return type;
! }
! finally
! {
! EndSync();
! }
}
// Define a constructor for this class.
public ConstructorBuilder DefineConstructor
(MethodAttributes attributes,
***************
*** 395,400 ****
{
StartSync();
! // TODO
! return null;
}
finally
--- 473,491 ----
{
StartSync();
! String name;
! if((attributes &
MethodAttributes.Static) != 0)
! {
! name = ".cctor";
! }
! else
! {
! name = ".ctor";
! }
! attributes |=
MethodAttributes.SpecialName;
! ConstructorBuilder con = new
ConstructorBuilder
! (this, name, attributes,
! callingConvention,
parameterTypes);
! needsDefaultConstructor = false;
! return con;
}
finally
***************
*** 512,516 ****
// Define a method for this class.
- [TODO]
public MethodBuilder DefineMethod
(String name, MethodAttributes attributes,
--- 603,606 ----
***************
*** 521,526 ****
{
StartSync();
! // TODO
! return null;
}
finally
--- 611,617 ----
{
StartSync();
! return new MethodBuilder
! (this, name, attributes,
callingConvention,
! returnType, parameterTypes);
}
finally
***************
*** 557,561 ****
private TypeBuilder DefineNestedType
(String name, TypeAttributes attr, Type parent,
! Type[] interfaces, int typeSize, PackingSize
packSize)
{
try
--- 648,652 ----
private TypeBuilder DefineNestedType
(String name, TypeAttributes attr, Type parent,
! Type[] interfaces, int typeSize, PackingSize
packingSize)
{
try
***************
*** 997,1000 ****
--- 1088,1092 ----
{
StartSync();
+ ClrTypeSetParent(privateData,
module.GetTypeToken(parent));
this.parent = parent;
}
***************
*** 1025,1028 ****
--- 1117,1164 ----
methods.Add(method);
}
+
+ // Create a new type.
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ extern private static IntPtr ClrTypeCreate
+ (IntPtr module, String name, String nspace,
+ TypeAttributes attr, TypeToken parent);
+
+ // Set the parent of a type to a new value.
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ extern private static void ClrTypeSetParent
+ (IntPtr classInfo, TypeToken parent);
+
+ // Add an interface to a type.
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ extern private static void ClrTypeAddInterface
+ (IntPtr classInfo, TypeToken iface);
+
+ // Get the packing size for a type.
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ extern private static int ClrTypeGetPackingSize(IntPtr classInfo);
+
+ // Set the packing size for a type.
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ extern private static void ClrTypeSetPackingSize
+ (IntPtr classInfo, int packingSize);
+
+ // Get the class size for a type.
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ extern private static int ClrTypeGetClassSize(IntPtr classInfo);
+
+ // Set the class size for a type.
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ extern private static void ClrTypeSetClassSize
+ (IntPtr classInfo, int classSize);
+
+ // Import a class information structure into a module.
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ extern internal static int ClrTypeImport
+ (IntPtr module, IntPtr classInfo);
+
+ // Import a member information structure into a module.
+ [MethodImpl(MethodImplOptions.InternalCall)]
+ extern internal static int ClrTypeImportMember
+ (IntPtr module, IntPtr memberInfo);
}; // class TypeBuilder
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/Reflection/Emit AssemblyBuilder.cs,1.4,1.5 ConstructorBuilder.cs,1.2,1.3 EnumBuilder.cs,1.2,1.3 FieldBuilder.cs,1.3,1.4 ILGenerator.cs,1.5,1.6 LocalBuilder.cs,1.3,1.4 MethodBuilder.cs,1.2,1.3 ModuleBuilder.cs,1.5,1.6 ParameterBuilder.cs,1.2,1.3 PropertyBuilder.cs,1.3,1.4 TypeBuilder.cs,1.4,1.5,
Rhys Weatherley <address@hidden> <=