b31c3f342cf1ed2847c552b0c07ae29ed996209e
[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 bool is_pinned;
20                 private bool is_array;
21                 private bool is_ref;
22                 private bool use_type_spec;
23
24                 public PeapiTypeRef (PEAPI.Type peapi_type)
25                 {
26                         this.peapi_type = peapi_type;
27                         is_pinned = false;
28                         is_array = false;
29                         is_ref = false;
30                         use_type_spec = false;
31                 }
32
33                 public bool IsPinned {
34                         get { return is_pinned; }
35                 }
36
37                 public bool IsArray {
38                         get { return is_array; }
39                 }
40
41                 public bool IsRef {
42                         get { return is_ref; }
43                 }
44
45                 public bool UseTypeSpec {
46                         get { return use_type_spec; }
47                 }
48
49                 public PEAPI.Type PeapiType {
50                         get { return peapi_type; }
51                 }
52
53                 public void MakeArray ()
54                 {
55                         use_type_spec = true;
56                         peapi_type = new PEAPI.ZeroBasedArray (peapi_type);
57                         is_array = true;
58                 }
59
60                 public void MakeBoundArray (ArrayList bound_list)
61                 {
62                         use_type_spec = true;
63
64                         int dimen = bound_list.Count;
65                         int[] lower_array = new int[dimen];
66                         int[] size_array = new int[dimen];
67                         bool lower_set = false;
68                         bool size_set = false;
69                         bool prev_lower_set = true;
70                         bool prev_size_set = true;
71
72                         // TODO: There should probably be an error reported if
73                         // something like [3...,3...5] is done
74                         for (int i=0; i<dimen; i++) {
75                                 DictionaryEntry bound = (DictionaryEntry) bound_list[i];
76
77                                 if (bound.Key != TypeRef.Ellipsis && prev_lower_set) {
78                                         lower_array[i] = (int) bound.Key;
79                                         lower_set = true;
80                                 } else {
81                                         prev_lower_set = false;
82                                 }
83                                 if (bound.Value != TypeRef.Ellipsis && prev_size_set) {
84                                         size_array[i] = (int) bound.Value;
85                                         size_set = true;
86                                 } else {
87                                         prev_size_set = false;
88                                 }
89                         }
90                         if (lower_set && size_set) {
91                                 peapi_type = new PEAPI.BoundArray (peapi_type,
92                                                 (uint) dimen, lower_array, size_array);
93                         } else if (size_set) {
94                                 peapi_type = new PEAPI.BoundArray (peapi_type,
95                                                 (uint) dimen, size_array);
96                         } else {
97                                 peapi_type = new PEAPI.BoundArray (peapi_type, (uint) dimen);
98                         }
99                         is_array = true;
100                 }
101
102                 public void MakeManagedPointer ()
103                 {
104                         use_type_spec = true;
105
106                         peapi_type = new PEAPI.ManagedPointer (peapi_type);
107                         is_ref = true;
108                 }
109
110                 public void MakeUnmanagedPointer ()
111                 {
112                         use_type_spec = true;
113
114                         peapi_type = new PEAPI.UnmanagedPointer (peapi_type);
115                 }
116
117                 public void MakeCustomModified (CodeGen code_gen, PEAPI.CustomModifier modifier,
118                                 IClassRef klass)
119                 {
120                         use_type_spec = true;
121
122                         klass.Resolve (code_gen);
123                         peapi_type = new PEAPI.CustomModifiedType (peapi_type,
124                                         modifier, klass.PeapiClass);
125                 }
126
127                 public void MakePinned ()
128                 {
129                         use_type_spec = true;
130                         is_pinned = true;
131                 }
132
133                 public void Resolve (CodeGen code_gen)
134                 {
135
136                 }
137
138
139         }
140
141 }
142