2008-06-11 Marek Safar <marek.safar@gmail.com>
[mono.git] / mcs / mcs / decl.cs
index 129720b307cf49f9d2f50ff1c03b0b6f1c8a06e1..f98c5ae909d34127577625f819d5228ea96b7732 100644 (file)
@@ -4,10 +4,10 @@
 // Author: Miguel de Icaza (miguel@gnu.org)
 //         Marek Safar (marek.safar@seznam.cz)
 //
-// Licensed under the terms of the GNU GPL
+// Dual licensed under the terms of the MIT X11 or GNU GPL
 //
-// (C) 2001 Ximian, Inc (http://www.ximian.com)
-// (C) 2004 Novell, Inc
+// Copyright 2001 Ximian, Inc (http://www.ximian.com)
+// Copyright 2004-2008 Novell, Inc
 //
 // TODO: Move the method verification stuff from the class.cs and interface.cs here
 //
@@ -130,7 +130,7 @@ namespace Mono.CSharp {
                                return MakeName (Name, TypeArguments);
                }
 
-               public Expression GetTypeExpression ()
+               public ATypeNameExpression GetTypeExpression ()
                {
                        if (Left == null) {
                                if (TypeArguments != null)
@@ -164,11 +164,6 @@ namespace Mono.CSharp {
                        }
                }
 
-               [Obsolete ("Use GetSignatureForError ()")]
-               public string PrettyName {
-                       get { return TypeArguments == null ? Name : MethodName + "<" + TypeArguments.ToString () + ">"; }
-               }
-
                public string MethodName {
                        get {
                                string connect = is_double_colon ? "::" : ".";
@@ -181,8 +176,8 @@ namespace Mono.CSharp {
 
                // Please use this only for error reporting.   For normal uses, just use the Equals and GetHashCode methods that make
                // MemberName a proper hash key, and avoid tons of memory allocations
-               public string FullyQualifiedName {
-                       get { return TypeArguments == null ? MethodName : MethodName + "<" + TypeArguments.ToString () + ">"; }
+               string FullyQualifiedName {
+                       get { return TypeArguments == null ? MethodName : MethodName + "<" + TypeArguments.GetSignatureForError () + ">"; }
                }
 
                public string GetSignatureForError ()
@@ -886,9 +881,8 @@ namespace Mono.CSharp {
 
                public TypeContainer PartialContainer;          
 
-               readonly bool is_generic;
+               protected readonly bool is_generic;
                readonly int count_type_params;
-               readonly int count_current_type_params;
 
                //
                // Whether we are Generic
@@ -916,7 +910,7 @@ namespace Mono.CSharp {
                        PartialContainer = null;
                        if (name.TypeArguments != null) {
                                is_generic = true;
-                               count_type_params = count_current_type_params = name.TypeArguments.Count;
+                               count_type_params = name.TypeArguments.Count;
                        }
                        if (parent != null)
                                count_type_params += parent.count_type_params;
@@ -1036,10 +1030,23 @@ namespace Mono.CSharp {
                                type.GetSignatureForError ());
                }
 
+               public override void Emit ()
+               {
+#if GMCS_SOURCE
+                       if (type_params != null) {
+                               int offset = count_type_params - type_params.Length;
+                               for (int i = offset; i < type_params.Length; i++)
+                                       CurrentTypeParameters [i - offset].Emit ();
+                       }
+#endif
+
+                       base.Emit ();
+               }
+
                public override string GetSignatureForError ()
                {       
                        if (IsGeneric) {
-                               return SimpleName.RemoveGenericArity (Name) + TypeParameter.GetSignatureForError (CurrentTypeParameters);
+                               return SimpleName.RemoveGenericArity (Name) + TypeParameter.GetSignatureForError (type_params);
                        }
                        // Parent.GetSignatureForError
                        return Name;
@@ -1270,22 +1277,9 @@ namespace Mono.CSharp {
                //
                // Extensions for generics
                //
-               TypeParameter[] type_params;
+               protected TypeParameter[] type_params;
                TypeParameter[] type_param_list;
 
-               protected string GetInstantiationName ()
-               {
-                       StringBuilder sb = new StringBuilder (Name);
-                       sb.Append ("<");
-                       for (int i = 0; i < type_param_list.Length; i++) {
-                               if (i > 0)
-                                       sb.Append (",");
-                               sb.Append (type_param_list [i].Name);
-                       }
-                       sb.Append (">");
-                       return sb.ToString ();
-               }
-
                bool check_type_parameter (ArrayList list, int start, string name)
                {
                        for (int i = 0; i < start; i++) {
@@ -1408,12 +1402,12 @@ namespace Mono.CSharp {
                        get {
                                if (!IsGeneric)
                                        throw new InvalidOperationException ();
-                               if ((PartialContainer != null) && (PartialContainer != this))
-                                       return PartialContainer.CurrentTypeParameters;
-                               if (type_params != null)
-                                       return type_params;
-                               else
+
+                               // TODO: Something is seriously broken here
+                               if (type_params == null)
                                        return new TypeParameter [0];
+
+                               return type_params;
                        }
                }
 
@@ -1423,12 +1417,6 @@ namespace Mono.CSharp {
                        }
                }
 
-               public int CountCurrentTypeParameters {
-                       get {
-                               return count_current_type_params;
-                       }
-               }
-
                public TypeParameterExpr LookupGeneric (string name, Location loc)
                {
                        if (!IsGeneric)