Skip to content

Commit

Permalink
2002-08-15 Martin Baulig <martin@gnome.org>
Browse files Browse the repository at this point in the history
	* typemanager.cs (IMemberContainer.Type): New property.
	(IMemberContainer.IsInterface): New property.

	The following changes are conditional to BROKEN_RUNTIME, which is
	defined at the top of the file.

	* typemanager.cs (MemberCache.MemberCache): Don't add the base
	class'es members, but add all members from TypeHandle.ObjectType
	if we're an interface.
	(MemberCache.AddMembers): Set the Declared flag if member.DeclaringType
	is the current type.
	(MemberCache.CacheEntry.Container): Removed this field.
	(TypeHandle.GetMembers): Include inherited members.

svn path=/trunk/mcs/; revision=6648
  • Loading branch information
Martin Baulig committed Aug 15, 2002
1 parent 38486c6 commit 1c829a1
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 8 deletions.
16 changes: 16 additions & 0 deletions mcs/mcs/ChangeLog
@@ -1,3 +1,19 @@
2002-08-15 Martin Baulig <martin@gnome.org>

* typemanager.cs (IMemberContainer.Type): New property.
(IMemberContainer.IsInterface): New property.

The following changes are conditional to BROKEN_RUNTIME, which is
defined at the top of the file.

* typemanager.cs (MemberCache.MemberCache): Don't add the base
class'es members, but add all members from TypeHandle.ObjectType
if we're an interface.
(MemberCache.AddMembers): Set the Declared flag if member.DeclaringType
is the current type.
(MemberCache.CacheEntry.Container): Removed this field.
(TypeHandle.GetMembers): Include inherited members.

2002-08-14 Gonzalo Paniagua Javier <gonzalo@ximian.com>

* typemanager.cs: fixed compilation and added a comment on a field that
Expand Down
79 changes: 71 additions & 8 deletions mcs/mcs/typemanager.cs
Expand Up @@ -9,7 +9,7 @@
// (C) 2001 Ximian, Inc (http://www.ximian.com)
//
//
#define CACHE
#undef BROKEN_RUNTIME

using System;
using System.Globalization;
Expand Down Expand Up @@ -159,10 +159,18 @@ public interface IMemberContainer : ICachingMemberFinder {
get;
}

Type Type {
get;
}

IMemberContainer Parent {
get;
}

bool IsInterface {
get;
}

MemberList GetMembers (MemberTypes mt, BindingFlags bf);
}

Expand Down Expand Up @@ -2249,11 +2257,17 @@ public MemberCache (IMemberContainer container)
Timer.IncrementCounter (CounterType.MemberCache);
Timer.StartTimer (TimerType.CacheInit);

#if BROKEN_RUNTIME
IMemberContainer current = Container;
do {
AddMembers (current);
current = current.Parent;
} while (current != null);
#else
AddMembers (Container);
if (Container.IsInterface)
AddMembers (TypeHandle.ObjectType);
#endif

Timer.StopTimer (TimerType.CacheInit);
}
Expand Down Expand Up @@ -2290,6 +2304,11 @@ void AddMembers (MemberTypes mt, BindingFlags bf, IMemberContainer container)
MemberHash.Add (name, list);
}

#if !BROKEN_RUNTIME
new_bf = (member.DeclaringType == container.Type) ?
bf | BindingFlags.DeclaredOnly : bf;
#endif

list.Add (new CacheEntry (container, member, mt, new_bf));
}
}
Expand Down Expand Up @@ -2366,16 +2385,20 @@ protected enum EntryType {
}

protected struct CacheEntry {
#if BROKEN_RUNTIME
// FIXME: This field is a temporary hack until the Mono runtime is fixed
// and distinguishes between ReflectedType and DeclaringType.
public readonly IMemberContainer Container;
#endif
public readonly EntryType EntryType;
public readonly MemberInfo Member;

public CacheEntry (IMemberContainer container, MemberInfo member, MemberTypes mt,
BindingFlags bf)
{
#if BROKEN_RUNTIME
this.Container = container;
#endif
this.Member = member;
this.EntryType = GetEntryType (mt, bf);
}
Expand All @@ -2390,6 +2413,7 @@ protected struct CacheEntry {
IMemberContainer current = Container;

foreach (CacheEntry entry in applicable) {
#if BROKEN_RUNTIME
if (entry.Container != current) {
current = entry.Container;

Expand All @@ -2412,15 +2436,36 @@ protected struct CacheEntry {
if ((list.Count > 0) && (list [0] is PropertyInfo))
break;
}
#else
if (declared_only && (entry.Member.DeclaringType != Container.Type))
break;
#endif

if ((entry.EntryType & type & EntryType.MaskType) == 0)
continue;

if ((entry.EntryType & type & EntryType.MaskStatic) == 0)
continue;

if (filter (entry.Member, criteria))
if (filter (entry.Member, criteria)) {
list.Add (entry.Member);
#if !BROKEN_RUNTIME
//
// Events and types are returned by both `static' and `instance'
// searches, which means that our above FindMembers will
// return two copies of the same.
//
if (list.Count == 1 && !(list [0] is MethodBase))
break;

//
// Multiple properties: we query those just to find out the indexer
// name
//
if ((list.Count > 0) && (list [0] is PropertyInfo))
break;
#endif
}
}
}

Expand Down Expand Up @@ -2457,7 +2502,6 @@ protected struct CacheEntry {
}

public sealed class TypeHandle : IMemberContainer {
public readonly Type Type;
public readonly TypeHandle BaseType;
public readonly MemberCache MemberCache;

Expand Down Expand Up @@ -2516,22 +2560,25 @@ private static void Initialize ()
}

private static PtrHashtable type_hash = new PtrHashtable ();
private static bool initialized = false; //Gonzalo: this field is never used

static TypeHandle object_type = null;
static TypeHandle array_type = null;
private static TypeHandle object_type = null;
private static TypeHandle array_type = null;

private Type type;
private bool is_interface;

private TypeHandle (Type type)
{
this.Type = type;
this.type = type;
if (type.BaseType != null)
BaseType = GetTypeHandle (type.BaseType);
else {
else if (type != TypeManager.object_type) {
//
// This happens with interfaces, they have a null
// basetype. Look members up in the Object class.
//
BaseType = object_type;
is_interface = true;
}
this.MemberCache = new MemberCache (this);
}
Expand All @@ -2544,16 +2591,32 @@ private TypeHandle (Type type)
}
}

public Type Type {
get {
return type;
}
}

public IMemberContainer Parent {
get {
return BaseType;
}
}

public bool IsInterface {
get {
return is_interface;
}
}

public MemberList GetMembers (MemberTypes mt, BindingFlags bf)
{
#if BROKEN_RUNTIME
return new MemberList (Type.FindMembers (
mt, bf | BindingFlags.DeclaredOnly, null, null));
#else
return new MemberList (Type.FindMembers (mt, bf, null, null));
#endif
}

// IMemberFinder methods
Expand Down

0 comments on commit 1c829a1

Please sign in to comment.