2008-06-11 Marek Safar <marek.safar@gmail.com>
[mono.git] / mcs / mcs / decl.cs
index 190a3988364ef564356516bd0e19903872c366d5..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)
@@ -142,7 +142,7 @@ namespace Mono.CSharp {
                        if (is_double_colon) {
                                if (Left.Left != null)
                                        throw new InternalErrorException ("The left side of a :: should be an identifier");
-                               return new QualifiedAliasMember (Left.Name, Basename, Location);
+                               return new QualifiedAliasMember (Left.Name, Name, TypeArguments, Location);
                        }
 
                        Expression lexpr = Left.GetTypeExpression ();
@@ -164,31 +164,29 @@ namespace Mono.CSharp {
                        }
                }
 
-               public string FullName {
-                       get {
-                               if (TypeArguments != null)
-                                       return Name + "<" + TypeArguments.ToString () + ">";
-                               else
-                                       return Name;
-                       }
-               }
-
                public string MethodName {
                        get {
                                string connect = is_double_colon ? "::" : ".";
                                if (Left != null)
-                                       return Left.FullName + connect + Name;
+                                       return Left.FullyQualifiedName + connect + Name;
                                else
                                        return Name;
                        }
                }
-               
+
+               // 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
+               string FullyQualifiedName {
+                       get { return TypeArguments == null ? MethodName : MethodName + "<" + TypeArguments.GetSignatureForError () + ">"; }
+               }
+
                public string GetSignatureForError ()
                {
-                       if (TypeArguments != null)
-                               return MethodName + "<" + TypeArguments.GetSignatureForError () + ">";
-
-                       return MethodName;
+                       string append = TypeArguments == null ? "" : "<" + TypeArguments.GetSignatureForError () + ">";
+                       if (Left == null)
+                               return Name + append;
+                       string connect = is_double_colon ? "::" : ".";
+                       return Left.GetSignatureForError () + connect + Name + append;
                }
 
                public override bool Equals (object other)
@@ -883,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
@@ -913,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;
@@ -1033,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;
@@ -1201,7 +1211,7 @@ namespace Mono.CSharp {
                        return null;
                }
 
-               public virtual ExtensionMethodGroupExpr LookupExtensionMethod (Type extensionType, string name)
+               public virtual ExtensionMethodGroupExpr LookupExtensionMethod (Type extensionType, string name, Location loc)
                {
                        return null;
                }
@@ -1267,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++) {
@@ -1405,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;
                        }
                }
 
@@ -1420,12 +1417,6 @@ namespace Mono.CSharp {
                        }
                }
 
-               public int CountCurrentTypeParameters {
-                       get {
-                               return count_current_type_params;
-                       }
-               }
-
                public TypeParameterExpr LookupGeneric (string name, Location loc)
                {
                        if (!IsGeneric)