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 MemberName Left;
33 public static readonly MemberName Null = new MemberName ("");
35 public MemberName (string name)
40 public MemberName (MemberName left, string name)
46 public MemberName (MemberName left, MemberName right)
49 Left = (right.Left == null) ? left : new MemberName (left, right.Left);
52 static readonly char [] dot_array = { '.' };
54 public static MemberName FromDotted (string name)
56 string [] elements = name.Split (dot_array);
57 int count = elements.Length;
59 MemberName n = new MemberName (elements [i++]);
61 n = new MemberName (n, elements [i++]);
65 public string GetName ()
67 return GetName (false);
70 public string GetName (bool is_generic)
72 string name = is_generic ? Basename : Name;
74 return Left.GetName (is_generic) + "." + name;
80 /// This returns exclusively the name as seen on the source code
81 /// it is not the fully qualifed type after resolution
83 public string GetPartialName ()
86 return Left.GetPartialName () + "." + Name;
91 public string GetTypeName ()
94 return Left.GetTypeName () + "." + Name;
99 public Expression GetTypeExpression (Location loc)
102 Expression lexpr = Left.GetTypeExpression (loc);
104 return new MemberAccess (lexpr, Name, loc);
106 return new SimpleName (Name, loc);
110 public MemberName Clone ()
113 return new MemberName (Left.Clone (), Name);
115 return new MemberName (Name);
118 public string Basename {
124 public override string ToString ()
127 return Left + "." + Name;
132 public override bool Equals (object other)
134 return Equals (other as MemberName);
137 public bool Equals (MemberName other)
141 if (other == null || Name != other.Name)
144 if (TypeArguments == null)
145 return other.TypeArguments == null;
147 if (other.TypeArguments == null || TypeArguments.Count != other.TypeArguments.Count)
151 return other.Left == null;
153 return Left.Equals (other.Left);
156 public override int GetHashCode ()
158 int hash = Name.GetHashCode ();
159 for (MemberName n = Left; n != null; n = n.Left)
160 hash ^= n.Name.GetHashCode ();
163 if (TypeArguments != null)
164 hash ^= TypeArguments.Count << 5;
167 return hash & 0x7FFFFFFF;
172 /// Base representation for members. This is used to keep track
173 /// of Name, Location and Modifier flags, and handling Attributes.
175 public abstract class MemberCore : Attributable {
180 protected string cached_name;
183 if (cached_name == null)
184 cached_name = MemberName.GetName (false);
189 // Is not readonly because of IndexerName attribute
190 private MemberName member_name;
191 public MemberName MemberName {
192 get { return member_name; }
196 /// Modifier flags that the user specified in the source code
200 public /*readonly*/ TypeContainer Parent;
203 /// Location where this declaration happens
205 public readonly Location Location;
208 /// XML documentation comment
210 public string DocComment;
213 /// Represents header string for documentation comment
214 /// for each member types.
216 public abstract string DocCommentHeader { get; }
220 Obsolete_Undetected = 1, // Obsolete attribute has not been detected yet
221 Obsolete = 1 << 1, // Type has obsolete attribute
222 ClsCompliance_Undetected = 1 << 2, // CLS Compliance has not been detected yet
223 ClsCompliant = 1 << 3, // Type is CLS Compliant
224 CloseTypeCreated = 1 << 4, // Tracks whether we have Closed the type
225 HasCompliantAttribute_Undetected = 1 << 5, // Presence of CLSCompliantAttribute has not been detected
226 HasClsCompliantAttribute = 1 << 6, // Type has CLSCompliantAttribute
227 ClsCompliantAttributeTrue = 1 << 7, // Type has CLSCompliant (true)
228 Excluded_Undetected = 1 << 8, // Conditional attribute has not been detected yet
229 Excluded = 1 << 9, // Method is conditional
230 TestMethodDuplication = 1 << 10, // Test for duplication must be performed
235 /// MemberCore flags at first detected then cached
237 internal Flags caching_flags;
239 public MemberCore (TypeContainer parent, MemberName name, Attributes attrs,
243 if (parent is PartialContainer && !(this is PartialContainer))
244 throw new InternalErrorException ("A PartialContainer cannot be the direct parent of a member");
249 caching_flags = Flags.Obsolete_Undetected | Flags.ClsCompliance_Undetected | Flags.HasCompliantAttribute_Undetected | Flags.Excluded_Undetected;
252 protected virtual void SetMemberName (MemberName new_name)
254 member_name = new_name;
259 /// Tests presence of ObsoleteAttribute and report proper error
261 protected void CheckUsageOfObsoleteAttribute (Type type)
266 ObsoleteAttribute obsolete_attr = AttributeTester.GetObsoleteAttribute (type);
267 if (obsolete_attr == null)
270 AttributeTester.Report_ObsoleteMessage (obsolete_attr, type.FullName, Location);
273 public abstract bool Define ();
276 // Returns full member name for error message
278 public virtual string GetSignatureForError ()
284 /// Use this method when MethodBuilder is null
286 public virtual string GetSignatureForError (TypeContainer tc)
292 /// Base Emit method. This is also entry point for CLS-Compliant verification.
294 public virtual void Emit ()
296 // Hack with Parent == null is for EnumMember
297 if (Parent == null || (GetObsoleteAttribute (Parent) == null && Parent.GetObsoleteAttribute (Parent) == null))
298 VerifyObsoleteAttribute ();
300 if (!RootContext.VerifyClsCompliance)
303 VerifyClsCompliance (Parent);
306 public bool InUnsafe {
308 return ((ModFlags & Modifiers.UNSAFE) != 0) || Parent.UnsafeContext;
312 public virtual bool IsUsed {
314 return (caching_flags & Flags.IsUsed) != 0;
318 public void SetMemberIsUsed ()
320 caching_flags |= Flags.IsUsed;
324 // Whehter is it ok to use an unsafe pointer in this type container
326 public bool UnsafeOK (DeclSpace parent)
329 // First check if this MemberCore modifier flags has unsafe set
331 if ((ModFlags & Modifiers.UNSAFE) != 0)
334 if (parent.UnsafeContext)
337 Expression.UnsafeError (Location);
342 /// Returns instance of ObsoleteAttribute for this MemberCore
344 public ObsoleteAttribute GetObsoleteAttribute (DeclSpace ds)
346 // ((flags & (Flags.Obsolete_Undetected | Flags.Obsolete)) == 0) is slower, but why ?
347 if ((caching_flags & Flags.Obsolete_Undetected) == 0 && (caching_flags & Flags.Obsolete) == 0) {
351 caching_flags &= ~Flags.Obsolete_Undetected;
353 if (OptAttributes == null)
356 Attribute obsolete_attr = OptAttributes.Search (
357 TypeManager.obsolete_attribute_type, ds.EmitContext);
358 if (obsolete_attr == null)
361 ObsoleteAttribute obsolete = obsolete_attr.GetObsoleteAttribute (ds.EmitContext);
362 if (obsolete == null)
365 caching_flags |= Flags.Obsolete;
370 /// Analyze whether CLS-Compliant verification must be execute for this MemberCore.
372 public override bool IsClsCompliaceRequired (DeclSpace container)
374 if ((caching_flags & Flags.ClsCompliance_Undetected) == 0)
375 return (caching_flags & Flags.ClsCompliant) != 0;
377 if (GetClsCompliantAttributeValue (container) && IsExposedFromAssembly (container)) {
378 caching_flags &= ~Flags.ClsCompliance_Undetected;
379 caching_flags |= Flags.ClsCompliant;
383 caching_flags &= ~Flags.ClsCompliance_Undetected;
388 /// Returns true when MemberCore is exposed from assembly.
390 public bool IsExposedFromAssembly (DeclSpace ds)
392 if ((ModFlags & (Modifiers.PUBLIC | Modifiers.PROTECTED)) == 0)
395 DeclSpace parentContainer = ds;
396 while (parentContainer != null && parentContainer.ModFlags != 0) {
397 if ((parentContainer.ModFlags & (Modifiers.PUBLIC | Modifiers.PROTECTED)) == 0)
399 parentContainer = parentContainer.Parent;
405 /// Resolve CLSCompliantAttribute value or gets cached value.
407 bool GetClsCompliantAttributeValue (DeclSpace ds)
409 if (OptAttributes != null) {
410 Attribute cls_attribute = OptAttributes.Search (
411 TypeManager.cls_compliant_attribute_type, ds.EmitContext);
412 if (cls_attribute != null) {
413 caching_flags |= Flags.HasClsCompliantAttribute;
414 return cls_attribute.GetClsCompliantAttributeValue (ds.EmitContext);
417 return ds.GetClsCompliantAttributeValue ();
421 /// Returns true if MemberCore is explicitly marked with CLSCompliantAttribute
423 protected bool HasClsCompliantAttribute {
425 return (caching_flags & Flags.HasClsCompliantAttribute) != 0;
430 /// It helps to handle error 102 & 111 detection
432 public virtual bool MarkForDuplicationCheck ()
438 /// The main virtual method for CLS-Compliant verifications.
439 /// The method returns true if member is CLS-Compliant and false if member is not
440 /// CLS-Compliant which means that CLS-Compliant tests are not necessary. A descendants override it
441 /// and add their extra verifications.
443 protected virtual bool VerifyClsCompliance (DeclSpace ds)
445 if (!IsClsCompliaceRequired (ds)) {
446 if (HasClsCompliantAttribute && RootContext.WarningLevel >= 2) {
447 if (!IsExposedFromAssembly (ds))
448 Report.Warning (3019, Location, "CLS compliance checking will not be performed on '{0}' because it is private or internal", GetSignatureForError ());
449 if (!CodeGen.Assembly.IsClsCompliant)
450 Report.Warning (3021, Location, "'{0}' does not need a CLSCompliant attribute because the assembly does not have a CLSCompliant attribute", GetSignatureForError ());
455 if (!CodeGen.Assembly.IsClsCompliant) {
456 if (HasClsCompliantAttribute) {
457 Report.Error (3014, Location, "'{0}' cannot be marked as CLS-compliant because the assembly does not have a CLSCompliant attribute", GetSignatureForError ());
462 int index = Name.LastIndexOf ('.');
463 if (Name [index > 0 ? index + 1 : 0] == '_') {
464 Report.Error (3008, Location, "Identifier '{0}' is not CLS-compliant", GetSignatureForError () );
469 protected abstract void VerifyObsoleteAttribute ();
472 // Raised (and passed an XmlElement that contains the comment)
473 // when GenerateDocComment is writing documentation expectedly.
475 internal virtual void OnGenerateDocComment (DeclSpace ds, XmlElement intermediateNode)
480 // Returns a string that represents the signature for this
481 // member which should be used in XML documentation.
483 public virtual string GetDocCommentName (DeclSpace ds)
485 if (ds == null || this is DeclSpace)
486 return DocCommentHeader + Name;
488 return String.Concat (DocCommentHeader, ds.Name, ".", Name);
492 // Generates xml doc comments (if any), and if required,
493 // handle warning report.
495 internal virtual void GenerateDocComment (DeclSpace ds)
497 DocUtil.GenerateDocComment (this, ds);
502 /// Base class for structs, classes, enumerations and interfaces.
505 /// They all create new declaration spaces. This
506 /// provides the common foundation for managing those name
509 public abstract class DeclSpace : MemberCore, IAlias {
511 /// This points to the actual definition that is being
512 /// created with System.Reflection.Emit
514 public TypeBuilder TypeBuilder;
517 // This is the namespace in which this typecontainer
518 // was declared. We use this to resolve names.
520 public NamespaceEntry NamespaceEntry;
522 private Hashtable Cache = new Hashtable ();
524 public string Basename;
526 protected Hashtable defined_names;
528 // The emit context for toplevel objects.
529 protected EmitContext ec;
531 public EmitContext EmitContext {
535 static string[] attribute_targets = new string [] { "type" };
537 public DeclSpace (NamespaceEntry ns, TypeContainer parent, MemberName name,
538 Attributes attrs, Location l)
539 : base (parent, name, attrs, l)
542 Basename = name.Name;
543 defined_names = new Hashtable ();
547 /// Adds the member to defined_names table. It tests for duplications and enclosing name conflicts
549 protected bool AddToContainer (MemberCore symbol, string name)
551 if (name == Basename && !(this is Interface) && !(this is Enum)) {
552 Report.SymbolRelatedToPreviousError (this);
553 Report.Error (542, symbol.Location, "'{0}': member names cannot be the same as their enclosing type", symbol.GetSignatureForError ());
557 MemberCore mc = (MemberCore) defined_names [name];
560 defined_names.Add (name, symbol);
564 if (symbol.MarkForDuplicationCheck () && mc.MarkForDuplicationCheck ())
567 Report.SymbolRelatedToPreviousError (mc);
568 Report.Error (102, symbol.Location, "The type '{0}' already contains a definition for '{1}'", GetSignatureForError (), name);
572 public void RecordDecl ()
574 if ((NamespaceEntry != null) && (Parent == RootContext.Tree.Types))
575 NamespaceEntry.DefineName (MemberName.Basename, this);
579 /// Returns the MemberCore associated with a given name in the declaration
580 /// space. It doesn't return method based symbols !!
583 public MemberCore GetDefinition (string name)
585 return (MemberCore)defined_names [name];
588 bool in_transit = false;
591 /// This function is used to catch recursive definitions
594 public bool InTransit {
605 // root_types contains all the types. All TopLevel types
606 // hence have a parent that points to `root_types', that is
607 // why there is a non-obvious test down here.
609 public bool IsTopLevel {
612 if (Parent.Parent == null)
619 public virtual void CloseType ()
621 if ((caching_flags & Flags.CloseTypeCreated) == 0){
623 TypeBuilder.CreateType ();
626 // The try/catch is needed because
627 // nested enumerations fail to load when they
630 // Even if this is the right order (enumerations
631 // declared after types).
633 // Note that this still creates the type and
634 // it is possible to save it
636 caching_flags |= Flags.CloseTypeCreated;
641 /// Should be overriten by the appropriate declaration space
643 public abstract TypeBuilder DefineType ();
646 /// Define all members, but don't apply any attributes or do anything which may
647 /// access not-yet-defined classes. This method also creates the MemberCache.
649 public abstract bool DefineMembers (TypeContainer parent);
652 // Whether this is an `unsafe context'
654 public bool UnsafeContext {
656 if ((ModFlags & Modifiers.UNSAFE) != 0)
659 return Parent.UnsafeContext;
664 EmitContext type_resolve_ec;
665 protected EmitContext TypeResolveEmitContext {
667 if (type_resolve_ec == null) {
668 // FIXME: I think this should really be one of:
670 // a. type_resolve_ec = Parent.EmitContext;
671 // b. type_resolve_ec = new EmitContext (Parent, Parent, loc, null, null, ModFlags, false);
673 // However, if Parent == RootContext.Tree.Types, its NamespaceEntry will be null.
675 type_resolve_ec = new EmitContext (Parent, this, Location.Null, null, null, ModFlags, false);
677 return type_resolve_ec;
682 // Resolves the expression `e' for a type, and will recursively define
683 // types. This should only be used for resolving base types.
685 public TypeExpr ResolveBaseTypeExpr (Expression e, bool silent, Location loc)
687 TypeResolveEmitContext.loc = loc;
688 TypeResolveEmitContext.ContainerType = TypeBuilder;
690 return e.ResolveAsTypeTerminal (TypeResolveEmitContext, silent);
693 public bool CheckAccessLevel (Type check_type)
695 if (check_type == TypeBuilder)
698 TypeAttributes check_attr = check_type.Attributes & TypeAttributes.VisibilityMask;
701 // Broken Microsoft runtime, return public for arrays, no matter what
702 // the accessibility is for their underlying class, and they return
703 // NonPublic visibility for pointers
705 if (check_type.IsArray || check_type.IsPointer)
706 return CheckAccessLevel (TypeManager.GetElementType (check_type));
708 if (TypeBuilder == null)
709 // FIXME: TypeBuilder will be null when invoked by Class.GetNormalBases().
710 // However, this is invoked again later -- so safe to return true.
711 // May also be null when resolving top-level attributes.
715 case TypeAttributes.Public:
718 case TypeAttributes.NotPublic:
720 // This test should probably use the declaringtype.
722 return check_type.Assembly == TypeBuilder.Assembly;
724 case TypeAttributes.NestedPublic:
727 case TypeAttributes.NestedPrivate:
728 return NestedAccessible (check_type);
730 case TypeAttributes.NestedFamily:
731 return FamilyAccessible (check_type);
733 case TypeAttributes.NestedFamANDAssem:
734 return (check_type.Assembly == TypeBuilder.Assembly) &&
735 FamilyAccessible (check_type);
737 case TypeAttributes.NestedFamORAssem:
738 return (check_type.Assembly == TypeBuilder.Assembly) ||
739 FamilyAccessible (check_type);
741 case TypeAttributes.NestedAssembly:
742 return check_type.Assembly == TypeBuilder.Assembly;
745 Console.WriteLine ("HERE: " + check_attr);
750 protected bool NestedAccessible (Type check_type)
752 Type declaring = check_type.DeclaringType;
753 return TypeBuilder == declaring ||
754 TypeManager.IsNestedChildOf (TypeBuilder, declaring);
757 protected bool FamilyAccessible (Type check_type)
759 Type declaring = check_type.DeclaringType;
760 if (TypeBuilder == declaring ||
761 TypeBuilder.IsSubclassOf (declaring))
764 return NestedAccessible (check_type);
767 // Access level of a type.
769 enum AccessLevel { // Each column represents `is this scope larger or equal to Blah scope'
770 // Public Assembly Protected
771 Protected = (0 << 0) | (0 << 1) | (X << 2),
772 Public = (X << 0) | (X << 1) | (X << 2),
773 Private = (0 << 0) | (0 << 1) | (0 << 2),
774 Internal = (0 << 0) | (X << 1) | (0 << 2),
775 ProtectedOrInternal = (0 << 0) | (X << 1) | (X << 2),
778 static AccessLevel GetAccessLevelFromModifiers (int flags)
780 if ((flags & Modifiers.INTERNAL) != 0) {
782 if ((flags & Modifiers.PROTECTED) != 0)
783 return AccessLevel.ProtectedOrInternal;
785 return AccessLevel.Internal;
787 } else if ((flags & Modifiers.PROTECTED) != 0)
788 return AccessLevel.Protected;
790 else if ((flags & Modifiers.PRIVATE) != 0)
791 return AccessLevel.Private;
794 return AccessLevel.Public;
797 // What is the effective access level of this?
799 AccessLevel EffectiveAccessLevel {
801 AccessLevel myAccess = GetAccessLevelFromModifiers (ModFlags);
802 if (!IsTopLevel && (Parent != null))
803 return myAccess & Parent.EffectiveAccessLevel;
809 // Return the access level for type `t'
810 static AccessLevel TypeEffectiveAccessLevel (Type t)
813 return AccessLevel.Public;
814 if (t.IsNestedPrivate)
815 return AccessLevel.Private;
817 return AccessLevel.Internal;
819 // By now, it must be nested
820 AccessLevel parentLevel = TypeEffectiveAccessLevel (t.DeclaringType);
822 if (t.IsNestedPublic)
824 if (t.IsNestedAssembly)
825 return parentLevel & AccessLevel.Internal;
826 if (t.IsNestedFamily)
827 return parentLevel & AccessLevel.Protected;
828 if (t.IsNestedFamORAssem)
829 return parentLevel & AccessLevel.ProtectedOrInternal;
830 if (t.IsNestedFamANDAssem)
831 throw new NotImplementedException ("NestedFamANDAssem not implemented, cant make this kind of type from c# anyways");
833 // nested private is taken care of
835 throw new Exception ("I give up, what are you?");
839 // This answers `is the type P, as accessible as a member M which has the
840 // accessability @flags which is declared as a nested member of the type T, this declspace'
842 public bool AsAccessible (Type p, int flags)
845 // 1) if M is private, its accessability is the same as this declspace.
846 // we already know that P is accessible to T before this method, so we
850 if ((flags & Modifiers.PRIVATE) != 0)
853 while (p.IsArray || p.IsPointer || p.IsByRef)
854 p = TypeManager.GetElementType (p);
856 AccessLevel pAccess = TypeEffectiveAccessLevel (p);
857 AccessLevel mAccess = this.EffectiveAccessLevel &
858 GetAccessLevelFromModifiers (flags);
860 // for every place from which we can access M, we must
861 // be able to access P as well. So, we want
862 // For every bit in M and P, M_i -> P_1 == true
863 // or, ~ (M -> P) == 0 <-> ~ ( ~M | P) == 0
865 return ~ (~ mAccess | pAccess) == 0;
868 public static void Error_AmbiguousTypeReference (Location loc, string name, string t1, string t2)
870 Report.Error (104, loc,
871 "`{0}' is an ambiguous reference ({1} or {2})",
876 // Return the nested type with name @name. Ensures that the nested type
877 // is defined if necessary. Do _not_ use this when you have a MemberCache handy.
879 public virtual Type FindNestedType (string name)
884 private Type LookupNestedTypeInHierarchy (string name)
886 // if the member cache has been created, lets use it.
887 // the member cache is MUCH faster.
888 if (MemberCache != null)
889 return MemberCache.FindNestedType (name);
891 // no member cache. Do it the hard way -- reflection
893 for (Type current_type = TypeBuilder;
894 current_type != null && current_type != TypeManager.object_type;
895 current_type = current_type.BaseType) {
896 if (current_type is TypeBuilder) {
897 DeclSpace decl = this;
898 if (current_type != TypeBuilder)
899 decl = TypeManager.LookupDeclSpace (current_type);
900 t = decl.FindNestedType (name);
902 t = TypeManager.GetNestedType (current_type, name);
905 if (t != null && CheckAccessLevel (t))
913 // Public function used to locate types, this can only
914 // be used after the ResolveTree function has been invoked.
916 // Set 'ignore_cs0104' to true if you want to ignore cs0104 errors.
918 // Returns: Type or null if they type can not be found.
920 public FullNamedExpression LookupType (string name, Location loc, bool ignore_cs0104)
922 if (this is PartialContainer)
923 throw new InternalErrorException ("Should not get here");
925 if (Cache.Contains (name))
926 return (FullNamedExpression) Cache [name];
928 FullNamedExpression e;
929 Type t = LookupNestedTypeInHierarchy (name);
931 e = new TypeExpression (t, Location.Null);
932 else if (Parent != null && Parent != RootContext.Tree.Types)
933 e = Parent.LookupType (name, loc, ignore_cs0104);
935 e = NamespaceEntry.LookupNamespaceOrType (this, name, loc, ignore_cs0104);
942 /// This function is broken and not what you're looking for. It should only
943 /// be used while the type is still being created since it doesn't use the cache
944 /// and relies on the filter doing the member name check.
946 public abstract MemberList FindMembers (MemberTypes mt, BindingFlags bf,
947 MemberFilter filter, object criteria);
950 /// If we have a MemberCache, return it. This property may return null if the
951 /// class doesn't have a member cache or while it's still being created.
953 public abstract MemberCache MemberCache {
957 public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
959 if (a.Type == TypeManager.required_attr_type) {
960 Report.Error (1608, a.Location, "The RequiredAttribute attribute is not permitted on C# types");
963 TypeBuilder.SetCustomAttribute (cb);
967 /// Goes through class hierarchy and get value of first CLSCompliantAttribute that found.
968 /// If no is attribute exists then return assembly CLSCompliantAttribute.
970 public bool GetClsCompliantAttributeValue ()
972 if ((caching_flags & Flags.HasCompliantAttribute_Undetected) == 0)
973 return (caching_flags & Flags.ClsCompliantAttributeTrue) != 0;
975 caching_flags &= ~Flags.HasCompliantAttribute_Undetected;
977 if (OptAttributes != null) {
978 Attribute cls_attribute = OptAttributes.Search (TypeManager.cls_compliant_attribute_type, ec);
979 if (cls_attribute != null) {
980 caching_flags |= Flags.HasClsCompliantAttribute;
981 if (cls_attribute.GetClsCompliantAttributeValue (ec)) {
982 caching_flags |= Flags.ClsCompliantAttributeTrue;
989 if (Parent == null) {
990 if (CodeGen.Assembly.IsClsCompliant) {
991 caching_flags |= Flags.ClsCompliantAttributeTrue;
997 if (Parent.GetClsCompliantAttributeValue ()) {
998 caching_flags |= Flags.ClsCompliantAttributeTrue;
1004 public override string[] ValidAttributeTargets {
1006 return attribute_targets;
1010 bool IAlias.IsType {
1011 get { return true; }
1014 string IAlias.Name {
1015 get { return Name; }
1018 TypeExpr IAlias.ResolveAsType (EmitContext ec)
1020 if (TypeBuilder == null)
1021 throw new InvalidOperationException ();
1023 return new TypeExpression (TypeBuilder, Location);
1028 /// This is a readonly list of MemberInfo's.
1030 public class MemberList : IList {
1031 public readonly IList List;
1035 /// Create a new MemberList from the given IList.
1037 public MemberList (IList list)
1042 this.List = new ArrayList ();
1047 /// Concatenate the ILists `first' and `second' to a new MemberList.
1049 public MemberList (IList first, IList second)
1051 ArrayList list = new ArrayList ();
1052 list.AddRange (first);
1053 list.AddRange (second);
1058 public static readonly MemberList Empty = new MemberList (new ArrayList ());
1061 /// Cast the MemberList into a MemberInfo[] array.
1064 /// This is an expensive operation, only use it if it's really necessary.
1066 public static explicit operator MemberInfo [] (MemberList list)
1068 Timer.StartTimer (TimerType.MiscTimer);
1069 MemberInfo [] result = new MemberInfo [list.Count];
1070 list.CopyTo (result, 0);
1071 Timer.StopTimer (TimerType.MiscTimer);
1083 public bool IsSynchronized {
1085 return List.IsSynchronized;
1089 public object SyncRoot {
1091 return List.SyncRoot;
1095 public void CopyTo (Array array, int index)
1097 List.CopyTo (array, index);
1102 public IEnumerator GetEnumerator ()
1104 return List.GetEnumerator ();
1109 public bool IsFixedSize {
1115 public bool IsReadOnly {
1121 object IList.this [int index] {
1123 return List [index];
1127 throw new NotSupportedException ();
1131 // FIXME: try to find out whether we can avoid the cast in this indexer.
1132 public MemberInfo this [int index] {
1134 return (MemberInfo) List [index];
1138 public int Add (object value)
1140 throw new NotSupportedException ();
1143 public void Clear ()
1145 throw new NotSupportedException ();
1148 public bool Contains (object value)
1150 return List.Contains (value);
1153 public int IndexOf (object value)
1155 return List.IndexOf (value);
1158 public void Insert (int index, object value)
1160 throw new NotSupportedException ();
1163 public void Remove (object value)
1165 throw new NotSupportedException ();
1168 public void RemoveAt (int index)
1170 throw new NotSupportedException ();
1175 /// This interface is used to get all members of a class when creating the
1176 /// member cache. It must be implemented by all DeclSpace derivatives which
1177 /// want to support the member cache and by TypeHandle to get caching of
1178 /// non-dynamic types.
1180 public interface IMemberContainer {
1182 /// The name of the IMemberContainer. This is only used for
1183 /// debugging purposes.
1190 /// The type of this IMemberContainer.
1197 /// Returns the IMemberContainer of the base class or null if this
1198 /// is an interface or TypeManger.object_type.
1199 /// This is used when creating the member cache for a class to get all
1200 /// members from the base class.
1202 MemberCache BaseCache {
1207 /// Whether this is an interface.
1214 /// Returns all members of this class with the corresponding MemberTypes
1215 /// and BindingFlags.
1218 /// When implementing this method, make sure not to return any inherited
1219 /// members and check the MemberTypes and BindingFlags properly.
1220 /// Unfortunately, System.Reflection is lame and doesn't provide a way to
1221 /// get the BindingFlags (static/non-static,public/non-public) in the
1222 /// MemberInfo class, but the cache needs this information. That's why
1223 /// this method is called multiple times with different BindingFlags.
1225 MemberList GetMembers (MemberTypes mt, BindingFlags bf);
1228 /// Return the container's member cache.
1230 MemberCache MemberCache {
1236 /// The MemberCache is used by dynamic and non-dynamic types to speed up
1237 /// member lookups. It has a member name based hash table; it maps each member
1238 /// name to a list of CacheEntry objects. Each CacheEntry contains a MemberInfo
1239 /// and the BindingFlags that were initially used to get it. The cache contains
1240 /// all members of the current class and all inherited members. If this cache is
1241 /// for an interface types, it also contains all inherited members.
1243 /// There are two ways to get a MemberCache:
1244 /// * if this is a dynamic type, lookup the corresponding DeclSpace and then
1245 /// use the DeclSpace.MemberCache property.
1246 /// * if this not a dynamic type, call TypeHandle.GetTypeHandle() to get a
1247 /// TypeHandle instance for the type and then use TypeHandle.MemberCache.
1249 public class MemberCache {
1250 public readonly IMemberContainer Container;
1251 protected Hashtable member_hash;
1252 protected Hashtable method_hash;
1255 /// Create a new MemberCache for the given IMemberContainer `container'.
1257 public MemberCache (IMemberContainer container)
1259 this.Container = container;
1261 Timer.IncrementCounter (CounterType.MemberCache);
1262 Timer.StartTimer (TimerType.CacheInit);
1264 // If we have a base class (we have a base class unless we're
1265 // TypeManager.object_type), we deep-copy its MemberCache here.
1266 if (Container.BaseCache != null)
1267 member_hash = SetupCache (Container.BaseCache);
1269 member_hash = new Hashtable ();
1271 // If this is neither a dynamic type nor an interface, create a special
1272 // method cache with all declared and inherited methods.
1273 Type type = container.Type;
1274 if (!(type is TypeBuilder) && !type.IsInterface &&
1275 (Container.BaseCache == null || Container.BaseCache.method_hash != null)) {
1276 method_hash = new Hashtable ();
1280 // Add all members from the current class.
1281 AddMembers (Container);
1283 Timer.StopTimer (TimerType.CacheInit);
1286 public MemberCache (Type[] ifaces)
1289 // The members of this cache all belong to other caches.
1290 // So, 'Container' will not be used.
1292 this.Container = null;
1294 member_hash = new Hashtable ();
1298 foreach (Type itype in ifaces)
1299 AddCacheContents (TypeManager.LookupMemberCache (itype));
1303 /// Bootstrap this member cache by doing a deep-copy of our base.
1305 Hashtable SetupCache (MemberCache base_class)
1307 Hashtable hash = new Hashtable ();
1309 if (base_class == null)
1312 IDictionaryEnumerator it = base_class.member_hash.GetEnumerator ();
1313 while (it.MoveNext ()) {
1314 hash [it.Key] = ((ArrayList) it.Value).Clone ();
1321 /// Add the contents of `cache' to the member_hash.
1323 void AddCacheContents (MemberCache cache)
1325 IDictionaryEnumerator it = cache.member_hash.GetEnumerator ();
1326 while (it.MoveNext ()) {
1327 ArrayList list = (ArrayList) member_hash [it.Key];
1329 member_hash [it.Key] = list = new ArrayList ();
1331 ArrayList entries = (ArrayList) it.Value;
1332 for (int i = entries.Count-1; i >= 0; i--) {
1333 CacheEntry entry = (CacheEntry) entries [i];
1335 if (entry.Container != cache.Container)
1343 /// Add all members from class `container' to the cache.
1345 void AddMembers (IMemberContainer container)
1347 // We need to call AddMembers() with a single member type at a time
1348 // to get the member type part of CacheEntry.EntryType right.
1349 if (!container.IsInterface) {
1350 AddMembers (MemberTypes.Constructor, container);
1351 AddMembers (MemberTypes.Field, container);
1353 AddMembers (MemberTypes.Method, container);
1354 AddMembers (MemberTypes.Property, container);
1355 AddMembers (MemberTypes.Event, container);
1356 // Nested types are returned by both Static and Instance searches.
1357 AddMembers (MemberTypes.NestedType,
1358 BindingFlags.Static | BindingFlags.Public, container);
1359 AddMembers (MemberTypes.NestedType,
1360 BindingFlags.Static | BindingFlags.NonPublic, container);
1363 void AddMembers (MemberTypes mt, IMemberContainer container)
1365 AddMembers (mt, BindingFlags.Static | BindingFlags.Public, container);
1366 AddMembers (mt, BindingFlags.Static | BindingFlags.NonPublic, container);
1367 AddMembers (mt, BindingFlags.Instance | BindingFlags.Public, container);
1368 AddMembers (mt, BindingFlags.Instance | BindingFlags.NonPublic, container);
1372 /// Add all members from class `container' with the requested MemberTypes and
1373 /// BindingFlags to the cache. This method is called multiple times with different
1374 /// MemberTypes and BindingFlags.
1376 void AddMembers (MemberTypes mt, BindingFlags bf, IMemberContainer container)
1378 MemberList members = container.GetMembers (mt, bf);
1380 foreach (MemberInfo member in members) {
1381 string name = member.Name;
1383 // We use a name-based hash table of ArrayList's.
1384 ArrayList list = (ArrayList) member_hash [name];
1386 list = new ArrayList ();
1387 member_hash.Add (name, list);
1390 // When this method is called for the current class, the list will
1391 // already contain all inherited members from our base classes.
1392 // We cannot add new members in front of the list since this'd be an
1393 // expensive operation, that's why the list is sorted in reverse order
1394 // (ie. members from the current class are coming last).
1395 list.Add (new CacheEntry (container, member, mt, bf));
1400 /// Add all declared and inherited methods from class `type' to the method cache.
1402 void AddMethods (Type type)
1404 AddMethods (BindingFlags.Static | BindingFlags.Public |
1405 BindingFlags.FlattenHierarchy, type);
1406 AddMethods (BindingFlags.Static | BindingFlags.NonPublic |
1407 BindingFlags.FlattenHierarchy, type);
1408 AddMethods (BindingFlags.Instance | BindingFlags.Public, type);
1409 AddMethods (BindingFlags.Instance | BindingFlags.NonPublic, type);
1412 void AddMethods (BindingFlags bf, Type type)
1415 // Consider the case:
1417 // class X { public virtual int f() {} }
1420 // When processing 'Y', the method_cache will already have a copy of 'f',
1421 // with ReflectedType == X. However, we want to ensure that its ReflectedType == Y
1423 MethodBase [] members = type.GetMethods (bf);
1425 Array.Reverse (members);
1427 foreach (MethodBase member in members) {
1428 string name = member.Name;
1430 // We use a name-based hash table of ArrayList's.
1431 ArrayList list = (ArrayList) method_hash [name];
1433 list = new ArrayList ();
1434 method_hash.Add (name, list);
1437 if (member.IsVirtual &&
1438 (member.Attributes & MethodAttributes.NewSlot) == 0) {
1439 MethodInfo base_method = ((MethodInfo) member).GetBaseDefinition ();
1441 if (base_method == member) {
1443 // Both mcs and CSC 1.1 seem to emit a somewhat broken
1444 // ...Invoke () function for delegates: it's missing a 'newslot'.
1445 // CSC 2.0 emits a 'newslot' for a delegate's Invoke.
1447 if (member.Name != "Invoke" ||
1448 !type.IsSubclassOf (TypeManager.multicast_delegate_type)) {
1449 Report.SymbolRelatedToPreviousError (base_method);
1450 Report.Warning (-28,
1451 "The method '{0}' is marked 'override'," +
1452 " but doesn't appear to override any virtual or abstract method:" +
1453 " it may be ignored during overload resolution",
1454 TypeManager.CSharpSignature (base_method));
1460 list.Add (new CacheEntry (null, base_method, MemberTypes.Method, bf));
1461 if ((base_method.Attributes & MethodAttributes.NewSlot) != 0)
1465 // Shouldn't get here. Mono appears to be buggy.
1467 MethodInfo new_base_method = base_method.GetBaseDefinition ();
1468 if (new_base_method == base_method) {
1469 Report.SymbolRelatedToPreviousError (base_method);
1470 Report.Warning (-28,
1471 "The method '{0}' is marked 'override'," +
1472 " but doesn't appear to overrided any virtual or abstract method:" +
1473 " it may be ignored during overload resolution",
1474 TypeManager.CSharpSignature (base_method));
1477 base_method = new_base_method;
1484 // Unfortunately, the elements returned by Type.GetMethods() aren't
1485 // sorted so we need to do this check for every member.
1486 BindingFlags new_bf = bf;
1487 if (member.DeclaringType == type)
1488 new_bf |= BindingFlags.DeclaredOnly;
1490 list.Add (new CacheEntry (Container, member, MemberTypes.Method, new_bf));
1495 /// Compute and return a appropriate `EntryType' magic number for the given
1496 /// MemberTypes and BindingFlags.
1498 protected static EntryType GetEntryType (MemberTypes mt, BindingFlags bf)
1500 EntryType type = EntryType.None;
1502 if ((mt & MemberTypes.Constructor) != 0)
1503 type |= EntryType.Constructor;
1504 if ((mt & MemberTypes.Event) != 0)
1505 type |= EntryType.Event;
1506 if ((mt & MemberTypes.Field) != 0)
1507 type |= EntryType.Field;
1508 if ((mt & MemberTypes.Method) != 0)
1509 type |= EntryType.Method;
1510 if ((mt & MemberTypes.Property) != 0)
1511 type |= EntryType.Property;
1512 // Nested types are returned by static and instance searches.
1513 if ((mt & MemberTypes.NestedType) != 0)
1514 type |= EntryType.NestedType | EntryType.Static | EntryType.Instance;
1516 if ((bf & BindingFlags.Instance) != 0)
1517 type |= EntryType.Instance;
1518 if ((bf & BindingFlags.Static) != 0)
1519 type |= EntryType.Static;
1520 if ((bf & BindingFlags.Public) != 0)
1521 type |= EntryType.Public;
1522 if ((bf & BindingFlags.NonPublic) != 0)
1523 type |= EntryType.NonPublic;
1524 if ((bf & BindingFlags.DeclaredOnly) != 0)
1525 type |= EntryType.Declared;
1531 /// The `MemberTypes' enumeration type is a [Flags] type which means that it may
1532 /// denote multiple member types. Returns true if the given flags value denotes a
1533 /// single member types.
1535 public static bool IsSingleMemberType (MemberTypes mt)
1538 case MemberTypes.Constructor:
1539 case MemberTypes.Event:
1540 case MemberTypes.Field:
1541 case MemberTypes.Method:
1542 case MemberTypes.Property:
1543 case MemberTypes.NestedType:
1552 /// We encode the MemberTypes and BindingFlags of each members in a "magic"
1553 /// number to speed up the searching process.
1556 protected enum EntryType {
1561 MaskStatic = Instance|Static,
1565 MaskProtection = Public|NonPublic,
1569 Constructor = 0x020,
1576 MaskType = Constructor|Event|Field|Method|Property|NestedType
1579 protected class CacheEntry {
1580 public readonly IMemberContainer Container;
1581 public readonly EntryType EntryType;
1582 public readonly MemberInfo Member;
1584 public CacheEntry (IMemberContainer container, MemberInfo member,
1585 MemberTypes mt, BindingFlags bf)
1587 this.Container = container;
1588 this.Member = member;
1589 this.EntryType = GetEntryType (mt, bf);
1592 public override string ToString ()
1594 return String.Format ("CacheEntry ({0}:{1}:{2})", Container.Name,
1600 /// This is called each time we're walking up one level in the class hierarchy
1601 /// and checks whether we can abort the search since we've already found what
1602 /// we were looking for.
1604 protected bool DoneSearching (ArrayList list)
1607 // We've found exactly one member in the current class and it's not
1608 // a method or constructor.
1610 if (list.Count == 1 && !(list [0] is MethodBase))
1614 // Multiple properties: we query those just to find out the indexer
1617 if ((list.Count > 0) && (list [0] is PropertyInfo))
1624 /// Looks up members with name `name'. If you provide an optional
1625 /// filter function, it'll only be called with members matching the
1626 /// requested member name.
1628 /// This method will try to use the cache to do the lookup if possible.
1630 /// Unlike other FindMembers implementations, this method will always
1631 /// check all inherited members - even when called on an interface type.
1633 /// If you know that you're only looking for methods, you should use
1634 /// MemberTypes.Method alone since this speeds up the lookup a bit.
1635 /// When doing a method-only search, it'll try to use a special method
1636 /// cache (unless it's a dynamic type or an interface) and the returned
1637 /// MemberInfo's will have the correct ReflectedType for inherited methods.
1638 /// The lookup process will automatically restart itself in method-only
1639 /// search mode if it discovers that it's about to return methods.
1641 ArrayList global = new ArrayList ();
1642 bool using_global = false;
1644 static MemberInfo [] emptyMemberInfo = new MemberInfo [0];
1646 public MemberInfo [] FindMembers (MemberTypes mt, BindingFlags bf, string name,
1647 MemberFilter filter, object criteria)
1650 throw new Exception ();
1652 bool declared_only = (bf & BindingFlags.DeclaredOnly) != 0;
1653 bool method_search = mt == MemberTypes.Method;
1654 // If we have a method cache and we aren't already doing a method-only search,
1655 // then we restart a method search if the first match is a method.
1656 bool do_method_search = !method_search && (method_hash != null);
1658 ArrayList applicable;
1660 // If this is a method-only search, we try to use the method cache if
1661 // possible; a lookup in the method cache will return a MemberInfo with
1662 // the correct ReflectedType for inherited methods.
1664 if (method_search && (method_hash != null))
1665 applicable = (ArrayList) method_hash [name];
1667 applicable = (ArrayList) member_hash [name];
1669 if (applicable == null)
1670 return emptyMemberInfo;
1673 // 32 slots gives 53 rss/54 size
1674 // 2/4 slots gives 55 rss
1676 // Strange: from 25,000 calls, only 1,800
1677 // are above 2. Why does this impact it?
1680 using_global = true;
1682 Timer.StartTimer (TimerType.CachedLookup);
1684 EntryType type = GetEntryType (mt, bf);
1686 IMemberContainer current = Container;
1689 // `applicable' is a list of all members with the given member name `name'
1690 // in the current class and all its base classes. The list is sorted in
1691 // reverse order due to the way how the cache is initialy created (to speed
1692 // things up, we're doing a deep-copy of our base).
1694 for (int i = applicable.Count-1; i >= 0; i--) {
1695 CacheEntry entry = (CacheEntry) applicable [i];
1697 // This happens each time we're walking one level up in the class
1698 // hierarchy. If we're doing a DeclaredOnly search, we must abort
1699 // the first time this happens (this may already happen in the first
1700 // iteration of this loop if there are no members with the name we're
1701 // looking for in the current class).
1702 if (entry.Container != current) {
1703 if (declared_only || DoneSearching (global))
1706 current = entry.Container;
1709 // Is the member of the correct type ?
1710 if ((entry.EntryType & type & EntryType.MaskType) == 0)
1713 // Is the member static/non-static ?
1714 if ((entry.EntryType & type & EntryType.MaskStatic) == 0)
1717 // Apply the filter to it.
1718 if (filter (entry.Member, criteria)) {
1719 if ((entry.EntryType & EntryType.MaskType) != EntryType.Method)
1720 do_method_search = false;
1721 global.Add (entry.Member);
1725 Timer.StopTimer (TimerType.CachedLookup);
1727 // If we have a method cache and we aren't already doing a method-only
1728 // search, we restart in method-only search mode if the first match is
1729 // a method. This ensures that we return a MemberInfo with the correct
1730 // ReflectedType for inherited methods.
1731 if (do_method_search && (global.Count > 0)){
1732 using_global = false;
1734 return FindMembers (MemberTypes.Method, bf, name, filter, criteria);
1737 using_global = false;
1738 MemberInfo [] copy = new MemberInfo [global.Count];
1739 global.CopyTo (copy);
1743 // find the nested type @name in @this.
1744 public Type FindNestedType (string name)
1746 ArrayList applicable = (ArrayList) member_hash [name];
1747 if (applicable == null)
1750 for (int i = applicable.Count-1; i >= 0; i--) {
1751 CacheEntry entry = (CacheEntry) applicable [i];
1752 if ((entry.EntryType & EntryType.NestedType & EntryType.MaskType) != 0)
1753 return (Type) entry.Member;
1760 // This finds the method or property for us to override. invocationType is the type where
1761 // the override is going to be declared, name is the name of the method/property, and
1762 // paramTypes is the parameters, if any to the method or property
1764 // Because the MemberCache holds members from this class and all the base classes,
1765 // we can avoid tons of reflection stuff.
1767 public MemberInfo FindMemberToOverride (Type invocationType, string name, Type [] paramTypes, bool is_property)
1769 ArrayList applicable;
1770 if (method_hash != null && !is_property)
1771 applicable = (ArrayList) method_hash [name];
1773 applicable = (ArrayList) member_hash [name];
1775 if (applicable == null)
1778 // Walk the chain of methods, starting from the top.
1780 for (int i = applicable.Count - 1; i >= 0; i--) {
1781 CacheEntry entry = (CacheEntry) applicable [i];
1783 if ((entry.EntryType & (is_property ? (EntryType.Property | EntryType.Field) : EntryType.Method)) == 0)
1786 PropertyInfo pi = null;
1787 MethodInfo mi = null;
1788 FieldInfo fi = null;
1789 Type [] cmpAttrs = null;
1792 if ((entry.EntryType & EntryType.Field) != 0) {
1793 fi = (FieldInfo)entry.Member;
1795 // TODO: For this case we ignore member type
1796 //fb = TypeManager.GetField (fi);
1797 //cmpAttrs = new Type[] { fb.MemberType };
1799 pi = (PropertyInfo) entry.Member;
1800 cmpAttrs = TypeManager.GetArgumentTypes (pi);
1803 mi = (MethodInfo) entry.Member;
1804 cmpAttrs = TypeManager.GetArgumentTypes (mi);
1808 // TODO: Almost duplicate !
1810 switch (fi.Attributes & FieldAttributes.FieldAccessMask) {
1811 case FieldAttributes.Private:
1813 // A private method is Ok if we are a nested subtype.
1814 // The spec actually is not very clear about this, see bug 52458.
1816 if (invocationType != entry.Container.Type &
1817 TypeManager.IsNestedChildOf (invocationType, entry.Container.Type))
1821 case FieldAttributes.FamANDAssem:
1822 case FieldAttributes.Assembly:
1824 // Check for assembly methods
1826 if (mi.DeclaringType.Assembly != CodeGen.Assembly.Builder)
1830 return entry.Member;
1834 // Check the arguments
1836 if (cmpAttrs.Length != paramTypes.Length)
1839 for (int j = cmpAttrs.Length - 1; j >= 0; j --)
1840 if (paramTypes [j] != cmpAttrs [j])
1844 // get one of the methods because this has the visibility info.
1847 mi = pi.GetGetMethod (true);
1849 mi = pi.GetSetMethod (true);
1855 switch (mi.Attributes & MethodAttributes.MemberAccessMask) {
1856 case MethodAttributes.Private:
1858 // A private method is Ok if we are a nested subtype.
1859 // The spec actually is not very clear about this, see bug 52458.
1861 if (invocationType == entry.Container.Type ||
1862 TypeManager.IsNestedChildOf (invocationType, entry.Container.Type))
1863 return entry.Member;
1866 case MethodAttributes.FamANDAssem:
1867 case MethodAttributes.Assembly:
1869 // Check for assembly methods
1871 if (mi.DeclaringType.Assembly == CodeGen.Assembly.Builder)
1872 return entry.Member;
1877 // A protected method is ok, because we are overriding.
1878 // public is always ok.
1880 return entry.Member;
1890 /// The method is looking for conflict with inherited symbols (errors CS0108, CS0109).
1891 /// We handle two cases. The first is for types without parameters (events, field, properties).
1892 /// The second are methods, indexers and this is why ignore_complex_types is here.
1893 /// The latest param is temporary hack. See DoDefineMembers method for more info.
1895 public MemberInfo FindMemberWithSameName (string name, bool ignore_complex_types, MemberInfo ignore_member)
1897 ArrayList applicable = null;
1899 if (method_hash != null)
1900 applicable = (ArrayList) method_hash [name];
1902 if (applicable != null) {
1903 for (int i = applicable.Count - 1; i >= 0; i--) {
1904 CacheEntry entry = (CacheEntry) applicable [i];
1905 if ((entry.EntryType & EntryType.Public) != 0)
1906 return entry.Member;
1910 if (member_hash == null)
1912 applicable = (ArrayList) member_hash [name];
1914 if (applicable != null) {
1915 for (int i = applicable.Count - 1; i >= 0; i--) {
1916 CacheEntry entry = (CacheEntry) applicable [i];
1917 if ((entry.EntryType & EntryType.Public) != 0 & entry.Member != ignore_member) {
1918 if (ignore_complex_types) {
1919 if ((entry.EntryType & EntryType.Method) != 0)
1922 // Does exist easier way how to detect indexer ?
1923 if ((entry.EntryType & EntryType.Property) != 0) {
1924 Type[] arg_types = TypeManager.GetArgumentTypes ((PropertyInfo)entry.Member);
1925 if (arg_types.Length > 0)
1929 return entry.Member;
1936 Hashtable locase_table;
1939 /// Builds low-case table for CLS Compliance test
1941 public Hashtable GetPublicMembers ()
1943 if (locase_table != null)
1944 return locase_table;
1946 locase_table = new Hashtable ();
1947 foreach (DictionaryEntry entry in member_hash) {
1948 ArrayList members = (ArrayList)entry.Value;
1949 for (int ii = 0; ii < members.Count; ++ii) {
1950 CacheEntry member_entry = (CacheEntry) members [ii];
1952 if ((member_entry.EntryType & EntryType.Public) == 0)
1955 // TODO: Does anyone know easier way how to detect that member is internal ?
1956 switch (member_entry.EntryType & EntryType.MaskType) {
1957 case EntryType.Constructor:
1960 case EntryType.Field:
1961 if ((((FieldInfo)member_entry.Member).Attributes & (FieldAttributes.Assembly | FieldAttributes.Public)) == FieldAttributes.Assembly)
1965 case EntryType.Method:
1966 if ((((MethodInfo)member_entry.Member).Attributes & (MethodAttributes.Assembly | MethodAttributes.Public)) == MethodAttributes.Assembly)
1970 case EntryType.Property:
1971 PropertyInfo pi = (PropertyInfo)member_entry.Member;
1972 if (pi.GetSetMethod () == null && pi.GetGetMethod () == null)
1976 case EntryType.Event:
1977 EventInfo ei = (EventInfo)member_entry.Member;
1978 MethodInfo mi = ei.GetAddMethod ();
1979 if ((mi.Attributes & (MethodAttributes.Assembly | MethodAttributes.Public)) == MethodAttributes.Assembly)
1983 string lcase = ((string)entry.Key).ToLower (System.Globalization.CultureInfo.InvariantCulture);
1984 locase_table [lcase] = member_entry.Member;
1988 return locase_table;
1991 public Hashtable Members {
1998 /// Cls compliance check whether methods or constructors parameters differing only in ref or out, or in array rank
2000 public void VerifyClsParameterConflict (ArrayList al, MethodCore method, MemberInfo this_builder)
2002 EntryType tested_type = (method is Constructor ? EntryType.Constructor : EntryType.Method) | EntryType.Public;
2004 for (int i = 0; i < al.Count; ++i) {
2005 MemberCache.CacheEntry entry = (MemberCache.CacheEntry) al [i];
2008 if (entry.Member == this_builder)
2011 if ((entry.EntryType & tested_type) != tested_type)
2014 MethodBase method_to_compare = (MethodBase)entry.Member;
2015 if (AttributeTester.AreOverloadedMethodParamsClsCompliant (method.ParameterTypes, TypeManager.GetArgumentTypes (method_to_compare)))
2018 IMethodData md = TypeManager.GetMethod (method_to_compare);
2020 // TODO: now we are ignoring CLSCompliance(false) on method from other assembly which is buggy.
2021 // However it is exactly what csc does.
2022 if (md != null && !md.IsClsCompliaceRequired (method.Parent))
2025 Report.SymbolRelatedToPreviousError (entry.Member);
2026 Report.Error (3006, method.Location, "Overloaded method '{0}' differing only in ref or out, or in array rank, is not CLS-compliant", method.GetSignatureForError ());