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