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