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 EnumB


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/Reflection/Emit EnumBuilder.cs,1.1,1.2 ILGenerator.cs,1.4,1.5 ModuleBuilder.cs,1.2,1.3TypeBuilder.cs,1.2,1.3
Date: Tue, 18 Mar 2003 04:55:11 -0500

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

Modified Files:
        EnumBuilder.cs ILGenerator.cs ModuleBuilder.cs TypeBuilder.cs 
Log Message:


Continue the implementation of the Reflection.Emit API.


Index: EnumBuilder.cs
===================================================================
RCS file: 
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Reflection/Emit/EnumBuilder.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** EnumBuilder.cs      4 May 2002 05:16:06 -0000       1.1
--- EnumBuilder.cs      18 Mar 2003 09:54:50 -0000      1.2
***************
*** 30,38 ****
  using System.Runtime.CompilerServices;
  
! [TODO]
! public sealed class EnumBuilder
  {
  
!       // TODO
  
  }; // class EnumBuilder
--- 30,391 ----
  using System.Runtime.CompilerServices;
  
! public sealed class EnumBuilder : Type
  {
+       // Internal state.
+       private TypeBuilder builder;
+       private Type underlyingType;
+       private FieldBuilder underlyingField;
  
!       // Constructor.
!       internal EnumBuilder(ModuleBuilder module, String name, String nspace,
!                                                TypeAttributes visibility, 
Type underlyingType)
!                       {
!                               // Only allowed to specify the visibility.
!                               if((visibility & 
~TypeAttributes.VisibilityMask) != 0)
!                               {
!                                       throw new 
ArgumentException(_("Emit_InvalidTypeAttrs"));
!                               }
! 
!                               // Create a type builder behind the scenes.
!                               builder = new TypeBuilder
!                                       (module, name, nspace,
!                                        visibility | TypeAttributes.Sealed,
!                                        typeof(System.Enum), null, 
PackingSize.Unspecified,
!                                        0, null);
! 
!                               // Define the "value__" field for the 
enumeration.
!                               this.underlyingType = underlyingType;
!                               this.underlyingField = builder.DefineField
!                                       ("value__", underlyingType,
!                                        FieldAttributes.Private | 
FieldAttributes.SpecialName);
!                       }
! 
!       // Create the final type for this enumeration.
!       public Type CreateType()
!                       {
!                               return builder.CreateType();
!                       }
! 
!       // Define a literal within this enumeration.
!       public FieldBuilder DefineLiteral(String literalName, Object 
literalValue)
!                       {
!                               FieldBuilder field;
!                               field = builder.DefineField
!                                       (literalName, builder,  // Note: use 
correct enum type.
!                                        FieldAttributes.Public | 
FieldAttributes.Static |
!                                        FieldAttributes.Literal);
!                               field.SetConstant(literalValue);
!                               return field;
!                       }
! 
!       // Invoke a specific type member.
!       public override Object InvokeMember
!                               (String name, BindingFlags invokeAttr, Binder 
binder,
!                                Object target, Object[] args, 
ParameterModifier[] modifiers,
!                                CultureInfo culture, String[] namedParameters)
!                       {
!                               return builder.InvokeMember(name, invokeAttr, 
binder,
!                                                                               
    target, args, modifiers,
!                                                                               
    culture, namedParameters);
!                       }
! 
!       // Implementation of "GetConstructor" provided by subclasses.
!       protected override ConstructorInfo
!                                       GetConstructorImpl(BindingFlags 
bindingAttr,
!                                                                      Binder 
binder,
!                                                                      
CallingConventions callingConventions,
!                                                                      Type[] 
types,
!                                                                      
ParameterModifier[] modifiers)
!                       {
!                               return builder.GetConstructor
!                                               (bindingAttr, binder, 
callingConventions,
!                                            types, modifiers);
!                       }
! 
!       // Get all constructors for this type.
!       public override ConstructorInfo[] GetConstructors(BindingFlags 
bindingAttr)
!                       {
!                               return builder.GetConstructors(bindingAttr);
!                       }
! 
!       // Get the custom attributes that are associated with this member.
!       public override Object[] GetCustomAttributes(bool inherit)
!                       {
!                               return builder.GetCustomAttributes(inherit);
!                       }
!       public override Object[] GetCustomAttributes(Type type, bool inherit)
!                       {
!                               return builder.GetCustomAttributes(type, 
inherit);
!                       }
! 
!       // Determine if custom attributes are defined for this member.
!       public override bool IsDefined(Type type, bool inherit)
!                       {
!                               return builder.IsDefined(type, inherit);
!                       }
! 
!       // Get the element type.
!       public override Type GetElementType()
!                       {
!                               return builder.GetElementType();
!                       }
! 
!       // Get an event from this type.
!       public override EventInfo GetEvent(String name, BindingFlags 
bindingAttr)
!                       {
!                               return builder.GetEvent(name, bindingAttr);
!                       }
! 
!       // Get the list of all events within this type.
!       public override EventInfo[] GetEvents()
!                       {
!                               return builder.GetEvents();
!                       }
!       public override EventInfo[] GetEvents(BindingFlags bindingAttr)
!                       {
!                               return builder.GetEvents(bindingAttr);
!                       }
! 
!       // Get a field from this type.
!       public override FieldInfo GetField(String name, BindingFlags 
bindingAttr)
!                       {
!                               return builder.GetField(name, bindingAttr);
!                       }
! 
!       // Get the list of all fields within this type.
!       public override FieldInfo[] GetFields(BindingFlags bindingAttr)
!                       {
!                               return builder.GetFields(bindingAttr);
!                       }
! 
!       // Get an interface from within this type.
!       public override Type GetInterface(String name, bool ignoreCase)
!                       {
!                               return builder.GetInterface(name, ignoreCase);
!                       }
! 
!       // Get an interface mapping for this type.
!       public override InterfaceMapping GetInterfaceMap(Type interfaceType)
!                       {
!                               return builder.GetInterfaceMap(interfaceType);
!                       }
! 
!       // Get the list of all interfaces that are implemented by this type.
!       public override Type[] GetInterfaces()
!                       {
!                               return builder.GetInterfaces();
!                       }
! 
!       // Get a list of members that have a specific name.
!       public override MemberInfo[] GetMember
!                               (String name, MemberTypes type, BindingFlags 
bindingAttr)
!                       {
!                               return builder.GetMember(name, type, 
bindingAttr);
!                       }
! 
!       // Get a list of all members in this type.
!       public override MemberInfo[] GetMembers(BindingFlags bindingAttr)
!                       {
!                               return builder.GetMembers(bindingAttr);
!                       }
! 
!       // Implementation of "GetMethod".
!       protected override MethodInfo GetMethodImpl
!                               (String name, BindingFlags bindingAttr,
!                                Binder binder, CallingConventions 
callConvention,
!                                Type[] types, ParameterModifier[] modifiers)
!                       {
!                               return builder.GetMethod(name, bindingAttr, 
binder,
!                                                                            
callConvention, types, modifiers);
!                       }
! 
!       // Get a list of all methods in this type.
!       public override MethodInfo[] GetMethods(BindingFlags bindingAttr)
!                       {
!                               return builder.GetMethods(bindingAttr);
!                       }
! 
!       // Get a nested type that is contained within this type.
!       public override Type GetNestedType(String name, BindingFlags 
bindingAttr)
!                       {
!                               return builder.GetNestedType(name, bindingAttr);
!                       }
! 
!       // Get a list of all nested types in this type.
!       public override Type[] GetNestedTypes(BindingFlags bindingAttr)
!                       {
!                               return builder.GetNestedTypes(bindingAttr);
!                       }
! 
!       // Get a list of all properites in this type.
!       public override PropertyInfo[] GetProperties(BindingFlags bindingAttr)
!                       {
!                               return builder.GetProperties(bindingAttr);
!                       }
! 
!       // Get a specific property from within this type.
!       protected override PropertyInfo GetPropertyImpl
!                               (String name, BindingFlags bindingAttr, Binder 
binder,
!                                Type returnType, Type[] types, 
ParameterModifier[] modifiers)
!                       {
!                               return builder.GetProperty(name, bindingAttr, 
binder,
!                                                                               
   returnType, types, modifiers);
!                       }
! 
!       // Get the attribute flags for this type.
!       protected override TypeAttributes GetAttributeFlagsImpl()
!                       {
!                               return builder.attr;
!                       }
! 
!       // Determine if this type has an element type.
!       protected override bool HasElementTypeImpl()
!                       {
!                               return builder.HasElementTypeImpl();
!                       }
! 
!       // Determine if this type is an array.
!       protected override bool IsArrayImpl()
!                       {
!                               return false;
!                       }
! 
!       // Determine if this type is a "by reference" type.
!       protected override bool IsByRefImpl()
!                       {
!                               return false;
!                       }
!       
!       // Determine if this type imports a COM type.
!       protected override bool IsCOMObjectImpl()
!                       {
!                               return false;
!                       }
! 
!       // Determine if this is a pointer type.
!       protected override bool IsPointerImpl()
!                       {
!                               return false;
!                       }
! 
!       // Determine if this is a primitive type.
!       protected override bool IsPrimitiveImpl()
!                       {
!                               return false;
!                       }
! 
!       // Determine if this type is a subclass of "c".
!       public override bool IsSubclassOf(Type c)
!                       {
!                               return builder.IsSubclassOf(c);
!                       }
! 
!       // Get the assembly associated with this type.
!       public override Assembly Assembly
!                       {
!                               get
!                               {
!                                       return builder.Assembly;
!                               }
!                       }
! 
!       // Get the full assembly-qualified name of this type.
!       public override String AssemblyQualifiedName
!                       {
!                               get
!                               {
!                                       return builder.AssemblyQualifiedName;
!                               }
!                       }
! 
!       // Get the full name of this type.
!       public override String FullName
!                       {
!                               get
!                               {
!                                       return builder.FullName;
!                               }
!                       }
! 
!       // Get the base type of this type.
!       public override Type BaseType
!                       {
!                               get
!                               {
!                                       return builder.BaseType;
!                               }
!                       }
! 
!       // Get the GUID of this type.
!       public override Guid GUID
!                       {
!                               get
!                               {
!                                       return builder.GUID;
!                               }
!                       }
! 
!       // Get the module associated with this type.
!       public override Module Module
!                       {
!                               get
!                               {
!                                       return builder.Module;
!                               }
!                       }
! 
!       // Get the name of this type.
!       public override String Name
!                       {
!                               get
!                               {
!                                       return builder.Name;
!                               }
!                       }
! 
!       // Get the namespace of this type.
!       public override String Namespace
!                       {
!                               get
!                               {
!                                       return builder.Namespace;
!                               }
!                       }
! 
!       // Get the type handle for this enumerated type.
!       public override RuntimeTypeHandle TypeHandle
!                       {
!                               get
!                               {
!                                       return builder.TypeHandle;
!                               }
!                       }
! 
!       // Get the token for this enumerated type.
!       public TypeToken TypeToken
!                       {
!                               get
!                               {
!                                       return builder.TypeToken;
!                               }
!                       }
! 
!       // Get the underlying field.
!       public FieldBuilder UnderlyingField
!                       {
!                               get
!                               {
!                                       return underlyingField;
!                               }
!                       }
! 
!       // Get the underlying type for this enumeration.
!       public override Type UnderlyingSystemType
!                       {
!                               get
!                               {
!                                       return underlyingType;
!                               }
!                       }
  
  }; // class EnumBuilder

Index: ILGenerator.cs
===================================================================
RCS file: 
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Reflection/Emit/ILGenerator.cs,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** ILGenerator.cs      17 Mar 2003 10:13:43 -0000      1.4
--- ILGenerator.cs      18 Mar 2003 09:54:50 -0000      1.5
***************
*** 33,36 ****
--- 33,37 ----
  {
        // Internal state.
+       private ModuleBuilder module;
        private byte[] code;
        private int offset;
***************
*** 59,64 ****
  
        // Constructor.
!       internal ILGenerator()
                        {
                                code = new byte [32];
                                offset = 0;
--- 60,66 ----
  
        // Constructor.
!       internal ILGenerator(ModuleBuilder module)
                        {
+                               this.module = module;
                                code = new byte [32];
                                offset = 0;
***************
*** 139,142 ****
--- 141,164 ----
                        }
  
+       // Emit a token value to the current method's code.
+       private void EmitToken(int token)
+                       {
+                               EmitByte(token);
+                               EmitByte(token >> 8);
+                               EmitByte(token >> 16);
+                               EmitByte(token >> 24);
+                       }
+ 
+       // Emit a token value to the current method's code and register it
+       // to have a token fixup at the end of the assembly output process.
+       private void EmitTokenWithFixup(int token)
+                       {
+                               // TODO: fixups
+                               EmitByte(token);
+                               EmitByte(token >> 8);
+                               EmitByte(token >> 16);
+                               EmitByte(token >> 24);
+                       }
+ 
        // Emit an opcode value to the current method's code and then
        // adjust the stack height information accordingly.  We use a
***************
*** 286,289 ****
--- 308,318 ----
                                EmitByte(bytes[7]);
                        }
+       public virtual void Emit(OpCode opcode, String val)
+                       {
+                               StringToken token = 
module.GetStringConstant(val);
+                               EmitOpcode(ref opcode);
+                               EmitToken(token.Token);
+                       }
+ 
  
        [TODO]
***************
*** 412,421 ****
        [TODO]
        public virtual void Emit(OpCode opcode, SignatureHelper shelper)
-       {
-               throw new NotImplementedException("Emit");
-       }
- 
-       [TODO]
-       public virtual void Emit(OpCode opcode, String val)
        {
                throw new NotImplementedException("Emit");
--- 441,444 ----

Index: ModuleBuilder.cs
===================================================================
RCS file: 
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Reflection/Emit/ModuleBuilder.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** ModuleBuilder.cs    1 Mar 2003 20:26:31 -0000       1.2
--- ModuleBuilder.cs    18 Mar 2003 09:54:50 -0000      1.3
***************
*** 55,59 ****
  
                                // Create the module type for this module.
!                               moduleType = new TypeBuilder(assembly, this, 
"<Module>",
                                                                                
         null, TypeAttributes.NotPublic,
                                                                                
         null, null,
--- 55,59 ----
  
                                // Create the module type for this module.
!                               moduleType = new TypeBuilder(this, "<Module>",
                                                                                
         null, TypeAttributes.NotPublic,
                                                                                
         null, null,
***************
*** 71,75 ****
  
        // Start a synchronized operation on this module.
!       private void StartSync()
                        {
                                assembly.StartSync();
--- 71,75 ----
  
        // Start a synchronized operation on this module.
!       internal void StartSync()
                        {
                                assembly.StartSync();
***************
*** 77,81 ****
  
        // End a synchronized operation on this module.
!       private void EndSync()
                        {
                                assembly.EndSync();
--- 77,81 ----
  
        // End a synchronized operation on this module.
!       internal void EndSync()
                        {
                                assembly.EndSync();
***************
*** 83,90 ****
  
        // Create the global functions in this module.
-       [TODO]
        public void CreateGlobalFunctions()
                        {
!                               // TODO
                        }
  
--- 83,89 ----
  
        // Create the global functions in this module.
        public void CreateGlobalFunctions()
                        {
!                               moduleType.CreateType();
                        }
  
***************
*** 102,106 ****
  
        // Define an enumerated type within this module.
-       [TODO]
        public EnumBuilder DefineEnum(String name, TypeAttributes visibility,
                                                                  Type 
underlyingType)
--- 101,104 ----
***************
*** 109,114 ****
                                {
                                        StartSync();
!                                       // TODO
!                                       return null;
                                }
                                finally
--- 107,123 ----
                                {
                                        StartSync();
!                                       int index = name.LastIndexOf('.');
!                                       String nspace;
!                                       if(index != -1)
!                                       {
!                                               nspace = name.Substring(0, 
index);
!                                               name = name.Substring(index + 
1);
!                                       }
!                                       else
!                                       {
!                                               nspace = null;
!                                       }
!                                       return new EnumBuilder(this, name, 
nspace,
!                                                                               
   visibility, underlyingType);
                                }
                                finally
***************
*** 119,123 ****
  
        // Define a global method within this module.
-       [TODO]
        public MethodBuilder DefineGlobalMethod
                                (String name, MethodAttributes attributes,
--- 128,131 ----
***************
*** 128,133 ****
                                {
                                        StartSync();
!                                       // TODO
!                                       return null;
                                }
                                finally
--- 136,146 ----
                                {
                                        StartSync();
!                                       if((attributes & 
MethodAttributes.Static) == 0)
!                                       {
!                                               throw new 
ArgumentException(_("Emit_GlobalNonStatic"));
!                                       }
!                                       return moduleType.DefineMethod
!                                               (name, attributes, 
callingConvention,
!                                                returnType, parameterTypes);
                                }
                                finally
***************
*** 146,150 ****
  
        // Define initialized data as a global field.
-       [TODO]
        public FieldBuilder DefineInitializedData
                                (String name, byte[] data, FieldAttributes 
attributes)
--- 159,162 ----
***************
*** 153,158 ****
                                {
                                        StartSync();
!                                       // TODO
!                                       return null;
                                }
                                finally
--- 165,170 ----
                                {
                                        StartSync();
!                                       return moduleType.DefineInitializedData
!                                               (name, data, attributes);
                                }
                                finally
***************
*** 163,167 ****
  
        // Define a global PInvoke method.
-       [TODO]
        public MethodBuilder DefinePInvokeMethod
                                (String name, String dllName, String entryName,
--- 175,178 ----
***************
*** 172,185 ****
                                 CharSet nativeCharSet)
                        {
!                               try
!                               {
!                                       StartSync();
!                                       // TODO
!                                       return null;
!                               }
!                               finally
!                               {
!                                       EndSync();
!                               }
                        }
        public MethodBuilder DefinePInvokeMethod
--- 183,190 ----
                                 CharSet nativeCharSet)
                        {
!                               return moduleType.DefinePInvokeMethod
!                                       (name, dllName, entryName, attributes,
!                                    callingConvention, returnType, 
parameterTypes,
!                                        nativeCallConv, nativeCharSet);
                        }
        public MethodBuilder DefinePInvokeMethod
***************
*** 191,198 ****
                                 CharSet nativeCharSet)
                        {
!                               return DefinePInvokeMethod(name, dllName, name,
!                                                                               
   attributes, callingConvention,
!                                                                               
   returnType, parameterTypes,
!                                                                               
   nativeCallConv, nativeCharSet);
                        }
  
--- 196,203 ----
                                 CharSet nativeCharSet)
                        {
!                               return moduleType.DefinePInvokeMethod
!                                       (name, dllName, name, attributes,
!                                    callingConvention, returnType, 
parameterTypes,
!                                        nativeCallConv, nativeCharSet);
                        }
  
***************
*** 221,225 ****
  
        // Define a type witin this module.
-       [TODO]
        private TypeBuilder DefineType(String name, TypeAttributes attr,
                                                                   Type parent, 
Type[] interfaces,
--- 226,229 ----
***************
*** 229,234 ****
                                {
                                        StartSync();
!                                       // TODO
!                                       return null;
                                }
                                finally
--- 233,250 ----
                                {
                                        StartSync();
!                                       int index = name.LastIndexOf('.');
!                                       String nspace;
!                                       if(index != -1)
!                                       {
!                                               nspace = name.Substring(0, 
index);
!                                               name = name.Substring(index + 
1);
!                                       }
!                                       else
!                                       {
!                                               nspace = null;
!                                       }
!                                       return new TypeBuilder(this, name, 
nspace, attr,
!                                                                               
   parent, interfaces, packSize,
!                                                                               
   typeSize, null);
                                }
                                finally
***************
*** 280,292 ****
  
        // Define uninitialized data as a global field.
-       [TODO]
        public FieldBuilder DefineUninitializedData
!                               (String name, byte[] data, FieldAttributes 
attributes)
                        {
                                try
                                {
                                        StartSync();
!                                       // TODO
!                                       return null;
                                }
                                finally
--- 296,307 ----
  
        // Define uninitialized data as a global field.
        public FieldBuilder DefineUninitializedData
!                               (String name, int size, FieldAttributes 
attributes)
                        {
                                try
                                {
                                        StartSync();
!                                       return 
moduleType.DefineUninitializedData
!                                               (name, size, attributes);
                                }
                                finally
***************
*** 407,410 ****
--- 422,429 ----
        public StringToken GetStringConstant(String str)
                        {
+                               if(str == null)
+                               {
+                                       throw new ArgumentNullException("str");
+                               }
                                // TODO
                                return new StringToken(0);

Index: TypeBuilder.cs
===================================================================
RCS file: 
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Reflection/Emit/TypeBuilder.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** TypeBuilder.cs      28 Sep 2002 10:55:13 -0000      1.2
--- TypeBuilder.cs      18 Mar 2003 09:54:50 -0000      1.3
***************
*** 32,43 ****
  using System.Security.Permissions;
  
! public sealed class TypeBuilder : Type
  {
        // Internal state.
!       private AssemblyBuilder assembly;
!       private Module module;
        private String name;
        private String nspace;
!       private TypeAttributes attr;
        private Type parent;
        private Type[] interfaces;
--- 32,42 ----
  using System.Security.Permissions;
  
! public sealed class TypeBuilder : Type, IClrProgramItem
  {
        // Internal state.
!       private ModuleBuilder module;
        private String name;
        private String nspace;
!       internal TypeAttributes attr;
        private Type parent;
        private Type[] interfaces;
***************
*** 47,50 ****
--- 46,51 ----
        private ClrType type;
        private TypeToken token;
+       private IntPtr privateData;
+       private Type underlyingSystemType;
  
        // Constants.
***************
*** 52,62 ****
  
        // Constructor.
!       internal TypeBuilder(AssemblyBuilder assembly, Module module,
!                                                String name, String nspace,
                                                 TypeAttributes attr, Type 
parent, Type[] interfaces,
                                                 PackingSize packingSize, int 
typeSize,
                                                 Type declaringType)
                        {
!                               this.assembly = assembly;
                                this.module = module;
                                this.name = name;
--- 53,80 ----
  
        // Constructor.
!       internal TypeBuilder(ModuleBuilder module, String name, String nspace,
                                                 TypeAttributes attr, Type 
parent, Type[] interfaces,
                                                 PackingSize packingSize, int 
typeSize,
                                                 Type declaringType)
                        {
!                               // Validate the parameters.
!                               if(name == null)
!                               {
!                                       throw new ArgumentNullException("name");
!                               }
!                               else if(name == String.Empty)
!                               {
!                                       throw new 
ArgumentException(_("Emit_NameEmpty"));
!                               }
!                               if(nspace == null)
!                               {
!                                       nspace = String.Empty;
!                               }
!                               // TODO
! 
!                               // Check for an existing type with this name.
!                               // TODO
! 
!                               // Initialize the internal state.
                                this.module = module;
                                this.name = name;
***************
*** 69,72 ****
--- 87,91 ----
                                this.declaringType = declaringType;
                                this.type = null;
+                               this.underlyingSystemType = null;
                                this.token = new TypeToken(0);  // TODO
                        }
***************
*** 217,226 ****
  
        // Get the underlying system type for this type.
-       [TODO]
        public override Type UnderlyingSystemType
                        {
                                get
                                {
!                                       // TODO: enumerated type handling.
                                        return this;
                                }
--- 236,259 ----
  
        // Get the underlying system type for this type.
        public override Type UnderlyingSystemType
                        {
                                get
                                {
!                                       if(type != null)
!                                       {
!                                               return 
type.UnderlyingSystemType;
!                                       }
!                                       else if(IsEnum)
!                                       {
!                                               if(underlyingSystemType != null)
!                                               {
!                                                       return 
underlyingSystemType;
!                                               }
!                                               else
!                                               {
!                                                       throw new 
InvalidOperationException
!                                                               
(_("Emit_UnderlyingNotSet"));
!                                               }
!                                       }
                                        return this;
                                }
***************
*** 249,253 ****
        private void StartSync()
                        {
!                               assembly.StartSync();
                                if(type != null)
                                {
--- 282,286 ----
        private void StartSync()
                        {
!                               module.StartSync();
                                if(type != null)
                                {
***************
*** 259,263 ****
        private void EndSync()
                        {
!                               assembly.EndSync();
                        }
  
--- 292,296 ----
        private void EndSync()
                        {
!                               module.EndSync();
                        }
  
***************
*** 403,406 ****
--- 436,444 ----
                                        StartSync();
                                        // TODO
+                                       if(IsEnum && underlyingSystemType == 
null &&
+                                          (attributes & 
FieldAttributes.Static) == 0)
+                                       {
+                                               underlyingSystemType = type;
+                                       }
                                        return null;
                                }
***************
*** 411,416 ****
                        }
  
        // Define static initialized data within this class.
-       [TODO]
        public FieldBuilder DefineInitializedData
                                (String name, byte[] data, FieldAttributes 
attributes)
--- 449,497 ----
                        }
  
+       // Define a data field within this class.
+       private FieldBuilder DefineData(String name, byte[] data,
+                                                                   int size, 
FieldAttributes attributes)
+                       {
+                               // Validate the parameters.
+                               if(name == null)
+                               {
+                                       throw new ArgumentNullException("name");
+                               }
+                               else if(name == String.Empty)
+                               {
+                                       throw new 
ArgumentException(_("Emit_NameEmpty"));
+                               }
+                               else if(size <= 0 || size > 0x003EFFFF)
+                               {
+                                       throw new 
ArgumentException(_("Emit_DataSize"));
+                               }
+ 
+                               // We must not have created the type yet.
+                               CheckNotCreated();
+ 
+                               // Look for or create a value type for the 
field.
+                               String typeName = "$ArrayType$" + 
size.ToString();
+                               Type type = module.GetType(typeName);
+                               if(type == null)
+                               {
+                                       TypeBuilder builder;
+                                       builder = module.DefineType
+                                                       (typeName,
+                                                        TypeAttributes.Public |
+                                                        TypeAttributes.Sealed |
+                                                        
TypeAttributes.ExplicitLayout,
+                                                        
typeof(System.ValueType),
+                                                        PackingSize.Size1, 
size);
+                                       type = builder.CreateType();
+                               }
+ 
+                               // Define the field and set the data on it.
+                               FieldBuilder field = DefineField
+                                       (name, type, attributes | 
FieldAttributes.Static);
+                               // TODO: set the data
+                               return field;
+                       }
+ 
        // Define static initialized data within this class.
        public FieldBuilder DefineInitializedData
                                (String name, byte[] data, FieldAttributes 
attributes)
***************
*** 419,424 ****
                                {
                                        StartSync();
!                                       // TODO
!                                       return null;
                                }
                                finally
--- 500,508 ----
                                {
                                        StartSync();
!                                       if(data == null)
!                                       {
!                                               throw new 
ArgumentNullException("data");
!                                       }
!                                       return DefineData(name, data, 
data.Length, attributes);
                                }
                                finally
***************
*** 472,476 ****
  
        // Define a nested type within this class.
-       [TODO]
        private TypeBuilder DefineNestedType
                                (String name, TypeAttributes attr, Type parent,
--- 556,559 ----
***************
*** 480,485 ****
                                {
                                        StartSync();
!                                       // TODO
!                                       return null;
                                }
                                finally
--- 563,570 ----
                                {
                                        StartSync();
!                                       return new TypeBuilder(module,
!                                                                               
   name, null, attr, parent,
!                                                                               
   interfaces, packingSize,
!                                                                               
   typeSize, this);
                                }
                                finally
***************
*** 598,603 ****
                                {
                                        StartSync();
!                                       // TODO
!                                       return null;
                                }
                                finally
--- 683,687 ----
                                {
                                        StartSync();
!                                       return DefineData(name, null, size, 
attributes);
                                }
                                finally
***************
*** 927,930 ****
--- 1011,1023 ----
                        {
                                return name;
+                       }
+ 
+       // Implement the IClrProgramItem interface.
+       IntPtr IClrProgramItem.ClrHandle
+                       {
+                               get
+                               {
+                                       return privateData;
+                               }
                        }
  





reply via email to

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