Merge pull request #1874 from saper/bug_29679
[mono.git] / mcs / ilasm / codegen / BaseTypeRef.cs
1 //
2 // Mono.ILASM.BaseTypeRef
3 //
4 // Author(s):
5 //  Ankit Jain  <jankit@novell.com>
6 //
7 // Copyright 2006 Novell, Inc (http://www.novell.com)
8 //
9
10 using System;
11 using System.Collections;
12
13 namespace Mono.ILASM {
14
15         public abstract class BaseTypeRef : ModifiableType {
16                 protected string full_name;
17                 protected string sig_mod;
18                 protected PEAPI.Type type;
19                 protected bool is_resolved;
20                 protected Hashtable method_table;
21                 protected Hashtable field_table;
22
23                 protected BaseTypeRef (string full_name)
24                         : this (full_name, null, null)
25                 {
26                 }
27
28                 protected BaseTypeRef (string full_name, ArrayList conv_list, string sig_mod)
29                 {
30                         this.full_name = full_name;
31                         this.sig_mod = sig_mod;
32                         is_resolved = false;
33                         if (conv_list != null)
34                                 ConversionList = conv_list;
35                 }
36
37                 public virtual string FullName {
38                         get { return full_name + sig_mod; }
39                 }
40
41                 public override string SigMod {
42                         get { return sig_mod; }
43                         set { sig_mod = value; }
44                 }
45
46                 public PEAPI.Type PeapiType {
47                         get { return type; }
48                 }
49
50                 public bool IsResolved {
51                         get { return is_resolved; }
52                 }
53
54                 public abstract void Resolve (CodeGen code_gen);
55
56                 public abstract BaseTypeRef Clone ();
57
58                 protected abstract BaseMethodRef CreateMethodRef (BaseTypeRef ret_type,
59                         PEAPI.CallConv call_conv, string name, BaseTypeRef[] param, int gen_param_count);
60
61                 public virtual BaseMethodRef GetMethodRef (BaseTypeRef ret_type,
62                         PEAPI.CallConv call_conv, string name, BaseTypeRef[] param, int gen_param_count)
63                 {
64                         BaseMethodRef mr = null;
65
66                         /* Note: FullName not reqd as this is cached per object */
67                         string key = MethodDef.CreateSignature (ret_type, call_conv, name, param, gen_param_count, true);
68                         if (method_table == null)
69                                 method_table = new Hashtable ();
70                         else
71                                 mr = (BaseMethodRef) method_table [key];
72
73                         if (mr == null) {
74                                 mr = CreateMethodRef (ret_type, call_conv, name, param, gen_param_count);
75                                 method_table [key] = mr;
76                         }
77
78                         return mr;
79                 }
80
81                 protected abstract IFieldRef CreateFieldRef (BaseTypeRef ret_type, string name);
82
83                 public virtual IFieldRef GetFieldRef (BaseTypeRef ret_type, string name)
84                 {
85                         IFieldRef fr = null;
86                         string key = ret_type.FullName + name;
87
88                         if (field_table == null)
89                                 field_table = new Hashtable ();
90                         else
91                                 fr = (IFieldRef) field_table [key];
92
93                         if (fr == null) {
94                                 fr = CreateFieldRef (ret_type, name);
95                                 field_table [key] = fr;
96                         }
97
98                         return fr;
99                 }
100
101         }
102
103 }