Put the merging back.
[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
308                                 "System.Reflection.IReflect",
309                                 "System.Reflection.ICustomAttributeProvider",
310
311                                 //
312                                 // Generic types
313                                 //
314                                 "System.Collections.Generic.IEnumerator`1",
315                                 "System.Collections.Generic.IEnumerable`1"
316                         };
317
318                         foreach (string iname in interfaces_first_stage)
319                                 BootstrapCorlib_ResolveInterface (root, iname);
320
321                         //
322                         // These are the base value types
323                         //
324                         string [] structs_first_stage = {
325                                 "System.Byte",    "System.SByte",
326                                 "System.Int16",   "System.UInt16",
327                                 "System.Int32",   "System.UInt32",
328                                 "System.Int64",   "System.UInt64",
329                         };
330
331                         foreach (string cname in structs_first_stage)
332                                 BootstrapCorlib_ResolveStruct (root, cname);
333
334                         //
335                         // Now, we can load the enumerations, after this point,
336                         // we can use enums.
337                         //
338                         TypeManager.InitEnumUnderlyingTypes ();
339
340                         string [] structs_second_stage = {
341                                 "System.Single",  "System.Double",
342                                 "System.Char",    "System.Boolean",
343                                 "System.Decimal", "System.Void",
344                                 "System.RuntimeFieldHandle",
345                                 "System.RuntimeArgumentHandle",
346                                 "System.RuntimeTypeHandle",
347                                 "System.IntPtr",
348                                 "System.TypedReference",
349                                 "System.ArgIterator"
350                         };
351                         
352                         foreach (string cname in structs_second_stage)
353                                 BootstrapCorlib_ResolveStruct (root, cname);
354                         
355                         //
356                         // These are classes that depends on the core interfaces
357                         //
358                         string [] classes_second_stage = {
359                                 "System.Reflection.MemberInfo",
360                                 "System.Type",
361                                 "System.Exception",
362                                 "System.Activator",
363
364                                 //
365                                 // These are not really important in the order, but they
366                                 // are used by the compiler later on (typemanager/CoreLookupType-d)
367                                 //
368                                 "System.Runtime.CompilerServices.RuntimeHelpers",
369                                 "System.Reflection.DefaultMemberAttribute",
370                                 "System.Threading.Monitor",
371                                 
372                                 "System.AttributeUsageAttribute",
373                                 "System.Runtime.InteropServices.DllImportAttribute",
374                                 "System.Runtime.CompilerServices.MethodImplAttribute",
375                                 "System.Runtime.InteropServices.MarshalAsAttribute",
376                                 "System.Runtime.CompilerServices.NewConstraintAttribute",
377                                 "System.Diagnostics.ConditionalAttribute",
378                                 "System.ObsoleteAttribute",
379                                 "System.ParamArrayAttribute",
380                                 "System.CLSCompliantAttribute",
381                                 "System.Security.UnverifiableCodeAttribute",
382                                 "System.Security.Permissions.SecurityAttribute",
383                                 "System.Runtime.CompilerServices.IndexerNameAttribute",
384                                 "System.Runtime.InteropServices.InAttribute",
385                                 "System.Runtime.InteropServices.StructLayoutAttribute",
386                                 "System.Runtime.InteropServices.FieldOffsetAttribute",
387                                 "System.InvalidOperationException",
388                                 "System.NotSupportedException",
389                                 "System.MarshalByRefObject",
390                                 "System.Security.CodeAccessPermission"
391                         };
392
393                         // We must store them here before calling BootstrapCorlib_ResolveDelegate.
394                         TypeManager.string_type = BootstrapCorlib_ResolveClass (root, "System.String");
395                         TypeManager.enum_type = BootstrapCorlib_ResolveClass (root, "System.Enum");
396                         TypeManager.array_type = BootstrapCorlib_ResolveClass (root, "System.Array");
397                         TypeManager.multicast_delegate_type = BootstrapCorlib_ResolveClass (root, "System.MulticastDelegate");
398                         TypeManager.delegate_type = BootstrapCorlib_ResolveClass (root, "System.Delegate");
399                         
400                         foreach (string cname in classes_second_stage)
401                                 BootstrapCorlib_ResolveClass (root, cname);
402
403                         BootstrapCorlib_ResolveDelegate (root, "System.AsyncCallback");
404                 }
405                         
406                 // <summary>
407                 //   Closes all open types
408                 // </summary>
409                 //
410                 // <remarks>
411                 //   We usually use TypeBuilder types.  When we are done
412                 //   creating the type (which will happen after we have added
413                 //   methods, fields, etc) we need to "Define" them before we
414                 //   can save the Assembly
415                 // </remarks>
416                 static public void CloseTypes ()
417                 {
418                         TypeContainer root = Tree.Types;
419                         
420                         if (root.Enums != null)
421                                 foreach (Enum en in root.Enums)
422                                         en.CloseType ();
423
424                         if (attribute_types != null)
425                                 foreach (TypeContainer tc in attribute_types)
426                                         tc.CloseType ();
427                         
428                         //
429                         // We do this in two passes, first we close the structs,
430                         // then the classes, because it seems the code needs it this
431                         // way.  If this is really what is going on, we should probably
432                         // make sure that we define the structs in order as well.
433                         //
434                         foreach (TypeContainer tc in type_container_resolve_order){
435                                 if (tc.Kind == Kind.Struct && tc.Parent == tree.Types){
436                                         tc.CloseType ();
437                                 }
438                         }
439
440                         foreach (TypeContainer tc in type_container_resolve_order){
441                                 if (!(tc.Kind == Kind.Struct && tc.Parent == tree.Types))
442                                         tc.CloseType ();                                        
443                         }
444                         
445                         if (root.Delegates != null)
446                                 foreach (Delegate d in root.Delegates)
447                                         d.CloseType ();
448
449
450                         //
451                         // If we have a <PrivateImplementationDetails> class, close it
452                         //
453                         if (helper_classes != null){
454                                 foreach (TypeBuilder type_builder in helper_classes)
455                                         type_builder.CreateType ();
456                         }
457                         
458                         attribute_types = null;
459                         type_container_resolve_order = null;
460                         helper_classes = null;
461                         //tree = null;
462                         TypeManager.CleanUp ();
463                 }
464
465                 /// <summary>
466                 ///   Used to register classes that need to be closed after all the
467                 ///   user defined classes
468                 /// </summary>
469                 public static void RegisterHelperClass (TypeBuilder helper_class)
470                 {
471                         if (helper_classes == null)
472                                 helper_classes = new ArrayList ();
473                         helper_classes.Add (helper_class);
474                 }
475                 
476                 //
477                 // This idea is from Felix Arrese-Igor
478                 //
479                 // Returns : the implicit parent of a composite namespace string
480                 //   eg. Implicit parent of A.B is A
481                 //
482                 static public string ImplicitParent (string ns)
483                 {
484                         int i = ns.LastIndexOf ('.');
485                         if (i < 0)
486                                 return null;
487                         
488                         return ns.Substring (0, i);
489                 }
490
491                 static TypeExpr NamespaceLookup (DeclSpace ds, string name,
492                                                  int num_type_args, Location loc)
493                 {
494                         //
495                         // Try in the current namespace and all its implicit parents
496                         //
497                         for (NamespaceEntry ns = ds.NamespaceEntry; ns != null; ns = ns.ImplicitParent) {
498                                 IAlias result = ns.Lookup (ds, name, num_type_args, false, loc);
499
500                                 if (result == null)
501                                         continue;
502
503                                 if (!result.IsType)
504                                         return null;
505
506                                 return result.Type;
507                         }
508
509                         return null;
510                 }
511                 
512                 static public TypeExpr LookupType (DeclSpace ds, string name, bool silent,
513                                                    Location loc)
514                 {
515                         return LookupType (ds, name, silent, 0, loc);
516                 }
517
518                 //
519                 // Public function used to locate types, this can only
520                 // be used after the ResolveTree function has been invoked.
521                 //
522                 // Returns: Type or null if they type can not be found.
523                 //
524                 // Come to think of it, this should be a DeclSpace
525                 //
526                 static public TypeExpr LookupType (DeclSpace ds, string name, bool silent,
527                                                    int num_type_params, Location loc)
528                 {
529                         TypeExpr t;
530
531                         if (ds.Cache.Contains (name)){
532                                 t = (TypeExpr) ds.Cache [name];
533                                 if (t != null)
534                                         return t;
535                         } else {
536                                 //
537                                 // For the case the type we are looking for is nested within this one
538                                 // or is in any base class
539                                 //
540                                 DeclSpace containing_ds = ds;
541                                 while (containing_ds != null){
542                                         Type current_type = containing_ds.TypeBuilder;
543                                         
544                                         while (current_type != null) {
545                                                 //
546                                                 // nested class
547                                                 //
548                                                 Type type = TypeManager.LookupType (current_type.FullName + "." + name);
549                                                 if (type != null){
550                                                         type = ds.ResolveNestedType (type, loc);
551                                                         t = new TypeExpression (type, loc);
552                                                         ds.Cache [name] = t;
553                                                         return t;
554                                                 }
555                                                 
556                                                 current_type = current_type.BaseType;
557                                         }
558                                         
559                                         containing_ds = containing_ds.Parent;
560                                 }
561                                 
562                                 t = NamespaceLookup (ds, name, num_type_params, loc);
563                                 if (t != null){
564                                         ds.Cache [name] = t;
565                                         return t;
566                                 }
567                         }
568
569                         if (!silent)
570                                 Report.Error (246, loc, "Cannot find type `"+name+"'");
571                         
572                         return null;
573                 }
574
575                 // <summary>
576                 //   This is the silent version of LookupType, you can use this
577                 //   to `probe' for a type
578                 // </summary>
579                 static public TypeExpr LookupType (TypeContainer tc, string name, Location loc)
580                 {
581                         return LookupType (tc, name, true, loc);
582                 }
583
584                 static void Report1530 (Location loc)
585                 {
586                         Report.Error (1530, loc, "Keyword new not allowed for namespace elements");
587                 }
588                 
589                 static public void PopulateCoreType (TypeContainer root, string name)
590                 {
591                         DeclSpace ds = (DeclSpace) root.GetDefinition (name);
592
593                         ds.DefineMembers (root);
594                         ds.Define ();
595                 }
596                 
597                 static public void BootCorlib_PopulateCoreTypes ()
598                 {
599                         TypeContainer root = tree.Types;
600
601                         PopulateCoreType (root, "System.Object");
602                         PopulateCoreType (root, "System.ValueType");
603                         PopulateCoreType (root, "System.Attribute");
604                 }
605                 
606                 // <summary>
607                 //   Populates the structs and classes with fields and methods
608                 // </summary>
609                 //
610                 // This is invoked after all interfaces, structs and classes
611                 // have been defined through `ResolveTree' 
612                 static public void PopulateTypes ()
613                 {
614                         TypeContainer root = Tree.Types;
615
616                         if (attribute_types != null)
617                                 foreach (TypeContainer tc in attribute_types)
618                                         tc.DefineMembers (root);
619
620                         if (type_container_resolve_order != null){
621                                 if (RootContext.StdLib){
622                                         foreach (TypeContainer tc in type_container_resolve_order)
623                                                 tc.DefineMembers (root);
624                                 } else {
625                                         foreach (TypeContainer tc in type_container_resolve_order) {
626                                                 // When compiling corlib, these types have already been
627                                                 // populated from BootCorlib_PopulateCoreTypes ().
628                                                 if (((tc.Name == "System.Object") ||
629                                                      (tc.Name == "System.Attribute") ||
630                                                      (tc.Name == "System.ValueType")))
631                                                 continue;
632
633                                                 tc.DefineMembers (root);
634                                         }
635                                 } 
636                         }
637
638                         ArrayList delegates = root.Delegates;
639                         if (delegates != null){
640                                 foreach (Delegate d in delegates)
641                                         if ((d.ModFlags & Modifiers.NEW) == 0)
642                                                 d.DefineMembers (root);
643                                         else
644                                                 Report1530 (d.Location);
645                         }
646
647                         ArrayList enums = root.Enums;
648                         if (enums != null){
649                                 foreach (Enum en in enums)
650                                         if ((en.ModFlags & Modifiers.NEW) == 0)
651                                                 en.DefineMembers (root);
652                                         else
653                                                 Report1530 (en.Location);
654                         }
655
656                         //
657                         // Check for cycles in the struct layout
658                         //
659                         if (type_container_resolve_order != null){
660                                 Hashtable seen = new Hashtable ();
661                                 foreach (TypeContainer tc in type_container_resolve_order)
662                                         TypeManager.CheckStructCycles (tc, seen);
663                         }
664                 }
665
666                 //
667                 // A generic hook delegate
668                 //
669                 public delegate void Hook ();
670
671                 //
672                 // A hook invoked when the code has been generated.
673                 //
674                 public static event Hook EmitCodeHook;
675
676                 //
677                 // DefineTypes is used to fill in the members of each type.
678                 //
679                 static public void DefineTypes ()
680                 {
681                         TypeContainer root = Tree.Types;
682
683                         if (attribute_types != null)
684                                 foreach (TypeContainer tc in attribute_types)
685                                         tc.Define ();
686
687                         if (type_container_resolve_order != null){
688                                 foreach (TypeContainer tc in type_container_resolve_order) {
689                                         // When compiling corlib, these types have already been
690                                         // populated from BootCorlib_PopulateCoreTypes ().
691                                         if (!RootContext.StdLib &&
692                                             ((tc.Name == "System.Object") ||
693                                              (tc.Name == "System.Attribute") ||
694                                              (tc.Name == "System.ValueType")))
695                                                 continue;
696
697                                         if ((tc.ModFlags & Modifiers.NEW) == 0)
698                                                 tc.Define ();
699                                 }
700                         }
701
702                         ArrayList delegates = root.Delegates;
703                         if (delegates != null){
704                                 foreach (Delegate d in delegates)
705                                         if ((d.ModFlags & Modifiers.NEW) == 0)
706                                                 d.Define ();
707                         }
708
709                         ArrayList enums = root.Enums;
710                         if (enums != null){
711                                 foreach (Enum en in enums)
712                                         if ((en.ModFlags & Modifiers.NEW) == 0)
713                                                 en.Define ();
714                         }
715                 }
716
717                 static public void EmitCode ()
718                 {
719                         if (attribute_types != null)
720                                 foreach (TypeContainer tc in attribute_types)
721                                         tc.EmitType ();
722
723                         CodeGen.Assembly.Emit (Tree.Types);
724                         CodeGen.Module.Emit (Tree.Types);
725                         
726                         if (Tree.Types.Enums != null) {
727                                 foreach (Enum e in Tree.Types.Enums)
728                                         e.Emit ();
729                         }
730
731                         if (type_container_resolve_order != null) {
732                                 foreach (TypeContainer tc in type_container_resolve_order)
733                                         tc.EmitType ();
734                         }
735                         
736                         if (Tree.Types.Delegates != null) {
737                                 foreach (Delegate d in Tree.Types.Delegates)
738                                         d.Emit ();
739                         }                       
740                         //
741                         // Run any hooks after all the types have been defined.
742                         // This is used to create nested auxiliary classes for example
743                         //
744
745                         if (EmitCodeHook != null)
746                                 EmitCodeHook ();
747                 }
748                 
749                 //
750                 // Public Field, used to track which method is the public entry
751                 // point.
752                 //
753                 static public MethodInfo EntryPoint;
754
755                 //
756                 // Track the location of the entry point.
757                 //
758                 static public Location EntryPointLocation;
759
760                 //
761                 // These are used to generate unique names on the structs and fields.
762                 //
763                 static int field_count;
764                 
765                 //
766                 // Makes an initialized struct, returns the field builder that
767                 // references the data.  Thanks go to Sergey Chaban for researching
768                 // how to do this.  And coming up with a shorter mechanism than I
769                 // was able to figure out.
770                 //
771                 // This works but makes an implicit public struct $ArrayType$SIZE and
772                 // makes the fields point to it.  We could get more control if we did
773                 // use instead:
774                 //
775                 // 1. DefineNestedType on the impl_details_class with our struct.
776                 //
777                 // 2. Define the field on the impl_details_class
778                 //
779                 static public FieldBuilder MakeStaticData (byte [] data)
780                 {
781                         FieldBuilder fb;
782                         
783                         if (impl_details_class == null){
784                                 impl_details_class = CodeGen.Module.Builder.DefineType (
785                                         "<PrivateImplementationDetails>",
786                                         TypeAttributes.NotPublic,
787                                         TypeManager.object_type);
788                                 
789                                 RegisterHelperClass (impl_details_class);
790                         }
791
792                         fb = impl_details_class.DefineInitializedData (
793                                 "$$field-" + (field_count++), data,
794                                 FieldAttributes.Static | FieldAttributes.Assembly);
795                         
796                         return fb;
797                 }
798         }
799 }
800               
801