2 // decl.cs: Declaration base class for structs, classes, enums and interfaces.
4 // Author: Miguel de Icaza (miguel@gnu.org)
5 // Marek Safar (marek.safar@seznam.cz)
7 // Dual licensed under the terms of the MIT X11 or GNU GPL
9 // Copyright 2001 Ximian, Inc (http://www.ximian.com)
10 // Copyright 2004-2008 Novell, Inc
16 using System.Collections;
17 using System.Globalization;
18 using System.Reflection.Emit;
19 using System.Reflection;
21 #if BOOTSTRAP_WITH_OLDLIB || NET_2_1
22 using XmlElement = System.Object;
27 namespace Mono.CSharp {
30 // Better name would be DottenName
32 public class MemberName {
33 public readonly string Name;
34 public readonly TypeArguments TypeArguments;
36 public readonly MemberName Left;
37 public readonly Location Location;
39 public static readonly MemberName Null = new MemberName ("");
43 private MemberName (MemberName left, string name, bool is_double_colon,
48 this.is_double_colon = is_double_colon;
52 private MemberName (MemberName left, string name, bool is_double_colon,
53 TypeArguments args, Location loc)
54 : this (left, name, is_double_colon, loc)
56 if (args != null && args.Count > 0)
57 this.TypeArguments = args;
60 public MemberName (string name)
61 : this (name, Location.Null)
64 public MemberName (string name, Location loc)
65 : this (null, name, false, loc)
68 public MemberName (string name, TypeArguments args, Location loc)
69 : this (null, name, false, args, loc)
72 public MemberName (MemberName left, string name)
73 : this (left, name, left != null ? left.Location : Location.Null)
76 public MemberName (MemberName left, string name, Location loc)
77 : this (left, name, false, loc)
80 public MemberName (MemberName left, string name, TypeArguments args, Location loc)
81 : this (left, name, false, args, loc)
84 public MemberName (string alias, string name, TypeArguments args, Location loc)
85 : this (new MemberName (alias, loc), name, true, args, loc)
88 public MemberName (MemberName left, MemberName right)
89 : this (left, right, right.Location)
92 public MemberName (MemberName left, MemberName right, Location loc)
93 : this (null, right.Name, false, right.TypeArguments, loc)
95 if (right.is_double_colon)
96 throw new InternalErrorException ("Cannot append double_colon member name");
97 this.Left = (right.Left == null) ? left : new MemberName (left, right.Left);
101 public string GetName ()
103 return GetName (false);
106 public bool IsGeneric {
108 if (TypeArguments != null)
110 else if (Left != null)
111 return Left.IsGeneric;
117 public string GetName (bool is_generic)
119 string name = is_generic ? Basename : Name;
121 return Left.GetName (is_generic) + (is_double_colon ? "::" : ".") + name;
126 public ATypeNameExpression GetTypeExpression ()
129 if (TypeArguments != null)
130 return new SimpleName (Basename, TypeArguments, Location);
132 return new SimpleName (Name, Location);
135 if (is_double_colon) {
136 if (Left.Left != null)
137 throw new InternalErrorException ("The left side of a :: should be an identifier");
138 return new QualifiedAliasMember (Left.Name, Name, TypeArguments, Location);
141 Expression lexpr = Left.GetTypeExpression ();
142 return new MemberAccess (lexpr, Name, TypeArguments, Location);
145 public MemberName Clone ()
147 MemberName left_clone = Left == null ? null : Left.Clone ();
148 return new MemberName (left_clone, Name, is_double_colon, TypeArguments, Location);
151 public string Basename {
153 if (TypeArguments != null)
154 return MakeName (Name, TypeArguments);
159 public string GetSignatureForError ()
161 string append = TypeArguments == null ? "" : "<" + TypeArguments.GetSignatureForError () + ">";
163 return Name + append;
164 string connect = is_double_colon ? "::" : ".";
165 return Left.GetSignatureForError () + connect + Name + append;
168 public override bool Equals (object other)
170 return Equals (other as MemberName);
173 public bool Equals (MemberName other)
177 if (other == null || Name != other.Name)
179 if (is_double_colon != other.is_double_colon)
182 if ((TypeArguments != null) &&
183 (other.TypeArguments == null || TypeArguments.Count != other.TypeArguments.Count))
186 if ((TypeArguments == null) && (other.TypeArguments != null))
190 return other.Left == null;
192 return Left.Equals (other.Left);
195 public override int GetHashCode ()
197 int hash = Name.GetHashCode ();
198 for (MemberName n = Left; n != null; n = n.Left)
199 hash ^= n.Name.GetHashCode ();
203 if (TypeArguments != null)
204 hash ^= TypeArguments.Count << 5;
206 return hash & 0x7FFFFFFF;
209 public int CountTypeArguments {
211 if (TypeArguments != null)
212 return TypeArguments.Count;
213 else if (Left != null)
214 return Left.CountTypeArguments;
220 public static string MakeName (string name, TypeArguments args)
225 return name + "`" + args.Count;
228 public static string MakeName (string name, int count)
230 return name + "`" + count;
235 /// Base representation for members. This is used to keep track
236 /// of Name, Location and Modifier flags, and handling Attributes.
238 public abstract class MemberCore : Attributable, IResolveContext {
243 protected string cached_name;
244 // TODO: Remove in favor of MemberName
247 if (cached_name == null)
248 cached_name = MemberName.GetName (!(this is GenericMethod) && !(this is Method));
253 // Is not readonly because of IndexerName attribute
254 private MemberName member_name;
255 public MemberName MemberName {
256 get { return member_name; }
260 /// Modifier flags that the user specified in the source code
262 private int mod_flags;
263 public int ModFlags {
266 if ((value & Modifiers.COMPILER_GENERATED) != 0)
267 caching_flags = Flags.IsUsed | Flags.IsAssigned;
274 public /*readonly*/ DeclSpace Parent;
277 /// Location where this declaration happens
279 public Location Location {
280 get { return member_name.Location; }
284 /// XML documentation comment
286 protected string comment;
289 /// Represents header string for documentation comment
290 /// for each member types.
292 public abstract string DocCommentHeader { get; }
296 Obsolete_Undetected = 1, // Obsolete attribute has not been detected yet
297 Obsolete = 1 << 1, // Type has obsolete attribute
298 ClsCompliance_Undetected = 1 << 2, // CLS Compliance has not been detected yet
299 ClsCompliant = 1 << 3, // Type is CLS Compliant
300 CloseTypeCreated = 1 << 4, // Tracks whether we have Closed the type
301 HasCompliantAttribute_Undetected = 1 << 5, // Presence of CLSCompliantAttribute has not been detected
302 HasClsCompliantAttribute = 1 << 6, // Type has CLSCompliantAttribute
303 ClsCompliantAttributeTrue = 1 << 7, // Type has CLSCompliant (true)
304 Excluded_Undetected = 1 << 8, // Conditional attribute has not been detected yet
305 Excluded = 1 << 9, // Method is conditional
306 MethodOverloadsExist = 1 << 10, // Test for duplication must be performed
308 IsAssigned = 1 << 12, // Field is assigned
309 HasExplicitLayout = 1 << 13,
310 PartialDefinitionExists = 1 << 14, // Set when corresponding partial method definition exists
311 HasStructLayout = 1 << 15 // Has StructLayoutAttribute
315 /// MemberCore flags at first detected then cached
317 internal Flags caching_flags;
319 public MemberCore (DeclSpace parent, MemberName name, Attributes attrs)
322 this.Parent = parent;
324 caching_flags = Flags.Obsolete_Undetected | Flags.ClsCompliance_Undetected | Flags.HasCompliantAttribute_Undetected | Flags.Excluded_Undetected;
327 protected virtual void SetMemberName (MemberName new_name)
329 member_name = new_name;
333 protected bool CheckAbstractAndExtern (bool has_block)
335 if (Parent.PartialContainer.Kind == Kind.Interface)
339 if ((ModFlags & Modifiers.EXTERN) != 0) {
340 Report.Error (179, Location, "`{0}' cannot declare a body because it is marked extern",
341 GetSignatureForError ());
345 if ((ModFlags & Modifiers.ABSTRACT) != 0) {
346 Report.Error (500, Location, "`{0}' cannot declare a body because it is marked abstract",
347 GetSignatureForError ());
351 if ((ModFlags & (Modifiers.ABSTRACT | Modifiers.EXTERN | Modifiers.PARTIAL)) == 0) {
352 if (RootContext.Version >= LanguageVersion.LINQ && this is Property.PropertyMethod &&
353 !(this is Indexer.GetIndexerMethod || this is Indexer.SetIndexerMethod)) {
354 Report.Error (840, Location, "`{0}' must have a body because it is not marked abstract or extern. The property can be automatically implemented when you define both accessors",
355 GetSignatureForError ());
357 Report.Error (501, Location, "`{0}' must have a body because it is not marked abstract, extern, or partial",
358 GetSignatureForError ());
367 public void CheckProtectedModifier ()
369 if ((ModFlags & Modifiers.PROTECTED) == 0)
372 if (Parent.PartialContainer.Kind == Kind.Struct) {
373 Report.Error (666, Location, "`{0}': Structs cannot contain protected members",
374 GetSignatureForError ());
378 if ((Parent.ModFlags & Modifiers.STATIC) != 0) {
379 Report.Error (1057, Location, "`{0}': Static classes cannot contain protected members",
380 GetSignatureForError ());
384 if (((Parent.ModFlags & Modifiers.SEALED) != 0) &&
385 ((ModFlags & Modifiers.OVERRIDE) == 0) && (Name != "Finalize")) {
386 Report.Warning (628, 4, Location, "`{0}': new protected member declared in sealed class",
387 GetSignatureForError ());
392 public abstract bool Define ();
394 public virtual string DocComment {
404 // Returns full member name for error message
406 public virtual string GetSignatureForError ()
408 if (Parent == null || Parent.Parent == null)
409 return member_name.GetSignatureForError ();
411 return Parent.GetSignatureForError () + "." + member_name.GetSignatureForError ();
415 /// Base Emit method. This is also entry point for CLS-Compliant verification.
417 public virtual void Emit ()
419 if (!RootContext.VerifyClsCompliance)
422 if (Report.WarningLevel > 0)
423 VerifyClsCompliance ();
426 public bool IsCompilerGenerated {
428 if ((mod_flags & Modifiers.COMPILER_GENERATED) != 0)
431 return Parent == null ? false : Parent.IsCompilerGenerated;
435 public virtual bool IsUsed {
436 get { return (caching_flags & Flags.IsUsed) != 0; }
439 public void SetMemberIsUsed ()
441 caching_flags |= Flags.IsUsed;
445 /// Returns instance of ObsoleteAttribute for this MemberCore
447 public virtual ObsoleteAttribute GetObsoleteAttribute ()
449 if ((caching_flags & (Flags.Obsolete_Undetected | Flags.Obsolete)) == 0)
452 caching_flags &= ~Flags.Obsolete_Undetected;
454 if (OptAttributes == null || TypeManager.obsolete_attribute_type == null)
457 Attribute obsolete_attr = OptAttributes.Search (TypeManager.obsolete_attribute_type);
458 if (obsolete_attr == null)
461 caching_flags |= Flags.Obsolete;
463 ObsoleteAttribute obsolete = obsolete_attr.GetObsoleteAttribute ();
464 if (obsolete == null)
471 /// Checks for ObsoleteAttribute presence. It's used for testing of all non-types elements
473 public virtual void CheckObsoleteness (Location loc)
475 ObsoleteAttribute oa = GetObsoleteAttribute ();
477 AttributeTester.Report_ObsoleteMessage (oa, GetSignatureForError (), loc);
480 // Access level of a type.
483 { // Each column represents `is this scope larger or equal to Blah scope'
484 // Public Assembly Protected
485 Protected = (0 << 0) | (0 << 1) | (X << 2),
486 Public = (X << 0) | (X << 1) | (X << 2),
487 Private = (0 << 0) | (0 << 1) | (0 << 2),
488 Internal = (0 << 0) | (X << 1) | (0 << 2),
489 ProtectedOrInternal = (0 << 0) | (X << 1) | (X << 2),
492 static AccessLevel GetAccessLevelFromModifiers (int flags)
494 if ((flags & Modifiers.INTERNAL) != 0) {
496 if ((flags & Modifiers.PROTECTED) != 0)
497 return AccessLevel.ProtectedOrInternal;
499 return AccessLevel.Internal;
501 } else if ((flags & Modifiers.PROTECTED) != 0)
502 return AccessLevel.Protected;
503 else if ((flags & Modifiers.PRIVATE) != 0)
504 return AccessLevel.Private;
506 return AccessLevel.Public;
510 // Returns the access level for type `t'
512 static AccessLevel GetAccessLevelFromType (Type t)
515 return AccessLevel.Public;
516 if (t.IsNestedPrivate)
517 return AccessLevel.Private;
519 return AccessLevel.Internal;
521 if (t.IsNestedPublic)
522 return AccessLevel.Public;
523 if (t.IsNestedAssembly)
524 return AccessLevel.Internal;
525 if (t.IsNestedFamily)
526 return AccessLevel.Protected;
527 if (t.IsNestedFamORAssem)
528 return AccessLevel.ProtectedOrInternal;
529 if (t.IsNestedFamANDAssem)
530 throw new NotImplementedException ("NestedFamANDAssem not implemented, cant make this kind of type from c# anyways");
532 // nested private is taken care of
534 throw new Exception ("I give up, what are you?");
538 // Checks whether the type P is as accessible as this member
540 public bool IsAccessibleAs (Type p)
543 // if M is private, its accessibility is the same as this declspace.
544 // we already know that P is accessible to T before this method, so we
547 if ((mod_flags & Modifiers.PRIVATE) != 0)
550 while (TypeManager.HasElementType (p))
551 p = TypeManager.GetElementType (p);
554 if (p.IsGenericParameter)
557 if (TypeManager.IsGenericType (p)) {
558 foreach (Type t in p.GetGenericArguments ()) {
559 if (!IsAccessibleAs (t))
565 for (Type p_parent = null; p != null; p = p_parent) {
566 p_parent = p.DeclaringType;
567 AccessLevel pAccess = GetAccessLevelFromType (p);
568 if (pAccess == AccessLevel.Public)
571 bool same_access_restrictions = false;
572 for (MemberCore mc = this; !same_access_restrictions && mc != null && mc.Parent != null; mc = mc.Parent) {
573 AccessLevel al = GetAccessLevelFromModifiers (mc.ModFlags);
575 case AccessLevel.Internal:
576 if (al == AccessLevel.Private || al == AccessLevel.Internal)
577 same_access_restrictions = TypeManager.IsThisOrFriendAssembly (p.Assembly);
581 case AccessLevel.Protected:
582 if (al == AccessLevel.Protected) {
583 same_access_restrictions = mc.Parent.IsBaseType (p_parent);
587 if (al == AccessLevel.Private) {
589 // When type is private and any of its parents derives from
590 // protected type then the type is accessible
592 while (mc.Parent != null) {
593 if (mc.Parent.IsBaseType (p_parent))
594 same_access_restrictions = true;
601 case AccessLevel.ProtectedOrInternal:
602 if (al == AccessLevel.Protected)
603 same_access_restrictions = mc.Parent.IsBaseType (p_parent);
604 else if (al == AccessLevel.Internal)
605 same_access_restrictions = TypeManager.IsThisOrFriendAssembly (p.Assembly);
606 else if (al == AccessLevel.ProtectedOrInternal)
607 same_access_restrictions = mc.Parent.IsBaseType (p_parent) &&
608 TypeManager.IsThisOrFriendAssembly (p.Assembly);
612 case AccessLevel.Private:
614 // Both are private and share same parent
616 if (al == AccessLevel.Private)
617 same_access_restrictions = TypeManager.IsEqual (mc.Parent.TypeBuilder, p_parent);
622 throw new InternalErrorException (al.ToString ());
626 if (!same_access_restrictions)
634 /// Analyze whether CLS-Compliant verification must be execute for this MemberCore.
636 public override bool IsClsComplianceRequired ()
638 if ((caching_flags & Flags.ClsCompliance_Undetected) == 0)
639 return (caching_flags & Flags.ClsCompliant) != 0;
641 if (GetClsCompliantAttributeValue () && IsExposedFromAssembly ()) {
642 caching_flags &= ~Flags.ClsCompliance_Undetected;
643 caching_flags |= Flags.ClsCompliant;
647 caching_flags &= ~Flags.ClsCompliance_Undetected;
652 /// Returns true when MemberCore is exposed from assembly.
654 public bool IsExposedFromAssembly ()
656 if ((ModFlags & (Modifiers.PUBLIC | Modifiers.PROTECTED)) == 0)
659 DeclSpace parentContainer = Parent;
660 while (parentContainer != null && parentContainer.ModFlags != 0) {
661 if ((parentContainer.ModFlags & (Modifiers.PUBLIC | Modifiers.PROTECTED)) == 0)
663 parentContainer = parentContainer.Parent;
669 /// Goes through class hierarchy and gets value of first found CLSCompliantAttribute.
670 /// If no is attribute exists then assembly CLSCompliantAttribute is returned.
672 public virtual bool GetClsCompliantAttributeValue ()
674 if ((caching_flags & Flags.HasCompliantAttribute_Undetected) == 0)
675 return (caching_flags & Flags.ClsCompliantAttributeTrue) != 0;
677 caching_flags &= ~Flags.HasCompliantAttribute_Undetected;
679 if (OptAttributes != null && TypeManager.cls_compliant_attribute_type != null) {
680 Attribute cls_attribute = OptAttributes.Search (
681 TypeManager.cls_compliant_attribute_type);
682 if (cls_attribute != null) {
683 caching_flags |= Flags.HasClsCompliantAttribute;
684 bool value = cls_attribute.GetClsCompliantAttributeValue ();
686 caching_flags |= Flags.ClsCompliantAttributeTrue;
691 // It's null for TypeParameter
695 if (Parent.GetClsCompliantAttributeValue ()) {
696 caching_flags |= Flags.ClsCompliantAttributeTrue;
703 /// Returns true if MemberCore is explicitly marked with CLSCompliantAttribute
705 protected bool HasClsCompliantAttribute {
707 if ((caching_flags & Flags.HasCompliantAttribute_Undetected) != 0)
708 GetClsCompliantAttributeValue ();
710 return (caching_flags & Flags.HasClsCompliantAttribute) != 0;
715 /// Returns true when a member supports multiple overloads (methods, indexers, etc)
717 public virtual bool EnableOverloadChecks (MemberCore overload)
723 /// The main virtual method for CLS-Compliant verifications.
724 /// The method returns true if member is CLS-Compliant and false if member is not
725 /// CLS-Compliant which means that CLS-Compliant tests are not necessary. A descendants override it
726 /// and add their extra verifications.
728 protected virtual bool VerifyClsCompliance ()
730 if (!IsClsComplianceRequired ()) {
731 if (HasClsCompliantAttribute && Report.WarningLevel >= 2) {
732 if (!IsExposedFromAssembly ())
733 Report.Warning (3019, 2, Location, "CLS compliance checking will not be performed on `{0}' because it is not visible from outside this assembly", GetSignatureForError ());
734 if (!CodeGen.Assembly.IsClsCompliant)
735 Report.Warning (3021, 2, Location, "`{0}' does not need a CLSCompliant attribute because the assembly is not marked as CLS-compliant", GetSignatureForError ());
740 if (HasClsCompliantAttribute) {
741 if (CodeGen.Assembly.ClsCompliantAttribute == null && !CodeGen.Assembly.IsClsCompliant) {
742 Report.Warning (3014, 1, Location,
743 "`{0}' cannot be marked as CLS-compliant because the assembly is not marked as CLS-compliant",
744 GetSignatureForError ());
748 if (!Parent.IsClsComplianceRequired ()) {
749 Report.Warning (3018, 1, Location, "`{0}' cannot be marked as CLS-compliant because it is a member of non CLS-compliant type `{1}'",
750 GetSignatureForError (), Parent.GetSignatureForError ());
755 if (member_name.Name [0] == '_') {
756 Report.Warning (3008, 1, Location, "Identifier `{0}' is not CLS-compliant", GetSignatureForError () );
762 // Raised (and passed an XmlElement that contains the comment)
763 // when GenerateDocComment is writing documentation expectedly.
765 internal virtual void OnGenerateDocComment (XmlElement intermediateNode)
770 // Returns a string that represents the signature for this
771 // member which should be used in XML documentation.
773 public virtual string GetDocCommentName (DeclSpace ds)
775 if (ds == null || this is DeclSpace)
776 return DocCommentHeader + Name;
778 return String.Concat (DocCommentHeader, ds.Name, ".", Name);
782 // Generates xml doc comments (if any), and if required,
783 // handle warning report.
785 internal virtual void GenerateDocComment (DeclSpace ds)
788 DocUtil.GenerateDocComment (this, ds);
789 } catch (Exception e) {
790 throw new InternalErrorException (this, e);
794 public override IResolveContext ResolveContext {
798 #region IResolveContext Members
800 public DeclSpace DeclContainer {
801 get { return Parent; }
804 public virtual DeclSpace GenericDeclContainer {
805 get { return DeclContainer; }
808 public bool IsInObsoleteScope {
810 if (GetObsoleteAttribute () != null)
813 return Parent == null ? false : Parent.IsInObsoleteScope;
817 public bool IsInUnsafeScope {
819 if ((ModFlags & Modifiers.UNSAFE) != 0)
822 return Parent == null ? false : Parent.IsInUnsafeScope;
830 /// Base class for structs, classes, enumerations and interfaces.
833 /// They all create new declaration spaces. This
834 /// provides the common foundation for managing those name
837 public abstract class DeclSpace : MemberCore {
839 /// This points to the actual definition that is being
840 /// created with System.Reflection.Emit
842 public TypeBuilder TypeBuilder;
845 /// If we are a generic type, this is the type we are
846 /// currently defining. We need to lookup members on this
847 /// instead of the TypeBuilder.
849 public Type CurrentType;
852 // This is the namespace in which this typecontainer
853 // was declared. We use this to resolve names.
855 public NamespaceEntry NamespaceEntry;
857 private Hashtable Cache = new Hashtable ();
859 public readonly string Basename;
861 protected Hashtable defined_names;
863 public TypeContainer PartialContainer;
865 protected readonly bool is_generic;
866 readonly int count_type_params;
869 // Whether we are Generic
871 public bool IsGeneric {
875 else if (Parent != null)
876 return Parent.IsGeneric;
882 static string[] attribute_targets = new string [] { "type" };
884 public DeclSpace (NamespaceEntry ns, DeclSpace parent, MemberName name,
886 : base (parent, name, attrs)
889 Basename = name.Basename;
890 defined_names = new Hashtable ();
891 PartialContainer = null;
892 if (name.TypeArguments != null) {
894 count_type_params = name.TypeArguments.Count;
897 count_type_params += parent.count_type_params;
900 public override DeclSpace GenericDeclContainer {
905 /// Adds the member to defined_names table. It tests for duplications and enclosing name conflicts
907 protected virtual bool AddToContainer (MemberCore symbol, string name)
909 MemberCore mc = (MemberCore) defined_names [name];
912 defined_names.Add (name, symbol);
916 if (symbol.EnableOverloadChecks (mc))
919 Report.SymbolRelatedToPreviousError (mc);
920 if ((mc.ModFlags & Modifiers.PARTIAL) != 0 && (symbol is ClassOrStruct || symbol is Interface)) {
921 Error_MissingPartialModifier (symbol);
925 if (this is RootTypes) {
926 Report.Error (101, symbol.Location,
927 "The namespace `{0}' already contains a definition for `{1}'",
928 ((DeclSpace)symbol).NamespaceEntry.GetSignatureForError (), symbol.MemberName.Name);
929 } else if (symbol is TypeParameter) {
930 Report.Error (692, symbol.Location,
931 "Duplicate type parameter `{0}'", symbol.GetSignatureForError ());
933 Report.Error (102, symbol.Location,
934 "The type `{0}' already contains a definition for `{1}'",
935 GetSignatureForError (), symbol.MemberName.Name);
941 protected void RemoveFromContainer (string name)
943 defined_names.Remove (name);
947 /// Returns the MemberCore associated with a given name in the declaration
948 /// space. It doesn't return method based symbols !!
951 public MemberCore GetDefinition (string name)
953 return (MemberCore)defined_names [name];
956 public bool IsStaticClass {
957 get { return (ModFlags & Modifiers.STATIC) != 0; }
961 // root_types contains all the types. All TopLevel types
962 // hence have a parent that points to `root_types', that is
963 // why there is a non-obvious test down here.
965 public bool IsTopLevel {
966 get { return (Parent != null && Parent.Parent == null); }
969 public virtual void CloseType ()
971 if ((caching_flags & Flags.CloseTypeCreated) == 0){
973 TypeBuilder.CreateType ();
976 // The try/catch is needed because
977 // nested enumerations fail to load when they
980 // Even if this is the right order (enumerations
981 // declared after types).
983 // Note that this still creates the type and
984 // it is possible to save it
986 caching_flags |= Flags.CloseTypeCreated;
990 protected virtual TypeAttributes TypeAttr {
991 get { return CodeGen.Module.DefaultCharSetType; }
995 /// Should be overriten by the appropriate declaration space
997 public abstract TypeBuilder DefineType ();
999 protected void Error_MissingPartialModifier (MemberCore type)
1001 Report.Error (260, type.Location,
1002 "Missing partial modifier on declaration of type `{0}'. Another partial declaration of this type exists",
1003 type.GetSignatureForError ());
1006 public override void Emit ()
1009 if (type_params != null) {
1010 int offset = count_type_params - type_params.Length;
1011 for (int i = offset; i < type_params.Length; i++)
1012 CurrentTypeParameters [i - offset].Emit ();
1015 if ((ModFlags & Modifiers.COMPILER_GENERATED) != 0 && !Parent.IsCompilerGenerated)
1016 TypeBuilder.SetCustomAttribute (TypeManager.GetCompilerGeneratedAttribute (Location));
1022 public override string GetSignatureForError ()
1024 return MemberName.GetSignatureForError ();
1027 public bool CheckAccessLevel (Type check_type)
1029 TypeBuilder tb = TypeBuilder;
1031 if (this is GenericMethod) {
1032 tb = Parent.TypeBuilder;
1034 // FIXME: Generic container does not work with nested generic
1035 // anonymous method stories
1036 if (TypeBuilder == null)
1041 check_type = TypeManager.DropGenericTypeArguments (check_type);
1042 if (check_type == tb)
1046 // Broken Microsoft runtime, return public for arrays, no matter what
1047 // the accessibility is for their underlying class, and they return
1048 // NonPublic visibility for pointers
1050 if (check_type.IsArray || check_type.IsPointer)
1051 return CheckAccessLevel (TypeManager.GetElementType (check_type));
1053 TypeAttributes check_attr = check_type.Attributes & TypeAttributes.VisibilityMask;
1055 switch (check_attr){
1056 case TypeAttributes.Public:
1059 case TypeAttributes.NotPublic:
1060 return TypeManager.IsThisOrFriendAssembly (check_type.Assembly);
1062 case TypeAttributes.NestedPublic:
1063 return CheckAccessLevel (check_type.DeclaringType);
1065 case TypeAttributes.NestedPrivate:
1066 Type declaring = check_type.DeclaringType;
1067 return tb == declaring || TypeManager.IsNestedChildOf (tb, declaring);
1069 case TypeAttributes.NestedFamily:
1071 // Only accessible to methods in current type or any subtypes
1073 return FamilyAccessible (tb, check_type);
1075 case TypeAttributes.NestedFamANDAssem:
1076 return TypeManager.IsThisOrFriendAssembly (check_type.Assembly) &&
1077 FamilyAccessible (tb, check_type);
1079 case TypeAttributes.NestedFamORAssem:
1080 return FamilyAccessible (tb, check_type) ||
1081 TypeManager.IsThisOrFriendAssembly (check_type.Assembly);
1083 case TypeAttributes.NestedAssembly:
1084 return TypeManager.IsThisOrFriendAssembly (check_type.Assembly);
1087 throw new NotImplementedException (check_attr.ToString ());
1090 static bool FamilyAccessible (Type tb, Type check_type)
1092 Type declaring = check_type.DeclaringType;
1093 return TypeManager.IsNestedFamilyAccessible (tb, declaring);
1096 public bool IsBaseType (Type baseType)
1098 if (TypeManager.IsInterfaceType (baseType))
1099 throw new NotImplementedException ();
1101 Type type = TypeBuilder;
1102 while (type != null) {
1103 if (TypeManager.IsEqual (type, baseType))
1106 type = type.BaseType;
1112 private Type LookupNestedTypeInHierarchy (string name)
1115 // if the member cache has been created, lets use it.
1116 // the member cache is MUCH faster.
1117 if (MemberCache != null) {
1118 t = MemberCache.FindNestedType (name);
1123 // FIXME: This hack is needed because member cache does not work
1124 // with nested base generic types, it does only type name copy and
1125 // not type construction
1132 // no member cache. Do it the hard way -- reflection
1133 for (Type current_type = TypeBuilder;
1134 current_type != null && current_type != TypeManager.object_type;
1135 current_type = current_type.BaseType) {
1137 Type ct = TypeManager.DropGenericTypeArguments (current_type);
1138 if (ct is TypeBuilder) {
1139 TypeContainer tc = ct == TypeBuilder
1140 ? PartialContainer : TypeManager.LookupTypeContainer (ct);
1142 t = tc.FindNestedType (name);
1144 t = TypeManager.GetNestedType (ct, name);
1147 if ((t == null) || !CheckAccessLevel (t))
1151 if (!TypeManager.IsGenericType (current_type))
1154 Type[] args = TypeManager.GetTypeArguments (current_type);
1155 Type[] targs = TypeManager.GetTypeArguments (t);
1156 for (int i = 0; i < args.Length; i++)
1157 targs [i] = args [i];
1159 t = t.MakeGenericType (targs);
1168 public virtual ExtensionMethodGroupExpr LookupExtensionMethod (Type extensionType, string name, Location loc)
1174 // Public function used to locate types.
1176 // Set 'ignore_cs0104' to true if you want to ignore cs0104 errors.
1178 // Returns: Type or null if they type can not be found.
1180 public FullNamedExpression LookupNamespaceOrType (string name, Location loc, bool ignore_cs0104)
1182 if (Cache.Contains (name))
1183 return (FullNamedExpression) Cache [name];
1185 FullNamedExpression e;
1186 int errors = Report.Errors;
1187 Type t = LookupNestedTypeInHierarchy (name);
1189 e = new TypeExpression (t, Location.Null);
1190 else if (Parent != null)
1191 e = Parent.LookupNamespaceOrType (name, loc, ignore_cs0104);
1193 e = NamespaceEntry.LookupNamespaceOrType (this, name, loc, ignore_cs0104);
1195 if (errors == Report.Errors)
1202 /// This function is broken and not what you're looking for. It should only
1203 /// be used while the type is still being created since it doesn't use the cache
1204 /// and relies on the filter doing the member name check.
1207 // [Obsolete ("Only MemberCache approach should be used")]
1208 public virtual MemberList FindMembers (MemberTypes mt, BindingFlags bf,
1209 MemberFilter filter, object criteria)
1211 throw new NotSupportedException ();
1215 /// If we have a MemberCache, return it. This property may return null if the
1216 /// class doesn't have a member cache or while it's still being created.
1218 public abstract MemberCache MemberCache {
1222 public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
1224 if (a.Type == TypeManager.required_attr_type) {
1225 Report.Error (1608, a.Location, "The RequiredAttribute attribute is not permitted on C# types");
1228 TypeBuilder.SetCustomAttribute (cb);
1232 // Extensions for generics
1234 protected TypeParameter[] type_params;
1235 TypeParameter[] type_param_list;
1237 TypeParameter[] initialize_type_params ()
1239 if (type_param_list != null)
1240 return type_param_list;
1242 DeclSpace the_parent = Parent;
1243 if (this is GenericMethod)
1246 ArrayList list = new ArrayList ();
1247 if (the_parent != null && the_parent.IsGeneric) {
1248 // FIXME: move generics info out of DeclSpace
1249 TypeParameter[] parent_params = the_parent.PartialContainer.TypeParameters;
1250 list.AddRange (parent_params);
1253 int count = type_params != null ? type_params.Length : 0;
1254 for (int i = 0; i < count; i++) {
1255 TypeParameter param = type_params [i];
1257 if (Parent.IsGeneric) {
1258 foreach (TypeParameter tp in Parent.PartialContainer.CurrentTypeParameters) {
1259 if (tp.Name != param.Name)
1262 Report.SymbolRelatedToPreviousError (tp.Location, null);
1263 Report.Warning (693, 3, param.Location,
1264 "Type parameter `{0}' has the same name as the type parameter from outer type `{1}'",
1265 param.Name, Parent.GetSignatureForError ());
1270 type_param_list = new TypeParameter [list.Count];
1271 list.CopyTo (type_param_list, 0);
1272 return type_param_list;
1275 public virtual void SetParameterInfo (ArrayList constraints_list)
1278 if (constraints_list != null) {
1280 80, Location, "Constraints are not allowed " +
1281 "on non-generic declarations");
1287 TypeParameterName[] names = MemberName.TypeArguments.GetDeclarations ();
1288 type_params = new TypeParameter [names.Length];
1291 // Register all the names
1293 for (int i = 0; i < type_params.Length; i++) {
1294 TypeParameterName name = names [i];
1296 Constraints constraints = null;
1297 if (constraints_list != null) {
1298 int total = constraints_list.Count;
1299 for (int ii = 0; ii < total; ++ii) {
1300 Constraints constraints_at = (Constraints)constraints_list[ii];
1301 // TODO: it is used by iterators only
1302 if (constraints_at == null) {
1303 constraints_list.RemoveAt (ii);
1307 if (constraints_at.TypeParameter == name.Name) {
1308 constraints = constraints_at;
1309 constraints_list.RemoveAt(ii);
1315 type_params [i] = new TypeParameter (
1316 Parent, this, name.Name, constraints, name.OptAttributes,
1319 AddToContainer (type_params [i], name.Name);
1322 if (constraints_list != null && constraints_list.Count > 0) {
1323 foreach (Constraints constraint in constraints_list) {
1324 Report.Error(699, constraint.Location, "`{0}': A constraint references nonexistent type parameter `{1}'",
1325 GetSignatureForError (), constraint.TypeParameter);
1330 public TypeParameter[] TypeParameters {
1333 throw new InvalidOperationException ();
1334 if ((PartialContainer != null) && (PartialContainer != this))
1335 return PartialContainer.TypeParameters;
1336 if (type_param_list == null)
1337 initialize_type_params ();
1339 return type_param_list;
1343 public TypeParameter[] CurrentTypeParameters {
1346 throw new InvalidOperationException ();
1348 // TODO: Something is seriously broken here
1349 if (type_params == null)
1350 return new TypeParameter [0];
1356 public int CountTypeParameters {
1358 return count_type_params;
1362 public TypeParameterExpr LookupGeneric (string name, Location loc)
1367 TypeParameter [] current_params;
1368 if (this is TypeContainer)
1369 current_params = PartialContainer.CurrentTypeParameters;
1371 current_params = CurrentTypeParameters;
1373 foreach (TypeParameter type_param in current_params) {
1374 if (type_param.Name == name)
1375 return new TypeParameterExpr (type_param, loc);
1379 return Parent.LookupGeneric (name, loc);
1384 // Used for error reporting only
1385 public virtual Type LookupAnyGeneric (string typeName)
1387 return NamespaceEntry.NS.LookForAnyGenericType (typeName);
1390 public override string[] ValidAttributeTargets {
1391 get { return attribute_targets; }
1394 protected override bool VerifyClsCompliance ()
1396 if (!base.VerifyClsCompliance ()) {
1400 if (type_params != null) {
1401 foreach (TypeParameter tp in type_params) {
1402 if (tp.Constraints == null)
1405 tp.Constraints.VerifyClsCompliance ();
1409 IDictionary cache = TypeManager.AllClsTopLevelTypes;
1413 string lcase = Name.ToLower (System.Globalization.CultureInfo.InvariantCulture);
1414 if (!cache.Contains (lcase)) {
1415 cache.Add (lcase, this);
1419 object val = cache [lcase];
1421 Type t = AttributeTester.GetImportedIgnoreCaseClsType (lcase);
1424 Report.SymbolRelatedToPreviousError (t);
1427 Report.SymbolRelatedToPreviousError ((DeclSpace)val);
1430 Report.Warning (3005, 1, Location, "Identifier `{0}' differing only in case is not CLS-compliant", GetSignatureForError ());
1436 /// This is a readonly list of MemberInfo's.
1438 public class MemberList : IList {
1439 public readonly IList List;
1443 /// Create a new MemberList from the given IList.
1445 public MemberList (IList list)
1450 this.List = new ArrayList ();
1455 /// Concatenate the ILists `first' and `second' to a new MemberList.
1457 public MemberList (IList first, IList second)
1459 ArrayList list = new ArrayList ();
1460 list.AddRange (first);
1461 list.AddRange (second);
1466 public static readonly MemberList Empty = new MemberList (new ArrayList (0));
1469 /// Cast the MemberList into a MemberInfo[] array.
1472 /// This is an expensive operation, only use it if it's really necessary.
1474 public static explicit operator MemberInfo [] (MemberList list)
1476 Timer.StartTimer (TimerType.MiscTimer);
1477 MemberInfo [] result = new MemberInfo [list.Count];
1478 list.CopyTo (result, 0);
1479 Timer.StopTimer (TimerType.MiscTimer);
1491 public bool IsSynchronized {
1493 return List.IsSynchronized;
1497 public object SyncRoot {
1499 return List.SyncRoot;
1503 public void CopyTo (Array array, int index)
1505 List.CopyTo (array, index);
1510 public IEnumerator GetEnumerator ()
1512 return List.GetEnumerator ();
1517 public bool IsFixedSize {
1523 public bool IsReadOnly {
1529 object IList.this [int index] {
1531 return List [index];
1535 throw new NotSupportedException ();
1539 // FIXME: try to find out whether we can avoid the cast in this indexer.
1540 public MemberInfo this [int index] {
1542 return (MemberInfo) List [index];
1546 public int Add (object value)
1548 throw new NotSupportedException ();
1551 public void Clear ()
1553 throw new NotSupportedException ();
1556 public bool Contains (object value)
1558 return List.Contains (value);
1561 public int IndexOf (object value)
1563 return List.IndexOf (value);
1566 public void Insert (int index, object value)
1568 throw new NotSupportedException ();
1571 public void Remove (object value)
1573 throw new NotSupportedException ();
1576 public void RemoveAt (int index)
1578 throw new NotSupportedException ();
1583 /// This interface is used to get all members of a class when creating the
1584 /// member cache. It must be implemented by all DeclSpace derivatives which
1585 /// want to support the member cache and by TypeHandle to get caching of
1586 /// non-dynamic types.
1588 public interface IMemberContainer {
1590 /// The name of the IMemberContainer. This is only used for
1591 /// debugging purposes.
1598 /// The type of this IMemberContainer.
1605 /// Returns the IMemberContainer of the base class or null if this
1606 /// is an interface or TypeManger.object_type.
1607 /// This is used when creating the member cache for a class to get all
1608 /// members from the base class.
1610 MemberCache BaseCache {
1615 /// Whether this is an interface.
1622 /// Returns all members of this class with the corresponding MemberTypes
1623 /// and BindingFlags.
1626 /// When implementing this method, make sure not to return any inherited
1627 /// members and check the MemberTypes and BindingFlags properly.
1628 /// Unfortunately, System.Reflection is lame and doesn't provide a way to
1629 /// get the BindingFlags (static/non-static,public/non-public) in the
1630 /// MemberInfo class, but the cache needs this information. That's why
1631 /// this method is called multiple times with different BindingFlags.
1633 MemberList GetMembers (MemberTypes mt, BindingFlags bf);
1637 /// The MemberCache is used by dynamic and non-dynamic types to speed up
1638 /// member lookups. It has a member name based hash table; it maps each member
1639 /// name to a list of CacheEntry objects. Each CacheEntry contains a MemberInfo
1640 /// and the BindingFlags that were initially used to get it. The cache contains
1641 /// all members of the current class and all inherited members. If this cache is
1642 /// for an interface types, it also contains all inherited members.
1644 /// There are two ways to get a MemberCache:
1645 /// * if this is a dynamic type, lookup the corresponding DeclSpace and then
1646 /// use the DeclSpace.MemberCache property.
1647 /// * if this not a dynamic type, call TypeHandle.GetTypeHandle() to get a
1648 /// TypeHandle instance for the type and then use TypeHandle.MemberCache.
1650 public class MemberCache {
1651 public readonly IMemberContainer Container;
1652 protected Hashtable member_hash;
1653 protected Hashtable method_hash;
1656 /// Create a new MemberCache for the given IMemberContainer `container'.
1658 public MemberCache (IMemberContainer container)
1660 this.Container = container;
1662 Timer.IncrementCounter (CounterType.MemberCache);
1663 Timer.StartTimer (TimerType.CacheInit);
1665 // If we have a base class (we have a base class unless we're
1666 // TypeManager.object_type), we deep-copy its MemberCache here.
1667 if (Container.BaseCache != null)
1668 member_hash = SetupCache (Container.BaseCache);
1670 member_hash = new Hashtable ();
1672 // If this is neither a dynamic type nor an interface, create a special
1673 // method cache with all declared and inherited methods.
1674 Type type = container.Type;
1675 if (!(type is TypeBuilder) && !type.IsInterface &&
1676 // !(type.IsGenericType && (type.GetGenericTypeDefinition () is TypeBuilder)) &&
1677 !TypeManager.IsGenericType (type) && !TypeManager.IsGenericParameter (type) &&
1678 (Container.BaseCache == null || Container.BaseCache.method_hash != null)) {
1679 method_hash = new Hashtable ();
1683 // Add all members from the current class.
1684 AddMembers (Container);
1686 Timer.StopTimer (TimerType.CacheInit);
1689 public MemberCache (Type baseType, IMemberContainer container)
1691 this.Container = container;
1692 if (baseType == null)
1693 this.member_hash = new Hashtable ();
1695 this.member_hash = SetupCache (TypeManager.LookupMemberCache (baseType));
1698 public MemberCache (Type[] ifaces)
1701 // The members of this cache all belong to other caches.
1702 // So, 'Container' will not be used.
1704 this.Container = null;
1706 member_hash = new Hashtable ();
1710 foreach (Type itype in ifaces)
1711 AddCacheContents (TypeManager.LookupMemberCache (itype));
1714 public MemberCache (IMemberContainer container, Type base_class, Type[] ifaces)
1716 this.Container = container;
1718 // If we have a base class (we have a base class unless we're
1719 // TypeManager.object_type), we deep-copy its MemberCache here.
1720 if (Container.BaseCache != null)
1721 member_hash = SetupCache (Container.BaseCache);
1723 member_hash = new Hashtable ();
1725 if (base_class != null)
1726 AddCacheContents (TypeManager.LookupMemberCache (base_class));
1727 if (ifaces != null) {
1728 foreach (Type itype in ifaces) {
1729 MemberCache cache = TypeManager.LookupMemberCache (itype);
1731 AddCacheContents (cache);
1737 /// Bootstrap this member cache by doing a deep-copy of our base.
1739 static Hashtable SetupCache (MemberCache base_class)
1741 if (base_class == null)
1742 return new Hashtable ();
1744 Hashtable hash = new Hashtable (base_class.member_hash.Count);
1745 IDictionaryEnumerator it = base_class.member_hash.GetEnumerator ();
1746 while (it.MoveNext ()) {
1747 hash.Add (it.Key, ((ArrayList) it.Value).Clone ());
1754 // Converts ModFlags to BindingFlags
1756 static BindingFlags GetBindingFlags (int modifiers)
1759 if ((modifiers & Modifiers.STATIC) != 0)
1760 bf = BindingFlags.Static;
1762 bf = BindingFlags.Instance;
1764 if ((modifiers & Modifiers.PRIVATE) != 0)
1765 bf |= BindingFlags.NonPublic;
1767 bf |= BindingFlags.Public;
1773 /// Add the contents of `cache' to the member_hash.
1775 void AddCacheContents (MemberCache cache)
1777 IDictionaryEnumerator it = cache.member_hash.GetEnumerator ();
1778 while (it.MoveNext ()) {
1779 ArrayList list = (ArrayList) member_hash [it.Key];
1781 member_hash [it.Key] = list = new ArrayList ();
1783 ArrayList entries = (ArrayList) it.Value;
1784 for (int i = entries.Count-1; i >= 0; i--) {
1785 CacheEntry entry = (CacheEntry) entries [i];
1787 if (entry.Container != cache.Container)
1795 /// Add all members from class `container' to the cache.
1797 void AddMembers (IMemberContainer container)
1799 // We need to call AddMembers() with a single member type at a time
1800 // to get the member type part of CacheEntry.EntryType right.
1801 if (!container.IsInterface) {
1802 AddMembers (MemberTypes.Constructor, container);
1803 AddMembers (MemberTypes.Field, container);
1805 AddMembers (MemberTypes.Method, container);
1806 AddMembers (MemberTypes.Property, container);
1807 AddMembers (MemberTypes.Event, container);
1808 // Nested types are returned by both Static and Instance searches.
1809 AddMembers (MemberTypes.NestedType,
1810 BindingFlags.Static | BindingFlags.Public, container);
1811 AddMembers (MemberTypes.NestedType,
1812 BindingFlags.Static | BindingFlags.NonPublic, container);
1815 void AddMembers (MemberTypes mt, IMemberContainer container)
1817 AddMembers (mt, BindingFlags.Static | BindingFlags.Public, container);
1818 AddMembers (mt, BindingFlags.Static | BindingFlags.NonPublic, container);
1819 AddMembers (mt, BindingFlags.Instance | BindingFlags.Public, container);
1820 AddMembers (mt, BindingFlags.Instance | BindingFlags.NonPublic, container);
1823 public void AddMember (MemberInfo mi, MemberCore mc)
1825 AddMember (mi.MemberType, GetBindingFlags (mc.ModFlags), Container, mi.Name, mi);
1828 public void AddGenericMember (MemberInfo mi, InterfaceMemberBase mc)
1830 AddMember (mi.MemberType, GetBindingFlags (mc.ModFlags), Container,
1831 MemberName.MakeName (mc.GetFullName (mc.MemberName), mc.MemberName.TypeArguments), mi);
1834 public void AddNestedType (DeclSpace type)
1836 AddMember (MemberTypes.NestedType, GetBindingFlags (type.ModFlags), (IMemberContainer) type.Parent,
1837 type.TypeBuilder.Name, type.TypeBuilder);
1840 public void AddInterface (MemberCache baseCache)
1842 if (baseCache.member_hash.Count > 0)
1843 AddCacheContents (baseCache);
1846 void AddMember (MemberTypes mt, BindingFlags bf, IMemberContainer container,
1847 string name, MemberInfo member)
1849 // We use a name-based hash table of ArrayList's.
1850 ArrayList list = (ArrayList) member_hash [name];
1852 list = new ArrayList (1);
1853 member_hash.Add (name, list);
1856 // When this method is called for the current class, the list will
1857 // already contain all inherited members from our base classes.
1858 // We cannot add new members in front of the list since this'd be an
1859 // expensive operation, that's why the list is sorted in reverse order
1860 // (ie. members from the current class are coming last).
1861 list.Add (new CacheEntry (container, member, mt, bf));
1865 /// Add all members from class `container' with the requested MemberTypes and
1866 /// BindingFlags to the cache. This method is called multiple times with different
1867 /// MemberTypes and BindingFlags.
1869 void AddMembers (MemberTypes mt, BindingFlags bf, IMemberContainer container)
1871 MemberList members = container.GetMembers (mt, bf);
1873 foreach (MemberInfo member in members) {
1874 string name = member.Name;
1876 AddMember (mt, bf, container, name, member);
1878 if (member is MethodInfo) {
1879 string gname = TypeManager.GetMethodName ((MethodInfo) member);
1881 AddMember (mt, bf, container, gname, member);
1887 /// Add all declared and inherited methods from class `type' to the method cache.
1889 void AddMethods (Type type)
1891 AddMethods (BindingFlags.Static | BindingFlags.Public |
1892 BindingFlags.FlattenHierarchy, type);
1893 AddMethods (BindingFlags.Static | BindingFlags.NonPublic |
1894 BindingFlags.FlattenHierarchy, type);
1895 AddMethods (BindingFlags.Instance | BindingFlags.Public, type);
1896 AddMethods (BindingFlags.Instance | BindingFlags.NonPublic, type);
1899 static ArrayList overrides = new ArrayList ();
1901 void AddMethods (BindingFlags bf, Type type)
1903 MethodBase [] members = type.GetMethods (bf);
1905 Array.Reverse (members);
1907 foreach (MethodBase member in members) {
1908 string name = member.Name;
1910 // We use a name-based hash table of ArrayList's.
1911 ArrayList list = (ArrayList) method_hash [name];
1913 list = new ArrayList (1);
1914 method_hash.Add (name, list);
1917 MethodInfo curr = (MethodInfo) member;
1918 while (curr.IsVirtual && (curr.Attributes & MethodAttributes.NewSlot) == 0) {
1919 MethodInfo base_method = curr.GetBaseDefinition ();
1921 if (base_method == curr)
1922 // Not every virtual function needs to have a NewSlot flag.
1925 overrides.Add (curr);
1926 list.Add (new CacheEntry (null, base_method, MemberTypes.Method, bf));
1930 if (overrides.Count > 0) {
1931 for (int i = 0; i < overrides.Count; ++i)
1932 TypeManager.RegisterOverride ((MethodBase) overrides [i], curr);
1936 // Unfortunately, the elements returned by Type.GetMethods() aren't
1937 // sorted so we need to do this check for every member.
1938 BindingFlags new_bf = bf;
1939 if (member.DeclaringType == type)
1940 new_bf |= BindingFlags.DeclaredOnly;
1942 list.Add (new CacheEntry (Container, member, MemberTypes.Method, new_bf));
1947 /// Compute and return a appropriate `EntryType' magic number for the given
1948 /// MemberTypes and BindingFlags.
1950 protected static EntryType GetEntryType (MemberTypes mt, BindingFlags bf)
1952 EntryType type = EntryType.None;
1954 if ((mt & MemberTypes.Constructor) != 0)
1955 type |= EntryType.Constructor;
1956 if ((mt & MemberTypes.Event) != 0)
1957 type |= EntryType.Event;
1958 if ((mt & MemberTypes.Field) != 0)
1959 type |= EntryType.Field;
1960 if ((mt & MemberTypes.Method) != 0)
1961 type |= EntryType.Method;
1962 if ((mt & MemberTypes.Property) != 0)
1963 type |= EntryType.Property;
1964 // Nested types are returned by static and instance searches.
1965 if ((mt & MemberTypes.NestedType) != 0)
1966 type |= EntryType.NestedType | EntryType.Static | EntryType.Instance;
1968 if ((bf & BindingFlags.Instance) != 0)
1969 type |= EntryType.Instance;
1970 if ((bf & BindingFlags.Static) != 0)
1971 type |= EntryType.Static;
1972 if ((bf & BindingFlags.Public) != 0)
1973 type |= EntryType.Public;
1974 if ((bf & BindingFlags.NonPublic) != 0)
1975 type |= EntryType.NonPublic;
1976 if ((bf & BindingFlags.DeclaredOnly) != 0)
1977 type |= EntryType.Declared;
1983 /// The `MemberTypes' enumeration type is a [Flags] type which means that it may
1984 /// denote multiple member types. Returns true if the given flags value denotes a
1985 /// single member types.
1987 public static bool IsSingleMemberType (MemberTypes mt)
1990 case MemberTypes.Constructor:
1991 case MemberTypes.Event:
1992 case MemberTypes.Field:
1993 case MemberTypes.Method:
1994 case MemberTypes.Property:
1995 case MemberTypes.NestedType:
2004 /// We encode the MemberTypes and BindingFlags of each members in a "magic"
2005 /// number to speed up the searching process.
2008 protected enum EntryType {
2013 MaskStatic = Instance|Static,
2017 MaskProtection = Public|NonPublic,
2021 Constructor = 0x020,
2028 NotExtensionMethod = 0x800,
2030 MaskType = Constructor|Event|Field|Method|Property|NestedType
2033 protected class CacheEntry {
2034 public readonly IMemberContainer Container;
2035 public EntryType EntryType;
2036 public readonly MemberInfo Member;
2038 public CacheEntry (IMemberContainer container, MemberInfo member,
2039 MemberTypes mt, BindingFlags bf)
2041 this.Container = container;
2042 this.Member = member;
2043 this.EntryType = GetEntryType (mt, bf);
2046 public override string ToString ()
2048 return String.Format ("CacheEntry ({0}:{1}:{2})", Container.Name,
2054 /// This is called each time we're walking up one level in the class hierarchy
2055 /// and checks whether we can abort the search since we've already found what
2056 /// we were looking for.
2058 protected bool DoneSearching (ArrayList list)
2061 // We've found exactly one member in the current class and it's not
2062 // a method or constructor.
2064 if (list.Count == 1 && !(list [0] is MethodBase))
2068 // Multiple properties: we query those just to find out the indexer
2071 if ((list.Count > 0) && (list [0] is PropertyInfo))
2078 /// Looks up members with name `name'. If you provide an optional
2079 /// filter function, it'll only be called with members matching the
2080 /// requested member name.
2082 /// This method will try to use the cache to do the lookup if possible.
2084 /// Unlike other FindMembers implementations, this method will always
2085 /// check all inherited members - even when called on an interface type.
2087 /// If you know that you're only looking for methods, you should use
2088 /// MemberTypes.Method alone since this speeds up the lookup a bit.
2089 /// When doing a method-only search, it'll try to use a special method
2090 /// cache (unless it's a dynamic type or an interface) and the returned
2091 /// MemberInfo's will have the correct ReflectedType for inherited methods.
2092 /// The lookup process will automatically restart itself in method-only
2093 /// search mode if it discovers that it's about to return methods.
2095 ArrayList global = new ArrayList ();
2096 bool using_global = false;
2098 static MemberInfo [] emptyMemberInfo = new MemberInfo [0];
2100 public MemberInfo [] FindMembers (MemberTypes mt, BindingFlags bf, string name,
2101 MemberFilter filter, object criteria)
2104 throw new Exception ();
2106 bool declared_only = (bf & BindingFlags.DeclaredOnly) != 0;
2107 bool method_search = mt == MemberTypes.Method;
2108 // If we have a method cache and we aren't already doing a method-only search,
2109 // then we restart a method search if the first match is a method.
2110 bool do_method_search = !method_search && (method_hash != null);
2112 ArrayList applicable;
2114 // If this is a method-only search, we try to use the method cache if
2115 // possible; a lookup in the method cache will return a MemberInfo with
2116 // the correct ReflectedType for inherited methods.
2118 if (method_search && (method_hash != null))
2119 applicable = (ArrayList) method_hash [name];
2121 applicable = (ArrayList) member_hash [name];
2123 if (applicable == null)
2124 return emptyMemberInfo;
2127 // 32 slots gives 53 rss/54 size
2128 // 2/4 slots gives 55 rss
2130 // Strange: from 25,000 calls, only 1,800
2131 // are above 2. Why does this impact it?
2134 using_global = true;
2136 Timer.StartTimer (TimerType.CachedLookup);
2138 EntryType type = GetEntryType (mt, bf);
2140 IMemberContainer current = Container;
2142 bool do_interface_search = current.IsInterface;
2144 // `applicable' is a list of all members with the given member name `name'
2145 // in the current class and all its base classes. The list is sorted in
2146 // reverse order due to the way how the cache is initialy created (to speed
2147 // things up, we're doing a deep-copy of our base).
2149 for (int i = applicable.Count-1; i >= 0; i--) {
2150 CacheEntry entry = (CacheEntry) applicable [i];
2152 // This happens each time we're walking one level up in the class
2153 // hierarchy. If we're doing a DeclaredOnly search, we must abort
2154 // the first time this happens (this may already happen in the first
2155 // iteration of this loop if there are no members with the name we're
2156 // looking for in the current class).
2157 if (entry.Container != current) {
2161 if (!do_interface_search && DoneSearching (global))
2164 current = entry.Container;
2167 // Is the member of the correct type ?
2168 if ((entry.EntryType & type & EntryType.MaskType) == 0)
2171 // Is the member static/non-static ?
2172 if ((entry.EntryType & type & EntryType.MaskStatic) == 0)
2175 // Apply the filter to it.
2176 if (filter (entry.Member, criteria)) {
2177 if ((entry.EntryType & EntryType.MaskType) != EntryType.Method) {
2178 do_method_search = false;
2181 // Because interfaces support multiple inheritance we have to be sure that
2182 // base member is from same interface, so only top level member will be returned
2183 if (do_interface_search && global.Count > 0) {
2184 bool member_already_exists = false;
2186 foreach (MemberInfo mi in global) {
2187 if (mi is MethodBase)
2190 if (IsInterfaceBaseInterface (TypeManager.GetInterfaces (mi.DeclaringType), entry.Member.DeclaringType)) {
2191 member_already_exists = true;
2195 if (member_already_exists)
2199 global.Add (entry.Member);
2203 Timer.StopTimer (TimerType.CachedLookup);
2205 // If we have a method cache and we aren't already doing a method-only
2206 // search, we restart in method-only search mode if the first match is
2207 // a method. This ensures that we return a MemberInfo with the correct
2208 // ReflectedType for inherited methods.
2209 if (do_method_search && (global.Count > 0)){
2210 using_global = false;
2212 return FindMembers (MemberTypes.Method, bf, name, filter, criteria);
2215 using_global = false;
2216 MemberInfo [] copy = new MemberInfo [global.Count];
2217 global.CopyTo (copy);
2222 /// Returns true if iterface exists in any base interfaces (ifaces)
2224 static bool IsInterfaceBaseInterface (Type[] ifaces, Type ifaceToFind)
2226 foreach (Type iface in ifaces) {
2227 if (iface == ifaceToFind)
2230 Type[] base_ifaces = TypeManager.GetInterfaces (iface);
2231 if (base_ifaces.Length > 0 && IsInterfaceBaseInterface (base_ifaces, ifaceToFind))
2237 // find the nested type @name in @this.
2238 public Type FindNestedType (string name)
2240 ArrayList applicable = (ArrayList) member_hash [name];
2241 if (applicable == null)
2244 for (int i = applicable.Count-1; i >= 0; i--) {
2245 CacheEntry entry = (CacheEntry) applicable [i];
2246 if ((entry.EntryType & EntryType.NestedType & EntryType.MaskType) != 0)
2247 return (Type) entry.Member;
2253 public MemberInfo FindBaseEvent (Type invocation_type, string name)
2255 ArrayList applicable = (ArrayList) member_hash [name];
2256 if (applicable == null)
2260 // Walk the chain of events, starting from the top.
2262 for (int i = applicable.Count - 1; i >= 0; i--)
2264 CacheEntry entry = (CacheEntry) applicable [i];
2265 if ((entry.EntryType & EntryType.Event) == 0)
2268 EventInfo ei = (EventInfo)entry.Member;
2269 return ei.GetAddMethod (true);
2276 // Looks for extension methods with defined name and extension type
2278 public ArrayList FindExtensionMethods (Type extensionType, string name, bool publicOnly)
2281 if (method_hash != null)
2282 entries = (ArrayList)method_hash [name];
2284 entries = (ArrayList)member_hash [name];
2286 if (entries == null)
2289 EntryType entry_type = EntryType.Static | EntryType.Method | EntryType.NotExtensionMethod;
2291 entry_type |= EntryType.Public;
2293 EntryType found_entry_type = entry_type & ~EntryType.NotExtensionMethod;
2295 ArrayList candidates = null;
2296 foreach (CacheEntry entry in entries) {
2297 if ((entry.EntryType & entry_type) == found_entry_type) {
2298 MethodBase mb = (MethodBase)entry.Member;
2300 IMethodData md = TypeManager.GetMethod (mb);
2301 AParametersCollection pd = md == null ?
2302 TypeManager.GetParameterData (mb) : md.ParameterInfo;
2304 Type ex_type = pd.ExtensionMethodType;
2305 if (ex_type == null) {
2306 entry.EntryType |= EntryType.NotExtensionMethod;
2310 //if (implicit conversion between ex_type and extensionType exist) {
2311 if (candidates == null)
2312 candidates = new ArrayList (2);
2313 candidates.Add (mb);
2322 // This finds the method or property for us to override. invocation_type is the type where
2323 // the override is going to be declared, name is the name of the method/property, and
2324 // param_types is the parameters, if any to the method or property
2326 // Because the MemberCache holds members from this class and all the base classes,
2327 // we can avoid tons of reflection stuff.
2329 public MemberInfo FindMemberToOverride (Type invocation_type, string name, AParametersCollection parameters, GenericMethod generic_method, bool is_property)
2331 ArrayList applicable;
2332 if (method_hash != null && !is_property)
2333 applicable = (ArrayList) method_hash [name];
2335 applicable = (ArrayList) member_hash [name];
2337 if (applicable == null)
2340 // Walk the chain of methods, starting from the top.
2342 for (int i = applicable.Count - 1; i >= 0; i--) {
2343 CacheEntry entry = (CacheEntry) applicable [i];
2345 if ((entry.EntryType & (is_property ? (EntryType.Property | EntryType.Field) : EntryType.Method)) == 0)
2348 PropertyInfo pi = null;
2349 MethodInfo mi = null;
2350 FieldInfo fi = null;
2351 AParametersCollection cmp_attrs;
2354 if ((entry.EntryType & EntryType.Field) != 0) {
2355 fi = (FieldInfo)entry.Member;
2356 cmp_attrs = Parameters.EmptyReadOnlyParameters;
2358 pi = (PropertyInfo) entry.Member;
2359 cmp_attrs = TypeManager.GetParameterData (pi);
2362 mi = (MethodInfo) entry.Member;
2363 cmp_attrs = TypeManager.GetParameterData (mi);
2367 // TODO: Almost duplicate !
2369 switch (fi.Attributes & FieldAttributes.FieldAccessMask) {
2370 case FieldAttributes.PrivateScope:
2372 case FieldAttributes.Private:
2374 // A private method is Ok if we are a nested subtype.
2375 // The spec actually is not very clear about this, see bug 52458.
2377 if (!invocation_type.Equals (entry.Container.Type) &&
2378 !TypeManager.IsNestedChildOf (invocation_type, entry.Container.Type))
2381 case FieldAttributes.FamANDAssem:
2382 case FieldAttributes.Assembly:
2384 // Check for assembly methods
2386 if (mi.DeclaringType.Assembly != CodeGen.Assembly.Builder)
2390 return entry.Member;
2394 // Check the arguments
2396 if (cmp_attrs.Count != parameters.Count)
2400 for (j = 0; j < cmp_attrs.Count; ++j) {
2402 // LAMESPEC: No idea why `params' modifier is ignored
2404 if ((parameters.FixedParameters [j].ModFlags & ~Parameter.Modifier.PARAMS) !=
2405 (cmp_attrs.FixedParameters [j].ModFlags & ~Parameter.Modifier.PARAMS))
2408 if (!TypeManager.IsEqual (parameters.Types [j], cmp_attrs.Types [j]))
2412 if (j < cmp_attrs.Count)
2416 // check generic arguments for methods
2419 Type [] cmpGenArgs = TypeManager.GetGenericArguments (mi);
2420 if (generic_method == null && cmpGenArgs != null && cmpGenArgs.Length != 0)
2422 if (generic_method != null && cmpGenArgs != null && cmpGenArgs.Length != generic_method.TypeParameters.Length)
2427 // get one of the methods because this has the visibility info.
2430 mi = pi.GetGetMethod (true);
2432 mi = pi.GetSetMethod (true);
2438 switch (mi.Attributes & MethodAttributes.MemberAccessMask) {
2439 case MethodAttributes.PrivateScope:
2441 case MethodAttributes.Private:
2443 // A private method is Ok if we are a nested subtype.
2444 // The spec actually is not very clear about this, see bug 52458.
2446 if (!invocation_type.Equals (entry.Container.Type) &&
2447 !TypeManager.IsNestedChildOf (invocation_type, entry.Container.Type))
2450 case MethodAttributes.FamANDAssem:
2451 case MethodAttributes.Assembly:
2453 // Check for assembly methods
2455 if (!TypeManager.IsThisOrFriendAssembly (mi.DeclaringType.Assembly))
2459 return entry.Member;
2466 /// The method is looking for conflict with inherited symbols (errors CS0108, CS0109).
2467 /// We handle two cases. The first is for types without parameters (events, field, properties).
2468 /// The second are methods, indexers and this is why ignore_complex_types is here.
2469 /// The latest param is temporary hack. See DoDefineMembers method for more info.
2471 public MemberInfo FindMemberWithSameName (string name, bool ignore_complex_types, MemberInfo ignore_member)
2473 ArrayList applicable = null;
2475 if (method_hash != null)
2476 applicable = (ArrayList) method_hash [name];
2478 if (applicable != null) {
2479 for (int i = applicable.Count - 1; i >= 0; i--) {
2480 CacheEntry entry = (CacheEntry) applicable [i];
2481 if ((entry.EntryType & EntryType.Public) != 0)
2482 return entry.Member;
2486 if (member_hash == null)
2488 applicable = (ArrayList) member_hash [name];
2490 if (applicable != null) {
2491 for (int i = applicable.Count - 1; i >= 0; i--) {
2492 CacheEntry entry = (CacheEntry) applicable [i];
2493 if ((entry.EntryType & EntryType.Public) != 0 & entry.Member != ignore_member) {
2494 if (ignore_complex_types) {
2495 if ((entry.EntryType & EntryType.Method) != 0)
2498 // Does exist easier way how to detect indexer ?
2499 if ((entry.EntryType & EntryType.Property) != 0) {
2500 AParametersCollection arg_types = TypeManager.GetParameterData ((PropertyInfo)entry.Member);
2501 if (arg_types.Count > 0)
2505 return entry.Member;
2512 Hashtable locase_table;
2515 /// Builds low-case table for CLS Compliance test
2517 public Hashtable GetPublicMembers ()
2519 if (locase_table != null)
2520 return locase_table;
2522 locase_table = new Hashtable ();
2523 foreach (DictionaryEntry entry in member_hash) {
2524 ArrayList members = (ArrayList)entry.Value;
2525 for (int ii = 0; ii < members.Count; ++ii) {
2526 CacheEntry member_entry = (CacheEntry) members [ii];
2528 if ((member_entry.EntryType & EntryType.Public) == 0)
2531 // TODO: Does anyone know easier way how to detect that member is internal ?
2532 switch (member_entry.EntryType & EntryType.MaskType) {
2533 case EntryType.Constructor:
2536 case EntryType.Field:
2537 if ((((FieldInfo)member_entry.Member).Attributes & (FieldAttributes.Assembly | FieldAttributes.Public)) == FieldAttributes.Assembly)
2541 case EntryType.Method:
2542 if ((((MethodInfo)member_entry.Member).Attributes & (MethodAttributes.Assembly | MethodAttributes.Public)) == MethodAttributes.Assembly)
2546 case EntryType.Property:
2547 PropertyInfo pi = (PropertyInfo)member_entry.Member;
2548 if (pi.GetSetMethod () == null && pi.GetGetMethod () == null)
2552 case EntryType.Event:
2553 EventInfo ei = (EventInfo)member_entry.Member;
2554 MethodInfo mi = ei.GetAddMethod ();
2555 if ((mi.Attributes & (MethodAttributes.Assembly | MethodAttributes.Public)) == MethodAttributes.Assembly)
2559 string lcase = ((string)entry.Key).ToLower (System.Globalization.CultureInfo.InvariantCulture);
2560 locase_table [lcase] = member_entry.Member;
2564 return locase_table;
2567 public Hashtable Members {
2574 /// Cls compliance check whether methods or constructors parameters differing only in ref or out, or in array rank
2577 // TODO: refactor as method is always 'this'
2578 public static void VerifyClsParameterConflict (ArrayList al, MethodCore method, MemberInfo this_builder)
2580 EntryType tested_type = (method is Constructor ? EntryType.Constructor : EntryType.Method) | EntryType.Public;
2582 for (int i = 0; i < al.Count; ++i) {
2583 MemberCache.CacheEntry entry = (MemberCache.CacheEntry) al [i];
2586 if (entry.Member == this_builder)
2589 if ((entry.EntryType & tested_type) != tested_type)
2592 MethodBase method_to_compare = (MethodBase)entry.Member;
2593 AttributeTester.Result result = AttributeTester.AreOverloadedMethodParamsClsCompliant (
2594 method.Parameters, TypeManager.GetParameterData (method_to_compare));
2596 if (result == AttributeTester.Result.Ok)
2599 IMethodData md = TypeManager.GetMethod (method_to_compare);
2601 // TODO: now we are ignoring CLSCompliance(false) on method from other assembly which is buggy.
2602 // However it is exactly what csc does.
2603 if (md != null && !md.IsClsComplianceRequired ())
2606 Report.SymbolRelatedToPreviousError (entry.Member);
2608 case AttributeTester.Result.RefOutArrayError:
2609 Report.Warning (3006, 1, method.Location,
2610 "Overloaded method `{0}' differing only in ref or out, or in array rank, is not CLS-compliant",
2611 method.GetSignatureForError ());
2613 case AttributeTester.Result.ArrayArrayError:
2614 Report.Warning (3007, 1, method.Location,
2615 "Overloaded method `{0}' differing only by unnamed array types is not CLS-compliant",
2616 method.GetSignatureForError ());
2620 throw new NotImplementedException (result.ToString ());
2624 public bool CheckExistingMembersOverloads (MemberCore member, string name, Parameters parameters)
2626 ArrayList entries = (ArrayList)member_hash [name];
2627 if (entries == null)
2630 int method_param_count = parameters.Count;
2631 for (int i = entries.Count - 1; i >= 0; --i) {
2632 CacheEntry ce = (CacheEntry) entries [i];
2634 if (ce.Container != member.Parent.PartialContainer)
2638 AParametersCollection pd;
2639 if ((ce.EntryType & EntryType.Property) != 0) {
2640 pd = TypeManager.GetParameterData ((PropertyInfo) ce.Member);
2643 MethodBase mb = (MethodBase) ce.Member;
2645 // TODO: This is more like a hack, because we are adding generic methods
2646 // twice with and without arity name
2647 if (mb.IsGenericMethod && !member.MemberName.IsGeneric)
2650 pd = TypeManager.GetParameterData (mb);
2654 if (p_types.Length != method_param_count)
2657 if (method_param_count > 0) {
2658 int ii = method_param_count - 1;
2659 Type type_a, type_b;
2661 type_a = parameters.Types [ii];
2662 type_b = p_types [ii];
2665 if (type_a.IsGenericParameter && type_a.DeclaringMethod != null)
2668 if (type_b.IsGenericParameter && type_b.DeclaringMethod != null)
2671 if ((pd.FixedParameters [ii].ModFlags & Parameter.Modifier.ISBYREF) !=
2672 (parameters.FixedParameters [ii].ModFlags & Parameter.Modifier.ISBYREF))
2675 } while (type_a == type_b && ii-- != 0);
2681 // Operators can differ in return type only
2683 if (member is Operator) {
2684 Operator op = TypeManager.GetMethod ((MethodBase) ce.Member) as Operator;
2685 if (op != null && op.ReturnType != ((Operator) member).ReturnType)
2690 // Report difference in parameter modifiers only
2692 if (pd != null && member is MethodCore) {
2693 ii = method_param_count;
2694 while (ii-- != 0 && parameters.FixedParameters [ii].ModFlags == pd.FixedParameters [ii].ModFlags &&
2695 parameters.ExtensionMethodType == pd.ExtensionMethodType);
2698 MethodCore mc = TypeManager.GetMethod ((MethodBase) ce.Member) as MethodCore;
2699 Report.SymbolRelatedToPreviousError (ce.Member);
2700 if ((member.ModFlags & Modifiers.PARTIAL) != 0 && (mc.ModFlags & Modifiers.PARTIAL) != 0) {
2701 if (parameters.HasParams || pd.HasParams) {
2702 Report.Error (758, member.Location,
2703 "A partial method declaration and partial method implementation cannot differ on use of `params' modifier");
2705 Report.Error (755, member.Location,
2706 "A partial method declaration and partial method implementation must be both an extension method or neither");
2709 Report.Error (663, member.Location,
2710 "An overloaded method `{0}' cannot differ on use of parameter modifiers only",
2711 member.GetSignatureForError ());
2718 if ((ce.EntryType & EntryType.Method) != 0) {
2719 Method method_a = member as Method;
2720 Method method_b = TypeManager.GetMethod ((MethodBase) ce.Member) as Method;
2721 if (method_a != null && method_b != null && (method_a.ModFlags & method_b.ModFlags & Modifiers.PARTIAL) != 0) {
2722 const int partial_modifiers = Modifiers.STATIC | Modifiers.UNSAFE;
2723 if (method_a.IsPartialDefinition == method_b.IsPartialImplementation) {
2724 if ((method_a.ModFlags & partial_modifiers) == (method_b.ModFlags & partial_modifiers) ||
2725 method_a.Parent.IsInUnsafeScope && method_b.Parent.IsInUnsafeScope) {
2726 if (method_a.IsPartialImplementation) {
2727 method_a.SetPartialDefinition (method_b);
2728 entries.RemoveAt (i);
2730 method_b.SetPartialDefinition (method_a);
2735 if ((method_a.ModFlags & Modifiers.STATIC) != (method_b.ModFlags & Modifiers.STATIC)) {
2736 Report.SymbolRelatedToPreviousError (ce.Member);
2737 Report.Error (763, member.Location,
2738 "A partial method declaration and partial method implementation must be both `static' or neither");
2741 Report.SymbolRelatedToPreviousError (ce.Member);
2742 Report.Error (764, member.Location,
2743 "A partial method declaration and partial method implementation must be both `unsafe' or neither");
2747 Report.SymbolRelatedToPreviousError (ce.Member);
2748 if (method_a.IsPartialDefinition) {
2749 Report.Error (756, member.Location, "A partial method `{0}' declaration is already defined",
2750 member.GetSignatureForError ());
2753 Report.Error (757, member.Location, "A partial method `{0}' implementation is already defined",
2754 member.GetSignatureForError ());
2758 Report.SymbolRelatedToPreviousError (ce.Member);
2759 IMethodData duplicate_member = TypeManager.GetMethod ((MethodBase) ce.Member);
2760 if (member is Operator && duplicate_member is Operator) {
2761 Report.Error (557, member.Location, "Duplicate user-defined conversion in type `{0}'",
2762 member.Parent.GetSignatureForError ());
2766 bool is_reserved_a = member is AbstractPropertyEventMethod || member is Operator;
2767 bool is_reserved_b = duplicate_member is AbstractPropertyEventMethod || duplicate_member is Operator;
2769 if (is_reserved_a || is_reserved_b) {
2770 Report.Error (82, member.Location, "A member `{0}' is already reserved",
2772 TypeManager.GetFullNameSignature (ce.Member) :
2773 member.GetSignatureForError ());
2777 Report.SymbolRelatedToPreviousError (ce.Member);
2780 Report.Error (111, member.Location,
2781 "A member `{0}' is already defined. Rename this member or use different parameter types",
2782 member.GetSignatureForError ());