From b5c5563b1826e52864388590d824a735a919c954 Mon Sep 17 00:00:00 2001 From: Martin Baulig Date: Mon, 31 May 2004 02:44:20 +0000 Subject: [PATCH] **** Merged from MCS **** svn path=/trunk/mcs/; revision=28526 --- mcs/gmcs/decl.cs | 35 +++++++++++++++++++++++++----- mcs/gmcs/expression.cs | 48 ++++++++++++++++++----------------------- mcs/gmcs/namespace.cs | 5 ++++- mcs/gmcs/rootcontext.cs | 35 ++++++++++++++++++++---------- mcs/gmcs/typemanager.cs | 13 +++++++---- 5 files changed, 88 insertions(+), 48 deletions(-) diff --git a/mcs/gmcs/decl.cs b/mcs/gmcs/decl.cs index c2f326f79101f..67a6686065771 100755 --- a/mcs/gmcs/decl.cs +++ b/mcs/gmcs/decl.cs @@ -1091,18 +1091,27 @@ Type LookupInterfaceOrClass (string ns, string name, out bool error) object r; error = false; + int p = name.LastIndexOf ('.'); if (dh.Lookup (ns, name, out r)) return (Type) r; else { + // + // If the type is not a nested type, we do not need `LookupType's processing. + // If the @name does not have a `.' in it, this cant be a nested type. + // if (ns != ""){ - if (Namespace.IsNamespace (ns)){ - string fullname = (ns != "") ? ns + "." + name : name; - t = TypeManager.LookupType (fullname); + if (Namespace.IsNamespace (ns)) { + if (p != -1) + t = TypeManager.LookupType (ns + "." + name); + else + t = TypeManager.LookupTypeDirect (ns + "." + name); } else t = null; - } else + } else if (p != -1) t = TypeManager.LookupType (name); + else + t = TypeManager.LookupTypeDirect (name); } if (t != null) { @@ -1113,7 +1122,7 @@ Type LookupInterfaceOrClass (string ns, string name, out bool error) // // In case we are fed a composite name, normalize it. // - int p = name.LastIndexOf ('.'); + if (p != -1){ ns = MakeFQN (ns, name.Substring (0, p)); name = name.Substring (p+1); @@ -2255,6 +2264,22 @@ protected bool DoneSearching (ArrayList list) return copy; } + // find the nested type @name in @this. + public Type FindNestedType (string name) + { + ArrayList applicable = (ArrayList) member_hash [name]; + if (applicable == null) + return null; + + for (int i = applicable.Count-1; i >= 0; i--) { + CacheEntry entry = (CacheEntry) applicable [i]; + if ((entry.EntryType & EntryType.NestedType & EntryType.MaskType) != 0) + return (Type) entry.Member; + } + + return null; + } + // // This finds the method or property for us to override. invocationType is the type where // the override is going to be declared, name is the name of the method/property, and diff --git a/mcs/gmcs/expression.cs b/mcs/gmcs/expression.cs index 861bac84cbb6c..eecf5cc2b4be1 100755 --- a/mcs/gmcs/expression.cs +++ b/mcs/gmcs/expression.cs @@ -4754,7 +4754,7 @@ static bool IsApplicable (EmitContext ec, ArrayList arguments, MethodBase candid // // false is normal form, true is expanded form // - Hashtable candidate_to_form = new PtrHashtable (); + Hashtable candidate_to_form = null; // @@ -4794,14 +4794,16 @@ static bool IsApplicable (EmitContext ec, ArrayList arguments, MethodBase candid candidates.Add (candidate); applicable_type = candidate.DeclaringType; found_applicable = true; - candidate_to_form [candidate] = false; } else if (IsParamsMethodApplicable (ec, me, Arguments, ref methods [i])) { + if (candidate_to_form == null) + candidate_to_form = new PtrHashtable (); + // Candidate is applicable in expanded form - MethodBase candidate = methods [i]; + MethodBase candidate = methods [i]; candidates.Add (candidate); applicable_type = candidate.DeclaringType; found_applicable = true; - candidate_to_form [candidate] = true; + candidate_to_form [candidate] = candidate; } } @@ -4817,11 +4819,11 @@ static bool IsApplicable (EmitContext ec, ArrayList arguments, MethodBase candid for (int ix = 0; ix < candidate_top; ix++){ MethodBase candidate = (MethodBase) candidates [ix]; - bool cand_params = (bool) candidate_to_form [candidate]; + bool cand_params = candidate_to_form != null && candidate_to_form.Contains (candidate); bool method_params = false; if (method != null) - method_params = (bool) candidate_to_form [method]; + method_params = candidate_to_form != null && candidate_to_form.Contains (method); int x = BetterFunction (ec, Arguments, candidate, cand_params, @@ -4896,7 +4898,7 @@ static bool IsApplicable (EmitContext ec, ArrayList arguments, MethodBase candid // Now check that there are no ambiguities i.e the selected method // should be better than all the others // - bool best_params = (bool) candidate_to_form [method]; + bool best_params = candidate_to_form != null && candidate_to_form.Contains (method); for (int ix = 0; ix < candidate_top; ix++){ MethodBase candidate = (MethodBase) candidates [ix]; @@ -4916,7 +4918,7 @@ static bool IsApplicable (EmitContext ec, ArrayList arguments, MethodBase candid // IsApplicable (ec, Arguments, method))) // continue; - bool cand_params = (bool) candidate_to_form [candidate]; + bool cand_params = candidate_to_form != null && candidate_to_form.Contains (candidate); int x = BetterFunction (ec, Arguments, method, best_params, candidate, cand_params, @@ -7117,23 +7119,15 @@ static void error176 (Location loc, string name) "type name instead"); } - static bool IdenticalNameAndTypeName (EmitContext ec, Expression left_original, Location loc) + static bool IdenticalNameAndTypeName (EmitContext ec, Expression left_original, Expression left, Location loc) { - if (left_original == null) - return false; - - if (!(left_original is SimpleName)) + SimpleName sn = left_original as SimpleName; + if (sn == null || left == null || left.Type.Name != sn.Name) return false; - SimpleName sn = (SimpleName) left_original; - - TypeExpr t = RootContext.LookupType (ec.DeclSpace, sn.Name, true, loc); - if (t != null) - return true; - - return false; + return RootContext.LookupType (ec.DeclSpace, sn.Name, true, loc) != null; } - + public static Expression ResolveMemberAccess (EmitContext ec, Expression member_lookup, Expression left, Location loc, Expression left_original) @@ -7185,7 +7179,7 @@ static bool IdenticalNameAndTypeName (EmitContext ec, Expression left_original, if (decl_type.IsSubclassOf (TypeManager.enum_type)) { if (left_is_explicit && !left_is_type && - !IdenticalNameAndTypeName (ec, left_original, loc)) { + !IdenticalNameAndTypeName (ec, left_original, member_lookup, loc)) { error176 (loc, fe.FieldInfo.Name); return null; } @@ -7266,23 +7260,23 @@ static bool IdenticalNameAndTypeName (EmitContext ec, Expression left_original, if (!me.IsStatic){ if ((ec.IsFieldInitializer || ec.IsStatic) && - IdenticalNameAndTypeName (ec, left_original, loc)) + IdenticalNameAndTypeName (ec, left_original, member_lookup, loc)) return member_lookup; - + SimpleName.Error_ObjectRefRequired (ec, loc, me.Name); return null; } } else { - if (!me.IsInstance){ - if (IdenticalNameAndTypeName (ec, left_original, loc)) + if (!me.IsInstance) { + if (IdenticalNameAndTypeName (ec, left_original, left, loc)) return member_lookup; if (left_is_explicit) { error176 (loc, me.Name); return null; } - } + } // // Since we can not check for instance objects in SimpleName, diff --git a/mcs/gmcs/namespace.cs b/mcs/gmcs/namespace.cs index 6e3fbda610fe0..22e245e43726e 100755 --- a/mcs/gmcs/namespace.cs +++ b/mcs/gmcs/namespace.cs @@ -105,7 +105,10 @@ public IAlias Lookup (DeclSpace ds, string name, Location loc) if (ns != null) return ns; - t = TypeManager.LookupType (DeclSpace.MakeFQN (fullname, name)); + // + // The type is not a nested type here + // + t = TypeManager.LookupTypeDirect (DeclSpace.MakeFQN (fullname, name)); if ((t == null) || ((ds != null) && !ds.CheckAccessLevel (t))) return null; diff --git a/mcs/gmcs/rootcontext.cs b/mcs/gmcs/rootcontext.cs index 1428b19099b0a..5ffaf5ee15cea 100755 --- a/mcs/gmcs/rootcontext.cs +++ b/mcs/gmcs/rootcontext.cs @@ -487,13 +487,13 @@ static public string ImplicitParent (string ns) } static TypeExpr NamespaceLookup (DeclSpace ds, string name, - int num_type_args, Location loc) + int num_type_args, bool silent, Location loc) { // // Try in the current namespace and all its implicit parents // for (NamespaceEntry ns = ds.NamespaceEntry; ns != null; ns = ns.ImplicitParent) { - IAlias result = ns.Lookup (ds, name, num_type_args, loc); + IAlias result = ns.Lookup (ds, name, num_type_args, silent, loc); if (result == null) continue; @@ -528,8 +528,6 @@ static public string ImplicitParent (string ns) if (ds.Cache.Contains (name)){ t = (TypeExpr) ds.Cache [name]; - if (t != null) - return t; } else { // // For the case the type we are looking for is nested within this one @@ -537,9 +535,26 @@ static public string ImplicitParent (string ns) // DeclSpace containing_ds = ds; while (containing_ds != null){ + + // if the member cache has been created, lets use it. + // the member cache is MUCH faster. + if (containing_ds.MemberCache != null) { + Type type = containing_ds.MemberCache.FindNestedType (name); + if (type == null) { + containing_ds = containing_ds.Parent; + continue; + } + + t = new TypeExpression (type, loc); + ds.Cache [name] = t; + return t; + } + + // no member cache. Do it the hard way -- reflection Type current_type = containing_ds.TypeBuilder; - while (current_type != null) { + while (current_type != null && + current_type != TypeManager.object_type) { // // nested class // @@ -556,17 +571,15 @@ static public string ImplicitParent (string ns) containing_ds = containing_ds.Parent; } - t = NamespaceLookup (ds, name, num_type_params, loc); - if (t != null){ + t = NamespaceLookup (ds, name, num_type_params, silent, loc); + if (!silent) ds.Cache [name] = t; - return t; - } } - if (!silent) + if (t == null && !silent) Report.Error (246, loc, "Cannot find type `"+name+"'"); - return null; + return t; } // diff --git a/mcs/gmcs/typemanager.cs b/mcs/gmcs/typemanager.cs index b893c5c25450e..4b643cf5f328f 100755 --- a/mcs/gmcs/typemanager.cs +++ b/mcs/gmcs/typemanager.cs @@ -690,12 +690,17 @@ public static Type LookupTypeDirect (string name) Type t = (Type) types [name]; if (t != null) return t; - + + if (negative_hits.Contains (name)) + return null; + t = LookupTypeReflection (name); + if (t == null) - return null; - - types [name] = t; + negative_hits [name] = null; + else + types [name] = t; + return t; }