2 // decl.cs: Declaration base class for structs, classes, enums and interfaces.
4 // Author: Miguel de Icaza (miguel@gnu.org)
5 // Marek Safar (marek.safar@seznam.cz)
7 // Dual licensed under the terms of the MIT X11 or GNU GPL
9 // Copyright 2001 Ximian, Inc (http://www.ximian.com)
10 // Copyright 2004-2008 Novell, Inc
11 // Copyright 2011 Xamarin Inc
16 using System.Collections.Generic;
17 using System.Diagnostics;
19 using Mono.CompilerServices.SymbolWriter;
22 using XmlElement = System.Object;
28 using IKVM.Reflection;
29 using IKVM.Reflection.Emit;
31 using System.Reflection;
32 using System.Reflection.Emit;
35 namespace Mono.CSharp {
38 // Better name would be DottenName
40 [DebuggerDisplay ("{GetSignatureForError()}")]
41 public class MemberName
43 public static readonly MemberName Null = new MemberName ("");
45 public readonly string Name;
46 public TypeParameters TypeParameters;
47 public readonly FullNamedExpression ExplicitInterface;
48 public readonly Location Location;
50 public readonly MemberName Left;
52 public MemberName (string name)
53 : this (name, Location.Null)
56 public MemberName (string name, Location loc)
57 : this (null, name, loc)
60 public MemberName (string name, TypeParameters tparams, Location loc)
65 this.TypeParameters = tparams;
68 public MemberName (string name, TypeParameters tparams, FullNamedExpression explicitInterface, Location loc)
69 : this (name, tparams, loc)
71 this.ExplicitInterface = explicitInterface;
74 public MemberName (MemberName left, string name, Location loc)
81 public MemberName (MemberName left, string name, FullNamedExpression explicitInterface, Location loc)
82 : this (left, name, loc)
84 this.ExplicitInterface = explicitInterface;
87 public MemberName (MemberName left, MemberName right)
89 this.Name = right.Name;
90 this.Location = right.Location;
91 this.TypeParameters = right.TypeParameters;
97 return TypeParameters == null ? 0 : TypeParameters.Count;
101 public bool IsGeneric {
103 return TypeParameters != null;
107 public string Basename {
109 if (TypeParameters != null)
110 return MakeName (Name, TypeParameters);
115 public void CreateMetadataName (StringBuilder sb)
118 Left.CreateMetadataName (sb);
120 if (sb.Length != 0) {
124 sb.Append (Basename);
127 public string GetSignatureForDocumentation ()
131 if (ExplicitInterface != null)
132 s = ExplicitInterface.GetSignatureForError () + "." + s;
137 return Left.GetSignatureForDocumentation () + "." + s;
140 public string GetSignatureForError ()
142 string s = TypeParameters == null ? null : "<" + TypeParameters.GetSignatureForError () + ">";
145 if (ExplicitInterface != null)
146 s = ExplicitInterface.GetSignatureForError () + "." + s;
151 return Left.GetSignatureForError () + "." + s;
154 public override bool Equals (object other)
156 return Equals (other as MemberName);
159 public bool Equals (MemberName other)
163 if (other == null || Name != other.Name)
166 if ((TypeParameters != null) &&
167 (other.TypeParameters == null || TypeParameters.Count != other.TypeParameters.Count))
170 if ((TypeParameters == null) && (other.TypeParameters != null))
174 return other.Left == null;
176 return Left.Equals (other.Left);
179 public override int GetHashCode ()
181 int hash = Name.GetHashCode ();
182 for (MemberName n = Left; n != null; n = n.Left)
183 hash ^= n.Name.GetHashCode ();
185 if (TypeParameters != null)
186 hash ^= TypeParameters.Count << 5;
188 return hash & 0x7FFFFFFF;
191 public static string MakeName (string name, TypeParameters args)
196 return name + "`" + args.Count;
199 public static string MakeName (string name, int count)
201 return name + "`" + count;
205 public class SimpleMemberName
208 public Location Location;
210 public SimpleMemberName (string name, Location loc)
218 /// Base representation for members. This is used to keep track
219 /// of Name, Location and Modifier flags, and handling Attributes.
221 [System.Diagnostics.DebuggerDisplay ("{GetSignatureForError()}")]
222 public abstract class MemberCore : Attributable, IMemberContext, IMemberDefinition
224 string IMemberDefinition.Name {
226 return member_name.Name;
230 // Is not readonly because of IndexerName attribute
231 private MemberName member_name;
232 public MemberName MemberName {
233 get { return member_name; }
237 /// Modifier flags that the user specified in the source code
239 private Modifiers mod_flags;
240 public Modifiers ModFlags {
243 if ((value & Modifiers.COMPILER_GENERATED) != 0)
244 caching_flags = Flags.IsUsed | Flags.IsAssigned;
251 public virtual ModuleContainer Module {
253 return Parent.Module;
257 public /*readonly*/ TypeContainer Parent;
260 /// Location where this declaration happens
262 public Location Location {
263 get { return member_name.Location; }
267 /// XML documentation comment
269 protected string comment;
272 /// Represents header string for documentation comment
273 /// for each member types.
275 public abstract string DocCommentHeader { get; }
279 Obsolete_Undetected = 1, // Obsolete attribute has not been detected yet
280 Obsolete = 1 << 1, // Type has obsolete attribute
281 ClsCompliance_Undetected = 1 << 2, // CLS Compliance has not been detected yet
282 ClsCompliant = 1 << 3, // Type is CLS Compliant
283 CloseTypeCreated = 1 << 4, // Tracks whether we have Closed the type
284 HasCompliantAttribute_Undetected = 1 << 5, // Presence of CLSCompliantAttribute has not been detected
285 HasClsCompliantAttribute = 1 << 6, // Type has CLSCompliantAttribute
286 ClsCompliantAttributeFalse = 1 << 7, // Member has CLSCompliant(false)
287 Excluded_Undetected = 1 << 8, // Conditional attribute has not been detected yet
288 Excluded = 1 << 9, // Method is conditional
289 MethodOverloadsExist = 1 << 10, // Test for duplication must be performed
291 IsAssigned = 1 << 12, // Field is assigned
292 HasExplicitLayout = 1 << 13,
293 PartialDefinitionExists = 1 << 14, // Set when corresponding partial method definition exists
294 HasStructLayout = 1 << 15, // Has StructLayoutAttribute
295 HasInstanceConstructor = 1 << 16,
296 HasUserOperators = 1 << 17,
297 CanBeReused = 1 << 18,
298 InterfacesExpanded = 1 << 19
302 /// MemberCore flags at first detected then cached
304 internal Flags caching_flags;
306 public MemberCore (TypeContainer parent, MemberName name, Attributes attrs)
308 this.Parent = parent;
310 caching_flags = Flags.Obsolete_Undetected | Flags.ClsCompliance_Undetected | Flags.HasCompliantAttribute_Undetected | Flags.Excluded_Undetected;
311 AddAttributes (attrs, this);
314 protected virtual void SetMemberName (MemberName new_name)
316 member_name = new_name;
319 public virtual void Accept (StructuralVisitor visitor)
321 visitor.Visit (this);
324 protected bool CheckAbstractAndExtern (bool has_block)
326 if (Parent.PartialContainer.Kind == MemberKind.Interface)
330 if ((ModFlags & Modifiers.EXTERN) != 0) {
331 Report.Error (179, Location, "`{0}' cannot declare a body because it is marked extern",
332 GetSignatureForError ());
336 if ((ModFlags & Modifiers.ABSTRACT) != 0) {
337 Report.Error (500, Location, "`{0}' cannot declare a body because it is marked abstract",
338 GetSignatureForError ());
342 if ((ModFlags & (Modifiers.ABSTRACT | Modifiers.EXTERN | Modifiers.PARTIAL)) == 0 && !(Parent is Delegate)) {
343 if (Compiler.Settings.Version >= LanguageVersion.V_3) {
344 Property.PropertyMethod pm = this as Property.PropertyMethod;
345 if (pm is Indexer.GetIndexerMethod || pm is Indexer.SetIndexerMethod)
348 if (pm != null && pm.Property.AccessorSecond == null) {
349 Report.Error (840, Location,
350 "`{0}' must have a body because it is not marked abstract or extern. The property can be automatically implemented when you define both accessors",
351 GetSignatureForError ());
356 Report.Error (501, Location, "`{0}' must have a body because it is not marked abstract, extern, or partial",
357 GetSignatureForError ());
365 protected void CheckProtectedModifier ()
367 if ((ModFlags & Modifiers.PROTECTED) == 0)
370 if (Parent.PartialContainer.Kind == MemberKind.Struct) {
371 Report.Error (666, Location, "`{0}': Structs cannot contain protected members",
372 GetSignatureForError ());
376 if ((Parent.ModFlags & Modifiers.STATIC) != 0) {
377 Report.Error (1057, Location, "`{0}': Static classes cannot contain protected members",
378 GetSignatureForError ());
382 if ((Parent.ModFlags & Modifiers.SEALED) != 0 && (ModFlags & Modifiers.OVERRIDE) == 0 &&
383 !(this is Destructor)) {
384 Report.Warning (628, 4, Location, "`{0}': new protected member declared in sealed class",
385 GetSignatureForError ());
390 public abstract bool Define ();
392 public virtual string DocComment {
402 // Returns full member name for error message
404 public virtual string GetSignatureForError ()
406 var parent = Parent.GetSignatureForError ();
408 return member_name.GetSignatureForError ();
410 return parent + "." + member_name.GetSignatureForError ();
414 /// Base Emit method. This is also entry point for CLS-Compliant verification.
416 public virtual void Emit ()
418 if (!Compiler.Settings.VerifyClsCompliance)
421 VerifyClsCompliance ();
424 public bool IsAvailableForReuse {
426 return (caching_flags & Flags.CanBeReused) != 0;
429 caching_flags = value ? (caching_flags | Flags.CanBeReused) : (caching_flags & ~Flags.CanBeReused);
433 public bool IsCompilerGenerated {
435 if ((mod_flags & Modifiers.COMPILER_GENERATED) != 0)
438 return Parent == null ? false : Parent.IsCompilerGenerated;
442 public bool IsImported {
448 public virtual bool IsUsed {
450 return (caching_flags & Flags.IsUsed) != 0;
454 protected Report Report {
456 return Compiler.Report;
460 public void SetIsUsed ()
462 caching_flags |= Flags.IsUsed;
465 public void SetIsAssigned ()
467 caching_flags |= Flags.IsAssigned;
470 public virtual void SetConstraints (List<Constraints> constraints_list)
472 var tparams = member_name.TypeParameters;
473 if (tparams == null) {
474 Report.Error (80, Location, "Constraints are not allowed on non-generic declarations");
478 foreach (var c in constraints_list) {
479 var tp = tparams.Find (c.TypeParameter.Value);
481 Report.Error (699, c.Location, "`{0}': A constraint references nonexistent type parameter `{1}'",
482 GetSignatureForError (), c.TypeParameter.Value);
491 /// Returns instance of ObsoleteAttribute for this MemberCore
493 public virtual ObsoleteAttribute GetAttributeObsolete ()
495 if ((caching_flags & (Flags.Obsolete_Undetected | Flags.Obsolete)) == 0)
498 caching_flags &= ~Flags.Obsolete_Undetected;
500 if (OptAttributes == null)
503 Attribute obsolete_attr = OptAttributes.Search (Module.PredefinedAttributes.Obsolete);
504 if (obsolete_attr == null)
507 caching_flags |= Flags.Obsolete;
509 ObsoleteAttribute obsolete = obsolete_attr.GetObsoleteAttribute ();
510 if (obsolete == null)
517 /// Checks for ObsoleteAttribute presence. It's used for testing of all non-types elements
519 public virtual void CheckObsoleteness (Location loc)
521 ObsoleteAttribute oa = GetAttributeObsolete ();
523 AttributeTester.Report_ObsoleteMessage (oa, GetSignatureForError (), loc, Report);
527 // Checks whether the type P is as accessible as this member
529 public bool IsAccessibleAs (TypeSpec p)
532 // if M is private, its accessibility is the same as this declspace.
533 // we already know that P is accessible to T before this method, so we
536 if ((mod_flags & Modifiers.PRIVATE) != 0)
539 while (TypeManager.HasElementType (p))
540 p = TypeManager.GetElementType (p);
542 if (p.IsGenericParameter)
545 for (TypeSpec p_parent; p != null; p = p_parent) {
546 p_parent = p.DeclaringType;
549 foreach (TypeSpec t in p.TypeArguments) {
550 if (!IsAccessibleAs (t))
555 var pAccess = p.Modifiers & Modifiers.AccessibilityMask;
556 if (pAccess == Modifiers.PUBLIC)
559 bool same_access_restrictions = false;
560 for (MemberCore mc = this; !same_access_restrictions && mc != null && mc.Parent != null; mc = mc.Parent) {
561 var al = mc.ModFlags & Modifiers.AccessibilityMask;
563 case Modifiers.INTERNAL:
564 if (al == Modifiers.PRIVATE || al == Modifiers.INTERNAL)
565 same_access_restrictions = p.MemberDefinition.IsInternalAsPublic (mc.Module.DeclaringAssembly);
569 case Modifiers.PROTECTED:
570 if (al == Modifiers.PROTECTED) {
571 same_access_restrictions = mc.Parent.PartialContainer.IsBaseTypeDefinition (p_parent);
575 if (al == Modifiers.PRIVATE) {
577 // When type is private and any of its parents derives from
578 // protected type then the type is accessible
580 while (mc.Parent != null && mc.Parent.PartialContainer != null) {
581 if (mc.Parent.PartialContainer.IsBaseTypeDefinition (p_parent))
582 same_access_restrictions = true;
589 case Modifiers.PROTECTED | Modifiers.INTERNAL:
590 if (al == Modifiers.INTERNAL)
591 same_access_restrictions = p.MemberDefinition.IsInternalAsPublic (mc.Module.DeclaringAssembly);
592 else if (al == (Modifiers.PROTECTED | Modifiers.INTERNAL))
593 same_access_restrictions = mc.Parent.PartialContainer.IsBaseTypeDefinition (p_parent) && p.MemberDefinition.IsInternalAsPublic (mc.Module.DeclaringAssembly);
595 goto case Modifiers.PROTECTED;
599 case Modifiers.PRIVATE:
601 // Both are private and share same parent
603 if (al == Modifiers.PRIVATE) {
604 var decl = mc.Parent;
606 same_access_restrictions = decl.CurrentType.MemberDefinition == p_parent.MemberDefinition;
607 } while (!same_access_restrictions && !decl.PartialContainer.IsTopLevel && (decl = decl.Parent) != null);
613 throw new InternalErrorException (al.ToString ());
617 if (!same_access_restrictions)
625 /// Analyze whether CLS-Compliant verification must be execute for this MemberCore.
627 public override bool IsClsComplianceRequired ()
629 if ((caching_flags & Flags.ClsCompliance_Undetected) == 0)
630 return (caching_flags & Flags.ClsCompliant) != 0;
632 caching_flags &= ~Flags.ClsCompliance_Undetected;
634 if (HasClsCompliantAttribute) {
635 if ((caching_flags & Flags.ClsCompliantAttributeFalse) != 0)
638 caching_flags |= Flags.ClsCompliant;
642 if (Parent.IsClsComplianceRequired ()) {
643 caching_flags |= Flags.ClsCompliant;
650 public virtual string[] ConditionalConditions ()
656 /// Returns true when MemberCore is exposed from assembly.
658 public bool IsExposedFromAssembly ()
660 if ((ModFlags & (Modifiers.PUBLIC | Modifiers.PROTECTED)) == 0)
661 return this is NamespaceContainer;
663 var parentContainer = Parent.PartialContainer;
664 while (parentContainer != null) {
665 if ((parentContainer.ModFlags & (Modifiers.PUBLIC | Modifiers.PROTECTED)) == 0)
668 parentContainer = parentContainer.Parent.PartialContainer;
675 // Does extension methods look up to find a method which matches name and extensionType.
676 // Search starts from this namespace and continues hierarchically up to top level.
678 public ExtensionMethodCandidates LookupExtensionMethod (TypeSpec extensionType, string name, int arity)
682 var ns = m as NamespaceContainer;
684 return ns.LookupExtensionMethod (this, extensionType, name, arity, 0);
692 public virtual FullNamedExpression LookupNamespaceAlias (string name)
694 return Parent.LookupNamespaceAlias (name);
697 public virtual FullNamedExpression LookupNamespaceOrType (string name, int arity, LookupMode mode, Location loc)
699 return Parent.LookupNamespaceOrType (name, arity, mode, loc);
703 /// Goes through class hierarchy and gets value of first found CLSCompliantAttribute.
704 /// If no is attribute exists then assembly CLSCompliantAttribute is returned.
706 public bool? CLSAttributeValue {
708 if ((caching_flags & Flags.HasCompliantAttribute_Undetected) == 0) {
709 if ((caching_flags & Flags.HasClsCompliantAttribute) == 0)
712 return (caching_flags & Flags.ClsCompliantAttributeFalse) == 0;
715 caching_flags &= ~Flags.HasCompliantAttribute_Undetected;
717 if (OptAttributes != null) {
718 Attribute cls_attribute = OptAttributes.Search (Module.PredefinedAttributes.CLSCompliant);
719 if (cls_attribute != null) {
720 caching_flags |= Flags.HasClsCompliantAttribute;
721 if (cls_attribute.GetClsCompliantAttributeValue ())
724 caching_flags |= Flags.ClsCompliantAttributeFalse;
734 /// Returns true if MemberCore is explicitly marked with CLSCompliantAttribute
736 protected bool HasClsCompliantAttribute {
738 return CLSAttributeValue.HasValue;
743 /// Returns true when a member supports multiple overloads (methods, indexers, etc)
745 public virtual bool EnableOverloadChecks (MemberCore overload)
751 /// The main virtual method for CLS-Compliant verifications.
752 /// The method returns true if member is CLS-Compliant and false if member is not
753 /// CLS-Compliant which means that CLS-Compliant tests are not necessary. A descendants override it
754 /// and add their extra verifications.
756 protected virtual bool VerifyClsCompliance ()
758 if (HasClsCompliantAttribute) {
759 if (!Module.DeclaringAssembly.HasCLSCompliantAttribute) {
760 Attribute a = OptAttributes.Search (Module.PredefinedAttributes.CLSCompliant);
761 if ((caching_flags & Flags.ClsCompliantAttributeFalse) != 0) {
762 Report.Warning (3021, 2, a.Location,
763 "`{0}' does not need a CLSCompliant attribute because the assembly is not marked as CLS-compliant",
764 GetSignatureForError ());
766 Report.Warning (3014, 1, a.Location,
767 "`{0}' cannot be marked as CLS-compliant because the assembly is not marked as CLS-compliant",
768 GetSignatureForError ());
773 if (!IsExposedFromAssembly ()) {
774 Attribute a = OptAttributes.Search (Module.PredefinedAttributes.CLSCompliant);
775 Report.Warning (3019, 2, a.Location, "CLS compliance checking will not be performed on `{0}' because it is not visible from outside this assembly", GetSignatureForError ());
779 if ((caching_flags & Flags.ClsCompliantAttributeFalse) != 0) {
780 if (Parent is Interface && Parent.IsClsComplianceRequired ()) {
781 Report.Warning (3010, 1, Location, "`{0}': CLS-compliant interfaces must have only CLS-compliant members", GetSignatureForError ());
782 } else if (Parent.Kind == MemberKind.Class && (ModFlags & Modifiers.ABSTRACT) != 0 && Parent.IsClsComplianceRequired ()) {
783 Report.Warning (3011, 1, Location, "`{0}': only CLS-compliant members can be abstract", GetSignatureForError ());
789 if (Parent.Kind != MemberKind.Namespace && Parent.Kind != 0 && !Parent.IsClsComplianceRequired ()) {
790 Attribute a = OptAttributes.Search (Module.PredefinedAttributes.CLSCompliant);
791 Report.Warning (3018, 1, a.Location, "`{0}' cannot be marked as CLS-compliant because it is a member of non CLS-compliant type `{1}'",
792 GetSignatureForError (), Parent.GetSignatureForError ());
796 if (!IsExposedFromAssembly ())
799 if (!Parent.IsClsComplianceRequired ())
803 if (member_name.Name [0] == '_') {
804 Warning_IdentifierNotCompliant ();
807 if (member_name.TypeParameters != null)
808 member_name.TypeParameters.VerifyClsCompliance ();
813 protected void Warning_IdentifierNotCompliant ()
815 Report.Warning (3008, 1, MemberName.Location, "Identifier `{0}' is not CLS-compliant", GetSignatureForError ());
818 public virtual string GetCallerMemberName ()
820 return MemberName.Name;
824 // Returns a string that represents the signature for this
825 // member which should be used in XML documentation.
827 public abstract string GetSignatureForDocumentation ();
829 public virtual void GetCompletionStartingWith (string prefix, List<string> results)
831 Parent.GetCompletionStartingWith (prefix, results);
835 // Generates xml doc comments (if any), and if required,
836 // handle warning report.
838 internal virtual void GenerateDocComment (DocumentationBuilder builder)
840 if (DocComment == null) {
841 if (IsExposedFromAssembly ()) {
842 Constructor c = this as Constructor;
843 if (c == null || !c.IsDefault ())
844 Report.Warning (1591, 4, Location,
845 "Missing XML comment for publicly visible type or member `{0}'", GetSignatureForError ());
852 builder.GenerateDocumentationForMember (this);
853 } catch (Exception e) {
854 throw new InternalErrorException (this, e);
858 public virtual void WriteDebugSymbol (MonoSymbolFile file)
862 #region IMemberContext Members
864 public virtual CompilerContext Compiler {
866 return Module.Compiler;
870 public virtual TypeSpec CurrentType {
871 get { return Parent.CurrentType; }
874 public MemberCore CurrentMemberDefinition {
878 public virtual TypeParameters CurrentTypeParameters {
882 public bool IsObsolete {
884 if (GetAttributeObsolete () != null)
887 return Parent == null ? false : Parent.IsObsolete;
891 public bool IsUnsafe {
893 if ((ModFlags & Modifiers.UNSAFE) != 0)
896 return Parent == null ? false : Parent.IsUnsafe;
900 public bool IsStatic {
902 return (ModFlags & Modifiers.STATIC) != 0;
910 // Base member specification. A member specification contains
911 // member details which can alter in the context (e.g. generic instances)
913 public abstract class MemberSpec
916 public enum StateFlags
918 Obsolete_Undetected = 1, // Obsolete attribute has not been detected yet
919 Obsolete = 1 << 1, // Member has obsolete attribute
920 CLSCompliant_Undetected = 1 << 2, // CLSCompliant attribute has not been detected yet
921 CLSCompliant = 1 << 3, // Member is CLS Compliant
922 MissingDependency_Undetected = 1 << 4,
923 MissingDependency = 1 << 5,
924 HasDynamicElement = 1 << 6,
925 ConstraintsChecked = 1 << 7,
927 IsAccessor = 1 << 9, // Method is an accessor
928 IsGeneric = 1 << 10, // Member contains type arguments
930 PendingMetaInflate = 1 << 12,
931 PendingMakeMethod = 1 << 13,
932 PendingMemberCacheMembers = 1 << 14,
933 PendingBaseTypeInflate = 1 << 15,
934 InterfacesExpanded = 1 << 16,
935 IsNotCSharpCompatible = 1 << 17,
936 SpecialRuntimeType = 1 << 18,
937 InflatedExpressionType = 1 << 19,
938 InflatedNullableType = 1 << 20,
939 GenericIterateInterface = 1 << 21,
940 GenericTask = 1 << 22,
941 InterfacesImported = 1 << 23,
945 // Some flags can be copied directly from other member
947 protected const StateFlags SharedStateFlags =
948 StateFlags.CLSCompliant | StateFlags.CLSCompliant_Undetected |
949 StateFlags.Obsolete | StateFlags.Obsolete_Undetected |
950 StateFlags.MissingDependency | StateFlags.MissingDependency_Undetected |
951 StateFlags.HasDynamicElement;
953 protected Modifiers modifiers;
954 public StateFlags state;
955 protected IMemberDefinition definition;
956 public readonly MemberKind Kind;
957 protected TypeSpec declaringType;
961 public int ID = counter++;
964 protected MemberSpec (MemberKind kind, TypeSpec declaringType, IMemberDefinition definition, Modifiers modifiers)
967 this.declaringType = declaringType;
968 this.definition = definition;
969 this.modifiers = modifiers;
971 if (kind == MemberKind.MissingType)
972 state = StateFlags.MissingDependency;
974 state = StateFlags.Obsolete_Undetected | StateFlags.CLSCompliant_Undetected | StateFlags.MissingDependency_Undetected;
979 public virtual int Arity {
985 public TypeSpec DeclaringType {
987 return declaringType;
990 declaringType = value;
994 public IMemberDefinition MemberDefinition {
1000 public Modifiers Modifiers {
1009 public virtual string Name {
1011 return definition.Name;
1015 public bool IsAbstract {
1016 get { return (modifiers & Modifiers.ABSTRACT) != 0; }
1019 public bool IsAccessor {
1021 return (state & StateFlags.IsAccessor) != 0;
1024 state = value ? state | StateFlags.IsAccessor : state & ~StateFlags.IsAccessor;
1029 // Return true when this member is a generic in C# terms
1030 // A nested non-generic type of generic type will return false
1032 public bool IsGeneric {
1034 return (state & StateFlags.IsGeneric) != 0;
1037 state = value ? state | StateFlags.IsGeneric : state & ~StateFlags.IsGeneric;
1042 // Returns true for imported members which are not compatible with C# language
1044 public bool IsNotCSharpCompatible {
1046 return (state & StateFlags.IsNotCSharpCompatible) != 0;
1049 state = value ? state | StateFlags.IsNotCSharpCompatible : state & ~StateFlags.IsNotCSharpCompatible;
1053 public bool IsPrivate {
1054 get { return (modifiers & Modifiers.PRIVATE) != 0; }
1057 public bool IsPublic {
1058 get { return (modifiers & Modifiers.PUBLIC) != 0; }
1061 public bool IsStatic {
1063 return (modifiers & Modifiers.STATIC) != 0;
1069 public virtual ObsoleteAttribute GetAttributeObsolete ()
1071 if ((state & (StateFlags.Obsolete | StateFlags.Obsolete_Undetected)) == 0)
1074 state &= ~StateFlags.Obsolete_Undetected;
1076 var oa = definition.GetAttributeObsolete ();
1078 state |= StateFlags.Obsolete;
1084 // Returns a list of missing dependencies of this member. The list
1085 // will contain types only but it can have numerous values for members
1086 // like methods where both return type and all parameters are checked
1088 public List<TypeSpec> GetMissingDependencies ()
1090 if ((state & (StateFlags.MissingDependency | StateFlags.MissingDependency_Undetected)) == 0)
1093 state &= ~StateFlags.MissingDependency_Undetected;
1095 var imported = definition as ImportedDefinition;
1096 List<TypeSpec> missing;
1097 if (imported != null) {
1098 missing = ResolveMissingDependencies ();
1099 } else if (this is ElementTypeSpec) {
1100 missing = ((ElementTypeSpec) this).Element.GetMissingDependencies ();
1105 if (missing != null) {
1106 state |= StateFlags.MissingDependency;
1112 public abstract List<TypeSpec> ResolveMissingDependencies ();
1114 protected virtual bool IsNotCLSCompliant (out bool attrValue)
1116 var cls = MemberDefinition.CLSAttributeValue;
1117 attrValue = cls ?? false;
1118 return cls == false;
1121 public virtual string GetSignatureForDocumentation ()
1123 return DeclaringType.GetSignatureForDocumentation () + "." + Name;
1126 public virtual string GetSignatureForError ()
1128 var bf = MemberDefinition as Property.BackingField;
1133 name = bf.OriginalProperty.MemberName.Name;
1136 return DeclaringType.GetSignatureForError () + "." + name;
1139 public virtual MemberSpec InflateMember (TypeParameterInflator inflator)
1141 var inflated = (MemberSpec) MemberwiseClone ();
1142 inflated.declaringType = inflator.TypeInstance;
1143 if (DeclaringType.IsGenericOrParentIsGeneric)
1144 inflated.state |= StateFlags.PendingMetaInflate;
1146 inflated.ID += 1000000;
1152 // Is this member accessible from invocation context
1154 public bool IsAccessible (IMemberContext ctx)
1156 var ma = Modifiers & Modifiers.AccessibilityMask;
1157 if (ma == Modifiers.PUBLIC)
1160 var parentType = /* this as TypeSpec ?? */ DeclaringType;
1161 var ctype = ctx.CurrentType;
1163 if (ma == Modifiers.PRIVATE) {
1167 // It's only accessible to the current class or children
1169 if (parentType.MemberDefinition == ctype.MemberDefinition)
1172 return TypeManager.IsNestedChildOf (ctype, parentType.MemberDefinition);
1175 if ((ma & Modifiers.INTERNAL) != 0) {
1177 var assembly = ctype == null ? ctx.Module.DeclaringAssembly : ctype.MemberDefinition.DeclaringAssembly;
1179 if (parentType == null) {
1180 b = ((ITypeDefinition) MemberDefinition).IsInternalAsPublic (assembly);
1182 b = DeclaringType.MemberDefinition.IsInternalAsPublic (assembly);
1185 if (b || ma == Modifiers.INTERNAL)
1190 // Checks whether `ctype' is a subclass or nested child of `parentType'.
1192 while (ctype != null) {
1193 if (TypeManager.IsFamilyAccessible (ctype, parentType))
1196 // Handle nested types.
1197 ctype = ctype.DeclaringType; // TODO: Untested ???
1204 // Returns member CLS compliance based on full member hierarchy
1206 public bool IsCLSCompliant ()
1208 if ((state & StateFlags.CLSCompliant_Undetected) != 0) {
1209 state &= ~StateFlags.CLSCompliant_Undetected;
1212 if (IsNotCLSCompliant (out compliant))
1216 if (DeclaringType != null) {
1217 compliant = DeclaringType.IsCLSCompliant ();
1219 compliant = ((ITypeDefinition) MemberDefinition).DeclaringAssembly.IsCLSCompliant;
1224 state |= StateFlags.CLSCompliant;
1227 return (state & StateFlags.CLSCompliant) != 0;
1230 public bool IsConditionallyExcluded (IMemberContext ctx, Location loc)
1232 if ((Kind & (MemberKind.Class | MemberKind.Method)) == 0)
1235 var conditions = MemberDefinition.ConditionalConditions ();
1236 if (conditions == null)
1239 var m = ctx.CurrentMemberDefinition;
1240 CompilationSourceFile unit = null;
1241 while (m != null && unit == null) {
1242 unit = m as CompilationSourceFile;
1247 foreach (var condition in conditions) {
1248 if (unit.IsConditionalDefined (condition))
1256 public override string ToString ()
1258 return GetSignatureForError ();
1263 // Member details which are same between all member
1266 public interface IMemberDefinition
1268 bool? CLSAttributeValue { get; }
1269 string Name { get; }
1270 bool IsImported { get; }
1272 string[] ConditionalConditions ();
1273 ObsoleteAttribute GetAttributeObsolete ();
1274 void SetIsAssigned ();
1278 public interface IMethodDefinition : IMemberDefinition
1280 MethodBase Metadata { get; }
1283 public interface IParametersMember : IInterfaceMemberSpec
1285 AParametersCollection Parameters { get; }
1288 public interface IInterfaceMemberSpec
1290 TypeSpec MemberType { get; }