* ExternFieldRef.cs: Resolve as a typespec field if neccasary, make
[mono.git] / mcs / ilasm / codegen / TypeRef.cs
1 //
2 // Mono.ILASM.TypeRef
3 //
4 // Author(s):
5 //  Jackson Harper (Jackson@LatitudeGeo.com)
6 //
7 // (C) 2003 Jackson Harper, All rights reserved
8 //
9
10 using System;
11 using System.Collections;
12
13 namespace Mono.ILASM {
14
15         /// <summary>
16         /// Reference to a type in the module being compiled.
17         /// </summary>
18         public class TypeRef : ModifiableType, IClassRef {
19
20                 private enum ConversionMethod {
21                         MakeArray,
22                         MakeBoundArray,
23                         MakeManagedPointer,
24                         MakeUnmanagedPointer,
25                         MakeCustomModified
26                 }
27
28                 private Location location;
29                 private string full_name;
30                 private PEAPI.Type type;
31
32                 private bool is_resolved;
33
34                 public static readonly TypeRef Ellipsis = new TypeRef ("ELLIPSIS", null);
35                 public static readonly TypeRef Any = new TypeRef ("any", null);
36
37                 public TypeRef (string full_name, Location location)
38                 {
39                         this.full_name = full_name;
40                         this.location = location;
41                         is_resolved = false;
42                 }
43
44                 public string FullName {
45                         get { return full_name; }
46                 }
47
48                 public PEAPI.Type PeapiType {
49                         get { return type; }
50                 }
51
52                 public PEAPI.Class PeapiClass {
53                         get { return type as PEAPI.Class; }
54                 }
55
56                 public bool IsResolved {
57                         get { return is_resolved; }
58                 }
59
60                 public  IMethodRef GetMethodRef (ITypeRef ret_type,
61                         PEAPI.CallConv call_conv, string name, ITypeRef[] param)
62                 {
63                         return new MethodRef (this, call_conv, ret_type, name, param);
64                 }
65
66                 public IFieldRef GetFieldRef (ITypeRef ret_type, string name)
67                 {
68                         return new FieldRef (this, ret_type, name);
69                 }
70
71                 public void Resolve (CodeGen code_gen)
72                 {
73                         if (is_resolved)
74                                 return;
75
76                         PEAPI.Type base_type;
77
78                         base_type = code_gen.TypeManager.GetPeapiType (full_name);
79                         type = Modify (code_gen, base_type, ref full_name);
80
81                         is_resolved = true;
82                 }
83
84                 public IClassRef AsClassRef (CodeGen code_gen)
85                 {
86                         return this;
87                 }
88
89                 public override string ToString ()
90                 {
91                         return FullName;
92                 }
93
94         }
95
96 }
97