2004-12-13 Marek Safar <marek.safar@seznam.cz>
authorMarek Safar <marek.safar@gmail.com>
Mon, 13 Dec 2004 08:19:53 +0000 (08:19 -0000)
committerMarek Safar <marek.safar@gmail.com>
Mon, 13 Dec 2004 08:19:53 +0000 (08:19 -0000)
* class.cs (TypeContainer.VerifyClsCompliance): Add error
3018 report.
(PropertyBase.VerifyClsCompliance): Add errror 3025 report.

* codegen.cs (ModuleClass.ApplyAttributeBuilder): Add error
3017 report.

* decl.cs (MemberCore.VerifyClsCompliance): Add warning 3021.

* parameter.cs (ReturnParameter.ApplyAttributeBuilder):
Add error 3023 report.
(Parameter.ApplyAttributeBuilder): Add error 3022 report.

* tree.cs (RootTypes.IsClsCompliaceRequired): Add fake
implementation.

svn path=/trunk/mcs/; revision=37687

mcs/mcs/ChangeLog
mcs/mcs/class.cs
mcs/mcs/codegen.cs
mcs/mcs/decl.cs
mcs/mcs/parameter.cs
mcs/mcs/tree.cs

index 1902c81a5995bf99f935302fc2a7bf53a11c1932..4cf745041530797855080afab333524a0af38755 100644 (file)
@@ -1,3 +1,21 @@
+2004-12-13  Marek Safar  <marek.safar@seznam.cz>
+
+       * class.cs (TypeContainer.VerifyClsCompliance): Add error
+       3018 report.
+       (PropertyBase.VerifyClsCompliance): Add errror 3025 report.
+
+       * codegen.cs (ModuleClass.ApplyAttributeBuilder): Add error
+       3017 report.
+       
+       * decl.cs (MemberCore.VerifyClsCompliance): Add warning 3021.
+
+       * parameter.cs (ReturnParameter.ApplyAttributeBuilder): 
+       Add error 3023 report.
+       (Parameter.ApplyAttributeBuilder): Add error 3022 report.
+
+       * tree.cs (RootTypes.IsClsCompliaceRequired): Add fake
+       implementation.
+
 2004-12-12  John Luke  <john.luke@gmail.com>
 
        * driver.cs (AddArgs): take -- into account when
index 193fc6f9f891384d407bbc7002713e2d1d9aedf8..83b0dedd5a2b12b171d985377f70db81868b8e57 100644 (file)
@@ -2285,6 +2285,11 @@ namespace Mono.CSharp {
                        if (base_type != null && !AttributeTester.IsClsCompliant (base_type)) {
                                Report.Error (3009, Location, "'{0}': base type '{1}' is not CLS-compliant", GetSignatureForError (), TypeManager.CSharpName (base_type));
                        }
+
+                       if (!Parent.IsClsCompliaceRequired (ds)) {
+                               Report.Error (3018, Location, "'{0}' cannot be marked as CLS-Compliant because it is a member of non CLS-Compliant type '{1}'", 
+                                       GetSignatureForError (), Parent.GetSignatureForError ());
+                       }
                        return true;
                }
 
@@ -5776,10 +5781,10 @@ namespace Mono.CSharp {
                                //
                                // Check for custom access modifier
                                //
-                                if (ModFlags == 0) {
-                                        ModFlags = method.ModFlags;
-                                        flags = method.flags;
-                                } else {
+                               if (ModFlags == 0) {
+                                       ModFlags = method.ModFlags;
+                                       flags = method.flags;
+                               } else {
                                        CheckModifiers (container, ModFlags);
                                        ModFlags |= (method.ModFlags & (~Modifiers.Accessibility));
                                        flags = Modifiers.MethodAttr (ModFlags);
@@ -5815,27 +5820,26 @@ namespace Mono.CSharp {
                        }
                        
                        void CheckModifiers (TypeContainer container, int modflags)
-                        {
-                                int flags = 0;
-                                int mflags = method.ModFlags & Modifiers.Accessibility;
-
-                                if ((mflags & Modifiers.PUBLIC) != 0) {
-                                        flags |= Modifiers.PROTECTED | Modifiers.INTERNAL | Modifiers.PRIVATE;
-                                }
-                                else if ((mflags & Modifiers.PROTECTED) != 0) {
-                                        if ((mflags & Modifiers.INTERNAL) != 0)
-                                                flags |= Modifiers.PROTECTED | Modifiers.INTERNAL;
+                       {
+                               int flags = 0;
+                               int mflags = method.ModFlags & Modifiers.Accessibility;
 
-                                        flags |= Modifiers.PRIVATE;
-                                }
-                                else if ((mflags & Modifiers.INTERNAL) != 0)
-                                        flags |= Modifiers.PRIVATE;
+                               if ((mflags & Modifiers.PUBLIC) != 0) {
+                                       flags |= Modifiers.PROTECTED | Modifiers.INTERNAL | Modifiers.PRIVATE;
+                               }
+                               else if ((mflags & Modifiers.PROTECTED) != 0) {
+                                       if ((mflags & Modifiers.INTERNAL) != 0)
+                                               flags |= Modifiers.PROTECTED | Modifiers.INTERNAL;
 
-                                if ((mflags == modflags) || (modflags & (~flags)) != 0)
-                                        Report.Error (273, Location, "{0}: accessibility modifier must be more restrictive than the property or indexer",
-                                                       GetSignatureForError (container));
-                        }
+                                       flags |= Modifiers.PRIVATE;
+                               }
+                               else if ((mflags & Modifiers.INTERNAL) != 0)
+                                       flags |= Modifiers.PRIVATE;
 
+                               if ((mflags == modflags) || (modflags & (~flags)) != 0)
+                                       Report.Error (273, Location, "{0}: accessibility modifier must be more restrictive than the property or indexer",
+                                               GetSignatureForError (container));
+                       }
                }
 
 
@@ -6039,6 +6043,17 @@ namespace Mono.CSharp {
                        Set.UpdateName (this);
                }
 
+               protected override bool VerifyClsCompliance (DeclSpace ds)
+               {
+                       if (!base.VerifyClsCompliance (ds))
+                               return false;
+
+                       if ((Get.ModFlags != ModFlags && !Get.IsDummy) || (Set.ModFlags != ModFlags && !Set.IsDummy)) {
+                               Report.Error (3025, Get.ModFlags != ModFlags ? Get.Location : Set.Location,
+                                       "CLS-compliant accessors must have the same accessibility as their property");
+                       }
+                       return true;
+               }
 
                public override string[] ValidAttributeTargets {
                        get {
index f42c572c8a2c85876197e02345dfc46790742c8d..221b2856dc4c39bc5b1357a8dc1013eb8dbb1066 100644 (file)
@@ -1054,6 +1054,7 @@ namespace Mono.CSharp {
                // TODO: make it private and move all builder based methods here
                public AssemblyBuilder Builder;
                bool is_cls_compliant;
+               public Attribute ClsCompliantAttribute;
 
                ListDictionary declarative_security;
 
@@ -1083,11 +1084,11 @@ namespace Mono.CSharp {
 
                public void ResolveClsCompliance ()
                {
-                       Attribute a = GetClsCompliantAttribute ();
-                       if (a == null)
+                       ClsCompliantAttribute = GetClsCompliantAttribute ();
+                       if (ClsCompliantAttribute == null)
                                return;
 
-                       is_cls_compliant = a.GetClsCompliantAttributeValue (null);
+                       is_cls_compliant = ClsCompliantAttribute.GetClsCompliantAttributeValue (null);
                }
 
                // fix bug #56621
@@ -1321,13 +1322,20 @@ namespace Mono.CSharp {
                                return;
                        }
                                
-                       ApplyAttributeBuilder (null, new CustomAttributeBuilder (TypeManager.unverifiable_code_ctor, new object [0]));
+                       Builder.SetCustomAttribute (new CustomAttributeBuilder (TypeManager.unverifiable_code_ctor, new object [0]));
                }
                 
                public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder customBuilder)
                {
-                       if (a != null && a.Type == TypeManager.cls_compliant_attribute_type) {
-                               Report.Warning (3012, a.Location, "You must specify the CLSCompliant attribute on the assembly, not the module, to enable CLS compliance checking");
+                       if (a.Type == TypeManager.cls_compliant_attribute_type) {
+                               if (CodeGen.Assembly.ClsCompliantAttribute == null) {
+                                       Report.Warning (3012, a.Location, "You must specify the CLSCompliant attribute on the assembly, not the module, to enable CLS compliance checking");
+                               }
+                               else if (CodeGen.Assembly.IsClsCompliant != a.GetBoolean ()) {
+                                       Report.SymbolRelatedToPreviousError (CodeGen.Assembly.ClsCompliantAttribute.Location, CodeGen.Assembly.ClsCompliantAttribute.Name);
+                                       Report.Error (3017, a.Location, "You cannot specify the CLSCompliant attribute on a module that differs from the CLSCompliant attribute on the assembly");
+                                       return;
+                               }
                        }
 
                        Builder.SetCustomAttribute (customBuilder);
index ee3a3c73fc7c040a0efac2dac0c65c54f2888a8e..0e10e35fd53887d91b26b8a61d675b40c087745c 100644 (file)
@@ -356,8 +356,11 @@ namespace Mono.CSharp {
                protected virtual bool VerifyClsCompliance (DeclSpace ds)
                {
                        if (!IsClsCompliaceRequired (ds)) {
-                               if ((RootContext.WarningLevel >= 2) && HasClsCompliantAttribute && !IsExposedFromAssembly (ds)) {
-                                       Report.Warning (3019, Location, "CLS compliance checking will not be performed on '{0}' because it is private or internal", GetSignatureForError ());
+                               if (HasClsCompliantAttribute && RootContext.WarningLevel >= 2) {
+                                       if (!IsExposedFromAssembly (ds))
+                                               Report.Warning (3019, Location, "CLS compliance checking will not be performed on '{0}' because it is private or internal", GetSignatureForError ());
+                                       if (!CodeGen.Assembly.IsClsCompliant)
+                                               Report.Warning (3021, Location, "'{0}' does not need a CLSCompliant attribute because the assembly does not have a CLSCompliant attribute", GetSignatureForError ());
                                }
                                return false;
                        }
index e05a90e6d723119bf91ca1a86d80a7dfdea10900..b65095461ffc7e025b008cb577377c3e0a5bee61 100644 (file)
@@ -69,6 +69,10 @@ namespace Mono.CSharp {
 
                public override void ApplyAttributeBuilder(Attribute a, CustomAttributeBuilder cb)
                {
+                       if (a.Type == TypeManager.cls_compliant_attribute_type) {
+                               Report.Warning (3023, 1, a.Location, "CLSCompliant attribute has no meaning when applied to return types. Try putting it on the method instead");
+                       }
+
                        // This occurs after Warning -28
                        if (builder == null)
                                return;
@@ -157,6 +161,11 @@ namespace Mono.CSharp {
                                Report.Error (674, a.Location, "Do not use 'System.ParamArrayAttribute'. Use the 'params' keyword instead");
                                return;
                        }
+
+                       if (a.Type == TypeManager.cls_compliant_attribute_type) {
+                               Report.Warning (3022, 1, a.Location, "CLSCompliant attribute has no meaning when applied to parameters. Try putting it on the method instead");
+                       }
+
                        base.ApplyAttributeBuilder (a, cb);
                }
 
index 194ce9b694d747aff184502a032b86edea51a05c..ad3423754ea6366d2519f09e2dd8e04c8161139d 100644 (file)
@@ -126,5 +126,11 @@ namespace Mono.CSharp
                {
                        throw new InvalidOperationException ();
                }
+
+               public override bool IsClsCompliaceRequired (DeclSpace ds)
+               {
+                       return true;
+               }
+
        }
 }