Welcome to mirror list, hosted at ThFree Co, Russian Federation.

PeapiTypeRef.cs « codegen « ilasm « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 704ba2df08699924cbae80fbe0e3d0a1a93ed0fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
//
// Mono.ILASM.PeapiTypeRef
//
// Author(s):
//  Jackson Harper (Jackson@LatitudeGeo.com)
//
// (C) 2003 Jackson Harper, All rights reserved
//


using System;
using System.Collections;

namespace Mono.ILASM {
        public class Pair {
                private PEAPI.Type type;
                private string sig;

                public Pair (PEAPI.Type type, string sig)
                {
                        this.type = type;
                        this.sig = sig;
                }

                public override int GetHashCode ()
                {
                        return type.GetHashCode () ^ sig.GetHashCode (); 
                }

                public override bool Equals (Object o)
                {
                        Pair p = o as Pair;

                        if (p == null)
                                return false;
                        
                        return (p.type == this.type && p.sig == this.sig);
                }
        }

        public class PeapiTypeRef  {

                private PEAPI.Type peapi_type;
                private bool is_pinned;
                private bool is_array;
                private bool is_ref;
                private bool use_type_spec;

                private static Hashtable type_table = new Hashtable ();

                public PeapiTypeRef (PEAPI.Type peapi_type)
                {
                        this.peapi_type = peapi_type;
                        is_pinned = false;
                        is_array = false;
                        is_ref = false;
                        use_type_spec = false;
                }

                public bool IsPinned {
                        get { return is_pinned; }
                }

                public bool IsArray {
                        get { return is_array; }
                }

                public bool IsRef {
                        get { return is_ref; }
                }

                public bool UseTypeSpec {
                        get { return use_type_spec; }
                }

                public PEAPI.Type PeapiType {
                        get { return peapi_type; }
                }

                public void MakeArray ()
                {
                        PEAPI.Type type;

                        use_type_spec = true;
                        is_array = true;

                        Pair p = new Pair (peapi_type, "[]");
                        type = type_table [p] as PEAPI.Type;
                        if (type == null) {
                                type = new PEAPI.ZeroBasedArray (peapi_type);
                                type_table [p] = type;
                        }
                        peapi_type = type;
                }

                public void MakeBoundArray (ArrayList bound_list)
                {
                        use_type_spec = true;
                        is_array = true;

                        int dimen = bound_list.Count;
                        int[] lower_array = new int[dimen];
                        int[] size_array = new int[dimen];
                        int [] lobounds = null;
                        int [] sizes = null;
                        int num_lower, num_sizes;
                        string sigmod = "";
                        PEAPI.Type type;
                        Pair p;

                        sigmod += "[";
                        for (int i=0; i<bound_list.Count; i++) {
                                DictionaryEntry e = (DictionaryEntry) bound_list [i];
                                if (e.Key != TypeRef.Ellipsis)
                                        sigmod += e.Key;
                                sigmod += "...";
                                if (e.Value != TypeRef.Ellipsis)
                                        sigmod += e.Value;
                                if (i + 1 < bound_list.Count)
                                        sigmod += ", ";
                        }
                        sigmod += "]";

                        p = new Pair (peapi_type, sigmod);
                        type = type_table [p] as PEAPI.Type;
                        if (type != null) {
                                peapi_type = type;
                                return;
                        }

                        num_sizes = num_lower = 0;
                        // TODO: There should probably be an error reported if
                        // something like [3...,3...5] is done
                        for (int i=0; i<dimen; i++) {
                                if (bound_list [i] == null)
                                        continue;
                                        
                                DictionaryEntry bound = (DictionaryEntry) bound_list [i];
                                
                                if (bound.Key != TypeRef.Ellipsis) {
                                        /* Lower bound specified */
                                        lower_array [i] = (int) bound.Key;
                                        num_lower = i + 1;
                                }
                                if (bound.Value != TypeRef.Ellipsis) {
                                        size_array [i] = (int) bound.Value;
                                        if (bound.Key != TypeRef.Ellipsis)
                                                /* .Value is Upper bound eg [1...5] */
                                                size_array [i] -= lower_array [i] - 1;
                                        num_sizes = i + 1;
                                }
                        }

                        if (num_lower > 0) {
                                lobounds = new int [num_lower];
                                Array.Copy (lower_array, lobounds, num_lower);
                        }

                        if (num_sizes > 0) {
                                sizes = new int [num_sizes];
                                Array.Copy (size_array, sizes, num_sizes);
                        }

                        peapi_type = new PEAPI.BoundArray (peapi_type,
                                                (uint) dimen, lobounds, sizes);
                        type_table [p] = peapi_type;
                }

                public void MakeManagedPointer ()
                {
                        PEAPI.Type type;
                        use_type_spec = true;
                        is_ref = true;

                        Pair p = new Pair (peapi_type, "&");
                        type = type_table [p] as PEAPI.Type;
                        if (type == null) {
                                type = new PEAPI.ManagedPointer (peapi_type);
                                type_table [p] = type;
                        }
                        peapi_type = type;
                }

                public void MakeUnmanagedPointer ()
                {
                        PEAPI.Type type;
                        use_type_spec = true;

                        Pair p = new Pair (peapi_type, "*");
                        type = type_table [p] as PEAPI.Type;
                        if (type == null) {
                                type = new PEAPI.UnmanagedPointer (peapi_type);
                                type_table [p] = type;
                        }
                        peapi_type = type;
                }

                public void MakeCustomModified (CodeGen code_gen, PEAPI.CustomModifier modifier,
                                BaseClassRef klass)
                {
			PEAPI.Type type;

                        use_type_spec = true;
                        
                        Pair p = new Pair (peapi_type, modifier.ToString ());
                        type = type_table [p] as PEAPI.Type;
                        if (type == null) {
                                klass.Resolve (code_gen);
                                type = new PEAPI.CustomModifiedType (peapi_type,
                                        modifier, klass.PeapiClass);
                                type_table [p] = type;
                        }
                        peapi_type = type;
                }

                public void MakePinned ()
                {
                        use_type_spec = true;
                        is_pinned = true;
                }

                public void Resolve (CodeGen code_gen)
                {

                }


        }

}