2005-10-24 Martin Baulig <martin@ximian.com>
[mono.git] / mcs / gmcs / decl.cs
index 186293cd2f020fd86f3f7f7d2336ed94288b8d6e..fe647854fb71d8ac13d3bd75f2e60a140cf2abc3 100644 (file)
@@ -382,21 +382,6 @@ namespace Mono.CSharp {
                        cached_name = null;
                }
 
-               /// <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 ();
 
                // 
@@ -415,16 +400,19 @@ namespace Mono.CSharp {
                /// </summary>
                public virtual void Emit ()
                {
-                       // Hack with Parent == null is for EnumMember
-                       if (Parent == null || (GetObsoleteAttribute (Parent) == null && Parent.GetObsoleteAttribute (Parent) == null))
-                               VerifyObsoleteAttribute ();
-
                        if (!RootContext.VerifyClsCompliance)
                                return;
 
                        VerifyClsCompliance (Parent);
                }
 
+               public virtual EmitContext EmitContext
+               {
+                       get {
+                               return Parent.EmitContext;
+                       }
+               }
+
                public bool InUnsafe {
                        get {
                                return ((ModFlags & Modifiers.UNSAFE) != 0) || Parent.UnsafeContext;
@@ -463,7 +451,7 @@ namespace Mono.CSharp {
                /// <summary>
                /// Returns instance of ObsoleteAttribute for this MemberCore
                /// </summary>
-               public ObsoleteAttribute GetObsoleteAttribute (DeclSpace ds)
+               public virtual ObsoleteAttribute GetObsoleteAttribute ()
                {
                        // ((flags & (Flags.Obsolete_Undetected | Flags.Obsolete)) == 0) is slower, but why ?
                        if ((caching_flags & Flags.Obsolete_Undetected) == 0 && (caching_flags & Flags.Obsolete) == 0) {
@@ -476,11 +464,11 @@ namespace Mono.CSharp {
                                return null;
 
                        Attribute obsolete_attr = OptAttributes.Search (
-                               TypeManager.obsolete_attribute_type, ds.EmitContext);
+                               TypeManager.obsolete_attribute_type, EmitContext);
                        if (obsolete_attr == null)
                                return null;
 
-                       ObsoleteAttribute obsolete = obsolete_attr.GetObsoleteAttribute (ds.EmitContext);
+                       ObsoleteAttribute obsolete = obsolete_attr.GetObsoleteAttribute (EmitContext);
                        if (obsolete == null)
                                return null;
 
@@ -491,9 +479,12 @@ namespace Mono.CSharp {
                /// <summary>
                /// Checks for ObsoleteAttribute presence. It's used for testing of all non-types elements
                /// </summary>
-               public void CheckObsoleteness (Location loc)
+               public virtual void CheckObsoleteness (Location loc)
                {
-                       ObsoleteAttribute oa = GetObsoleteAttribute (Parent);
+                       if (Parent != null)
+                               Parent.CheckObsoleteness (loc);
+
+                       ObsoleteAttribute oa = GetObsoleteAttribute ();
                        if (oa == null) {
                                return;
                        }
@@ -501,6 +492,18 @@ namespace Mono.CSharp {
                        AttributeTester.Report_ObsoleteMessage (oa, GetSignatureForError (), loc);
                }
 
+               protected void CheckObsoleteType (Expression type)
+               {
+                       ObsoleteAttribute obsolete_attr = AttributeTester.GetObsoleteAttribute (type.Type);
+                       if (obsolete_attr == null)
+                               return;
+
+                       if (GetObsoleteAttribute () != null || Parent.GetObsoleteAttribute () != null)
+                               return;
+
+                       AttributeTester.Report_ObsoleteMessage (obsolete_attr, TypeManager.CSharpName (type.Type), type.Location);
+               }
+
                /// <summary>
                /// Analyze whether CLS-Compliant verification must be execute for this MemberCore.
                /// </summary>
@@ -602,8 +605,6 @@ namespace Mono.CSharp {
                        return true;
                }
 
-               protected abstract void VerifyObsoleteAttribute ();
-
                //
                // Raised (and passed an XmlElement that contains the comment)
                // when GenerateDocComment is writing documentation expectedly.
@@ -675,8 +676,10 @@ namespace Mono.CSharp {
                // The emit context for toplevel objects.
                protected EmitContext ec;
                
-               public EmitContext EmitContext {
-                       get { return ec; }
+               public override EmitContext EmitContext {
+                       get {
+                               return ec;
+                       }
                }
 
                //
@@ -715,7 +718,7 @@ namespace Mono.CSharp {
                /// </summary>
                protected bool AddToContainer (MemberCore symbol, string name)
                {
-                       if (name == Basename && !(this is Interface) && !(this is Enum)) {
+                       if (name == MemberName.Name && !(this is Interface) && !(this is Enum)) {
                                if (symbol is TypeParameter)
                                        Report.Error (694, symbol.Location,
                                                      "Type parameter `{0}' has same name as " +
@@ -869,13 +872,9 @@ namespace Mono.CSharp {
                protected TypeExpr ResolveBaseTypeExpr (Expression e, bool silent, Location loc)
                {
                        TypeResolveEmitContext.loc = loc;
-                       TypeResolveEmitContext.ContainerType = TypeBuilder;
                        TypeResolveEmitContext.ResolvingTypeTree = true;
                        if (this is GenericMethod)
                                TypeResolveEmitContext.ContainerType = Parent.TypeBuilder;
-                       else
-                               TypeResolveEmitContext.ContainerType = TypeBuilder;
-
                        return e.ResolveAsTypeTerminal (TypeResolveEmitContext);
                }
                
@@ -1306,7 +1305,8 @@ namespace Mono.CSharp {
                                        }
                                }
 
-                               type_params [i] = new TypeParameter (Parent, name, constraints, Location);
+                               type_params [i] = new TypeParameter (
+                                       Parent, this, name, constraints, Location);
 
                                AddToContainer (type_params [i], name);
                        }
@@ -2110,7 +2110,7 @@ namespace Mono.CSharp {
                // Because the MemberCache holds members from this class and all the base classes,
                // we can avoid tons of reflection stuff.
                //
-               public MemberInfo FindMemberToOverride (Type invocationType, string name, Type [] paramTypes, bool is_property)
+               public MemberInfo FindMemberToOverride (Type invocationType, string name, Type [] paramTypes, GenericMethod genericMethod, bool is_property)
                {
                        ArrayList applicable;
                        if (method_hash != null && !is_property)
@@ -2186,7 +2186,20 @@ namespace Mono.CSharp {
                                        if (!TypeManager.IsEqual (paramTypes [j], cmpAttrs [j]))
                                                goto next;
                                }
-                               
+
+                               //
+                               // check generic arguments for methods
+                               //
+                               if (mi != null) {
+                                       Type [] cmpGenArgs = mi.GetGenericArguments ();
+                                       if (genericMethod != null && cmpGenArgs.Length > 0) {
+                                               if (genericMethod.TypeParameters.Length != cmpGenArgs.Length)
+                                                       goto next;
+                                       }
+                                       else if (! (genericMethod == null && cmpGenArgs.Length == 0))
+                                               goto next;
+                               }
+
                                //
                                // get one of the methods because this has the visibility info.
                                //