From: Marek Safar Date: Mon, 11 Jun 2007 20:40:50 +0000 (-0000) Subject: 2007-06-11 Marek Safar X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;h=3eec7b9dd390f34c1f6ef72a6d111239af65b967;p=mono.git 2007-06-11 Marek Safar * 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 --- diff --git a/mcs/mcs/ChangeLog b/mcs/mcs/ChangeLog index fdb46bcee9c..3684717fde5 100644 --- a/mcs/mcs/ChangeLog +++ b/mcs/mcs/ChangeLog @@ -1,3 +1,17 @@ +2007-06-11 Marek Safar + + * 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 * anonymous.cs (VerifyExplicitParameterCompatibility): Add flag to do diff --git a/mcs/mcs/class.cs b/mcs/mcs/class.cs index 9402ad7686d..6ad16011f12 100644 --- a/mcs/mcs/class.cs +++ b/mcs/mcs/class.cs @@ -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)) diff --git a/mcs/mcs/ecore.cs b/mcs/mcs/ecore.cs index 916d5d48cb6..08f3b2c8039 100644 --- a/mcs/mcs/ecore.cs +++ b/mcs/mcs/ecore.cs @@ -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; diff --git a/mcs/mcs/namespace.cs b/mcs/mcs/namespace.cs index 28cf7eb818a..ee22c1a9080 100644 --- a/mcs/mcs/namespace.cs +++ b/mcs/mcs/namespace.cs @@ -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) diff --git a/mcs/mcs/rootcontext.cs b/mcs/mcs/rootcontext.cs index 9eb5fdae489..46cd399c239 100644 --- a/mcs/mcs/rootcontext.cs +++ b/mcs/mcs/rootcontext.cs @@ -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); } - /// /// 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"); } // @@ -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 ();