Merge pull request #160 from garuma/tpl-dataflow-plumbing
[mono.git] / mcs / mcs / decl.cs
index 8a3dbae5d2bff827e6e734778a7cf64cb359dc99..27f4879aedc092fb3cb589ae8723db9d219c2fa1 100644 (file)
 //
 
 using System;
-using System.Text;
 using System.Collections.Generic;
-using System.Globalization;
-using System.Reflection.Emit;
-using System.Reflection;
+using System.Diagnostics;
 
 #if NET_2_1
 using XmlElement = System.Object;
@@ -24,14 +21,23 @@ 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 {
 
        //
        // Better name would be DottenName
        //
+       [DebuggerDisplay ("{GetSignatureForError()}")]
        public class MemberName {
                public readonly string Name;
-               public readonly TypeArguments TypeArguments;
+               public TypeArguments TypeArguments;
 
                public readonly MemberName Left;
                public readonly Location Location;
@@ -103,6 +109,12 @@ namespace Mono.CSharp {
                        return GetName (false);
                }
 
+               public int Arity {
+                       get {
+                               return TypeArguments == null ? 0 : TypeArguments.Count;
+                       }
+               }
+
                public bool IsGeneric {
                        get {
                                if (TypeArguments != null)
@@ -127,7 +139,7 @@ namespace Mono.CSharp {
                {
                        if (Left == null) {
                                if (TypeArguments != null)
-                                       return new SimpleName (Basename, TypeArguments, Location);
+                                       return new SimpleName (Name, TypeArguments, Location);
                                
                                return new SimpleName (Name, Location);
                        }
@@ -247,6 +259,7 @@ namespace Mono.CSharp {
        ///   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>
@@ -263,6 +276,12 @@ namespace Mono.CSharp {
                        }
                }
 
+               string IMemberDefinition.Name {
+                       get {
+                               return member_name.Name;
+                       }
+               }
+
                 // Is not readonly because of IndexerName attribute
                private MemberName member_name;
                public MemberName MemberName {
@@ -284,7 +303,13 @@ namespace Mono.CSharp {
                        }
                }
 
-               public /*readonly*/ DeclSpace Parent;
+               public virtual ModuleContainer Module {
+                       get {
+                               return Parent.Module;
+                       }
+               }
+
+               public /*readonly*/ TypeContainer Parent;
 
                /// <summary>
                ///   Location where this declaration happens
@@ -313,7 +338,7 @@ namespace Mono.CSharp {
                        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
@@ -331,7 +356,7 @@ namespace Mono.CSharp {
 
                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);
@@ -362,12 +387,12 @@ namespace Mono.CSharp {
                                }
                        } else {
                                if ((ModFlags & (Modifiers.ABSTRACT | Modifiers.EXTERN | Modifiers.PARTIAL)) == 0 && !(Parent is Delegate)) {
-                                       if (RootContext.Version >= LanguageVersion.V_3) {
+                                       if (Compiler.Settings.Version >= LanguageVersion.V_3) {
                                                Property.PropertyMethod pm = this as Property.PropertyMethod;
                                                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 ());
@@ -436,11 +461,10 @@ namespace Mono.CSharp {
                /// </summary>
                public virtual void Emit ()
                {
-                       if (!RootContext.VerifyClsCompliance)
+                       if (!Compiler.Settings.VerifyClsCompliance)
                                return;
 
-                       if (Report.WarningLevel > 0)
-                               VerifyClsCompliance ();
+                       VerifyClsCompliance ();
                }
 
                public bool IsCompilerGenerated {
@@ -452,8 +476,16 @@ namespace Mono.CSharp {
                        }
                }
 
+               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 {
@@ -467,10 +499,15 @@ namespace Mono.CSharp {
                        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;
@@ -480,7 +517,7 @@ namespace Mono.CSharp {
                        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;
 
@@ -498,44 +535,15 @@ namespace Mono.CSharp {
                /// </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.
@@ -548,19 +556,20 @@ namespace Mono.CSharp {
                        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;
 
@@ -570,13 +579,13 @@ namespace Mono.CSharp {
                                        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;
                                                }
 
@@ -586,7 +595,7 @@ namespace Mono.CSharp {
                                                        // 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; 
                                                        }
@@ -596,12 +605,12 @@ namespace Mono.CSharp {
 
                                        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:
@@ -611,7 +620,7 @@ namespace Mono.CSharp {
                                                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);
                                                }
                                                
@@ -637,16 +646,29 @@ namespace Mono.CSharp {
                        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>
@@ -664,9 +686,9 @@ namespace Mono.CSharp {
                        return true;
                }
 
-               public virtual ExtensionMethodGroupExpr LookupExtensionMethod (Type extensionType, string name, Location loc)
+               public virtual ExtensionMethodCandidates LookupExtensionMethod (TypeSpec extensionType, string name, int arity)
                {
-                       return Parent.LookupExtensionMethod (extensionType, name, loc);
+                       return Parent.LookupExtensionMethod (extensionType, name, arity);
                }
 
                public virtual FullNamedExpression LookupNamespaceAlias (string name)
@@ -674,43 +696,40 @@ namespace Mono.CSharp {
                        return Parent.NamespaceEntry.LookupNamespaceAlias (name);
                }
 
-               public virtual FullNamedExpression LookupNamespaceOrType (string name, Location loc, bool ignore_cs0104)
+               public virtual FullNamedExpression LookupNamespaceOrType (string name, int arity, LookupMode mode, Location loc)
                {
-                       return Parent.LookupNamespaceOrType (name, loc, ignore_cs0104);
+                       return Parent.LookupNamespaceOrType (name, arity, mode, loc);
                }
 
                /// <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 ()
-               {
-                       if ((caching_flags & Flags.HasCompliantAttribute_Undetected) == 0)
-                               return (caching_flags & Flags.ClsCompliantAttributeTrue) != 0;
-
-                       caching_flags &= ~Flags.HasCompliantAttribute_Undetected;
-
-                       if (OptAttributes != null) {
-                               Attribute cls_attribute = OptAttributes.Search (
-                                       PredefinedAttributes.Get.CLSCompliant);
-                               if (cls_attribute != null) {
-                                       caching_flags |= Flags.HasClsCompliantAttribute;
-                                       bool value = cls_attribute.GetClsCompliantAttributeValue ();
-                                       if (value)
-                                               caching_flags |= Flags.ClsCompliantAttributeTrue;
-                                       return value;
+               public bool? CLSAttributeValue {
+                       get {
+                               if ((caching_flags & Flags.HasCompliantAttribute_Undetected) == 0) {
+                                       if ((caching_flags & Flags.HasClsCompliantAttribute) == 0)
+                                               return null;
+
+                                       return (caching_flags & Flags.ClsCompliantAttributeFalse) == 0;
                                }
-                       }
-                       
-                       // It's null for TypeParameter
-                       if (Parent == null)
-                               return false;                   
 
-                       if (Parent.GetClsCompliantAttributeValue ()) {
-                               caching_flags |= Flags.ClsCompliantAttributeTrue;
-                               return true;
+                               caching_flags &= ~Flags.HasCompliantAttribute_Undetected;
+
+                               if (OptAttributes != null) {
+                                       Attribute cls_attribute = OptAttributes.Search (Module.PredefinedAttributes.CLSCompliant);
+                                       if (cls_attribute != null) {
+                                               caching_flags |= Flags.HasClsCompliantAttribute;
+                                               if (cls_attribute.GetClsCompliantAttributeValue ())
+                                                       return true;
+
+                                               caching_flags |= Flags.ClsCompliantAttributeFalse;
+                                               return false;
+                                       }
+                               }
+
+                               return null;
                        }
-                       return false;
                }
 
                /// <summary>
@@ -718,10 +737,7 @@ namespace Mono.CSharp {
                /// </summary>
                protected bool HasClsCompliantAttribute {
                        get {
-                               if ((caching_flags & Flags.HasCompliantAttribute_Undetected) != 0)
-                                       GetClsCompliantAttributeValue ();
-                               
-                               return (caching_flags & Flags.HasClsCompliantAttribute) != 0;
+                               return CLSAttributeValue.HasValue;
                        }
                }
 
@@ -741,72 +757,83 @@ namespace Mono.CSharp {
                /// </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;
-               }
 
-               //
-               // Raised (and passed an XmlElement that contains the comment)
-               // when GenerateDocComment is writing documentation expectedly.
-               //
-               internal virtual void OnGenerateDocComment (XmlElement intermediateNode)
-               {
+                       return true;
                }
 
                //
                // Returns a string that represents the signature for this 
                // member which should be used in XML documentation.
                //
-               public virtual string GetDocCommentName (DeclSpace ds)
-               {
-                       if (ds == null || this is DeclSpace)
-                               return DocCommentHeader + Name;
-                       else
-                               return String.Concat (DocCommentHeader, ds.Name, ".", Name);
-               }
+               public abstract string GetSignatureForDocumentation ();
 
                //
                // Generates xml doc comments (if any), and if required,
                // handle warning report.
                //
-               internal virtual void GenerateDocComment (DeclSpace ds)
+               internal virtual void GenerateDocComment (DocumentationBuilder builder)
                {
+                       if (DocComment == null) {
+                               if (IsExposedFromAssembly ()) {
+                                       Constructor c = this as Constructor;
+                                       if (c == null || !c.IsDefault ())
+                                               Report.Warning (1591, 4, Location,
+                                                       "Missing XML comment for publicly visible type or member `{0}'", GetSignatureForError ());
+                               }
+
+                               return;
+                       }
+
                        try {
-                               DocUtil.GenerateDocComment (this, ds, Report);
+                               builder.GenerateDocumentationForMember (this);
                        } catch (Exception e) {
                                throw new InternalErrorException (this, e);
                        }
@@ -815,15 +842,15 @@ namespace Mono.CSharp {
                #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 {
@@ -832,7 +859,7 @@ namespace Mono.CSharp {
 
                public bool IsObsolete {
                        get {
-                               if (GetObsoleteAttribute () != null)
+                               if (GetAttributeObsolete () != null)
                                        return true;
 
                                return Parent == null ? false : Parent.IsObsolete;
@@ -849,7 +876,9 @@ namespace Mono.CSharp {
                }
 
                public bool IsStatic {
-                       get { return (ModFlags & Modifiers.STATIC) != 0; }
+                       get {
+                               return (ModFlags & Modifiers.STATIC) != 0;
+                       }
                }
 
                #endregion
@@ -862,57 +891,321 @@ namespace Mono.CSharp {
        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,
+                       ConstraintsChecked = 1 << 7,
+
+                       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,
+                       IsNotCSharpCompatible = 1 << 17,
+                       SpecialRuntimeType = 1 << 18,
+                       InflatedExpressionType = 1 << 19,
+                       InflatedNullableType = 1 << 20,
+                       GenericIterateInterface = 1 << 21,
+                       GenericTask = 1 << 22
+               }
+
+               protected Modifiers modifiers;
+               public StateFlags state;
                protected IMemberDefinition definition;
                public readonly MemberKind Kind;
+               protected TypeSpec declaringType;
+
+#if DEBUG
+               static int counter;
+               public int ID = counter++;
+#endif
 
-               protected MemberSpec (MemberKind kind, IMemberDefinition definition, string name, Modifiers modifiers)
+               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 IMemberDefinition MemberDefinition {
+                       get {
+                               return definition;
+                       }
+               }
+
+               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;
+                       }
+               }
+
+               //
+               // Returns true for imported members which are not compatible with C# language
+               //
+               public bool IsNotCSharpCompatible {
+                       get {
+                               return (state & StateFlags.IsNotCSharpCompatible) != 0;
+                       }
+                       set {
+                               state = value ? state | StateFlags.IsNotCSharpCompatible : state & ~StateFlags.IsNotCSharpCompatible;
+                       }
+               }
+
+               public bool IsPrivate {
+                       get { return (modifiers & Modifiers.PRIVATE) != 0; }
+               }
+
+               public bool IsPublic {
+                       get { return (modifiers & Modifiers.PUBLIC) != 0; }
                }
 
-               public abstract Type DeclaringType { get; }
+               public bool IsStatic {
+                       get { 
+                               return (modifiers & Modifiers.STATIC) != 0;
+                       }
+               }
 
-               public ObsoleteAttribute GetObsoleteAttribute ()
+               #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<TypeSpec> GetMissingDependencies ()
+               {
+                       if ((state & (StateFlags.MissingDependency | StateFlags.MissingDependency_Undetected)) == 0)
+                               return null;
+
+                       state &= ~StateFlags.MissingDependency_Undetected;
+
+                       var imported = definition as ImportedDefinition;
+                       List<TypeSpec> missing;
+                       if (imported != null) {
+                               missing = 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; }
+               public abstract List<TypeSpec> ResolveMissingDependencies ();
+
+               protected virtual bool IsNotCLSCompliant (out bool attrValue)
+               {
+                       var cls = MemberDefinition.CLSAttributeValue;
+                       attrValue = cls ?? false;
+                       return cls == false;
                }
-               
-               public string Name {
-                       get { return name; }
+
+               public virtual string GetSignatureForDocumentation ()
+               {
+                       return DeclaringType.GetSignatureForDocumentation () + "." + Name;
                }
 
-               public bool IsStatic {
-                       get { return (modifiers & Modifiers.STATIC) != 0; }
+               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 invocation context
+               //
+               public bool IsAccessible (IMemberContext ctx)
+               {
+                       var ma = Modifiers & Modifiers.AccessibilityMask;
+                       if (ma == Modifiers.PUBLIC)
+                               return true;
+
+                       var parentType = /* this as TypeSpec ?? */ DeclaringType;
+                       var ctype = ctx.CurrentType;
+
+                       if (ma == Modifiers.PRIVATE) {
+                               if (ctype == null)
+                                       return false;
+                               //
+                               // It's only accessible to the current class or children
+                               //
+                               if (parentType.MemberDefinition == ctype.MemberDefinition)
+                                       return true;
+
+                               return TypeManager.IsNestedChildOf (ctype, parentType.MemberDefinition);
+                       }
+
+                       if ((ma & Modifiers.INTERNAL) != 0) {
+                               bool b;
+                               var assembly = ctype == null ? ctx.Module.DeclaringAssembly : ctype.MemberDefinition.DeclaringAssembly;
+
+                               if (parentType == null) {
+                                       b = ((ITypeDefinition) MemberDefinition).IsInternalAsPublic (assembly);
+                               } else {
+                                       b = DeclaringType.MemberDefinition.IsInternalAsPublic (assembly);
+                               }
+
+                               if (b || ma == Modifiers.INTERNAL)
+                                       return b;
+                       }
+
+                       //
+                       // Checks whether `ctype' is a subclass or nested child of `parentType'.
+                       //
+                       while (ctype != null) {
+                               if (TypeManager.IsFamilyAccessible (ctype, parentType))
+                                       return true;
+
+                               // Handle nested types.
+                               ctype = ctype.DeclaringType;    // TODO: Untested ???
+                       }
+
+                       return false;
+               }
+
+               //
+               // Returns member CLS compliance based on full member hierarchy
+               //
+               public bool IsCLSCompliant ()
+               {
+                       if ((state & StateFlags.CLSCompliant_Undetected) != 0) {
+                               state &= ~StateFlags.CLSCompliant_Undetected;
+
+                               bool compliant;
+                               if (IsNotCLSCompliant (out compliant))
+                                       return false;
+
+                               if (!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 (CompilerContext ctx, 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 (ctx, condition))
+                                       return false;
+                       }
+
+                       return true;
+               }
+
+               public override string ToString ()
+               {
+                       return GetSignatureForError ();
                }
        }
 
@@ -922,18 +1215,31 @@ namespace Mono.CSharp {
        //
        public interface IMemberDefinition
        {
-               ObsoleteAttribute GetObsoleteAttribute ();
+               bool? CLSAttributeValue { get; }
+               string Name { get; }
+               bool IsImported { get; }
+
+               string[] ConditionalConditions ();
+               ObsoleteAttribute GetAttributeObsolete ();
+               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
@@ -941,21 +1247,12 @@ namespace Mono.CSharp {
                /// </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;
+               public NamespaceContainer NamespaceEntry;
 
-               private Dictionary<string, FullNamedExpression> Cache = new Dictionary<string, FullNamedExpression> ();
-               
                public readonly string Basename;
                
                protected Dictionary<string, MemberCore> defined_names;
@@ -981,9 +1278,9 @@ namespace Mono.CSharp {
                        }
                }
 
-               static string[] attribute_targets = new string [] { "type" };
+               static readonly string[] attribute_targets = new string [] { "type" };
 
-               public DeclSpace (NamespaceEntry ns, DeclSpace parent, MemberName name,
+               public DeclSpace (NamespaceContainer ns, DeclSpace parent, MemberName name,
                                  Attributes attrs)
                        : base (parent, name, attrs)
                {
@@ -1026,17 +1323,13 @@ namespace Mono.CSharp {
                                return false;
                        }
 
-                       if (this is ModuleContainer) {
-                               Report.Error (101, symbol.Location, 
-                                       "The namespace `{0}' already contains a definition for `{1}'",
-                                       ((DeclSpace)symbol).NamespaceEntry.GetSignatureForError (), symbol.MemberName.Name);
-                       } else if (symbol is TypeParameter) {
+                       if (symbol is TypeParameter) {
                                Report.Error (692, symbol.Location,
                                        "Duplicate type parameter `{0}'", symbol.GetSignatureForError ());
                        } else {
                                Report.Error (102, symbol.Location,
-                                             "The type `{0}' already contains a definition for `{1}'",
-                                             GetSignatureForError (), symbol.MemberName.Name);
+                                       "The type `{0}' already contains a definition for `{1}'",
+                                       GetSignatureForError (), symbol.MemberName.Name);
                        }
 
                        return false;
@@ -1058,11 +1351,7 @@ namespace Mono.CSharp {
                        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
@@ -1077,35 +1366,12 @@ namespace Mono.CSharp {
                        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; }
-               }
+               protected abstract TypeAttributes TypeAttr { get; }
 
                /// <remarks>
                ///  Should be overriten by the appropriate declaration space
                /// </remarks>
-               public abstract TypeBuilder DefineType ();
+               public abstract void DefineType ();
 
                protected void Error_MissingPartialModifier (MemberCore type)
                {
@@ -1114,234 +1380,16 @@ namespace Mono.CSharp {
                                type.GetSignatureForError ());
                }
 
-               public override void Emit ()
+               public override string GetSignatureForDocumentation ()
                {
-                       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 ();
+                       return Name;
                }
 
                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, ConstructorInfo ctor, byte[] cdata, PredefinedAttributes pa)
-               {
-                       if (a.Type == pa.Required) {
-                               Report.Error (1608, a.Location, "The RequiredAttribute attribute is not permitted on C# types");
-                               return;
-                       }
-
-                       TypeBuilder.SetCustomAttribute (ctor, cdata);
-               }
-
                TypeParameter[] initialize_type_params ()
                {
                        if (type_param_list != null)
@@ -1427,7 +1475,7 @@ namespace Mono.CSharp {
                                }
 
                                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);
                        }
@@ -1440,7 +1488,7 @@ namespace Mono.CSharp {
                        }
                }
 
-               public TypeParameter[] TypeParameters {
+               protected TypeParameter[] TypeParameters {
                        get {
                                if (!IsGeneric)
                                        throw new InvalidOperationException ();
@@ -1453,26 +1501,12 @@ namespace Mono.CSharp {
                        }
                }
 
-               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; }
                }
@@ -1485,35 +1519,10 @@ namespace Mono.CSharp {
 
                        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;
                }
        }