5 // Jackson Harper (Jackson@LatitudeGeo.com)
7 // (C) 2003 Jackson Harper, All rights reserved
11 using System.Collections;
13 namespace Mono.ILASM {
16 /// Reference to a type in the module being compiled.
18 public class TypeRef : IClassRef {
20 private enum ConversionMethod {
28 private Location location;
29 private string full_name;
30 private PEAPI.Type resolved_type;
31 private ArrayList conversion_list;
32 private bool is_pinned;
34 private bool is_array;
36 private bool is_resolved;
38 public static readonly TypeRef Ellipsis = new TypeRef ("ELLIPSIS", null);
39 public static readonly TypeRef Any = new TypeRef ("any", null);
41 public TypeRef (string full_name, Location location)
43 this.full_name = full_name;
44 this.location = location;
48 conversion_list = new ArrayList ();
52 public string FullName {
53 get { return full_name; }
56 public bool IsPinned {
57 get { return is_pinned; }
61 get { return is_array; }
65 get { return is_ref; }
68 public PEAPI.Type PeapiType {
69 get { return resolved_type; }
72 public PEAPI.Class PeapiClass {
73 get { return resolved_type as PEAPI.Class; }
76 public bool IsResolved {
77 get { return is_resolved; }
80 public void MakeArray ()
82 conversion_list.Add (ConversionMethod.MakeArray);
86 public void MakeBoundArray (ArrayList bounds)
88 conversion_list.Add (ConversionMethod.MakeBoundArray);
89 conversion_list.Add (bounds);
93 public void MakeManagedPointer ()
95 conversion_list.Add (ConversionMethod.MakeManagedPointer);
99 public void MakeUnmanagedPointer ()
101 conversion_list.Add (ConversionMethod.MakeUnmanagedPointer);
104 public void MakeCustomModified (CodeGen code_gen, PEAPI.CustomModifier modifier,
107 conversion_list.Add (ConversionMethod.MakeCustomModified);
108 conversion_list.Add (klass);
109 conversion_list.Add (modifier);
112 public void MakePinned ()
117 public IMethodRef GetMethodRef (ITypeRef ret_type,
118 PEAPI.CallConv call_conv, string name, ITypeRef[] param)
120 return new MethodRef (this, call_conv, ret_type, name, param);
123 public IFieldRef GetFieldRef (ITypeRef ret_type, string name)
125 return new FieldRef (this, ret_type, name);
128 public void Resolve (CodeGen code_gen)
133 PEAPI.Type base_type;
134 PeapiTypeRef peapi_type;
135 int count = conversion_list.Count;
137 base_type = code_gen.TypeManager.GetPeapiType (full_name);
139 /// TODO: Proper error message
140 if (base_type == null) {
141 Console.WriteLine ("Type not defined: {0} {1}", full_name, location);
145 peapi_type = new PeapiTypeRef (base_type, full_name);
147 for (int i=0; i<count; i++) {
148 switch ((ConversionMethod) conversion_list[i]) {
149 case ConversionMethod.MakeArray:
150 peapi_type.MakeArray ();
152 case ConversionMethod.MakeBoundArray:
153 peapi_type.MakeBoundArray ((ArrayList) conversion_list[++i]);
155 case ConversionMethod.MakeManagedPointer:
156 peapi_type.MakeManagedPointer ();
158 case ConversionMethod.MakeUnmanagedPointer:
159 peapi_type.MakeUnmanagedPointer ();
161 case ConversionMethod.MakeCustomModified:
162 peapi_type.MakeCustomModified (code_gen, (PEAPI.CustomModifier) conversion_list[++i],
163 (IClassRef) conversion_list[++i]);
168 resolved_type = peapi_type.PeapiType;
173 public IClassRef AsClassRef (CodeGen code_gen)
178 public override string ToString ()