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