// Licensed under the terms of the GNU GPL
//
// (C) 2001 Ximian, Inc (http://www.ximian.com)
+// (C) 2004 Novell, Inc
//
// TODO: Move the method verification stuff from the class.cs and interface.cs here
//
using System.Reflection.Emit;
using System.Reflection;
+#if BOOTSTRAP_WITH_OLDLIB
+using XmlElement = System.Object;
+#else
+using System.Xml;
+#endif
+
namespace Mono.CSharp {
+ public class MemberName {
+ public string Name;
+ public readonly MemberName Left;
+
+ public static readonly MemberName Null = new MemberName ("");
+
+ public MemberName (string name)
+ {
+ this.Name = name;
+ }
+
+ public MemberName (MemberName left, string name)
+ : this (name)
+ {
+ this.Left = left;
+ }
+
+ public MemberName (MemberName left, MemberName right)
+ : this (left, right.Name)
+ {
+ }
+
+ public string GetName ()
+ {
+ return GetName (false);
+ }
+
+ public string GetName (bool is_generic)
+ {
+ string name = is_generic ? Basename : Name;
+ if (Left != null)
+ return Left.GetName (is_generic) + "." + name;
+ else
+ return name;
+ }
+
+ ///
+ /// This returns exclusively the name as seen on the source code
+ /// it is not the fully qualifed type after resolution
+ ///
+ public string GetPartialName ()
+ {
+ if (Left != null)
+ return Left.GetPartialName () + "." + Name;
+ else
+ return Name;
+ }
+
+ public string GetTypeName ()
+ {
+ if (Left != null)
+ return Left.GetTypeName () + "." + Name;
+ else
+ return Name;
+ }
+
+ public Expression GetTypeExpression (Location loc)
+ {
+ if (Left != null) {
+ Expression lexpr = Left.GetTypeExpression (loc);
+
+ return new MemberAccess (lexpr, Name, loc);
+ } else {
+ return new SimpleName (Name, loc);
+ }
+ }
+
+ public MemberName Clone ()
+ {
+ if (Left != null)
+ return new MemberName (Left.Clone (), Name);
+ else
+ return new MemberName (Name);
+ }
+
+ public string Basename {
+ get {
+ return Name;
+ }
+ }
+
+ public override string ToString ()
+ {
+ if (Left != null)
+ return Left + "." + Name;
+ else
+ return Name;
+ }
+ }
+
/// <summary>
/// Base representation for members. This is used to keep track
/// of Name, Location and Modifier flags, and handling Attributes.
/// <summary>
/// Public name
/// </summary>
- public string Name;
+ public string Name {
+ get {
+ // !(this is GenericMethod) && !(this is Method)
+ return MemberName.GetName (false);
+ }
+ }
+
+ // Is not readonly because of IndexerName attribute
+ public MemberName MemberName;
/// <summary>
/// Modifier flags that the user specified in the source code
/// </summary>
public readonly Location Location;
+ /// <summary>
+ /// XML documentation comment
+ /// </summary>
+ public string DocComment;
+
+ /// <summary>
+ /// Represents header string for documentation comment
+ /// for each member types.
+ /// </summary>
+ public abstract string DocCommentHeader { get; }
+
[Flags]
public enum Flags {
Obsolete_Undetected = 1, // Obsolete attribute has not been detected yet
HasClsCompliantAttribute = 1 << 6, // Type has CLSCompliantAttribute
ClsCompliantAttributeTrue = 1 << 7, // Type has CLSCompliant (true)
Excluded_Undetected = 1 << 8, // Conditional attribute has not been detected yet
- Excluded = 1 << 9 // Method is conditional
-
+ Excluded = 1 << 9, // Method is conditional
+ TestMethodDuplication = 1 << 10 // Test for duplication must be performed
}
/// <summary>
/// MemberCore flags at first detected then cached
/// </summary>
- protected Flags caching_flags;
+ internal Flags caching_flags;
- public MemberCore (TypeContainer parent, string name, Attributes attrs,
+ public MemberCore (TypeContainer parent, MemberName name, Attributes attrs,
Location loc)
: base (attrs)
{
Parent = parent;
- Name = name;
+ MemberName = name;
Location = loc;
caching_flags = Flags.Obsolete_Undetected | Flags.ClsCompliance_Undetected | Flags.HasCompliantAttribute_Undetected | Flags.Excluded_Undetected;
}
return Name;
}
+ /// <summary>
+ /// Use this method when MethodBuilder is null
+ /// </summary>
+ public virtual string GetSignatureForError (TypeContainer tc)
+ {
+ return Name;
+ }
+
/// <summary>
/// Base Emit method. This is also entry point for CLS-Compliant verification.
/// </summary>
public virtual void Emit ()
{
- VerifyObsoleteAttribute ();
+ // Hack with Parent == null is for EnumMember
+ if (Parent == null || (GetObsoleteAttribute (Parent) == null && Parent.GetObsoleteAttribute (Parent) == null))
+ VerifyObsoleteAttribute ();
if (!RootContext.VerifyClsCompliance)
return;
VerifyClsCompliance (Parent);
}
+ public bool InUnsafe {
+ get {
+ return ((ModFlags & Modifiers.UNSAFE) != 0) || Parent.UnsafeContext;
+ }
+ }
+
//
// Whehter is it ok to use an unsafe pointer in this type container
//
if (OptAttributes == null)
return null;
- // TODO: remove this allocation
- EmitContext ec = new EmitContext (ds.Parent, ds, ds.Location,
- null, null, ds.ModFlags, false);
-
- Attribute obsolete_attr = OptAttributes.Search (TypeManager.obsolete_attribute_type, ec);
+ Attribute obsolete_attr = OptAttributes.Search (
+ TypeManager.obsolete_attribute_type, ds.EmitContext);
if (obsolete_attr == null)
return null;
- ObsoleteAttribute obsolete = obsolete_attr.GetObsoleteAttribute (ds);
+ ObsoleteAttribute obsolete = obsolete_attr.GetObsoleteAttribute (ds.EmitContext);
if (obsolete == null)
return null;
/// <summary>
/// Returns true when MemberCore is exposed from assembly.
/// </summary>
- protected bool IsExposedFromAssembly (DeclSpace ds)
+ public bool IsExposedFromAssembly (DeclSpace ds)
{
if ((ModFlags & (Modifiers.PUBLIC | Modifiers.PROTECTED)) == 0)
return false;
bool GetClsCompliantAttributeValue (DeclSpace ds)
{
if (OptAttributes != null) {
- EmitContext ec = new EmitContext (ds.Parent, ds, ds.Location,
- null, null, ds.ModFlags, false);
- Attribute cls_attribute = OptAttributes.GetClsCompliantAttribute (ec);
+ Attribute cls_attribute = OptAttributes.Search (
+ TypeManager.cls_compliant_attribute_type, ds.EmitContext);
if (cls_attribute != null) {
caching_flags |= Flags.HasClsCompliantAttribute;
- return cls_attribute.GetClsCompliantAttributeValue (ds);
+ return cls_attribute.GetClsCompliantAttributeValue (ds.EmitContext);
}
}
return ds.GetClsCompliantAttributeValue ();
protected virtual bool VerifyClsCompliance (DeclSpace ds)
{
if (!IsClsCompliaceRequired (ds)) {
- if (HasClsCompliantAttribute && !IsExposedFromAssembly (ds)) {
- Report.Warning (Message.CS3019_CLS_compliance_checking_will_not_be_performed_on_because_it_is_private_or_internal, Location, GetSignatureForError ());
+ if (HasClsCompliantAttribute && RootContext.WarningLevel >= 2) {
+ if (!IsExposedFromAssembly (ds))
+ Report.Warning (3019, Location, "CLS compliance checking will not be performed on '{0}' because it is private or internal", GetSignatureForError ());
+ if (!CodeGen.Assembly.IsClsCompliant)
+ Report.Warning (3021, Location, "'{0}' does not need a CLSCompliant attribute because the assembly does not have a CLSCompliant attribute", GetSignatureForError ());
}
return false;
}
if (!CodeGen.Assembly.IsClsCompliant) {
if (HasClsCompliantAttribute) {
- Report.Error (Message.CS3014_cannot_be_marked_as_CLS_compliant_because_the_assembly_does_not_have_a_CLSCompliant_attribute, Location, GetSignatureForError ());
+ Report.Error (3014, Location, "'{0}' cannot be marked as CLS-compliant because the assembly does not have a CLSCompliant attribute", GetSignatureForError ());
}
+ return false;
}
int index = Name.LastIndexOf ('.');
if (Name [index > 0 ? index + 1 : 0] == '_') {
- Report.Error (Message.CS3008_Identifier_is_not_CLS_compliant, Location, GetSignatureForError () );
+ Report.Error (3008, Location, "Identifier '{0}' is not CLS-compliant", GetSignatureForError () );
}
return true;
}
protected abstract void VerifyObsoleteAttribute ();
+ //
+ // Raised (and passed an XmlElement that contains the comment)
+ // when GenerateDocComment is writing documentation expectedly.
+ //
+ internal virtual void OnGenerateDocComment (DeclSpace ds, XmlElement intermediateNode)
+ {
+ }
+
+ //
+ // Returns a string that represents the signature for this
+ // member which should be used in XML documentation.
+ //
+ public virtual string GetDocCommentName (DeclSpace ds)
+ {
+ if (ds == null || this is DeclSpace)
+ return DocCommentHeader + Name;
+ else
+ return String.Concat (DocCommentHeader, ds.Name, ".", Name);
+ }
+
+ //
+ // Generates xml doc comments (if any), and if required,
+ // handle warning report.
+ //
+ internal virtual void GenerateDocComment (DeclSpace ds)
+ {
+ DocUtil.GenerateDocComment (this, ds);
+ }
}
/// <summary>
/// provides the common foundation for managing those name
/// spaces.
/// </remarks>
- public abstract class DeclSpace : MemberCore {
+ public abstract class DeclSpace : MemberCore, IAlias {
/// <summary>
- /// this points to the actual definition that is being
+ /// This points to the actual definition that is being
/// created with System.Reflection.Emit
/// </summary>
public TypeBuilder TypeBuilder;
public string Basename;
- /// <summary>
- /// defined_names is used for toplevel objects
- /// </summary>
protected Hashtable defined_names;
+ // The emit context for toplevel objects.
+ protected EmitContext ec;
+
+ public EmitContext EmitContext {
+ get { return ec; }
+ }
+
static string[] attribute_targets = new string [] { "type" };
- public DeclSpace (NamespaceEntry ns, TypeContainer parent, string name, Attributes attrs, Location l)
+ public DeclSpace (NamespaceEntry ns, TypeContainer parent, MemberName name,
+ Attributes attrs, Location l)
: base (parent, name, attrs, l)
{
NamespaceEntry = ns;
- Basename = name.Substring (1 + name.LastIndexOf ('.'));
+ Basename = name.Name;
defined_names = new Hashtable ();
}
- public void RecordDecl ()
- {
- if ((NamespaceEntry != null) && (Parent == RootContext.Tree.Types))
- NamespaceEntry.DefineName (Basename, this);
- }
-
/// <summary>
- /// The result value from adding an declaration into
- /// a struct or a class
+ /// Adds the member to defined_names table. It tests for duplications and enclosing name conflicts
/// </summary>
- public enum AdditionResult {
- /// <summary>
- /// The declaration has been successfully
- /// added to the declation space.
- /// </summary>
- Success,
-
- /// <summary>
- /// The symbol has already been defined.
- /// </summary>
- NameExists,
-
- /// <summary>
- /// Returned if the declation being added to the
- /// name space clashes with its container name.
- ///
- /// The only exceptions for this are constructors
- /// and static constructors
- /// </summary>
- EnclosingClash,
-
- /// <summary>
- /// Returned if a constructor was created (because syntactically
- /// it looked like a constructor) but was not (because the name
- /// of the method is not the same as the container class
- /// </summary>
- NotAConstructor,
-
- /// <summary>
- /// This is only used by static constructors to emit the
- /// error 111, but this error for other things really
- /// happens at another level for other functions.
- /// </summary>
- MethodExists,
-
- /// <summary>
- /// Some other error.
- /// </summary>
- Error
- }
-
- /// <summary>
- /// Returns a status code based purely on the name
- /// of the member being added
- /// </summary>
- protected AdditionResult IsValid (string basename, string name)
+ protected bool AddToContainer (MemberCore symbol, bool is_method, string fullname, string basename)
{
- if (basename == Basename)
- return AdditionResult.EnclosingClash;
+ if (basename == Basename && !(this is Interface)) {
+ Report.SymbolRelatedToPreviousError (this);
+ Report.Error (542, symbol.Location, "'{0}': member names cannot be the same as their enclosing type", symbol.GetSignatureForError ());
+ return false;
+ }
+
+ MemberCore mc = (MemberCore)defined_names [fullname];
+
+ if (is_method && (mc is MethodCore || mc is IMethodData)) {
+ symbol.caching_flags |= Flags.TestMethodDuplication;
+ mc.caching_flags |= Flags.TestMethodDuplication;
+ return true;
+ }
- if (defined_names.Contains (name))
- return AdditionResult.NameExists;
+ if (mc != null) {
+ Report.SymbolRelatedToPreviousError (mc);
+ Report.Error (102, symbol.Location, "The type '{0}' already contains a definition for '{1}'", GetSignatureForError (), basename);
+ return false;
+ }
- return AdditionResult.Success;
+ defined_names.Add (fullname, symbol);
+ return true;
}
- public static int length;
- public static int small;
-
- /// <summary>
- /// Introduce @name into this declaration space and
- /// associates it with the object @o. Note that for
- /// methods this will just point to the first method. o
- /// </summary>
- public void DefineName (string name, object o)
+ public void RecordDecl ()
{
- defined_names.Add (name, o);
-
-#if DEBUGME
- int p = name.LastIndexOf ('.');
- int l = name.Length;
- length += l;
- small += l -p;
-#endif
+ if ((NamespaceEntry != null) && (Parent == RootContext.Tree.Types))
+ NamespaceEntry.DefineName (MemberName.Basename, this);
}
/// <summary>
- /// Returns the object associated with a given name in the declaration
- /// space. This is the inverse operation of `DefineName'
+ /// Returns the MemberCore associated with a given name in the declaration
+ /// space. It doesn't return method based symbols !!
/// </summary>
- public object GetDefinition (string name)
+ ///
+ public MemberCore GetDefinition (string name)
{
- return defined_names [name];
+ return (MemberCore)defined_names [name];
}
bool in_transit = false;
/// <summary>
/// Looks up the alias for the name
/// </summary>
- public string LookupAlias (string name)
+ public IAlias LookupAlias (string name)
{
if (NamespaceEntry != null)
return NamespaceEntry.LookupAlias (name);
}
// <summary>
- // Looks up the type, as parsed into the expression `e'
+ // Looks up the type, as parsed into the expression `e'.
// </summary>
+ //[Obsolete ("This method is going away soon")]
public Type ResolveType (Expression e, bool silent, Location loc)
{
- if (type_resolve_ec == null)
- type_resolve_ec = GetTypeResolveEmitContext (Parent, loc);
- type_resolve_ec.loc = loc;
- type_resolve_ec.ContainerType = TypeBuilder;
-
- int errors = Report.Errors;
- TypeExpr d = e.ResolveAsTypeTerminal (type_resolve_ec);
-
- if (d == null || d.eclass != ExprClass.Type){
- if (!silent && errors == Report.Errors){
- Report.Error (246, loc, "Cannot find type `"+ e.ToString () +"'");
- }
- return null;
- }
-
- if (!d.CheckAccessLevel (this)) {
- Report.Error (Message.CS0122_is_inaccessible_due_to_its_protection_level, loc, d.Name);
- return null;
- }
-
- return d.Type;
+ TypeExpr d = ResolveTypeExpr (e, silent, loc);
+ return d == null ? null : d.Type;
}
// <summary>
// Resolves the expression `e' for a type, and will recursively define
- // types.
+ // types. This should only be used for resolving base types.
// </summary>
public TypeExpr ResolveTypeExpr (Expression e, bool silent, Location loc)
{
type_resolve_ec.loc = loc;
type_resolve_ec.ContainerType = TypeBuilder;
- TypeExpr d = e.ResolveAsTypeTerminal (type_resolve_ec);
-
- if (d == null || d.eclass != ExprClass.Type){
- if (!silent){
- Report.Error (246, loc, "Cannot find type `"+ e +"'");
- }
- return null;
- }
-
- return d;
+ return e.ResolveAsTypeTerminal (type_resolve_ec, silent);
}
- public bool CheckAccessLevel (Type check_type)
+ public bool CheckAccessLevel (Type check_type)
{
if (check_type == TypeBuilder)
return true;
TypeAttributes check_attr = check_type.Attributes & TypeAttributes.VisibilityMask;
-
+
//
// Broken Microsoft runtime, return public for arrays, no matter what
// the accessibility is for their underlying class, and they return
if (check_type.IsArray || check_type.IsPointer)
return CheckAccessLevel (TypeManager.GetElementType (check_type));
+ if (TypeBuilder == null)
+ // FIXME: TypeBuilder will be null when invoked by Class.GetNormalBases().
+ // However, this is invoked again later -- so safe to return true.
+ // May also be null when resolving top-level attributes.
+ return true;
+
switch (check_attr){
case TypeAttributes.Public:
return true;
case TypeAttributes.NotPublic:
-
- // In same cases is null.
- if (TypeBuilder == null)
- return true;
-
//
// This test should probably use the declaringtype.
//
return true;
case TypeAttributes.NestedPrivate:
- string check_type_name = check_type.FullName;
- string type_name = TypeBuilder.FullName;
-
- int cio = check_type_name.LastIndexOf ('+');
- string container = check_type_name.Substring (0, cio);
-
- //
- // Check if the check_type is a nested class of the current type
- //
- if (check_type_name.StartsWith (type_name + "+")){
- return true;
- }
-
- if (type_name.StartsWith (container)){
- return true;
- }
-
- return false;
+ return NestedAccessible (check_type);
case TypeAttributes.NestedFamily:
- //
- // Only accessible to methods in current type or any subtypes
- //
return FamilyAccessible (check_type);
case TypeAttributes.NestedFamANDAssem:
}
- protected bool FamilyAccessible (Type check_type)
+ protected bool NestedAccessible (Type check_type)
{
- Type declaring = check_type.DeclaringType;
- if (TypeBuilder.IsSubclassOf (declaring))
- return true;
-
string check_type_name = check_type.FullName;
-
+
+ // At this point, we already know check_type is a nested class.
int cio = check_type_name.LastIndexOf ('+');
- string container = check_type_name.Substring (0, cio);
-
- //
- // Check if the check_type is a nested class of the current type
- //
- if (check_type_name.StartsWith (container + "+"))
+
+ // Ensure that the string 'container' has a '+' in it to avoid false matches
+ string container = check_type_name.Substring (0, cio + 1);
+
+ // Ensure that type_name ends with a '+' so that it can match 'container', if necessary
+ string type_name = TypeBuilder.FullName + "+";
+
+ // If the current class is nested inside the container of check_type,
+ // we can access check_type even if it is private or protected.
+ return type_name.StartsWith (container);
+ }
+
+ protected bool FamilyAccessible (Type check_type)
+ {
+ Type declaring = check_type.DeclaringType;
+ if (TypeBuilder == declaring ||
+ TypeBuilder.IsSubclassOf (declaring))
return true;
- return false;
+ return NestedAccessible (check_type);
}
// Access level of a type.
return t;
}
- public static void Error_AmbiguousTypeReference (Location loc, string name, Type t1, Type t2)
+ public static void Error_AmbiguousTypeReference (Location loc, string name, string t1, string t2)
{
Report.Error (104, loc,
- String.Format ("`{0}' is an ambiguous reference ({1} or {2}) ", name,
- t1.FullName, t2.FullName));
+ "`{0}' is an ambiguous reference ({1} or {2})",
+ name, t1, t2);
}
/// <summary>
if (name.IndexOf ('.') > 0)
continue;
- string alias_value = ns.LookupAlias (name);
+ IAlias alias_value = ns.LookupAlias (name);
if (alias_value != null) {
- t = LookupInterfaceOrClass ("", alias_value, out error);
+ t = LookupInterfaceOrClass ("", alias_value.Name, out error);
if (error)
return null;
if (match != null){
if (t != null){
if (CheckAccessLevel (match)) {
- Error_AmbiguousTypeReference (loc, name, t, match);
+ Error_AmbiguousTypeReference (loc, name, t.FullName, match.FullName);
return null;
}
continue;
caching_flags &= ~Flags.HasCompliantAttribute_Undetected;
if (OptAttributes != null) {
- EmitContext ec = new EmitContext (Parent, this, Location,
- null, null, ModFlags, false);
- Attribute cls_attribute = OptAttributes.GetClsCompliantAttribute (ec);
+ Attribute cls_attribute = OptAttributes.Search (TypeManager.cls_compliant_attribute_type, ec);
if (cls_attribute != null) {
caching_flags |= Flags.HasClsCompliantAttribute;
- if (cls_attribute.GetClsCompliantAttributeValue (this)) {
+ if (cls_attribute.GetClsCompliantAttributeValue (ec)) {
caching_flags |= Flags.ClsCompliantAttributeTrue;
return true;
}
return attribute_targets;
}
}
+
+ bool IAlias.IsType {
+ get { return true; }
+ }
+
+ string IAlias.Name {
+ get { return Name; }
+ }
+
+ TypeExpr IAlias.ResolveAsType (EmitContext ec)
+ {
+ if (TypeBuilder == null)
+ throw new InvalidOperationException ();
+
+ return new TypeExpression (TypeBuilder, Location);
+ }
}
/// <summary>
}
/// <summary>
- /// Returns the IMemberContainer of the parent class or null if this
+ /// Returns the IMemberContainer of the base class or null if this
/// is an interface or TypeManger.object_type.
/// This is used when creating the member cache for a class to get all
- /// members from the parent class.
+ /// members from the base class.
/// </summary>
- IMemberContainer Parent {
+ MemberCache BaseCache {
get;
}
public readonly IMemberContainer Container;
protected Hashtable member_hash;
protected Hashtable method_hash;
-
+
/// <summary>
/// Create a new MemberCache for the given IMemberContainer `container'.
/// </summary>
Timer.IncrementCounter (CounterType.MemberCache);
Timer.StartTimer (TimerType.CacheInit);
-
-
- // If we have a parent class (we have a parent class unless we're
+ // If we have a base class (we have a base class unless we're
// TypeManager.object_type), we deep-copy its MemberCache here.
- if (Container.IsInterface) {
- MemberCache parent;
-
- if (Container.Parent != null)
- parent = Container.Parent.MemberCache;
- else
- parent = TypeHandle.ObjectType.MemberCache;
- member_hash = SetupCacheForInterface (parent);
- } else if (Container.Parent != null)
- member_hash = SetupCache (Container.Parent.MemberCache);
+ if (Container.BaseCache != null)
+ member_hash = SetupCache (Container.BaseCache);
else
member_hash = new Hashtable ();
Timer.StopTimer (TimerType.CacheInit);
}
+ public MemberCache (Type[] ifaces)
+ {
+ //
+ // The members of this cache all belong to other caches.
+ // So, 'Container' will not be used.
+ //
+ this.Container = null;
+
+ member_hash = new Hashtable ();
+ if (ifaces == null)
+ return;
+
+ foreach (Type itype in ifaces)
+ AddCacheContents (TypeManager.LookupMemberCache (itype));
+ }
+
/// <summary>
- /// Bootstrap this member cache by doing a deep-copy of our parent.
+ /// Bootstrap this member cache by doing a deep-copy of our base.
/// </summary>
- Hashtable SetupCache (MemberCache parent)
+ Hashtable SetupCache (MemberCache base_class)
{
Hashtable hash = new Hashtable ();
- IDictionaryEnumerator it = parent.member_hash.GetEnumerator ();
+ if (base_class == null)
+ return hash;
+
+ IDictionaryEnumerator it = base_class.member_hash.GetEnumerator ();
while (it.MoveNext ()) {
hash [it.Key] = ((ArrayList) it.Value).Clone ();
- }
+ }
return hash;
}
-
/// <summary>
- /// Add the contents of `new_hash' to `hash'.
+ /// Add the contents of `cache' to the member_hash.
/// </summary>
- void AddHashtable (Hashtable hash, MemberCache cache)
+ void AddCacheContents (MemberCache cache)
{
- Hashtable new_hash = cache.member_hash;
- IDictionaryEnumerator it = new_hash.GetEnumerator ();
+ IDictionaryEnumerator it = cache.member_hash.GetEnumerator ();
while (it.MoveNext ()) {
- ArrayList list = (ArrayList) hash [it.Key];
+ ArrayList list = (ArrayList) member_hash [it.Key];
if (list == null)
- hash [it.Key] = list = new ArrayList ();
+ member_hash [it.Key] = list = new ArrayList ();
+
+ ArrayList entries = (ArrayList) it.Value;
+ for (int i = entries.Count-1; i >= 0; i--) {
+ CacheEntry entry = (CacheEntry) entries [i];
- foreach (CacheEntry entry in (ArrayList) it.Value) {
if (entry.Container != cache.Container)
break;
list.Add (entry);
}
}
- /// <summary>
- /// Bootstrap the member cache for an interface type.
- /// Type.GetMembers() won't return any inherited members for interface types,
- /// so we need to do this manually. Interfaces also inherit from System.Object.
- /// </summary>
- Hashtable SetupCacheForInterface (MemberCache parent)
- {
- Hashtable hash = SetupCache (parent);
- TypeExpr [] ifaces = TypeManager.GetInterfaces (Container.Type);
-
- foreach (TypeExpr iface in ifaces) {
- Type itype = iface.Type;
-
- IMemberContainer iface_container =
- TypeManager.LookupMemberContainer (itype);
-
- MemberCache iface_cache = iface_container.MemberCache;
-
- AddHashtable (hash, iface_cache);
- }
-
- return hash;
- }
-
/// <summary>
/// Add all members from class `container' to the cache.
/// </summary>
{
// We need to call AddMembers() with a single member type at a time
// to get the member type part of CacheEntry.EntryType right.
- AddMembers (MemberTypes.Constructor, container);
- AddMembers (MemberTypes.Field, container);
+ if (!container.IsInterface) {
+ AddMembers (MemberTypes.Constructor, container);
+ AddMembers (MemberTypes.Field, container);
+ }
AddMembers (MemberTypes.Method, container);
AddMembers (MemberTypes.Property, container);
AddMembers (MemberTypes.Event, container);
}
// When this method is called for the current class, the list will
- // already contain all inherited members from our parent classes.
+ // already contain all inherited members from our base classes.
// We cannot add new members in front of the list since this'd be an
// expensive operation, that's why the list is sorted in reverse order
// (ie. members from the current class are coming last).
this.Member = member;
this.EntryType = GetEntryType (mt, bf);
}
+
+ public override string ToString ()
+ {
+ return String.Format ("CacheEntry ({0}:{1}:{2})", Container.Name,
+ EntryType, Member);
+ }
}
/// <summary>
// `applicable' is a list of all members with the given member name `name'
- // in the current class and all its parent classes. The list is sorted in
+ // in the current class and all its base classes. The list is sorted in
// reverse order due to the way how the cache is initialy created (to speed
- // things up, we're doing a deep-copy of our parent).
+ // things up, we're doing a deep-copy of our base).
for (int i = applicable.Count-1; i >= 0; i--) {
CacheEntry entry = (CacheEntry) applicable [i];
// Does exist easier way how to detect indexer ?
if ((entry.EntryType & EntryType.Property) != 0) {
Type[] arg_types = TypeManager.GetArgumentTypes ((PropertyInfo)entry.Member);
- if (arg_types.Length == 1)
+ if (arg_types.Length > 0)
continue;
}
}
continue;
Report.SymbolRelatedToPreviousError (entry.Member);
- Report.Error (Message.CS3006_Overloaded_method_differing_only_in_ref_or_out_or_in_array_rank_is_not_CLS_compliant, method.Location, method.GetSignatureForError ());
+ Report.Error (3006, method.Location, "Overloaded method '{0}' differing only in ref or out, or in array rank, is not CLS-compliant", method.GetSignatureForError ());
}
}
}