dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/Reflection/Emit Constr


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/Reflection/Emit ConstructorBuilder.cs,1.3,1.4 EventBuilder.cs,1.3,1.4 FieldBuilder.cs,1.4,1.5 ILGenerator.cs,1.6,1.7 MethodBuilder.cs,1.3,1.4 PropertyBuilder.cs,1.4,1.5 SignatureHelper.cs,1.1,1.2 TypeBuilder.cs,1.5,1.6
Date: Sat, 22 Mar 2003 00:12:33 -0500

Update of /cvsroot/dotgnu-pnet/pnetlib/runtime/System/Reflection/Emit
In directory subversions:/tmp/cvs-serv29340/runtime/System/Reflection/Emit

Modified Files:
        ConstructorBuilder.cs EventBuilder.cs FieldBuilder.cs 
        ILGenerator.cs MethodBuilder.cs PropertyBuilder.cs 
        SignatureHelper.cs TypeBuilder.cs 
Log Message:


Implement signature building routines for Reflection.Emit; modify
field, event, method, and property creation to use the
signature building routines.


Index: ConstructorBuilder.cs
===================================================================
RCS file: 
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Reflection/Emit/ConstructorBuilder.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** ConstructorBuilder.cs       22 Mar 2003 01:33:16 -0000      1.3
--- ConstructorBuilder.cs       22 Mar 2003 05:12:30 -0000      1.4
***************
*** 30,33 ****
--- 30,34 ----
  using System.Globalization;
  using System.Security.Permissions;
+ using System.Runtime.InteropServices;
  using System.Runtime.CompilerServices;
  
***************
*** 40,43 ****
--- 41,45 ----
        private ILGenerator ilGenerator;
        private bool initLocals;
+       private SignatureHelper helper;
  
        // Constructor.
***************
*** 54,62 ****
                                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.
--- 56,69 ----
                                this.initLocals = true;
  
+                               // Create the signature.
+                               helper = SignatureHelper.GetMethodSigHelper
+                                               (type.module, callingConvention,
+                                                (CallingConvention)0,
+                                                typeof(void), parameterTypes);
+ 
                                // Create the constructor method.
                                this.privateData = MethodBuilder.ClrMethodCreate
                                        (((IClrProgramItem)type).ClrHandle, 
name,
!                                        attributes, helper.sig);
  
                                // Add the constructor to the type for 
post-processing.
***************
*** 301,311 ****
  
        // Get the signature of this constructor as a string.
-       [TODO]
        public String Signature 
                        {
                                get
                                {
!                                       // TODO
!                                       return String.Empty;
                                }
                        }
--- 308,316 ----
  
        // Get the signature of this constructor as a string.
        public String Signature 
                        {
                                get
                                {
!                                       return helper.ToString();
                                }
                        }

Index: EventBuilder.cs
===================================================================
RCS file: 
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Reflection/Emit/EventBuilder.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** EventBuilder.cs     20 Mar 2003 06:22:59 -0000      1.3
--- EventBuilder.cs     22 Mar 2003 05:12:30 -0000      1.4
***************
*** 54,58 ****
                                this.privateData = ClrEventCreate
                                        (((IClrProgramItem)type).ClrHandle, 
name,
!                                        eventType, attributes);
                        }
  
--- 54,59 ----
                                this.privateData = ClrEventCreate
                                        (((IClrProgramItem)type).ClrHandle, 
name,
!                                        
SignatureHelper.CSToILType(type.module, eventType),
!                                        attributes);
                        }
  
***************
*** 149,153 ****
        [MethodImpl(MethodImplOptions.InternalCall)]
        extern private static IntPtr ClrEventCreate
!                       (IntPtr classInfo, String name, Type type,
                         EventAttributes attributes);
  
--- 150,154 ----
        [MethodImpl(MethodImplOptions.InternalCall)]
        extern private static IntPtr ClrEventCreate
!                       (IntPtr classInfo, String name, IntPtr type,
                         EventAttributes attributes);
  

Index: FieldBuilder.cs
===================================================================
RCS file: 
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Reflection/Emit/FieldBuilder.cs,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** FieldBuilder.cs     22 Mar 2003 01:33:16 -0000      1.4
--- FieldBuilder.cs     22 Mar 2003 05:12:30 -0000      1.5
***************
*** 42,47 ****
                                this.type = type;
                                this.privateData = ClrFieldCreate
!                                       (((IClrProgramItem)type).ClrHandle,
!                                        name, fieldType, attributes);
                        }
  
--- 42,48 ----
                                this.type = type;
                                this.privateData = ClrFieldCreate
!                                       (((IClrProgramItem)type).ClrHandle, 
name,
!                                        
SignatureHelper.CSToILType(type.module, fieldType),
!                                        attributes);
                        }
  
***************
*** 270,274 ****
        [MethodImpl(MethodImplOptions.InternalCall)]
        extern private static IntPtr ClrFieldCreate
!                       (IntPtr classInfo, String name, Type type,
                         FieldAttributes attributes);
  
--- 271,275 ----
        [MethodImpl(MethodImplOptions.InternalCall)]
        extern private static IntPtr ClrFieldCreate
!                       (IntPtr classInfo, String name, IntPtr type,
                         FieldAttributes attributes);
  

Index: ILGenerator.cs
===================================================================
RCS file: 
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Reflection/Emit/ILGenerator.cs,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -r1.6 -r1.7
*** ILGenerator.cs      22 Mar 2003 01:33:16 -0000      1.6
--- ILGenerator.cs      22 Mar 2003 05:12:30 -0000      1.7
***************
*** 22,30 ****
   */
  
- using System;
- using System.IO;
- using System.Collections;
- using System.Diagnostics.SymbolStore;
- 
  #if !ECMA_COMPAT
  
--- 22,25 ----
***************
*** 32,35 ****
--- 27,35 ----
  {
  
+ using System;
+ using System.IO;
+ using System.Diagnostics.SymbolStore;
+ using System.Runtime.InteropServices;
+ 
  public class ILGenerator
  {
***************
*** 42,46 ****
        private LabelInfo[] labels;
        private int numLabels;
!       private ArrayList locals;
        private ExceptionTry exceptionStack;
        private ExceptionTry exceptionList;
--- 42,47 ----
        private LabelInfo[] labels;
        private int numLabels;
!       private SignatureHelper locals;
!       private int numLocals;
        private ExceptionTry exceptionStack;
        private ExceptionTry exceptionList;
***************
*** 341,349 ****
                                if(locals == null)
                                {
!                                       locals = new ArrayList();
                                }
                                LocalBuilder builder = new LocalBuilder
!                                               (module, localType, 
locals.Count);
!                               locals.Add(builder);
                                return builder;
                        }
--- 342,351 ----
                                if(locals == null)
                                {
!                                       locals = 
SignatureHelper.GetLocalVarSigHelper(module);
                                }
+                               locals.AddArgument(localType);
                                LocalBuilder builder = new LocalBuilder
!                                               (module, localType, numLocals);
!                               ++numLocals;
                                return builder;
                        }
***************
*** 893,901 ****
                        }
  
!       [TODO]
        public virtual void Emit(OpCode opcode, SignatureHelper shelper)
!       {
!               throw new NotImplementedException("Emit");
!       }
  
        // Emit an instruction that refers to a type.
--- 895,916 ----
                        }
  
!       // Emit an instruction that takes a signature token as an argument.
        public virtual void Emit(OpCode opcode, SignatureHelper shelper)
!                       {
!                               // Emit the instruction.
!                               SignatureToken token = 
module.GetSignatureToken(shelper);
!                               EmitOpcode(ref opcode);
!                               EmitToken(token.Token);
! 
!                               // Adjust the stack height for the "calli" 
instruction.
!                               if(opcode.stackPop == 
(int)(StackBehaviour.Varpop))
!                               {
!                                       height -= shelper.numArgs + 1;
!                                       if(height < 0)
!                                       {
!                                               height = 0;
!                                       }
!                               }
!                       }
  
        // Emit an instruction that refers to a type.
***************
*** 907,921 ****
                        }
  
!       [TODO]
!       public void EmitCall(OpCode opcode, MethodInfo methodinfo, Type[] 
optionalParamTypes)
!       {
!               throw new NotImplementedException("EmitCall");
!       }
  
!       [TODO]
!       public void EmitCalli(OpCode opcode, CallingConventions call_conv, Type 
returnType, Type[] paramTypes, Type[] optionalParamTypes)
!       {
!               throw new NotImplementedException("EmitCalli");
!       }
  
        // Exit a lexical naming scope for debug information.
--- 922,1027 ----
                        }
  
!       // Emit an instruction to call a method with vararg parameters.
!       public void EmitCall(OpCode opcode, MethodInfo methodInfo,
!                                                Type[] optionalParamTypes)
!                       {
!                               // Call the method call directly if no optional 
parameters.
!                               if(optionalParamTypes == null ||
!                                  optionalParamTypes.Length == 0)
!                               {
!                                       Emit(opcode, methodInfo);
!                                       return;
!                               }
  
!                               // Get the method's token, which takes care of 
importing.
!                               MethodToken token = 
module.GetMethodToken(methodInfo);
! 
!                               // Make a copy of the method's signature and 
adjust it.
!                               SignatureHelper helper =
!                                       
SignatureHelper.GetMethodSigHelper(module, token);
!                               helper.AddSentinel();
!                               foreach(Type type in optionalParamTypes)
!                               {
!                                       helper.AddArgument(type);
!                               }
! 
!                               // Create a new token for the vararg member 
reference.
!                               int refToken = 
MethodBuilder.ClrMethodCreateVarArgRef
!                                               (module.privateData, 
token.Token, helper.sig);
! 
!                               // Emit the raw instruction.
!                               EmitRawOpcode(opcode.value);
!                               EmitTokenWithFixup(refToken);
! 
!                               // Adjust the stack to account for the changes.
!                               if(opcode.stackPush == 
(int)(StackBehaviour.Varpush))
!                               {
!                                       if(methodInfo.ReturnType != 
typeof(void))
!                                       {
!                                               ++height;
!                                       }
!                               }
!                               if(opcode.stackPop == 
(int)(StackBehaviour.Varpop))
!                               {
!                                       height -= optionalParamTypes.Length;
!                                       if(methodInfo is MethodBuilder)
!                                       {
!                                               height -= 
((MethodBuilder)methodInfo).numParams;
!                                       }
!                                       else
!                                       {
!                                               ParameterInfo[] paramList = 
methodInfo.GetParameters();
!                                               if(paramList != null)
!                                               {
!                                                       height -= 
paramList.Length;
!                                               }
!                                       }
!                                       if(!methodInfo.IsStatic && opcode.value 
!= 0x73) // "newobj"
!                                       {
!                                               --height;
!                                       }
!                               }
!                               if(height > maxHeight)
!                               {
!                                       maxHeight = height;
!                               }
!                               else if(height < 0)
!                               {
!                                       height = 0;
!                               }
!                       }
! 
!       // Emit an indirect call instruction.
!       public void EmitCalli(OpCode opcode, CallingConventions callConv,
!                                                 Type returnType, Type[] 
paramTypes,
!                                                 Type[] optionalParamTypes)
!                       {
!                               // Check the calling convention.
!                               if(optionalParamTypes != null)
!                               {
!                                       if((callConv & 
CallingConventions.VarArgs) == 0)
!                                       {
!                                               throw new 
InvalidOperationException
!                                                       
(_("Emit_VarArgsWithNonVarArgMethod"));
!                                       }
!                               }
! 
!                               // Build the full signature.
!                               SignatureHelper helper =
!                                       SignatureHelper.GetMethodSigHelper
!                                               (module, callConv, 
(CallingConvention)0,
!                                                returnType, paramTypes);
!                               if(optionalParamTypes != null)
!                               {
!                                       helper.AddSentinel();
!                                       foreach(Type type in optionalParamTypes)
!                                       {
!                                               helper.AddArgument(type);
!                                       }
!                               }
! 
!                               // Emit the instruction using the constructed 
signature.
!                               Emit(opcode, helper);
!                       }
  
        // Exit a lexical naming scope for debug information.

Index: MethodBuilder.cs
===================================================================
RCS file: 
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Reflection/Emit/MethodBuilder.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** MethodBuilder.cs    22 Mar 2003 01:33:16 -0000      1.3
--- MethodBuilder.cs    22 Mar 2003 05:12:30 -0000      1.4
***************
*** 30,33 ****
--- 30,34 ----
  using System.Globalization;
  using System.Security.Permissions;
+ using System.Runtime.InteropServices;
  using System.Runtime.CompilerServices;
  
***************
*** 43,46 ****
--- 44,48 ----
        private Type returnType;
        private ParameterBuilder returnBuilder;
+       private SignatureHelper helper;
        internal int numParams;
  
***************
*** 77,85 ****
                                                                        ? 
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.
--- 79,92 ----
                                                                        ? 
parameterTypes.Length : 0);
  
+                               // Create the method signature.
+                               helper = SignatureHelper.GetMethodSigHelper
+                                               (type.module, callingConvention,
+                                                (CallingConvention)0,
+                                                returnType, parameterTypes);
+ 
                                // Create the method.
                                this.privateData = ClrMethodCreate
                                        (((IClrProgramItem)type).ClrHandle, 
name,
!                                        attributes, helper.sig);
  
                                // Add the method to the type for 
post-processing.
***************
*** 444,454 ****
  
        // Get the string form of the signature of this method.
-       [TODO]
        public override String Signature 
                        {
                                get
                                {
!                                       // TODO
!                                       return String.Empty;
                                }
                        }
--- 451,459 ----
  
        // Get the string form of the signature of this method.
        public override String Signature 
                        {
                                get
                                {
!                                       return helper.ToString();
                                }
                        }
***************
*** 483,489 ****
        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.
--- 488,492 ----
        extern internal static IntPtr ClrMethodCreate
                        (IntPtr classInfo, String name,
!                        MethodAttributes attributes, IntPtr signature);
  
        // Set the implementation attributes for a method item.
***************
*** 491,494 ****
--- 494,502 ----
        extern internal static void ClrMethodSetImplAttrs
                        (IntPtr item, MethodImplAttributes attributes);
+ 
+       // Create a member reference for a vararg method call.
+       [MethodImpl(MethodImplOptions.InternalCall)]
+       extern internal static int ClrMethodCreateVarArgRef
+                       (IntPtr module, int methodToken, IntPtr signature);
  
  }; // class MethodBuilder

Index: PropertyBuilder.cs
===================================================================
RCS file: 
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Reflection/Emit/PropertyBuilder.cs,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** PropertyBuilder.cs  22 Mar 2003 01:33:16 -0000      1.4
--- PropertyBuilder.cs  22 Mar 2003 05:12:30 -0000      1.5
***************
*** 60,67 ****
                                this.setMethod = null;
  
                                // Create the property.
                                this.privateData = ClrPropertyCreate
                                        (((IClrProgramItem)type).ClrHandle, 
name,
!                                        attributes, returnType, 
parameterTypes);
                        }
  
--- 60,72 ----
                                this.setMethod = null;
  
+                               // Create the property signature.
+                               SignatureHelper helper =
+                                       SignatureHelper.GetPropertySigHelper
+                                               (type.module, returnType, 
parameterTypes);
+ 
                                // Create the property.
                                this.privateData = ClrPropertyCreate
                                        (((IClrProgramItem)type).ClrHandle, 
name,
!                                        attributes, helper.sig);
                        }
  
***************
*** 360,365 ****
        extern private static IntPtr ClrPropertyCreate
                        (IntPtr classInfo, String name,
!                        PropertyAttributes attributes,
!                        Type returnType, Type[] parameterTypes);
  
        // Add semantic information to this property.
--- 365,369 ----
        extern private static IntPtr ClrPropertyCreate
                        (IntPtr classInfo, String name,
!                        PropertyAttributes attributes, IntPtr signature);
  
        // Add semantic information to this property.

Index: SignatureHelper.cs
===================================================================
RCS file: 
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Reflection/Emit/SignatureHelper.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** SignatureHelper.cs  4 May 2002 05:16:06 -0000       1.1
--- SignatureHelper.cs  22 Mar 2003 05:12:30 -0000      1.2
***************
*** 26,38 ****
  
  using System;
  using System.Reflection;
  using System.Globalization;
  using System.Runtime.CompilerServices;
  
- [TODO]
  public sealed class SignatureHelper
  {
  
!       // TODO
  
  }; // class SignatureHelper
--- 26,396 ----
  
  using System;
+ using System.Text;
  using System.Reflection;
  using System.Globalization;
+ using System.Runtime.InteropServices;
  using System.Runtime.CompilerServices;
  
  public sealed class SignatureHelper
  {
+       // Internal state.
+       private Module mod;
+       private IntPtr context;
+       internal IntPtr sig;
+       internal int numArgs;
+       private CallingConvention callConv;
  
!       // Constructor.
!       private SignatureHelper(Module mod, IntPtr context, IntPtr sig)
!                       {
!                               this.mod = mod;
!                               this.context = context;
!                               this.sig = sig;
!                               this.numArgs = 0;
!                               this.callConv = (CallingConvention)0;
!                       }
!       private SignatureHelper(Module mod, IntPtr context, IntPtr sig,
!                                                       CallingConvention 
callConv)
!                       {
!                               this.mod = mod;
!                               this.context = context;
!                               this.sig = sig;
!                               this.numArgs = 0;
!                               this.callConv = callConv;
!                       }
! 
!       // Convert a module into an ILContext value.
!       private static IntPtr ModuleToContext(Module mod)
!                       {
!                               if(mod == null)
!                               {
!                                       throw new ArgumentNullException("mod");
!                               }
!                               else if(!(mod is ModuleBuilder))
!                               {
!                                       throw new NotSupportedException
!                                               (_("Emit_NeedDynamicModule"));
!                               }
!                               return ClrSigModuleToContext(mod.privateData);
!                       }
! 
!       // Convert a C# type into an ILType value.
!       private static IntPtr CSToILType(Module mod, IntPtr context, Type type)
!                       {
!                               if(type == null)
!                               {
!                                       return ClrSigCreatePrimitive(context, 
typeof(void));
!                               }
!                               else if(type.IsPrimitive || type == 
typeof(void))
!                               {
!                                       return ClrSigCreatePrimitive(context, 
type);
!                               }
!                               else if(type.IsArray)
!                               {
!                                       return ClrSigCreateArray
!                                               (context, type.GetArrayRank(),
!                                                CSToILType(mod, context, 
type.GetElementType()));
!                               }
!                               else if(type.IsPointer)
!                               {
!                                       return ClrSigCreatePointer
!                                               (context,
!                                                CSToILType(mod, context, 
type.GetElementType()));
!                               }
!                               else if(type.IsByRef)
!                               {
!                                       return ClrSigCreateByRef
!                                               (context,
!                                                CSToILType(mod, context, 
type.GetElementType()));
!                               }
!                               else if(type.IsGenericType)
!                               {
!                                       throw new NotSupportedException
!                                               
(_("Emit_GenericsNotSupported"));
!                               }
!                               else if(type.IsValueType)
!                               {
!                                       return ClrSigCreateValueType
!                                               (mod.privateData,
!                                                
(((ModuleBuilder)mod).GetTypeToken(type)).Token);
!                               }
!                               else
!                               {
!                                       return ClrSigCreateClass
!                                               (mod.privateData,
!                                                
(((ModuleBuilder)mod).GetTypeToken(type)).Token);
!                               }
!                       }
!       internal static IntPtr CSToILType(Module mod, Type type)
!                       {
!                               return CSToILType(mod, ModuleToContext(mod), 
type);
!                       }
! 
!       // Create a signature helper for a field signature.
!       public static SignatureHelper GetFieldSigHelper(Module mod)
!                       {
!                               IntPtr context = ModuleToContext(mod);
!                               return new SignatureHelper
!                                       (mod, context, 
ClrSigCreateField(context));
!                       }
! 
!       // Create a signature helper for a local variable signature.
!       public static SignatureHelper GetLocalVarSigHelper(Module mod)
!                       {
!                               IntPtr context = ModuleToContext(mod);
!                               return new SignatureHelper
!                                       (mod, context, 
ClrSigCreateLocal(context));
!                       }
! 
!       // Create a signature helper for a method signature.
!       internal static SignatureHelper GetMethodSigHelper
!                               (Module mod, CallingConventions callConv,
!                                CallingConvention unmanagedCallConv, Type 
returnType,
!                                Type[] parameterTypes)
!                       {
!                               // Convert the module into a signature create 
context.
!                               IntPtr context = ModuleToContext(mod);
! 
!                               // Determine the calling convention flags to 
use.
!                               int conv = 0;           /* default */
!                               if((callConv & CallingConventions.VarArgs) != 0)
!                               {
!                                       conv = 0x05;    /* vararg */
!                               }
!                               if((callConv & CallingConventions.HasThis) != 0)
!                               {
!                                       conv |= 0x20;   /* hasthis */
!                               }
!                               if((callConv & CallingConventions.ExplicitThis) 
!= 0)
!                               {
!                                       conv |= 0x40;   /* explicitthis */
!                               }
! 
!                               // Create the basic signature helper.
!                               IntPtr sig = ClrSigCreateMethod
!                                       (context, conv, CSToILType(mod, 
context, returnType));
!                               SignatureHelper helper = new SignatureHelper
!                                       (mod, context, sig, unmanagedCallConv);
! 
!                               // Add the parameters to the helper.
!                               if(parameterTypes != null)
!                               {
!                                       foreach(Type type in parameterTypes)
!                                       {
!                                               helper.AddArgument(type);
!                                       }
!                               }
!                               return helper;
!                       }
!       public static SignatureHelper GetMethodSigHelper
!                               (Module mod, CallingConvention 
unmanagedCallConv,
!                                Type returnType)
!                       {
!                               return GetMethodSigHelper
!                                       (mod, CallingConventions.Standard,
!                                        unmanagedCallConv, returnType, null);
!                       }
!       public static SignatureHelper GetMethodSigHelper
!                               (Module mod, CallingConventions 
callingConvention,
!                                Type returnType)
!                       {
!                               return GetMethodSigHelper
!                                       (mod, callingConvention, 
(CallingConvention)0,
!                                        returnType, null);
!                       }
!       public static SignatureHelper GetMethodSigHelper
!                               (Module mod, Type returnType, Type[] 
parameterTypes)
!                       {
!                               return GetMethodSigHelper
!                                       (mod, CallingConventions.Standard,
!                                        (CallingConvention)0, returnType, 
parameterTypes);
!                       }
!       internal static SignatureHelper GetMethodSigHelper
!                               (Module mod, MethodToken token)
!                       {
!                               IntPtr context = ModuleToContext(mod);
!                               IntPtr sig = ClrSigCreateMethodCopy
!                                       (context, mod.privateData, token.Token);
!                               return new SignatureHelper(mod, context, sig);
!                       }
! 
!       // Create a signature helper for a property signature.
!       public static SignatureHelper GetPropertySigHelper
!                               (Module mod, Type returnType, Type[] 
parameterTypes)
!                       {
!                               // Convert the module into a signature create 
context.
!                               IntPtr context = ModuleToContext(mod);
! 
!                               // Create the basic signature helper.
!                               IntPtr sig = ClrSigCreateProperty
!                                       (context, CSToILType(mod, context, 
returnType));
!                               SignatureHelper helper = new SignatureHelper
!                                       (mod, context, sig);
! 
!                               // Add the parameters to the helper.
!                               if(parameterTypes != null)
!                               {
!                                       foreach(Type type in parameterTypes)
!                                       {
!                                               helper.AddArgument(type);
!                                       }
!                               }
!                               return helper;
!                       }
! 
!       // Add an argument type to a signature.
!       public void AddArgument(Type clsArgument)
!                       {
!                               if(clsArgument == null)
!                               {
!                                       throw new 
ArgumentNullException("clsArgument");
!                               }
!                               IntPtr type = CSToILType(mod, context, 
clsArgument);
!                               if(!ClrSigAddArgument(context, sig, type))
!                               {
!                                       throw new InvalidOperationException
!                                               (_("Emit_InvalidSigArgument"));
!                               }
!                               ++numArgs;
!                       }
! 
!       // Add a vararg sentinel to a signature.
!       public void AddSentinel()
!                       {
!                               if(!ClrSigAddSentinel(context, sig))
!                               {
!                                       throw new InvalidOperationException
!                                               (_("Emit_InvalidSigArgument"));
!                               }
!                       }
! 
!       // Determine if two signatures are equal.
!       public override bool Equals(Object obj)
!                       {
!                               SignatureHelper helper = (obj as 
SignatureHelper);
!                               if(helper != null && helper.mod == mod)
!                               {
!                                       return ClrSigIdentical(sig, helper.sig);
!                               }
!                               else
!                               {
!                                       return false;
!                               }
!                       }
! 
!       // Get the hash code for a signature.
!       public override int GetHashCode()
!                       {
!                               return ClrSigGetHashCode(sig);
!                       }
! 
!       // Convert the signature into an array of bytes.
!       public byte[] GetSignature()
!                       {
!                               return ClrSigGetBytes(mod.privateData, sig);
!                       }
! 
!       // Convert this signature into a string.
!       public override String ToString()
!                       {
!                               byte[] bytes = GetSignature();
!                               StringBuilder builder = new StringBuilder();
!                               builder.Append("Length: " + 
bytes.Length.ToString() +
!                                                          Environment.NewLine);
!                               if(bytes[0] == 0x06)    /* field */
!                               {
!                                       builder.Append("Field Signature" + 
Environment.NewLine);
!                               }
!                               else
!                               {
!                                       builder.Append("Arguments: " + 
numArgs.ToString() +
!                                                                  
Environment.NewLine);
!                               }
!                               builder.Append("Signature:" + 
Environment.NewLine);
!                               foreach(byte val in bytes)
!                               {
!                                       builder.Append(val.ToString() + " ");
!                               }
!                               builder.Append(Environment.NewLine);
!                               return builder.ToString();
!                       }
! 
!       // Internal version of "ModuleToContext".
!       [MethodImpl(MethodImplOptions.InternalCall)]
!       extern private static IntPtr ClrSigModuleToContext(IntPtr module);
! 
!       // Create a primitive type value.
!       [MethodImpl(MethodImplOptions.InternalCall)]
!       extern private static IntPtr ClrSigCreatePrimitive
!                       (IntPtr context, Type type);
! 
!       // Create an array type value.
!       [MethodImpl(MethodImplOptions.InternalCall)]
!       extern private static IntPtr ClrSigCreateArray
!                       (IntPtr context, int rank, IntPtr elemType);
! 
!       // Create a pointer type value.
!       [MethodImpl(MethodImplOptions.InternalCall)]
!       extern private static IntPtr ClrSigCreatePointer
!                       (IntPtr context, IntPtr elemType);
! 
!       // Create a by-reference type value.
!       [MethodImpl(MethodImplOptions.InternalCall)]
!       extern private static IntPtr ClrSigCreateByRef
!                       (IntPtr context, IntPtr elemType);
! 
!       // Create a value type value.
!       [MethodImpl(MethodImplOptions.InternalCall)]
!       extern private static IntPtr ClrSigCreateValueType
!                       (IntPtr module, int typeToken);
! 
!       // Create a class type value.
!       [MethodImpl(MethodImplOptions.InternalCall)]
!       extern private static IntPtr ClrSigCreateClass
!                       (IntPtr module, int typeToken);
! 
!       // Create a field signature type value.
!       [MethodImpl(MethodImplOptions.InternalCall)]
!       extern private static IntPtr ClrSigCreateField(IntPtr context);
! 
!       // Create a local variable signature type value.
!       [MethodImpl(MethodImplOptions.InternalCall)]
!       extern private static IntPtr ClrSigCreateLocal(IntPtr context);
! 
!       // Create a method signature type value.
!       [MethodImpl(MethodImplOptions.InternalCall)]
!       extern private static IntPtr ClrSigCreateMethod
!                       (IntPtr context, int callConv, IntPtr returnType);
! 
!       // Create a method signature type value as a copy of another.
!       [MethodImpl(MethodImplOptions.InternalCall)]
!       extern private static IntPtr ClrSigCreateMethodCopy
!                       (IntPtr context, IntPtr module, int methodToken);
! 
!       // Create a property signature type value.
!       [MethodImpl(MethodImplOptions.InternalCall)]
!       extern private static IntPtr ClrSigCreateProperty
!                       (IntPtr context, IntPtr returnType);
! 
!       // Add an argument to a signature.  Returns false if args not allowed.
!       [MethodImpl(MethodImplOptions.InternalCall)]
!       extern private static bool ClrSigAddArgument
!                       (IntPtr context, IntPtr sig, IntPtr arg);
! 
!       // Add a sentinel to a signature.  Returns false if args not allowed.
!       [MethodImpl(MethodImplOptions.InternalCall)]
!       extern private static bool ClrSigAddSentinel(IntPtr context, IntPtr 
sig);
! 
!       // Determine if two signatures are identical.
!       [MethodImpl(MethodImplOptions.InternalCall)]
!       extern private static bool ClrSigIdentical(IntPtr sig1, IntPtr sig2);
! 
!       // Get the hash code for a signature.
!       [MethodImpl(MethodImplOptions.InternalCall)]
!       extern private static int ClrSigGetHashCode(IntPtr sig);
! 
!       // Get the bytes of a signature.
!       [MethodImpl(MethodImplOptions.InternalCall)]
!       extern private static byte[] ClrSigGetBytes(IntPtr module, IntPtr sig);
  
  }; // class SignatureHelper

Index: TypeBuilder.cs
===================================================================
RCS file: 
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Reflection/Emit/TypeBuilder.cs,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -r1.5 -r1.6
*** TypeBuilder.cs      22 Mar 2003 01:33:16 -0000      1.5
--- TypeBuilder.cs      22 Mar 2003 05:12:30 -0000      1.6
***************
*** 1103,1106 ****
--- 1103,1113 ----
                        }
  
+       // Determine if this is a generic type.
+       protected override bool IsGenericTypeImpl()
+                       {
+                               // Cannot make generic types with a builder yet.
+                               return false;
+                       }
+ 
        // Implement the IClrProgramItem interface.
        IntPtr IClrProgramItem.ClrHandle





reply via email to

[Prev in Thread] Current Thread [Next in Thread]