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