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