2004-03-30 Martin Baulig <martin@ximian.com>
[mono.git] / mcs / gmcs / rootcontext.cs
1 //
2 // rootcontext.cs: keeps track of our tree representation, and assemblies loaded.
3 //
4 // Author: Miguel de Icaza (miguel@ximian.com)
5 //         Ravi Pratap     (ravi@ximian.com)
6 //
7 // Licensed under the terms of the GNU GPL
8 //
9 // (C) 2001 Ximian, Inc (http://www.ximian.com)
10
11 using System;
12 using System.Collections;
13 using System.Reflection;
14 using System.Reflection.Emit;
15 using System.Diagnostics;
16
17 namespace Mono.CSharp {
18
19         public class RootContext {
20
21                 //
22                 // Contains the parsed tree
23                 //
24                 static Tree tree;
25
26                 //
27                 // This hashtable contains all of the #definitions across the source code
28                 // it is used by the ConditionalAttribute handler.
29                 //
30                 public static Hashtable AllDefines = new Hashtable ();
31                 
32                 //
33                 // Whether we are being linked against the standard libraries.
34                 // This is only used to tell whether `System.Object' should
35                 // have a parent or not.
36                 //
37                 public static bool StdLib = true;
38
39                 //
40                 // This keeps track of the order in which classes were defined
41                 // so that we can poulate them in that order.
42                 //
43                 // Order is important, because we need to be able to tell by
44                 // examining the parent's list of methods which ones are virtual
45                 // or abstract as well as the parent names (to implement new, 
46                 // override).
47                 //
48                 static ArrayList type_container_resolve_order;
49                 static ArrayList interface_resolve_order;
50                 static ArrayList attribute_types;
51
52                 //
53                 // Holds a reference to the Private Implementation Details
54                 // class.
55                 //
56                 static ArrayList helper_classes;
57                 
58                 static TypeBuilder impl_details_class;
59
60                 public static int WarningLevel = 2;
61
62                 public static Target Target = Target.Exe;
63                 public static string TargetExt = ".exe";
64
65                 //
66                 // If set, enable C# version 2 features
67                 //
68                 public static bool V2 = true;
69                 //
70                 // Constructor
71                 //
72                 static RootContext ()
73                 {
74                         tree = new Tree ();
75                         interface_resolve_order = new ArrayList ();
76                         type_container_resolve_order = new ArrayList ();
77                 }
78
79                 public static bool NeedsEntryPoint {
80                         get {
81                                 return RootContext.Target == Target.Exe || RootContext.Target == Target.WinExe;
82                         }
83                 }
84
85                 static public Tree Tree {
86                         get {
87                                 return tree;
88                         }
89                 }
90
91                 static public string MainClass;
92                 
93                 public static void RegisterOrder (Interface iface)
94                 {
95                         interface_resolve_order.Add (iface);
96                 }
97                 
98                 public static void RegisterOrder (TypeContainer tc)
99                 {
100                         type_container_resolve_order.Add (tc);
101                 }
102
103                 public static void RegisterAttribute (TypeContainer tc)
104                 {
105                         if (attribute_types == null)
106                                 attribute_types = new ArrayList ();
107                         
108                         attribute_types.Add (tc);
109                 }
110                 
111                 // 
112                 // The default compiler checked state
113                 //
114                 static public bool Checked = false;
115
116                 //
117                 // Whether to allow Unsafe code
118                 //
119                 static public bool Unsafe = false;
120                 
121                 static string MakeFQN (string nsn, string name)
122                 {
123                         if (nsn == "")
124                                 return name;
125                         return String.Concat (nsn, ".", name);
126                 }
127
128                 // <remarks>
129                 //   This function is used to resolve the hierarchy tree.
130                 //   It processes interfaces, structs and classes in that order.
131                 //
132                 //   It creates the TypeBuilder's as it processes the user defined
133                 //   types.  
134                 // </remarks>
135                 static public void ResolveTree ()
136                 {
137                         //
138                         // Process the attribute types separately and before anything else
139                         //
140                         if (attribute_types != null)
141                                 foreach (TypeContainer tc in attribute_types)
142                                         tc.DefineType ();
143                         
144                         //
145                         // Interfaces are processed next, as classes and
146                         // structs might inherit from an object or implement
147                         // a set of interfaces, we need to be able to tell
148                         // them appart by just using the TypeManager.
149                         //
150                         TypeContainer root = Tree.Types;
151
152                         ArrayList ifaces = root.Interfaces;
153                         if (ifaces != null){
154                                 foreach (Interface i in ifaces) 
155                                         i.DefineType ();
156                         }
157
158                         foreach (TypeContainer tc in root.Types)
159                                 tc.DefineType ();
160
161                         if (root.Delegates != null)
162                                 foreach (Delegate d in root.Delegates) 
163                                         d.DefineType ();
164
165                         if (root.Enums != null)
166                                 foreach (Enum e in root.Enums)
167                                         e.DefineType ();
168                 }
169
170                 static void Error_TypeConflict (string name, Location loc)
171                 {
172                         Report.Error (
173                                 520, loc, "`" + name + "' conflicts with a predefined type");
174                 }
175
176                 static void Error_TypeConflict (string name)
177                 {
178                         Report.Error (
179                                 520, "`" + name + "' conflicts with a predefined type");
180                 }
181
182                 //
183                 // Resolves a single class during the corlib bootstrap process
184                 //
185                 static TypeBuilder BootstrapCorlib_ResolveClass (TypeContainer root, string name)
186                 {
187                         object o = root.GetDefinition (name);
188                         if (o == null){
189                                 Report.Error (518, "The predefined type `" + name + "' is not defined");
190                                 return null;
191                         }
192
193                         if (!(o is Class)){
194                                 if (o is DeclSpace){
195                                         DeclSpace d = (DeclSpace) o;
196
197                                         Error_TypeConflict (name, d.Location);
198                                 } else
199                                         Error_TypeConflict (name);
200
201                                 return null;
202                         }
203
204                         return ((DeclSpace) o).DefineType ();
205                 }
206
207                 //
208                 // Resolves a struct during the corlib bootstrap process
209                 //
210                 static void BootstrapCorlib_ResolveStruct (TypeContainer root, string name)
211                 {
212                         object o = root.GetDefinition (name);
213                         if (o == null){
214                                 Report.Error (518, "The predefined type `" + name + "' is not defined");
215                                 return;
216                         }
217
218                         if (!(o is Struct)){
219                                 if (o is DeclSpace){
220                                         DeclSpace d = (DeclSpace) o;
221
222                                         Error_TypeConflict (name, d.Location);
223                                 } else
224                                         Error_TypeConflict (name);
225
226                                 return;
227                         }
228
229                         ((DeclSpace) o).DefineType ();
230                 }
231
232                 //
233                 // Resolves a struct during the corlib bootstrap process
234                 //
235                 static void BootstrapCorlib_ResolveInterface (TypeContainer root, string name)
236                 {
237                         object o = root.GetDefinition (name);
238                         if (o == null){
239                                 Report.Error (518, "The predefined type `" + name + "' is not defined");
240                                 return;
241                         }
242
243                         if (!(o is Interface)){
244                                 if (o is DeclSpace){
245                                         DeclSpace d = (DeclSpace) o;
246
247                                         Error_TypeConflict (name, d.Location);
248                                 } else
249                                         Error_TypeConflict (name);
250
251                                 return;
252                         }
253
254                         ((DeclSpace) o).DefineType ();
255                 }
256
257                 //
258                 // Resolves a delegate during the corlib bootstrap process
259                 //
260                 static void BootstrapCorlib_ResolveDelegate (TypeContainer root, string name)
261                 {
262                         object o = root.GetDefinition (name);
263                         if (o == null){
264                                 Report.Error (518, "The predefined type `" + name + "' is not defined");
265                                 Environment.Exit (0);
266                         }
267
268                         if (!(o is Delegate)){
269                                 Error_TypeConflict (name);
270                                 return;
271                         }
272
273                         ((DeclSpace) o).DefineType ();
274                 }
275                 
276
277                 /// <summary>
278                 ///    Resolves the core types in the compiler when compiling with --nostdlib
279                 /// </summary>
280                 static public void ResolveCore ()
281                 {
282                         TypeContainer root = Tree.Types;
283
284                         TypeManager.object_type = BootstrapCorlib_ResolveClass (root, "System.Object");
285                         TypeManager.value_type = BootstrapCorlib_ResolveClass (root, "System.ValueType");
286                         TypeManager.attribute_type = BootstrapCorlib_ResolveClass (root, "System.Attribute");
287                         
288                         string [] interfaces_first_stage = {
289                                 "System.IComparable", "System.ICloneable",
290                                 "System.IConvertible",
291                                 
292                                 "System.Collections.IEnumerable",
293                                 "System.Collections.ICollection",
294                                 "System.Collections.IEnumerator",
295                                 "System.Collections.IList", 
296                                 "System.IAsyncResult",
297                                 "System.IDisposable",
298                                 
299                                 "System.Runtime.Serialization.ISerializable",
300
301                                 "System.Reflection.IReflect",
302                                 "System.Reflection.ICustomAttributeProvider"
303                         };
304
305                         foreach (string iname in interfaces_first_stage)
306                                 BootstrapCorlib_ResolveInterface (root, iname);
307
308                         //
309                         // These are the base value types
310                         //
311                         string [] structs_first_stage = {
312                                 "System.Byte",    "System.SByte",
313                                 "System.Int16",   "System.UInt16",
314                                 "System.Int32",   "System.UInt32",
315                                 "System.Int64",   "System.UInt64",
316                         };
317
318                         foreach (string cname in structs_first_stage)
319                                 BootstrapCorlib_ResolveStruct (root, cname);
320
321                         //
322                         // Now, we can load the enumerations, after this point,
323                         // we can use enums.
324                         //
325                         TypeManager.InitEnumUnderlyingTypes ();
326
327                         string [] structs_second_stage = {
328                                 "System.Single",  "System.Double",
329                                 "System.Char",    "System.Boolean",
330                                 "System.Decimal", "System.Void",
331                                 "System.RuntimeFieldHandle",
332                                 "System.RuntimeTypeHandle",
333                                 "System.IntPtr"
334                         };
335                         
336                         foreach (string cname in structs_second_stage)
337                                 BootstrapCorlib_ResolveStruct (root, cname);
338                         
339                         //
340                         // These are classes that depends on the core interfaces
341                         //
342                         string [] classes_second_stage = {
343                                 "System.Reflection.MemberInfo",
344                                 "System.Type",
345                                 "System.Exception",
346
347                                 //
348                                 // These are not really important in the order, but they
349                                 // are used by the compiler later on (typemanager/CoreLookupType-d)
350                                 //
351                                 "System.Runtime.CompilerServices.RuntimeHelpers",
352                                 "System.Reflection.DefaultMemberAttribute",
353                                 "System.Threading.Monitor",
354                                 
355                                 "System.AttributeUsageAttribute",
356                                 "System.Runtime.InteropServices.DllImportAttribute",
357                                 "System.Runtime.CompilerServices.MethodImplAttribute",
358                                 "System.Runtime.InteropServices.MarshalAsAttribute",
359                                 "System.Runtime.CompilerServices.NewConstraintAttribute",
360                                 "System.Diagnostics.ConditionalAttribute",
361                                 "System.ObsoleteAttribute",
362                                 "System.ParamArrayAttribute",
363                                 "System.Security.UnverifiableCodeAttribute",
364                                 "System.Runtime.CompilerServices.IndexerNameAttribute",
365                                 "System.Runtime.InteropServices.InAttribute",
366                                 "System.InvalidOperationException"
367
368                         };
369
370                         // We must store them here before calling BootstrapCorlib_ResolveDelegate.
371                         TypeManager.string_type = BootstrapCorlib_ResolveClass (root, "System.String");
372                         TypeManager.enum_type = BootstrapCorlib_ResolveClass (root, "System.Enum");
373                         TypeManager.array_type = BootstrapCorlib_ResolveClass (root, "System.Array");
374                         TypeManager.multicast_delegate_type = BootstrapCorlib_ResolveClass (root, "System.MulticastDelegate");
375                         TypeManager.delegate_type = BootstrapCorlib_ResolveClass (root, "System.Delegate");
376                         
377                         foreach (string cname in classes_second_stage)
378                                 BootstrapCorlib_ResolveClass (root, cname);
379
380                         BootstrapCorlib_ResolveDelegate (root, "System.AsyncCallback");
381                 }
382                         
383                 // <summary>
384                 //   Closes all open types
385                 // </summary>
386                 //
387                 // <remarks>
388                 //   We usually use TypeBuilder types.  When we are done
389                 //   creating the type (which will happen after we have added
390                 //   methods, fields, etc) we need to "Define" them before we
391                 //   can save the Assembly
392                 // </remarks>
393                 static public void CloseTypes ()
394                 {
395                         TypeContainer root = Tree.Types;
396                         
397                         if (root.Enums != null)
398                                 foreach (Enum en in root.Enums)
399                                         en.CloseType ();
400
401                         if (attribute_types != null)
402                                 foreach (TypeContainer tc in attribute_types)
403                                         tc.CloseType ();
404                         
405                         foreach (Interface iface in interface_resolve_order)
406                                 iface.CloseType ();
407
408                         //
409                         // We do this in two passes, first we close the structs,
410                         // then the classes, because it seems the code needs it this
411                         // way.  If this is really what is going on, we should probably
412                         // make sure that we define the structs in order as well.
413                         //
414                         foreach (TypeContainer tc in type_container_resolve_order){
415                                 if (tc is Struct && tc.Parent == tree.Types){
416                                         tc.CloseType ();
417                                 }
418                         }
419
420                         foreach (TypeContainer tc in type_container_resolve_order){
421                                 if (!(tc is Struct && tc.Parent == tree.Types))
422                                         tc.CloseType ();                                        
423                         }
424                         
425                         if (root.Delegates != null)
426                                 foreach (Delegate d in root.Delegates)
427                                         d.CloseType ();
428
429
430                         //
431                         // If we have a <PrivateImplementationDetails> class, close it
432                         //
433                         if (helper_classes != null){
434                                 foreach (TypeBuilder type_builder in helper_classes)
435                                         type_builder.CreateType ();
436                         }
437                         
438                         attribute_types = null;
439                         interface_resolve_order = null;
440                         type_container_resolve_order = null;
441                         helper_classes = null;
442                         tree = null;
443                         TypeManager.CleanUp ();
444                 }
445
446                 /// <summary>
447                 ///   Used to register classes that need to be closed after all the
448                 ///   user defined classes
449                 /// </summary>
450                 public static void RegisterHelperClass (TypeBuilder helper_class)
451                 {
452                         if (helper_classes == null)
453                                 helper_classes = new ArrayList ();
454                         helper_classes.Add (helper_class);
455                 }
456                 
457                 //
458                 // This idea is from Felix Arrese-Igor
459                 //
460                 // Returns : the implicit parent of a composite namespace string
461                 //   eg. Implicit parent of A.B is A
462                 //
463                 static public string ImplicitParent (string ns)
464                 {
465                         int i = ns.LastIndexOf ('.');
466                         if (i < 0)
467                                 return null;
468                         
469                         return ns.Substring (0, i);
470                 }
471
472                 static Type NamespaceLookup (DeclSpace ds, string name,
473                                              int num_type_args, Location loc)
474                 {
475                         //
476                         // Try in the current namespace and all its implicit parents
477                         //
478                         for (NamespaceEntry ns = ds.NamespaceEntry; ns != null; ns = ns.ImplicitParent) {
479                                 object result = ns.Lookup (ds, name, loc);
480                                 if (result == null)
481                                         continue;
482
483                                 Type t = result as Type;
484                                 if (t != null) {
485                                         if (TypeManager.CheckGeneric (t, num_type_args))
486                                                 return t;
487                                         else
488                                                 continue;
489                                 }
490
491                                 return null;
492                         }
493
494                         return null;
495                 }
496                 
497                 static public Type LookupType (DeclSpace ds, string name, bool silent,
498                                                Location loc)
499                 {
500                         return LookupType (ds, name, silent, 0, loc);
501                 }
502
503                 //
504                 // Public function used to locate types, this can only
505                 // be used after the ResolveTree function has been invoked.
506                 //
507                 // Returns: Type or null if they type can not be found.
508                 //
509                 // Come to think of it, this should be a DeclSpace
510                 //
511                 static public Type LookupType (DeclSpace ds, string name, bool silent,
512                                                int num_type_params, Location loc)
513                 {
514                         Type t;
515
516                         if (ds.Cache.Contains (name)){
517                                 t = (Type) ds.Cache [name];
518                                 if (t != null)
519                                         return t;
520                         } else {
521                                 //
522                                 // For the case the type we are looking for is nested within this one
523                                 // or is in any base class
524                                 //
525                                 DeclSpace containing_ds = ds;
526                                 while (containing_ds != null){
527                                         Type current_type = containing_ds.TypeBuilder;
528                                         
529                                         while (current_type != null) {
530                                                 //
531                                                 // nested class
532                                                 //
533                                                 t = TypeManager.LookupType (current_type.FullName + "." + name);
534                                                 if (t != null){
535                                                         ds.Cache [name] = t;
536                                                         return t;
537                                                 }
538                                                 
539                                                 current_type = current_type.BaseType;
540                                         }
541                                         
542                                         containing_ds = containing_ds.Parent;
543                                 }
544                                 
545                                 t = NamespaceLookup (ds, name, num_type_params, loc);
546                                 if (t != null){
547                                         ds.Cache [name] = t;
548                                         return t;
549                                 }
550                         }
551
552                         if (!silent)
553                                 Report.Error (246, loc, "Cannot find type `"+name+"'");
554                         
555                         return null;
556                 }
557
558                 // <summary>
559                 //   This is the silent version of LookupType, you can use this
560                 //   to `probe' for a type
561                 // </summary>
562                 static public Type LookupType (TypeContainer tc, string name, Location loc)
563                 {
564                         return LookupType (tc, name, true, loc);
565                 }
566
567                 static public bool IsNamespace (string name)
568                 {
569                         Namespace ns;
570
571                         if (tree.Namespaces != null){
572                                 ns = (Namespace) tree.Namespaces [name];
573
574                                 if (ns != null)
575                                         return true;
576                         }
577
578                         return false;
579                 }
580
581                 static void Report1530 (Location loc)
582                 {
583                         Report.Error (1530, loc, "Keyword new not allowed for namespace elements");
584                 }
585                 
586                 static public void PopulateCoreType (TypeContainer root, string name)
587                 {
588                         DeclSpace ds = (DeclSpace) root.GetDefinition (name);
589
590                         ds.DefineMembers (root);
591                         ds.Define (root);
592                 }
593                 
594                 static public void BootCorlib_PopulateCoreTypes ()
595                 {
596                         TypeContainer root = tree.Types;
597
598                         PopulateCoreType (root, "System.Object");
599                         PopulateCoreType (root, "System.ValueType");
600                         PopulateCoreType (root, "System.Attribute");
601                 }
602                 
603                 // <summary>
604                 //   Populates the structs and classes with fields and methods
605                 // </summary>
606                 //
607                 // This is invoked after all interfaces, structs and classes
608                 // have been defined through `ResolveTree' 
609                 static public void PopulateTypes ()
610                 {
611                         TypeContainer root = Tree.Types;
612
613                         if (attribute_types != null)
614                                 foreach (TypeContainer tc in attribute_types)
615                                         tc.DefineMembers (root);
616                         
617                         if (interface_resolve_order != null){
618                                 foreach (Interface iface in interface_resolve_order)
619                                         if ((iface.ModFlags & Modifiers.NEW) == 0)
620                                                 iface.DefineMembers (root);
621                                         else
622                                                 Report1530 (iface.Location);
623                         }
624
625
626                         if (type_container_resolve_order != null){
627                                 if (RootContext.StdLib){
628                                         foreach (TypeContainer tc in type_container_resolve_order)
629                                                 tc.DefineMembers (root);
630                                 } else {
631                                         foreach (TypeContainer tc in type_container_resolve_order) {
632                                                 // When compiling corlib, these types have already been
633                                                 // populated from BootCorlib_PopulateCoreTypes ().
634                                                 if (((tc.Name == "System.Object") ||
635                                                      (tc.Name == "System.Attribute") ||
636                                                      (tc.Name == "System.ValueType")))
637                                                 continue;
638
639                                                 tc.DefineMembers (root);
640                                         }
641                                 } 
642                         }
643
644                         ArrayList delegates = root.Delegates;
645                         if (delegates != null){
646                                 foreach (Delegate d in delegates)
647                                         if ((d.ModFlags & Modifiers.NEW) == 0)
648                                                 d.DefineMembers (root);
649                                         else
650                                                 Report1530 (d.Location);
651                         }
652
653                         ArrayList enums = root.Enums;
654                         if (enums != null){
655                                 foreach (Enum en in enums)
656                                         if ((en.ModFlags & Modifiers.NEW) == 0)
657                                                 en.DefineMembers (root);
658                                         else
659                                                 Report1530 (en.Location);
660                         }
661                 }
662
663                 //
664                 // A generic hook delegate
665                 //
666                 public delegate void Hook ();
667
668                 //
669                 // A hook invoked when the code has been generated.
670                 //
671                 public static event Hook EmitCodeHook;
672
673                 //
674                 // DefineTypes is used to fill in the members of each type.
675                 //
676                 static public void DefineTypes ()
677                 {
678                         TypeContainer root = Tree.Types;
679
680                         if (attribute_types != null)
681                                 foreach (TypeContainer tc in attribute_types)
682                                         tc.Define (root);
683                         
684                         if (interface_resolve_order != null){
685                                 foreach (Interface iface in interface_resolve_order)
686                                         if ((iface.ModFlags & Modifiers.NEW) == 0)
687                                                 iface.Define (root);
688                         }
689
690
691                         if (type_container_resolve_order != null){
692                                 foreach (TypeContainer tc in type_container_resolve_order) {
693                                         // When compiling corlib, these types have already been
694                                         // populated from BootCorlib_PopulateCoreTypes ().
695                                         if (!RootContext.StdLib &&
696                                             ((tc.Name == "System.Object") ||
697                                              (tc.Name == "System.Attribute") ||
698                                              (tc.Name == "System.ValueType")))
699                                                 continue;
700
701                                         if ((tc.ModFlags & Modifiers.NEW) == 0)
702                                                 tc.Define (root);
703                                 }
704                         }
705
706                         ArrayList delegates = root.Delegates;
707                         if (delegates != null){
708                                 foreach (Delegate d in delegates)
709                                         if ((d.ModFlags & Modifiers.NEW) == 0)
710                                                 d.Define (root);
711                         }
712
713                         ArrayList enums = root.Enums;
714                         if (enums != null){
715                                 foreach (Enum en in enums)
716                                         if ((en.ModFlags & Modifiers.NEW) == 0)
717                                                 en.Define (root);
718                         }
719                 }
720
721                 static public void EmitCode ()
722                 {
723                         //
724                         // Because of the strange way in which we do things, global
725                         // attributes must be processed first.
726                         //
727                         CodeGen.Assembly.Emit ();
728                         CodeGen.Module.Emit ();
729                         
730                         if (attribute_types != null)
731                                 foreach (TypeContainer tc in attribute_types)
732                                         tc.Emit ();
733
734                         if (interface_resolve_order != null){
735                                 foreach (Interface iface in interface_resolve_order)
736                                         iface.Emit ();
737                         }                        
738                         
739                         if (type_container_resolve_order != null) {
740                                 foreach (TypeContainer tc in type_container_resolve_order)
741                                         tc.EmitConstants ();
742                                 
743                                 foreach (TypeContainer tc in type_container_resolve_order)
744                                         tc.Emit ();
745                         }
746                         
747                         //
748                         // Run any hooks after all the types have been defined.
749                         // This is used to create nested auxiliary classes for example
750                         //
751
752                         if (EmitCodeHook != null)
753                                 EmitCodeHook ();
754                 }
755                 
756                 //
757                 // Public Field, used to track which method is the public entry
758                 // point.
759                 //
760                 static public MethodInfo EntryPoint;
761
762                 //
763                 // Track the location of the entry point.
764                 //
765                 static public Location EntryPointLocation;
766
767                 //
768                 // These are used to generate unique names on the structs and fields.
769                 //
770                 static int field_count;
771                 
772                 //
773                 // Makes an initialized struct, returns the field builder that
774                 // references the data.  Thanks go to Sergey Chaban for researching
775                 // how to do this.  And coming up with a shorter mechanism than I
776                 // was able to figure out.
777                 //
778                 // This works but makes an implicit public struct $ArrayType$SIZE and
779                 // makes the fields point to it.  We could get more control if we did
780                 // use instead:
781                 //
782                 // 1. DefineNestedType on the impl_details_class with our struct.
783                 //
784                 // 2. Define the field on the impl_details_class
785                 //
786                 static public FieldBuilder MakeStaticData (byte [] data)
787                 {
788                         FieldBuilder fb;
789                         
790                         if (impl_details_class == null){
791                                 impl_details_class = CodeGen.Module.Builder.DefineType (
792                                         "<PrivateImplementationDetails>",
793                                         TypeAttributes.NotPublic,
794                                         TypeManager.object_type);
795                                 
796                                 RegisterHelperClass (impl_details_class);
797                         }
798
799                         fb = impl_details_class.DefineInitializedData (
800                                 "$$field-" + (field_count++), data,
801                                 FieldAttributes.Static | FieldAttributes.Assembly);
802                         
803                         return fb;
804                 }
805         }
806 }
807               
808