5 // Jackson Harper (Jackson@LatitudeGeo.com)
7 // (C) 2003 Jackson Harper, All rights reserved
11 using System.Collections;
13 namespace Mono.ILASM {
16 /// Reference to a type in the module being compiled.
18 public class TypeRef : ModifiableType, IClassRef {
21 private Location location;
22 private string full_name;
23 private string sig_mod;
24 private PEAPI.Type type;
25 private bool is_valuetype;
26 private Hashtable genericinst_table;
27 private Hashtable p_genericinst_table;
29 private bool is_resolved;
31 public static readonly TypeRef Ellipsis = new TypeRef ("ELLIPSIS", false, null);
32 public static readonly TypeRef Any = new TypeRef ("any", false, null);
34 public TypeRef (string full_name, bool is_valuetype, Location location)
35 : this (full_name, is_valuetype, location, null, null)
39 public TypeRef (string full_name, bool is_valuetype, Location location, ArrayList conv_list, string sig_mod)
41 this.full_name = full_name;
42 this.location = location;
43 this.is_valuetype = is_valuetype;
44 this.sig_mod = sig_mod;
45 if (conv_list != null)
46 ConversionList = conv_list;
50 public string FullName {
51 get { return full_name + sig_mod; }
54 public override string SigMod {
55 get { return sig_mod; }
56 set { sig_mod = value; }
59 public PEAPI.Type PeapiType {
63 public PEAPI.Class PeapiClass {
64 get { return type as PEAPI.Class; }
67 public IClassRef Clone ()
69 return new TypeRef (full_name, is_valuetype, location, (ArrayList) ConversionList.Clone (), sig_mod);
72 public bool IsResolved {
73 get { return is_resolved; }
76 public void MakeValueClass ()
81 public GenericTypeInst GetGenericTypeInst (GenericArguments gen_args)
83 string sig = gen_args.ToString ();
84 GenericTypeInst gtri = null;
86 if (genericinst_table == null)
87 genericinst_table = new Hashtable ();
89 gtri = genericinst_table [sig] as GenericTypeInst;
92 gtri = new GenericTypeInst (this, gen_args, is_valuetype);
93 genericinst_table [sig] = gtri;
99 public PEAPI.Type ResolveInstance (CodeGen code_gen, GenericArguments gen_args)
101 PEAPI.GenericTypeInst gtri = null;
102 string sig = gen_args.ToString ();
104 if (p_genericinst_table == null)
105 p_genericinst_table = new Hashtable ();
107 gtri = p_genericinst_table [sig] as PEAPI.GenericTypeInst;
113 gtri = new PEAPI.GenericTypeInst (PeapiType, gen_args.Resolve (code_gen));
114 p_genericinst_table [sig] = gtri;
120 public IMethodRef GetMethodRef (ITypeRef ret_type,
121 PEAPI.CallConv call_conv, string name, ITypeRef[] param, int gen_param_count)
123 return new MethodRef (this, call_conv, ret_type, name, param, gen_param_count);
126 public IFieldRef GetFieldRef (ITypeRef ret_type, string name)
128 return new FieldRef (this, ret_type, name);
131 public void Resolve (CodeGen code_gen)
136 PEAPI.Type base_type;
138 base_type = code_gen.TypeManager.GetPeapiType (full_name);
140 if (base_type == null) {
141 code_gen.Report.Error ("Reference to undefined class '" +
145 type = Modify (code_gen, base_type);
150 public IClassRef AsClassRef (CodeGen code_gen)
155 public override string ToString ()