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 TypeRef (string full_name, Location location)
40 this.full_name = full_name;
41 this.location = location;
45 conversion_list = new ArrayList ();
49 public string FullName {
50 get { return full_name; }
53 public bool IsPinned {
54 get { return is_pinned; }
58 get { return is_array; }
62 get { return is_ref; }
65 public PEAPI.Type PeapiType {
66 get { return resolved_type; }
69 public PEAPI.Class PeapiClass {
70 get { return resolved_type as PEAPI.Class; }
73 public bool IsResolved {
74 get { return is_resolved; }
77 public void MakeArray ()
79 conversion_list.Add (ConversionMethod.MakeArray);
83 public void MakeBoundArray (ArrayList bounds)
85 conversion_list.Add (ConversionMethod.MakeBoundArray);
86 conversion_list.Add (bounds);
90 public void MakeManagedPointer ()
92 conversion_list.Add (ConversionMethod.MakeManagedPointer);
96 public void MakeUnmanagedPointer ()
98 conversion_list.Add (ConversionMethod.MakeUnmanagedPointer);
101 public void MakeCustomModified (PEAPI.CustomModifier modifier)
103 conversion_list.Add (ConversionMethod.MakeCustomModified);
104 conversion_list.Add (modifier);
107 public void MakePinned ()
112 public IMethodRef GetMethodRef (ITypeRef ret_type,
113 PEAPI.CallConv call_conv, string name, ITypeRef[] param)
115 return new MethodRef (this, ret_type, name, param);
118 public IFieldRef GetFieldRef (ITypeRef ret_type, string name)
120 return new FieldRef (this, ret_type, name);
123 public void Resolve (CodeGen code_gen)
128 PEAPI.Type base_type;
129 PeapiTypeRef peapi_type;
130 int count = conversion_list.Count;
132 base_type = code_gen.TypeManager.GetPeapiType (full_name);
134 /// TODO: Proper error message
135 if (base_type == null) {
136 Console.WriteLine ("Type not defined: {0} {1}", full_name, location);
140 peapi_type = new PeapiTypeRef (base_type, full_name);
142 for (int i=0; i<count; i++) {
143 switch ((ConversionMethod) conversion_list[i]) {
144 case ConversionMethod.MakeArray:
145 peapi_type.MakeArray ();
147 case ConversionMethod.MakeBoundArray:
148 peapi_type.MakeBoundArray ((ArrayList) conversion_list[++i]);
150 case ConversionMethod.MakeManagedPointer:
151 peapi_type.MakeManagedPointer ();
153 case ConversionMethod.MakeUnmanagedPointer:
154 peapi_type.MakeUnmanagedPointer ();
156 case ConversionMethod.MakeCustomModified:
157 peapi_type.MakeCustomModified ((PEAPI.CustomModifier) conversion_list[++i]);
162 resolved_type = peapi_type.PeapiType;
167 public IClassRef AsClassRef (CodeGen code_gen)
172 public override string ToString ()