In .:
[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 : BaseTypeRef {
20
21                 private static Hashtable s_method_table = new Hashtable ();
22
23                 public PrimitiveTypeRef (PEAPI.PrimitiveType type, string full_name)
24                         : base (full_name)
25                 {
26                         this.type = type;
27                         SigMod = String.Empty;
28                 }
29
30                 public string Name {
31                         get { return full_name; }
32                 }
33
34                 public override void Resolve (CodeGen code_gen)
35                 {
36                         if (is_resolved)
37                                 return;
38
39                         // Perform all of the types modifications
40                         type = Modify (code_gen, type);
41
42                         is_resolved = true;
43                 }
44
45                 /// <summary>
46                 /// Primitive types can be created like this System.String instead
47                 /// of like a normal type that would be [mscorlib]System.String This
48                 /// method returns a proper primitive type if the supplied name is
49                 /// the name of a primitive type.
50                 /// </summary>
51                 public static PrimitiveTypeRef GetPrimitiveType (string full_name)
52                 {
53                         switch (full_name) {
54                         case "System.String":
55                                 return new PrimitiveTypeRef (PEAPI.PrimitiveType.String, full_name);
56                         case "System.Object":
57                                 return new PrimitiveTypeRef (PEAPI.PrimitiveType.Object, full_name);
58                         default:
59                                 return null;
60                         }
61                 }
62
63                 protected override BaseMethodRef CreateMethodRef (BaseTypeRef ret_type,
64                         PEAPI.CallConv call_conv, string name, BaseTypeRef[] param, int gen_param_count)
65                 {
66                         throw new InternalErrorException ("Should not be called");
67                 }
68
69                 public override BaseMethodRef GetMethodRef (BaseTypeRef ret_type, PEAPI.CallConv call_conv,
70                                 string name, BaseTypeRef[] param, int gen_param_count)
71                 {
72                         /* Use FullName also here, as we are caching in a static hashtable */
73                         string key = FullName + MethodDef.CreateSignature (ret_type, name, param, gen_param_count);
74                         TypeSpecMethodRef mr = s_method_table [key] as TypeSpecMethodRef;
75                         if (mr != null)
76                                 return mr;
77
78                         //FIXME: generic methodref for primitive type?
79                         mr = new TypeSpecMethodRef (this, call_conv, ret_type, name, param, gen_param_count);
80                         s_method_table [key] = mr;
81                         return mr;
82                 }
83
84                 protected override IFieldRef CreateFieldRef (BaseTypeRef ret_type, string name)
85                 {
86                         Report.Error ("PrimitiveType's can't have fields!");
87                         return null;
88                 }
89
90                 public BaseClassRef AsClassRef (CodeGen code_gen)
91                 {
92                         /*
93                         PEAPI.ClassRef class_ref = code_gen.ExternTable.GetValueClass ("corlib", FullName);
94                         ExternTypeRef type_ref = new ExternTypeRef (class_ref, FullName);
95
96                         // TODO: Need to do the rest of the conversion (in order)
97                         if (IsArray)
98                                 type_ref.MakeArray ();
99
100                         return type_ref;
101                         */
102                         throw new NotImplementedException ("This method is getting depricated.");
103                 }
104
105         }
106
107 }
108