2009-10-23 Marek Safar <marek.safar@gmail.com>
authorMarek Safar <marek.safar@gmail.com>
Fri, 23 Oct 2009 07:42:36 +0000 (07:42 -0000)
committerMarek Safar <marek.safar@gmail.com>
Fri, 23 Oct 2009 07:42:36 +0000 (07:42 -0000)
* typemanager.cs, eval.cs, decl.cs, roottypes.cs, context.cs,
anonymous.cs, expression.cs, rootcontext.cs, ecore.cs, class.cs,
flowanalysis.cs, cs-parser.jay, driver.cs, codegen.cs: Split
ModuleContainer. Add common unclosed member check routine.

svn path=/trunk/mcs/; revision=144719

15 files changed:
mcs/mcs/ChangeLog
mcs/mcs/anonymous.cs
mcs/mcs/class.cs
mcs/mcs/codegen.cs
mcs/mcs/context.cs
mcs/mcs/cs-parser.jay
mcs/mcs/decl.cs
mcs/mcs/driver.cs
mcs/mcs/ecore.cs
mcs/mcs/eval.cs
mcs/mcs/expression.cs
mcs/mcs/flowanalysis.cs
mcs/mcs/rootcontext.cs
mcs/mcs/roottypes.cs
mcs/mcs/typemanager.cs

index 83e30e393d33eadd1cfdb205b5dedef2321d570d..69bd9becc6eed22d04654c207e91aee8e3e9a944 100644 (file)
@@ -1,3 +1,10 @@
+2009-10-23  Marek Safar  <marek.safar@gmail.com>
+
+       * typemanager.cs, eval.cs, decl.cs, roottypes.cs, context.cs,
+       anonymous.cs, expression.cs, rootcontext.cs, ecore.cs, class.cs,
+       flowanalysis.cs, cs-parser.jay, driver.cs, codegen.cs: Split
+       ModuleContainer. Add common unclosed member check routine.
+
 2009-10-22  Marek Safar  <marek.safar@gmail.com>
 
        * argument.cs: Use literal flag for real literals only.
index 4932b04d30785814ce6296cdff57572c9b4d3b23..1b9a14101ae099e13f437259ddcceb539fd8006e 100644 (file)
@@ -506,7 +506,7 @@ namespace Mono.CSharp {
                                Type t = MutateGenericType (method.DeclaringType);
                                if (t != method.DeclaringType) {
                                        method = (MethodInfo) TypeManager.DropGenericMethodArguments (method);
-                                       if (method.Module == Module.Builder)
+                                       if (TypeManager.IsBeingCompiled (method))
                                                method = TypeBuilder.GetMethod (t, method);
                                        else
                                                method = (MethodInfo) MethodInfo.GetMethodFromHandle (method.MethodHandle, t.TypeHandle);
@@ -528,7 +528,7 @@ namespace Mono.CSharp {
                                Type t = MutateGenericType (ctor.DeclaringType);
                                if (t != ctor.DeclaringType) {
                                        ctor = (ConstructorInfo) TypeManager.DropGenericMethodArguments (ctor);
-                                       if (ctor.Module == Module.Builder)
+                                       if (TypeManager.IsBeingCompiled (ctor))
                                                return TypeBuilder.GetConstructor (t, ctor);
                                                
                                        return (ConstructorInfo) ConstructorInfo.GetMethodFromHandle (ctor.MethodHandle, t.TypeHandle);
@@ -544,7 +544,7 @@ namespace Mono.CSharp {
                                Type t = MutateGenericType (field.DeclaringType);
                                if (t != field.DeclaringType) {
                                        field = TypeManager.DropGenericTypeArguments (field.DeclaringType).GetField (field.Name, TypeManager.AllMembers);
-                                       if (field.Module == Module.Builder)
+                                       if (TypeManager.IsBeingCompiled (field))
                                                return TypeBuilder.GetField (t, field);
 
                                        return FieldInfo.GetFieldFromHandle (field.FieldHandle, t.TypeHandle);                                          
index 941643913049bfab19b0f5f627b063bcb28ec88c..eaa359d928b89b006b21721e21f2511da2591861 100644 (file)
@@ -1007,7 +1007,7 @@ namespace Mono.CSharp {
                                                return false;
                                        }
 
-                                       ModuleBuilder builder = Module.Builder;
+                                       ModuleBuilder builder = Module.Compiled.Builder;
                                        TypeBuilder = builder.DefineType (
                                                Name, TypeAttr, default_parent, type_size);
                                } else {
@@ -3545,7 +3545,7 @@ namespace Mono.CSharp {
                                // which has InternalsVisibleTo
                                //
                                if ((thisp & MethodAttributes.FamORAssem) == MethodAttributes.FamORAssem){
-                                       return TypeManager.IsThisOrFriendAssembly (Parent.Module.Builder.Assembly, base_method.DeclaringType.Assembly);
+                                       return TypeManager.IsThisOrFriendAssembly (Parent.Module.Assembly, base_method.DeclaringType.Assembly);
                                } else if ((thisp & MethodAttributes.Family) != MethodAttributes.Family) {
                                        //
                                        // if it's not "protected internal", it must be "protected"
index 060ea2e450bc7fd1da00d5d48e91df10e850fd86..f2bd9b8e36f8bd8c12acdfff21a15948dd9db529 100644 (file)
@@ -97,7 +97,7 @@ namespace Mono.CSharp {
                        AssemblyName an = Assembly.GetAssemblyName (name, name);
                        
                        Assembly.Builder = current_domain.DefineDynamicAssembly (an, AssemblyBuilderAccess.Run | COMPILER_ACCESS);
-                       RootContext.ToplevelTypes = new ModuleContainer (ctx, true);
+                       RootContext.ToplevelTypes = new ModuleCompiled (ctx, true);
                        RootContext.ToplevelTypes.Builder = Assembly.Builder.DefineDynamicModule (Basename (name), false);
                        Assembly.Name = Assembly.Builder.GetName ();
                }
index 71d19c7a3e83287bc0775ce27030e5a0d5fe263e..bc703083888f23c475929231147d332d005e7eb9 100644 (file)
@@ -320,6 +320,9 @@ namespace Mono.CSharp
 
                public ResolveContext (IMemberContext mc)
                {
+                       if (mc == null)
+                               throw new ArgumentNullException ();
+
                        MemberContext = mc;
 
                        //
@@ -651,4 +654,4 @@ namespace Mono.CSharp
                        return new FlagsHandle (this, options, enable ? options : 0);
                }
        }
-}
\ No newline at end of file
+}
index 36f193aab0df1b9020d2828916f6b556fb6c04fe..ab7b09bc278cb2b922ad1064c20692ac06436857 100644 (file)
@@ -671,7 +671,7 @@ attribute_sections
 
                        if (global_attrs_enabled) {
                                if (current_attr_target == "module") {
-                                       current_container.Module.AddAttributes (sect);
+                                       current_container.Module.Compiled.AddAttributes (sect);
                                        $$ = null;
                                } else if (current_attr_target != null && current_attr_target.Length > 0) {
                                        CodeGen.Assembly.AddAttributes (sect, current_namespace);
@@ -702,7 +702,7 @@ attribute_sections
 
                        if (global_attrs_enabled) {
                                if (current_attr_target == "module") {
-                                       current_container.Module.AddAttributes (sect);
+                                       current_container.Module.Compiled.AddAttributes (sect);
                                        $$ = null;
                                } else if (current_attr_target == "assembly") {
                                        CodeGen.Assembly.AddAttributes (sect, current_namespace);
index e3d108c85bf07c23664c192b5b25a544ef5f9e5e..58ed6313dd972a640a53f8bec7c3d3d6719d30a3 100644 (file)
@@ -585,7 +585,7 @@ namespace Mono.CSharp {
                                        switch (pAccess) {
                                        case AccessLevel.Internal:
                                                if (al == AccessLevel.Private || al == AccessLevel.Internal)
-                                                       same_access_restrictions = TypeManager.IsThisOrFriendAssembly (Parent.Module.Builder.Assembly, p.Assembly);
+                                                       same_access_restrictions = TypeManager.IsThisOrFriendAssembly (Parent.Module.Assembly, p.Assembly);
                                                
                                                break;
                                                
@@ -613,10 +613,10 @@ namespace Mono.CSharp {
                                                if (al == AccessLevel.Protected)
                                                        same_access_restrictions = mc.Parent.IsBaseType (p_parent);
                                                else if (al == AccessLevel.Internal)
-                                                       same_access_restrictions = TypeManager.IsThisOrFriendAssembly (Parent.Module.Builder.Assembly, p.Assembly);
+                                                       same_access_restrictions = TypeManager.IsThisOrFriendAssembly (Parent.Module.Assembly, p.Assembly);
                                                else if (al == AccessLevel.ProtectedOrInternal)
                                                        same_access_restrictions = mc.Parent.IsBaseType (p_parent) &&
-                                                               TypeManager.IsThisOrFriendAssembly (Parent.Module.Builder.Assembly, p.Assembly);
+                                                               TypeManager.IsThisOrFriendAssembly (Parent.Module.Assembly, p.Assembly);
                                                
                                                break;
                                                
@@ -1113,7 +1113,7 @@ namespace Mono.CSharp {
                                return true;
 
                        case TypeAttributes.NotPublic:
-                               return TypeManager.IsThisOrFriendAssembly (Module.Builder.Assembly, check_type.Assembly);
+                               return TypeManager.IsThisOrFriendAssembly (Module.Assembly, check_type.Assembly);
                                
                        case TypeAttributes.NestedPublic:
                                return CheckAccessLevel (check_type.DeclaringType);
@@ -1129,15 +1129,15 @@ namespace Mono.CSharp {
                                return FamilyAccessible (tb, check_type);
 
                        case TypeAttributes.NestedFamANDAssem:
-                               return TypeManager.IsThisOrFriendAssembly (Module.Builder.Assembly, check_type.Assembly) && 
+                               return TypeManager.IsThisOrFriendAssembly (Module.Assembly, check_type.Assembly) && 
                                        FamilyAccessible (tb, check_type);
 
                        case TypeAttributes.NestedFamORAssem:
                                return FamilyAccessible (tb, check_type) ||
-                                       TypeManager.IsThisOrFriendAssembly (Module.Builder.Assembly, check_type.Assembly);
+                                       TypeManager.IsThisOrFriendAssembly (Module.Assembly, check_type.Assembly);
 
                        case TypeAttributes.NestedAssembly:
-                               return TypeManager.IsThisOrFriendAssembly (Module.Builder.Assembly, check_type.Assembly);
+                               return TypeManager.IsThisOrFriendAssembly (Module.Assembly, check_type.Assembly);
                        }
 
                        throw new NotImplementedException (check_attr.ToString ());
index 32a2495f6c3ae8d100a3c66d93808e7ba6b45071..a851fa243e24798cf4003c92596befc4cd23705d 100644 (file)
@@ -1638,7 +1638,7 @@ namespace Mono.CSharp
                public bool Compile ()
                {
                        // TODO: Should be passed to parser as an argument
-                       RootContext.ToplevelTypes = new ModuleContainer (ctx, RootContext.Unsafe);
+                       RootContext.ToplevelTypes = new ModuleCompiled (ctx, RootContext.Unsafe);
 
                        Parse ();
                        if (Report.Errors > 0)
index 960ef278a89968ceb9be799ab36213c1b94903c7..76d7e242156cd22a2df78cc380ac1e418fb083e3 100644 (file)
@@ -1743,7 +1743,7 @@ namespace Mono.CSharp {
                        //
                        // This works only sometimes
                        //
-                       if (type.Module == RootContext.ToplevelTypes.Builder)
+                       if (TypeManager.IsBeingCompiled (type))
                                return Child.GetValue ();
 #endif
 
index 28ab1f96f43829e5fb73520b9394233ecd12b7fb..a450d6b5186df1c7754add6b76748b531f4a7a5c 100644 (file)
@@ -113,7 +113,7 @@ namespace Mono.CSharp {
                                if (driver == null)
                                        throw new Exception ("Failed to create compiler driver with the given arguments");
 
-                               RootContext.ToplevelTypes = new ModuleContainer (ctx, true);
+                               RootContext.ToplevelTypes = new ModuleCompiled (ctx, true);
                                
                                driver.ProcessDefaultConfig ();
 
@@ -122,7 +122,7 @@ namespace Mono.CSharp {
                                        startup_files.Add (file.Path);
                                
                                CompilerCallableEntryPoint.Reset ();
-                               RootContext.ToplevelTypes = new ModuleContainer (ctx, true);
+                               RootContext.ToplevelTypes = new ModuleCompiled (ctx, true);
 
                                driver.LoadReferences ();
                                RootContext.EvalMode = true;
@@ -147,7 +147,7 @@ namespace Mono.CSharp {
                                new StreamReportPrinter (MessageOutput);
 
                        ctx = new CompilerContext (new Report (printer));
-                       RootContext.ToplevelTypes = new ModuleContainer (ctx, true);
+                       RootContext.ToplevelTypes = new ModuleCompiled (ctx, true);
 
                        //
                        // PartialReset should not reset the core types, this is very redundant.
index 24afdeb9e0183678cfc1903495c2c77075cd8bea..d77b452517a2481af459d26d6ccb9dd08c5d6b5c 100644 (file)
@@ -5043,7 +5043,7 @@ namespace Mono.CSharp {
                                return false;
 
                        method = TypeManager.DropGenericMethodArguments (method);
-                       if (method.DeclaringType.Module == RootContext.ToplevelTypes.Builder) {
+                       if (TypeManager.IsBeingCompiled (method)) {
                                IMethodData md = TypeManager.GetMethod (method);
                                if (md != null)
                                        return md.IsExcluded ();
@@ -9719,7 +9719,7 @@ namespace Mono.CSharp {
 
                AnonymousTypeClass CreateAnonymousType (ResolveContext ec, ArrayList parameters)
                {
-                       AnonymousTypeClass type = parent.Module.GetAnonymousType (parameters);
+                       AnonymousTypeClass type = parent.Module.Compiled.GetAnonymousType (parameters);
                        if (type != null)
                                return type;
 
@@ -9733,7 +9733,7 @@ namespace Mono.CSharp {
                        if (ec.Report.Errors == 0)
                                type.CloseType ();
 
-                       parent.Module.AddAnonymousType (type);
+                       parent.Module.Compiled.AddAnonymousType (type);
                        return type;
                }
 
index 0a835cd851d55366b89de6f0cdf8d38263eae651..c9f58f9fc1b1e3267e5bbe16be1056193bfeb053 100644 (file)
@@ -1202,7 +1202,7 @@ namespace Mono.CSharp
 
                                field_type_hash.Add (type, this);
 
-                               if (type.Module == RootContext.ToplevelTypes.Builder) {
+                               if (TypeManager.IsBeingCompiled (type)) {
                                        TypeContainer tc = TypeManager.LookupTypeContainer (TypeManager.DropGenericTypeArguments (type));
 
                                        ArrayList public_fields = new ArrayList ();
index 06daafad5e4bb608573b0d9239c77b3146db49b8..b11fa309176c2b5fbfd4daa0665d6b690a3e9885 100644 (file)
@@ -108,7 +108,7 @@ namespace Mono.CSharp {
                //
                // Contains the parsed tree
                //
-               static ModuleContainer root;
+               static ModuleCompiled root;
 
                //
                // This hashtable contains all of the #definitions across the source code
@@ -191,7 +191,7 @@ namespace Mono.CSharp {
                        return AllDefines.Contains (value);
                }
 
-               static public ModuleContainer ToplevelTypes {
+               static public ModuleCompiled ToplevelTypes {
                        get { return root; }
                        set { root = value; }
                }
index cb823e1a7fe992b1559a1e8822578a842729e093..0c9b6b23e7793a0f8ee41ffdf223fede16d977bf 100644 (file)
@@ -18,26 +18,56 @@ 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;
                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 (CompilerContext context, 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;
@@ -92,7 +122,18 @@ 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 {
@@ -109,7 +150,7 @@ namespace Mono.CSharp
                                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]));
                                }
                        }
                }
@@ -155,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))
index 051caa48e1ce23be0c23efd85f1111fe2051f1f8..715d0321577f067493e6ca1a8a558a42c5815233 100644 (file)
@@ -333,7 +333,7 @@ namespace Mono.CSharp {
 
        public static MemberCache LookupMemberCache (Type t)
        {
-               if (t.Module == RootContext.ToplevelTypes.Builder) {
+               if (IsBeingCompiled (t)) {
                        DeclSpace container = (DeclSpace)builder_to_declspace [t];
                        if (container != null)
                                return container.MemberCache;
@@ -790,7 +790,7 @@ namespace Mono.CSharp {
                        return t;
 
                // TODO: All predefined imported types have to have correct signature
-               if (t.Module != RootContext.ToplevelTypes.Builder)
+               if (!IsBeingCompiled (t))
                        return t;
 
                DeclSpace ds = (DeclSpace)RootContext.ToplevelTypes.GetDefinition (t.FullName);
@@ -1238,6 +1238,14 @@ namespace Mono.CSharp {
                return cache.FindMembers (mt, bf, name, FilterWithClosure_delegate, null);
        }
 
+       //
+       // Return true for SRE dynamic/unclosed members
+       //
+       public static bool IsBeingCompiled (MemberInfo mi)
+       {
+               return mi.Module.Assembly == RootContext.ToplevelTypes.Module.Assembly;
+       }
+
        public static bool IsBuiltinType (Type t)
        {
                t = TypeToCoreType (t);
@@ -1285,7 +1293,7 @@ namespace Mono.CSharp {
                if (t != object_type)
                        return false;
 
-               if (t.Module == RootContext.ToplevelTypes.Builder)
+               if (IsBeingCompiled (t))
                        return false;
 
                PredefinedAttribute pa = PredefinedAttributes.Get.Dynamic;