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