* ExternFieldRef.cs: Resolve as a typespec field if neccasary, make
[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
13 namespace Mono.ILASM {
14
15         /// <summary>
16         /// Reference to a primitive type, ie string, object, char
17         /// </summary>
18         public class PrimitiveTypeRef : ModifiableType, ITypeRef {
19
20                 private string full_name;
21                 private PEAPI.Type type;
22
23                 private bool is_resolved;
24
25                 public PrimitiveTypeRef (PEAPI.PrimitiveType type, string full_name)
26                 {
27                         this.type = type;
28                         this.full_name = full_name;
29                 
30                         is_resolved = false;
31                 }
32
33                 public string FullName {
34                         get { return full_name; }
35                 }
36
37                 public PEAPI.Type PeapiType {
38                         get { return type; }
39                 }
40
41                 public void Resolve (CodeGen code_gen)
42                 {
43                         if (is_resolved)
44                                 return;
45
46                         // Perform all of the types modifications
47                         type = Modify (code_gen, type, ref full_name);
48                         
49                         is_resolved = true;
50                 }
51
52                 /// <summary>
53                 /// Primitive types can be created like this System.String instead
54                 /// of like a normal type that would be [mscorlib]System.String This
55                 /// method returns a proper primitive type if the supplied name is
56                 /// the name of a primitive type.
57                 /// </summary>
58                 public static PrimitiveTypeRef GetPrimitiveType (string full_name)
59                 {
60                         switch (full_name) {
61                         case "System.String":
62                                 return new PrimitiveTypeRef (PEAPI.PrimitiveType.String, full_name);
63                         case "System.Object":
64                                 return new PrimitiveTypeRef (PEAPI.PrimitiveType.Object, full_name);
65                         default:
66                                 return null;
67                         }
68                 }
69
70                 public IMethodRef GetMethodRef (ITypeRef ret_type, PEAPI.CallConv call_conv,
71                                 string name, ITypeRef[] param)
72                 {
73                         return new TypeSpecMethodRef (this, ret_type, call_conv, name, param);
74                 }
75
76                 public IFieldRef GetFieldRef (ITypeRef ret_type, string name)
77                 {
78                         return new TypeSpecFieldRef (this, ret_type, name);
79                 }
80
81                 public IClassRef AsClassRef (CodeGen code_gen)
82                 {
83                         /*
84                         PEAPI.ClassRef class_ref = code_gen.ExternTable.GetValueClass ("corlib", FullName);
85                         ExternTypeRef type_ref = new ExternTypeRef (class_ref, FullName);
86
87                         // TODO: Need to do the rest of the conversion (in order)
88                         if (IsArray)
89                                 type_ref.MakeArray ();
90
91                         return type_ref;
92                         */
93                         throw new NotImplementedException ("This method is getting depricated.");
94                 }
95
96         }
97
98 }
99