Mercurial > projects > ddmd
annotate dmd/Type.d @ 174:af724d3510d7
lot os toCBuffer methods implemented
moved shared Type.* stuff into Global
author | korDen |
---|---|
date | Sun, 10 Oct 2010 03:47:23 +0400 |
parents | 96c0fff6897d |
children | fa9a71a9f5a8 |
rev | line source |
---|---|
0 | 1 module dmd.Type; |
2 | |
114 | 3 import dmd.common; |
0 | 4 import dmd.TY; |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
5 import dmd.Parameter; |
0 | 6 import dmd.TOK; |
7 import dmd.STC; | |
8 import dmd.TypeArray; | |
9 import dmd.DotVarExp; | |
10 import dmd.ErrorExp; | |
11 import dmd.StringExp; | |
12 import dmd.IntegerExp; | |
13 import dmd.VarExp; | |
14 import dmd.TemplateParameter; | |
15 import dmd.TypeInfoSharedDeclaration; | |
16 import dmd.TypeInfoConstDeclaration; | |
17 import dmd.TypeInfoInvariantDeclaration; | |
18 import dmd.Module; | |
19 import dmd.Id; | |
20 import dmd.Util; | |
21 import dmd.VarDeclaration; | |
22 import dmd.Loc; | |
23 import dmd.Scope; | |
24 import dmd.OutBuffer; | |
25 import dmd.Identifier; | |
26 import dmd.HdrGenState; | |
27 import dmd.Expression; | |
28 import dmd.Dsymbol; | |
29 import dmd.MATCH; | |
30 import dmd.TypeInfoDeclaration; | |
31 import dmd.ClassDeclaration; | |
32 import dmd.StringTable; | |
33 import dmd.ArrayTypes; | |
34 import dmd.TypeBasic; | |
35 import dmd.DYNCAST; | |
36 import dmd.MOD; | |
37 import dmd.Lexer; | |
38 import dmd.TypeSArray; | |
39 import dmd.TypeDArray; | |
40 import dmd.TypeAArray; | |
41 import dmd.TypePointer; | |
42 import dmd.TypeReference; | |
43 import dmd.TypeFunction; | |
44 import dmd.TypeDelegate; | |
45 import dmd.TypeIdentifier; | |
46 import dmd.TypeInstance; | |
47 import dmd.TypeTypeof; | |
48 import dmd.TypeReturn; | |
49 import dmd.TypeStruct; | |
50 import dmd.TypeEnum; | |
51 import dmd.TypeTypedef; | |
52 import dmd.TypeClass; | |
53 import dmd.TypeTuple; | |
54 import dmd.TypeSlice; | |
55 import dmd.Global; | |
56 import dmd.StringValue; | |
131
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
57 import dmd.TRUST; |
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
58 import dmd.TemplateDeclaration; |
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
59 import dmd.DotIdExp; |
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
60 import dmd.AggregateDeclaration; |
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
61 import dmd.DotTemplateInstanceExp; |
135 | 62 import dmd.Token; |
63 import dmd.TypeInfoWildDeclaration; | |
131
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
64 |
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
65 import dmd.expression.Util; |
0 | 66 |
67 import dmd.backend.Symbol; | |
68 import dmd.backend.TYPE; | |
69 import dmd.backend.dt_t; | |
70 import dmd.backend.Util; | |
71 import dmd.backend.TYM; | |
72 import dmd.backend.mTY; | |
73 | |
74 import core.stdc.stdio; | |
75 | |
4 | 76 import core.memory; |
2 | 77 |
0 | 78 /* These have default values for 32 bit code, they get |
79 * adjusted for 64 bit code. | |
80 */ | |
81 | |
174 | 82 __gshared int PTRSIZE = 4; |
83 | |
84 __gshared int Tsize_t; | |
85 __gshared int Tptrdiff_t; | |
0 | 86 |
87 /* REALSIZE = size a real consumes in memory | |
88 * REALPAD = 'padding' added to the CPU real size to bring it up to REALSIZE | |
89 * REALALIGNSIZE = alignment for reals | |
90 */ | |
91 version (TARGET_OSX) { | |
157
b7b61140701d
* added all missing default cases in switch statements
trass3r
parents:
140
diff
changeset
|
92 extern(C++) __gshared int REALSIZE = 16; |
174 | 93 __gshared int REALPAD = 6; |
94 __gshared int REALALIGNSIZE = 16; | |
22
fd4acc376c45
Implemented object file output and linking on linux.
Robert Clipsham <robert@octarineparrot.com>
parents:
20
diff
changeset
|
95 } else version (POSIX) { /// TARGET_LINUX || TARGET_FREEBSD || TARGET_SOLARIS |
157
b7b61140701d
* added all missing default cases in switch statements
trass3r
parents:
140
diff
changeset
|
96 extern(C++) __gshared int REALSIZE = 12; |
174 | 97 __gshared int REALPAD = 2; |
98 __gshared int REALALIGNSIZE = 4; | |
0 | 99 } else { |
157
b7b61140701d
* added all missing default cases in switch statements
trass3r
parents:
140
diff
changeset
|
100 extern(C++) __gshared int REALSIZE = 10; |
174 | 101 __gshared int REALPAD = 0; |
102 __gshared int REALALIGNSIZE = 2; | |
0 | 103 } |
104 | |
105 /**** | |
106 * Given an identifier, figure out which TemplateParameter it is. | |
107 * Return -1 if not found. | |
108 */ | |
109 | |
110 int templateIdentifierLookup(Identifier id, TemplateParameters parameters) | |
111 { | |
121
347de076ad34
TemplateParameters -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
112 foreach (size_t i, TemplateParameter tp; parameters) |
174 | 113 { |
0 | 114 if (tp.ident.equals(id)) |
115 return i; | |
116 } | |
117 return -1; | |
118 } | |
119 | |
120 int templateParameterLookup(Type tparam, TemplateParameters parameters) | |
121 { | |
122 assert(tparam.ty == Tident); | |
123 TypeIdentifier tident = cast(TypeIdentifier)tparam; | |
124 //printf("\ttident = '%s'\n", tident.toChars()); | |
125 if (tident.idents.dim == 0) | |
126 { | |
127 return templateIdentifierLookup(tident.ident, parameters); | |
128 } | |
129 return -1; | |
130 } | |
131 | |
135 | 132 /*************************** |
133 * Return !=0 if modfrom can be implicitly converted to modto | |
134 */ | |
135 int MODimplicitConv(MOD modfrom, MOD modto) | |
136 { | |
137 if (modfrom == modto) | |
138 return 1; | |
139 | |
140 //printf("MODimplicitConv(from = %x, to = %x)\n", modfrom, modto); | |
141 static uint X(MOD m, MOD n) | |
142 { | |
143 return (((m) << 4) | (n)); | |
144 } | |
145 switch (X(modfrom, modto)) | |
146 { | |
147 case X(MOD.MODundefined, MOD.MODconst): | |
148 case X(MOD.MODimmutable, MOD.MODconst): | |
149 case X(MOD.MODwild, MOD.MODconst): | |
150 case X(MOD.MODimmutable, MOD.MODconst | MOD.MODshared): | |
151 case X(MOD.MODshared, MOD.MODconst | MOD.MODshared): | |
152 case X(MOD.MODwild | MOD.MODshared, MOD.MODconst | MOD.MODshared): | |
153 return 1; | |
154 | |
155 default: | |
156 return 0; | |
157 } | |
158 } | |
159 | |
160 /********************************* | |
161 * Mangling for mod. | |
162 */ | |
163 void MODtoDecoBuffer(OutBuffer buf, MOD mod) | |
164 { | |
165 switch (mod) | |
166 { | |
167 case MOD.MODundefined: | |
168 break; | |
169 case MOD.MODconst: | |
170 buf.writeByte('x'); | |
171 break; | |
172 case MOD.MODimmutable: | |
173 buf.writeByte('y'); | |
174 break; | |
175 case MOD.MODshared: | |
176 buf.writeByte('O'); | |
177 break; | |
178 case MOD.MODshared | MOD.MODconst: | |
179 buf.writestring("Ox"); | |
180 break; | |
181 case MOD.MODwild: | |
182 buf.writestring("Ng"); | |
183 break; | |
184 case MOD.MODshared | MOD.MODwild: | |
185 buf.writestring("ONg"); | |
186 break; | |
187 default: | |
188 assert(0); | |
189 } | |
190 } | |
191 | |
192 /********************************* | |
193 * Name for mod. | |
194 */ | |
195 void MODtoBuffer(OutBuffer buf, MOD mod) | |
196 { | |
197 switch (mod) | |
198 { | |
199 case MOD.MODundefined: | |
200 break; | |
201 | |
202 case MOD.MODimmutable: | |
203 buf.writestring(Token.tochars[TOK.TOKimmutable]); | |
204 break; | |
205 | |
206 case MOD.MODshared: | |
207 buf.writestring(Token.tochars[TOK.TOKshared]); | |
208 break; | |
209 | |
210 case MOD.MODshared | MOD.MODconst: | |
211 buf.writestring(Token.tochars[TOK.TOKshared]); | |
212 buf.writeByte(' '); | |
213 case MOD.MODconst: | |
214 buf.writestring(Token.tochars[TOK.TOKconst]); | |
215 break; | |
216 | |
217 case MOD.MODshared | MOD.MODwild: | |
218 buf.writestring(Token.tochars[TOK.TOKshared]); | |
219 buf.writeByte(' '); | |
220 case MOD.MODwild: | |
221 buf.writestring(Token.tochars[TOKwild]); | |
222 break; | |
223 default: | |
224 assert(0); | |
225 } | |
226 } | |
227 | |
0 | 228 class Type |
229 { | |
230 TY ty; | |
231 MOD mod; // modifiers MODxxxx | |
232 /* pick this order of numbers so switch statements work better | |
233 */ | |
234 /// #define MODconst 1 // type is const | |
95 | 235 /// #define MODinvariant 4 // type is immutable |
236 /// #define MODimmutable 4 // type is immutable | |
0 | 237 /// #define MODshared 2 // type is shared |
238 string deco; | |
239 | |
240 /* These are cached values that are lazily evaluated by constOf(), invariantOf(), etc. | |
241 * They should not be referenced by anybody but mtype.c. | |
242 * They can be null if not lazily evaluated yet. | |
243 * Note that there is no "shared immutable", because that is just immutable | |
135 | 244 * Naked == no MOD bits |
0 | 245 */ |
246 | |
135 | 247 Type cto; // MODconst ? naked version of this type : const version |
248 Type ito; // MODimmutable ? naked version of this type : immutable version | |
249 Type sto; // MODshared ? naked version of this type : shared mutable version | |
250 Type scto; // MODshared|MODconst ? naked version of this type : shared const version | |
251 Type wto; // MODwild ? naked version of this type : wild version | |
252 Type swto; // MODshared|MODwild ? naked version of this type : shared wild version | |
253 | |
0 | 254 |
255 Type pto; // merged pointer to this type | |
256 Type rto; // reference to this type | |
257 Type arrayof; // array of this type | |
258 TypeInfoDeclaration vtinfo; // TypeInfo object for this Type | |
259 | |
260 type* ctype; // for back end | |
261 | |
174 | 262 static __gshared Type basic[TY.TMAX]; |
263 static __gshared ubyte mangleChar[TY.TMAX]; | |
264 static __gshared ubyte sizeTy[TY.TMAX]; | |
0 | 265 |
266 // These tables are for implicit conversion of binary ops; | |
267 // the indices are the type of operand one, followed by operand two. | |
174 | 268 static __gshared ubyte impcnvResult[TY.TMAX][TY.TMAX] = [ |
0 | 269 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], |
270 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
271 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
272 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
273 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
274 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
275 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
276 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
277 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
278 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
279 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
280 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
281 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
282 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
283 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
284 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,19,19,19,19,19,20,21,22,23,24,25,23,24,25,29,30,31,37,19,37,37,37,37,37,37,37,37,37], | |
285 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,19,19,19,19,19,20,21,22,23,24,25,23,24,25,29,30,31,37,19,37,37,37,37,37,37,37,37,37], | |
286 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,19,19,19,19,19,20,21,22,23,24,25,23,24,25,29,30,31,37,19,37,37,37,37,37,37,37,37,37], | |
287 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,19,19,19,19,19,20,21,22,23,24,25,23,24,25,29,30,31,37,19,37,37,37,37,37,37,37,37,37], | |
288 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,19,19,19,19,19,20,21,22,23,24,25,23,24,25,29,30,31,37,19,37,37,37,37,37,37,37,37,37], | |
289 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,20,20,20,20,20,20,21,22,23,24,25,23,24,25,29,30,31,37,20,37,37,37,37,37,37,37,37,37], | |
290 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,21,21,21,21,21,21,21,22,23,24,25,23,24,25,29,30,31,37,21,37,37,37,37,37,37,37,37,37], | |
291 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,22,22,22,22,22,22,22,22,23,24,25,23,24,25,29,30,31,37,22,37,37,37,37,37,37,37,37,37], | |
292 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,23,23,23,23,23,23,23,23,23,24,25,23,24,25,29,30,31,37,23,37,37,37,37,37,37,37,37,37], | |
293 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,24,24,24,24,24,24,24,24,24,24,25,24,24,25,30,30,31,37,24,37,37,37,37,37,37,37,37,37], | |
294 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,25,25,25,25,25,25,25,25,25,25,25,25,25,25,31,31,31,37,25,37,37,37,37,37,37,37,37,37], | |
295 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,23,23,23,23,23,23,23,23,23,24,25,26,27,28,29,30,31,37,23,37,37,37,37,37,37,37,37,37], | |
296 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,24,24,24,24,24,24,24,24,24,24,25,27,27,28,30,30,31,37,24,37,37,37,37,37,37,37,37,37], | |
297 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,25,25,25,25,25,25,25,25,25,25,25,28,28,28,31,31,31,37,25,37,37,37,37,37,37,37,37,37], | |
298 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,29,29,29,29,29,29,29,29,29,30,31,29,30,31,29,30,31,37,29,37,37,37,37,37,37,37,37,37], | |
299 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,30,30,30,30,30,30,30,30,30,30,31,30,30,31,30,30,31,37,30,37,37,37,37,37,37,37,37,37], | |
300 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,37,31,37,37,37,37,37,37,37,37,37], | |
301 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
302 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,19,19,19,19,19,20,21,22,23,24,25,23,24,25,29,30,31,37,33,37,37,37,37,37,37,37,37,37], | |
303 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
304 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
305 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
306 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
307 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
308 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
309 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
310 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
311 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
312 ]; | |
313 | |
174 | 314 static __gshared ubyte impcnvType1[TY.TMAX][TY.TMAX] = [ |
0 | 315 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], |
316 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
317 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
318 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
319 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
320 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
321 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
322 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
323 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
324 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
325 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
326 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
327 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
328 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
329 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
330 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,19,19,19,19,19,20,21,22,23,24,25,23,24,25,23,24,25,37,19,37,37,37,37,37,37,37,37,37], | |
331 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,19,19,19,19,19,20,21,22,23,24,25,23,24,25,23,24,25,37,19,37,37,37,37,37,37,37,37,37], | |
332 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,19,19,19,19,19,20,21,22,23,24,25,23,24,25,23,24,25,37,19,37,37,37,37,37,37,37,37,37], | |
333 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,19,19,19,19,19,20,21,22,23,24,25,23,24,25,23,24,25,37,19,37,37,37,37,37,37,37,37,37], | |
334 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,19,19,19,19,19,20,21,22,23,24,25,23,24,25,23,24,25,37,19,37,37,37,37,37,37,37,37,37], | |
335 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,20,20,20,20,20,20,21,22,23,24,25,23,24,25,23,24,25,37,20,37,37,37,37,37,37,37,37,37], | |
336 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,21,21,21,21,21,21,21,22,23,24,25,23,24,25,23,24,25,37,21,37,37,37,37,37,37,37,37,37], | |
337 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,22,22,22,22,22,22,22,22,23,24,25,23,24,25,23,24,25,37,22,37,37,37,37,37,37,37,37,37], | |
338 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,23,23,23,23,23,23,23,23,23,24,25,23,24,25,23,24,25,37,23,37,37,37,37,37,37,37,37,37], | |
339 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,24,24,24,24,24,24,24,24,24,24,25,24,24,25,24,24,25,37,24,37,37,37,37,37,37,37,37,37], | |
340 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,37,25,37,37,37,37,37,37,37,37,37], | |
341 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,26,26,26,26,26,26,26,26,26,27,28,26,27,28,26,27,28,37,26,37,37,37,37,37,37,37,37,37], | |
342 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,27,27,27,27,27,27,27,27,27,27,28,27,27,28,27,27,28,37,27,37,37,37,37,37,37,37,37,37], | |
343 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,37,28,37,37,37,37,37,37,37,37,37], | |
344 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,29,29,29,29,29,29,29,29,29,30,31,29,30,31,29,30,31,37,29,37,37,37,37,37,37,37,37,37], | |
345 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,30,30,30,30,30,30,30,30,30,30,31,30,30,31,30,30,31,37,30,37,37,37,37,37,37,37,37,37], | |
346 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,31,37,31,37,37,37,37,37,37,37,37,37], | |
347 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
348 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,19,19,19,19,19,20,21,22,23,24,25,23,24,25,23,24,25,37,33,37,37,37,37,37,37,37,37,37], | |
349 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
350 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
351 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
352 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
353 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
354 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
355 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
356 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
357 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
358 ]; | |
174 | 359 |
360 static __gshared ubyte impcnvType2[TY.TMAX][TY.TMAX] = [ | |
0 | 361 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], |
362 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
363 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
364 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
365 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
366 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
367 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
368 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
369 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
370 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
371 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
372 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
373 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
374 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
375 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
376 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,19,19,19,19,19,20,21,22,23,24,25,26,27,28,29,30,31,37,19,37,37,37,37,37,37,37,37,37], | |
377 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,19,19,19,19,19,20,21,22,23,24,25,26,27,28,29,30,31,37,19,37,37,37,37,37,37,37,37,37], | |
378 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,19,19,19,19,19,20,21,22,23,24,25,26,27,28,29,30,31,37,19,37,37,37,37,37,37,37,37,37], | |
379 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,19,19,19,19,19,20,21,22,23,24,25,26,27,28,29,30,31,37,19,37,37,37,37,37,37,37,37,37], | |
380 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,19,19,19,19,19,20,21,22,23,24,25,26,27,28,29,30,31,37,19,37,37,37,37,37,37,37,37,37], | |
381 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,20,20,20,20,20,20,21,22,23,24,25,26,27,28,29,30,31,37,20,37,37,37,37,37,37,37,37,37], | |
382 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,21,21,21,21,21,21,21,22,23,24,25,26,27,28,29,30,31,37,21,37,37,37,37,37,37,37,37,37], | |
383 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,22,22,22,22,22,22,22,22,23,24,25,26,27,28,29,30,31,37,22,37,37,37,37,37,37,37,37,37], | |
384 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,23,23,23,23,23,23,23,23,23,24,25,26,27,28,29,30,31,37,23,37,37,37,37,37,37,37,37,37], | |
385 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,24,24,24,24,24,24,24,24,24,24,25,27,27,28,30,30,31,37,24,37,37,37,37,37,37,37,37,37], | |
386 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,25,25,25,25,25,25,25,25,25,25,25,28,28,28,31,31,31,37,25,37,37,37,37,37,37,37,37,37], | |
387 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,23,23,23,23,23,23,23,23,23,24,25,26,27,28,29,30,31,37,23,37,37,37,37,37,37,37,37,37], | |
388 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,24,24,24,24,24,24,24,24,24,24,25,27,27,28,30,30,31,37,24,37,37,37,37,37,37,37,37,37], | |
389 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,25,25,25,25,25,25,25,25,25,25,25,28,28,28,31,31,31,37,25,37,37,37,37,37,37,37,37,37], | |
390 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,23,23,23,23,23,23,23,23,23,24,25,26,27,28,29,30,31,37,23,37,37,37,37,37,37,37,37,37], | |
391 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,24,24,24,24,24,24,24,24,24,24,25,27,27,28,30,30,31,37,24,37,37,37,37,37,37,37,37,37], | |
392 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,25,25,25,25,25,25,25,25,25,25,25,28,28,28,31,31,31,37,25,37,37,37,37,37,37,37,37,37], | |
393 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
394 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,19,19,19,19,19,20,21,22,23,24,25,26,27,28,29,30,31,37,33,37,37,37,37,37,37,37,37,37], | |
395 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
396 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
397 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
398 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
399 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
400 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
401 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
402 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
403 [37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37], | |
404 ]; | |
405 | |
406 // If !=0, give warning on implicit conversion | |
174 | 407 static __gshared const(bool) impcnvWarn[TY.TMAX][TY.TMAX] = [ |
0 | 408 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], |
409 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
410 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
411 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
412 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
413 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
414 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
415 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
416 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
417 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
418 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
419 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
420 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
421 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
422 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
423 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0], | |
424 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
425 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0], | |
426 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0], | |
427 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0], | |
428 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0], | |
429 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,0,1,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0], | |
430 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0], | |
431 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
432 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
433 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
434 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
435 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
436 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
437 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
438 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
439 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
440 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
441 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
442 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
443 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
444 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
445 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
446 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
447 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
448 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
449 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
450 [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], | |
451 ]; | |
452 | |
453 this(TY ty) | |
454 { | |
455 this.ty = ty; | |
456 } | |
174 | 457 |
0 | 458 Type syntaxCopy() |
459 { | |
460 assert(false); | |
461 } | |
462 | |
45 | 463 bool equals(Object o) |
0 | 464 { |
465 Type t = cast(Type)o; | |
466 //printf("Type.equals(%s, %s)\n", toChars(), t.toChars()); | |
467 if (this is o || (t && deco == t.deco) && // deco strings are unique | |
468 deco !is null) // and semantic() has been run | |
469 { | |
470 //printf("deco = '%s', t.deco = '%s'\n", deco, t.deco); | |
471 return 1; | |
472 } | |
473 //if (deco && t && t.deco) printf("deco = '%s', t.deco = '%s'\n", deco, t.deco); | |
474 return 0; | |
475 } | |
174 | 476 |
0 | 477 DYNCAST dyncast() { return DYNCAST.DYNCAST_TYPE; } // kludge for template.isType() |
478 | |
479 /******************************* | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
480 * Covariant means that 'this' can substitute for 't', |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
481 * i.e. a pure function is a match for an impure type. * Returns: |
0 | 482 * 0 types are distinct |
483 * 1 this is covariant with t | |
484 * 2 arguments match as far as overloading goes, | |
485 * but types are not covariant | |
486 * 3 cannot determine covariance because of forward references | |
487 */ | |
488 int covariant(Type t) | |
489 { | |
79 | 490 static if (false) |
491 { | |
0 | 492 printf("Type.covariant(t = %s) %s\n", t.toChars(), toChars()); |
493 printf("deco = %p, %p\n", deco, t.deco); | |
494 // printf("ty = %d\n", next.ty); | |
495 printf("mod = %x, %x\n", mod, t.mod); | |
496 } | |
497 | |
498 int inoutmismatch = 0; | |
499 | |
500 TypeFunction t1; | |
501 TypeFunction t2; | |
502 | |
503 if (equals(t)) | |
504 return 1; // covariant | |
505 | |
506 if (ty != TY.Tfunction || t.ty != TY.Tfunction) | |
507 goto Ldistinct; | |
508 | |
509 t1 = cast(TypeFunction)this; | |
510 t2 = cast(TypeFunction)t; | |
511 | |
512 if (t1.varargs != t2.varargs) | |
513 goto Ldistinct; | |
514 | |
515 if (t1.parameters && t2.parameters) | |
516 { | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
517 size_t dim = Parameter.dim(t1.parameters); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
518 if (dim != Parameter.dim(t2.parameters)) |
0 | 519 goto Ldistinct; |
520 | |
521 for (size_t i = 0; i < dim; i++) | |
174 | 522 { |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
523 auto arg1 = Parameter.getNth(t1.parameters, i); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
524 auto arg2 = Parameter.getNth(t2.parameters, i); |
0 | 525 |
526 if (!arg1.type.equals(arg2.type)) | |
527 { | |
528 ///static if (false) { | |
529 /// // turn on this for contravariant argument types, see bugzilla 3075 | |
98 | 530 /// // BUG: cannot convert ref to const to ref to immutable |
0 | 531 /// // We can add const, but not subtract it |
532 /// if (arg2.type.implicitConvTo(arg1.type) < MATCH.MATCHconst) | |
533 ///} | |
534 goto Ldistinct; | |
535 } | |
131
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
536 const StorageClass sc = STC.STCref | STC.STCin | STC.STCout | STC.STClazy; |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
537 if ((arg1.storageClass & sc) != (arg2.storageClass & sc)) |
0 | 538 inoutmismatch = 1; |
539 // We can add scope, but not subtract it | |
540 if (!(arg1.storageClass & STC.STCscope) && (arg2.storageClass & STC.STCscope)) | |
541 inoutmismatch = 1; | |
542 } | |
543 } | |
544 else if (t1.parameters != t2.parameters) | |
545 goto Ldistinct; | |
546 | |
547 // The argument lists match | |
548 if (inoutmismatch) | |
549 goto Lnotcovariant; | |
550 if (t1.linkage != t2.linkage) | |
551 goto Lnotcovariant; | |
552 | |
553 { | |
554 // Return types | |
555 Type t1n = t1.next; | |
556 Type t2n = t2.next; | |
557 | |
79 | 558 if (t1n is null || t2n is null) // happens with return type inference |
559 goto Lnotcovariant; | |
560 | |
0 | 561 if (t1n.equals(t2n)) |
562 goto Lcovariant; | |
563 if (t1n.ty == TY.Tclass && t2n.ty == TY.Tclass) | |
564 { | |
565 /* If same class type, but t2n is const, then it's | |
566 * covariant. Do this test first because it can work on | |
567 * forward references. | |
568 */ | |
569 if ((cast(TypeClass)t1n).sym == (cast(TypeClass)t2n).sym && | |
135 | 570 MODimplicitConv(t1n.mod, t2n.mod)) |
0 | 571 goto Lcovariant; |
572 | |
573 // If t1n is forward referenced: | |
574 ClassDeclaration cd = (cast(TypeClass)t1n).sym; | |
575 if (!cd.baseClass && cd.baseclasses.dim && !cd.isInterfaceDeclaration()) | |
576 { | |
577 return 3; | |
578 } | |
579 } | |
580 if (t1n.implicitConvTo(t2n)) | |
581 goto Lcovariant; | |
582 } | |
583 | |
584 goto Lnotcovariant; | |
585 | |
586 Lcovariant: | |
587 /* Can convert mutable to const | |
588 */ | |
135 | 589 if (!MODimplicitConv(t2.mod, t1.mod)) |
590 goto Lnotcovariant; | |
591 static if(false) { | |
0 | 592 if (t1.mod != t2.mod) |
593 { | |
594 if (!(t1.mod & MOD.MODconst) && (t2.mod & MOD.MODconst)) | |
595 goto Lnotcovariant; | |
596 if (!(t1.mod & MOD.MODshared) && (t2.mod & MOD.MODshared)) | |
597 goto Lnotcovariant; | |
598 } | |
135 | 599 } |
0 | 600 /* Can convert pure to impure, and nothrow to throw |
601 */ | |
602 if (!t1.ispure && t2.ispure) | |
603 goto Lnotcovariant; | |
604 | |
605 if (!t1.isnothrow && t2.isnothrow) | |
606 goto Lnotcovariant; | |
607 | |
608 if (t1.isref != t2.isref) | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
609 goto Lnotcovariant; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
610 |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
611 /* Can convert safe/trusted to system |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
612 */ |
131
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
613 if (t1.trust <= TRUST.TRUSTsystem && t2.trust >= TRUST.TRUSTtrusted) |
0 | 614 goto Lnotcovariant; |
615 | |
616 //printf("\tcovaraint: 1\n"); | |
617 return 1; | |
618 | |
619 Ldistinct: | |
620 //printf("\tcovaraint: 0\n"); | |
621 return 0; | |
622 | |
623 Lnotcovariant: | |
624 //printf("\tcovaraint: 2\n"); | |
625 return 2; | |
626 } | |
627 | |
628 string toChars() | |
629 { | |
630 scope OutBuffer buf = new OutBuffer(); | |
631 | |
632 HdrGenState hgs; | |
633 toCBuffer(buf, null, &hgs); | |
634 return buf.toChars(); | |
635 } | |
174 | 636 |
0 | 637 static char needThisPrefix() |
638 { | |
639 return 'M'; // name mangling prefix for functions needing 'this' | |
640 } | |
174 | 641 |
0 | 642 static void init() |
643 { | |
644 Lexer.initKeywords(); | |
645 | |
646 for (int i = 0; i < TY.TMAX; i++) | |
647 sizeTy[i] = TypeBasic.sizeof; | |
648 | |
649 sizeTy[TY.Tsarray] = TypeSArray.sizeof; | |
650 sizeTy[TY.Tarray] = TypeDArray.sizeof; | |
651 //sizeTy[TY.Tnarray] = TypeNArray.sizeof; | |
652 sizeTy[TY.Taarray] = TypeAArray.sizeof; | |
653 sizeTy[TY.Tpointer] = TypePointer.sizeof; | |
654 sizeTy[TY.Treference] = TypeReference.sizeof; | |
655 sizeTy[TY.Tfunction] = TypeFunction.sizeof; | |
656 sizeTy[TY.Tdelegate] = TypeDelegate.sizeof; | |
657 sizeTy[TY.Tident] = TypeIdentifier.sizeof; | |
658 sizeTy[TY.Tinstance] = TypeInstance.sizeof; | |
659 sizeTy[TY.Ttypeof] = TypeTypeof.sizeof; | |
660 sizeTy[TY.Tenum] = TypeEnum.sizeof; | |
661 sizeTy[TY.Ttypedef] = TypeTypedef.sizeof; | |
662 sizeTy[TY.Tstruct] = TypeStruct.sizeof; | |
663 sizeTy[TY.Tclass] = TypeClass.sizeof; | |
664 sizeTy[TY.Ttuple] = TypeTuple.sizeof; | |
665 sizeTy[TY.Tslice] = TypeSlice.sizeof; | |
666 sizeTy[TY.Treturn] = TypeReturn.sizeof; | |
667 | |
668 mangleChar[TY.Tarray] = 'A'; | |
669 mangleChar[TY.Tsarray] = 'G'; | |
670 mangleChar[TY.Tnarray] = '@'; | |
671 mangleChar[TY.Taarray] = 'H'; | |
672 mangleChar[TY.Tpointer] = 'P'; | |
673 mangleChar[TY.Treference] = 'R'; | |
674 mangleChar[TY.Tfunction] = 'F'; | |
675 mangleChar[TY.Tident] = 'I'; | |
676 mangleChar[TY.Tclass] = 'C'; | |
677 mangleChar[TY.Tstruct] = 'S'; | |
678 mangleChar[TY.Tenum] = 'E'; | |
679 mangleChar[TY.Ttypedef] = 'T'; | |
680 mangleChar[TY.Tdelegate] = 'D'; | |
681 | |
682 mangleChar[TY.Tnone] = 'n'; | |
683 mangleChar[TY.Tvoid] = 'v'; | |
684 mangleChar[TY.Tint8] = 'g'; | |
685 mangleChar[TY.Tuns8] = 'h'; | |
686 mangleChar[TY.Tint16] = 's'; | |
687 mangleChar[TY.Tuns16] = 't'; | |
688 mangleChar[TY.Tint32] = 'i'; | |
689 mangleChar[TY.Tuns32] = 'k'; | |
690 mangleChar[TY.Tint64] = 'l'; | |
691 mangleChar[TY.Tuns64] = 'm'; | |
692 mangleChar[TY.Tfloat32] = 'f'; | |
693 mangleChar[TY.Tfloat64] = 'd'; | |
694 mangleChar[TY.Tfloat80] = 'e'; | |
695 | |
696 mangleChar[TY.Timaginary32] = 'o'; | |
697 mangleChar[TY.Timaginary64] = 'p'; | |
698 mangleChar[TY.Timaginary80] = 'j'; | |
699 mangleChar[TY.Tcomplex32] = 'q'; | |
700 mangleChar[TY.Tcomplex64] = 'r'; | |
701 mangleChar[TY.Tcomplex80] = 'c'; | |
702 | |
703 mangleChar[TY.Tbool] = 'b'; | |
704 mangleChar[TY.Tascii] = 'a'; | |
705 mangleChar[TY.Twchar] = 'u'; | |
706 mangleChar[TY.Tdchar] = 'w'; | |
707 | |
135 | 708 // '@' shouldn't appear anywhere in the deco'd names |
0 | 709 mangleChar[TY.Tbit] = '@'; |
710 mangleChar[TY.Tinstance] = '@'; | |
711 mangleChar[TY.Terror] = '@'; | |
712 mangleChar[TY.Ttypeof] = '@'; | |
713 mangleChar[TY.Ttuple] = 'B'; | |
714 mangleChar[TY.Tslice] = '@'; | |
715 mangleChar[TY.Treturn] = '@'; | |
716 | |
717 debug { | |
718 for (int i = 0; i < TY.TMAX; i++) { | |
719 if (!mangleChar[i]) { | |
720 writef("ty = %d\n", i); | |
721 } | |
722 assert(mangleChar[i]); | |
723 } | |
724 } | |
725 // Set basic types | |
174 | 726 enum TY[] basetab = [ |
0 | 727 TY.Tvoid, TY.Tint8, TY.Tuns8, TY.Tint16, TY.Tuns16, TY.Tint32, TY.Tuns32, TY.Tint64, TY.Tuns64, |
728 TY.Tfloat32, TY.Tfloat64, TY.Tfloat80, | |
729 TY.Timaginary32, TY.Timaginary64, TY.Timaginary80, | |
730 TY.Tcomplex32, TY.Tcomplex64, TY.Tcomplex80, | |
731 TY.Tbool, | |
732 TY.Tascii, TY.Twchar, TY.Tdchar | |
733 ]; | |
734 | |
735 foreach (bt; basetab) { | |
736 Type t = new TypeBasic(bt); | |
737 t = t.merge(); | |
738 basic[bt] = t; | |
739 } | |
740 | |
741 basic[TY.Terror] = basic[TY.Tint32]; | |
742 | |
743 tvoidptr = tvoid.pointerTo(); | |
98 | 744 tstring = tchar.invariantOf().arrayOf(); |
0 | 745 |
746 if (global.params.isX86_64) { | |
747 PTRSIZE = 8; | |
748 if (global.params.isLinux || global.params.isFreeBSD || global.params.isSolaris) | |
749 REALSIZE = 10; | |
750 else | |
751 REALSIZE = 8; | |
752 Tsize_t = TY.Tuns64; | |
753 Tptrdiff_t = TY.Tint64; | |
754 } | |
755 else | |
756 { | |
757 PTRSIZE = 4; | |
758 version (TARGET_OSX) { | |
759 REALSIZE = 16; | |
760 REALPAD = 6; | |
761 } else version (XXX) { //#elif TARGET_LINUX || TARGET_FREEBSD || TARGET_SOLARIS | |
762 REALSIZE = 12; | |
763 REALPAD = 2; | |
764 } else { | |
765 REALSIZE = 10; | |
766 REALPAD = 0; | |
767 } | |
768 Tsize_t = TY.Tuns32; | |
769 Tptrdiff_t = TY.Tint32; | |
770 } | |
771 } | |
174 | 772 |
0 | 773 ulong size() |
774 { | |
775 return size(Loc(0)); | |
776 } | |
174 | 777 |
0 | 778 ulong size(Loc loc) |
779 { | |
780 error(loc, "no size for type %s", toChars()); | |
781 return 1; | |
782 } | |
174 | 783 |
0 | 784 uint alignsize() |
785 { | |
786 return cast(uint)size(Loc(0)); /// | |
787 } | |
788 | |
789 Type semantic(Loc loc, Scope sc) | |
790 { | |
791 return merge(); | |
792 } | |
174 | 793 |
0 | 794 Type trySemantic(Loc loc, Scope sc) |
795 { | |
796 uint errors = global.errors; | |
797 global.gag++; // suppress printing of error messages | |
798 Type t = semantic(loc, sc); | |
799 global.gag--; | |
800 if (errors != global.errors) // if any errors happened | |
801 { | |
802 global.errors = errors; | |
803 t = null; | |
804 } | |
805 return t; | |
806 } | |
807 | |
808 /******************************** | |
809 * Name mangling. | |
810 * Input: | |
811 * flag 0x100 do not do const/invariant | |
812 */ | |
813 void toDecoBuffer(OutBuffer buf, int flag = 0) | |
20
1628b221808d
Fleshed out more unimplemented methods.
Robert Clipsham <robert@octarineparrot.com>
parents:
16
diff
changeset
|
814 { |
0 | 815 if (flag != mod && flag != 0x100) |
816 { | |
135 | 817 MODtoDecoBuffer(buf, mod); |
0 | 818 } |
819 buf.writeByte(mangleChar[ty]); | |
820 } | |
174 | 821 |
0 | 822 Type merge() |
823 { | |
824 Type t = this; | |
825 assert(t); | |
826 | |
827 //printf("merge(%s)\n", toChars()); | |
828 if (deco is null) | |
829 { | |
830 OutBuffer buf = new OutBuffer(); | |
831 | |
832 //if (next) | |
833 //next = next.merge(); | |
834 toDecoBuffer(buf); | |
174 | 835 StringValue* sv = global.type_stringtable.update(buf.extractString()); |
0 | 836 if (sv.ptrvalue) |
837 { | |
838 t = cast(Type) sv.ptrvalue; | |
839 debug { | |
840 if (!t.deco) | |
841 writef("t = %s\n", t.toChars()); | |
842 } | |
843 assert(t.deco); | |
844 //printf("old value, deco = '%s' %p\n", t.deco, t.deco); | |
845 } | |
846 else | |
847 { | |
848 sv.ptrvalue = cast(void*)this; | |
849 deco = sv.lstring.string_; | |
850 //printf("new value, deco = '%s' %p\n", t.deco, t.deco); | |
851 } | |
852 } | |
853 return t; | |
854 } | |
855 | |
856 /************************************* | |
857 * This version does a merge even if the deco is already computed. | |
858 * Necessary for types that have a deco, but are not merged. | |
859 */ | |
860 Type merge2() | |
861 { | |
862 //printf("merge2(%s)\n", toChars()); | |
863 Type t = this; | |
864 assert(t); | |
865 if (!t.deco) | |
866 return t.merge(); | |
867 | |
174 | 868 StringValue* sv = global.type_stringtable.lookup(t.deco); |
0 | 869 if (sv && sv.ptrvalue) |
174 | 870 { |
0 | 871 t = cast(Type)sv.ptrvalue; |
872 assert(t.deco); | |
873 } | |
874 else | |
875 assert(0); | |
876 | |
877 return t; | |
878 } | |
879 | |
880 void toCBuffer(OutBuffer buf, Identifier ident, HdrGenState* hgs) | |
881 { | |
882 toCBuffer2(buf, hgs, MOD.MODundefined); | |
883 if (ident) | |
884 { | |
885 buf.writeByte(' '); | |
886 buf.writestring(ident.toChars()); | |
887 } | |
888 } | |
889 | |
890 void toCBuffer2(OutBuffer buf, HdrGenState* hgs, MOD mod) | |
891 { | |
892 if (mod != this.mod) | |
174 | 893 { |
0 | 894 toCBuffer3(buf, hgs, mod); |
895 return; | |
896 } | |
897 buf.writestring(toChars()); | |
898 } | |
899 | |
900 void toCBuffer3(OutBuffer buf, HdrGenState* hgs, MOD mod) | |
901 { | |
902 if (mod != this.mod) | |
903 { | |
904 if (this.mod & MOD.MODshared) | |
135 | 905 { |
906 MODtoBuffer(buf, this.mod & MOD.MODshared); | |
907 buf.writeByte('('); | |
908 } | |
0 | 909 |
135 | 910 if (this.mod & ~MOD.MODshared) |
911 { | |
912 MODtoBuffer(buf, this.mod & ~MOD.MODshared); | |
913 buf.writeByte('('); | |
914 toCBuffer2(buf, hgs, this.mod); | |
915 buf.writeByte(')'); | |
916 } | |
917 else | |
918 toCBuffer2(buf, hgs, this.mod); | |
919 if (this.mod & MOD.MODshared) | |
920 { | |
921 buf.writeByte(')'); | |
922 } | |
0 | 923 } |
924 } | |
925 | |
926 void modToBuffer(OutBuffer buf) | |
927 { | |
135 | 928 if (mod) |
929 { | |
930 buf.writeByte(' '); | |
931 MODtoBuffer(buf, mod); | |
932 } | |
0 | 933 } |
934 | |
935 version (CPP_MANGLE) { | |
936 void toCppMangle(OutBuffer buf, CppMangleState* cms) | |
937 { | |
938 assert(false); | |
939 } | |
940 } | |
941 bool isintegral() | |
942 { | |
943 return false; | |
944 } | |
174 | 945 |
0 | 946 bool isfloating() // real, imaginary, or complex |
947 { | |
948 return false; | |
949 } | |
174 | 950 |
0 | 951 bool isreal() |
952 { | |
953 return false; | |
954 } | |
174 | 955 |
0 | 956 bool isimaginary() |
957 { | |
958 return false; | |
959 } | |
174 | 960 |
0 | 961 bool iscomplex() |
962 { | |
963 return false; | |
964 } | |
174 | 965 |
0 | 966 bool isscalar() |
967 { | |
968 return false; | |
969 } | |
174 | 970 |
0 | 971 bool isunsigned() |
972 { | |
973 return false; | |
974 } | |
174 | 975 |
0 | 976 bool isauto() |
977 { | |
978 return false; | |
979 } | |
174 | 980 |
12
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
4
diff
changeset
|
981 bool isString() |
0 | 982 { |
983 return false; | |
984 } | |
174 | 985 |
0 | 986 /************************** |
987 * Given: | |
988 * T a, b; | |
989 * Can we assign: | |
990 * a = b; | |
991 * ? | |
992 */ | |
73 | 993 bool isAssignable() |
0 | 994 { |
995 return true; | |
996 } | |
174 | 997 |
0 | 998 bool checkBoolean() // if can be converted to boolean value |
999 { | |
1000 return isscalar(); | |
1001 } | |
1002 | |
1003 /********************************* | |
1004 * Check type to see if it is based on a deprecated symbol. | |
1005 */ | |
1006 void checkDeprecated(Loc loc, Scope sc) | |
1007 { | |
1008 Dsymbol s = toDsymbol(sc); | |
1009 if (s) | |
1010 s.checkDeprecated(loc, sc); | |
1011 } | |
1012 | |
1013 bool isConst() { return (mod & MOD.MODconst) != 0; } | |
1014 | |
135 | 1015 int isImmutable() { return mod & MOD.MODimmutable; } |
0 | 1016 |
135 | 1017 int isMutable() { return !(mod & (MOD.MODconst | MOD.MODimmutable | MOD.MODwild)); } |
0 | 1018 |
1019 int isShared() { return mod & MOD.MODshared; } | |
1020 | |
1021 int isSharedConst() { return mod == (MOD.MODshared | MOD.MODconst); } | |
174 | 1022 |
135 | 1023 int isWild() { return mod & MOD.MODwild; } |
1024 | |
1025 int isSharedWild() { return mod == (MOD.MODshared | MOD.MODwild); } | |
1026 | |
1027 int isNaked() { return mod == 0; } | |
1028 | |
0 | 1029 |
1030 /******************************** | |
1031 * Convert to 'const'. | |
1032 */ | |
1033 Type constOf() | |
1034 { | |
1035 //printf("Type.constOf() %p %s\n", this, toChars()); | |
1036 if (mod == MOD.MODconst) | |
1037 return this; | |
1038 if (cto) | |
1039 { | |
1040 assert(cto.mod == MOD.MODconst); | |
1041 return cto; | |
1042 } | |
1043 Type t = makeConst(); | |
1044 t = t.merge(); | |
1045 t.fixTo(this); | |
1046 //printf("-Type.constOf() %p %s\n", t, toChars()); | |
1047 return t; | |
1048 } | |
1049 | |
1050 /******************************** | |
1051 * Convert to 'immutable'. | |
1052 */ | |
1053 Type invariantOf() | |
174 | 1054 { |
0 | 1055 //printf("Type.invariantOf() %p %s\n", this, toChars()); |
135 | 1056 if (isImmutable()) |
0 | 1057 { |
1058 return this; | |
1059 } | |
1060 if (ito) | |
1061 { | |
135 | 1062 assert(ito.isImmutable()); |
0 | 1063 return ito; |
1064 } | |
1065 Type t = makeInvariant(); | |
1066 t = t.merge(); | |
1067 t.fixTo(this); | |
1068 //printf("\t%p\n", t); | |
1069 return t; | |
1070 } | |
1071 | |
1072 Type mutableOf() | |
1073 { | |
1074 //printf("Type.mutableOf() %p, %s\n", this, toChars()); | |
1075 Type t = this; | |
1076 if (isConst()) | |
174 | 1077 { |
0 | 1078 if (isShared()) |
1079 t = sto; // shared const => shared | |
1080 else | |
135 | 1081 t = cto; // const => naked |
0 | 1082 assert(!t || t.isMutable()); |
1083 } | |
135 | 1084 else if (isImmutable()) |
174 | 1085 { |
0 | 1086 t = ito; |
1087 assert(!t || (t.isMutable() && !t.isShared())); | |
1088 } | |
135 | 1089 else if (isWild()) |
1090 { | |
1091 if (isShared()) | |
1092 t = sto; // shared wild => shared | |
1093 else | |
1094 t = wto; // wild => naked | |
1095 assert(!t || t.isMutable()); | |
1096 } | |
0 | 1097 if (!t) |
1098 { | |
135 | 1099 t = makeMutable(); |
0 | 1100 t = t.merge(); |
1101 t.fixTo(this); | |
1102 } | |
135 | 1103 assert(t.isMutable()); |
0 | 1104 return t; |
1105 } | |
1106 | |
1107 Type sharedOf() | |
1108 { | |
1109 //printf("Type.sharedOf() %p, %s\n", this, toChars()); | |
1110 if (mod == MOD.MODshared) | |
1111 { | |
1112 return this; | |
1113 } | |
1114 if (sto) | |
1115 { | |
1116 assert(sto.isShared()); | |
1117 return sto; | |
1118 } | |
1119 | |
1120 Type t = makeShared(); | |
1121 t = t.merge(); | |
1122 t.fixTo(this); | |
1123 | |
1124 //printf("\t%p\n", t); | |
1125 return t; | |
1126 } | |
1127 | |
1128 Type sharedConstOf() | |
1129 { | |
1130 //printf("Type.sharedConstOf() %p, %s\n", this, toChars()); | |
1131 if (mod == (MODshared | MODconst)) | |
1132 { | |
1133 return this; | |
1134 } | |
1135 if (scto) | |
1136 { | |
1137 assert(scto.mod == (MODshared | MODconst)); | |
1138 return scto; | |
1139 } | |
1140 | |
1141 Type t = makeSharedConst(); | |
1142 t = t.merge(); | |
1143 t.fixTo(this); | |
1144 //printf("\t%p\n", t); | |
1145 | |
1146 return t; | |
1147 } | |
98 | 1148 |
1149 /******************************** | |
1150 * Make type unshared. | |
135 | 1151 * 0 => 0 |
1152 * const => const | |
1153 * immutable => immutable | |
1154 * shared => 0 | |
1155 * shared const => const | |
1156 * wild => wild | |
1157 * shared wild => wild | |
98 | 1158 */ |
1159 Type unSharedOf() | |
1160 { | |
1161 //writef("Type::unSharedOf() %p, %s\n", this, toChars()); | |
1162 Type t = this; | |
1163 | |
1164 if (isShared()) | |
1165 { | |
1166 if (isConst()) | |
1167 t = cto; // shared const => const | |
135 | 1168 else if (isWild()) |
1169 t = wto; // shared wild => wild | |
98 | 1170 else |
1171 t = sto; | |
1172 assert(!t || !t.isShared()); | |
1173 } | |
1174 | |
1175 if (!t) | |
1176 { | |
1177 uint sz = this.classinfo.init.length; | |
1178 t = cast(Type)GC.malloc(sz); | |
1179 memcpy(cast(void*)t, cast(void*)this, sz); | |
1180 t.mod = mod & ~MODshared; | |
1181 t.deco = null; | |
1182 t.arrayof = null; | |
1183 t.pto = null; | |
1184 t.rto = null; | |
1185 t.cto = null; | |
1186 t.ito = null; | |
1187 t.sto = null; | |
1188 t.scto = null; | |
135 | 1189 t.wto = null; |
1190 t.swto = null; | |
98 | 1191 t.vtinfo = null; |
1192 t = t.merge(); | |
174 | 1193 |
98 | 1194 t.fixTo(this); |
1195 } | |
1196 assert(!t.isShared()); | |
1197 return t; | |
1198 } | |
1199 | |
174 | 1200 |
135 | 1201 /******************************** |
1202 * Convert to 'wild'. | |
1203 */ | |
1204 | |
1205 Type wildOf() | |
1206 { | |
1207 //printf("Type::wildOf() %p %s\n", this, toChars()); | |
1208 if (mod == MOD.MODwild) | |
1209 { | |
1210 return this; | |
1211 } | |
1212 if (wto) | |
1213 { | |
1214 assert(wto.isWild()); | |
1215 return wto; | |
1216 } | |
1217 Type t = makeWild(); | |
1218 t = t.merge(); | |
1219 t.fixTo(this); | |
1220 //printf("\t%p %s\n", t, t->toChars()); | |
1221 return t; | |
1222 } | |
1223 | |
1224 Type sharedWildOf() | |
1225 { | |
1226 //printf("Type::sharedWildOf() %p, %s\n", this, toChars()); | |
1227 if (mod == (MOD.MODwild)) | |
1228 { | |
1229 return this; | |
1230 } | |
1231 if (swto) | |
1232 { | |
1233 assert(swto.mod == (MOD.MODshared | MOD.MODwild)); | |
1234 return swto; | |
1235 } | |
1236 Type t = makeSharedWild(); | |
1237 t = t.merge(); | |
1238 t.fixTo(this); | |
1239 //printf("\t%p\n", t); | |
1240 return t; | |
1241 } | |
1242 | |
0 | 1243 static uint X(MOD m, MOD n) |
1244 { | |
135 | 1245 return (((m) << 4) | (n)); |
0 | 1246 } |
1247 | |
1248 /********************************** | |
1249 * For our new type 'this', which is type-constructed from t, | |
135 | 1250 * fill in the cto, ito, sto, scto, wto shortcuts. |
0 | 1251 */ |
1252 void fixTo(Type t) | |
1253 { | |
1254 ito = t.ito; | |
1255 static if (false) { | |
1256 /* Cannot do these because these are not fully transitive: | |
1257 * there can be a shared ptr to immutable, for example. | |
1258 * Immutable subtypes are always immutable, though. | |
1259 */ | |
1260 cto = t.cto; | |
1261 sto = t.sto; | |
1262 scto = t.scto; | |
1263 } | |
1264 | |
1265 assert(mod != t.mod); | |
1266 | |
1267 switch (X(mod, t.mod)) | |
1268 { | |
1269 case X(MOD.MODundefined, MOD.MODconst): | |
1270 cto = t; | |
1271 break; | |
1272 | |
135 | 1273 case X(MOD.MODundefined, MOD.MODimmutable): |
0 | 1274 ito = t; |
1275 break; | |
1276 | |
1277 case X(MOD.MODundefined, MOD.MODshared): | |
1278 sto = t; | |
1279 break; | |
1280 | |
1281 case X(MOD.MODundefined, MOD.MODshared | MOD.MODconst): | |
1282 scto = t; | |
1283 break; | |
1284 | |
135 | 1285 case X(MOD.MODundefined, MODwild): |
1286 wto = t; | |
1287 break; | |
1288 | |
1289 case X(MOD.MODundefined, MODshared | MODwild): | |
1290 swto = t; | |
1291 break; | |
1292 | |
0 | 1293 |
1294 case X(MOD.MODconst, MOD.MODundefined): | |
1295 cto = null; | |
1296 goto L2; | |
1297 | |
135 | 1298 case X(MOD.MODconst, MOD.MODimmutable): |
0 | 1299 ito = t; |
1300 goto L2; | |
1301 | |
1302 case X(MOD.MODconst, MOD.MODshared): | |
1303 sto = t; | |
1304 goto L2; | |
1305 | |
1306 case X(MOD.MODconst, MOD.MODshared | MOD.MODconst): | |
1307 scto = t; | |
135 | 1308 goto L2; |
1309 | |
1310 case X(MOD.MODconst, MOD.MODwild): | |
1311 wto = t; | |
1312 goto L2; | |
1313 | |
1314 case X(MOD.MODconst, MOD.MODshared | MOD.MODwild): | |
1315 swto = t; | |
0 | 1316 L2: |
1317 t.cto = this; | |
1318 break; | |
1319 | |
1320 | |
135 | 1321 case X(MOD.MODimmutable, MOD.MODundefined): |
0 | 1322 ito = null; |
1323 goto L3; | |
1324 | |
135 | 1325 case X(MOD.MODimmutable, MOD.MODconst): |
0 | 1326 cto = t; |
1327 goto L3; | |
1328 | |
135 | 1329 case X(MOD.MODimmutable, MOD.MODshared): |
0 | 1330 sto = t; |
1331 goto L3; | |
1332 | |
135 | 1333 case X(MOD.MODimmutable, MOD.MODshared | MOD.MODconst): |
0 | 1334 scto = t; |
135 | 1335 goto L3; |
1336 | |
1337 case X(MOD.MODimmutable, MOD.MODwild): | |
1338 wto = t; | |
1339 goto L3; | |
1340 | |
1341 case X(MOD.MODimmutable, MOD.MODshared | MOD.MODwild): | |
1342 swto = t; | |
0 | 1343 L3: |
1344 t.ito = this; | |
1345 if (t.cto) t.cto.ito = this; | |
1346 if (t.sto) t.sto.ito = this; | |
1347 if (t.scto) t.scto.ito = this; | |
135 | 1348 if (t.wto) t.wto.ito = this; |
1349 if (t.swto) t.swto.ito = this; | |
0 | 1350 break; |
1351 | |
1352 | |
1353 case X(MOD.MODshared, MOD.MODundefined): | |
1354 sto = null; | |
1355 goto L4; | |
1356 | |
1357 case X(MOD.MODshared, MOD.MODconst): | |
1358 cto = t; | |
1359 goto L4; | |
1360 | |
135 | 1361 case X(MOD.MODshared, MOD.MODimmutable): |
0 | 1362 ito = t; |
1363 goto L4; | |
1364 | |
1365 case X(MOD.MODshared, MOD.MODshared | MOD.MODconst): | |
1366 scto = t; | |
135 | 1367 goto L4; |
1368 | |
1369 case X(MOD.MODshared, MOD.MODwild): | |
1370 wto = t; | |
1371 goto L4; | |
1372 | |
1373 case X(MOD.MODshared, MOD.MODshared | MOD.MODwild): | |
1374 swto = t; | |
0 | 1375 L4: |
1376 t.sto = this; | |
1377 break; | |
1378 | |
1379 | |
1380 case X(MOD.MODshared | MOD.MODconst, MOD.MODundefined): | |
1381 scto = null; | |
135 | 1382 goto L5; |
0 | 1383 |
1384 case X(MOD.MODshared | MOD.MODconst, MOD.MODconst): | |
1385 cto = t; | |
135 | 1386 goto L5; |
0 | 1387 |
135 | 1388 case X(MOD.MODshared | MOD.MODconst, MOD.MODimmutable): |
0 | 1389 ito = t; |
135 | 1390 goto L5; |
1391 | |
1392 case X(MOD.MODshared | MOD.MODconst, MOD.MODwild): | |
1393 wto = t; | |
1394 goto L5; | |
0 | 1395 |
1396 case X(MOD.MODshared | MOD.MODconst, MOD.MODshared): | |
1397 sto = t; | |
135 | 1398 goto L5; |
1399 | |
1400 case X(MOD.MODshared | MOD.MODconst, MOD.MODshared | MOD.MODwild): | |
1401 swto = t; | |
0 | 1402 L5: |
1403 t.scto = this; | |
1404 break; | |
174 | 1405 |
135 | 1406 case X(MOD.MODwild, MOD.MODundefined): |
1407 wto = null; | |
1408 goto L6; | |
1409 | |
1410 case X(MOD.MODwild, MOD.MODconst): | |
1411 cto = t; | |
1412 goto L6; | |
1413 | |
1414 case X(MOD.MODwild, MOD.MODimmutable): | |
1415 ito = t; | |
1416 goto L6; | |
1417 | |
1418 case X(MOD.MODwild, MOD.MODshared): | |
1419 sto = t; | |
1420 goto L6; | |
1421 | |
1422 case X(MOD.MODwild, MOD.MODshared | MOD.MODconst): | |
1423 scto = t; | |
1424 goto L6; | |
1425 | |
1426 case X(MOD.MODwild, MOD.MODshared | MOD.MODwild): | |
1427 swto = t; | |
1428 L6: | |
1429 t.wto = this; | |
1430 break; | |
1431 | |
1432 | |
1433 case X(MOD.MODshared | MOD.MODwild, MOD.MODundefined): | |
1434 swto = null; | |
1435 goto L7; | |
1436 | |
1437 case X(MOD.MODshared | MOD.MODwild, MOD.MODconst): | |
1438 cto = t; | |
1439 goto L7; | |
1440 | |
1441 case X(MOD.MODshared | MOD.MODwild, MOD.MODimmutable): | |
1442 ito = t; | |
1443 goto L7; | |
1444 | |
1445 case X(MOD.MODshared | MOD.MODwild, MOD.MODshared): | |
1446 sto = t; | |
1447 goto L7; | |
1448 | |
1449 case X(MOD.MODshared | MOD.MODwild, MOD.MODshared | MOD.MODconst): | |
1450 scto = t; | |
1451 goto L7; | |
1452 | |
1453 case X(MOD.MODshared | MOD.MODwild, MOD.MODwild): | |
1454 wto = t; | |
1455 L7: | |
1456 t.swto = this; | |
1457 break; | |
0 | 1458 } |
1459 | |
1460 check(); | |
1461 t.check(); | |
1462 //printf("fixTo: %s, %s\n", toChars(), t.toChars()); | |
1463 } | |
174 | 1464 |
0 | 1465 /*************************** |
1466 * Look for bugs in constructing types. | |
1467 */ | |
1468 void check() | |
1469 { | |
1470 switch (mod) | |
1471 { | |
1472 case MOD.MODundefined: | |
1473 if (cto) assert(cto.mod == MOD.MODconst); | |
135 | 1474 if (ito) assert(ito.mod == MOD.MODimmutable); |
0 | 1475 if (sto) assert(sto.mod == MOD.MODshared); |
1476 if (scto) assert(scto.mod == (MOD.MODshared | MOD.MODconst)); | |
135 | 1477 if (wto) assert(wto.mod == MOD.MODwild); |
1478 if (swto) assert(swto.mod == (MOD.MODshared | MOD.MODwild)); | |
0 | 1479 break; |
1480 | |
1481 case MOD.MODconst: | |
1482 if (cto) assert(cto.mod == MOD.MODundefined); | |
135 | 1483 if (ito) assert(ito.mod == MOD.MODimmutable); |
0 | 1484 if (sto) assert(sto.mod == MOD.MODshared); |
1485 if (scto) assert(scto.mod == (MOD.MODshared | MOD.MODconst)); | |
135 | 1486 if (wto) assert(wto.mod == MOD.MODwild); |
1487 if (swto) assert(swto.mod == (MOD.MODshared | MOD.MODwild)); | |
0 | 1488 break; |
1489 | |
135 | 1490 case MOD.MODimmutable: |
0 | 1491 if (cto) assert(cto.mod == MOD.MODconst); |
1492 if (ito) assert(ito.mod == MOD.MODundefined); | |
1493 if (sto) assert(sto.mod == MOD.MODshared); | |
1494 if (scto) assert(scto.mod == (MOD.MODshared | MOD.MODconst)); | |
135 | 1495 if (wto) assert(wto.mod == MOD.MODwild); |
1496 if (swto) assert(swto.mod == (MOD.MODshared | MOD.MODwild)); | |
0 | 1497 break; |
1498 | |
1499 case MOD.MODshared: | |
1500 if (cto) assert(cto.mod == MOD.MODconst); | |
135 | 1501 if (ito) assert(ito.mod == MOD.MODimmutable); |
0 | 1502 if (sto) assert(sto.mod == MOD.MODundefined); |
1503 if (scto) assert(scto.mod == (MOD.MODshared | MOD.MODconst)); | |
135 | 1504 if (wto) assert(wto.mod == MOD.MODwild); |
1505 if (swto) assert(swto.mod == (MOD.MODshared | MOD.MODwild)); | |
0 | 1506 break; |
1507 | |
1508 case MOD.MODshared | MOD.MODconst: | |
1509 if (cto) assert(cto.mod == MOD.MODconst); | |
135 | 1510 if (ito) assert(ito.mod == MOD.MODimmutable); |
0 | 1511 if (sto) assert(sto.mod == MOD.MODshared); |
1512 if (scto) assert(scto.mod == MOD.MODundefined); | |
135 | 1513 if (wto) assert(wto.mod == MOD.MODwild); |
1514 if (swto) assert(swto.mod == (MOD.MODshared | MOD.MODwild)); | |
0 | 1515 break; |
174 | 1516 |
135 | 1517 case MOD.MODwild: |
1518 if (cto) assert(cto.mod == MOD.MODconst); | |
1519 if (ito) assert(ito.mod == MOD.MODimmutable); | |
1520 if (sto) assert(sto.mod == MOD.MODshared); | |
1521 if (scto) assert(scto.mod == (MOD.MODshared | MOD.MODconst)); | |
1522 if (wto) assert(wto.mod == MOD.MODundefined); | |
1523 if (swto) assert(swto.mod == (MOD.MODshared | MOD.MODwild)); | |
1524 break; | |
1525 | |
1526 case MOD.MODshared | MOD.MODwild: | |
1527 if (cto) assert(cto.mod == MOD.MODconst); | |
1528 if (ito) assert(ito.mod == MOD.MODimmutable); | |
1529 if (sto) assert(sto.mod == MOD.MODshared); | |
1530 if (scto) assert(scto.mod == (MOD.MODshared | MOD.MODconst)); | |
1531 if (wto) assert(wto.mod == MOD.MODwild); | |
1532 if (swto) assert(swto.mod == MOD.MODundefined); | |
1533 break; | |
0 | 1534 } |
1535 | |
1536 Type tn = nextOf(); | |
1537 if (tn && ty != TY.Tfunction && ty != TY.Tdelegate) | |
1538 { | |
1539 // Verify transitivity | |
1540 switch (mod) | |
1541 { | |
1542 case MOD.MODundefined: | |
1543 break; | |
1544 | |
1545 case MOD.MODconst: | |
135 | 1546 assert(tn.mod & MOD.MODimmutable || tn.mod & MOD.MODconst); |
0 | 1547 break; |
1548 | |
135 | 1549 case MOD.MODimmutable: |
1550 assert(tn.mod == MOD.MODimmutable); | |
0 | 1551 break; |
1552 | |
1553 case MOD.MODshared: | |
135 | 1554 assert(tn.mod & MOD.MODimmutable || tn.mod & MOD.MODshared); |
0 | 1555 break; |
1556 | |
1557 case MOD.MODshared | MOD.MODconst: | |
135 | 1558 assert(tn.mod & MOD.MODimmutable || tn.mod & (MOD.MODshared | MOD.MODconst)); |
1559 break; | |
1560 | |
1561 case MOD.MODwild: | |
1562 assert(tn.mod); | |
1563 break; | |
1564 | |
1565 case MOD.MODshared | MOD.MODwild: | |
1566 assert(tn.mod == MOD.MODimmutable || tn.mod == (MOD.MODshared | MOD.MODconst) || tn.mod == (MOD.MODshared | MOD.MODwild)); | |
0 | 1567 break; |
1568 } | |
1569 tn.check(); | |
1570 } | |
1571 } | |
1572 | |
51 | 1573 /************************************ |
1574 * Apply MODxxxx bits to existing type. | |
1575 */ | |
0 | 1576 Type castMod(uint mod) |
1577 { | |
51 | 1578 Type t; |
1579 | |
1580 switch (mod) | |
1581 { | |
1582 case 0: | |
135 | 1583 t = unSharedOf().mutableOf(); |
51 | 1584 break; |
1585 | |
1586 case MODconst: | |
135 | 1587 t = unSharedOf().constOf(); |
51 | 1588 break; |
1589 | |
135 | 1590 case MODimmutable: |
51 | 1591 t = invariantOf(); |
1592 break; | |
1593 | |
1594 case MODshared: | |
135 | 1595 t = mutableOf().sharedOf(); |
51 | 1596 break; |
1597 | |
1598 case MODshared | MODconst: | |
1599 t = sharedConstOf(); | |
135 | 1600 break; |
1601 | |
1602 case MODwild: | |
1603 t = unSharedOf().wildOf(); | |
1604 break; | |
1605 | |
1606 case MODshared | MODwild: | |
1607 t = sharedWildOf(); | |
51 | 1608 break; |
1609 | |
1610 default: | |
1611 assert(0); | |
1612 } | |
1613 return t; | |
0 | 1614 } |
174 | 1615 |
0 | 1616 /************************************ |
1617 * Add MODxxxx bits to existing type. | |
1618 * We're adding, not replacing, so adding const to | |
1619 * a shared type => "shared const" | |
1620 */ | |
1621 Type addMod(MOD mod) | |
1622 { | |
1623 Type t = this; | |
1624 | |
1625 /* Add anything to immutable, and it remains immutable | |
1626 */ | |
135 | 1627 //printf("addMod(%x) %s\n", mod, toChars()); |
1628 if (!t.isImmutable()) | |
0 | 1629 { |
1630 switch (mod) | |
1631 { | |
1632 case MOD.MODundefined: | |
1633 break; | |
1634 | |
1635 case MOD.MODconst: | |
1636 if (isShared()) | |
1637 t = sharedConstOf(); | |
1638 else | |
1639 t = constOf(); | |
1640 break; | |
1641 | |
135 | 1642 case MOD.MODimmutable: |
0 | 1643 t = invariantOf(); |
1644 break; | |
1645 | |
1646 case MOD.MODshared: | |
1647 if (isConst()) | |
1648 t = sharedConstOf(); | |
135 | 1649 else if (isWild()) |
1650 t = sharedWildOf(); | |
0 | 1651 else |
1652 t = sharedOf(); | |
1653 break; | |
1654 | |
1655 case MOD.MODshared | MOD.MODconst: | |
1656 t = sharedConstOf(); | |
1657 break; | |
174 | 1658 |
135 | 1659 case MOD.MODwild: |
1660 if (isConst()) | |
1661 {} | |
1662 else if (isShared()) | |
1663 t = sharedWildOf(); | |
1664 else | |
1665 t = wildOf(); | |
1666 break; | |
1667 | |
1668 case MOD.MODshared | MOD.MODwild: | |
1669 t = sharedWildOf(); | |
1670 break; | |
0 | 1671 } |
1672 } | |
1673 return t; | |
1674 } | |
174 | 1675 |
131
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
1676 Type addStorageClass(StorageClass stc) |
0 | 1677 { |
1678 /* Just translate to MOD bits and let addMod() do the work | |
1679 */ | |
1680 MOD mod = MOD.MODundefined; | |
1681 | |
1682 if (stc & STC.STCimmutable) | |
135 | 1683 mod = MOD.MODimmutable; |
0 | 1684 else |
174 | 1685 { |
0 | 1686 if (stc & (STC.STCconst | STC.STCin)) |
1687 mod = MOD.MODconst; | |
1688 if (stc & STC.STCshared) | |
1689 mod |= MOD.MODshared; | |
135 | 1690 if (stc & STC.STCwild) |
1691 mod |= MOD.MODwild; | |
0 | 1692 } |
1693 | |
1694 return addMod(mod); | |
1695 } | |
174 | 1696 |
0 | 1697 Type pointerTo() |
1698 { | |
1699 if (pto is null) | |
1700 { | |
1701 Type t = new TypePointer(this); | |
1702 pto = t.merge(); | |
1703 } | |
1704 | |
1705 return pto; | |
1706 } | |
174 | 1707 |
0 | 1708 Type referenceTo() |
1709 { | |
1710 assert(false); | |
1711 } | |
1712 | |
1713 version (DumbClone) { | |
1714 final Type clone() | |
1715 { | |
1716 auto size = this.classinfo.init.length; | |
2 | 1717 auto ptr = GC.malloc(size); |
0 | 1718 memcpy(ptr, cast(void*)this, size); |
1719 | |
1720 return cast(Type)ptr; | |
1721 } | |
1722 } else { | |
1723 final Type cloneTo(Type t) | |
1724 { | |
1725 t.ctype = ctype; | |
1726 return t; | |
1727 } | |
1728 | |
1729 Type clone() | |
1730 { | |
1731 assert(this.classinfo is Type.classinfo); | |
1732 return cloneTo(new Type(ty)); | |
1733 } | |
1734 } | |
174 | 1735 |
0 | 1736 Type arrayOf() |
1737 { | |
1738 if (!arrayof) | |
174 | 1739 { |
0 | 1740 Type t = new TypeDArray(this); |
1741 arrayof = t.merge(); | |
1742 } | |
1743 return arrayof; | |
1744 } | |
174 | 1745 |
0 | 1746 Type makeConst() |
1747 { | |
1748 //printf("Type.makeConst() %p, %s\n", this, toChars()); | |
1749 if (cto) | |
1750 return cto; | |
1751 | |
1752 Type t = clone(); | |
1753 t.mod = MOD.MODconst; | |
174 | 1754 |
0 | 1755 t.deco = null; |
1756 t.arrayof = null; | |
1757 t.pto = null; | |
1758 t.rto = null; | |
1759 t.cto = null; | |
1760 t.ito = null; | |
1761 t.sto = null; | |
1762 t.scto = null; | |
135 | 1763 t.wto = null; |
1764 t.swto = null; | |
0 | 1765 t.vtinfo = null; |
174 | 1766 |
0 | 1767 //printf("-Type.makeConst() %p, %s\n", t, toChars()); |
1768 return t; | |
1769 } | |
174 | 1770 |
0 | 1771 Type makeInvariant() |
1772 { | |
1773 if (ito) { | |
1774 return ito; | |
1775 } | |
1776 | |
1777 Type t = clone(); | |
135 | 1778 t.mod = MOD.MODimmutable; |
0 | 1779 |
1780 t.deco = null; | |
1781 t.arrayof = null; | |
1782 t.pto = null; | |
1783 t.rto = null; | |
1784 t.cto = null; | |
1785 t.ito = null; | |
1786 t.sto = null; | |
1787 t.scto = null; | |
135 | 1788 t.wto = null; |
1789 t.swto = null; | |
0 | 1790 t.vtinfo = null; |
1791 | |
1792 return t; | |
1793 } | |
174 | 1794 |
0 | 1795 Type makeShared() |
1796 { | |
1797 if (sto) | |
1798 return sto; | |
1799 | |
1800 Type t = clone(); | |
1801 t.mod = MOD.MODshared; | |
1802 | |
1803 t.deco = null; | |
1804 t.arrayof = null; | |
1805 t.pto = null; | |
1806 t.rto = null; | |
1807 t.cto = null; | |
1808 t.ito = null; | |
1809 t.sto = null; | |
1810 t.scto = null; | |
135 | 1811 t.wto = null; |
1812 t.swto = null; | |
0 | 1813 t.vtinfo = null; |
1814 | |
1815 return t; | |
1816 } | |
174 | 1817 |
0 | 1818 Type makeSharedConst() |
1819 { | |
1820 if (scto) | |
1821 return scto; | |
1822 | |
1823 Type t = clone(); | |
1824 t.mod = MODshared | MODconst; | |
1825 | |
1826 t.deco = null; | |
1827 t.arrayof = null; | |
1828 t.pto = null; | |
1829 t.rto = null; | |
1830 t.cto = null; | |
1831 t.ito = null; | |
1832 t.sto = null; | |
1833 t.scto = null; | |
135 | 1834 t.wto = null; |
1835 t.swto = null; | |
0 | 1836 t.vtinfo = null; |
1837 | |
1838 return t; | |
1839 } | |
174 | 1840 |
135 | 1841 Type makeWild() |
1842 { | |
1843 if (wto) | |
1844 return wto; | |
174 | 1845 |
135 | 1846 Type t = clone(); |
1847 t.mod = MOD.MODwild; | |
1848 t.deco = null; | |
1849 t.arrayof = null; | |
1850 t.pto = null; | |
1851 t.rto = null; | |
1852 t.cto = null; | |
1853 t.ito = null; | |
1854 t.sto = null; | |
1855 t.scto = null; | |
1856 t.wto = null; | |
1857 t.swto = null; | |
1858 t.vtinfo = null; | |
1859 return t; | |
1860 } | |
1861 | |
1862 Type makeSharedWild() | |
1863 { | |
1864 if (swto) | |
1865 return swto; | |
174 | 1866 |
135 | 1867 Type t = clone(); |
1868 t.mod = MOD.MODshared | MOD.MODwild; | |
1869 t.deco = null; | |
1870 t.arrayof = null; | |
1871 t.pto = null; | |
1872 t.rto = null; | |
1873 t.cto = null; | |
1874 t.ito = null; | |
1875 t.sto = null; | |
1876 t.scto = null; | |
1877 t.wto = null; | |
1878 t.swto = null; | |
1879 t.vtinfo = null; | |
1880 return t; | |
1881 } | |
1882 | |
1883 Type makeMutable() | |
1884 { | |
1885 Type t = clone(); | |
1886 t.mod = mod & MOD.MODshared; | |
1887 t.deco = null; | |
1888 t.arrayof = null; | |
1889 t.pto = null; | |
1890 t.rto = null; | |
1891 t.cto = null; | |
1892 t.ito = null; | |
1893 t.sto = null; | |
1894 t.scto = null; | |
1895 t.wto = null; | |
1896 t.swto = null; | |
1897 t.vtinfo = null; | |
1898 return t; | |
1899 } | |
174 | 1900 |
0 | 1901 Dsymbol toDsymbol(Scope sc) |
1902 { | |
1903 return null; | |
1904 } | |
1905 | |
1906 /******************************* | |
1907 * If this is a shell around another type, | |
1908 * get that other type. | |
1909 */ | |
174 | 1910 |
0 | 1911 Type toBasetype() |
1912 { | |
1913 return this; | |
1914 } | |
174 | 1915 |
0 | 1916 /************************** |
1917 * Return type with the top level of it being mutable. | |
1918 */ | |
1919 Type toHeadMutable() | |
1920 { | |
1921 if (!mod) | |
1922 return this; | |
1923 | |
1924 return mutableOf(); | |
1925 } | |
174 | 1926 |
0 | 1927 bool isBaseOf(Type t, int* poffset) |
1928 { | |
1929 return false; // assume not | |
1930 } | |
174 | 1931 |
0 | 1932 /******************************* |
1933 * Determine if converting 'this' to 'to' is an identity operation, | |
1934 * a conversion to const operation, or the types aren't the same. | |
1935 * Returns: | |
1936 * MATCHequal 'this' == 'to' | |
1937 * MATCHconst 'to' is const | |
1938 * MATCHnomatch conversion to mutable or invariant | |
1939 */ | |
1940 MATCH constConv(Type to) | |
1941 { | |
1942 if (equals(to)) | |
1943 return MATCH.MATCHexact; | |
135 | 1944 if (ty == to.ty && MODimplicitConv(mod, to.mod)) |
0 | 1945 return MATCH.MATCHconst; |
1946 return MATCH.MATCHnomatch; | |
1947 } | |
174 | 1948 |
0 | 1949 /******************************** |
1950 * Determine if 'this' can be implicitly converted | |
1951 * to type 'to'. | |
1952 * Returns: | |
1953 * MATCHnomatch, MATCHconvert, MATCHconst, MATCHexact | |
1954 */ | |
1955 MATCH implicitConvTo(Type to) | |
1956 { | |
1957 //printf("Type.implicitConvTo(this=%p, to=%p)\n", this, to); | |
1958 //printf("from: %s\n", toChars()); | |
1959 //printf("to : %s\n", to.toChars()); | |
1960 if (this is to) | |
1961 return MATCHexact; | |
1962 | |
1963 return MATCHnomatch; | |
1964 } | |
174 | 1965 |
0 | 1966 ClassDeclaration isClassHandle() |
1967 { | |
1968 return null; | |
1969 } | |
1970 | |
1971 Expression getProperty(Loc loc, Identifier ident) | |
1972 { | |
1973 Expression e; | |
1974 | |
1975 version (LOGDOTEXP) { | |
1976 printf("Type.getProperty(type = '%s', ident = '%s')\n", toChars(), ident.toChars()); | |
1977 } | |
1978 if (ident == Id.__sizeof) | |
1979 { | |
1980 e = new IntegerExp(loc, size(loc), Type.tsize_t); | |
1981 } | |
1982 else if (ident == Id.size) | |
1983 { | |
1984 error(loc, ".size property should be replaced with .sizeof"); | |
1985 e = new ErrorExp(); | |
1986 } | |
1987 else if (ident is Id.alignof_) | |
1988 { | |
1989 e = new IntegerExp(loc, alignsize(), Type.tsize_t); | |
1990 } | |
1991 else if (ident == Id.typeinfo_) | |
1992 { | |
1993 if (!global.params.useDeprecated) | |
1994 error(loc, ".typeinfo deprecated, use typeid(type)"); | |
1995 e = getTypeInfo(null); | |
1996 } | |
1997 else if (ident == Id.init_) | |
1998 { | |
1999 if (ty == TY.Tvoid) | |
2000 error(loc, "void does not have an initializer"); | |
2001 e = defaultInit(loc); | |
2002 } | |
2003 else if (ident is Id.mangleof_) | |
2004 { | |
2005 string s; | |
174 | 2006 if (!deco) { |
0 | 2007 s = toChars(); |
2008 error(loc, "forward reference of type %s.mangleof", s); | |
2009 } else { | |
2010 s = deco; | |
2011 } | |
2012 | |
2013 e = new StringExp(loc, s, 'c'); | |
87
b17640f0e4e8
Fixed a bug with a Scope.this(Scope enclosing) being called instead of Scope.clone() method (as a copy ctor replacement)
korDen
parents:
79
diff
changeset
|
2014 scope Scope sc = new Scope(); |
0 | 2015 e = e.semantic(sc); |
2016 } | |
2017 else if (ident is Id.stringof_) | |
174 | 2018 { |
0 | 2019 string s = toChars(); |
2020 e = new StringExp(loc, s, 'c'); | |
87
b17640f0e4e8
Fixed a bug with a Scope.this(Scope enclosing) being called instead of Scope.clone() method (as a copy ctor replacement)
korDen
parents:
79
diff
changeset
|
2021 scope Scope sc = new Scope(); |
0 | 2022 e = e.semantic(sc); |
2023 } | |
2024 else | |
2025 { | |
2026 error(loc, "no property '%s' for type '%s'", ident.toChars(), toChars()); | |
2027 e = new ErrorExp(); | |
2028 } | |
2029 return e; | |
2030 } | |
174 | 2031 |
0 | 2032 Expression dotExp(Scope sc, Expression e, Identifier ident) |
2033 { | |
2034 VarDeclaration v = null; | |
2035 | |
2036 version (LOGDOTEXP) { | |
2037 printf("Type.dotExp(e = '%s', ident = '%s')\n", e.toChars(), ident.toChars()); | |
2038 } | |
2039 if (e.op == TOK.TOKdotvar) | |
2040 { | |
2041 DotVarExp dv = cast(DotVarExp)e; | |
2042 v = dv.var.isVarDeclaration(); | |
2043 } | |
2044 else if (e.op == TOK.TOKvar) | |
2045 { | |
2046 VarExp ve = cast(VarExp)e; | |
2047 v = ve.var.isVarDeclaration(); | |
2048 } | |
2049 if (v) | |
2050 { | |
2051 if (ident is Id.offset) | |
2052 { | |
2053 if (!global.params.useDeprecated) | |
2054 error(e.loc, ".offset deprecated, use .offsetof"); | |
2055 goto Loffset; | |
2056 } | |
2057 else if (ident is Id.offsetof) | |
2058 { | |
2059 Loffset: | |
2060 if (v.storage_class & STC.STCfield) | |
2061 { | |
2062 e = new IntegerExp(e.loc, v.offset, Type.tsize_t); | |
2063 return e; | |
2064 } | |
2065 } | |
2066 else if (ident is Id.init_) | |
2067 { | |
2068 static if (false) { | |
2069 if (v.init) | |
2070 { | |
2071 if (v.init.isVoidInitializer()) | |
2072 error(e.loc, "%s.init is void", v.toChars()); | |
2073 else | |
2074 { Loc loc = e.loc; | |
2075 e = v.init.toExpression(); | |
2076 if (e.op == TOK.TOKassign || e.op == TOK.TOKconstruct || e.op == TOK.TOKblit) | |
2077 { | |
2078 e = (cast(AssignExp)e).e2; | |
2079 | |
2080 /* Take care of case where we used a 0 | |
2081 * to initialize the struct. | |
2082 */ | |
2083 if (e.type == Type.tint32 && | |
2084 e.isBool(0) && | |
2085 v.type.toBasetype().ty == TY.Tstruct) | |
2086 { | |
2087 e = v.type.defaultInit(e.loc); | |
2088 } | |
2089 } | |
2090 e = e.optimize(WANTvalue | WANTinterpret); | |
2091 // if (!e.isConst()) | |
2092 // error(loc, ".init cannot be evaluated at compile time"); | |
2093 } | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2094 goto Lreturn; |
0 | 2095 } |
2096 } | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2097 e = defaultInit(e.loc); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2098 goto Lreturn; |
0 | 2099 } |
2100 } | |
2101 if (ident is Id.typeinfo_) | |
2102 { | |
2103 if (!global.params.useDeprecated) | |
2104 error(e.loc, ".typeinfo deprecated, use typeid(type)"); | |
2105 e = getTypeInfo(sc); | |
2106 } | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2107 else if (ident is Id.stringof_) |
174 | 2108 { |
0 | 2109 string s = e.toChars(); |
2110 e = new StringExp(e.loc, s, 'c'); | |
2111 } | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2112 else |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2113 e = getProperty(e.loc, ident); |
174 | 2114 |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2115 Lreturn: |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2116 e = e.semantic(sc); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2117 return e; |
0 | 2118 } |
174 | 2119 |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2120 /*************************************** |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2121 * Figures out what to do with an undefined member reference |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2122 * for classes and structs. |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2123 */ |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2124 Expression noMember(Scope sc, Expression e, Identifier ident) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2125 { |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2126 assert(ty == TY.Tstruct || ty == TY.Tclass); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2127 AggregateDeclaration sym = toDsymbol(sc).isAggregateDeclaration(); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2128 assert(sym); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2129 |
131
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
2130 if (ident !is Id.__sizeof && |
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
2131 ident !is Id.alignof_ && |
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
2132 ident !is Id.init_ && |
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
2133 ident !is Id.mangleof_ && |
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
2134 ident !is Id.stringof_ && |
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
2135 ident !is Id.offsetof) |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2136 { |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2137 /* See if we should forward to the alias this. |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2138 */ |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2139 if (sym.aliasthis) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2140 { /* Rewrite e.ident as: |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2141 * e.aliasthis.ident |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2142 */ |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2143 e = new DotIdExp(e.loc, e, sym.aliasthis.ident); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2144 e = new DotIdExp(e.loc, e, ident); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2145 return e.semantic(sc); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2146 } |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2147 |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2148 /* Look for overloaded opDot() to see if we should forward request |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2149 * to it. |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2150 */ |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2151 Dsymbol fd = search_function(sym, Id.opDot); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2152 if (fd) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2153 { /* Rewrite e.ident as: |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2154 * e.opDot().ident |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2155 */ |
131
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
2156 e = build_overload(e.loc, sc, e, null, fd.ident); |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2157 e = new DotIdExp(e.loc, e, ident); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2158 return e.semantic(sc); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2159 } |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2160 |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2161 /* Look for overloaded opDispatch to see if we should forward request |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2162 * to it. |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2163 */ |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2164 fd = search_function(sym, Id.opDispatch); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2165 if (fd) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2166 { |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2167 /* Rewrite e.ident as: |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2168 * e.opDispatch!("ident") |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2169 */ |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2170 TemplateDeclaration td = fd.isTemplateDeclaration(); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2171 if (!td) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2172 { |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2173 fd.error("must be a template opDispatch(string s), not a %s", fd.kind()); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2174 return new ErrorExp(); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2175 } |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2176 auto se = new StringExp(e.loc, ident.toChars()); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2177 auto tiargs = new Objects(); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2178 tiargs.push(se); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2179 e = new DotTemplateInstanceExp(e.loc, e, Id.opDispatch, tiargs); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2180 (cast(DotTemplateInstanceExp)e).ti.tempdecl = td; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2181 return e; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2182 //return e.semantic(sc); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2183 } |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2184 } |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2185 |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2186 return Type.dotExp(sc, e, ident); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2187 } |
174 | 2188 |
0 | 2189 uint memalign(uint salign) |
2190 { | |
2191 return salign; | |
2192 } | |
174 | 2193 |
0 | 2194 Expression defaultInit(Loc loc) |
2195 { | |
170 | 2196 version (LOGDEFAULTINIT) { |
2197 printf("Type.defaultInit() '%.*s'\n", toChars()); | |
2198 } | |
2199 return null; | |
0 | 2200 } |
174 | 2201 |
135 | 2202 /*************************************** |
2203 * Use when we prefer the default initializer to be a literal, | |
2204 * rather than a global immutable variable. | |
2205 */ | |
174 | 2206 //Expression defaultInitLiteral(Loc loc = Loc(0)) |
2207 Expression defaultInitLiteral(Loc loc) | |
135 | 2208 { |
2209 version(LOGDEFAULTINIT) { | |
2210 printf("Type::defaultInitLiteral() '%s'\n", toChars()); | |
2211 } | |
2212 return defaultInit(loc); | |
2213 } | |
2214 | |
0 | 2215 ///bool isZeroInit(Loc loc = Loc(0)) // if initializer is 0 |
2216 bool isZeroInit(Loc loc) // if initializer is 0 | |
2217 { | |
2218 assert(false); | |
2219 } | |
174 | 2220 |
0 | 2221 dt_t** toDt(dt_t** pdt) |
2222 { | |
2223 //printf("Type.toDt()\n"); | |
2224 Expression e = defaultInit(Loc(0)); | |
2225 return e.toDt(pdt); | |
2226 } | |
174 | 2227 |
0 | 2228 Identifier getTypeInfoIdent(int internal) |
2229 { | |
2230 // _init_10TypeInfo_%s | |
2231 scope OutBuffer buf = new OutBuffer(); | |
2232 Identifier id; | |
2233 char* name; | |
2234 int len; | |
2235 | |
2236 if (internal) | |
174 | 2237 { |
0 | 2238 buf.writeByte(mangleChar[ty]); |
2239 if (ty == TY.Tarray) | |
2240 buf.writeByte(mangleChar[(cast(TypeArray)this).next.ty]); | |
2241 } | |
2242 else | |
2243 toDecoBuffer(buf); | |
2244 | |
2245 len = buf.offset; | |
14
2cc604139636
Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents:
4
diff
changeset
|
2246 version (Bug4054) |
2cc604139636
Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents:
4
diff
changeset
|
2247 name = cast(char*)GC.malloc(19 + len.sizeof * 3 + len + 1); |
2cc604139636
Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents:
4
diff
changeset
|
2248 else |
0 | 2249 name = cast(char*)alloca(19 + len.sizeof * 3 + len + 1); |
2250 buf.writeByte(0); | |
2251 version (TARGET_OSX) { | |
2252 // The LINKc will prepend the _ | |
2253 len = sprintf(name, "D%dTypeInfo_%s6__initZ".ptr, 9 + len, buf.data); | |
2254 } else { | |
2255 len = sprintf(name, "_D%dTypeInfo_%s6__initZ".ptr, 9 + len, buf.data); | |
2256 } | |
2257 if (global.params.isWindows) | |
2258 name++; // C mangling will add it back in | |
2259 //printf("name = %s\n", name); | |
2260 id = Lexer.idPool(name[0..len-1].idup); | |
2261 return id; | |
2262 } | |
174 | 2263 |
0 | 2264 /* These form the heart of template argument deduction. |
2265 * Given 'this' being the type argument to the template instance, | |
2266 * it is matched against the template declaration parameter specialization | |
2267 * 'tparam' to determine the type to be used for the parameter. | |
2268 * Example: | |
2269 * template Foo(T:T*) // template declaration | |
2270 * Foo!(int*) // template instantiation | |
2271 * Input: | |
2272 * this = int* | |
2273 * tparam = T | |
2274 * parameters = [ T:T* ] // Array of TemplateParameter's | |
2275 * Output: | |
2276 * dedtypes = [ int ] // Array of Expression/Type's | |
2277 */ | |
2278 MATCH deduceType(Scope sc, Type tparam, TemplateParameters parameters, Objects dedtypes) | |
2279 { | |
98 | 2280 static if (false) |
2281 { | |
0 | 2282 printf("Type.deduceType()\n"); |
2283 printf("\tthis = %d, ", ty); print(); | |
2284 printf("\ttparam = %d, ", tparam.ty); tparam.print(); | |
2285 } | |
2286 if (!tparam) | |
2287 goto Lnomatch; | |
2288 | |
2289 if (this == tparam) | |
2290 goto Lexact; | |
2291 | |
2292 if (tparam.ty == Tident) | |
2293 { | |
2294 // Determine which parameter tparam is | |
2295 int i = templateParameterLookup(tparam, parameters); | |
2296 if (i == -1) | |
2297 { | |
2298 if (!sc) | |
2299 goto Lnomatch; | |
2300 | |
2301 /* Need a loc to go with the semantic routine. | |
2302 */ | |
2303 Loc loc; | |
2304 if (parameters.dim) | |
2305 { | |
121
347de076ad34
TemplateParameters -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
2306 auto tp = parameters[0]; |
0 | 2307 loc = tp.loc; |
2308 } | |
2309 | |
2310 /* BUG: what if tparam is a template instance, that | |
2311 * has as an argument another Tident? | |
2312 */ | |
2313 tparam = tparam.semantic(loc, sc); | |
2314 assert(tparam.ty != Tident); | |
2315 return deduceType(sc, tparam, parameters, dedtypes); | |
2316 } | |
2317 | |
121
347de076ad34
TemplateParameters -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
2318 auto tp = parameters[i]; |
0 | 2319 |
2320 // Found the corresponding parameter tp | |
2321 if (!tp.isTemplateTypeParameter()) | |
2322 goto Lnomatch; | |
2323 Type tt = this; | |
113
3482c73a991b
More cleanup for arrays
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
110
diff
changeset
|
2324 Type at = cast(Type)dedtypes[i]; |
0 | 2325 |
98 | 2326 // 5*5 == 25 cases |
135 | 2327 static pure int X(int U, int T) { return ((U << 4) | T); } |
174 | 2328 |
98 | 2329 switch (X(tparam.mod, mod)) |
2330 { | |
2331 case X(0, 0): | |
2332 case X(0, MODconst): | |
135 | 2333 case X(0, MODimmutable): |
98 | 2334 case X(0, MODshared): |
2335 case X(0, MODconst | MODshared): | |
135 | 2336 case X(0, MODwild): |
2337 case X(0, MODwild | MODshared): | |
98 | 2338 // foo(U:U) T => T |
2339 // foo(U:U) const(T) => const(T) | |
2340 // foo(U:U) immutable(T) => immutable(T) | |
2341 // foo(U:U) shared(T) => shared(T) | |
2342 // foo(U:U) const(shared(T)) => const(shared(T)) | |
135 | 2343 // foo(U:U) wild(T) => wild(T) |
2344 // foo(U:U) wild(shared(T)) => wild(shared(T)) | |
0 | 2345 if (!at) |
110 | 2346 { dedtypes[i] = tt; |
0 | 2347 goto Lexact; |
2348 } | |
98 | 2349 break; |
2350 | |
2351 case X(MODconst, MODconst): | |
135 | 2352 case X(MODimmutable, MODimmutable): |
98 | 2353 case X(MODshared, MODshared): |
2354 case X(MODconst | MODshared, MODconst | MODshared): | |
135 | 2355 case X(MODwild, MODwild): |
2356 case X(MODwild | MODshared, MODwild | MODshared): | |
2357 case X(MODconst, MODwild): | |
2358 case X(MODconst, MODwild | MODshared): | |
98 | 2359 // foo(U:const(U)) const(T) => T |
2360 // foo(U:immutable(U)) immutable(T) => T | |
2361 // foo(U:shared(U)) shared(T) => T | |
2362 // foo(U:const(shared(U)) const(shared(T))=> T | |
135 | 2363 // foo(U:wild(U)) wild(T) => T |
2364 // foo(U:wild(shared(U)) wild(shared(T)) => T | |
2365 // foo(U:const(U)) wild(shared(T)) => shared(T) | |
98 | 2366 tt = mutableOf().unSharedOf(); |
0 | 2367 if (!at) |
110 | 2368 { |
94
3a0b150c9841
Objects -> Vector!Object iteration 1
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
87
diff
changeset
|
2369 dedtypes[i] = tt; |
0 | 2370 goto Lexact; |
2371 } | |
98 | 2372 break; |
2373 | |
2374 case X(MODconst, 0): | |
2375 case X(MODconst, MODimmutable): | |
2376 case X(MODconst, MODconst | MODshared): | |
2377 case X(MODconst | MODshared, MODimmutable): | |
135 | 2378 case X(MODshared, MODwild | MODshared): |
98 | 2379 // foo(U:const(U)) T => T |
2380 // foo(U:const(U)) immutable(T) => T | |
2381 // foo(U:const(U)) const(shared(T)) => shared(T) | |
2382 // foo(U:const(shared(U)) immutable(T) => T | |
135 | 2383 // foo(U:shared(U)) wild(shared(T)) => wild(T) |
0 | 2384 tt = mutableOf(); |
2385 if (!at) | |
110 | 2386 { dedtypes[i] = tt; |
98 | 2387 goto Lconst; |
0 | 2388 } |
98 | 2389 break; |
2390 | |
2391 case X(MODshared, MODconst | MODshared): | |
2392 case X(MODconst | MODshared, MODshared): | |
2393 // foo(U:shared(U)) const(shared(T)) => const(T) | |
2394 // foo(U:const(shared(U)) shared(T) => T | |
2395 tt = unSharedOf(); | |
0 | 2396 if (!at) |
110 | 2397 { dedtypes[i] = tt; |
0 | 2398 goto Lconst; |
2399 } | |
98 | 2400 break; |
2401 | |
2402 case X(MODimmutable, 0): | |
2403 case X(MODimmutable, MODconst): | |
2404 case X(MODimmutable, MODshared): | |
2405 case X(MODimmutable, MODconst | MODshared): | |
2406 case X(MODconst, MODshared): | |
2407 case X(MODshared, 0): | |
2408 case X(MODshared, MODconst): | |
2409 case X(MODshared, MODimmutable): | |
2410 case X(MODconst | MODshared, 0): | |
2411 case X(MODconst | MODshared, MODconst): | |
135 | 2412 case X(MODimmutable, MODwild): |
2413 case X(MODshared, MODwild): | |
2414 case X(MODconst | MODshared, MODwild): | |
2415 case X(MODwild, 0): | |
2416 case X(MODwild, MODconst): | |
2417 case X(MODwild, MODimmutable): | |
2418 case X(MODwild, MODshared): | |
2419 case X(MODwild, MODconst | MODshared): | |
2420 case X(MODwild | MODshared, 0): | |
2421 case X(MODwild | MODshared, MODconst): | |
2422 case X(MODwild | MODshared, MODimmutable): | |
2423 case X(MODwild | MODshared, MODshared): | |
2424 case X(MODwild | MODshared, MODconst | MODshared): | |
2425 case X(MODwild | MODshared, MODwild): | |
2426 case X(MODimmutable, MODwild | MODshared): | |
2427 case X(MODconst | MODshared, MODwild | MODshared): | |
2428 case X(MODwild, MODwild | MODshared): | |
98 | 2429 // foo(U:immutable(U)) T => nomatch |
2430 // foo(U:immutable(U)) const(T) => nomatch | |
2431 // foo(U:immutable(U)) shared(T) => nomatch | |
2432 // foo(U:immutable(U)) const(shared(T)) => nomatch | |
2433 // foo(U:const(U)) shared(T) => nomatch | |
2434 // foo(U:shared(U)) T => nomatch | |
2435 // foo(U:shared(U)) const(T) => nomatch | |
2436 // foo(U:shared(U)) immutable(T) => nomatch | |
2437 // foo(U:const(shared(U)) T => nomatch | |
2438 // foo(U:const(shared(U)) const(T) => nomatch | |
135 | 2439 // foo(U:immutable(U)) wild(T) => nomatch |
2440 // foo(U:shared(U)) wild(T) => nomatch | |
2441 // foo(U:const(shared(U)) wild(T) => nomatch | |
2442 // foo(U:wild(U)) T => nomatch | |
2443 // foo(U:wild(U)) const(T) => nomatch | |
2444 // foo(U:wild(U)) immutable(T) => nomatch | |
2445 // foo(U:wild(U)) shared(T) => nomatch | |
2446 // foo(U:wild(U)) const(shared(T)) => nomatch | |
2447 // foo(U:wild(shared(U)) T => nomatch | |
2448 // foo(U:wild(shared(U)) const(T) => nomatch | |
2449 // foo(U:wild(shared(U)) immutable(T) => nomatch | |
2450 // foo(U:wild(shared(U)) shared(T) => nomatch | |
2451 // foo(U:wild(shared(U)) const(shared(T)) => nomatch | |
2452 // foo(U:wild(shared(U)) wild(T) => nomatch | |
2453 // foo(U:immutable(U)) wild(shared(T)) => nomatch | |
2454 // foo(U:const(shared(U))) wild(shared(T)) => nomatch | |
2455 // foo(U:wild(U)) wild(shared(T)) => nomatch | |
98 | 2456 //if (!at) |
0 | 2457 goto Lnomatch; |
98 | 2458 break; |
2459 | |
2460 default: | |
2461 assert(0); | |
0 | 2462 } |
2463 | |
2464 if (tt.equals(at)) | |
2465 goto Lexact; | |
2466 else if (tt.ty == Tclass && at.ty == Tclass) | |
2467 { | |
2468 return tt.implicitConvTo(at); | |
2469 } | |
2470 else if (tt.ty == Tsarray && at.ty == Tarray && | |
2471 tt.nextOf().implicitConvTo(at.nextOf()) >= MATCHconst) | |
2472 { | |
2473 goto Lexact; | |
2474 } | |
2475 else | |
2476 goto Lnomatch; | |
2477 } | |
2478 | |
2479 if (ty != tparam.ty) | |
2480 return implicitConvTo(tparam); | |
2481 // goto Lnomatch; | |
2482 | |
2483 if (nextOf()) | |
2484 return nextOf().deduceType(sc, tparam.nextOf(), parameters, dedtypes); | |
2485 | |
2486 Lexact: | |
2487 return MATCHexact; | |
2488 | |
2489 Lnomatch: | |
2490 return MATCHnomatch; | |
2491 | |
2492 version (DMDV2) { | |
2493 Lconst: | |
2494 return MATCHconst; | |
2495 } | |
2496 } | |
2497 | |
2498 void resolve(Loc loc, Scope sc, Expression* pe, Type* pt, Dsymbol* ps) | |
2499 { | |
2500 //printf("Type.resolve() %s, %d\n", toChars(), ty); | |
2501 Type t = semantic(loc, sc); | |
2502 *pt = t; | |
2503 *pe = null; | |
2504 *ps = null; | |
2505 } | |
2506 | |
174 | 2507 static __gshared TypeInfoDeclaration internalTI[TMAX]; |
2508 | |
0 | 2509 /******************************************* |
2510 * Get a canonicalized form of the TypeInfo for use with the internal | |
2511 * runtime library routines. Canonicalized in that static arrays are | |
2512 * represented as dynamic arrays, enums are represented by their | |
2513 * underlying type, etc. This reduces the number of TypeInfo's needed, | |
2514 * so we can use the custom internal ones more. | |
2515 */ | |
2516 Expression getInternalTypeInfo(Scope sc) | |
2517 { | |
2518 TypeInfoDeclaration tid; | |
2519 Expression e; | |
2520 Type t; | |
2521 | |
2522 //printf("Type.getInternalTypeInfo() %s\n", toChars()); | |
2523 t = toBasetype(); | |
2524 switch (t.ty) | |
2525 { | |
2526 case Tsarray: | |
2527 static if (false) { | |
2528 // convert to corresponding dynamic array type | |
2529 t = t.nextOf().mutableOf().arrayOf(); | |
2530 } | |
2531 break; | |
2532 | |
2533 case Tclass: | |
2534 if ((cast(TypeClass)t).sym.isInterfaceDeclaration()) | |
2535 break; | |
2536 goto Linternal; | |
2537 | |
2538 case Tarray: | |
2539 // convert to corresponding dynamic array type | |
2540 t = t.nextOf().mutableOf().arrayOf(); | |
2541 if (t.nextOf().ty != Tclass) | |
2542 break; | |
2543 goto Linternal; | |
2544 | |
2545 case Tfunction: | |
2546 case Tdelegate: | |
2547 case Tpointer: | |
2548 Linternal: | |
2549 tid = internalTI[t.ty]; | |
2550 if (!tid) | |
174 | 2551 { |
0 | 2552 tid = new TypeInfoDeclaration(t, 1); |
2553 internalTI[t.ty] = tid; | |
2554 } | |
2555 e = new VarExp(Loc(0), tid); | |
2556 e = e.addressOf(sc); | |
2557 e.type = tid.type; // do this so we don't get redundant dereference | |
2558 return e; | |
2559 | |
2560 default: | |
2561 break; | |
2562 } | |
2563 //printf("\tcalling getTypeInfo() %s\n", t.toChars()); | |
2564 return t.getTypeInfo(sc); | |
2565 } | |
174 | 2566 |
0 | 2567 /**************************************************** |
2568 * Get the exact TypeInfo. | |
2569 */ | |
2570 Expression getTypeInfo(Scope sc) | |
2571 { | |
2572 Expression e; | |
2573 Type t; | |
2574 | |
2575 //printf("Type.getTypeInfo() %p, %s\n", this, toChars()); | |
2576 t = merge2(); // do this since not all Type's are merge'd | |
2577 if (!t.vtinfo) | |
2578 { | |
2579 version (DMDV2) { | |
2580 if (t.isShared()) // does both 'shared' and 'shared const' | |
2581 t.vtinfo = new TypeInfoSharedDeclaration(t); | |
2582 else if (t.isConst()) | |
2583 t.vtinfo = new TypeInfoConstDeclaration(t); | |
135 | 2584 else if (t.isImmutable()) |
0 | 2585 t.vtinfo = new TypeInfoInvariantDeclaration(t); |
135 | 2586 else if (t.isWild()) |
2587 t.vtinfo = new TypeInfoWildDeclaration(t); | |
2588 | |
0 | 2589 else |
2590 t.vtinfo = t.getTypeInfoDeclaration(); | |
2591 } else { | |
2592 t.vtinfo = t.getTypeInfoDeclaration(); | |
2593 } | |
2594 assert(t.vtinfo); | |
2595 vtinfo = t.vtinfo; | |
2596 | |
2597 /* If this has a custom implementation in std/typeinfo, then | |
2598 * do not generate a COMDAT for it. | |
2599 */ | |
2600 if (!t.builtinTypeInfo()) | |
174 | 2601 { |
0 | 2602 // Generate COMDAT |
2603 if (sc) // if in semantic() pass | |
174 | 2604 { |
0 | 2605 // Find module that will go all the way to an object file |
2606 Module m = sc.module_.importedFrom; | |
74
7e0d548de9e6
Switch Arrays of Dsymbols to the new templated Vector type
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
73
diff
changeset
|
2607 m.members.push(t.vtinfo); |
0 | 2608 } |
2609 else // if in obj generation pass | |
2610 { | |
2611 t.vtinfo.toObjFile(global.params.multiobj); | |
2612 } | |
2613 } | |
2614 } | |
2615 e = new VarExp(Loc(0), t.vtinfo); | |
2616 e = e.addressOf(sc); | |
2617 e.type = t.vtinfo.type; // do this so we don't get redundant dereference | |
2618 return e; | |
2619 } | |
174 | 2620 |
0 | 2621 TypeInfoDeclaration getTypeInfoDeclaration() |
2622 { | |
2623 //printf("Type.getTypeInfoDeclaration() %s\n", toChars()); | |
2624 return new TypeInfoDeclaration(this, 0); | |
2625 } | |
174 | 2626 |
0 | 2627 /* These decide if there's an instance for them already in std.typeinfo, |
2628 * because then the compiler doesn't need to build one. | |
2629 */ | |
2630 bool builtinTypeInfo() | |
2631 { | |
2632 return false; | |
2633 } | |
174 | 2634 |
0 | 2635 /******************************* |
2636 * If one of the subtypes of this type is a TypeIdentifier, | |
2637 * i.e. it's an unresolved type, return that type. | |
2638 */ | |
2639 Type reliesOnTident() | |
2640 { | |
2641 return null; | |
2642 } | |
174 | 2643 |
135 | 2644 /*************************************** |
2645 * Return !=0 if the type or any of its subtypes is wild. | |
2646 */ | |
2647 | |
2648 int hasWild() | |
2649 { | |
2650 return mod & MOD.MODwild; | |
2651 } | |
2652 | |
2653 /*************************************** | |
2654 * Return MOD bits matching argument type (targ) to wild parameter type (this). | |
2655 */ | |
2656 | |
2657 uint wildMatch(Type targ) | |
2658 { | |
2659 return 0; | |
2660 } | |
174 | 2661 |
0 | 2662 Expression toExpression() |
2663 { | |
2664 assert(false); | |
2665 } | |
174 | 2666 |
0 | 2667 /*************************************** |
2668 * Return true if type has pointers that need to | |
2669 * be scanned by the GC during a collection cycle. | |
2670 */ | |
2671 bool hasPointers() | |
2672 { | |
2673 return false; | |
2674 } | |
174 | 2675 |
0 | 2676 /************************************* |
2677 * If this is a type of something, return that something. | |
2678 */ | |
2679 Type nextOf() | |
2680 { | |
2681 return null; | |
2682 } | |
174 | 2683 |
53 | 2684 /**************************************** |
2685 * Return the mask that an integral type will | |
2686 * fit into. | |
2687 */ | |
0 | 2688 ulong sizemask() |
2689 { | |
53 | 2690 ulong m; |
2691 | |
2692 switch (toBasetype().ty) | |
2693 { | |
2694 case Tbool: m = 1; break; | |
2695 case Tchar: | |
2696 case Tint8: | |
2697 case Tuns8: m = 0xFF; break; | |
2698 case Twchar: | |
2699 case Tint16: | |
2700 case Tuns16: m = 0xFFFFUL; break; | |
2701 case Tdchar: | |
2702 case Tint32: | |
2703 case Tuns32: m = 0xFFFFFFFFUL; break; | |
2704 case Tint64: | |
2705 case Tuns64: m = 0xFFFFFFFFFFFFFFFFUL; break; | |
2706 default: | |
2707 assert(0); | |
2708 } | |
2709 return m; | |
0 | 2710 } |
174 | 2711 |
0 | 2712 static void error(T...)(Loc loc, string format, T t) |
2713 { | |
2714 .error(loc, format, t); | |
2715 } | |
174 | 2716 |
0 | 2717 static void warning(T...)(Loc loc, string format, T t) |
2718 { | |
2719 assert(false); | |
2720 } | |
2721 | |
2722 // For backend | |
2723 /***************************** | |
2724 * Return back end type corresponding to D front end type. | |
2725 */ | |
2726 TYM totym() | |
2727 { | |
2728 TYM t; | |
2729 | |
2730 switch (ty) | |
2731 { | |
2732 case TY.Tvoid: t = TYM.TYvoid; break; | |
2733 case TY.Tint8: t = TYM.TYschar; break; | |
2734 case TY.Tuns8: t = TYM.TYuchar; break; | |
2735 case TY.Tint16: t = TYM.TYshort; break; | |
2736 case TY.Tuns16: t = TYM.TYushort; break; | |
2737 case TY.Tint32: t = TYM.TYint; break; | |
2738 case TY.Tuns32: t = TYM.TYuint; break; | |
2739 case TY.Tint64: t = TYM.TYllong; break; | |
2740 case TY.Tuns64: t = TYM.TYullong; break; | |
2741 case TY.Tfloat32: t = TYM.TYfloat; break; | |
2742 case TY.Tfloat64: t = TYM.TYdouble; break; | |
2743 case TY.Tfloat80: t = TYM.TYldouble; break; | |
2744 case TY.Timaginary32: t = TYM.TYifloat; break; | |
2745 case TY.Timaginary64: t = TYM.TYidouble; break; | |
2746 case TY.Timaginary80: t = TYM.TYildouble; break; | |
2747 case TY.Tcomplex32: t = TYM.TYcfloat; break; | |
2748 case TY.Tcomplex64: t = TYM.TYcdouble; break; | |
2749 case TY.Tcomplex80: t = TYM.TYcldouble; break; | |
2750 //case Tbit: t = TYM.TYuchar; break; | |
2751 case TY.Tbool: t = TYM.TYbool; break; | |
2752 case TY.Tchar: t = TYM.TYchar; break; | |
2753 version (XXX) { ///TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_SOLARIS | |
2754 case TY.Twchar: t = TYM.TYwchar_t; break; | |
2755 case TY.Tdchar: t = TYM.TYdchar; break; | |
2756 } else { | |
2757 case TY.Twchar: t = TYM.TYwchar_t; break; | |
2758 case TY.Tdchar: | |
2759 t = (global.params.symdebug == 1) ? TYM.TYdchar : TYM.TYulong; | |
2760 break; | |
2761 } | |
2762 | |
2763 case TY.Taarray: t = TYM.TYaarray; break; | |
2764 case TY.Tclass: | |
2765 case TY.Treference: | |
2766 case TY.Tpointer: t = TYM.TYnptr; break; | |
2767 case TY.Tdelegate: t = TYM.TYdelegate; break; | |
2768 case TY.Tarray: t = TYM.TYdarray; break; | |
98 | 2769 version(SARRAYVALUE) |
2770 { case TY.Tsarray: t = TYstruct; break;} | |
2771 else | |
2772 { case TY.Tsarray: t = TYM.TYarray; break;} | |
0 | 2773 case TY.Tstruct: t = TYM.TYstruct; break; |
2774 | |
2775 case TY.Tenum: | |
2776 case TY.Ttypedef: | |
2777 t = toBasetype().totym(); | |
2778 break; | |
2779 | |
2780 case TY.Tident: | |
2781 case TY.Ttypeof: | |
2782 debug { | |
2783 writef("ty = %d, '%s'\n", ty, toChars()); | |
2784 } | |
2785 error (Loc(0), "forward reference of %s", toChars()); | |
2786 t = TYM.TYint; | |
2787 break; | |
2788 | |
2789 default: | |
2790 debug { | |
2791 writef("ty = %d, '%s'\n", ty, toChars()); | |
2792 } | |
2793 assert(0); | |
2794 } | |
2795 | |
2796 version (DMDV2) { | |
2797 // Add modifiers | |
2798 switch (mod) | |
2799 { | |
2800 case MOD.MODundefined: | |
2801 break; | |
2802 case MOD.MODconst: | |
135 | 2803 case MOD.MODwild: |
0 | 2804 t |= mTY.mTYconst; |
2805 break; | |
135 | 2806 case MOD.MODimmutable: |
0 | 2807 t |= mTY.mTYimmutable; |
2808 break; | |
2809 case MOD.MODshared: | |
2810 t |= mTY.mTYshared; | |
2811 break; | |
135 | 2812 case MOD.MODshared | MOD.MODwild: |
0 | 2813 case MOD.MODshared | MOD.MODconst: |
2814 t |= mTY.mTYshared | mTY.mTYconst; | |
2815 break; | |
2816 default: | |
2817 assert(0); | |
2818 } | |
2819 } | |
2820 | |
2821 return t; | |
2822 } | |
174 | 2823 |
0 | 2824 /*************************************** |
2825 * Convert from D type to C type. | |
2826 * This is done so C debug info can be generated. | |
2827 */ | |
2828 type* toCtype() | |
2829 { | |
2830 if (!ctype) | |
2831 { | |
2832 ctype = type_fake(totym()); | |
2833 ctype.Tcount++; | |
2834 } | |
2835 return ctype; | |
2836 } | |
174 | 2837 |
0 | 2838 type* toCParamtype() |
2839 { | |
2840 return toCtype(); | |
2841 } | |
174 | 2842 |
0 | 2843 Symbol* toSymbol() |
2844 { | |
2845 assert(false); | |
2846 } | |
174 | 2847 |
0 | 2848 // For eliminating dynamic_cast |
2849 TypeBasic isTypeBasic() | |
2850 { | |
2851 return null; | |
2852 } | |
2853 | |
2854 static Type tvoid() | |
2855 { | |
2856 return basic[TY.Tvoid]; | |
2857 } | |
2858 | |
2859 static Type tint8() | |
2860 { | |
2861 return basic[TY.Tint8]; | |
2862 } | |
2863 | |
2864 static Type tuns8() | |
2865 { | |
2866 return basic[TY.Tuns8]; | |
2867 } | |
2868 | |
2869 static Type tint16() | |
2870 { | |
2871 return basic[TY.Tint16]; | |
2872 } | |
2873 | |
2874 static Type tuns16() | |
2875 { | |
2876 return basic[TY.Tuns16]; | |
2877 } | |
2878 | |
2879 static Type tint32() | |
2880 { | |
2881 return basic[TY.Tint32]; | |
2882 } | |
2883 | |
2884 static Type tuns32() | |
2885 { | |
2886 return basic[TY.Tuns32]; | |
2887 } | |
2888 | |
2889 static Type tint64() | |
2890 { | |
2891 return basic[TY.Tint64]; | |
2892 } | |
2893 | |
2894 static Type tuns64() | |
2895 { | |
2896 return basic[TY.Tuns64]; | |
2897 } | |
2898 | |
2899 static Type tfloat32() | |
2900 { | |
2901 return basic[TY.Tfloat32]; | |
2902 } | |
2903 | |
2904 static Type tfloat64() | |
2905 { | |
2906 return basic[TY.Tfloat64]; | |
2907 } | |
2908 | |
2909 static Type tfloat80() | |
2910 { | |
2911 return basic[TY.Tfloat80]; | |
2912 } | |
2913 | |
2914 static Type timaginary32() | |
2915 { | |
2916 return basic[TY.Timaginary32]; | |
2917 } | |
2918 | |
2919 static Type timaginary64() | |
2920 { | |
2921 return basic[TY.Timaginary64]; | |
2922 } | |
2923 | |
2924 static Type timaginary80() | |
2925 { | |
2926 return basic[TY.Timaginary80]; | |
2927 } | |
2928 | |
2929 static Type tcomplex32() | |
2930 { | |
2931 return basic[TY.Tcomplex32]; | |
2932 } | |
2933 | |
2934 static Type tcomplex64() | |
2935 { | |
2936 return basic[TY.Tcomplex64]; | |
2937 } | |
2938 | |
2939 static Type tcomplex80() | |
2940 { | |
2941 return basic[TY.Tcomplex80]; | |
2942 } | |
2943 | |
2944 static Type tbit() | |
2945 { | |
2946 return basic[TY.Tbit]; | |
2947 } | |
2948 | |
2949 static Type tbool() | |
2950 { | |
2951 return basic[TY.Tbool]; | |
2952 } | |
2953 | |
2954 static Type tchar() | |
2955 { | |
2956 return basic[TY.Tchar]; | |
2957 } | |
2958 | |
2959 static Type twchar() | |
2960 { | |
2961 return basic[TY.Twchar]; | |
2962 } | |
2963 | |
2964 static Type tdchar() | |
2965 { | |
2966 return basic[TY.Tdchar]; | |
2967 } | |
174 | 2968 |
0 | 2969 // Some special types |
2970 static Type tshiftcnt() | |
2971 { | |
2972 return tint32; // right side of shift expression | |
2973 } | |
2974 | |
2975 // #define tboolean tint32 // result of boolean expression | |
2976 static Type tboolean() | |
2977 { | |
2978 return tbool; // result of boolean expression | |
2979 } | |
174 | 2980 |
0 | 2981 static Type tindex() |
2982 { | |
2983 return tint32; // array/ptr index | |
2984 } | |
174 | 2985 |
2986 static __gshared Type tvoidptr; // void* | |
2987 static __gshared Type tstring; // immutable(char)[] | |
98 | 2988 |
0 | 2989 static Type terror() |
2990 { | |
2991 return basic[TY.Terror]; // for error recovery | |
2992 } | |
2993 | |
2994 static Type tsize_t() | |
2995 { | |
2996 return basic[Tsize_t]; // matches size_t alias | |
2997 } | |
174 | 2998 |
0 | 2999 static Type tptrdiff_t() |
3000 { | |
3001 return basic[Tptrdiff_t]; // matches ptrdiff_t alias | |
3002 } | |
174 | 3003 |
0 | 3004 static Type thash_t() |
3005 { | |
3006 return tsize_t; // matches hash_t alias | |
3007 } | |
14
2cc604139636
Implemented Linux support for ddmd. Some parts are a bit hacky to just "get it working", that said, druntime and phobos compile, and unittests pass.
Robert Clipsham <robert@octarineparrot.com>
parents:
4
diff
changeset
|
3008 } |