A type parameter can never be optional.
[mono.git] / mcs / gmcs / decl.cs
index 97903704bd005f14ab6dd130da7dc7c1ea8d751c..800a622ad3e08bd69ffd748644d2270ce278f077 100755 (executable)
@@ -2,6 +2,7 @@
 // decl.cs: Declaration base class for structs, classes, enums and interfaces.
 //
 // Author: Miguel de Icaza (miguel@gnu.org)
+//         Marek Safar (marek.safar@seznam.cz)
 //
 // Licensed under the terms of the GNU GPL
 //
@@ -13,6 +14,7 @@
 using System;
 using System.Text;
 using System.Collections;
+using System.Globalization;
 using System.Reflection.Emit;
 using System.Reflection;
 
@@ -268,6 +270,9 @@ namespace Mono.CSharp {
                        HasCompliantAttribute_Undetected = 1 << 5,      // Presence of CLSCompliantAttribute has not been detected
                        HasClsCompliantAttribute = 1 << 6,                      // Type has CLSCompliantAttribute
                        ClsCompliantAttributeTrue = 1 << 7,                     // Type has CLSCompliant (true)
+                       Excluded_Undetected = 1 << 8,           // Conditional attribute has not been detected yet
+                       Excluded = 1 << 9                                       // Method is conditional
+
                }
   
                /// <summary>
@@ -281,7 +286,22 @@ namespace Mono.CSharp {
                        Name = name.GetName (!(this is GenericMethod) && !(this is Method));
                        MemberName = name;
                        Location = loc;
-                       caching_flags = Flags.Obsolete_Undetected | Flags.ClsCompliance_Undetected | Flags.HasCompliantAttribute_Undetected;
+                       caching_flags = Flags.Obsolete_Undetected | Flags.ClsCompliance_Undetected | Flags.HasCompliantAttribute_Undetected | Flags.Excluded_Undetected;
+               }
+
+               /// <summary>
+               /// Tests presence of ObsoleteAttribute and report proper error
+               /// </summary>
+               protected void CheckUsageOfObsoleteAttribute (Type type)
+               {
+                       if (type == null)
+                               return;
+
+                       ObsoleteAttribute obsolete_attr = AttributeTester.GetObsoleteAttribute (type);
+                       if (obsolete_attr == null)
+                               return;
+
+                       AttributeTester.Report_ObsoleteMessage (obsolete_attr, type.FullName, Location);
                }
 
                public abstract bool Define (TypeContainer parent);
@@ -299,6 +319,8 @@ namespace Mono.CSharp {
                /// </summary>
                public virtual void Emit (TypeContainer container)
                {
+                       VerifyObsoleteAttribute ();
+
                        if (!RootContext.VerifyClsCompliance)
                                return;
 
@@ -323,6 +345,37 @@ namespace Mono.CSharp {
                        return false;
                }
 
+               /// <summary>
+               /// Returns instance of ObsoleteAttribute for this MemberCore
+               /// </summary>
+               public ObsoleteAttribute GetObsoleteAttribute (DeclSpace ds)
+               {
+                       // ((flags & (Flags.Obsolete_Undetected | Flags.Obsolete)) == 0) is slower, but why ?
+                       if ((caching_flags & Flags.Obsolete_Undetected) == 0 && (caching_flags & Flags.Obsolete) == 0) {
+                               return null;
+                       }
+
+                       caching_flags &= ~Flags.Obsolete_Undetected;
+
+                       if (OptAttributes == null)
+                               return null;
+
+                       // TODO: remove this allocation
+                       EmitContext ec = new EmitContext (ds.Parent, ds, ds.Location,
+                               null, null, ds.ModFlags, false);
+
+                       Attribute obsolete_attr = OptAttributes.Search (TypeManager.obsolete_attribute_type, ec);
+                       if (obsolete_attr == null)
+                               return null;
+
+                       ObsoleteAttribute obsolete = obsolete_attr.GetObsoleteAttribute (ds);
+                       if (obsolete == null)
+                               return null;
+
+                       caching_flags |= Flags.Obsolete;
+                       return obsolete;
+               }
+
                /// <summary>
                /// Analyze whether CLS-Compliant verification must be execute for this MemberCore.
                /// </summary>
@@ -484,6 +537,8 @@ namespace Mono.CSharp {
                        return true;
                }
 
+               protected abstract void VerifyObsoleteAttribute ();
+
        }
 
        /// <summary>
@@ -542,6 +597,8 @@ namespace Mono.CSharp {
 
                TypeContainer parent;
 
+               static string[] attribute_targets = new string [] { "type" };
+
                public DeclSpace (NamespaceEntry ns, TypeContainer parent, MemberName name,
                                  Attributes attrs, Location l)
                        : base (name, attrs, l)
@@ -777,8 +834,7 @@ namespace Mono.CSharp {
                public Type ResolveType (TypeExpr d, Location loc)
                {
                        if (!d.CheckAccessLevel (this)) {
-                               Report. Error (122, loc,  "`" + d.Name + "' " +
-                                      "is inaccessible because of its protection level");
+                               Report.Error_T (122, loc, d.Name);
                                return null;
                        }
 
@@ -1247,6 +1303,19 @@ namespace Mono.CSharp {
                                if (t != null)
                                        return t;
 
+                               if (name.IndexOf ('.') > 0)
+                                       continue;
+
+                               IAlias alias_value = ns.LookupAlias (name);
+                               if (alias_value != null) {
+                                       t = LookupInterfaceOrClass ("", alias_value.Name, out error);
+                                       if (error)
+                                               return null;
+
+                                       if (t != null)
+                                               return t;
+                               }
+
                                //
                                // Now check the using clause list
                                //
@@ -1361,7 +1430,7 @@ namespace Mono.CSharp {
                                        if (l != type_name.Length)
                                                continue;
 
-                                       if (String.Compare (Name, type_name, true) == 0 && 
+                                       if (String.Compare (Name, type_name, true, CultureInfo.InvariantCulture) == 0 && 
                                                AttributeTester.IsClsCompliant (TypeManager.all_imported_types [type_name] as Type)) {
                                                Report.SymbolRelatedToPreviousError ((Type)TypeManager.all_imported_types [type_name]);
                                                return false;
@@ -1374,7 +1443,7 @@ namespace Mono.CSharp {
                                if (l != name.Length)
                                        continue;
 
-                               if (String.Compare (Name, name, true) == 0) { 
+                               if (String.Compare (Name, name, true, CultureInfo.InvariantCulture) == 0) { 
 
                                        if (Name == name)
                                                continue;
@@ -1572,6 +1641,12 @@ namespace Mono.CSharp {
                                return new TypeExpression (TypeBuilder, Location);
                        }
                }
+
+               protected override string[] ValidAttributeTargets {
+                       get {
+                               return attribute_targets;
+                       }
+               }
        }
 
        /// <summary>