**** Merged from MCS ****
[mono-project.git] / mcs / ilasm / codegen / PeapiTypeRef.cs
blob959c6b762c4aff65ef66ef1a73832f72a5b74390
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 //
11 using System;
12 using System.Collections;
14 namespace Mono.ILASM {
16 public class PeapiTypeRef {
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;
24 public PeapiTypeRef (PEAPI.Type peapi_type)
26 this.peapi_type = peapi_type;
27 is_pinned = false;
28 is_array = false;
29 is_ref = false;
30 use_type_spec = false;
33 public bool IsPinned {
34 get { return is_pinned; }
37 public bool IsArray {
38 get { return is_array; }
41 public bool IsRef {
42 get { return is_ref; }
45 public bool UseTypeSpec {
46 get { return use_type_spec; }
49 public PEAPI.Type PeapiType {
50 get { return peapi_type; }
53 public void MakeArray ()
55 use_type_spec = true;
56 peapi_type = new PEAPI.ZeroBasedArray (peapi_type);
57 is_array = true;
60 public void MakeBoundArray (ArrayList bound_list)
62 use_type_spec = true;
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;
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 if (bound_list [i] != null) {
76 DictionaryEntry bound = (DictionaryEntry) bound_list[i];
78 if (bound.Key != TypeRef.Ellipsis && prev_lower_set) {
79 lower_array[i] = (int) bound.Key;
80 lower_set = true;
81 } else {
82 prev_lower_set = false;
84 if (bound.Value != TypeRef.Ellipsis && prev_size_set) {
85 size_array[i] = (int) bound.Value;
86 size_set = true;
87 } else {
88 prev_size_set = false;
92 if (lower_set && size_set) {
93 peapi_type = new PEAPI.BoundArray (peapi_type,
94 (uint) dimen, lower_array, size_array);
95 } else if (size_set) {
96 peapi_type = new PEAPI.BoundArray (peapi_type,
97 (uint) dimen, size_array);
98 } else {
99 peapi_type = new PEAPI.BoundArray (peapi_type, (uint) dimen);
101 is_array = true;
104 public void MakeManagedPointer ()
106 use_type_spec = true;
108 peapi_type = new PEAPI.ManagedPointer (peapi_type);
109 is_ref = true;
112 public void MakeUnmanagedPointer ()
114 use_type_spec = true;
116 peapi_type = new PEAPI.UnmanagedPointer (peapi_type);
119 public void MakeCustomModified (CodeGen code_gen, PEAPI.CustomModifier modifier,
120 IClassRef klass)
122 use_type_spec = true;
124 klass.Resolve (code_gen);
125 peapi_type = new PEAPI.CustomModifiedType (peapi_type,
126 modifier, klass.PeapiClass);
129 public void MakePinned ()
131 use_type_spec = true;
132 is_pinned = true;
135 public void Resolve (CodeGen code_gen)