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 // Licensed under the terms of the GNU GPL
9 // (C) 2001 Ximian, Inc (http://www.ximian.com)
10 // (C) 2004 Novell, Inc
12 // TODO: Move the method verification stuff from the class.cs and interface.cs here
16 using System.Collections;
17 using System.Globalization;
18 using System.Reflection.Emit;
19 using System.Reflection;
21 #if BOOTSTRAP_WITH_OLDLIB
22 using XmlElement = System.Object;
27 namespace Mono.CSharp {
29 public class MemberName {
30 public readonly string Name;
31 public readonly TypeArguments TypeArguments;
33 public readonly MemberName Left;
34 public readonly Location Location;
36 public static readonly MemberName Null = new MemberName ("");
40 private MemberName (MemberName left, string name, bool is_double_colon,
45 this.is_double_colon = is_double_colon;
49 private MemberName (MemberName left, string name, bool is_double_colon,
50 TypeArguments args, Location loc)
51 : this (left, name, is_double_colon, loc)
53 this.TypeArguments = args;
56 public MemberName (string name)
57 : this (name, Location.Null)
60 public MemberName (string name, Location loc)
61 : this (null, name, false, loc)
64 public MemberName (string name, TypeArguments args, Location loc)
65 : this (null, name, false, args, loc)
68 public MemberName (MemberName left, string name)
69 : this (left, name, left != null ? left.Location : Location.Null)
72 public MemberName (MemberName left, string name, Location loc)
73 : this (left, name, false, loc)
76 public MemberName (MemberName left, string name, TypeArguments args, Location loc)
77 : this (left, name, false, args, loc)
80 public MemberName (string alias, string name, Location loc)
81 : this (new MemberName (alias, loc), name, true, loc)
84 public MemberName (MemberName left, MemberName right)
85 : this (left, right, right.Location)
88 public MemberName (MemberName left, MemberName right, Location loc)
89 : this (null, right.Name, false, right.TypeArguments, loc)
91 if (right.is_double_colon)
92 throw new InternalErrorException ("Cannot append double_colon member name");
93 this.Left = (right.Left == null) ? left : new MemberName (left, right.Left);
96 public string GetName ()
98 return GetName (false);
101 public bool IsGeneric {
103 if (TypeArguments != null)
105 else if (Left != null)
106 return Left.IsGeneric;
112 public string GetName (bool is_generic)
114 string name = is_generic ? Basename : Name;
115 string connect = is_double_colon ? "::" : ".";
117 return Left.GetName (is_generic) + connect + name;
122 public string GetTypeName ()
124 string connect = is_double_colon ? "::" : ".";
126 return Left.GetTypeName () + connect + Name;
131 public Expression GetTypeExpression ()
134 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, Location);
141 Expression lexpr = Left.GetTypeExpression ();
142 return new MemberAccess (lexpr, Name);
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);
160 public string FullName {
162 if (TypeArguments != null)
163 return Name + "<" + TypeArguments + ">";
169 public string MethodName {
171 string connect = is_double_colon ? "::" : ".";
173 return Left.FullName + connect + Name;
179 public override string ToString ()
181 string connect = is_double_colon ? "::" : ".";
183 return Left.FullName + connect + FullName;
188 public override bool Equals (object other)
190 return Equals (other as MemberName);
193 public bool Equals (MemberName other)
197 if (other == null || Name != other.Name)
199 if (is_double_colon != other.is_double_colon)
202 if ((TypeArguments != null) &&
203 (other.TypeArguments == null || TypeArguments.Count != other.TypeArguments.Count))
206 if ((TypeArguments == null) && (other.TypeArguments != null))
210 return other.Left == null;
212 return Left.Equals (other.Left);
215 public override int GetHashCode ()
217 int hash = Name.GetHashCode ();
218 for (MemberName n = Left; n != null; n = n.Left)
219 hash ^= n.Name.GetHashCode ();
223 if (TypeArguments != null)
224 hash ^= TypeArguments.Count << 5;
226 return hash & 0x7FFFFFFF;
229 public int CountTypeArguments {
231 if (TypeArguments == null)
234 return TypeArguments.Count;
238 public static string MakeName (string name, TypeArguments args)
243 return name + "`" + args.Count;
246 public static string MakeName (string name, int count)
248 return name + "`" + count;
251 protected bool IsUnbound {
253 if ((Left != null) && Left.IsUnbound)
255 else if (TypeArguments == null)
258 return TypeArguments.IsUnbound;
262 protected bool CheckUnbound (Location loc)
264 if ((Left != null) && !Left.CheckUnbound (loc))
266 if ((TypeArguments != null) && !TypeArguments.IsUnbound) {
267 Report.Error (1031, loc, "Type expected");
276 /// Base representation for members. This is used to keep track
277 /// of Name, Location and Modifier flags, and handling Attributes.
279 public abstract class MemberCore : Attributable, IResolveContext {
284 protected string cached_name;
287 if (cached_name == null)
288 cached_name = MemberName.GetName (false);
293 // Is not readonly because of IndexerName attribute
294 private MemberName member_name;
295 public MemberName MemberName {
296 get { return member_name; }
300 /// Modifier flags that the user specified in the source code
304 public readonly DeclSpace Parent;
307 /// Location where this declaration happens
309 public Location Location {
310 get { return member_name.Location; }
314 /// XML documentation comment
316 protected string comment;
319 /// Represents header string for documentation comment
320 /// for each member types.
322 public abstract string DocCommentHeader { get; }
326 Obsolete_Undetected = 1, // Obsolete attribute has not been detected yet
327 Obsolete = 1 << 1, // Type has obsolete attribute
328 ClsCompliance_Undetected = 1 << 2, // CLS Compliance has not been detected yet
329 ClsCompliant = 1 << 3, // Type is CLS Compliant
330 CloseTypeCreated = 1 << 4, // Tracks whether we have Closed the type
331 HasCompliantAttribute_Undetected = 1 << 5, // Presence of CLSCompliantAttribute has not been detected
332 HasClsCompliantAttribute = 1 << 6, // Type has CLSCompliantAttribute
333 ClsCompliantAttributeTrue = 1 << 7, // Type has CLSCompliant (true)
334 Excluded_Undetected = 1 << 8, // Conditional attribute has not been detected yet
335 Excluded = 1 << 9, // Method is conditional
336 TestMethodDuplication = 1 << 10, // Test for duplication must be performed
338 IsAssigned = 1 << 12, // Field is assigned
339 HasExplicitLayout = 1 << 13
343 /// MemberCore flags at first detected then cached
345 internal Flags caching_flags;
347 public MemberCore (DeclSpace parent, MemberName name, Attributes attrs)
350 this.Parent = parent;
352 caching_flags = Flags.Obsolete_Undetected | Flags.ClsCompliance_Undetected | Flags.HasCompliantAttribute_Undetected | Flags.Excluded_Undetected;
355 protected virtual void SetMemberName (MemberName new_name)
357 member_name = new_name;
361 public abstract bool Define ();
363 public virtual string DocComment {
373 // Returns full member name for error message
375 public virtual string GetSignatureForError ()
377 if (Parent == null || Parent.Parent == null)
378 return member_name.ToString ();
380 return String.Concat (Parent.GetSignatureForError (), '.', member_name.ToString ());
384 /// Base Emit method. This is also entry point for CLS-Compliant verification.
386 public virtual void Emit ()
388 if (!RootContext.VerifyClsCompliance)
391 VerifyClsCompliance ();
394 public virtual bool IsUsed {
395 get { return (caching_flags & Flags.IsUsed) != 0; }
398 public void SetMemberIsUsed ()
400 caching_flags |= Flags.IsUsed;
404 /// Returns instance of ObsoleteAttribute for this MemberCore
406 public virtual ObsoleteAttribute GetObsoleteAttribute ()
408 // ((flags & (Flags.Obsolete_Undetected | Flags.Obsolete)) == 0) is slower, but why ?
409 if ((caching_flags & Flags.Obsolete_Undetected) == 0 && (caching_flags & Flags.Obsolete) == 0) {
413 caching_flags &= ~Flags.Obsolete_Undetected;
415 if (OptAttributes == null)
418 Attribute obsolete_attr = OptAttributes.Search (
419 TypeManager.obsolete_attribute_type);
420 if (obsolete_attr == null)
423 ObsoleteAttribute obsolete = obsolete_attr.GetObsoleteAttribute ();
424 if (obsolete == null)
427 caching_flags |= Flags.Obsolete;
432 /// Checks for ObsoleteAttribute presence. It's used for testing of all non-types elements
434 public virtual void CheckObsoleteness (Location loc)
437 Parent.CheckObsoleteness (loc);
439 ObsoleteAttribute oa = GetObsoleteAttribute ();
444 AttributeTester.Report_ObsoleteMessage (oa, GetSignatureForError (), loc);
448 /// Analyze whether CLS-Compliant verification must be execute for this MemberCore.
450 public override bool IsClsComplianceRequired ()
452 if ((caching_flags & Flags.ClsCompliance_Undetected) == 0)
453 return (caching_flags & Flags.ClsCompliant) != 0;
455 if (GetClsCompliantAttributeValue () && IsExposedFromAssembly ()) {
456 caching_flags &= ~Flags.ClsCompliance_Undetected;
457 caching_flags |= Flags.ClsCompliant;
461 caching_flags &= ~Flags.ClsCompliance_Undetected;
466 /// Returns true when MemberCore is exposed from assembly.
468 public bool IsExposedFromAssembly ()
470 if ((ModFlags & (Modifiers.PUBLIC | Modifiers.PROTECTED)) == 0)
473 DeclSpace parentContainer = Parent;
474 while (parentContainer != null && parentContainer.ModFlags != 0) {
475 if ((parentContainer.ModFlags & (Modifiers.PUBLIC | Modifiers.PROTECTED)) == 0)
477 parentContainer = parentContainer.Parent;
483 /// Goes through class hierarchy and gets value of first found CLSCompliantAttribute.
484 /// If no is attribute exists then assembly CLSCompliantAttribute is returned.
486 public virtual bool GetClsCompliantAttributeValue ()
488 if ((caching_flags & Flags.HasCompliantAttribute_Undetected) == 0)
489 return (caching_flags & Flags.ClsCompliantAttributeTrue) != 0;
491 caching_flags &= ~Flags.HasCompliantAttribute_Undetected;
493 if (OptAttributes != null) {
494 Attribute cls_attribute = OptAttributes.Search (
495 TypeManager.cls_compliant_attribute_type);
496 if (cls_attribute != null) {
497 caching_flags |= Flags.HasClsCompliantAttribute;
498 bool value = cls_attribute.GetClsCompliantAttributeValue ();
500 caching_flags |= Flags.ClsCompliantAttributeTrue;
505 if (Parent.GetClsCompliantAttributeValue ()) {
506 caching_flags |= Flags.ClsCompliantAttributeTrue;
513 /// Returns true if MemberCore is explicitly marked with CLSCompliantAttribute
515 protected bool HasClsCompliantAttribute {
517 return (caching_flags & Flags.HasClsCompliantAttribute) != 0;
522 /// It helps to handle error 102 & 111 detection
524 public virtual bool MarkForDuplicationCheck ()
530 /// The main virtual method for CLS-Compliant verifications.
531 /// The method returns true if member is CLS-Compliant and false if member is not
532 /// CLS-Compliant which means that CLS-Compliant tests are not necessary. A descendants override it
533 /// and add their extra verifications.
535 protected virtual bool VerifyClsCompliance ()
537 if (!IsClsComplianceRequired ()) {
538 if (HasClsCompliantAttribute && RootContext.WarningLevel >= 2) {
539 if (!IsExposedFromAssembly ())
540 Report.Warning (3019, 2, Location, "CLS compliance checking will not be performed on `{0}' because it is not visible from outside this assembly", GetSignatureForError ());
541 if (!CodeGen.Assembly.IsClsCompliant)
542 Report.Warning (3021, 2, Location, "`{0}' does not need a CLSCompliant attribute because the assembly is not marked as CLS-compliant", GetSignatureForError ());
547 if (!CodeGen.Assembly.IsClsCompliant) {
548 if (HasClsCompliantAttribute) {
549 Report.Error (3014, Location,
550 "`{0}' cannot be marked as CLS-compliant because the assembly is not marked as CLS-compliant",
551 GetSignatureForError ());
556 if (member_name.Name [0] == '_') {
557 Report.Error (3008, Location, "Identifier `{0}' is not CLS-compliant", GetSignatureForError () );
563 // Raised (and passed an XmlElement that contains the comment)
564 // when GenerateDocComment is writing documentation expectedly.
566 internal virtual void OnGenerateDocComment (XmlElement intermediateNode)
571 // Returns a string that represents the signature for this
572 // member which should be used in XML documentation.
574 public virtual string GetDocCommentName (DeclSpace ds)
576 if (ds == null || this is DeclSpace)
577 return DocCommentHeader + Name;
579 return String.Concat (DocCommentHeader, ds.Name, ".", Name);
583 // Generates xml doc comments (if any), and if required,
584 // handle warning report.
586 internal virtual void GenerateDocComment (DeclSpace ds)
588 DocUtil.GenerateDocComment (this, ds);
591 public override IResolveContext ResolveContext {
595 #region IResolveContext Members
597 public DeclSpace DeclContainer {
598 get { return Parent; }
601 public virtual DeclSpace GenericDeclContainer {
602 get { return DeclContainer; }
605 public bool IsInObsoleteScope {
607 if (GetObsoleteAttribute () != null)
610 return Parent == null ? false : Parent.IsInObsoleteScope;
614 public bool IsInUnsafeScope {
616 if ((ModFlags & Modifiers.UNSAFE) != 0)
619 return Parent == null ? false : Parent.IsInUnsafeScope;
627 /// Base class for structs, classes, enumerations and interfaces.
630 /// They all create new declaration spaces. This
631 /// provides the common foundation for managing those name
634 public abstract class DeclSpace : MemberCore {
637 /// This points to the actual definition that is being
638 /// created with System.Reflection.Emit
640 public TypeBuilder TypeBuilder;
643 // This is the namespace in which this typecontainer
644 // was declared. We use this to resolve names.
646 public NamespaceEntry NamespaceEntry;
648 private Hashtable Cache = new Hashtable ();
650 public string Basename;
652 protected Hashtable defined_names;
654 public TypeContainer PartialContainer;
657 // Whether we are Generic
659 public bool IsGeneric {
660 get { return false; }
663 static string[] attribute_targets = new string [] { "type" };
665 public DeclSpace (NamespaceEntry ns, DeclSpace parent, MemberName name,
667 : base (parent, name, attrs)
670 Basename = name.Name;
671 defined_names = new Hashtable ();
672 PartialContainer = null;
675 public override DeclSpace GenericDeclContainer {
680 /// Adds the member to defined_names table. It tests for duplications and enclosing name conflicts
682 protected virtual bool AddToContainer (MemberCore symbol, string name)
684 MemberCore mc = (MemberCore) defined_names [name];
687 defined_names.Add (name, symbol);
691 if (symbol.MarkForDuplicationCheck () && mc.MarkForDuplicationCheck ())
694 Report.SymbolRelatedToPreviousError (mc);
695 if ((mc.ModFlags & Modifiers.PARTIAL) != 0 && (symbol is ClassOrStruct || symbol is Interface)) {
696 Error_MissingPartialModifier (symbol);
700 if (this is RootTypes) {
701 Report.Error (101, symbol.Location,
702 "The namespace `{0}' already contains a definition for `{1}'",
703 ((DeclSpace)symbol).NamespaceEntry.GetSignatureForError (), symbol.MemberName.Name);
705 Report.Error (102, symbol.Location,
706 "The type `{0}' already contains a definition for `{1}'",
707 GetSignatureForError (), symbol.MemberName.Name);
714 /// Returns the MemberCore associated with a given name in the declaration
715 /// space. It doesn't return method based symbols !!
718 public MemberCore GetDefinition (string name)
720 return (MemberCore)defined_names [name];
724 // root_types contains all the types. All TopLevel types
725 // hence have a parent that points to `root_types', that is
726 // why there is a non-obvious test down here.
728 public bool IsTopLevel {
729 get { return (Parent != null && Parent.Parent == null); }
732 public virtual void CloseType ()
734 if ((caching_flags & Flags.CloseTypeCreated) == 0){
736 TypeBuilder.CreateType ();
739 // The try/catch is needed because
740 // nested enumerations fail to load when they
743 // Even if this is the right order (enumerations
744 // declared after types).
746 // Note that this still creates the type and
747 // it is possible to save it
749 caching_flags |= Flags.CloseTypeCreated;
753 protected virtual TypeAttributes TypeAttr {
754 get { return CodeGen.Module.DefaultCharSetType; }
758 /// Should be overriten by the appropriate declaration space
760 public abstract TypeBuilder DefineType ();
763 /// Define all members, but don't apply any attributes or do anything which may
764 /// access not-yet-defined classes. This method also creates the MemberCache.
766 public virtual bool DefineMembers ()
768 if (((ModFlags & Modifiers.NEW) != 0) && IsTopLevel) {
769 Report.Error (1530, Location, "Keyword `new' is not allowed on namespace elements");
775 protected void Error_MissingPartialModifier (MemberCore type)
777 Report.Error (260, type.Location,
778 "Missing partial modifier on declaration of type `{0}'. Another partial declaration of this type exists",
779 type.GetSignatureForError ());
782 public override string GetSignatureForError ()
784 // Parent.GetSignatureForError
788 public bool CheckAccessLevel (Type check_type)
790 if (check_type == TypeBuilder)
793 TypeAttributes check_attr = check_type.Attributes & TypeAttributes.VisibilityMask;
796 // Broken Microsoft runtime, return public for arrays, no matter what
797 // the accessibility is for their underlying class, and they return
798 // NonPublic visibility for pointers
800 if (check_type.IsArray || check_type.IsPointer)
801 return CheckAccessLevel (TypeManager.GetElementType (check_type));
803 if (TypeBuilder == null)
804 // FIXME: TypeBuilder will be null when invoked by Class.GetNormalBases().
805 // However, this is invoked again later -- so safe to return true.
806 // May also be null when resolving top-level attributes.
810 case TypeAttributes.Public:
813 case TypeAttributes.NotPublic:
815 // This test should probably use the declaringtype.
817 return check_type.Assembly == TypeBuilder.Assembly;
819 case TypeAttributes.NestedPublic:
822 case TypeAttributes.NestedPrivate:
823 return NestedAccessible (check_type);
825 case TypeAttributes.NestedFamily:
826 return FamilyAccessible (check_type);
828 case TypeAttributes.NestedFamANDAssem:
829 return (check_type.Assembly == TypeBuilder.Assembly) &&
830 FamilyAccessible (check_type);
832 case TypeAttributes.NestedFamORAssem:
833 return (check_type.Assembly == TypeBuilder.Assembly) ||
834 FamilyAccessible (check_type);
836 case TypeAttributes.NestedAssembly:
837 return check_type.Assembly == TypeBuilder.Assembly;
840 Console.WriteLine ("HERE: " + check_attr);
845 protected bool NestedAccessible (Type check_type)
847 Type declaring = check_type.DeclaringType;
848 return TypeBuilder == declaring ||
849 TypeManager.IsNestedChildOf (TypeBuilder, declaring);
852 protected bool FamilyAccessible (Type check_type)
854 Type declaring = check_type.DeclaringType;
855 return TypeManager.IsNestedFamilyAccessible (TypeBuilder, declaring);
858 // Access level of a type.
860 enum AccessLevel { // Each column represents `is this scope larger or equal to Blah scope'
861 // Public Assembly Protected
862 Protected = (0 << 0) | (0 << 1) | (X << 2),
863 Public = (X << 0) | (X << 1) | (X << 2),
864 Private = (0 << 0) | (0 << 1) | (0 << 2),
865 Internal = (0 << 0) | (X << 1) | (0 << 2),
866 ProtectedOrInternal = (0 << 0) | (X << 1) | (X << 2),
869 static AccessLevel GetAccessLevelFromModifiers (int flags)
871 if ((flags & Modifiers.INTERNAL) != 0) {
873 if ((flags & Modifiers.PROTECTED) != 0)
874 return AccessLevel.ProtectedOrInternal;
876 return AccessLevel.Internal;
878 } else if ((flags & Modifiers.PROTECTED) != 0)
879 return AccessLevel.Protected;
881 else if ((flags & Modifiers.PRIVATE) != 0)
882 return AccessLevel.Private;
885 return AccessLevel.Public;
888 // What is the effective access level of this?
890 AccessLevel EffectiveAccessLevel {
892 AccessLevel myAccess = GetAccessLevelFromModifiers (ModFlags);
893 if (!IsTopLevel && (Parent != null))
894 return myAccess & Parent.EffectiveAccessLevel;
899 // Return the access level for type `t'
900 static AccessLevel TypeEffectiveAccessLevel (Type t)
903 return AccessLevel.Public;
904 if (t.IsNestedPrivate)
905 return AccessLevel.Private;
907 return AccessLevel.Internal;
909 // By now, it must be nested
910 AccessLevel parentLevel = TypeEffectiveAccessLevel (t.DeclaringType);
912 if (t.IsNestedPublic)
914 if (t.IsNestedAssembly)
915 return parentLevel & AccessLevel.Internal;
916 if (t.IsNestedFamily)
917 return parentLevel & AccessLevel.Protected;
918 if (t.IsNestedFamORAssem)
919 return parentLevel & AccessLevel.ProtectedOrInternal;
920 if (t.IsNestedFamANDAssem)
921 throw new NotImplementedException ("NestedFamANDAssem not implemented, cant make this kind of type from c# anyways");
923 // nested private is taken care of
925 throw new Exception ("I give up, what are you?");
929 // This answers `is the type P, as accessible as a member M which has the
930 // accessability @flags which is declared as a nested member of the type T, this declspace'
932 public bool AsAccessible (Type p, int flags)
935 // 1) if M is private, its accessability is the same as this declspace.
936 // we already know that P is accessible to T before this method, so we
940 if ((flags & Modifiers.PRIVATE) != 0)
943 while (p.IsArray || p.IsPointer || p.IsByRef)
944 p = TypeManager.GetElementType (p);
946 AccessLevel pAccess = TypeEffectiveAccessLevel (p);
947 AccessLevel mAccess = this.EffectiveAccessLevel &
948 GetAccessLevelFromModifiers (flags);
950 // for every place from which we can access M, we must
951 // be able to access P as well. So, we want
952 // For every bit in M and P, M_i -> P_1 == true
953 // or, ~ (M -> P) == 0 <-> ~ ( ~M | P) == 0
955 return ~ (~ mAccess | pAccess) == 0;
958 private Type LookupNestedTypeInHierarchy (string name)
960 // if the member cache has been created, lets use it.
961 // the member cache is MUCH faster.
962 if (MemberCache != null)
963 return MemberCache.FindNestedType (name);
965 // no member cache. Do it the hard way -- reflection
967 for (Type current_type = TypeBuilder;
968 current_type != null && current_type != TypeManager.object_type;
969 current_type = current_type.BaseType) {
970 if (current_type is TypeBuilder) {
971 TypeContainer tc = current_type == TypeBuilder
973 : TypeManager.LookupTypeContainer (current_type);
975 t = tc.FindNestedType (name);
977 t = TypeManager.GetNestedType (current_type, name);
980 if (t != null && CheckAccessLevel (t))
988 // Public function used to locate types.
990 // Set 'ignore_cs0104' to true if you want to ignore cs0104 errors.
992 // Returns: Type or null if they type can not be found.
994 public FullNamedExpression LookupType (string name, Location loc, bool ignore_cs0104)
996 if (Cache.Contains (name))
997 return (FullNamedExpression) Cache [name];
999 FullNamedExpression e;
1000 Type t = LookupNestedTypeInHierarchy (name);
1002 e = new TypeExpression (t, Location.Null);
1003 else if (Parent != null)
1004 e = Parent.LookupType (name, loc, ignore_cs0104);
1006 e = NamespaceEntry.LookupNamespaceOrType (this, name, loc, ignore_cs0104);
1013 /// This function is broken and not what you're looking for. It should only
1014 /// be used while the type is still being created since it doesn't use the cache
1015 /// and relies on the filter doing the member name check.
1017 public abstract MemberList FindMembers (MemberTypes mt, BindingFlags bf,
1018 MemberFilter filter, object criteria);
1021 /// If we have a MemberCache, return it. This property may return null if the
1022 /// class doesn't have a member cache or while it's still being created.
1024 public abstract MemberCache MemberCache {
1028 public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
1030 if (a.Type == TypeManager.required_attr_type) {
1031 Report.Error (1608, a.Location, "The RequiredAttribute attribute is not permitted on C# types");
1034 TypeBuilder.SetCustomAttribute (cb);
1037 public override string[] ValidAttributeTargets {
1038 get { return attribute_targets; }
1041 protected override bool VerifyClsCompliance ()
1043 if (!base.VerifyClsCompliance ()) {
1047 IDictionary cache = TypeManager.AllClsTopLevelTypes;
1048 string lcase = Name.ToLower (System.Globalization.CultureInfo.InvariantCulture);
1049 if (!cache.Contains (lcase)) {
1050 cache.Add (lcase, this);
1054 object val = cache [lcase];
1056 Type t = AttributeTester.GetImportedIgnoreCaseClsType (lcase);
1059 Report.SymbolRelatedToPreviousError (t);
1062 Report.SymbolRelatedToPreviousError ((DeclSpace)val);
1064 Report.Error (3005, Location, "Identifier `{0}' differing only in case is not CLS-compliant", GetSignatureForError ());
1070 /// This is a readonly list of MemberInfo's.
1072 public class MemberList : IList {
1073 public readonly IList List;
1077 /// Create a new MemberList from the given IList.
1079 public MemberList (IList list)
1084 this.List = new ArrayList ();
1089 /// Concatenate the ILists `first' and `second' to a new MemberList.
1091 public MemberList (IList first, IList second)
1093 ArrayList list = new ArrayList ();
1094 list.AddRange (first);
1095 list.AddRange (second);
1100 public static readonly MemberList Empty = new MemberList (new ArrayList ());
1103 /// Cast the MemberList into a MemberInfo[] array.
1106 /// This is an expensive operation, only use it if it's really necessary.
1108 public static explicit operator MemberInfo [] (MemberList list)
1110 Timer.StartTimer (TimerType.MiscTimer);
1111 MemberInfo [] result = new MemberInfo [list.Count];
1112 list.CopyTo (result, 0);
1113 Timer.StopTimer (TimerType.MiscTimer);
1125 public bool IsSynchronized {
1127 return List.IsSynchronized;
1131 public object SyncRoot {
1133 return List.SyncRoot;
1137 public void CopyTo (Array array, int index)
1139 List.CopyTo (array, index);
1144 public IEnumerator GetEnumerator ()
1146 return List.GetEnumerator ();
1151 public bool IsFixedSize {
1157 public bool IsReadOnly {
1163 object IList.this [int index] {
1165 return List [index];
1169 throw new NotSupportedException ();
1173 // FIXME: try to find out whether we can avoid the cast in this indexer.
1174 public MemberInfo this [int index] {
1176 return (MemberInfo) List [index];
1180 public int Add (object value)
1182 throw new NotSupportedException ();
1185 public void Clear ()
1187 throw new NotSupportedException ();
1190 public bool Contains (object value)
1192 return List.Contains (value);
1195 public int IndexOf (object value)
1197 return List.IndexOf (value);
1200 public void Insert (int index, object value)
1202 throw new NotSupportedException ();
1205 public void Remove (object value)
1207 throw new NotSupportedException ();
1210 public void RemoveAt (int index)
1212 throw new NotSupportedException ();
1217 /// This interface is used to get all members of a class when creating the
1218 /// member cache. It must be implemented by all DeclSpace derivatives which
1219 /// want to support the member cache and by TypeHandle to get caching of
1220 /// non-dynamic types.
1222 public interface IMemberContainer {
1224 /// The name of the IMemberContainer. This is only used for
1225 /// debugging purposes.
1232 /// The type of this IMemberContainer.
1239 /// Returns the IMemberContainer of the base class or null if this
1240 /// is an interface or TypeManger.object_type.
1241 /// This is used when creating the member cache for a class to get all
1242 /// members from the base class.
1244 MemberCache BaseCache {
1249 /// Whether this is an interface.
1256 /// Returns all members of this class with the corresponding MemberTypes
1257 /// and BindingFlags.
1260 /// When implementing this method, make sure not to return any inherited
1261 /// members and check the MemberTypes and BindingFlags properly.
1262 /// Unfortunately, System.Reflection is lame and doesn't provide a way to
1263 /// get the BindingFlags (static/non-static,public/non-public) in the
1264 /// MemberInfo class, but the cache needs this information. That's why
1265 /// this method is called multiple times with different BindingFlags.
1267 MemberList GetMembers (MemberTypes mt, BindingFlags bf);
1270 /// Return the container's member cache.
1272 MemberCache MemberCache {
1278 /// The MemberCache is used by dynamic and non-dynamic types to speed up
1279 /// member lookups. It has a member name based hash table; it maps each member
1280 /// name to a list of CacheEntry objects. Each CacheEntry contains a MemberInfo
1281 /// and the BindingFlags that were initially used to get it. The cache contains
1282 /// all members of the current class and all inherited members. If this cache is
1283 /// for an interface types, it also contains all inherited members.
1285 /// There are two ways to get a MemberCache:
1286 /// * if this is a dynamic type, lookup the corresponding DeclSpace and then
1287 /// use the DeclSpace.MemberCache property.
1288 /// * if this not a dynamic type, call TypeHandle.GetTypeHandle() to get a
1289 /// TypeHandle instance for the type and then use TypeHandle.MemberCache.
1291 public class MemberCache {
1292 public readonly IMemberContainer Container;
1293 protected Hashtable member_hash;
1294 protected Hashtable method_hash;
1297 /// Create a new MemberCache for the given IMemberContainer `container'.
1299 public MemberCache (IMemberContainer container)
1301 this.Container = container;
1303 Timer.IncrementCounter (CounterType.MemberCache);
1304 Timer.StartTimer (TimerType.CacheInit);
1306 // If we have a base class (we have a base class unless we're
1307 // TypeManager.object_type), we deep-copy its MemberCache here.
1308 if (Container.BaseCache != null)
1309 member_hash = SetupCache (Container.BaseCache);
1311 member_hash = new Hashtable ();
1313 // If this is neither a dynamic type nor an interface, create a special
1314 // method cache with all declared and inherited methods.
1315 Type type = container.Type;
1316 if (!(type is TypeBuilder) && !type.IsInterface &&
1317 (Container.BaseCache == null || Container.BaseCache.method_hash != null)) {
1318 method_hash = new Hashtable ();
1322 // Add all members from the current class.
1323 AddMembers (Container);
1325 Timer.StopTimer (TimerType.CacheInit);
1328 public MemberCache (Type[] ifaces)
1331 // The members of this cache all belong to other caches.
1332 // So, 'Container' will not be used.
1334 this.Container = null;
1336 member_hash = new Hashtable ();
1340 foreach (Type itype in ifaces)
1341 AddCacheContents (TypeManager.LookupMemberCache (itype));
1345 /// Bootstrap this member cache by doing a deep-copy of our base.
1347 static Hashtable SetupCache (MemberCache base_class)
1349 Hashtable hash = new Hashtable ();
1351 if (base_class == null)
1354 IDictionaryEnumerator it = base_class.member_hash.GetEnumerator ();
1355 while (it.MoveNext ()) {
1356 hash [it.Key] = ((ArrayList) it.Value).Clone ();
1363 /// Add the contents of `cache' to the member_hash.
1365 void AddCacheContents (MemberCache cache)
1367 IDictionaryEnumerator it = cache.member_hash.GetEnumerator ();
1368 while (it.MoveNext ()) {
1369 ArrayList list = (ArrayList) member_hash [it.Key];
1371 member_hash [it.Key] = list = new ArrayList ();
1373 ArrayList entries = (ArrayList) it.Value;
1374 for (int i = entries.Count-1; i >= 0; i--) {
1375 CacheEntry entry = (CacheEntry) entries [i];
1377 if (entry.Container != cache.Container)
1385 /// Add all members from class `container' to the cache.
1387 void AddMembers (IMemberContainer container)
1389 // We need to call AddMembers() with a single member type at a time
1390 // to get the member type part of CacheEntry.EntryType right.
1391 if (!container.IsInterface) {
1392 AddMembers (MemberTypes.Constructor, container);
1393 AddMembers (MemberTypes.Field, container);
1395 AddMembers (MemberTypes.Method, container);
1396 AddMembers (MemberTypes.Property, container);
1397 AddMembers (MemberTypes.Event, container);
1398 // Nested types are returned by both Static and Instance searches.
1399 AddMembers (MemberTypes.NestedType,
1400 BindingFlags.Static | BindingFlags.Public, container);
1401 AddMembers (MemberTypes.NestedType,
1402 BindingFlags.Static | BindingFlags.NonPublic, container);
1405 void AddMembers (MemberTypes mt, IMemberContainer container)
1407 AddMembers (mt, BindingFlags.Static | BindingFlags.Public, container);
1408 AddMembers (mt, BindingFlags.Static | BindingFlags.NonPublic, container);
1409 AddMembers (mt, BindingFlags.Instance | BindingFlags.Public, container);
1410 AddMembers (mt, BindingFlags.Instance | BindingFlags.NonPublic, container);
1414 /// Add all members from class `container' with the requested MemberTypes and
1415 /// BindingFlags to the cache. This method is called multiple times with different
1416 /// MemberTypes and BindingFlags.
1418 void AddMembers (MemberTypes mt, BindingFlags bf, IMemberContainer container)
1420 MemberList members = container.GetMembers (mt, bf);
1422 foreach (MemberInfo member in members) {
1423 string name = member.Name;
1425 // We use a name-based hash table of ArrayList's.
1426 ArrayList list = (ArrayList) member_hash [name];
1428 list = new ArrayList ();
1429 member_hash.Add (name, list);
1432 // When this method is called for the current class, the list will
1433 // already contain all inherited members from our base classes.
1434 // We cannot add new members in front of the list since this'd be an
1435 // expensive operation, that's why the list is sorted in reverse order
1436 // (ie. members from the current class are coming last).
1437 list.Add (new CacheEntry (container, member, mt, bf));
1442 /// Add all declared and inherited methods from class `type' to the method cache.
1444 void AddMethods (Type type)
1446 AddMethods (BindingFlags.Static | BindingFlags.Public |
1447 BindingFlags.FlattenHierarchy, type);
1448 AddMethods (BindingFlags.Static | BindingFlags.NonPublic |
1449 BindingFlags.FlattenHierarchy, type);
1450 AddMethods (BindingFlags.Instance | BindingFlags.Public, type);
1451 AddMethods (BindingFlags.Instance | BindingFlags.NonPublic, type);
1454 static ArrayList overrides = new ArrayList ();
1456 void AddMethods (BindingFlags bf, Type type)
1458 MethodBase [] members = type.GetMethods (bf);
1460 Array.Reverse (members);
1462 foreach (MethodBase member in members) {
1463 string name = member.Name;
1465 // We use a name-based hash table of ArrayList's.
1466 ArrayList list = (ArrayList) method_hash [name];
1468 list = new ArrayList ();
1469 method_hash.Add (name, list);
1472 MethodInfo curr = (MethodInfo) member;
1473 while (curr.IsVirtual && (curr.Attributes & MethodAttributes.NewSlot) == 0) {
1474 MethodInfo base_method = curr.GetBaseDefinition ();
1476 if (base_method == curr)
1477 // Not every virtual function needs to have a NewSlot flag.
1480 overrides.Add (curr);
1481 list.Add (new CacheEntry (null, base_method, MemberTypes.Method, bf));
1485 if (overrides.Count > 0) {
1486 for (int i = 0; i < overrides.Count; ++i)
1487 TypeManager.RegisterOverride ((MethodBase) overrides [i], curr);
1491 // Unfortunately, the elements returned by Type.GetMethods() aren't
1492 // sorted so we need to do this check for every member.
1493 BindingFlags new_bf = bf;
1494 if (member.DeclaringType == type)
1495 new_bf |= BindingFlags.DeclaredOnly;
1497 list.Add (new CacheEntry (Container, member, MemberTypes.Method, new_bf));
1502 /// Compute and return a appropriate `EntryType' magic number for the given
1503 /// MemberTypes and BindingFlags.
1505 protected static EntryType GetEntryType (MemberTypes mt, BindingFlags bf)
1507 EntryType type = EntryType.None;
1509 if ((mt & MemberTypes.Constructor) != 0)
1510 type |= EntryType.Constructor;
1511 if ((mt & MemberTypes.Event) != 0)
1512 type |= EntryType.Event;
1513 if ((mt & MemberTypes.Field) != 0)
1514 type |= EntryType.Field;
1515 if ((mt & MemberTypes.Method) != 0)
1516 type |= EntryType.Method;
1517 if ((mt & MemberTypes.Property) != 0)
1518 type |= EntryType.Property;
1519 // Nested types are returned by static and instance searches.
1520 if ((mt & MemberTypes.NestedType) != 0)
1521 type |= EntryType.NestedType | EntryType.Static | EntryType.Instance;
1523 if ((bf & BindingFlags.Instance) != 0)
1524 type |= EntryType.Instance;
1525 if ((bf & BindingFlags.Static) != 0)
1526 type |= EntryType.Static;
1527 if ((bf & BindingFlags.Public) != 0)
1528 type |= EntryType.Public;
1529 if ((bf & BindingFlags.NonPublic) != 0)
1530 type |= EntryType.NonPublic;
1531 if ((bf & BindingFlags.DeclaredOnly) != 0)
1532 type |= EntryType.Declared;
1538 /// The `MemberTypes' enumeration type is a [Flags] type which means that it may
1539 /// denote multiple member types. Returns true if the given flags value denotes a
1540 /// single member types.
1542 public static bool IsSingleMemberType (MemberTypes mt)
1545 case MemberTypes.Constructor:
1546 case MemberTypes.Event:
1547 case MemberTypes.Field:
1548 case MemberTypes.Method:
1549 case MemberTypes.Property:
1550 case MemberTypes.NestedType:
1559 /// We encode the MemberTypes and BindingFlags of each members in a "magic"
1560 /// number to speed up the searching process.
1563 protected enum EntryType {
1568 MaskStatic = Instance|Static,
1572 MaskProtection = Public|NonPublic,
1576 Constructor = 0x020,
1583 MaskType = Constructor|Event|Field|Method|Property|NestedType
1586 protected class CacheEntry {
1587 public readonly IMemberContainer Container;
1588 public readonly EntryType EntryType;
1589 public readonly MemberInfo Member;
1591 public CacheEntry (IMemberContainer container, MemberInfo member,
1592 MemberTypes mt, BindingFlags bf)
1594 this.Container = container;
1595 this.Member = member;
1596 this.EntryType = GetEntryType (mt, bf);
1599 public override string ToString ()
1601 return String.Format ("CacheEntry ({0}:{1}:{2})", Container.Name,
1607 /// This is called each time we're walking up one level in the class hierarchy
1608 /// and checks whether we can abort the search since we've already found what
1609 /// we were looking for.
1611 protected bool DoneSearching (ArrayList list)
1614 // We've found exactly one member in the current class and it's not
1615 // a method or constructor.
1617 if (list.Count == 1 && !(list [0] is MethodBase))
1621 // Multiple properties: we query those just to find out the indexer
1624 if ((list.Count > 0) && (list [0] is PropertyInfo))
1631 /// Looks up members with name `name'. If you provide an optional
1632 /// filter function, it'll only be called with members matching the
1633 /// requested member name.
1635 /// This method will try to use the cache to do the lookup if possible.
1637 /// Unlike other FindMembers implementations, this method will always
1638 /// check all inherited members - even when called on an interface type.
1640 /// If you know that you're only looking for methods, you should use
1641 /// MemberTypes.Method alone since this speeds up the lookup a bit.
1642 /// When doing a method-only search, it'll try to use a special method
1643 /// cache (unless it's a dynamic type or an interface) and the returned
1644 /// MemberInfo's will have the correct ReflectedType for inherited methods.
1645 /// The lookup process will automatically restart itself in method-only
1646 /// search mode if it discovers that it's about to return methods.
1648 ArrayList global = new ArrayList ();
1649 bool using_global = false;
1651 static MemberInfo [] emptyMemberInfo = new MemberInfo [0];
1653 public MemberInfo [] FindMembers (MemberTypes mt, BindingFlags bf, string name,
1654 MemberFilter filter, object criteria)
1657 throw new Exception ();
1659 bool declared_only = (bf & BindingFlags.DeclaredOnly) != 0;
1660 bool method_search = mt == MemberTypes.Method;
1661 // If we have a method cache and we aren't already doing a method-only search,
1662 // then we restart a method search if the first match is a method.
1663 bool do_method_search = !method_search && (method_hash != null);
1665 ArrayList applicable;
1667 // If this is a method-only search, we try to use the method cache if
1668 // possible; a lookup in the method cache will return a MemberInfo with
1669 // the correct ReflectedType for inherited methods.
1671 if (method_search && (method_hash != null))
1672 applicable = (ArrayList) method_hash [name];
1674 applicable = (ArrayList) member_hash [name];
1676 if (applicable == null)
1677 return emptyMemberInfo;
1680 // 32 slots gives 53 rss/54 size
1681 // 2/4 slots gives 55 rss
1683 // Strange: from 25,000 calls, only 1,800
1684 // are above 2. Why does this impact it?
1687 using_global = true;
1689 Timer.StartTimer (TimerType.CachedLookup);
1691 EntryType type = GetEntryType (mt, bf);
1693 IMemberContainer current = Container;
1695 bool do_interface_search = current.IsInterface;
1697 // `applicable' is a list of all members with the given member name `name'
1698 // in the current class and all its base classes. The list is sorted in
1699 // reverse order due to the way how the cache is initialy created (to speed
1700 // things up, we're doing a deep-copy of our base).
1702 for (int i = applicable.Count-1; i >= 0; i--) {
1703 CacheEntry entry = (CacheEntry) applicable [i];
1705 // This happens each time we're walking one level up in the class
1706 // hierarchy. If we're doing a DeclaredOnly search, we must abort
1707 // the first time this happens (this may already happen in the first
1708 // iteration of this loop if there are no members with the name we're
1709 // looking for in the current class).
1710 if (entry.Container != current) {
1714 if (!do_interface_search && DoneSearching (global))
1717 current = entry.Container;
1720 // Is the member of the correct type ?
1721 if ((entry.EntryType & type & EntryType.MaskType) == 0)
1724 // Is the member static/non-static ?
1725 if ((entry.EntryType & type & EntryType.MaskStatic) == 0)
1728 // Apply the filter to it.
1729 if (filter (entry.Member, criteria)) {
1730 if ((entry.EntryType & EntryType.MaskType) != EntryType.Method) {
1731 do_method_search = false;
1734 // Because interfaces support multiple inheritance we have to be sure that
1735 // base member is from same interface, so only top level member will be returned
1736 if (do_interface_search && global.Count > 0) {
1737 bool member_already_exists = false;
1739 foreach (MemberInfo mi in global) {
1740 if (mi is MethodBase)
1743 if (IsInterfaceBaseInterface (TypeManager.GetInterfaces (mi.DeclaringType), entry.Member.DeclaringType)) {
1744 member_already_exists = true;
1748 if (member_already_exists)
1752 global.Add (entry.Member);
1756 Timer.StopTimer (TimerType.CachedLookup);
1758 // If we have a method cache and we aren't already doing a method-only
1759 // search, we restart in method-only search mode if the first match is
1760 // a method. This ensures that we return a MemberInfo with the correct
1761 // ReflectedType for inherited methods.
1762 if (do_method_search && (global.Count > 0)){
1763 using_global = false;
1765 return FindMembers (MemberTypes.Method, bf, name, filter, criteria);
1768 using_global = false;
1769 MemberInfo [] copy = new MemberInfo [global.Count];
1770 global.CopyTo (copy);
1775 /// Returns true if iterface exists in any base interfaces (ifaces)
1777 static bool IsInterfaceBaseInterface (Type[] ifaces, Type ifaceToFind)
1779 foreach (Type iface in ifaces) {
1780 if (iface == ifaceToFind)
1783 Type[] base_ifaces = TypeManager.GetInterfaces (iface);
1784 if (base_ifaces.Length > 0 && IsInterfaceBaseInterface (base_ifaces, ifaceToFind))
1790 // find the nested type @name in @this.
1791 public Type FindNestedType (string name)
1793 ArrayList applicable = (ArrayList) member_hash [name];
1794 if (applicable == null)
1797 for (int i = applicable.Count-1; i >= 0; i--) {
1798 CacheEntry entry = (CacheEntry) applicable [i];
1799 if ((entry.EntryType & EntryType.NestedType & EntryType.MaskType) != 0)
1800 return (Type) entry.Member;
1807 // This finds the method or property for us to override. invocationType is the type where
1808 // the override is going to be declared, name is the name of the method/property, and
1809 // paramTypes is the parameters, if any to the method or property
1811 // Because the MemberCache holds members from this class and all the base classes,
1812 // we can avoid tons of reflection stuff.
1814 public MemberInfo FindMemberToOverride (Type invocationType, string name, Type [] paramTypes, bool is_property)
1816 ArrayList applicable;
1817 if (method_hash != null && !is_property)
1818 applicable = (ArrayList) method_hash [name];
1820 applicable = (ArrayList) member_hash [name];
1822 if (applicable == null)
1825 // Walk the chain of methods, starting from the top.
1827 for (int i = applicable.Count - 1; i >= 0; i--) {
1828 CacheEntry entry = (CacheEntry) applicable [i];
1830 if ((entry.EntryType & (is_property ? (EntryType.Property | EntryType.Field) : EntryType.Method)) == 0)
1833 PropertyInfo pi = null;
1834 MethodInfo mi = null;
1835 FieldInfo fi = null;
1836 Type [] cmpAttrs = null;
1839 if ((entry.EntryType & EntryType.Field) != 0) {
1840 fi = (FieldInfo)entry.Member;
1842 // TODO: For this case we ignore member type
1843 //fb = TypeManager.GetField (fi);
1844 //cmpAttrs = new Type[] { fb.MemberType };
1846 pi = (PropertyInfo) entry.Member;
1847 cmpAttrs = TypeManager.GetArgumentTypes (pi);
1850 mi = (MethodInfo) entry.Member;
1851 cmpAttrs = TypeManager.GetParameterData (mi).Types;
1855 // TODO: Almost duplicate !
1857 switch (fi.Attributes & FieldAttributes.FieldAccessMask) {
1858 case FieldAttributes.Private:
1860 // A private method is Ok if we are a nested subtype.
1861 // The spec actually is not very clear about this, see bug 52458.
1863 if (invocationType != entry.Container.Type &
1864 TypeManager.IsNestedChildOf (invocationType, entry.Container.Type))
1868 case FieldAttributes.FamANDAssem:
1869 case FieldAttributes.Assembly:
1871 // Check for assembly methods
1873 if (mi.DeclaringType.Assembly != CodeGen.Assembly.Builder)
1877 return entry.Member;
1881 // Check the arguments
1883 if (cmpAttrs.Length != paramTypes.Length)
1886 for (int j = cmpAttrs.Length - 1; j >= 0; j --)
1887 if (paramTypes [j] != cmpAttrs [j])
1891 // get one of the methods because this has the visibility info.
1894 mi = pi.GetGetMethod (true);
1896 mi = pi.GetSetMethod (true);
1902 switch (mi.Attributes & MethodAttributes.MemberAccessMask) {
1903 case MethodAttributes.Private:
1905 // A private method is Ok if we are a nested subtype.
1906 // The spec actually is not very clear about this, see bug 52458.
1908 if (invocationType == entry.Container.Type ||
1909 TypeManager.IsNestedChildOf (invocationType, entry.Container.Type))
1910 return entry.Member;
1913 case MethodAttributes.FamANDAssem:
1914 case MethodAttributes.Assembly:
1916 // Check for assembly methods
1918 if (mi.DeclaringType.Assembly == CodeGen.Assembly.Builder)
1919 return entry.Member;
1924 // A protected method is ok, because we are overriding.
1925 // public is always ok.
1927 return entry.Member;
1937 /// The method is looking for conflict with inherited symbols (errors CS0108, CS0109).
1938 /// We handle two cases. The first is for types without parameters (events, field, properties).
1939 /// The second are methods, indexers and this is why ignore_complex_types is here.
1940 /// The latest param is temporary hack. See DoDefineMembers method for more info.
1942 public MemberInfo FindMemberWithSameName (string name, bool ignore_complex_types, MemberInfo ignore_member)
1944 ArrayList applicable = null;
1946 if (method_hash != null)
1947 applicable = (ArrayList) method_hash [name];
1949 if (applicable != null) {
1950 for (int i = applicable.Count - 1; i >= 0; i--) {
1951 CacheEntry entry = (CacheEntry) applicable [i];
1952 if ((entry.EntryType & EntryType.Public) != 0)
1953 return entry.Member;
1957 if (member_hash == null)
1959 applicable = (ArrayList) member_hash [name];
1961 if (applicable != null) {
1962 for (int i = applicable.Count - 1; i >= 0; i--) {
1963 CacheEntry entry = (CacheEntry) applicable [i];
1964 if ((entry.EntryType & EntryType.Public) != 0 & entry.Member != ignore_member) {
1965 if (ignore_complex_types) {
1966 if ((entry.EntryType & EntryType.Method) != 0)
1969 // Does exist easier way how to detect indexer ?
1970 if ((entry.EntryType & EntryType.Property) != 0) {
1971 Type[] arg_types = TypeManager.GetArgumentTypes ((PropertyInfo)entry.Member);
1972 if (arg_types.Length > 0)
1976 return entry.Member;
1983 Hashtable locase_table;
1986 /// Builds low-case table for CLS Compliance test
1988 public Hashtable GetPublicMembers ()
1990 if (locase_table != null)
1991 return locase_table;
1993 locase_table = new Hashtable ();
1994 foreach (DictionaryEntry entry in member_hash) {
1995 ArrayList members = (ArrayList)entry.Value;
1996 for (int ii = 0; ii < members.Count; ++ii) {
1997 CacheEntry member_entry = (CacheEntry) members [ii];
1999 if ((member_entry.EntryType & EntryType.Public) == 0)
2002 // TODO: Does anyone know easier way how to detect that member is internal ?
2003 switch (member_entry.EntryType & EntryType.MaskType) {
2004 case EntryType.Constructor:
2007 case EntryType.Field:
2008 if ((((FieldInfo)member_entry.Member).Attributes & (FieldAttributes.Assembly | FieldAttributes.Public)) == FieldAttributes.Assembly)
2012 case EntryType.Method:
2013 if ((((MethodInfo)member_entry.Member).Attributes & (MethodAttributes.Assembly | MethodAttributes.Public)) == MethodAttributes.Assembly)
2017 case EntryType.Property:
2018 PropertyInfo pi = (PropertyInfo)member_entry.Member;
2019 if (pi.GetSetMethod () == null && pi.GetGetMethod () == null)
2023 case EntryType.Event:
2024 EventInfo ei = (EventInfo)member_entry.Member;
2025 MethodInfo mi = ei.GetAddMethod ();
2026 if ((mi.Attributes & (MethodAttributes.Assembly | MethodAttributes.Public)) == MethodAttributes.Assembly)
2030 string lcase = ((string)entry.Key).ToLower (System.Globalization.CultureInfo.InvariantCulture);
2031 locase_table [lcase] = member_entry.Member;
2035 return locase_table;
2038 public Hashtable Members {
2045 /// Cls compliance check whether methods or constructors parameters differing only in ref or out, or in array rank
2048 // TODO: refactor as method is always 'this'
2049 public static void VerifyClsParameterConflict (ArrayList al, MethodCore method, MemberInfo this_builder)
2051 EntryType tested_type = (method is Constructor ? EntryType.Constructor : EntryType.Method) | EntryType.Public;
2053 for (int i = 0; i < al.Count; ++i) {
2054 MemberCache.CacheEntry entry = (MemberCache.CacheEntry) al [i];
2057 if (entry.Member == this_builder)
2060 if ((entry.EntryType & tested_type) != tested_type)
2063 MethodBase method_to_compare = (MethodBase)entry.Member;
2064 AttributeTester.Result result = AttributeTester.AreOverloadedMethodParamsClsCompliant (
2065 method.ParameterTypes, TypeManager.GetParameterData (method_to_compare).Types);
2067 if (result == AttributeTester.Result.Ok)
2070 IMethodData md = TypeManager.GetMethod (method_to_compare);
2072 // TODO: now we are ignoring CLSCompliance(false) on method from other assembly which is buggy.
2073 // However it is exactly what csc does.
2074 if (md != null && !md.IsClsComplianceRequired ())
2077 Report.SymbolRelatedToPreviousError (entry.Member);
2079 case AttributeTester.Result.RefOutArrayError:
2080 Report.Error (3006, method.Location, "Overloaded method `{0}' differing only in ref or out, or in array rank, is not CLS-compliant", method.GetSignatureForError ());
2082 case AttributeTester.Result.ArrayArrayError:
2083 Report.Error (3007, method.Location, "Overloaded method `{0}' differing only by unnamed array types is not CLS-compliant", method.GetSignatureForError ());
2087 throw new NotImplementedException (result.ToString ());