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