* ILParser.jay: Use type instead of params for calli signatures.
[mono.git] / mcs / ilasm / codegen / PeapiTypeRef.cs
1 //
2 // Mono.ILASM.PeapiTypeRef
3 //
4 // Author(s):
5 //  Jackson Harper (Jackson@LatitudeGeo.com)
6 //
7 // (C) 2003 Jackson Harper, All rights reserved
8 //
9
10
11 using System;
12 using System.Collections;
13
14 namespace Mono.ILASM {
15
16         public class PeapiTypeRef  {
17
18                 private PEAPI.Type peapi_type;
19                 private string full_name;
20                 private bool is_pinned;
21                 private bool is_array;
22                 private bool is_ref;
23
24                 public PeapiTypeRef (PEAPI.Type peapi_type, string full_name)
25                 {
26                         this.peapi_type = peapi_type;
27                         this.full_name = full_name;
28                         is_pinned = false;
29                         is_array = false;
30                         is_ref = false;
31                 }
32
33                 public string FullName {
34                         get { return full_name; }
35                 }
36
37                 public bool IsPinned {
38                         get { return is_pinned; }
39                 }
40
41                 public bool IsArray {
42                         get { return is_array; }
43                 }
44
45                 public bool IsRef {
46                         get { return is_ref; }
47                 }
48
49                 public PEAPI.Type PeapiType {
50                         get { return peapi_type; }
51                 }
52
53                 public void MakeArray ()
54                 {
55                         if (peapi_type is PEAPI.Class) {
56                                 PEAPI.Class klass = (PEAPI.Class) peapi_type;
57                                 peapi_type = klass.GetZeroBasedArray ();
58                         } else {
59                                 peapi_type = new PEAPI.ZeroBasedArray (peapi_type);
60                         }
61                         full_name += "[]";
62                         is_array = true;
63                 }
64
65                 public void MakeBoundArray (ArrayList bound_list)
66                 {
67                         int dimen = bound_list.Count;
68                         int[] lower_array = new int[dimen];
69                         int[] size_array = new int[dimen];
70                         bool lower_set = false;
71                         bool size_set = false;
72                         bool prev_lower_set = true;
73                         bool prev_size_set = true;
74
75                         // TODO: There should probably be an error reported if
76                         // something like [3...,3...5] is done
77                         for (int i=0; i<dimen; i++) {
78                                 DictionaryEntry bound = (DictionaryEntry) bound_list[i];
79
80                                 if (bound.Key != null && prev_lower_set) {
81                                         lower_array[i] = (int) bound.Key;
82                                         lower_set = true;
83                                 } else {
84                                         prev_lower_set = false;
85                                 }
86                                 if (bound.Value != null && prev_size_set) {
87                                         size_array[i] = (int) bound.Value;
88                                         size_set = true;
89                                 } else {
90                                         prev_size_set = false;
91                                 }
92                         }
93                         if (lower_set && size_set) {
94                                 peapi_type = new PEAPI.BoundArray (peapi_type,
95                                                 (uint) dimen, lower_array, size_array);
96                         } else if (size_set) {
97                                 peapi_type = new PEAPI.BoundArray (peapi_type,
98                                                 (uint) dimen, size_array);
99                         } else {
100                                 peapi_type = new PEAPI.BoundArray (peapi_type, (uint) dimen);
101                         }
102                         /// TODO: Proper full names
103                         full_name += "[][]";
104                         is_array = true;
105                 }
106
107                 public void MakeManagedPointer ()
108                 {
109                         peapi_type = new PEAPI.ManagedPointer (peapi_type);
110                         full_name += "&";
111                         is_ref = true;
112                 }
113
114                 public void MakeUnmanagedPointer ()
115                 {
116                         peapi_type = new PEAPI.UnmanagedPointer (peapi_type);
117                         full_name += "*";
118                 }
119
120                 public void MakeCustomModified (PEAPI.CustomModifier modifier)
121                 {
122                         peapi_type = new PEAPI.CustomModifiedType (peapi_type,
123                                         PEAPI.CustomModifier.modreq, (PEAPI.Class) peapi_type);
124                 }
125
126                 public void MakePinned ()
127                 {
128                         is_pinned = true;
129                 }
130
131                 public void Resolve (CodeGen code_gen)
132                 {
133
134                 }
135
136
137         }
138
139 }
140