a697797121fd420aba49a005f9f9f907553e3a98
[mono.git] / mcs / ilasm / codegen / ExternTypeRef.cs
1 //
2 // Mono.ILASM.ExternTypeRef
3 //
4 // Author(s):
5 //  Jackson Harper (Jackson@LatitudeGeo.com)
6 //
7 // (C) 2003 Jackson Harper, All rights reserved
8 //
9
10
11 using System;
12 using System.Collections;
13
14 namespace Mono.ILASM {
15
16         /// <summary>
17         /// A reference to a type in another assembly
18         /// </summary>
19         public class ExternTypeRef : ModifiableType, IClassRef {
20
21                 private PEAPI.Type type;
22                 private ExternRef extern_ref;
23                 private string full_name;
24                 private string sig_mod;
25                 private bool is_valuetype;
26                 private ExternTable extern_table;
27
28                 private bool is_resolved;
29
30                 private Hashtable method_table;
31                 private Hashtable field_table;
32                 
33                 public ExternTypeRef (ExternRef extern_ref, string full_name,
34                                 bool is_valuetype, ExternTable extern_table)
35                 {
36                         this.extern_ref = extern_ref;
37                         this.full_name = full_name;
38                         this.is_valuetype = is_valuetype;
39                         this.extern_table = extern_table;
40                         sig_mod = String.Empty;
41
42                         method_table = new Hashtable ();
43                         field_table = new Hashtable ();
44                         
45                         is_resolved = false;
46                 }
47
48                 private ExternTypeRef (ExternRef extern_ref, string full_name,
49                                 bool is_valuetype, ExternTable extern_table,
50                                 ArrayList conv_list) : this (extern_ref, full_name,
51                                                 is_valuetype, extern_table)
52                 {
53                         ConversionList = conv_list;
54                 }
55                 
56                 public ExternTypeRef Clone ()
57                 {
58                         return new ExternTypeRef (extern_ref, FullName, is_valuetype,
59                                         extern_table, (ArrayList) ConversionList.Clone ());
60                 }
61                 
62                 public PEAPI.Type PeapiType {
63                         get { return type; }
64                 }
65
66                 public PEAPI.Class PeapiClass {
67                         get { return type as PEAPI.Class; }
68                 }
69
70                 public string FullName {
71                         get { return full_name + sig_mod; }
72                 }
73
74
75                 public override string SigMod {
76                         get { return sig_mod; }
77                         set { sig_mod = value; }
78                 }
79
80                 public void Resolve (CodeGen code_gen)
81                 {
82                         if (is_resolved)
83                                 return;
84
85                         if (is_valuetype)
86                                 type = extern_ref.GetValueType (full_name);
87                         else
88                                 type = extern_ref.GetType (full_name);
89
90                         type = Modify (code_gen, type);
91
92                         is_resolved = true;
93                 }
94
95                 public void MakeValueClass ()
96                 {
97                         is_valuetype = true;
98                 }
99
100                 public IMethodRef GetMethodRef (ITypeRef ret_type, PEAPI.CallConv call_conv,
101                                 string name, ITypeRef[] param)
102                 {
103                         string sig = MethodDef.CreateSignature (name, param);
104                         ExternMethodRef mr = method_table [sig] as ExternMethodRef;
105                         
106                         if (mr == null) {
107                                 mr = new ExternMethodRef (this, ret_type, call_conv, name, param);
108                                 method_table [sig] = mr;
109                         }
110
111                         return mr;
112                 }
113
114                 public IFieldRef GetFieldRef (ITypeRef ret_type, string name)
115                 {
116                         ExternFieldRef fr = field_table [name] as ExternFieldRef;
117
118                         if (fr == null) {
119                                 fr = new ExternFieldRef (this, ret_type, name);
120                                 field_table [name] = fr;
121                         }
122
123                         return fr;
124                 }
125         }
126
127 }
128