2009-11-10 Marek Safar <marek.safar@gmail.com>
[mono.git] / mcs / mcs / roottypes.cs
index e9d2d26bebf1cbdd38c219b296da8b2f7215ccce..0c9b6b23e7793a0f8ee41ffdf223fede16d977bf 100644 (file)
@@ -18,27 +18,60 @@ using System.Runtime.InteropServices;
 
 namespace Mono.CSharp
 {
+       //
+       // Module container, it can be used as a top-level type
+       //
+       public class ModuleContainer : TypeContainer
+       {
+               public CharSet DefaultCharSet = CharSet.Ansi;
+               public TypeAttributes DefaultCharSetType = TypeAttributes.AnsiClass;
+
+               protected Assembly assembly;
+
+               public ModuleContainer (Assembly assembly)
+                       : base (null, null, MemberName.Null, null, Kind.Root)
+               {
+                       this.assembly = assembly;
+               }
+
+               public Assembly Assembly {
+                       get { return assembly; }
+               }
+
+               // FIXME: Remove this evil one day
+               public ModuleCompiled Compiled {
+                       get { return (ModuleCompiled) this; }
+               }
+
+               public override ModuleContainer Module {
+                       get {
+                               return this;
+                       }
+               }
+       }
+
        //
        // Compiled top-level types
        //
-       public sealed class ModuleContainer : TypeContainer
+       public class ModuleCompiled : ModuleContainer
        {
                // TODO: It'd be so nice to have generics
                Hashtable anonymous_types;
-               public ModuleBuilder Builder;
-               bool is_unsafe;
+               readonly bool is_unsafe;
+               readonly CompilerContext context;
 
-               bool has_default_charset;
+               ModuleBuilder builder;
 
-               public CharSet DefaultCharSet = CharSet.Ansi;
-               public TypeAttributes DefaultCharSetType = TypeAttributes.AnsiClass;
+               bool has_default_charset;
 
                static readonly string[] attribute_targets = new string[] { "module" };
 
-               public ModuleContainer (bool isUnsafe)
-                       : base (null, null, MemberName.Null, null, Kind.Root)
+               public ModuleCompiled (CompilerContext context, bool isUnsafe)
+                       : base (null)
                {
                        this.is_unsafe = isUnsafe;
+                       this.context = context;
+
                        types = new ArrayList ();
                        anonymous_types = new Hashtable ();
                }
@@ -89,7 +122,22 @@ namespace Mono.CSharp
                                }
                        }
 
-                       Builder.SetCustomAttribute (cb);
+                       builder.SetCustomAttribute (cb);
+               }
+
+               public ModuleBuilder Builder {
+                       get {
+                               return builder;
+                       }
+
+                       set {
+                               builder = value;
+                               assembly = builder.Assembly;
+                       }
+               }
+
+               public override CompilerContext Compiler {
+                       get { return context; }
                }
 
                public override void Emit ()
@@ -98,11 +146,11 @@ namespace Mono.CSharp
                                OptAttributes.Emit ();
 
                        if (is_unsafe) {
-                               Type t = TypeManager.CoreLookupType ("System.Security", "UnverifiableCodeAttribute", Kind.Class, true);
+                               Type t = TypeManager.CoreLookupType (context, "System.Security", "UnverifiableCodeAttribute", Kind.Class, true);
                                if (t != null) {
                                        ConstructorInfo unverifiable_code_ctor = TypeManager.GetPredefinedConstructor (t, Location.Null, Type.EmptyTypes);
                                        if (unverifiable_code_ctor != null)
-                                               Builder.SetCustomAttribute (new CustomAttributeBuilder (unverifiable_code_ctor, new object [0]));
+                                               builder.SetCustomAttribute (new CustomAttributeBuilder (unverifiable_code_ctor, new object [0]));
                                }
                        }
                }
@@ -148,12 +196,6 @@ namespace Mono.CSharp
                        return true;
                }
 
-               public override ModuleContainer Module {
-                       get {
-                               return this;
-                       }
-               }
-
                protected override bool AddMemberType (DeclSpace ds)
                {
                        if (!AddToContainer (ds, ds.Name))
@@ -227,6 +269,12 @@ namespace Mono.CSharp
                        get { throw new InternalErrorException ("should not be called"); }
                }
 
+               public override CompilerContext Compiler {
+                       get {
+                               return PartialContainer.Compiler;
+                       }
+               }
+
                public override string DocCommentHeader {
                        get { throw new InternalErrorException ("should not be called"); }
                }