2007-06-11 Marek Safar <marek.safar@gmail.com>
authorMarek Safar <marek.safar@gmail.com>
Mon, 11 Jun 2007 20:40:50 +0000 (20:40 -0000)
committerMarek Safar <marek.safar@gmail.com>
Mon, 11 Jun 2007 20:40:50 +0000 (20:40 -0000)
* class.cs (DefineBaseTypes): Base type can be undefined.

* ecore.cs (TypeLookup): Minor refactoring.
(DoResolveAsTypeStep): Removed redundant check.

* namespace.cs (Lookup): Removed redundant check.

* rootcontext.cs (BootstrapCorlib_ResolveType): Uses normal
ResolveAsTypeTerminal step.
(BootstrapCorlib_*): Simplified.
(PopulateCoreType): Core types can be now external.

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

mcs/mcs/ChangeLog
mcs/mcs/class.cs
mcs/mcs/ecore.cs
mcs/mcs/namespace.cs
mcs/mcs/rootcontext.cs

index fdb46bcee9c4b78cc64ff5b84e643242037e3750..3684717fde582e70bc410f4ed9e88fbdb986c56c 100644 (file)
@@ -1,3 +1,17 @@
+2007-06-11  Marek Safar  <marek.safar@gmail.com>
+
+       * class.cs (DefineBaseTypes): Base type can be undefined.
+       
+       * ecore.cs (TypeLookup): Minor refactoring.
+       (DoResolveAsTypeStep): Removed redundant check.
+
+       * namespace.cs (Lookup): Removed redundant check.
+               
+       * rootcontext.cs (BootstrapCorlib_ResolveType): Uses normal 
+       ResolveAsTypeTerminal step.
+       (BootstrapCorlib_*): Simplified.
+       (PopulateCoreType): Core types can be now external.
+
 2007-06-07  Marek Safar  <marek.safar@gmail.com>
 
        * anonymous.cs (VerifyExplicitParameterCompatibility): Add flag to do
index 9402ad7686d48f2a88ec06d1d8126fefe6ffd8ba..6ad16011f1298cde5cb80731785f697f70a2f9d2 100644 (file)
@@ -1119,7 +1119,7 @@ namespace Mono.CSharp {
                        if (!CheckRecursiveDefinition (this))
                                return false;
 
-                       if (base_type != null) {
+                       if (base_type != null && base_type.Type != null) {
                                TypeBuilder.SetParent (base_type.Type);
 
                                ObsoleteAttribute obsolete_attr = AttributeTester.GetObsoleteAttribute (base_type.Type);
@@ -1452,7 +1452,7 @@ namespace Mono.CSharp {
 
                        InTransit = tc;
 
-                       if (base_type != null) {
+                       if (base_type != null && base_type.Type != null) {
                                Type t = TypeManager.DropGenericTypeArguments (base_type.Type);
                                TypeContainer ptc = TypeManager.LookupTypeContainer (t);
                                if ((ptc != null) && !ptc.CheckRecursiveDefinition (this))
index 916d5d48cb6fe945b1683fbb264dd3a6ae3103c2..08f3b2c8039d6482b4f2803100967fa86d899a91 100644 (file)
@@ -2623,14 +2623,17 @@ namespace Mono.CSharp {
 
                                if (type != null)
                                        return TypeManager.GetNestedType (type, substring);
-                               else if (resolved != null) {
+                               
+                               if (resolved != null) {
                                        resolved = (resolved as Namespace).Lookup (ec.DeclContainer, substring, Location.Null);
                                        if (resolved is TypeExpr)
                                                return resolved.Type;
-                                       else {
-                                               resolved.Error_UnexpectedKind (ec.DeclContainer, "type", loc);
-                                               return typeof (UnexpectedType);
-                                       }
+                                       
+                                       if (resolved == null)
+                                               return null;
+                                       
+                                       resolved.Error_UnexpectedKind (ec.DeclContainer, "type", loc);
+                                       return typeof (UnexpectedType);
                                }
                                else
                                        return null;
@@ -2642,11 +2645,11 @@ namespace Mono.CSharp {
                protected override TypeExpr DoResolveAsTypeStep (IResolveContext ec)
                {
                        Type t = TypeLookup (ec, name);
-                       if (t == null || !ec.DeclContainer.CheckAccessLevel (t)) {
+                       if (t == null) {
                                NamespaceEntry.Error_NamespaceNotFound (loc, name);
                                return null;
                        }
-                       else if (t == typeof(UnexpectedType))
+                       if (t == typeof(UnexpectedType))
                                return null;
                        type = t;
                        return this;
index 28cf7eb818aba4f7b0dbb419f509744f7ef7210d..ee22c1a9080aa64050615834147b068dc2b2abbe 100644 (file)
@@ -463,11 +463,7 @@ namespace Mono.CSharp {
                        if (namespaces.Contains (name))
                                return (Namespace) namespaces [name];
 
-                       TypeExpr te = LookupType (name, loc);
-                       if (te == null || !ds.CheckAccessLevel (te.Type))
-                               return null;
-
-                       return te;
+                       return LookupType (name, loc);
                }
 
                public void RegisterExternalExtensionMethodClass (Type type)
index 9eb5fdae489425a26ca8e12048d9b8cccb147720..46cd399c239adc358e1a59055d38eb5bd395a28c 100644 (file)
@@ -2,7 +2,9 @@
 // rootcontext.cs: keeps track of our tree representation, and assemblies loaded.
 //
 // Author: Miguel de Icaza (miguel@ximian.com)
-//         Ravi Pratap     (ravi@ximian.com)
+//            Ravi Pratap  (ravi@ximian.com)
+//            Marek Safar  (marek.safar@gmail.com)
+//
 //
 // Licensed under the terms of the GNU GPL
 //
@@ -170,96 +172,79 @@ namespace Mono.CSharp {
                                        d.DefineType ();
                }
 
-               static void Error_TypeConflict (string name, Location loc)
-               {
-                       Report.Error (
-                               520, loc, "`" + name + "' conflicts with a predefined type");
-               }
+               delegate bool VerifyBootstrapType (Type t);
 
-               static void Error_TypeConflict (string name)
-               {
-                       Report.Error (
-                               520, "`" + name + "' conflicts with a predefined type");
-               }
-
-               //
-               // Resolves a single class during the corlib bootstrap process
-               //
-               static Type BootstrapCorlib_ResolveClass (TypeContainer root, string name)
+               static Type BootstrapCorlib_ResolveType (TypeContainer root, string name, VerifyBootstrapType typeVerifier)
                {
-                       object o = root.GetDefinition (name);
-                       if (o == null){
-                               Report.Error (518, "The predefined type `" + name + "' is not defined or imported");
+                       TypeLookupExpression tle = new TypeLookupExpression (name);
+                       Report.DisableErrors ();
+                       TypeExpr te = tle.ResolveAsTypeTerminal (root, false);
+                       Report.EnableErrors ();
+                       if (te == null) {
+                               Report.Error (518, "The predefined type `{0}' is not defined or imported", name);
                                return null;
                        }
 
-                       if (!(o is Class)){
-                               if (o is DeclSpace){
-                                       DeclSpace d = (DeclSpace) o;
-
-                                       Error_TypeConflict (name, d.Location);
-                               } else
-                                       Error_TypeConflict (name);
+                       Type t = te.Type;
+                       if (!typeVerifier (t)) {
+                               MemberCore mc = root.GetDefinition (name);
+                               Location loc = Location.Null;
+                               if (mc != null) {
+                                       name = mc.GetSignatureForError ();
+                                       loc = mc.Location;
+                               }
 
+                               Report.Error (520, loc, "The predefined type `{0}' is not declared correctly", name);
                                return null;
                        }
 
-                       Type t = ((DeclSpace) o).DefineType ();
-                       if (t != null)
-                               AttributeTester.RegisterNonObsoleteType (t);
+                       AttributeTester.RegisterNonObsoleteType (t);
                        return t;
                }
+               //
+               // Resolves a single class during the corlib bootstrap process
+               //
+               static Type BootstrapCorlib_ResolveClass (TypeContainer root, string name)
+               {
+                       return BootstrapCorlib_ResolveType (root, name, IsClass);
+               }
+
+               static bool IsClass (Type t)
+               {
+                       DeclSpace ds = TypeManager.LookupDeclSpace (t);
+                       if (ds != null)
+                               return ds is Class;
+                       return t.IsClass;
+               }
 
                //
                // Resolves a struct during the corlib bootstrap process
                //
                static void BootstrapCorlib_ResolveStruct (TypeContainer root, string name)
                {
-                       object o = root.GetDefinition (name);
-                       if (o == null){
-                               Report.Error (518, "The predefined type `" + name + "' is not defined or imported");
-                               return;
-                       }
-
-                       if (!(o is Struct)){
-                               if (o is DeclSpace){
-                                       DeclSpace d = (DeclSpace) o;
-
-                                       Error_TypeConflict (name, d.Location);
-                               } else
-                                       Error_TypeConflict (name);
-
-                               return;
-                       }
+                       BootstrapCorlib_ResolveType (root, name, IsStruct);
+               }
 
-                       ((DeclSpace) o).DefineType ();
+               static bool IsStruct (Type t)
+               {
+                       DeclSpace ds = TypeManager.LookupDeclSpace (t);
+                       if (ds != null)
+                               return ds is Struct;
+                       
+                       return TypeManager.IsSubclassOf (t, TypeManager.value_type);                    
                }
 
                //
-               // Resolves a struct during the corlib bootstrap process
+               // Resolves an interface during the corlib bootstrap process
                //
                static void BootstrapCorlib_ResolveInterface (TypeContainer root, string name)
                {
-                       object o = root.GetDefinition (name);
-                       if (o == null){
-                               Report.Error (518, "The predefined type `" + name + "' is not defined or imported");
-                               return;
-                       }
-
-                       if (!(o is Interface)){
-                               if (o is DeclSpace){
-                                       DeclSpace d = (DeclSpace) o;
-
-                                       Error_TypeConflict (name, d.Location);
-                               } else
-                                       Error_TypeConflict (name);
-
-                               return;
-                       }
+                       BootstrapCorlib_ResolveType (root, name, IsInterface);
+               }
 
-                       Type t = ((DeclSpace) o).DefineType ();
-                       if (t != null)
-                               AttributeTester.RegisterNonObsoleteType (t);
+               static bool IsInterface (Type t)
+               {
+                       return t.IsInterface;
                }
 
                //
@@ -267,20 +252,13 @@ namespace Mono.CSharp {
                //
                static void BootstrapCorlib_ResolveDelegate (TypeContainer root, string name)
                {
-                       object o = root.GetDefinition (name);
-                       if (o == null){
-                               Report.Error (518, "The predefined type `" + name + "' is not defined or imported");
-                               return;
-                       }
-
-                       if (!(o is Delegate)){
-                               Error_TypeConflict (name);
-                               return;
-                       }
+                       BootstrapCorlib_ResolveType (root, name, IsDelegate);
+               }
 
-                       ((DeclSpace) o).DefineType ();
+               static bool IsDelegate (Type t)
+               {
+                       return TypeManager.IsDelegateType (t);
                }
-               
 
                /// <summary>
                ///    Resolves the core types in the compiler when compiling with --nostdlib
@@ -421,13 +399,10 @@ namespace Mono.CSharp {
 #if GMCS_SOURCE
                        BootstrapCorlib_ResolveStruct (root, "System.Nullable`1");
 #endif
-                       BootstrapCorlib_ResolveDelegate (root, "System.AsyncCallback");
+                       TypeManager.delegate_type = BootstrapCorlib_ResolveClass (root, "System.Delegate");
+                       BootstrapCorlib_ResolveClass (root, "System.MulticastDelegate");
 
-                       // These will be defined indirectly during the previous ResolveDelegate.
-                       // However make sure the rest of the checks happen.
-                       string [] delegate_types = { "System.Delegate", "System.MulticastDelegate" };
-                       foreach (string cname in delegate_types)
-                               BootstrapCorlib_ResolveClass (root, cname);
+                       BootstrapCorlib_ResolveDelegate (root, "System.AsyncCallback");
                }
                        
                // <summary>
@@ -497,6 +472,9 @@ namespace Mono.CSharp {
                static public void PopulateCoreType (TypeContainer root, string name)
                {
                        DeclSpace ds = (DeclSpace) root.GetDefinition (name);
+                       // Core type was imported
+                       if (ds == null)
+                               return;
 
                        ds.DefineMembers ();
                        ds.Define ();