Merge pull request #1464 from akoeplinger/fix-portable-target
[mono.git] / mcs / ilasm / codegen / ExternTypeRefInst.cs
1 //
2 // Mono.ILASM.ExternTypeRefInst
3 //
4 // Author(s):
5 //  Jackson Harper (Jackson@LatitudeGeo.com)
6 //
7 // (C) 2004 Novell, Inc (http://www.novell.com)
8 //
9
10
11 using System;
12 using System.Collections;
13
14 namespace Mono.ILASM {
15
16         public class ExternTypeRefInst : BaseTypeRef {
17
18                 private ExternTypeRef type_ref;
19                 private PEAPI.Type type;
20                 private bool is_valuetypeinst;
21                 private bool is_resolved;
22                 private GenericArguments gen_args;
23                 private static Hashtable method_table = new Hashtable ();
24
25                 public ExternTypeRefInst (ExternTypeRef type_ref, GenericArguments gen_args, bool is_valuetypeinst)
26                 {
27                         this.type_ref = type_ref;
28                         this.gen_args = gen_args;
29                         this.is_valuetypeinst = is_valuetypeinst;
30
31                         is_resolved = false;
32                 }
33
34                 public PEAPI.Type PeapiType {
35                         get { return type; }
36                 }
37
38                 public string FullName {
39                         get { return type_ref.FullName; }
40                 }
41
42
43                 public string SigMod {
44                         get { return type_ref.SigMod; }
45                         set { type_ref.SigMod = value; }
46                 }
47
48                 
49                 public bool IsPinned {
50                         get { return type_ref.IsPinned; }
51                 }
52
53                 public bool IsRef {
54                         get { return type_ref.IsRef; }
55                 }
56
57                 public bool IsArray {
58                         get { return type_ref.IsArray; }
59                 }
60
61                 public bool UseTypeSpec {
62                         get { return type_ref.UseTypeSpec; }
63                 }
64
65                 public ExternTypeRefInst Clone ()
66                 {
67                         return new ExternTypeRefInst (type_ref.Clone (), gen_args, is_valuetypeinst);
68                 }
69
70                 public void MakeArray ()
71                 {
72                         is_valuetypeinst = false;
73                         type_ref.MakeArray ();
74                 }
75
76                 public void MakeBoundArray (ArrayList bounds)
77                 {
78                         is_valuetypeinst = false;
79                         type_ref.MakeBoundArray (bounds);
80                 }
81
82                 public void MakeManagedPointer ()
83                 {
84                         type_ref.MakeManagedPointer ();
85                 }
86
87                 public void MakeUnmanagedPointer ()
88                 {
89                         type_ref.MakeUnmanagedPointer ();
90                 }
91
92                 public void MakeCustomModified (CodeGen code_gen,
93                                 PEAPI.CustomModifier modifier, BaseClassRef klass)
94                 {
95                         type_ref.MakeCustomModified (code_gen, modifier, klass);
96                 }
97
98                 public void MakePinned ()
99                 {
100                         type_ref.MakePinned ();
101                 }
102
103                 public void MakeValueClass ()
104                 {
105                         type_ref.MakeValueClass ();
106                 }
107
108                 public void Resolve (CodeGen code_gen)
109                 {
110                         if (is_resolved)
111                                 return;
112
113                         type_ref.Resolve (code_gen);
114
115                         type = new PEAPI.GenericTypeInst (type_ref.PeapiType, gen_args.Resolve (code_gen));
116
117                         is_resolved = true;
118                 }
119
120                 public BaseMethodRef GetMethodRef (BaseTypeRef ret_type, PEAPI.CallConv call_conv,
121                                 string name, BaseTypeRef[] param, int gen_param_count)
122                 {
123                         string key = type_ref.FullName + MethodDef.CreateSignature (ret_type, name, param, gen_param_count) + type_ref.SigMod;
124                         TypeSpecMethodRef mr = method_table [key] as TypeSpecMethodRef;
125                         if (mr == null) {        
126                                 mr = new TypeSpecMethodRef (this, ret_type, call_conv, name, param, gen_param_count);
127                                 method_table [key] = mr;
128                         }
129
130                         return mr;
131                 }
132
133                 public IFieldRef GetFieldRef (BaseTypeRef ret_type, string name)
134                 {
135                         return new TypeSpecFieldRef (this, ret_type, name);
136                 }
137         }
138 }
139