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 TypeRef Ellipsis = new TypeRef ("ELLIPSIS", null);
40 public TypeRef (string full_name, Location location)
42 this.full_name = full_name;
43 this.location = location;
47 conversion_list = new ArrayList ();
51 public string FullName {
52 get { return full_name; }
55 public bool IsPinned {
56 get { return is_pinned; }
60 get { return is_array; }
64 get { return is_ref; }
67 public PEAPI.Type PeapiType {
68 get { return resolved_type; }
71 public PEAPI.Class PeapiClass {
72 get { return resolved_type as PEAPI.Class; }
75 public bool IsResolved {
76 get { return is_resolved; }
79 public void MakeArray ()
81 conversion_list.Add (ConversionMethod.MakeArray);
85 public void MakeBoundArray (ArrayList bounds)
87 conversion_list.Add (ConversionMethod.MakeBoundArray);
88 conversion_list.Add (bounds);
92 public void MakeManagedPointer ()
94 conversion_list.Add (ConversionMethod.MakeManagedPointer);
98 public void MakeUnmanagedPointer ()
100 conversion_list.Add (ConversionMethod.MakeUnmanagedPointer);
103 public void MakeCustomModified (PEAPI.CustomModifier modifier)
105 conversion_list.Add (ConversionMethod.MakeCustomModified);
106 conversion_list.Add (modifier);
109 public void MakePinned ()
114 public IMethodRef GetMethodRef (ITypeRef ret_type,
115 PEAPI.CallConv call_conv, string name, ITypeRef[] param)
117 return new MethodRef (this, call_conv, ret_type, name, param);
120 public IFieldRef GetFieldRef (ITypeRef ret_type, string name)
122 return new FieldRef (this, ret_type, name);
125 public void Resolve (CodeGen code_gen)
130 PEAPI.Type base_type;
131 PeapiTypeRef peapi_type;
132 int count = conversion_list.Count;
134 base_type = code_gen.TypeManager.GetPeapiType (full_name);
136 /// TODO: Proper error message
137 if (base_type == null) {
138 Console.WriteLine ("Type not defined: {0} {1}", full_name, location);
142 peapi_type = new PeapiTypeRef (base_type, full_name);
144 for (int i=0; i<count; i++) {
145 switch ((ConversionMethod) conversion_list[i]) {
146 case ConversionMethod.MakeArray:
147 peapi_type.MakeArray ();
149 case ConversionMethod.MakeBoundArray:
150 peapi_type.MakeBoundArray ((ArrayList) conversion_list[++i]);
152 case ConversionMethod.MakeManagedPointer:
153 peapi_type.MakeManagedPointer ();
155 case ConversionMethod.MakeUnmanagedPointer:
156 peapi_type.MakeUnmanagedPointer ();
158 case ConversionMethod.MakeCustomModified:
159 peapi_type.MakeCustomModified ((PEAPI.CustomModifier) conversion_list[++i]);
164 resolved_type = peapi_type.PeapiType;
169 public IClassRef AsClassRef (CodeGen code_gen)
174 public override string ToString ()