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_resolved;
36 public TypeRef (string full_name, Location location)
38 this.full_name = full_name;
39 this.location = location;
41 conversion_list = new ArrayList ();
45 public string FullName {
46 get { return full_name; }
49 public bool IsPinned {
50 get { return is_pinned; }
53 public PEAPI.Type PeapiType {
54 get { return resolved_type; }
57 public PEAPI.Class PeapiClass {
58 get { return resolved_type as PEAPI.Class; }
61 public bool IsResolved {
62 get { return is_resolved; }
65 public void MakeArray ()
67 conversion_list.Add (ConversionMethod.MakeArray);
70 public void MakeBoundArray (ArrayList bounds)
72 conversion_list.Add (ConversionMethod.MakeBoundArray);
73 conversion_list.Add (bounds);
76 public void MakeManagedPointer ()
78 conversion_list.Add (ConversionMethod.MakeManagedPointer);
81 public void MakeUnmanagedPointer ()
83 conversion_list.Add (ConversionMethod.MakeUnmanagedPointer);
86 public void MakeCustomModified (PEAPI.CustomModifier modifier)
88 conversion_list.Add (ConversionMethod.MakeCustomModified);
89 conversion_list.Add (modifier);
92 public void MakePinned ()
97 public void Resolve (CodeGen code_gen)
102 PEAPI.Type base_type;
103 PeapiTypeRef peapi_type;
104 int count = conversion_list.Count;
106 base_type = code_gen.TypeManager.GetPeapiType (full_name);
108 /// TODO: Proper error message
109 if (base_type == null) {
110 Console.WriteLine ("Type not defined: {0} {1}", full_name, location);
114 peapi_type = new PeapiTypeRef (base_type, full_name);
116 for (int i=0; i<count; i++) {
117 switch ((ConversionMethod) conversion_list[i]) {
118 case ConversionMethod.MakeArray:
119 peapi_type.MakeArray ();
121 case ConversionMethod.MakeBoundArray:
122 peapi_type.MakeBoundArray ((ArrayList) conversion_list[++i]);
124 case ConversionMethod.MakeManagedPointer:
125 peapi_type.MakeManagedPointer ();
127 case ConversionMethod.MakeUnmanagedPointer:
128 peapi_type.MakeUnmanagedPointer ();
130 case ConversionMethod.MakeCustomModified:
131 peapi_type.MakeCustomModified ((PEAPI.CustomModifier) conversion_list[++i]);
136 resolved_type = peapi_type.PeapiType;
141 public override string ToString ()