[interp] Add more Math intrinsics (#19174)
[mono-project.git] / mcs / ilasm / codegen / GenericArguments.cs
blobdb098d44423510a4bd140d334b1a3484e5ea2c8a
1 //
2 // Mono.ILASM.GenericArguments
3 //
4 // Author(s):
5 // Ankit Jain <jankit@novell.com>
6 //
7 // Copyright 2005 Novell, Inc (http://www.novell.com)
8 //
10 using System;
11 using System.Collections;
12 using System.Text;
14 namespace Mono.ILASM {
16 public class GenericArguments {
17 ArrayList type_list;
18 string type_str;
19 BaseTypeRef [] type_arr;
20 bool is_resolved;
21 PEAPI.Type [] p_type_list;
23 public GenericArguments ()
25 type_list = null;
26 type_arr = null;
27 type_str = null;
28 is_resolved = false;
29 p_type_list = null;
32 public int Count {
33 get { return type_list.Count; }
36 public void Add (BaseTypeRef type)
38 if (type == null)
39 throw new InternalErrorException ();
41 if (type_list == null)
42 type_list = new ArrayList ();
43 var prim = PrimitiveTypeRef.GetPrimitiveType (type.FullName);
44 if (prim != null)
45 type_list.Add (prim);
46 else
47 type_list.Add (type);
48 type_str = null;
49 type_arr = null;
52 public BaseTypeRef [] ToArray ()
54 if (type_list == null)
55 return null;
56 if (type_arr == null)
57 type_arr = (BaseTypeRef []) type_list.ToArray (typeof (BaseTypeRef));
59 return type_arr;
62 public PEAPI.Type [] Resolve (CodeGen code_gen)
64 if (is_resolved)
65 return p_type_list;
67 int i = 0;
68 p_type_list = new PEAPI.Type [type_list.Count];
69 foreach (BaseTypeRef type in type_list) {
70 type.Resolve (code_gen);
71 p_type_list [i ++] = type.PeapiType;
73 is_resolved = true;
74 type_str = null;
75 return p_type_list;
78 public void Resolve (GenericParameters type_gen_params, GenericParameters method_gen_params)
80 foreach (BaseTypeRef type in type_list) {
81 BaseGenericTypeRef gtr = type as BaseGenericTypeRef;
82 if (gtr != null)
83 gtr.Resolve (type_gen_params, method_gen_params);
85 /* Reset, might have changed (think GenericParamRef) */
86 type_str = null;
89 private void MakeString ()
91 //Build full_name (foo < , >)
92 StringBuilder sb = new StringBuilder ();
93 sb.Append ("<");
94 foreach (BaseTypeRef tr in type_list)
95 sb.AppendFormat ("{0}, ", tr.FullName);
96 //Remove the extra ', ' at the end
97 sb.Length -= 2;
98 sb.Append (">");
99 type_str = sb.ToString ();
102 public override string ToString ()
104 if (type_str == null)
105 MakeString ();
106 return type_str;