//
using System;
-using System.Text;
using System.Collections.Generic;
-using System.Globalization;
-using System.Reflection.Emit;
-using System.Reflection;
#if NET_2_1
using XmlElement = System.Object;
using System.Xml;
#endif
+#if STATIC
+using IKVM.Reflection;
+using IKVM.Reflection.Emit;
+#else
+using System.Reflection;
+using System.Reflection.Emit;
+#endif
+
namespace Mono.CSharp {
//
//
public class MemberName {
public readonly string Name;
- public readonly TypeArguments TypeArguments;
+ public TypeArguments TypeArguments;
public readonly MemberName Left;
public readonly Location Location;
return GetName (false);
}
+ public int Arity {
+ get {
+ return TypeArguments == null ? 0 : TypeArguments.Count;
+ }
+ }
+
public bool IsGeneric {
get {
if (TypeArguments != null)
{
if (Left == null) {
if (TypeArguments != null)
- return new SimpleName (Basename, TypeArguments, Location);
+ return new SimpleName (Name, TypeArguments, Location);
return new SimpleName (Name, Location);
}
/// Base representation for members. This is used to keep track
/// of Name, Location and Modifier flags, and handling Attributes.
/// </summary>
+ [System.Diagnostics.DebuggerDisplay ("{GetSignatureForError()}")]
public abstract class MemberCore : Attributable, IMemberContext, IMemberDefinition
{
/// <summary>
}
}
+ string IMemberDefinition.Name {
+ get {
+ return member_name.Name;
+ }
+ }
+
// Is not readonly because of IndexerName attribute
private MemberName member_name;
public MemberName MemberName {
}
}
- public /*readonly*/ DeclSpace Parent;
+ public virtual ModuleContainer Module {
+ get {
+ return Parent.Module;
+ }
+ }
+
+ public /*readonly*/ TypeContainer Parent;
/// <summary>
/// Location where this declaration happens
CloseTypeCreated = 1 << 4, // Tracks whether we have Closed the type
HasCompliantAttribute_Undetected = 1 << 5, // Presence of CLSCompliantAttribute has not been detected
HasClsCompliantAttribute = 1 << 6, // Type has CLSCompliantAttribute
- ClsCompliantAttributeTrue = 1 << 7, // Type has CLSCompliant (true)
+ ClsCompliantAttributeFalse = 1 << 7, // Member has CLSCompliant(false)
Excluded_Undetected = 1 << 8, // Conditional attribute has not been detected yet
Excluded = 1 << 9, // Method is conditional
MethodOverloadsExist = 1 << 10, // Test for duplication must be performed
public MemberCore (DeclSpace parent, MemberName name, Attributes attrs)
{
- this.Parent = parent;
+ this.Parent = parent as TypeContainer;
member_name = name;
caching_flags = Flags.Obsolete_Undetected | Flags.ClsCompliance_Undetected | Flags.HasCompliantAttribute_Undetected | Flags.Excluded_Undetected;
AddAttributes (attrs, this);
if (pm is Indexer.GetIndexerMethod || pm is Indexer.SetIndexerMethod)
pm = null;
- if (pm != null && (pm.Property.Get.IsDummy || pm.Property.Set.IsDummy)) {
+ if (pm != null && pm.Property.AccessorSecond == null) {
Report.Error (840, Location,
"`{0}' must have a body because it is not marked abstract or extern. The property can be automatically implemented when you define both accessors",
GetSignatureForError ());
if (!RootContext.VerifyClsCompliance)
return;
- if (Report.WarningLevel > 0)
- VerifyClsCompliance ();
+ VerifyClsCompliance ();
}
public bool IsCompilerGenerated {
}
}
+ public bool IsImported {
+ get {
+ return false;
+ }
+ }
+
public virtual bool IsUsed {
- get { return (caching_flags & Flags.IsUsed) != 0; }
+ get {
+ return (caching_flags & Flags.IsUsed) != 0;
+ }
}
protected Report Report {
caching_flags |= Flags.IsUsed;
}
+ public void SetIsAssigned ()
+ {
+ caching_flags |= Flags.IsAssigned;
+ }
+
/// <summary>
/// Returns instance of ObsoleteAttribute for this MemberCore
/// </summary>
- public virtual ObsoleteAttribute GetObsoleteAttribute ()
+ public virtual ObsoleteAttribute GetAttributeObsolete ()
{
if ((caching_flags & (Flags.Obsolete_Undetected | Flags.Obsolete)) == 0)
return null;
if (OptAttributes == null)
return null;
- Attribute obsolete_attr = OptAttributes.Search (PredefinedAttributes.Get.Obsolete);
+ Attribute obsolete_attr = OptAttributes.Search (Module.PredefinedAttributes.Obsolete);
if (obsolete_attr == null)
return null;
/// </summary>
public virtual void CheckObsoleteness (Location loc)
{
- ObsoleteAttribute oa = GetObsoleteAttribute ();
+ ObsoleteAttribute oa = GetAttributeObsolete ();
if (oa != null)
AttributeTester.Report_ObsoleteMessage (oa, GetSignatureForError (), loc, Report);
}
- //
- // Returns the access level for type `t'
- //
- static Modifiers GetAccessLevelFromType (Type type)
- {
- var ma = type.Attributes;
- Modifiers mod;
- switch (ma & TypeAttributes.VisibilityMask) {
- case TypeAttributes.Public:
- case TypeAttributes.NestedPublic:
- mod = Modifiers.PUBLIC;
- break;
- case TypeAttributes.NestedPrivate:
- mod = Modifiers.PRIVATE;
- break;
- case TypeAttributes.NestedFamily:
- mod = Modifiers.PROTECTED;
- break;
- case TypeAttributes.NestedFamORAssem:
- mod = Modifiers.PROTECTED | Modifiers.INTERNAL;
- break;
- default:
- mod = Modifiers.INTERNAL;
- break;
- }
-
- return mod;
- }
-
//
// Checks whether the type P is as accessible as this member
//
- public bool IsAccessibleAs (Type p)
+ public bool IsAccessibleAs (TypeSpec p)
{
//
// if M is private, its accessibility is the same as this declspace.
while (TypeManager.HasElementType (p))
p = TypeManager.GetElementType (p);
- if (TypeManager.IsGenericParameter (p))
+ if (p.IsGenericParameter)
return true;
- if (TypeManager.IsGenericType (p)) {
- foreach (Type t in TypeManager.GetTypeArguments (p)) {
- if (!IsAccessibleAs (t))
- return false;
+ for (TypeSpec p_parent; p != null; p = p_parent) {
+ p_parent = p.DeclaringType;
+
+ if (p.IsGeneric) {
+ foreach (TypeSpec t in p.TypeArguments) {
+ if (!IsAccessibleAs (t))
+ return false;
+ }
}
- }
- for (Type p_parent = null; p != null; p = p_parent) {
- p_parent = p.DeclaringType;
- var pAccess = GetAccessLevelFromType (p);
+ var pAccess = p.Modifiers & Modifiers.AccessibilityMask;
if (pAccess == Modifiers.PUBLIC)
continue;
switch (pAccess) {
case Modifiers.INTERNAL:
if (al == Modifiers.PRIVATE || al == Modifiers.INTERNAL)
- same_access_restrictions = TypeManager.IsThisOrFriendAssembly (Parent.Module.Assembly, p.Assembly);
+ same_access_restrictions = p.MemberDefinition.IsInternalAsPublic (mc.Module.DeclaringAssembly);
break;
case Modifiers.PROTECTED:
if (al == Modifiers.PROTECTED) {
- same_access_restrictions = mc.Parent.IsBaseType (p_parent);
+ same_access_restrictions = mc.Parent.IsBaseTypeDefinition (p_parent);
break;
}
// protected type then the type is accessible
//
while (mc.Parent != null) {
- if (mc.Parent.IsBaseType (p_parent))
+ if (mc.Parent.IsBaseTypeDefinition (p_parent))
same_access_restrictions = true;
mc = mc.Parent;
}
case Modifiers.PROTECTED | Modifiers.INTERNAL:
if (al == Modifiers.INTERNAL)
- same_access_restrictions = TypeManager.IsThisOrFriendAssembly (Parent.Module.Assembly, p.Assembly);
- else if (al == Modifiers.PROTECTED)
- same_access_restrictions = mc.Parent.IsBaseType (p_parent);
+ same_access_restrictions = p.MemberDefinition.IsInternalAsPublic (mc.Module.DeclaringAssembly);
else if (al == (Modifiers.PROTECTED | Modifiers.INTERNAL))
- same_access_restrictions = mc.Parent.IsBaseType (p_parent) &&
- TypeManager.IsThisOrFriendAssembly (Parent.Module.Assembly, p.Assembly);
+ same_access_restrictions = mc.Parent.IsBaseTypeDefinition (p_parent) && p.MemberDefinition.IsInternalAsPublic (mc.Module.DeclaringAssembly);
+ else
+ goto case Modifiers.PROTECTED;
+
break;
case Modifiers.PRIVATE:
if (al == Modifiers.PRIVATE) {
var decl = mc.Parent;
do {
- same_access_restrictions = TypeManager.IsEqual (decl.TypeBuilder, p_parent);
+ same_access_restrictions = decl.CurrentType == p_parent;
} while (!same_access_restrictions && !decl.IsTopLevel && (decl = decl.Parent) != null);
}
if ((caching_flags & Flags.ClsCompliance_Undetected) == 0)
return (caching_flags & Flags.ClsCompliant) != 0;
- if (GetClsCompliantAttributeValue () && IsExposedFromAssembly ()) {
- caching_flags &= ~Flags.ClsCompliance_Undetected;
+ caching_flags &= ~Flags.ClsCompliance_Undetected;
+
+ if (HasClsCompliantAttribute) {
+ if ((caching_flags & Flags.ClsCompliantAttributeFalse) != 0)
+ return false;
+
+ caching_flags |= Flags.ClsCompliant;
+ return true;
+ }
+
+ if (Parent.PartialContainer.IsClsComplianceRequired ()) {
caching_flags |= Flags.ClsCompliant;
return true;
}
- caching_flags &= ~Flags.ClsCompliance_Undetected;
return false;
}
+ public virtual string[] ConditionalConditions ()
+ {
+ return null;
+ }
+
/// <summary>
/// Returns true when MemberCore is exposed from assembly.
/// </summary>
if ((ModFlags & (Modifiers.PUBLIC | Modifiers.PROTECTED)) == 0)
return false;
- DeclSpace parentContainer = Parent;
+ DeclSpace parentContainer = Parent.PartialContainer;
while (parentContainer != null && parentContainer.ModFlags != 0) {
if ((parentContainer.ModFlags & (Modifiers.PUBLIC | Modifiers.PROTECTED)) == 0)
return false;
return true;
}
- public virtual ExtensionMethodGroupExpr LookupExtensionMethod (Type extensionType, string name, Location loc)
+ public virtual IList<MethodSpec> LookupExtensionMethod (TypeSpec extensionType, string name, int arity, ref NamespaceEntry scope)
{
- return Parent.LookupExtensionMethod (extensionType, name, loc);
+ return Parent.LookupExtensionMethod (extensionType, name, arity, ref scope);
}
public virtual FullNamedExpression LookupNamespaceAlias (string name)
return Parent.NamespaceEntry.LookupNamespaceAlias (name);
}
- public virtual FullNamedExpression LookupNamespaceOrType (string name, Location loc, bool ignore_cs0104)
+ public virtual FullNamedExpression LookupNamespaceOrType (string name, int arity, Location loc, bool ignore_cs0104)
{
- return Parent.LookupNamespaceOrType (name, loc, ignore_cs0104);
+ return Parent.LookupNamespaceOrType (name, arity, loc, ignore_cs0104);
}
/// <summary>
/// Goes through class hierarchy and gets value of first found CLSCompliantAttribute.
/// If no is attribute exists then assembly CLSCompliantAttribute is returned.
/// </summary>
- public virtual bool GetClsCompliantAttributeValue ()
+ public bool IsNotCLSCompliant ()
{
if ((caching_flags & Flags.HasCompliantAttribute_Undetected) == 0)
- return (caching_flags & Flags.ClsCompliantAttributeTrue) != 0;
+ return (caching_flags & Flags.ClsCompliantAttributeFalse) != 0;
caching_flags &= ~Flags.HasCompliantAttribute_Undetected;
if (OptAttributes != null) {
- Attribute cls_attribute = OptAttributes.Search (
- PredefinedAttributes.Get.CLSCompliant);
+ Attribute cls_attribute = OptAttributes.Search (Module.PredefinedAttributes.CLSCompliant);
if (cls_attribute != null) {
caching_flags |= Flags.HasClsCompliantAttribute;
- bool value = cls_attribute.GetClsCompliantAttributeValue ();
- if (value)
- caching_flags |= Flags.ClsCompliantAttributeTrue;
- return value;
+ if (cls_attribute.GetClsCompliantAttributeValue ())
+ return false;
+
+ caching_flags |= Flags.ClsCompliantAttributeFalse;
+ return true;
}
}
-
- // It's null for TypeParameter
- if (Parent == null)
- return false;
- if (Parent.GetClsCompliantAttributeValue ()) {
- caching_flags |= Flags.ClsCompliantAttributeTrue;
- return true;
- }
return false;
}
protected bool HasClsCompliantAttribute {
get {
if ((caching_flags & Flags.HasCompliantAttribute_Undetected) != 0)
- GetClsCompliantAttributeValue ();
+ IsNotCLSCompliant ();
return (caching_flags & Flags.HasClsCompliantAttribute) != 0;
}
/// </summary>
protected virtual bool VerifyClsCompliance ()
{
- if (!IsClsComplianceRequired ()) {
- if (HasClsCompliantAttribute && Report.WarningLevel >= 2) {
- if (!IsExposedFromAssembly ()) {
- Attribute a = OptAttributes.Search (PredefinedAttributes.Get.CLSCompliant);
- 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 ());
+ if (HasClsCompliantAttribute) {
+ if (!Module.DeclaringAssembly.HasCLSCompliantAttribute) {
+ Attribute a = OptAttributes.Search (Module.PredefinedAttributes.CLSCompliant);
+ if ((caching_flags & Flags.ClsCompliantAttributeFalse) != 0) {
+ Report.Warning (3021, 2, a.Location,
+ "`{0}' does not need a CLSCompliant attribute because the assembly is not marked as CLS-compliant",
+ GetSignatureForError ());
+ } else {
+ Report.Warning (3014, 1, a.Location,
+ "`{0}' cannot be marked as CLS-compliant because the assembly is not marked as CLS-compliant",
+ GetSignatureForError ());
}
+ return false;
+ }
- if (!CodeGen.Assembly.IsClsCompliant) {
- Attribute a = OptAttributes.Search (PredefinedAttributes.Get.CLSCompliant);
- Report.Warning (3021, 2, a.Location, "`{0}' does not need a CLSCompliant attribute because the assembly is not marked as CLS-compliant", GetSignatureForError ());
- }
+ if (!IsExposedFromAssembly ()) {
+ Attribute a = OptAttributes.Search (Module.PredefinedAttributes.CLSCompliant);
+ 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 ());
+ return false;
}
- return false;
- }
- if (HasClsCompliantAttribute) {
- if (CodeGen.Assembly.ClsCompliantAttribute == null && !CodeGen.Assembly.IsClsCompliant) {
- Attribute a = OptAttributes.Search (PredefinedAttributes.Get.CLSCompliant);
- Report.Warning (3014, 1, a.Location,
- "`{0}' cannot be marked as CLS-compliant because the assembly is not marked as CLS-compliant",
- GetSignatureForError ());
+ if ((caching_flags & Flags.ClsCompliantAttributeFalse) != 0) {
+ if (Parent.Kind == MemberKind.Interface && Parent.IsClsComplianceRequired ()) {
+ Report.Warning (3010, 1, Location, "`{0}': CLS-compliant interfaces must have only CLS-compliant members", GetSignatureForError ());
+ } else if (Parent.Kind == MemberKind.Class && (ModFlags & Modifiers.ABSTRACT) != 0 && Parent.IsClsComplianceRequired ()) {
+ Report.Warning (3011, 1, Location, "`{0}': only CLS-compliant members can be abstract", GetSignatureForError ());
+ }
+
return false;
}
- if (!Parent.IsClsComplianceRequired ()) {
- Attribute a = OptAttributes.Search (PredefinedAttributes.Get.CLSCompliant);
- Report.Warning (3018, 1, a.Location, "`{0}' cannot be marked as CLS-compliant because it is a member of non CLS-compliant type `{1}'",
+ if (Parent.Parent != null && !Parent.IsClsComplianceRequired ()) {
+ Attribute a = OptAttributes.Search (Module.PredefinedAttributes.CLSCompliant);
+ Report.Warning (3018, 1, a.Location, "`{0}' cannot be marked as CLS-compliant because it is a member of non CLS-compliant type `{1}'",
GetSignatureForError (), Parent.GetSignatureForError ());
return false;
}
+ } else {
+ if (!IsExposedFromAssembly ())
+ return false;
+
+ if (!Parent.PartialContainer.IsClsComplianceRequired ())
+ return false;
}
if (member_name.Name [0] == '_') {
Report.Warning (3008, 1, Location, "Identifier `{0}' is not CLS-compliant", GetSignatureForError () );
}
+
return true;
}
#region IMemberContext Members
public virtual CompilerContext Compiler {
- get { return Parent.Module.Compiler; }
+ get { return Parent.Compiler; }
}
- public virtual Type CurrentType {
+ public virtual TypeSpec CurrentType {
get { return Parent.CurrentType; }
}
- public virtual TypeContainer CurrentTypeDefinition {
- get { return Parent.CurrentTypeDefinition; }
+ public MemberCore CurrentMemberDefinition {
+ get { return this; }
}
public virtual TypeParameter[] CurrentTypeParameters {
get { return null; }
}
+ public virtual bool HasUnresolvedConstraints {
+ get { return false; }
+ }
+
public bool IsObsolete {
get {
- if (GetObsoleteAttribute () != null)
+ if (GetAttributeObsolete () != null)
return true;
return Parent == null ? false : Parent.IsObsolete;
}
public bool IsStatic {
- get { return (ModFlags & Modifiers.STATIC) != 0; }
+ get {
+ return (ModFlags & Modifiers.STATIC) != 0;
+ }
}
#endregion
public abstract class MemberSpec
{
[Flags]
- protected enum StateFlags
+ public enum StateFlags
{
Obsolete_Undetected = 1, // Obsolete attribute has not been detected yet
- Obsolete = 1 << 1 // Member has obsolete attribute
- }
-
- readonly Modifiers modifiers;
- readonly string name;
- protected StateFlags state;
+ Obsolete = 1 << 1, // Member has obsolete attribute
+ CLSCompliant_Undetected = 1 << 2, // CLSCompliant attribute has not been detected yet
+ CLSCompliant = 1 << 3, // Member is CLS Compliant
+ MissingDependency_Undetected = 1 << 4,
+ MissingDependency = 1 << 5,
+ HasDynamicElement = 1 << 6,
+
+ IsAccessor = 1 << 9, // Method is an accessor
+ IsGeneric = 1 << 10, // Member contains type arguments
+
+ PendingMetaInflate = 1 << 12,
+ PendingMakeMethod = 1 << 13,
+ PendingMemberCacheMembers = 1 << 14,
+ PendingBaseTypeInflate = 1 << 15,
+ InterfacesExpanded = 1 << 16,
+ IsNotRealProperty = 1 << 17,
+ }
+
+ protected Modifiers modifiers;
+ public StateFlags state;
protected IMemberDefinition definition;
public readonly MemberKind Kind;
+ protected TypeSpec declaringType;
- protected MemberSpec (MemberKind kind, IMemberDefinition definition, string name, Modifiers modifiers)
+#if DEBUG
+ static int counter;
+ public int ID = counter++;
+#endif
+
+ protected MemberSpec (MemberKind kind, TypeSpec declaringType, IMemberDefinition definition, Modifiers modifiers)
{
+ this.Kind = kind;
+ this.declaringType = declaringType;
this.definition = definition;
- this.name = name;
this.modifiers = modifiers;
- state = StateFlags.Obsolete_Undetected;
+ state = StateFlags.Obsolete_Undetected | StateFlags.CLSCompliant_Undetected | StateFlags.MissingDependency_Undetected;
+ }
+
+ #region Properties
+
+ public virtual int Arity {
+ get {
+ return 0;
+ }
+ }
+
+ public TypeSpec DeclaringType {
+ get {
+ return declaringType;
+ }
+ set {
+ declaringType = value;
+ }
}
- public abstract Type DeclaringType { get; }
+ public IMemberDefinition MemberDefinition {
+ get {
+ return definition;
+ }
+ }
- public ObsoleteAttribute GetObsoleteAttribute ()
+ public Modifiers Modifiers {
+ get {
+ return modifiers;
+ }
+ set {
+ modifiers = value;
+ }
+ }
+
+ public virtual string Name {
+ get {
+ return definition.Name;
+ }
+ }
+
+ public bool IsAbstract {
+ get { return (modifiers & Modifiers.ABSTRACT) != 0; }
+ }
+
+ public bool IsAccessor {
+ get {
+ return (state & StateFlags.IsAccessor) != 0;
+ }
+ set {
+ state = value ? state | StateFlags.IsAccessor : state & ~StateFlags.IsAccessor;
+ }
+ }
+
+ //
+ // Return true when this member is a generic in C# terms
+ // A nested non-generic type of generic type will return false
+ //
+ public bool IsGeneric {
+ get {
+ return (state & StateFlags.IsGeneric) != 0;
+ }
+ set {
+ state = value ? state | StateFlags.IsGeneric : state & ~StateFlags.IsGeneric;
+ }
+ }
+
+ public bool IsPrivate {
+ get { return (modifiers & Modifiers.PRIVATE) != 0; }
+ }
+
+ public bool IsPublic {
+ get { return (modifiers & Modifiers.PUBLIC) != 0; }
+ }
+
+ public bool IsStatic {
+ get {
+ return (modifiers & Modifiers.STATIC) != 0;
+ }
+ }
+
+ #endregion
+
+ public virtual ObsoleteAttribute GetAttributeObsolete ()
{
if ((state & (StateFlags.Obsolete | StateFlags.Obsolete_Undetected)) == 0)
return null;
state &= ~StateFlags.Obsolete_Undetected;
- var oa = definition.GetObsoleteAttribute ();
+ var oa = definition.GetAttributeObsolete ();
if (oa != null)
state |= StateFlags.Obsolete;
return oa;
}
- public IMemberDefinition MemberDefinition {
- get { return definition; }
+ //
+ // Returns a list of missing dependencies of this member. The list
+ // will contain types only but it can have numerous values for members
+ // like methods where both return type and all parameters are checked
+ //
+ public List<MissingType> GetMissingDependencies ()
+ {
+ if ((state & (StateFlags.MissingDependency | StateFlags.MissingDependency_Undetected)) == 0)
+ return null;
+
+ state &= ~StateFlags.MissingDependency_Undetected;
+
+ var imported = definition as ImportedDefinition;
+ List<MissingType> missing;
+ if (imported != null) {
+ missing = imported.ResolveMissingDependencies ();
+ } else if (this is ElementTypeSpec) {
+ missing = ((ElementTypeSpec) this).Element.GetMissingDependencies ();
+ } else {
+ missing = null;
+ }
+
+ if (missing != null) {
+ state |= StateFlags.MissingDependency;
+ }
+
+ return missing;
}
- public Modifiers Modifiers {
- get { return modifiers; }
+ protected virtual bool IsNotCLSCompliant ()
+ {
+ return MemberDefinition.IsNotCLSCompliant ();
}
+
+ public virtual string GetSignatureForError ()
+ {
+ var bf = MemberDefinition as Property.BackingField;
+ var name = bf == null ? Name : bf.OriginalName;
+ return DeclaringType.GetSignatureForError () + "." + name;
+ }
+
+ public virtual MemberSpec InflateMember (TypeParameterInflator inflator)
+ {
+ var inflated = (MemberSpec) MemberwiseClone ();
+ inflated.declaringType = inflator.TypeInstance;
+ if (DeclaringType.IsGenericOrParentIsGeneric)
+ inflated.state |= StateFlags.PendingMetaInflate;
+#if DEBUG
+ inflated.ID += 1000000;
+#endif
+ return inflated;
+ }
+
+ //
+ // Is this member accessible from invocationType
+ //
+ public bool IsAccessible (TypeSpec invocationType)
+ {
+ var ma = Modifiers & Modifiers.AccessibilityMask;
+ if (ma == Modifiers.PUBLIC)
+ return true;
+
+ var parentType = /* this as TypeSpec ?? */ DeclaringType;
+
+ // It's null for module context
+ if (invocationType == null)
+ invocationType = InternalType.FakeInternalType;
- public string Name {
- get { return name; }
+ //
+ // If only accessible to the current class or children
+ //
+ if (ma == Modifiers.PRIVATE)
+ return invocationType.MemberDefinition == parentType.MemberDefinition ||
+ TypeManager.IsNestedChildOf (invocationType, parentType.MemberDefinition);
+
+ if ((ma & Modifiers.INTERNAL) != 0) {
+ bool b;
+ var assembly = invocationType == InternalType.FakeInternalType ?
+ RootContext.ToplevelTypes.DeclaringAssembly :
+ invocationType.MemberDefinition.DeclaringAssembly;
+
+ if (parentType == null) {
+ b = ((ITypeDefinition) MemberDefinition).IsInternalAsPublic (assembly);
+ } else {
+ b = DeclaringType.MemberDefinition.IsInternalAsPublic (assembly);
+ }
+
+ if (b || ma == Modifiers.INTERNAL)
+ return b;
+ }
+
+ // PROTECTED
+ if (!TypeManager.IsNestedFamilyAccessible (invocationType, parentType))
+ return false;
+
+ return true;
}
- public bool IsStatic {
- get { return (modifiers & Modifiers.STATIC) != 0; }
+ //
+ // Returns member CLS compliance based on full member hierarchy
+ //
+ public bool IsCLSCompliant ()
+ {
+ if ((state & StateFlags.CLSCompliant_Undetected) != 0) {
+ state &= ~StateFlags.CLSCompliant_Undetected;
+
+ if (IsNotCLSCompliant ())
+ return false;
+
+ bool compliant;
+ if (DeclaringType != null) {
+ compliant = DeclaringType.IsCLSCompliant ();
+ } else {
+ compliant = ((ITypeDefinition) MemberDefinition).DeclaringAssembly.IsCLSCompliant;
+ }
+
+ if (compliant)
+ state |= StateFlags.CLSCompliant;
+ }
+
+ return (state & StateFlags.CLSCompliant) != 0;
+ }
+
+ public bool IsConditionallyExcluded (Location loc)
+ {
+ if ((Kind & (MemberKind.Class | MemberKind.Method)) == 0)
+ return false;
+
+ var conditions = MemberDefinition.ConditionalConditions ();
+ if (conditions == null)
+ return false;
+
+ foreach (var condition in conditions) {
+ if (loc.CompilationUnit.IsConditionalDefined (condition))
+ return false;
+ }
+
+ return true;
+ }
+
+ public override string ToString ()
+ {
+ return GetSignatureForError ();
}
}
//
public interface IMemberDefinition
{
- ObsoleteAttribute GetObsoleteAttribute ();
+ string Name { get; }
+ bool IsImported { get; }
+
+ string[] ConditionalConditions ();
+ ObsoleteAttribute GetAttributeObsolete ();
+ bool IsNotCLSCompliant ();
+ void SetIsAssigned ();
void SetIsUsed ();
}
- /// <summary>
- /// Base class for structs, classes, enumerations and interfaces.
- /// </summary>
- /// <remarks>
- /// They all create new declaration spaces. This
- /// provides the common foundation for managing those name
- /// spaces.
- /// </remarks>
+ public interface IParametersMember : IInterfaceMemberSpec
+ {
+ AParametersCollection Parameters { get; }
+ }
+
+ public interface IInterfaceMemberSpec
+ {
+ TypeSpec MemberType { get; }
+ }
+
+ //
+ // Base type container declaration. It exists to handle partial types
+ // which share same definition (PartialContainer) but have different
+ // resolve scopes
+ //
public abstract class DeclSpace : MemberCore {
/// <summary>
/// This points to the actual definition that is being
/// </summary>
public TypeBuilder TypeBuilder;
- /// <summary>
- /// If we are a generic type, this is the type we are
- /// currently defining. We need to lookup members on this
- /// instead of the TypeBuilder.
- /// </summary>
- protected Type currentType;
-
//
// This is the namespace in which this typecontainer
// was declared. We use this to resolve names.
//
public NamespaceEntry NamespaceEntry;
- private Dictionary<string, FullNamedExpression> Cache = new Dictionary<string, FullNamedExpression> ();
-
public readonly string Basename;
protected Dictionary<string, MemberCore> defined_names;
defined_names.TryGetValue (name, out mc);
return mc;
}
-
- public bool IsStaticClass {
- get { return (ModFlags & Modifiers.STATIC) != 0; }
- }
-
+
//
// root_types contains all the types. All TopLevel types
// hence have a parent that points to `root_types', that is
return false;
}
- public virtual void CloseType ()
- {
- if ((caching_flags & Flags.CloseTypeCreated) == 0){
- try {
- TypeBuilder.CreateType ();
- } catch {
- //
- // The try/catch is needed because
- // nested enumerations fail to load when they
- // are defined.
- //
- // Even if this is the right order (enumerations
- // declared after types).
- //
- // Note that this still creates the type and
- // it is possible to save it
- }
- caching_flags |= Flags.CloseTypeCreated;
- }
- }
-
protected virtual TypeAttributes TypeAttr {
get { return Module.DefaultCharSetType; }
}
/// <remarks>
/// Should be overriten by the appropriate declaration space
/// </remarks>
- public abstract TypeBuilder DefineType ();
+ public abstract void DefineType ();
protected void Error_MissingPartialModifier (MemberCore type)
{
type.GetSignatureForError ());
}
- public override void Emit ()
- {
- if (type_params != null) {
- int offset = count_type_params - type_params.Length;
- for (int i = offset; i < type_params.Length; i++)
- CurrentTypeParameters [i - offset].Emit ();
- }
-
- if ((ModFlags & Modifiers.COMPILER_GENERATED) != 0 && !Parent.IsCompilerGenerated)
- PredefinedAttributes.Get.CompilerGenerated.EmitAttribute (TypeBuilder);
-
- base.Emit ();
- }
-
public override string GetSignatureForError ()
- {
+ {
return MemberName.GetSignatureForError ();
}
- public bool CheckAccessLevel (Type check_type)
- {
- Type tb = TypeBuilder;
-
- if (this is GenericMethod) {
- tb = Parent.TypeBuilder;
-
- // FIXME: Generic container does not work with nested generic
- // anonymous method stories
- if (TypeBuilder == null)
- return true;
- }
-
- check_type = TypeManager.DropGenericTypeArguments (check_type);
- if (check_type == tb)
- return true;
-
- // TODO: When called from LocalUsingAliasEntry tb is null
- // because we are in RootDeclSpace
- if (tb == null)
- tb = typeof (RootDeclSpace);
-
- //
- // Broken Microsoft runtime, return public for arrays, no matter what
- // the accessibility is for their underlying class, and they return
- // NonPublic visibility for pointers
- //
- if (TypeManager.HasElementType (check_type))
- return CheckAccessLevel (TypeManager.GetElementType (check_type));
-
- if (TypeManager.IsGenericParameter (check_type))
- return true;
-
- TypeAttributes check_attr = check_type.Attributes & TypeAttributes.VisibilityMask;
-
- switch (check_attr){
- case TypeAttributes.Public:
- return true;
-
- case TypeAttributes.NotPublic:
- return TypeManager.IsThisOrFriendAssembly (Module.Assembly, check_type.Assembly);
-
- case TypeAttributes.NestedPublic:
- return CheckAccessLevel (check_type.DeclaringType);
-
- case TypeAttributes.NestedPrivate:
- Type declaring = check_type.DeclaringType;
- return tb == declaring || TypeManager.IsNestedChildOf (tb, declaring);
-
- case TypeAttributes.NestedFamily:
- //
- // Only accessible to methods in current type or any subtypes
- //
- return FamilyAccessible (tb, check_type);
-
- case TypeAttributes.NestedFamANDAssem:
- return TypeManager.IsThisOrFriendAssembly (Module.Assembly, check_type.Assembly) &&
- FamilyAccessible (tb, check_type);
-
- case TypeAttributes.NestedFamORAssem:
- return FamilyAccessible (tb, check_type) ||
- TypeManager.IsThisOrFriendAssembly (Module.Assembly, check_type.Assembly);
-
- case TypeAttributes.NestedAssembly:
- return TypeManager.IsThisOrFriendAssembly (Module.Assembly, check_type.Assembly);
- }
-
- throw new NotImplementedException (check_attr.ToString ());
- }
-
- static bool FamilyAccessible (Type tb, Type check_type)
- {
- Type declaring = check_type.DeclaringType;
- return TypeManager.IsNestedFamilyAccessible (tb, declaring);
- }
-
- public bool IsBaseType (Type baseType)
- {
- // We are called from RootDeclspace
- if (TypeBuilder == null)
- return false;
-
- return TypeManager.IsSubclassOf (TypeBuilder, baseType);
- }
-
- private Type LookupNestedTypeInHierarchy (string name)
- {
- Type t = null;
- // if the member cache has been created, lets use it.
- // the member cache is MUCH faster.
- if (MemberCache != null) {
- t = MemberCache.FindNestedType (name);
- if (t == null)
- return null;
- }
-
- //
- // FIXME: This hack is needed because member cache does not work
- // with nested base generic types, it does only type name copy and
- // not type construction
- //
-
- // no member cache. Do it the hard way -- reflection
- for (Type current_type = TypeBuilder;
- current_type != null && current_type != TypeManager.object_type;
- current_type = current_type.BaseType) {
-
- Type ct = TypeManager.DropGenericTypeArguments (current_type);
- if (ct is TypeBuilder) {
- TypeContainer tc = ct == TypeBuilder
- ? PartialContainer : TypeManager.LookupTypeContainer (ct);
- if (tc != null)
- t = tc.FindNestedType (name);
- } else {
- t = TypeManager.GetNestedType (ct, name);
- }
-
- if ((t == null) || !CheckAccessLevel (t))
- continue;
-
- if (!TypeManager.IsGenericType (current_type))
- return t;
-
- Type[] args = TypeManager.GetTypeArguments (current_type);
- Type[] targs = TypeManager.GetTypeArguments (t);
- for (int i = 0; i < args.Length; i++)
- targs [i] = TypeManager.TypeToCoreType (args [i]);
-
- return t.MakeGenericType (targs);
- }
-
- return null;
- }
-
- //
- // Public function used to locate types.
- //
- // Set 'ignore_cs0104' to true if you want to ignore cs0104 errors.
- //
- // Returns: Type or null if they type can not be found.
- //
- public override FullNamedExpression LookupNamespaceOrType (string name, Location loc, bool ignore_cs0104)
- {
- FullNamedExpression e;
- if (Cache.TryGetValue (name, out e))
- return e;
-
- e = null;
- int errors = Report.Errors;
-
- TypeParameter[] tp = CurrentTypeParameters;
- if (tp != null) {
- TypeParameter tparam = TypeParameter.FindTypeParameter (tp, name);
- if (tparam != null)
- e = new TypeParameterExpr (tparam, Location.Null);
- }
-
- if (e == null) {
- Type t = LookupNestedTypeInHierarchy (name);
-
- if (t != null)
- e = new TypeExpression (t, Location.Null);
- else if (Parent != null)
- e = Parent.LookupNamespaceOrType (name, loc, ignore_cs0104);
- else
- e = NamespaceEntry.LookupNamespaceOrType (name, loc, ignore_cs0104);
- }
-
- if (errors == Report.Errors)
- Cache [name] = e;
-
- return e;
- }
-
- /// <remarks>
- /// This function is broken and not what you're looking for. It should only
- /// be used while the type is still being created since it doesn't use the cache
- /// and relies on the filter doing the member name check.
- /// </remarks>
- ///
- // [Obsolete ("Only MemberCache approach should be used")]
- public virtual MemberList FindMembers (MemberTypes mt, BindingFlags bf,
- MemberFilter filter, object criteria)
- {
- throw new NotSupportedException ();
- }
-
- /// <remarks>
- /// If we have a MemberCache, return it. This property may return null if the
- /// class doesn't have a member cache or while it's still being created.
- /// </remarks>
- public abstract MemberCache MemberCache {
- get;
- }
-
- public virtual ModuleContainer Module {
- get { return Parent.Module; }
- }
-
- public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb, PredefinedAttributes pa)
- {
- if (a.Type == pa.Required) {
- Report.Error (1608, a.Location, "The RequiredAttribute attribute is not permitted on C# types");
- return;
- }
- TypeBuilder.SetCustomAttribute (cb);
- }
-
TypeParameter[] initialize_type_params ()
{
if (type_param_list != null)
}
type_params [i] = new TypeParameter (
- Parent, this, name.Name, constraints, name.OptAttributes, variance, Location);
+ Parent, i, new MemberName (name.Name, Location), constraints, name.OptAttributes, variance);
AddToContainer (type_params [i], name.Name);
}
}
}
- public TypeParameter[] TypeParameters {
+ protected TypeParameter[] TypeParameters {
get {
if (!IsGeneric)
throw new InvalidOperationException ();
}
}
- public override Type CurrentType {
- get { return currentType != null ? currentType : TypeBuilder; }
- }
-
- public override TypeContainer CurrentTypeDefinition {
- get { return PartialContainer; }
- }
-
public int CountTypeParameters {
get {
return count_type_params;
}
}
- // Used for error reporting only
- public virtual Type LookupAnyGeneric (string typeName)
- {
- return NamespaceEntry.NS.LookForAnyGenericType (typeName);
- }
-
public override string[] ValidAttributeTargets {
get { return attribute_targets; }
}
if (type_params != null) {
foreach (TypeParameter tp in type_params) {
- if (tp.Constraints == null)
- continue;
-
- tp.Constraints.VerifyClsCompliance (Report);
+ tp.VerifyClsCompliance ();
}
}
- var cache = TypeManager.AllClsTopLevelTypes;
- if (cache == null)
- return true;
-
- string lcase = Name.ToLower (System.Globalization.CultureInfo.InvariantCulture);
- if (!cache.ContainsKey (lcase)) {
- cache.Add (lcase, this);
- return true;
- }
-
- object val = cache [lcase];
- if (val == null) {
- Type t = AttributeTester.GetImportedIgnoreCaseClsType (lcase);
- if (t == null)
- return true;
- Report.SymbolRelatedToPreviousError (t);
- }
- else {
- Report.SymbolRelatedToPreviousError ((DeclSpace)val);
- }
-
- Report.Warning (3005, 1, Location, "Identifier `{0}' differing only in case is not CLS-compliant", GetSignatureForError ());
return true;
}
}