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 ()
280 if (Parent == null || Parent.Parent == null)
283 return String.Concat (Parent.GetSignatureForError (), '.', Name);
287 /// Base Emit method. This is also entry point for CLS-Compliant verification.
289 public virtual void Emit ()
291 // Hack with Parent == null is for EnumMember
292 if (Parent == null || (GetObsoleteAttribute (Parent) == null && Parent.GetObsoleteAttribute (Parent) == null))
293 VerifyObsoleteAttribute ();
295 if (!RootContext.VerifyClsCompliance)
298 VerifyClsCompliance (Parent);
301 public bool InUnsafe {
303 return ((ModFlags & Modifiers.UNSAFE) != 0) || Parent.UnsafeContext;
307 public virtual bool IsUsed {
309 return (caching_flags & Flags.IsUsed) != 0;
313 public void SetMemberIsUsed ()
315 caching_flags |= Flags.IsUsed;
319 // Whehter is it ok to use an unsafe pointer in this type container
321 public bool UnsafeOK (DeclSpace parent)
324 // First check if this MemberCore modifier flags has unsafe set
326 if ((ModFlags & Modifiers.UNSAFE) != 0)
329 if (parent.UnsafeContext)
332 Expression.UnsafeError (Location);
337 /// Returns instance of ObsoleteAttribute for this MemberCore
339 public ObsoleteAttribute GetObsoleteAttribute (DeclSpace ds)
341 // ((flags & (Flags.Obsolete_Undetected | Flags.Obsolete)) == 0) is slower, but why ?
342 if ((caching_flags & Flags.Obsolete_Undetected) == 0 && (caching_flags & Flags.Obsolete) == 0) {
346 caching_flags &= ~Flags.Obsolete_Undetected;
348 if (OptAttributes == null)
351 Attribute obsolete_attr = OptAttributes.Search (
352 TypeManager.obsolete_attribute_type, ds.EmitContext);
353 if (obsolete_attr == null)
356 ObsoleteAttribute obsolete = obsolete_attr.GetObsoleteAttribute (ds.EmitContext);
357 if (obsolete == null)
360 caching_flags |= Flags.Obsolete;
365 /// Analyze whether CLS-Compliant verification must be execute for this MemberCore.
367 public override bool IsClsCompliaceRequired (DeclSpace container)
369 if ((caching_flags & Flags.ClsCompliance_Undetected) == 0)
370 return (caching_flags & Flags.ClsCompliant) != 0;
372 if (GetClsCompliantAttributeValue (container) && IsExposedFromAssembly (container)) {
373 caching_flags &= ~Flags.ClsCompliance_Undetected;
374 caching_flags |= Flags.ClsCompliant;
378 caching_flags &= ~Flags.ClsCompliance_Undetected;
383 /// Returns true when MemberCore is exposed from assembly.
385 public bool IsExposedFromAssembly (DeclSpace ds)
387 if ((ModFlags & (Modifiers.PUBLIC | Modifiers.PROTECTED)) == 0)
390 DeclSpace parentContainer = ds;
391 while (parentContainer != null && parentContainer.ModFlags != 0) {
392 if ((parentContainer.ModFlags & (Modifiers.PUBLIC | Modifiers.PROTECTED)) == 0)
394 parentContainer = parentContainer.Parent;
400 /// Resolve CLSCompliantAttribute value or gets cached value.
402 bool GetClsCompliantAttributeValue (DeclSpace ds)
404 if (OptAttributes != null) {
405 Attribute cls_attribute = OptAttributes.Search (
406 TypeManager.cls_compliant_attribute_type, ds.EmitContext);
407 if (cls_attribute != null) {
408 caching_flags |= Flags.HasClsCompliantAttribute;
409 return cls_attribute.GetClsCompliantAttributeValue (ds.EmitContext);
412 return ds.GetClsCompliantAttributeValue ();
416 /// Returns true if MemberCore is explicitly marked with CLSCompliantAttribute
418 protected bool HasClsCompliantAttribute {
420 return (caching_flags & Flags.HasClsCompliantAttribute) != 0;
425 /// It helps to handle error 102 & 111 detection
427 public virtual bool MarkForDuplicationCheck ()
433 /// The main virtual method for CLS-Compliant verifications.
434 /// The method returns true if member is CLS-Compliant and false if member is not
435 /// CLS-Compliant which means that CLS-Compliant tests are not necessary. A descendants override it
436 /// and add their extra verifications.
438 protected virtual bool VerifyClsCompliance (DeclSpace ds)
440 if (!IsClsCompliaceRequired (ds)) {
441 if (HasClsCompliantAttribute && RootContext.WarningLevel >= 2) {
442 if (!IsExposedFromAssembly (ds))
443 Report.Warning (3019, Location, "CLS compliance checking will not be performed on `{0}' because it is not visible from outside this assembly", GetSignatureForError ());
444 if (!CodeGen.Assembly.IsClsCompliant)
445 Report.Warning (3021, Location, "`{0}' does not need a CLSCompliant attribute because the assembly is not marked as CLS-compliant", GetSignatureForError ());
450 if (!CodeGen.Assembly.IsClsCompliant) {
451 if (HasClsCompliantAttribute) {
452 Report.Error (3014, Location,
453 "`{0}' cannot be marked as CLS-compliant because the assembly is not marked as CLS-compliant",
454 GetSignatureForError ());
459 if (member_name.Name [0] == '_') {
460 Report.Error (3008, Location, "Identifier `{0}' is not CLS-compliant", GetSignatureForError () );
465 protected abstract void VerifyObsoleteAttribute ();
468 // Raised (and passed an XmlElement that contains the comment)
469 // when GenerateDocComment is writing documentation expectedly.
471 internal virtual void OnGenerateDocComment (DeclSpace ds, XmlElement intermediateNode)
476 // Returns a string that represents the signature for this
477 // member which should be used in XML documentation.
479 public virtual string GetDocCommentName (DeclSpace ds)
481 if (ds == null || this is DeclSpace)
482 return DocCommentHeader + Name;
484 return String.Concat (DocCommentHeader, ds.Name, ".", Name);
488 // Generates xml doc comments (if any), and if required,
489 // handle warning report.
491 internal virtual void GenerateDocComment (DeclSpace ds)
493 DocUtil.GenerateDocComment (this, ds);
498 /// Base class for structs, classes, enumerations and interfaces.
501 /// They all create new declaration spaces. This
502 /// provides the common foundation for managing those name
505 public abstract class DeclSpace : MemberCore, IAlias {
507 /// This points to the actual definition that is being
508 /// created with System.Reflection.Emit
510 public TypeBuilder TypeBuilder;
513 // This is the namespace in which this typecontainer
514 // was declared. We use this to resolve names.
516 public NamespaceEntry NamespaceEntry;
518 private Hashtable Cache = new Hashtable ();
520 public string Basename;
522 protected Hashtable defined_names;
524 // The emit context for toplevel objects.
525 protected EmitContext ec;
527 public EmitContext EmitContext {
531 static string[] attribute_targets = new string [] { "type" };
533 public DeclSpace (NamespaceEntry ns, TypeContainer parent, MemberName name,
534 Attributes attrs, Location l)
535 : base (parent, name, attrs, l)
538 Basename = name.Name;
539 defined_names = new Hashtable ();
543 /// Adds the member to defined_names table. It tests for duplications and enclosing name conflicts
545 protected bool AddToContainer (MemberCore symbol, string name)
547 if (name == Basename && !(this is Interface) && !(this is Enum)) {
548 Report.SymbolRelatedToPreviousError (this);
549 Report.Error (542, symbol.Location, "`{0}': member names cannot be the same as their enclosing type", symbol.GetSignatureForError ());
553 MemberCore mc = (MemberCore) defined_names [name];
556 defined_names.Add (name, symbol);
560 if (symbol.MarkForDuplicationCheck () && mc.MarkForDuplicationCheck ())
563 if (this is RootTypes) {
564 // TODO: It should not reach this once we merge RecordDecl to AddTo
568 Report.SymbolRelatedToPreviousError (mc);
569 Report.Error (102, symbol.Location, "The type `{0}' already contains a definition for `{1}'",
570 GetSignatureForError (), symbol.MemberName.Name);
575 /// Returns the MemberCore associated with a given name in the declaration
576 /// space. It doesn't return method based symbols !!
579 public MemberCore GetDefinition (string name)
581 return (MemberCore)defined_names [name];
585 // root_types contains all the types. All TopLevel types
586 // hence have a parent that points to `root_types', that is
587 // why there is a non-obvious test down here.
589 public bool IsTopLevel {
591 return (Parent != null && Parent.Parent == null);
595 public virtual void CloseType ()
597 if ((caching_flags & Flags.CloseTypeCreated) == 0){
599 TypeBuilder.CreateType ();
602 // The try/catch is needed because
603 // nested enumerations fail to load when they
606 // Even if this is the right order (enumerations
607 // declared after types).
609 // Note that this still creates the type and
610 // it is possible to save it
612 caching_flags |= Flags.CloseTypeCreated;
616 protected virtual TypeAttributes TypeAttr {
618 return CodeGen.Module.DefaultCharSetType;
623 /// Should be overriten by the appropriate declaration space
625 public abstract TypeBuilder DefineType ();
628 /// Define all members, but don't apply any attributes or do anything which may
629 /// access not-yet-defined classes. This method also creates the MemberCache.
631 public virtual bool DefineMembers (TypeContainer parent)
633 if (((ModFlags & Modifiers.NEW) != 0) && IsTopLevel) {
634 Report.Error (1530, Location, "Keyword `new' is not allowed on namespace elements");
640 public override string GetSignatureForError ()
642 // Parent.GetSignatureForError
647 // Whether this is an `unsafe context'
649 public bool UnsafeContext {
651 if ((ModFlags & Modifiers.UNSAFE) != 0)
654 return Parent.UnsafeContext;
659 EmitContext type_resolve_ec;
660 protected EmitContext TypeResolveEmitContext {
662 if (type_resolve_ec == null) {
663 // FIXME: I think this should really be one of:
665 // a. type_resolve_ec = Parent.EmitContext;
666 // b. type_resolve_ec = new EmitContext (Parent, Parent, loc, null, null, ModFlags, false);
668 // However, if Parent == RootContext.Tree.Types, its NamespaceEntry will be null.
670 type_resolve_ec = new EmitContext (Parent, this, Location.Null, null, null, ModFlags, false);
672 return type_resolve_ec;
677 // Resolves the expression `e' for a type, and will recursively define
678 // types. This should only be used for resolving base types.
680 public TypeExpr ResolveBaseTypeExpr (Expression e, bool silent, Location loc)
682 TypeResolveEmitContext.loc = loc;
683 TypeResolveEmitContext.ContainerType = TypeBuilder;
685 return e.ResolveAsTypeTerminal (TypeResolveEmitContext, silent);
688 public bool CheckAccessLevel (Type check_type)
690 if (check_type == TypeBuilder)
693 TypeAttributes check_attr = check_type.Attributes & TypeAttributes.VisibilityMask;
696 // Broken Microsoft runtime, return public for arrays, no matter what
697 // the accessibility is for their underlying class, and they return
698 // NonPublic visibility for pointers
700 if (check_type.IsArray || check_type.IsPointer)
701 return CheckAccessLevel (TypeManager.GetElementType (check_type));
703 if (TypeBuilder == null)
704 // FIXME: TypeBuilder will be null when invoked by Class.GetNormalBases().
705 // However, this is invoked again later -- so safe to return true.
706 // May also be null when resolving top-level attributes.
710 case TypeAttributes.Public:
713 case TypeAttributes.NotPublic:
715 // This test should probably use the declaringtype.
717 return check_type.Assembly == TypeBuilder.Assembly;
719 case TypeAttributes.NestedPublic:
722 case TypeAttributes.NestedPrivate:
723 return NestedAccessible (check_type);
725 case TypeAttributes.NestedFamily:
726 return FamilyAccessible (check_type);
728 case TypeAttributes.NestedFamANDAssem:
729 return (check_type.Assembly == TypeBuilder.Assembly) &&
730 FamilyAccessible (check_type);
732 case TypeAttributes.NestedFamORAssem:
733 return (check_type.Assembly == TypeBuilder.Assembly) ||
734 FamilyAccessible (check_type);
736 case TypeAttributes.NestedAssembly:
737 return check_type.Assembly == TypeBuilder.Assembly;
740 Console.WriteLine ("HERE: " + check_attr);
745 protected bool NestedAccessible (Type check_type)
747 Type declaring = check_type.DeclaringType;
748 return TypeBuilder == declaring ||
749 TypeManager.IsNestedChildOf (TypeBuilder, declaring);
752 protected bool FamilyAccessible (Type check_type)
754 Type declaring = check_type.DeclaringType;
755 return TypeManager.IsNestedFamilyAccessible (TypeBuilder, declaring);
758 // Access level of a type.
760 enum AccessLevel { // Each column represents `is this scope larger or equal to Blah scope'
761 // Public Assembly Protected
762 Protected = (0 << 0) | (0 << 1) | (X << 2),
763 Public = (X << 0) | (X << 1) | (X << 2),
764 Private = (0 << 0) | (0 << 1) | (0 << 2),
765 Internal = (0 << 0) | (X << 1) | (0 << 2),
766 ProtectedOrInternal = (0 << 0) | (X << 1) | (X << 2),
769 static AccessLevel GetAccessLevelFromModifiers (int flags)
771 if ((flags & Modifiers.INTERNAL) != 0) {
773 if ((flags & Modifiers.PROTECTED) != 0)
774 return AccessLevel.ProtectedOrInternal;
776 return AccessLevel.Internal;
778 } else if ((flags & Modifiers.PROTECTED) != 0)
779 return AccessLevel.Protected;
781 else if ((flags & Modifiers.PRIVATE) != 0)
782 return AccessLevel.Private;
785 return AccessLevel.Public;
788 // What is the effective access level of this?
790 AccessLevel EffectiveAccessLevel {
792 AccessLevel myAccess = GetAccessLevelFromModifiers (ModFlags);
793 if (!IsTopLevel && (Parent != null))
794 return myAccess & Parent.EffectiveAccessLevel;
800 // Return the access level for type `t'
801 static AccessLevel TypeEffectiveAccessLevel (Type t)
804 return AccessLevel.Public;
805 if (t.IsNestedPrivate)
806 return AccessLevel.Private;
808 return AccessLevel.Internal;
810 // By now, it must be nested
811 AccessLevel parentLevel = TypeEffectiveAccessLevel (t.DeclaringType);
813 if (t.IsNestedPublic)
815 if (t.IsNestedAssembly)
816 return parentLevel & AccessLevel.Internal;
817 if (t.IsNestedFamily)
818 return parentLevel & AccessLevel.Protected;
819 if (t.IsNestedFamORAssem)
820 return parentLevel & AccessLevel.ProtectedOrInternal;
821 if (t.IsNestedFamANDAssem)
822 throw new NotImplementedException ("NestedFamANDAssem not implemented, cant make this kind of type from c# anyways");
824 // nested private is taken care of
826 throw new Exception ("I give up, what are you?");
830 // This answers `is the type P, as accessible as a member M which has the
831 // accessability @flags which is declared as a nested member of the type T, this declspace'
833 public bool AsAccessible (Type p, int flags)
836 // 1) if M is private, its accessability is the same as this declspace.
837 // we already know that P is accessible to T before this method, so we
841 if ((flags & Modifiers.PRIVATE) != 0)
844 while (p.IsArray || p.IsPointer || p.IsByRef)
845 p = TypeManager.GetElementType (p);
847 AccessLevel pAccess = TypeEffectiveAccessLevel (p);
848 AccessLevel mAccess = this.EffectiveAccessLevel &
849 GetAccessLevelFromModifiers (flags);
851 // for every place from which we can access M, we must
852 // be able to access P as well. So, we want
853 // For every bit in M and P, M_i -> P_1 == true
854 // or, ~ (M -> P) == 0 <-> ~ ( ~M | P) == 0
856 return ~ (~ mAccess | pAccess) == 0;
859 public static void Error_AmbiguousTypeReference (Location loc, string name, string t1, string t2)
861 Report.Error (104, loc, "`{0}' is an ambiguous reference between `{1}' and `{2}'",
866 // Return the nested type with name @name. Ensures that the nested type
867 // is defined if necessary. Do _not_ use this when you have a MemberCache handy.
869 public virtual Type FindNestedType (string name)
874 private Type LookupNestedTypeInHierarchy (string name)
876 // if the member cache has been created, lets use it.
877 // the member cache is MUCH faster.
878 if (MemberCache != null)
879 return MemberCache.FindNestedType (name);
881 // no member cache. Do it the hard way -- reflection
883 for (Type current_type = TypeBuilder;
884 current_type != null && current_type != TypeManager.object_type;
885 current_type = current_type.BaseType) {
886 if (current_type is TypeBuilder) {
887 DeclSpace decl = this;
888 if (current_type != TypeBuilder)
889 decl = TypeManager.LookupDeclSpace (current_type);
890 t = decl.FindNestedType (name);
892 t = TypeManager.GetNestedType (current_type, name);
895 if (t != null && CheckAccessLevel (t))
903 // Public function used to locate types, this can only
904 // be used after the ResolveTree function has been invoked.
906 // Set 'ignore_cs0104' to true if you want to ignore cs0104 errors.
908 // Returns: Type or null if they type can not be found.
910 public FullNamedExpression LookupType (string name, Location loc, bool ignore_cs0104)
912 if (this is PartialContainer)
913 throw new InternalErrorException ("Should not get here");
915 if (Cache.Contains (name))
916 return (FullNamedExpression) Cache [name];
918 FullNamedExpression e;
919 Type t = LookupNestedTypeInHierarchy (name);
921 e = new TypeExpression (t, Location.Null);
922 else if (Parent != null && Parent != RootContext.Tree.Types)
923 e = Parent.LookupType (name, loc, ignore_cs0104);
925 e = NamespaceEntry.LookupNamespaceOrType (this, name, loc, ignore_cs0104);
932 /// This function is broken and not what you're looking for. It should only
933 /// be used while the type is still being created since it doesn't use the cache
934 /// and relies on the filter doing the member name check.
936 public abstract MemberList FindMembers (MemberTypes mt, BindingFlags bf,
937 MemberFilter filter, object criteria);
940 /// If we have a MemberCache, return it. This property may return null if the
941 /// class doesn't have a member cache or while it's still being created.
943 public abstract MemberCache MemberCache {
947 public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
949 if (a.Type == TypeManager.required_attr_type) {
950 Report.Error (1608, a.Location, "The RequiredAttribute attribute is not permitted on C# types");
953 TypeBuilder.SetCustomAttribute (cb);
957 /// Goes through class hierarchy and get value of first CLSCompliantAttribute that found.
958 /// If no is attribute exists then return assembly CLSCompliantAttribute.
960 public bool GetClsCompliantAttributeValue ()
962 if ((caching_flags & Flags.HasCompliantAttribute_Undetected) == 0)
963 return (caching_flags & Flags.ClsCompliantAttributeTrue) != 0;
965 caching_flags &= ~Flags.HasCompliantAttribute_Undetected;
967 if (OptAttributes != null) {
968 Attribute cls_attribute = OptAttributes.Search (TypeManager.cls_compliant_attribute_type, ec);
969 if (cls_attribute != null) {
970 caching_flags |= Flags.HasClsCompliantAttribute;
971 if (cls_attribute.GetClsCompliantAttributeValue (ec)) {
972 caching_flags |= Flags.ClsCompliantAttributeTrue;
979 if (Parent == null) {
980 if (CodeGen.Assembly.IsClsCompliant) {
981 caching_flags |= Flags.ClsCompliantAttributeTrue;
987 if (Parent.GetClsCompliantAttributeValue ()) {
988 caching_flags |= Flags.ClsCompliantAttributeTrue;
994 public override string[] ValidAttributeTargets {
996 return attribute_targets;
1000 bool IAlias.IsType {
1001 get { return true; }
1004 string IAlias.Name {
1005 get { return Name; }
1008 TypeExpr IAlias.ResolveAsType (EmitContext ec)
1010 if (TypeBuilder == null)
1011 throw new InvalidOperationException ();
1013 return new TypeExpression (TypeBuilder, Location);
1018 /// This is a readonly list of MemberInfo's.
1020 public class MemberList : IList {
1021 public readonly IList List;
1025 /// Create a new MemberList from the given IList.
1027 public MemberList (IList list)
1032 this.List = new ArrayList ();
1037 /// Concatenate the ILists `first' and `second' to a new MemberList.
1039 public MemberList (IList first, IList second)
1041 ArrayList list = new ArrayList ();
1042 list.AddRange (first);
1043 list.AddRange (second);
1048 public static readonly MemberList Empty = new MemberList (new ArrayList ());
1051 /// Cast the MemberList into a MemberInfo[] array.
1054 /// This is an expensive operation, only use it if it's really necessary.
1056 public static explicit operator MemberInfo [] (MemberList list)
1058 Timer.StartTimer (TimerType.MiscTimer);
1059 MemberInfo [] result = new MemberInfo [list.Count];
1060 list.CopyTo (result, 0);
1061 Timer.StopTimer (TimerType.MiscTimer);
1073 public bool IsSynchronized {
1075 return List.IsSynchronized;
1079 public object SyncRoot {
1081 return List.SyncRoot;
1085 public void CopyTo (Array array, int index)
1087 List.CopyTo (array, index);
1092 public IEnumerator GetEnumerator ()
1094 return List.GetEnumerator ();
1099 public bool IsFixedSize {
1105 public bool IsReadOnly {
1111 object IList.this [int index] {
1113 return List [index];
1117 throw new NotSupportedException ();
1121 // FIXME: try to find out whether we can avoid the cast in this indexer.
1122 public MemberInfo this [int index] {
1124 return (MemberInfo) List [index];
1128 public int Add (object value)
1130 throw new NotSupportedException ();
1133 public void Clear ()
1135 throw new NotSupportedException ();
1138 public bool Contains (object value)
1140 return List.Contains (value);
1143 public int IndexOf (object value)
1145 return List.IndexOf (value);
1148 public void Insert (int index, object value)
1150 throw new NotSupportedException ();
1153 public void Remove (object value)
1155 throw new NotSupportedException ();
1158 public void RemoveAt (int index)
1160 throw new NotSupportedException ();
1165 /// This interface is used to get all members of a class when creating the
1166 /// member cache. It must be implemented by all DeclSpace derivatives which
1167 /// want to support the member cache and by TypeHandle to get caching of
1168 /// non-dynamic types.
1170 public interface IMemberContainer {
1172 /// The name of the IMemberContainer. This is only used for
1173 /// debugging purposes.
1180 /// The type of this IMemberContainer.
1187 /// Returns the IMemberContainer of the base class or null if this
1188 /// is an interface or TypeManger.object_type.
1189 /// This is used when creating the member cache for a class to get all
1190 /// members from the base class.
1192 MemberCache BaseCache {
1197 /// Whether this is an interface.
1204 /// Returns all members of this class with the corresponding MemberTypes
1205 /// and BindingFlags.
1208 /// When implementing this method, make sure not to return any inherited
1209 /// members and check the MemberTypes and BindingFlags properly.
1210 /// Unfortunately, System.Reflection is lame and doesn't provide a way to
1211 /// get the BindingFlags (static/non-static,public/non-public) in the
1212 /// MemberInfo class, but the cache needs this information. That's why
1213 /// this method is called multiple times with different BindingFlags.
1215 MemberList GetMembers (MemberTypes mt, BindingFlags bf);
1218 /// Return the container's member cache.
1220 MemberCache MemberCache {
1226 /// The MemberCache is used by dynamic and non-dynamic types to speed up
1227 /// member lookups. It has a member name based hash table; it maps each member
1228 /// name to a list of CacheEntry objects. Each CacheEntry contains a MemberInfo
1229 /// and the BindingFlags that were initially used to get it. The cache contains
1230 /// all members of the current class and all inherited members. If this cache is
1231 /// for an interface types, it also contains all inherited members.
1233 /// There are two ways to get a MemberCache:
1234 /// * if this is a dynamic type, lookup the corresponding DeclSpace and then
1235 /// use the DeclSpace.MemberCache property.
1236 /// * if this not a dynamic type, call TypeHandle.GetTypeHandle() to get a
1237 /// TypeHandle instance for the type and then use TypeHandle.MemberCache.
1239 public class MemberCache {
1240 public readonly IMemberContainer Container;
1241 protected Hashtable member_hash;
1242 protected Hashtable method_hash;
1245 /// Create a new MemberCache for the given IMemberContainer `container'.
1247 public MemberCache (IMemberContainer container)
1249 this.Container = container;
1251 Timer.IncrementCounter (CounterType.MemberCache);
1252 Timer.StartTimer (TimerType.CacheInit);
1254 // If we have a base class (we have a base class unless we're
1255 // TypeManager.object_type), we deep-copy its MemberCache here.
1256 if (Container.BaseCache != null)
1257 member_hash = SetupCache (Container.BaseCache);
1259 member_hash = new Hashtable ();
1261 // If this is neither a dynamic type nor an interface, create a special
1262 // method cache with all declared and inherited methods.
1263 Type type = container.Type;
1264 if (!(type is TypeBuilder) && !type.IsInterface &&
1265 (Container.BaseCache == null || Container.BaseCache.method_hash != null)) {
1266 method_hash = new Hashtable ();
1270 // Add all members from the current class.
1271 AddMembers (Container);
1273 Timer.StopTimer (TimerType.CacheInit);
1276 public MemberCache (Type[] ifaces)
1279 // The members of this cache all belong to other caches.
1280 // So, 'Container' will not be used.
1282 this.Container = null;
1284 member_hash = new Hashtable ();
1288 foreach (Type itype in ifaces)
1289 AddCacheContents (TypeManager.LookupMemberCache (itype));
1293 /// Bootstrap this member cache by doing a deep-copy of our base.
1295 Hashtable SetupCache (MemberCache base_class)
1297 Hashtable hash = new Hashtable ();
1299 if (base_class == null)
1302 IDictionaryEnumerator it = base_class.member_hash.GetEnumerator ();
1303 while (it.MoveNext ()) {
1304 hash [it.Key] = ((ArrayList) it.Value).Clone ();
1311 /// Add the contents of `cache' to the member_hash.
1313 void AddCacheContents (MemberCache cache)
1315 IDictionaryEnumerator it = cache.member_hash.GetEnumerator ();
1316 while (it.MoveNext ()) {
1317 ArrayList list = (ArrayList) member_hash [it.Key];
1319 member_hash [it.Key] = list = new ArrayList ();
1321 ArrayList entries = (ArrayList) it.Value;
1322 for (int i = entries.Count-1; i >= 0; i--) {
1323 CacheEntry entry = (CacheEntry) entries [i];
1325 if (entry.Container != cache.Container)
1333 /// Add all members from class `container' to the cache.
1335 void AddMembers (IMemberContainer container)
1337 // We need to call AddMembers() with a single member type at a time
1338 // to get the member type part of CacheEntry.EntryType right.
1339 if (!container.IsInterface) {
1340 AddMembers (MemberTypes.Constructor, container);
1341 AddMembers (MemberTypes.Field, container);
1343 AddMembers (MemberTypes.Method, container);
1344 AddMembers (MemberTypes.Property, container);
1345 AddMembers (MemberTypes.Event, container);
1346 // Nested types are returned by both Static and Instance searches.
1347 AddMembers (MemberTypes.NestedType,
1348 BindingFlags.Static | BindingFlags.Public, container);
1349 AddMembers (MemberTypes.NestedType,
1350 BindingFlags.Static | BindingFlags.NonPublic, container);
1353 void AddMembers (MemberTypes mt, IMemberContainer container)
1355 AddMembers (mt, BindingFlags.Static | BindingFlags.Public, container);
1356 AddMembers (mt, BindingFlags.Static | BindingFlags.NonPublic, container);
1357 AddMembers (mt, BindingFlags.Instance | BindingFlags.Public, container);
1358 AddMembers (mt, BindingFlags.Instance | BindingFlags.NonPublic, container);
1362 /// Add all members from class `container' with the requested MemberTypes and
1363 /// BindingFlags to the cache. This method is called multiple times with different
1364 /// MemberTypes and BindingFlags.
1366 void AddMembers (MemberTypes mt, BindingFlags bf, IMemberContainer container)
1368 MemberList members = container.GetMembers (mt, bf);
1370 foreach (MemberInfo member in members) {
1371 string name = member.Name;
1373 // We use a name-based hash table of ArrayList's.
1374 ArrayList list = (ArrayList) member_hash [name];
1376 list = new ArrayList ();
1377 member_hash.Add (name, list);
1380 // When this method is called for the current class, the list will
1381 // already contain all inherited members from our base classes.
1382 // We cannot add new members in front of the list since this'd be an
1383 // expensive operation, that's why the list is sorted in reverse order
1384 // (ie. members from the current class are coming last).
1385 list.Add (new CacheEntry (container, member, mt, bf));
1390 /// Add all declared and inherited methods from class `type' to the method cache.
1392 void AddMethods (Type type)
1394 AddMethods (BindingFlags.Static | BindingFlags.Public |
1395 BindingFlags.FlattenHierarchy, type);
1396 AddMethods (BindingFlags.Static | BindingFlags.NonPublic |
1397 BindingFlags.FlattenHierarchy, type);
1398 AddMethods (BindingFlags.Instance | BindingFlags.Public, type);
1399 AddMethods (BindingFlags.Instance | BindingFlags.NonPublic, type);
1402 static ArrayList overrides = new ArrayList ();
1404 void AddMethods (BindingFlags bf, Type type)
1406 MethodBase [] members = type.GetMethods (bf);
1408 Array.Reverse (members);
1410 foreach (MethodBase member in members) {
1411 string name = member.Name;
1413 // We use a name-based hash table of ArrayList's.
1414 ArrayList list = (ArrayList) method_hash [name];
1416 list = new ArrayList ();
1417 method_hash.Add (name, list);
1420 MethodInfo curr = (MethodInfo) member;
1421 while (curr.IsVirtual && (curr.Attributes & MethodAttributes.NewSlot) == 0) {
1422 MethodInfo base_method = curr.GetBaseDefinition ();
1424 if (base_method == curr)
1425 // Not every virtual function needs to have a NewSlot flag.
1428 overrides.Add (curr);
1429 list.Add (new CacheEntry (null, base_method, MemberTypes.Method, bf));
1433 if (overrides.Count > 0) {
1434 for (int i = 0; i < overrides.Count; ++i)
1435 TypeManager.RegisterOverride ((MethodBase) overrides [i], curr);
1439 // Unfortunately, the elements returned by Type.GetMethods() aren't
1440 // sorted so we need to do this check for every member.
1441 BindingFlags new_bf = bf;
1442 if (member.DeclaringType == type)
1443 new_bf |= BindingFlags.DeclaredOnly;
1445 list.Add (new CacheEntry (Container, member, MemberTypes.Method, new_bf));
1450 /// Compute and return a appropriate `EntryType' magic number for the given
1451 /// MemberTypes and BindingFlags.
1453 protected static EntryType GetEntryType (MemberTypes mt, BindingFlags bf)
1455 EntryType type = EntryType.None;
1457 if ((mt & MemberTypes.Constructor) != 0)
1458 type |= EntryType.Constructor;
1459 if ((mt & MemberTypes.Event) != 0)
1460 type |= EntryType.Event;
1461 if ((mt & MemberTypes.Field) != 0)
1462 type |= EntryType.Field;
1463 if ((mt & MemberTypes.Method) != 0)
1464 type |= EntryType.Method;
1465 if ((mt & MemberTypes.Property) != 0)
1466 type |= EntryType.Property;
1467 // Nested types are returned by static and instance searches.
1468 if ((mt & MemberTypes.NestedType) != 0)
1469 type |= EntryType.NestedType | EntryType.Static | EntryType.Instance;
1471 if ((bf & BindingFlags.Instance) != 0)
1472 type |= EntryType.Instance;
1473 if ((bf & BindingFlags.Static) != 0)
1474 type |= EntryType.Static;
1475 if ((bf & BindingFlags.Public) != 0)
1476 type |= EntryType.Public;
1477 if ((bf & BindingFlags.NonPublic) != 0)
1478 type |= EntryType.NonPublic;
1479 if ((bf & BindingFlags.DeclaredOnly) != 0)
1480 type |= EntryType.Declared;
1486 /// The `MemberTypes' enumeration type is a [Flags] type which means that it may
1487 /// denote multiple member types. Returns true if the given flags value denotes a
1488 /// single member types.
1490 public static bool IsSingleMemberType (MemberTypes mt)
1493 case MemberTypes.Constructor:
1494 case MemberTypes.Event:
1495 case MemberTypes.Field:
1496 case MemberTypes.Method:
1497 case MemberTypes.Property:
1498 case MemberTypes.NestedType:
1507 /// We encode the MemberTypes and BindingFlags of each members in a "magic"
1508 /// number to speed up the searching process.
1511 protected enum EntryType {
1516 MaskStatic = Instance|Static,
1520 MaskProtection = Public|NonPublic,
1524 Constructor = 0x020,
1531 MaskType = Constructor|Event|Field|Method|Property|NestedType
1534 protected class CacheEntry {
1535 public readonly IMemberContainer Container;
1536 public readonly EntryType EntryType;
1537 public readonly MemberInfo Member;
1539 public CacheEntry (IMemberContainer container, MemberInfo member,
1540 MemberTypes mt, BindingFlags bf)
1542 this.Container = container;
1543 this.Member = member;
1544 this.EntryType = GetEntryType (mt, bf);
1547 public override string ToString ()
1549 return String.Format ("CacheEntry ({0}:{1}:{2})", Container.Name,
1555 /// This is called each time we're walking up one level in the class hierarchy
1556 /// and checks whether we can abort the search since we've already found what
1557 /// we were looking for.
1559 protected bool DoneSearching (ArrayList list)
1562 // We've found exactly one member in the current class and it's not
1563 // a method or constructor.
1565 if (list.Count == 1 && !(list [0] is MethodBase))
1569 // Multiple properties: we query those just to find out the indexer
1572 if ((list.Count > 0) && (list [0] is PropertyInfo))
1579 /// Looks up members with name `name'. If you provide an optional
1580 /// filter function, it'll only be called with members matching the
1581 /// requested member name.
1583 /// This method will try to use the cache to do the lookup if possible.
1585 /// Unlike other FindMembers implementations, this method will always
1586 /// check all inherited members - even when called on an interface type.
1588 /// If you know that you're only looking for methods, you should use
1589 /// MemberTypes.Method alone since this speeds up the lookup a bit.
1590 /// When doing a method-only search, it'll try to use a special method
1591 /// cache (unless it's a dynamic type or an interface) and the returned
1592 /// MemberInfo's will have the correct ReflectedType for inherited methods.
1593 /// The lookup process will automatically restart itself in method-only
1594 /// search mode if it discovers that it's about to return methods.
1596 ArrayList global = new ArrayList ();
1597 bool using_global = false;
1599 static MemberInfo [] emptyMemberInfo = new MemberInfo [0];
1601 public MemberInfo [] FindMembers (MemberTypes mt, BindingFlags bf, string name,
1602 MemberFilter filter, object criteria)
1605 throw new Exception ();
1607 bool declared_only = (bf & BindingFlags.DeclaredOnly) != 0;
1608 bool method_search = mt == MemberTypes.Method;
1609 // If we have a method cache and we aren't already doing a method-only search,
1610 // then we restart a method search if the first match is a method.
1611 bool do_method_search = !method_search && (method_hash != null);
1613 ArrayList applicable;
1615 // If this is a method-only search, we try to use the method cache if
1616 // possible; a lookup in the method cache will return a MemberInfo with
1617 // the correct ReflectedType for inherited methods.
1619 if (method_search && (method_hash != null))
1620 applicable = (ArrayList) method_hash [name];
1622 applicable = (ArrayList) member_hash [name];
1624 if (applicable == null)
1625 return emptyMemberInfo;
1628 // 32 slots gives 53 rss/54 size
1629 // 2/4 slots gives 55 rss
1631 // Strange: from 25,000 calls, only 1,800
1632 // are above 2. Why does this impact it?
1635 using_global = true;
1637 Timer.StartTimer (TimerType.CachedLookup);
1639 EntryType type = GetEntryType (mt, bf);
1641 IMemberContainer current = Container;
1644 // `applicable' is a list of all members with the given member name `name'
1645 // in the current class and all its base classes. The list is sorted in
1646 // reverse order due to the way how the cache is initialy created (to speed
1647 // things up, we're doing a deep-copy of our base).
1649 for (int i = applicable.Count-1; i >= 0; i--) {
1650 CacheEntry entry = (CacheEntry) applicable [i];
1652 // This happens each time we're walking one level up in the class
1653 // hierarchy. If we're doing a DeclaredOnly search, we must abort
1654 // the first time this happens (this may already happen in the first
1655 // iteration of this loop if there are no members with the name we're
1656 // looking for in the current class).
1657 if (entry.Container != current) {
1658 if (declared_only || DoneSearching (global))
1661 current = entry.Container;
1664 // Is the member of the correct type ?
1665 if ((entry.EntryType & type & EntryType.MaskType) == 0)
1668 // Is the member static/non-static ?
1669 if ((entry.EntryType & type & EntryType.MaskStatic) == 0)
1672 // Apply the filter to it.
1673 if (filter (entry.Member, criteria)) {
1674 if ((entry.EntryType & EntryType.MaskType) != EntryType.Method)
1675 do_method_search = false;
1676 global.Add (entry.Member);
1680 Timer.StopTimer (TimerType.CachedLookup);
1682 // If we have a method cache and we aren't already doing a method-only
1683 // search, we restart in method-only search mode if the first match is
1684 // a method. This ensures that we return a MemberInfo with the correct
1685 // ReflectedType for inherited methods.
1686 if (do_method_search && (global.Count > 0)){
1687 using_global = false;
1689 return FindMembers (MemberTypes.Method, bf, name, filter, criteria);
1692 using_global = false;
1693 MemberInfo [] copy = new MemberInfo [global.Count];
1694 global.CopyTo (copy);
1698 // find the nested type @name in @this.
1699 public Type FindNestedType (string name)
1701 ArrayList applicable = (ArrayList) member_hash [name];
1702 if (applicable == null)
1705 for (int i = applicable.Count-1; i >= 0; i--) {
1706 CacheEntry entry = (CacheEntry) applicable [i];
1707 if ((entry.EntryType & EntryType.NestedType & EntryType.MaskType) != 0)
1708 return (Type) entry.Member;
1715 // This finds the method or property for us to override. invocationType is the type where
1716 // the override is going to be declared, name is the name of the method/property, and
1717 // paramTypes is the parameters, if any to the method or property
1719 // Because the MemberCache holds members from this class and all the base classes,
1720 // we can avoid tons of reflection stuff.
1722 public MemberInfo FindMemberToOverride (Type invocationType, string name, Type [] paramTypes, bool is_property)
1724 ArrayList applicable;
1725 if (method_hash != null && !is_property)
1726 applicable = (ArrayList) method_hash [name];
1728 applicable = (ArrayList) member_hash [name];
1730 if (applicable == null)
1733 // Walk the chain of methods, starting from the top.
1735 for (int i = applicable.Count - 1; i >= 0; i--) {
1736 CacheEntry entry = (CacheEntry) applicable [i];
1738 if ((entry.EntryType & (is_property ? (EntryType.Property | EntryType.Field) : EntryType.Method)) == 0)
1741 PropertyInfo pi = null;
1742 MethodInfo mi = null;
1743 FieldInfo fi = null;
1744 Type [] cmpAttrs = null;
1747 if ((entry.EntryType & EntryType.Field) != 0) {
1748 fi = (FieldInfo)entry.Member;
1750 // TODO: For this case we ignore member type
1751 //fb = TypeManager.GetField (fi);
1752 //cmpAttrs = new Type[] { fb.MemberType };
1754 pi = (PropertyInfo) entry.Member;
1755 cmpAttrs = TypeManager.GetArgumentTypes (pi);
1758 mi = (MethodInfo) entry.Member;
1759 cmpAttrs = TypeManager.GetArgumentTypes (mi);
1763 // TODO: Almost duplicate !
1765 switch (fi.Attributes & FieldAttributes.FieldAccessMask) {
1766 case FieldAttributes.Private:
1768 // A private method is Ok if we are a nested subtype.
1769 // The spec actually is not very clear about this, see bug 52458.
1771 if (invocationType != entry.Container.Type &
1772 TypeManager.IsNestedChildOf (invocationType, entry.Container.Type))
1776 case FieldAttributes.FamANDAssem:
1777 case FieldAttributes.Assembly:
1779 // Check for assembly methods
1781 if (mi.DeclaringType.Assembly != CodeGen.Assembly.Builder)
1785 return entry.Member;
1789 // Check the arguments
1791 if (cmpAttrs.Length != paramTypes.Length)
1794 for (int j = cmpAttrs.Length - 1; j >= 0; j --)
1795 if (paramTypes [j] != cmpAttrs [j])
1799 // get one of the methods because this has the visibility info.
1802 mi = pi.GetGetMethod (true);
1804 mi = pi.GetSetMethod (true);
1810 switch (mi.Attributes & MethodAttributes.MemberAccessMask) {
1811 case MethodAttributes.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))
1818 return entry.Member;
1821 case MethodAttributes.FamANDAssem:
1822 case MethodAttributes.Assembly:
1824 // Check for assembly methods
1826 if (mi.DeclaringType.Assembly == CodeGen.Assembly.Builder)
1827 return entry.Member;
1832 // A protected method is ok, because we are overriding.
1833 // public is always ok.
1835 return entry.Member;
1845 /// The method is looking for conflict with inherited symbols (errors CS0108, CS0109).
1846 /// We handle two cases. The first is for types without parameters (events, field, properties).
1847 /// The second are methods, indexers and this is why ignore_complex_types is here.
1848 /// The latest param is temporary hack. See DoDefineMembers method for more info.
1850 public MemberInfo FindMemberWithSameName (string name, bool ignore_complex_types, MemberInfo ignore_member)
1852 ArrayList applicable = null;
1854 if (method_hash != null)
1855 applicable = (ArrayList) method_hash [name];
1857 if (applicable != null) {
1858 for (int i = applicable.Count - 1; i >= 0; i--) {
1859 CacheEntry entry = (CacheEntry) applicable [i];
1860 if ((entry.EntryType & EntryType.Public) != 0)
1861 return entry.Member;
1865 if (member_hash == null)
1867 applicable = (ArrayList) member_hash [name];
1869 if (applicable != null) {
1870 for (int i = applicable.Count - 1; i >= 0; i--) {
1871 CacheEntry entry = (CacheEntry) applicable [i];
1872 if ((entry.EntryType & EntryType.Public) != 0 & entry.Member != ignore_member) {
1873 if (ignore_complex_types) {
1874 if ((entry.EntryType & EntryType.Method) != 0)
1877 // Does exist easier way how to detect indexer ?
1878 if ((entry.EntryType & EntryType.Property) != 0) {
1879 Type[] arg_types = TypeManager.GetArgumentTypes ((PropertyInfo)entry.Member);
1880 if (arg_types.Length > 0)
1884 return entry.Member;
1891 Hashtable locase_table;
1894 /// Builds low-case table for CLS Compliance test
1896 public Hashtable GetPublicMembers ()
1898 if (locase_table != null)
1899 return locase_table;
1901 locase_table = new Hashtable ();
1902 foreach (DictionaryEntry entry in member_hash) {
1903 ArrayList members = (ArrayList)entry.Value;
1904 for (int ii = 0; ii < members.Count; ++ii) {
1905 CacheEntry member_entry = (CacheEntry) members [ii];
1907 if ((member_entry.EntryType & EntryType.Public) == 0)
1910 // TODO: Does anyone know easier way how to detect that member is internal ?
1911 switch (member_entry.EntryType & EntryType.MaskType) {
1912 case EntryType.Constructor:
1915 case EntryType.Field:
1916 if ((((FieldInfo)member_entry.Member).Attributes & (FieldAttributes.Assembly | FieldAttributes.Public)) == FieldAttributes.Assembly)
1920 case EntryType.Method:
1921 if ((((MethodInfo)member_entry.Member).Attributes & (MethodAttributes.Assembly | MethodAttributes.Public)) == MethodAttributes.Assembly)
1925 case EntryType.Property:
1926 PropertyInfo pi = (PropertyInfo)member_entry.Member;
1927 if (pi.GetSetMethod () == null && pi.GetGetMethod () == null)
1931 case EntryType.Event:
1932 EventInfo ei = (EventInfo)member_entry.Member;
1933 MethodInfo mi = ei.GetAddMethod ();
1934 if ((mi.Attributes & (MethodAttributes.Assembly | MethodAttributes.Public)) == MethodAttributes.Assembly)
1938 string lcase = ((string)entry.Key).ToLower (System.Globalization.CultureInfo.InvariantCulture);
1939 locase_table [lcase] = member_entry.Member;
1943 return locase_table;
1946 public Hashtable Members {
1953 /// Cls compliance check whether methods or constructors parameters differing only in ref or out, or in array rank
1955 public void VerifyClsParameterConflict (ArrayList al, MethodCore method, MemberInfo this_builder)
1957 EntryType tested_type = (method is Constructor ? EntryType.Constructor : EntryType.Method) | EntryType.Public;
1959 for (int i = 0; i < al.Count; ++i) {
1960 MemberCache.CacheEntry entry = (MemberCache.CacheEntry) al [i];
1963 if (entry.Member == this_builder)
1966 if ((entry.EntryType & tested_type) != tested_type)
1969 MethodBase method_to_compare = (MethodBase)entry.Member;
1970 AttributeTester.Result result = AttributeTester.AreOverloadedMethodParamsClsCompliant (
1971 method.ParameterTypes, TypeManager.GetArgumentTypes (method_to_compare));
1973 if (result == AttributeTester.Result.Ok)
1976 IMethodData md = TypeManager.GetMethod (method_to_compare);
1978 // TODO: now we are ignoring CLSCompliance(false) on method from other assembly which is buggy.
1979 // However it is exactly what csc does.
1980 if (md != null && !md.IsClsCompliaceRequired (method.Parent))
1983 Report.SymbolRelatedToPreviousError (entry.Member);
1985 case AttributeTester.Result.RefOutArrayError:
1986 Report.Error (3006, method.Location, "Overloaded method `{0}' differing only in ref or out, or in array rank, is not CLS-compliant", method.GetSignatureForError ());
1988 case AttributeTester.Result.ArrayArrayError:
1989 Report.Error (3007, method.Location, "Overloaded method `{0}' differing only by unnamed array types is not CLS-compliant", method.GetSignatureForError ());
1993 throw new NotImplementedException (result.ToString ());