Skip to content

Commit

Permalink
**** Merged from MCS ****
Browse files Browse the repository at this point in the history
svn path=/trunk/mcs/; revision=28526
  • Loading branch information
Martin Baulig committed May 31, 2004
1 parent a02bf88 commit b5c5563
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 48 deletions.
35 changes: 30 additions & 5 deletions mcs/gmcs/decl.cs
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand Down
48 changes: 21 additions & 27 deletions mcs/gmcs/expression.cs
Expand Up @@ -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;


//
Expand Down Expand Up @@ -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;
}
}

Expand All @@ -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,
Expand Down Expand Up @@ -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];
Expand All @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion mcs/gmcs/namespace.cs
Expand Up @@ -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;

Expand Down
35 changes: 24 additions & 11 deletions mcs/gmcs/rootcontext.cs
Expand Up @@ -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;
Expand Down Expand Up @@ -528,18 +528,33 @@ 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
// or is in any base class
//
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
//
Expand All @@ -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;
}

// <summary>
Expand Down
13 changes: 9 additions & 4 deletions mcs/gmcs/typemanager.cs
Expand Up @@ -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;
}

Expand Down

0 comments on commit b5c5563

Please sign in to comment.