[corlib] Fix tests for watchOS. (#3131)
[mono.git] / mcs / ilasm / codegen / GenericArguments.cs
index 682e374c54a208a3436ca23a095aab2b1d700e02..afefa3958483ed24dfd6af99b51cfedc8e0d81f4 100644 (file)
@@ -7,9 +7,6 @@
 // Copyright 2005 Novell, Inc (http://www.novell.com)
 //
 
-//Note: This is shared by modified types of the same generic instance
-//      Eg. foo`1<int32> and foo`1<int32> [] would share their GenericArguments
-
 using System;
 using System.Collections;
 using System.Text;
@@ -19,23 +16,27 @@ namespace Mono.ILASM {
        public class GenericArguments {
                ArrayList type_list;
                string type_str;
-               ITypeRef [] type_arr;
+               BaseTypeRef [] type_arr;
+               bool is_resolved;
+               PEAPI.Type [] p_type_list;
 
                public GenericArguments ()
                {
                        type_list = null;
                        type_arr = null;
                        type_str = null;
+                       is_resolved = false;
+                       p_type_list = null;
                }
 
                public int Count {
                        get { return type_list.Count; }
                }
 
-               public void Add (ITypeRef type)
+               public void Add (BaseTypeRef type)
                {
                        if (type == null)
-                               throw new ArgumentException ("type");
+                               throw new InternalErrorException ();
 
                        if (type_list == null)
                                type_list = new ArrayList ();
@@ -44,34 +45,49 @@ namespace Mono.ILASM {
                        type_arr = null;
                }
                
-               public ITypeRef [] ToArray ()
+               public BaseTypeRef [] ToArray ()
                {
                        if (type_list == null)
                                return null;
                        if (type_arr == null)
-                               type_arr = (ITypeRef []) type_list.ToArray (typeof (ITypeRef));
+                               type_arr = (BaseTypeRef []) type_list.ToArray (typeof (BaseTypeRef));
 
                        return type_arr;
                }
 
                public PEAPI.Type [] Resolve (CodeGen code_gen)
                {
+                       if (is_resolved)
+                               return p_type_list;
+
                        int i = 0;
-                       PEAPI.Type [] p_type_list = new PEAPI.Type [type_list.Count];
-                       foreach (ITypeRef type in type_list) {
+                       p_type_list = new PEAPI.Type [type_list.Count];
+                       foreach (BaseTypeRef type in type_list) {
                                type.Resolve (code_gen);
                                p_type_list [i ++] = type.PeapiType;
                        }
-
+                       is_resolved = true;
+                       type_str = null;
                        return p_type_list;
                }
 
+               public void Resolve (GenericParameters type_gen_params, GenericParameters method_gen_params)
+               {
+                       foreach (BaseTypeRef type in type_list) {
+                               BaseGenericTypeRef gtr = type as BaseGenericTypeRef;
+                               if (gtr != null)
+                                       gtr.Resolve (type_gen_params, method_gen_params);
+                       }
+                       /* Reset, might have changed (think GenericParamRef) */
+                       type_str = null;
+               }
+
                private void MakeString ()
                {
                        //Build full_name (foo < , >)
                        StringBuilder sb = new StringBuilder ();
                        sb.Append ("<");
-                       foreach (ITypeRef tr in type_list)
+                       foreach (BaseTypeRef tr in type_list)
                                sb.AppendFormat ("{0}, ", tr.FullName);
                        //Remove the extra ', ' at the end
                        sb.Length -= 2;