Need three valued bool logic for CLSAttribute value
authorMarek Safar <marek.safar@gmail.com>
Thu, 3 Feb 2011 10:25:47 +0000 (10:25 +0000)
committerMarek Safar <marek.safar@gmail.com>
Thu, 3 Feb 2011 10:27:17 +0000 (10:27 +0000)
mcs/mcs/decl.cs
mcs/mcs/generic.cs
mcs/mcs/import.cs
mcs/mcs/membercache.cs
mcs/mcs/typespec.cs
mcs/tests/test-cls-17.cs

index 9776b8dd9738e8cd9c53cab1ebcb8b517a98e4dd..1b9e4d827845ebc60647410e72336aee57e1dbfb 100644 (file)
@@ -703,26 +703,31 @@ namespace Mono.CSharp {
                /// Goes through class hierarchy and gets value of first found CLSCompliantAttribute.
                /// If no is attribute exists then assembly CLSCompliantAttribute is returned.
                /// </summary>
-               public bool IsNotCLSCompliant ()
-               {
-                       if ((caching_flags & Flags.HasCompliantAttribute_Undetected) == 0)
-                               return (caching_flags & Flags.ClsCompliantAttributeFalse) != 0;
+               public bool? CLSAttributeValue {
+                       get {
+                               if ((caching_flags & Flags.HasCompliantAttribute_Undetected) == 0) {
+                                       if ((caching_flags & Flags.HasClsCompliantAttribute) == 0)
+                                               return null;
 
-                       caching_flags &= ~Flags.HasCompliantAttribute_Undetected;
+                                       return (caching_flags & Flags.ClsCompliantAttributeFalse) == 0;
+                               }
 
-                       if (OptAttributes != null) {
-                               Attribute cls_attribute = OptAttributes.Search (Module.PredefinedAttributes.CLSCompliant);
-                               if (cls_attribute != null) {
-                                       caching_flags |= Flags.HasClsCompliantAttribute;
-                                       if (cls_attribute.GetClsCompliantAttributeValue ())
-                                               return false;
+                               caching_flags &= ~Flags.HasCompliantAttribute_Undetected;
 
-                                       caching_flags |= Flags.ClsCompliantAttributeFalse;
-                                       return true;
+                               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 false;
+                               return null;
+                       }
                }
 
                /// <summary>
@@ -730,10 +735,7 @@ namespace Mono.CSharp {
                /// </summary>
                protected bool HasClsCompliantAttribute {
                        get {
-                               if ((caching_flags & Flags.HasCompliantAttribute_Undetected) != 0)
-                                       IsNotCLSCompliant ();
-                               
-                               return (caching_flags & Flags.HasClsCompliantAttribute) != 0;
+                               return CLSAttributeValue.HasValue;
                        }
                }
 
@@ -1061,9 +1063,11 @@ namespace Mono.CSharp {
 
                public abstract List<TypeSpec> ResolveMissingDependencies ();
 
-               protected virtual bool IsNotCLSCompliant ()
+               protected virtual bool IsNotCLSCompliant (out bool attrValue)
                {
-                       return MemberDefinition.IsNotCLSCompliant ();
+                       var cls = MemberDefinition.CLSAttributeValue;
+                       attrValue = cls ?? false;
+                       return cls == false;
                }
 
                public virtual string GetSignatureForError ()
@@ -1138,14 +1142,16 @@ namespace Mono.CSharp {
                        if ((state & StateFlags.CLSCompliant_Undetected) != 0) {
                                state &= ~StateFlags.CLSCompliant_Undetected;
 
-                               if (IsNotCLSCompliant ())
+                               bool compliant;
+                               if (IsNotCLSCompliant (out compliant))
                                        return false;
 
-                               bool compliant;
-                               if (DeclaringType != null) {
-                                       compliant = DeclaringType.IsCLSCompliant ();
-                               } else {
-                                       compliant = ((ITypeDefinition) MemberDefinition).DeclaringAssembly.IsCLSCompliant;
+                               if (!compliant) {
+                                       if (DeclaringType != null) {
+                                               compliant = DeclaringType.IsCLSCompliant ();
+                                       } else {
+                                               compliant = ((ITypeDefinition) MemberDefinition).DeclaringAssembly.IsCLSCompliant;
+                                       }
                                }
 
                                if (compliant)
@@ -1184,12 +1190,12 @@ namespace Mono.CSharp {
        //
        public interface IMemberDefinition
        {
+               bool? CLSAttributeValue { get; }
                string Name { get; }
                bool IsImported { get; }
 
                string[] ConditionalConditions ();
                ObsoleteAttribute GetAttributeObsolete ();
-               bool IsNotCLSCompliant ();
                void SetIsAssigned ();
                void SetIsUsed ();
        }
index 21df6c3b2a33f1818d132f4814b71fcc80b75cd5..a4f1d43b375890ec3d183bca793a7fdb970b2ba7 100644 (file)
@@ -1503,13 +1503,13 @@ namespace Mono.CSharp {
                        return open_type.GetAttributeObsolete ();
                }
 
-               protected override bool IsNotCLSCompliant ()
+               protected override bool IsNotCLSCompliant (out bool attrValue)
                {
-                       if (base.IsNotCLSCompliant ())
+                       if (base.IsNotCLSCompliant (out attrValue))
                                return true;
 
                        foreach (var ta in TypeArguments) {
-                               if (ta.MemberDefinition.IsNotCLSCompliant ())
+                               if (ta.MemberDefinition.CLSAttributeValue == false)
                                        return true;
                        }
 
index 49ece787beb35980b036d1b844cd2fd5d7fae109..af647f15859685d861f9ec3131cb3fdd1b2ba264 100644 (file)
@@ -1169,7 +1169,7 @@ namespace Mono.CSharp
                        public ObsoleteAttribute Obsolete;
                        public string[] Conditionals;
                        public string DefaultIndexerName;
-                       public bool IsNotCLSCompliant;
+                       public bool? CLSAttributeValue;
                        public TypeSpec CoClass;
                        
                        public static AttributesBag Read (MemberInfo mi, MetadataImporter importer)
@@ -1224,7 +1224,7 @@ namespace Mono.CSharp
                                                if (bag == null)
                                                        bag = new AttributesBag ();
 
-                                               bag.IsNotCLSCompliant = !(bool) a.ConstructorArguments[0].Value;
+                                               bag.CLSAttributeValue = (bool) a.ConstructorArguments[0].Value;
                                                continue;
                                        }
 
@@ -1324,12 +1324,13 @@ namespace Mono.CSharp
                        return cattrs.Obsolete;
                }
 
-               public bool IsNotCLSCompliant ()
-               {
-                       if (cattrs == null)
-                               ReadAttributes ();
+               public bool? CLSAttributeValue {
+                       get {
+                               if (cattrs == null)
+                                       ReadAttributes ();
 
-                       return cattrs.IsNotCLSCompliant;
+                               return cattrs.CLSAttributeValue;
+                       }
                }
 
                protected void ReadAttributes ()
index 88008066a01a01707cc233420a6b9a3d45f0b2d1..d182959e2ad153cc2336db77b306544ede752ddd 100644 (file)
@@ -1115,7 +1115,7 @@ namespace Mono.CSharp {
                                        if ((name_entry.Kind & MemberKind.MaskType) == 0)
                                                continue;
 
-                                       if (name_entry.MemberDefinition.IsNotCLSCompliant ())
+                                       if (name_entry.MemberDefinition.CLSAttributeValue == false)
                                            continue;
 
                                        IParametersMember p_a = name_entry as IParametersMember;
index 5751cab61d0a501461d184523242e137786af61b..488ad0d533022d151867942012d1a54218afe15f 100644 (file)
@@ -1119,9 +1119,10 @@ namespace Mono.CSharp
                        return null;
                }
 
-               bool IMemberDefinition.IsNotCLSCompliant ()
-               {
-                       return false;
+               bool? IMemberDefinition.CLSAttributeValue {
+                       get {
+                               return null;
+                       }
                }
 
                void IMemberDefinition.SetIsAssigned ()
@@ -1252,9 +1253,10 @@ namespace Mono.CSharp
                        return Element.MemberDefinition.ConditionalConditions ();
                }
 
-               bool IMemberDefinition.IsNotCLSCompliant ()
-               {
-                       return Element.MemberDefinition.IsNotCLSCompliant ();
+               bool? IMemberDefinition.CLSAttributeValue {
+                       get {
+                               return Element.MemberDefinition.CLSAttributeValue;
+                       }
                }
 
                public void SetIsAssigned ()
index 6d62d5eb2f6947f9f2dafb687850936db6ab127b..aa0415c52c472b65303d832cae24bf8128f0c351 100644 (file)
@@ -1,10 +1,20 @@
-// This code issues CS3014 error in csc ersion 1.1
+// Compiler options: -warnaserror
+
+// This code used to issue CS3014 errors in csc version 1.1
 
 using System;
 
 [assembly: CLSCompliant(false)]
 
 [CLSCompliant(true)]
-public class Foo {
+public enum E
+{
+       Value
+}
+
+[CLSCompliant(true)]
+public class Foo
+{
+       public E e;
        public static void Main () {}
 }
\ No newline at end of file