2005-01-31 Zoltan Varga <vargaz@freemail.hu>
[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
21                 private Location location;
22                 private string full_name;
23                 private string sig_mod;
24                 private PEAPI.Type type;
25                 private bool is_valuetype;
26
27                 private bool is_resolved;
28
29                 public static readonly TypeRef Ellipsis = new TypeRef ("ELLIPSIS", false, null);
30                 public static readonly TypeRef Any = new TypeRef ("any", false, null);
31
32                 public TypeRef (string full_name, bool is_valuetype, Location location)
33                 {
34                         this.full_name = full_name;
35                         this.location = location;
36                         this.is_valuetype = is_valuetype;
37                         sig_mod = String.Empty;
38                         is_resolved = false;
39                 }
40
41                 public string FullName {
42                         get { return full_name + sig_mod; }
43                 }
44
45                 public override string SigMod {
46                         get { return sig_mod; }
47                         set { sig_mod = value; }
48                 }
49
50                 public PEAPI.Type PeapiType {
51                         get { return type; }
52                 }
53
54                 public PEAPI.Class PeapiClass {
55                         get { return type as PEAPI.Class; }
56                 }
57
58                 public bool IsResolved {
59                         get { return is_resolved; }
60                 }
61
62                 public void MakeValueClass ()
63                 {
64                         is_valuetype = true;
65                 }
66
67                 public  IMethodRef GetMethodRef (ITypeRef ret_type,
68                         PEAPI.CallConv call_conv, string name, ITypeRef[] param)
69                 {
70                         return new MethodRef (this, call_conv, ret_type, name, param);
71                 }
72
73                 public IFieldRef GetFieldRef (ITypeRef ret_type, string name)
74                 {
75                         return new FieldRef (this, ret_type, name);
76                 }
77
78                 public void Resolve (CodeGen code_gen)
79                 {
80                         if (is_resolved)
81                                 return;
82
83                         PEAPI.Type base_type;
84
85                         base_type = code_gen.TypeManager.GetPeapiType (full_name);
86
87                         if (base_type == null) {
88                                 code_gen.Report.Error ("Reference to undefined class '" +
89                                                        FullName + "'");
90                                 return;
91                         }
92                         type = Modify (code_gen, base_type);
93
94                         is_resolved = true;
95                 }
96
97                 public IClassRef AsClassRef (CodeGen code_gen)
98                 {
99                         return this;
100                 }
101
102                 public override string ToString ()
103                 {
104                         return FullName;
105                 }
106
107         }
108
109 }
110