make line-endings uniform
[mono.git] / mcs / mcs / decl.cs
index 4468288f0e034863f57e27b0e9d852bbc97d7c37..6bbec398fe873cbc96eebce9830831691164c74c 100644 (file)
@@ -559,13 +559,19 @@ namespace Mono.CSharp {
                                return false;
                        }
 
-                       if (!CodeGen.Assembly.IsClsCompliant) {
-                               if (HasClsCompliantAttribute) {
+                       if (HasClsCompliantAttribute) {
+                               if (CodeGen.Assembly.ClsCompliantAttribute == null && !CodeGen.Assembly.IsClsCompliant) {
                                        Report.Error (3014, Location,
                                                "`{0}' cannot be marked as CLS-compliant because the assembly is not marked as CLS-compliant",
                                                GetSignatureForError ());
+                                       return false;
+                               }
+
+                               if (!Parent.IsClsComplianceRequired ()) {
+                                       Report.Warning (3018, 1, Location, "`{0}' cannot be marked as CLS-compliant because it is a member of non CLS-compliant type `{1}'", 
+                                               GetSignatureForError (), Parent.GetSignatureForError ());
+                                       return false;
                                }
-                               return false;
                        }
 
                        if (member_name.Name [0] == '_') {
@@ -832,7 +838,7 @@ namespace Mono.CSharp {
                public bool CheckAccessLevel (Type check_type)
                {
                        TypeBuilder tb;
-                       if ((this is GenericMethod) || (this is Iterator))
+                       if (this is GenericMethod)
                                tb = Parent.TypeBuilder;
                        else
                                tb = TypeBuilder;
@@ -847,11 +853,6 @@ namespace Mono.CSharp {
                                //        May also be null when resolving top-level attributes.
                                return true;
 
-                       if (TypeManager.IsGenericParameter (check_type))
-                               return true; // FIXME
-                       
-                       TypeAttributes check_attr = check_type.Attributes & TypeAttributes.VisibilityMask;
-
                        //
                        // Broken Microsoft runtime, return public for arrays, no matter what 
                        // the accessibility is for their underlying class, and they return 
@@ -860,6 +861,11 @@ namespace Mono.CSharp {
                        if (check_type.IsArray || check_type.IsPointer)
                                return CheckAccessLevel (TypeManager.GetElementType (check_type));
 
+                       if (TypeManager.IsGenericParameter(check_type))
+                               return true; // FIXME
+
+                       TypeAttributes check_attr = check_type.Attributes & TypeAttributes.VisibilityMask;
+
                        switch (check_attr){
                        case TypeAttributes.Public:
                                return true;
@@ -996,9 +1002,6 @@ namespace Mono.CSharp {
                //
                public bool AsAccessible (Type p, int flags)
                {
-                       if (TypeManager.IsGenericParameter (p))
-                               return true; // FIXME
-
                        //
                        // 1) if M is private, its accessability is the same as this declspace.
                        // we already know that P is accessible to T before this method, so we
@@ -1010,7 +1013,10 @@ namespace Mono.CSharp {
                        
                        while (p.IsArray || p.IsPointer || p.IsByRef)
                                p = TypeManager.GetElementType (p);
-                       
+
+                       if (TypeManager.IsGenericParameter(p))
+                               return true; // FIXME
+
                        AccessLevel pAccess = TypeEffectiveAccessLevel (p);
                        AccessLevel mAccess = this.EffectiveAccessLevel &
                                GetAccessLevelFromModifiers (flags);
@@ -1152,16 +1158,14 @@ namespace Mono.CSharp {
                                the_parent = null;
 
                        int start = 0;
-                       TypeParameter[] parent_params = null;
-                       if ((the_parent != null) && the_parent.IsGeneric) {
-                               parent_params = the_parent.initialize_type_params ();
-                               start = parent_params != null ? parent_params.Length : 0;
-                       }
-
                        ArrayList list = new ArrayList ();
-                       if (parent_params != null)
+                       if (the_parent != null && the_parent.IsGeneric) {
+                               // FIXME: move generics info out of DeclSpace
+                               TypeParameter[] parent_params = the_parent.PartialContainer.TypeParameters;
+                               start = parent_params.Length;
                                list.AddRange (parent_params);
-
+                       }
                        int count = type_params != null ? type_params.Length : 0;
                        for (int i = 0; i < count; i++) {
                                TypeParameter param = type_params [i];
@@ -1295,7 +1299,19 @@ namespace Mono.CSharp {
                                return false;
                        }
 
+                       if (type_params != null) {
+                               foreach (TypeParameter tp in type_params) {
+                                       if (tp.Constraints == null)
+                                               continue;
+
+                                       tp.Constraints.VerifyClsCompliance ();
+                               }
+                       }
+
                        IDictionary cache = TypeManager.AllClsTopLevelTypes;
+                       if (cache == null)
+                               return true;
+
                        string lcase = Name.ToLower (System.Globalization.CultureInfo.InvariantCulture);
                        if (!cache.Contains (lcase)) {
                                cache.Add (lcase, this);
@@ -2063,6 +2079,33 @@ namespace Mono.CSharp {
                        
                        return null;
                }
+
+               public MemberInfo FindBaseEvent (Type invocationType, string name)
+               {
+                       ArrayList applicable;
+                       if (method_hash != null)
+                               applicable = (ArrayList) method_hash [name];
+                       else
+                               applicable = (ArrayList) member_hash [name];
+                       
+                       if (applicable == null)
+                               return null;
+
+                       //
+                       // Walk the chain of events, starting from the top.
+                       //
+                       for (int i = applicable.Count - 1; i >= 0; i--) 
+                       {
+                               CacheEntry entry = (CacheEntry) applicable [i];
+                               if ((entry.EntryType & EntryType.Event) == 0)
+                                       continue;
+                               
+                               EventInfo ei = (EventInfo)entry.Member;
+                               return ei.GetAddMethod (true);
+                       }
+
+                       return null;
+               }
                
                //
                // This finds the method or property for us to override. invocationType is the type where
@@ -2116,24 +2159,25 @@ namespace Mono.CSharp {
                                        // TODO: Almost duplicate !
                                        // Check visibility
                                        switch (fi.Attributes & FieldAttributes.FieldAccessMask) {
-                                               case FieldAttributes.Private:
-                                                       //
-                                                       // A private method is Ok if we are a nested subtype.
-                                                       // The spec actually is not very clear about this, see bug 52458.
-                                                       //
-                                                       if (invocationType != entry.Container.Type &
-                                                               TypeManager.IsNestedChildOf (invocationType, entry.Container.Type))
-                                                               continue;
-
-                                                       break;
-                                               case FieldAttributes.FamANDAssem:
-                                               case FieldAttributes.Assembly:
-                                                       //
-                                                       // Check for assembly methods
-                                                       //
-                                                       if (mi.DeclaringType.Assembly != CodeGen.Assembly.Builder)
-                                                               continue;
-                                                       break;
+                                       case FieldAttributes.PrivateScope:
+                                               continue;
+                                       case FieldAttributes.Private:
+                                               //
+                                               // A private method is Ok if we are a nested subtype.
+                                               // The spec actually is not very clear about this, see bug 52458.
+                                               //
+                                               if (!invocationType.Equals (entry.Container.Type) &&
+                                                   !TypeManager.IsNestedChildOf (invocationType, entry.Container.Type))
+                                                       continue;
+                                               break;
+                                       case FieldAttributes.FamANDAssem:
+                                       case FieldAttributes.Assembly:
+                                               //
+                                               // Check for assembly methods
+                                               //
+                                               if (mi.DeclaringType.Assembly != CodeGen.Assembly.Builder)
+                                                       continue;
+                                               break;
                                        }
                                        return entry.Member;
                                }
@@ -2144,23 +2188,24 @@ namespace Mono.CSharp {
                                if (cmpAttrs.Length != paramTypes.Length)
                                        continue;
        
-                               for (int j = cmpAttrs.Length - 1; j >= 0; j --) {
+                               int j;
+                               for (j = 0; j < cmpAttrs.Length; ++j)
                                        if (!TypeManager.IsEqual (paramTypes [j], cmpAttrs [j]))
-                                               goto next;
-                               }
+                                               break;
+                               if (j < cmpAttrs.Length)
+                                       continue;
 
                                //
                                // check generic arguments for methods
                                //
                                if (mi != null) {
                                        Type [] cmpGenArgs = TypeManager.GetGenericArguments (mi);
-                                       if ((genericMethod != null) && (cmpGenArgs.Length > 0)) {
-                                               if (genericMethod.TypeParameters.Length != cmpGenArgs.Length)
-                                               goto next;
-                                       } else if (!((genericMethod == null) && (cmpGenArgs.Length == 0)))
-                                               goto next;
+                                       if (genericMethod == null && cmpGenArgs.Length != 0)
+                                               continue;
+                                       if (genericMethod != null && cmpGenArgs.Length != genericMethod.TypeParameters.Length)
+                                               continue;
                                }
-                               
+
                                //
                                // get one of the methods because this has the visibility info.
                                //
@@ -2174,34 +2219,27 @@ namespace Mono.CSharp {
                                // Check visibility
                                //
                                switch (mi.Attributes & MethodAttributes.MemberAccessMask) {
+                               case MethodAttributes.PrivateScope:
+                                       continue;
                                case MethodAttributes.Private:
                                        //
                                        // A private method is Ok if we are a nested subtype.
                                        // The spec actually is not very clear about this, see bug 52458.
                                        //
-                                       if (invocationType.Equals (entry.Container.Type) ||
-                                           TypeManager.IsNestedChildOf (invocationType, entry.Container.Type))
-                                               return entry.Member;
-                                       
+                                       if (!invocationType.Equals (entry.Container.Type) &&
+                                           !TypeManager.IsNestedChildOf (invocationType, entry.Container.Type))
+                                               continue;
                                        break;
                                case MethodAttributes.FamANDAssem:
                                case MethodAttributes.Assembly:
                                        //
                                        // Check for assembly methods
                                        //
-                                       if (mi.DeclaringType.Assembly == CodeGen.Assembly.Builder)
-                                               return entry.Member;
-                                       
+                                       if (mi.DeclaringType.Assembly != CodeGen.Assembly.Builder)
+                                               continue;
                                        break;
-                               default:
-                                       //
-                                       // A protected method is ok, because we are overriding.
-                                       // public is always ok.
-                                       //
-                                       return entry.Member;
                                }
-                       next:
-                               ;
+                               return entry.Member;
                        }
                        
                        return null;