In ilasm/tests:
[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 FullName {
37                         get { return full_name + sig_mod; }
38                 }
39
40                 public override string SigMod {
41                         get { return sig_mod; }
42                         set { sig_mod = value; }
43                 }
44
45                 public PEAPI.Type PeapiType {
46                         get { return type; }
47                 }
48
49                 public void Resolve (CodeGen code_gen)
50                 {
51                         if (is_resolved)
52                                 return;
53
54                         // Perform all of the types modifications
55                         type = Modify (code_gen, type);
56
57                         is_resolved = true;
58                 }
59
60                 /// <summary>
61                 /// Primitive types can be created like this System.String instead
62                 /// of like a normal type that would be [mscorlib]System.String This
63                 /// method returns a proper primitive type if the supplied name is
64                 /// the name of a primitive type.
65                 /// </summary>
66                 public static PrimitiveTypeRef GetPrimitiveType (string full_name)
67                 {
68                         switch (full_name) {
69                         case "System.String":
70                                 return new PrimitiveTypeRef (PEAPI.PrimitiveType.String, full_name);
71                         case "System.Object":
72                                 return new PrimitiveTypeRef (PEAPI.PrimitiveType.Object, full_name);
73                         default:
74                                 return null;
75                         }
76                 }
77
78                 public IMethodRef GetMethodRef (ITypeRef ret_type, PEAPI.CallConv call_conv,
79                                 string name, ITypeRef[] param)
80                 {
81                         string key = full_name + MethodDef.CreateSignature (ret_type, name, param) + sig_mod;
82                         TypeSpecMethodRef mr = method_table [key] as TypeSpecMethodRef;
83                         if (mr != null)
84                                 return mr;
85
86                         mr = new TypeSpecMethodRef (this, ret_type, call_conv, name, param);
87                         method_table [key] = mr;
88                         return mr;
89                 }
90
91                 public IFieldRef GetFieldRef (ITypeRef ret_type, string name)
92                 {
93                         return new TypeSpecFieldRef (this, ret_type, name);
94                 }
95
96                 public IClassRef AsClassRef (CodeGen code_gen)
97                 {
98                         /*
99                         PEAPI.ClassRef class_ref = code_gen.ExternTable.GetValueClass ("corlib", FullName);
100                         ExternTypeRef type_ref = new ExternTypeRef (class_ref, FullName);
101
102                         // TODO: Need to do the rest of the conversion (in order)
103                         if (IsArray)
104                                 type_ref.MakeArray ();
105
106                         return type_ref;
107                         */
108                         throw new NotImplementedException ("This method is getting depricated.");
109                 }
110
111         }
112
113 }
114