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