In ilasm/codegen:
[mono.git] / mcs / ilasm / codegen / PrimitiveTypeRef.cs
1 //
2 // Mono.ILASM.PrimitiveTypeRef
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         /// Reference to a primitive type, ie string, object, char
18         /// </summary>
19         public class PrimitiveTypeRef : ModifiableType, ITypeRef {
20
21                 private string full_name;
22                 private string sig_mod;
23                 private PEAPI.Type type;
24
25                 private bool is_resolved;
26                 private static Hashtable method_table = new Hashtable ();
27
28                 public PrimitiveTypeRef (PEAPI.PrimitiveType type, string full_name)
29                 {
30                         this.type = type;
31                         this.full_name = full_name;
32                         sig_mod = String.Empty;
33                         is_resolved = false;
34                 }
35
36                 public string Name {
37                         get { return full_name; }
38                 }
39
40                 public string FullName {
41                         get { return full_name + sig_mod; }
42                 }
43
44                 public override string SigMod {
45                         get { return sig_mod; }
46                         set { sig_mod = value; }
47                 }
48
49                 public PEAPI.Type PeapiType {
50                         get { return type; }
51                 }
52
53                 public void Resolve (CodeGen code_gen)
54                 {
55                         if (is_resolved)
56                                 return;
57
58                         // Perform all of the types modifications
59                         type = Modify (code_gen, type);
60
61                         is_resolved = true;
62                 }
63
64                 /// <summary>
65                 /// Primitive types can be created like this System.String instead
66                 /// of like a normal type that would be [mscorlib]System.String This
67                 /// method returns a proper primitive type if the supplied name is
68                 /// the name of a primitive type.
69                 /// </summary>
70                 public static PrimitiveTypeRef GetPrimitiveType (string full_name)
71                 {
72                         switch (full_name) {
73                         case "System.String":
74                                 return new PrimitiveTypeRef (PEAPI.PrimitiveType.String, full_name);
75                         case "System.Object":
76                                 return new PrimitiveTypeRef (PEAPI.PrimitiveType.Object, full_name);
77                         default:
78                                 return null;
79                         }
80                 }
81
82                 public IMethodRef GetMethodRef (ITypeRef ret_type, PEAPI.CallConv call_conv,
83                                 string name, ITypeRef[] param, int gen_param_count)
84                 {
85                         string key = full_name + MethodDef.CreateSignature (ret_type, name, param, gen_param_count) + sig_mod;
86                         TypeSpecMethodRef mr = method_table [key] as TypeSpecMethodRef;
87                         if (mr != null)
88                                 return mr;
89
90                         //FIXME: generic methodref for primitive type?
91                         mr = new TypeSpecMethodRef (this, ret_type, call_conv, name, param, gen_param_count);
92                         method_table [key] = mr;
93                         return mr;
94                 }
95
96                 public IFieldRef GetFieldRef (ITypeRef ret_type, string name)
97                 {
98                         return new TypeSpecFieldRef (this, ret_type, name);
99                 }
100
101                 public IClassRef AsClassRef (CodeGen code_gen)
102                 {
103                         /*
104                         PEAPI.ClassRef class_ref = code_gen.ExternTable.GetValueClass ("corlib", FullName);
105                         ExternTypeRef type_ref = new ExternTypeRef (class_ref, FullName);
106
107                         // TODO: Need to do the rest of the conversion (in order)
108                         if (IsArray)
109                                 type_ref.MakeArray ();
110
111                         return type_ref;
112                         */
113                         throw new NotImplementedException ("This method is getting depricated.");
114                 }
115
116         }
117
118 }
119