Mercurial > projects > ddmd
annotate dmd/Type.d @ 183:190ba98276b3
Several changes to make it build on posix systems.
I've only tried to build on Mac OS X but it should build on Linux now as well.
This should also fix ticket #9.
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Mon, 25 Oct 2010 15:36:13 +0200 |
parents | e3afd1303184 |
children | b0d41ff5e0df |
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) { | |
183
190ba98276b3
Several changes to make it build on posix systems.
Jacob Carlborg <doob@me.com>
parents:
178
diff
changeset
|
939 import dmd.CppMangleState; |
190ba98276b3
Several changes to make it build on posix systems.
Jacob Carlborg <doob@me.com>
parents:
178
diff
changeset
|
940 |
0 | 941 void toCppMangle(OutBuffer buf, CppMangleState* cms) |
942 { | |
943 assert(false); | |
944 } | |
945 } | |
946 bool isintegral() | |
947 { | |
948 return false; | |
949 } | |
174 | 950 |
0 | 951 bool isfloating() // real, imaginary, or complex |
952 { | |
953 return false; | |
954 } | |
174 | 955 |
0 | 956 bool isreal() |
957 { | |
958 return false; | |
959 } | |
174 | 960 |
0 | 961 bool isimaginary() |
962 { | |
963 return false; | |
964 } | |
174 | 965 |
0 | 966 bool iscomplex() |
967 { | |
968 return false; | |
969 } | |
174 | 970 |
0 | 971 bool isscalar() |
972 { | |
973 return false; | |
974 } | |
174 | 975 |
0 | 976 bool isunsigned() |
977 { | |
978 return false; | |
979 } | |
174 | 980 |
0 | 981 bool isauto() |
982 { | |
983 return false; | |
984 } | |
174 | 985 |
12
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
4
diff
changeset
|
986 bool isString() |
0 | 987 { |
988 return false; | |
989 } | |
174 | 990 |
0 | 991 /************************** |
992 * Given: | |
993 * T a, b; | |
994 * Can we assign: | |
995 * a = b; | |
996 * ? | |
997 */ | |
73 | 998 bool isAssignable() |
0 | 999 { |
1000 return true; | |
1001 } | |
174 | 1002 |
0 | 1003 bool checkBoolean() // if can be converted to boolean value |
1004 { | |
1005 return isscalar(); | |
1006 } | |
1007 | |
1008 /********************************* | |
1009 * Check type to see if it is based on a deprecated symbol. | |
1010 */ | |
1011 void checkDeprecated(Loc loc, Scope sc) | |
1012 { | |
1013 Dsymbol s = toDsymbol(sc); | |
1014 if (s) | |
1015 s.checkDeprecated(loc, sc); | |
1016 } | |
1017 | |
1018 bool isConst() { return (mod & MOD.MODconst) != 0; } | |
1019 | |
135 | 1020 int isImmutable() { return mod & MOD.MODimmutable; } |
0 | 1021 |
135 | 1022 int isMutable() { return !(mod & (MOD.MODconst | MOD.MODimmutable | MOD.MODwild)); } |
0 | 1023 |
1024 int isShared() { return mod & MOD.MODshared; } | |
1025 | |
1026 int isSharedConst() { return mod == (MOD.MODshared | MOD.MODconst); } | |
174 | 1027 |
135 | 1028 int isWild() { return mod & MOD.MODwild; } |
1029 | |
1030 int isSharedWild() { return mod == (MOD.MODshared | MOD.MODwild); } | |
1031 | |
1032 int isNaked() { return mod == 0; } | |
1033 | |
0 | 1034 |
1035 /******************************** | |
1036 * Convert to 'const'. | |
1037 */ | |
1038 Type constOf() | |
1039 { | |
1040 //printf("Type.constOf() %p %s\n", this, toChars()); | |
1041 if (mod == MOD.MODconst) | |
1042 return this; | |
1043 if (cto) | |
1044 { | |
1045 assert(cto.mod == MOD.MODconst); | |
1046 return cto; | |
1047 } | |
1048 Type t = makeConst(); | |
1049 t = t.merge(); | |
1050 t.fixTo(this); | |
1051 //printf("-Type.constOf() %p %s\n", t, toChars()); | |
1052 return t; | |
1053 } | |
1054 | |
1055 /******************************** | |
1056 * Convert to 'immutable'. | |
1057 */ | |
1058 Type invariantOf() | |
174 | 1059 { |
0 | 1060 //printf("Type.invariantOf() %p %s\n", this, toChars()); |
135 | 1061 if (isImmutable()) |
0 | 1062 { |
1063 return this; | |
1064 } | |
1065 if (ito) | |
1066 { | |
135 | 1067 assert(ito.isImmutable()); |
0 | 1068 return ito; |
1069 } | |
1070 Type t = makeInvariant(); | |
1071 t = t.merge(); | |
1072 t.fixTo(this); | |
1073 //printf("\t%p\n", t); | |
1074 return t; | |
1075 } | |
1076 | |
1077 Type mutableOf() | |
1078 { | |
1079 //printf("Type.mutableOf() %p, %s\n", this, toChars()); | |
1080 Type t = this; | |
1081 if (isConst()) | |
174 | 1082 { |
0 | 1083 if (isShared()) |
1084 t = sto; // shared const => shared | |
1085 else | |
135 | 1086 t = cto; // const => naked |
0 | 1087 assert(!t || t.isMutable()); |
1088 } | |
135 | 1089 else if (isImmutable()) |
174 | 1090 { |
0 | 1091 t = ito; |
1092 assert(!t || (t.isMutable() && !t.isShared())); | |
1093 } | |
135 | 1094 else if (isWild()) |
1095 { | |
1096 if (isShared()) | |
1097 t = sto; // shared wild => shared | |
1098 else | |
1099 t = wto; // wild => naked | |
1100 assert(!t || t.isMutable()); | |
1101 } | |
0 | 1102 if (!t) |
1103 { | |
135 | 1104 t = makeMutable(); |
0 | 1105 t = t.merge(); |
1106 t.fixTo(this); | |
1107 } | |
135 | 1108 assert(t.isMutable()); |
0 | 1109 return t; |
1110 } | |
1111 | |
1112 Type sharedOf() | |
1113 { | |
1114 //printf("Type.sharedOf() %p, %s\n", this, toChars()); | |
1115 if (mod == MOD.MODshared) | |
1116 { | |
1117 return this; | |
1118 } | |
1119 if (sto) | |
1120 { | |
1121 assert(sto.isShared()); | |
1122 return sto; | |
1123 } | |
1124 | |
1125 Type t = makeShared(); | |
1126 t = t.merge(); | |
1127 t.fixTo(this); | |
1128 | |
1129 //printf("\t%p\n", t); | |
1130 return t; | |
1131 } | |
1132 | |
1133 Type sharedConstOf() | |
1134 { | |
1135 //printf("Type.sharedConstOf() %p, %s\n", this, toChars()); | |
1136 if (mod == (MODshared | MODconst)) | |
1137 { | |
1138 return this; | |
1139 } | |
1140 if (scto) | |
1141 { | |
1142 assert(scto.mod == (MODshared | MODconst)); | |
1143 return scto; | |
1144 } | |
1145 | |
1146 Type t = makeSharedConst(); | |
1147 t = t.merge(); | |
1148 t.fixTo(this); | |
1149 //printf("\t%p\n", t); | |
1150 | |
1151 return t; | |
1152 } | |
98 | 1153 |
1154 /******************************** | |
1155 * Make type unshared. | |
135 | 1156 * 0 => 0 |
1157 * const => const | |
1158 * immutable => immutable | |
1159 * shared => 0 | |
1160 * shared const => const | |
1161 * wild => wild | |
1162 * shared wild => wild | |
98 | 1163 */ |
1164 Type unSharedOf() | |
1165 { | |
1166 //writef("Type::unSharedOf() %p, %s\n", this, toChars()); | |
1167 Type t = this; | |
1168 | |
1169 if (isShared()) | |
1170 { | |
1171 if (isConst()) | |
1172 t = cto; // shared const => const | |
135 | 1173 else if (isWild()) |
1174 t = wto; // shared wild => wild | |
98 | 1175 else |
1176 t = sto; | |
1177 assert(!t || !t.isShared()); | |
1178 } | |
1179 | |
1180 if (!t) | |
1181 { | |
178 | 1182 t = cloneThis(this); |
98 | 1183 t.mod = mod & ~MODshared; |
1184 t.deco = null; | |
1185 t.arrayof = null; | |
1186 t.pto = null; | |
1187 t.rto = null; | |
1188 t.cto = null; | |
1189 t.ito = null; | |
1190 t.sto = null; | |
1191 t.scto = null; | |
135 | 1192 t.wto = null; |
1193 t.swto = null; | |
98 | 1194 t.vtinfo = null; |
1195 t = t.merge(); | |
174 | 1196 |
98 | 1197 t.fixTo(this); |
1198 } | |
1199 assert(!t.isShared()); | |
1200 return t; | |
1201 } | |
1202 | |
174 | 1203 |
135 | 1204 /******************************** |
1205 * Convert to 'wild'. | |
1206 */ | |
1207 | |
1208 Type wildOf() | |
1209 { | |
1210 //printf("Type::wildOf() %p %s\n", this, toChars()); | |
1211 if (mod == MOD.MODwild) | |
1212 { | |
1213 return this; | |
1214 } | |
1215 if (wto) | |
1216 { | |
1217 assert(wto.isWild()); | |
1218 return wto; | |
1219 } | |
1220 Type t = makeWild(); | |
1221 t = t.merge(); | |
1222 t.fixTo(this); | |
1223 //printf("\t%p %s\n", t, t->toChars()); | |
1224 return t; | |
1225 } | |
1226 | |
1227 Type sharedWildOf() | |
1228 { | |
1229 //printf("Type::sharedWildOf() %p, %s\n", this, toChars()); | |
1230 if (mod == (MOD.MODwild)) | |
1231 { | |
1232 return this; | |
1233 } | |
1234 if (swto) | |
1235 { | |
1236 assert(swto.mod == (MOD.MODshared | MOD.MODwild)); | |
1237 return swto; | |
1238 } | |
1239 Type t = makeSharedWild(); | |
1240 t = t.merge(); | |
1241 t.fixTo(this); | |
1242 //printf("\t%p\n", t); | |
1243 return t; | |
1244 } | |
1245 | |
0 | 1246 static uint X(MOD m, MOD n) |
1247 { | |
135 | 1248 return (((m) << 4) | (n)); |
0 | 1249 } |
1250 | |
1251 /********************************** | |
1252 * For our new type 'this', which is type-constructed from t, | |
135 | 1253 * fill in the cto, ito, sto, scto, wto shortcuts. |
0 | 1254 */ |
1255 void fixTo(Type t) | |
1256 { | |
1257 ito = t.ito; | |
1258 static if (false) { | |
1259 /* Cannot do these because these are not fully transitive: | |
1260 * there can be a shared ptr to immutable, for example. | |
1261 * Immutable subtypes are always immutable, though. | |
1262 */ | |
1263 cto = t.cto; | |
1264 sto = t.sto; | |
1265 scto = t.scto; | |
1266 } | |
1267 | |
1268 assert(mod != t.mod); | |
1269 | |
1270 switch (X(mod, t.mod)) | |
1271 { | |
1272 case X(MOD.MODundefined, MOD.MODconst): | |
1273 cto = t; | |
1274 break; | |
1275 | |
135 | 1276 case X(MOD.MODundefined, MOD.MODimmutable): |
0 | 1277 ito = t; |
1278 break; | |
1279 | |
1280 case X(MOD.MODundefined, MOD.MODshared): | |
1281 sto = t; | |
1282 break; | |
1283 | |
1284 case X(MOD.MODundefined, MOD.MODshared | MOD.MODconst): | |
1285 scto = t; | |
1286 break; | |
1287 | |
135 | 1288 case X(MOD.MODundefined, MODwild): |
1289 wto = t; | |
1290 break; | |
1291 | |
1292 case X(MOD.MODundefined, MODshared | MODwild): | |
1293 swto = t; | |
1294 break; | |
1295 | |
0 | 1296 |
1297 case X(MOD.MODconst, MOD.MODundefined): | |
1298 cto = null; | |
1299 goto L2; | |
1300 | |
135 | 1301 case X(MOD.MODconst, MOD.MODimmutable): |
0 | 1302 ito = t; |
1303 goto L2; | |
1304 | |
1305 case X(MOD.MODconst, MOD.MODshared): | |
1306 sto = t; | |
1307 goto L2; | |
1308 | |
1309 case X(MOD.MODconst, MOD.MODshared | MOD.MODconst): | |
1310 scto = t; | |
135 | 1311 goto L2; |
1312 | |
1313 case X(MOD.MODconst, MOD.MODwild): | |
1314 wto = t; | |
1315 goto L2; | |
1316 | |
1317 case X(MOD.MODconst, MOD.MODshared | MOD.MODwild): | |
1318 swto = t; | |
0 | 1319 L2: |
1320 t.cto = this; | |
1321 break; | |
1322 | |
1323 | |
135 | 1324 case X(MOD.MODimmutable, MOD.MODundefined): |
0 | 1325 ito = null; |
1326 goto L3; | |
1327 | |
135 | 1328 case X(MOD.MODimmutable, MOD.MODconst): |
0 | 1329 cto = t; |
1330 goto L3; | |
1331 | |
135 | 1332 case X(MOD.MODimmutable, MOD.MODshared): |
0 | 1333 sto = t; |
1334 goto L3; | |
1335 | |
135 | 1336 case X(MOD.MODimmutable, MOD.MODshared | MOD.MODconst): |
0 | 1337 scto = t; |
135 | 1338 goto L3; |
1339 | |
1340 case X(MOD.MODimmutable, MOD.MODwild): | |
1341 wto = t; | |
1342 goto L3; | |
1343 | |
1344 case X(MOD.MODimmutable, MOD.MODshared | MOD.MODwild): | |
1345 swto = t; | |
0 | 1346 L3: |
1347 t.ito = this; | |
1348 if (t.cto) t.cto.ito = this; | |
1349 if (t.sto) t.sto.ito = this; | |
1350 if (t.scto) t.scto.ito = this; | |
135 | 1351 if (t.wto) t.wto.ito = this; |
1352 if (t.swto) t.swto.ito = this; | |
0 | 1353 break; |
1354 | |
1355 | |
1356 case X(MOD.MODshared, MOD.MODundefined): | |
1357 sto = null; | |
1358 goto L4; | |
1359 | |
1360 case X(MOD.MODshared, MOD.MODconst): | |
1361 cto = t; | |
1362 goto L4; | |
1363 | |
135 | 1364 case X(MOD.MODshared, MOD.MODimmutable): |
0 | 1365 ito = t; |
1366 goto L4; | |
1367 | |
1368 case X(MOD.MODshared, MOD.MODshared | MOD.MODconst): | |
1369 scto = t; | |
135 | 1370 goto L4; |
1371 | |
1372 case X(MOD.MODshared, MOD.MODwild): | |
1373 wto = t; | |
1374 goto L4; | |
1375 | |
1376 case X(MOD.MODshared, MOD.MODshared | MOD.MODwild): | |
1377 swto = t; | |
0 | 1378 L4: |
1379 t.sto = this; | |
1380 break; | |
1381 | |
1382 | |
1383 case X(MOD.MODshared | MOD.MODconst, MOD.MODundefined): | |
1384 scto = null; | |
135 | 1385 goto L5; |
0 | 1386 |
1387 case X(MOD.MODshared | MOD.MODconst, MOD.MODconst): | |
1388 cto = t; | |
135 | 1389 goto L5; |
0 | 1390 |
135 | 1391 case X(MOD.MODshared | MOD.MODconst, MOD.MODimmutable): |
0 | 1392 ito = t; |
135 | 1393 goto L5; |
1394 | |
1395 case X(MOD.MODshared | MOD.MODconst, MOD.MODwild): | |
1396 wto = t; | |
1397 goto L5; | |
0 | 1398 |
1399 case X(MOD.MODshared | MOD.MODconst, MOD.MODshared): | |
1400 sto = t; | |
135 | 1401 goto L5; |
1402 | |
1403 case X(MOD.MODshared | MOD.MODconst, MOD.MODshared | MOD.MODwild): | |
1404 swto = t; | |
0 | 1405 L5: |
1406 t.scto = this; | |
1407 break; | |
174 | 1408 |
135 | 1409 case X(MOD.MODwild, MOD.MODundefined): |
1410 wto = null; | |
1411 goto L6; | |
1412 | |
1413 case X(MOD.MODwild, MOD.MODconst): | |
1414 cto = t; | |
1415 goto L6; | |
1416 | |
1417 case X(MOD.MODwild, MOD.MODimmutable): | |
1418 ito = t; | |
1419 goto L6; | |
1420 | |
1421 case X(MOD.MODwild, MOD.MODshared): | |
1422 sto = t; | |
1423 goto L6; | |
1424 | |
1425 case X(MOD.MODwild, MOD.MODshared | MOD.MODconst): | |
1426 scto = t; | |
1427 goto L6; | |
1428 | |
1429 case X(MOD.MODwild, MOD.MODshared | MOD.MODwild): | |
1430 swto = t; | |
1431 L6: | |
1432 t.wto = this; | |
1433 break; | |
1434 | |
1435 | |
1436 case X(MOD.MODshared | MOD.MODwild, MOD.MODundefined): | |
1437 swto = null; | |
1438 goto L7; | |
1439 | |
1440 case X(MOD.MODshared | MOD.MODwild, MOD.MODconst): | |
1441 cto = t; | |
1442 goto L7; | |
1443 | |
1444 case X(MOD.MODshared | MOD.MODwild, MOD.MODimmutable): | |
1445 ito = t; | |
1446 goto L7; | |
1447 | |
1448 case X(MOD.MODshared | MOD.MODwild, MOD.MODshared): | |
1449 sto = t; | |
1450 goto L7; | |
1451 | |
1452 case X(MOD.MODshared | MOD.MODwild, MOD.MODshared | MOD.MODconst): | |
1453 scto = t; | |
1454 goto L7; | |
1455 | |
1456 case X(MOD.MODshared | MOD.MODwild, MOD.MODwild): | |
1457 wto = t; | |
1458 L7: | |
1459 t.swto = this; | |
1460 break; | |
0 | 1461 } |
1462 | |
1463 check(); | |
1464 t.check(); | |
1465 //printf("fixTo: %s, %s\n", toChars(), t.toChars()); | |
1466 } | |
174 | 1467 |
0 | 1468 /*************************** |
1469 * Look for bugs in constructing types. | |
1470 */ | |
1471 void check() | |
1472 { | |
1473 switch (mod) | |
1474 { | |
1475 case MOD.MODundefined: | |
1476 if (cto) assert(cto.mod == MOD.MODconst); | |
135 | 1477 if (ito) assert(ito.mod == MOD.MODimmutable); |
0 | 1478 if (sto) assert(sto.mod == MOD.MODshared); |
1479 if (scto) assert(scto.mod == (MOD.MODshared | MOD.MODconst)); | |
135 | 1480 if (wto) assert(wto.mod == MOD.MODwild); |
1481 if (swto) assert(swto.mod == (MOD.MODshared | MOD.MODwild)); | |
0 | 1482 break; |
1483 | |
1484 case MOD.MODconst: | |
1485 if (cto) assert(cto.mod == MOD.MODundefined); | |
135 | 1486 if (ito) assert(ito.mod == MOD.MODimmutable); |
0 | 1487 if (sto) assert(sto.mod == MOD.MODshared); |
1488 if (scto) assert(scto.mod == (MOD.MODshared | MOD.MODconst)); | |
135 | 1489 if (wto) assert(wto.mod == MOD.MODwild); |
1490 if (swto) assert(swto.mod == (MOD.MODshared | MOD.MODwild)); | |
0 | 1491 break; |
1492 | |
135 | 1493 case MOD.MODimmutable: |
0 | 1494 if (cto) assert(cto.mod == MOD.MODconst); |
1495 if (ito) assert(ito.mod == MOD.MODundefined); | |
1496 if (sto) assert(sto.mod == MOD.MODshared); | |
1497 if (scto) assert(scto.mod == (MOD.MODshared | MOD.MODconst)); | |
135 | 1498 if (wto) assert(wto.mod == MOD.MODwild); |
1499 if (swto) assert(swto.mod == (MOD.MODshared | MOD.MODwild)); | |
0 | 1500 break; |
1501 | |
1502 case MOD.MODshared: | |
1503 if (cto) assert(cto.mod == MOD.MODconst); | |
135 | 1504 if (ito) assert(ito.mod == MOD.MODimmutable); |
0 | 1505 if (sto) assert(sto.mod == MOD.MODundefined); |
1506 if (scto) assert(scto.mod == (MOD.MODshared | MOD.MODconst)); | |
135 | 1507 if (wto) assert(wto.mod == MOD.MODwild); |
1508 if (swto) assert(swto.mod == (MOD.MODshared | MOD.MODwild)); | |
0 | 1509 break; |
1510 | |
1511 case MOD.MODshared | MOD.MODconst: | |
1512 if (cto) assert(cto.mod == MOD.MODconst); | |
135 | 1513 if (ito) assert(ito.mod == MOD.MODimmutable); |
0 | 1514 if (sto) assert(sto.mod == MOD.MODshared); |
1515 if (scto) assert(scto.mod == MOD.MODundefined); | |
135 | 1516 if (wto) assert(wto.mod == MOD.MODwild); |
1517 if (swto) assert(swto.mod == (MOD.MODshared | MOD.MODwild)); | |
0 | 1518 break; |
174 | 1519 |
135 | 1520 case MOD.MODwild: |
1521 if (cto) assert(cto.mod == MOD.MODconst); | |
1522 if (ito) assert(ito.mod == MOD.MODimmutable); | |
1523 if (sto) assert(sto.mod == MOD.MODshared); | |
1524 if (scto) assert(scto.mod == (MOD.MODshared | MOD.MODconst)); | |
1525 if (wto) assert(wto.mod == MOD.MODundefined); | |
1526 if (swto) assert(swto.mod == (MOD.MODshared | MOD.MODwild)); | |
1527 break; | |
1528 | |
1529 case MOD.MODshared | MOD.MODwild: | |
1530 if (cto) assert(cto.mod == MOD.MODconst); | |
1531 if (ito) assert(ito.mod == MOD.MODimmutable); | |
1532 if (sto) assert(sto.mod == MOD.MODshared); | |
1533 if (scto) assert(scto.mod == (MOD.MODshared | MOD.MODconst)); | |
1534 if (wto) assert(wto.mod == MOD.MODwild); | |
1535 if (swto) assert(swto.mod == MOD.MODundefined); | |
1536 break; | |
0 | 1537 } |
1538 | |
1539 Type tn = nextOf(); | |
1540 if (tn && ty != TY.Tfunction && ty != TY.Tdelegate) | |
1541 { | |
1542 // Verify transitivity | |
1543 switch (mod) | |
1544 { | |
1545 case MOD.MODundefined: | |
1546 break; | |
1547 | |
1548 case MOD.MODconst: | |
135 | 1549 assert(tn.mod & MOD.MODimmutable || tn.mod & MOD.MODconst); |
0 | 1550 break; |
1551 | |
135 | 1552 case MOD.MODimmutable: |
1553 assert(tn.mod == MOD.MODimmutable); | |
0 | 1554 break; |
1555 | |
1556 case MOD.MODshared: | |
135 | 1557 assert(tn.mod & MOD.MODimmutable || tn.mod & MOD.MODshared); |
0 | 1558 break; |
1559 | |
1560 case MOD.MODshared | MOD.MODconst: | |
135 | 1561 assert(tn.mod & MOD.MODimmutable || tn.mod & (MOD.MODshared | MOD.MODconst)); |
1562 break; | |
1563 | |
1564 case MOD.MODwild: | |
1565 assert(tn.mod); | |
1566 break; | |
1567 | |
1568 case MOD.MODshared | MOD.MODwild: | |
1569 assert(tn.mod == MOD.MODimmutable || tn.mod == (MOD.MODshared | MOD.MODconst) || tn.mod == (MOD.MODshared | MOD.MODwild)); | |
0 | 1570 break; |
1571 } | |
1572 tn.check(); | |
1573 } | |
1574 } | |
1575 | |
51 | 1576 /************************************ |
1577 * Apply MODxxxx bits to existing type. | |
1578 */ | |
0 | 1579 Type castMod(uint mod) |
1580 { | |
51 | 1581 Type t; |
1582 | |
1583 switch (mod) | |
1584 { | |
1585 case 0: | |
135 | 1586 t = unSharedOf().mutableOf(); |
51 | 1587 break; |
1588 | |
1589 case MODconst: | |
135 | 1590 t = unSharedOf().constOf(); |
51 | 1591 break; |
1592 | |
135 | 1593 case MODimmutable: |
51 | 1594 t = invariantOf(); |
1595 break; | |
1596 | |
1597 case MODshared: | |
135 | 1598 t = mutableOf().sharedOf(); |
51 | 1599 break; |
1600 | |
1601 case MODshared | MODconst: | |
1602 t = sharedConstOf(); | |
135 | 1603 break; |
1604 | |
1605 case MODwild: | |
1606 t = unSharedOf().wildOf(); | |
1607 break; | |
1608 | |
1609 case MODshared | MODwild: | |
1610 t = sharedWildOf(); | |
51 | 1611 break; |
1612 | |
1613 default: | |
1614 assert(0); | |
1615 } | |
1616 return t; | |
0 | 1617 } |
174 | 1618 |
0 | 1619 /************************************ |
1620 * Add MODxxxx bits to existing type. | |
1621 * We're adding, not replacing, so adding const to | |
1622 * a shared type => "shared const" | |
1623 */ | |
1624 Type addMod(MOD mod) | |
1625 { | |
1626 Type t = this; | |
1627 | |
1628 /* Add anything to immutable, and it remains immutable | |
1629 */ | |
135 | 1630 //printf("addMod(%x) %s\n", mod, toChars()); |
1631 if (!t.isImmutable()) | |
0 | 1632 { |
1633 switch (mod) | |
1634 { | |
1635 case MOD.MODundefined: | |
1636 break; | |
1637 | |
1638 case MOD.MODconst: | |
1639 if (isShared()) | |
1640 t = sharedConstOf(); | |
1641 else | |
1642 t = constOf(); | |
1643 break; | |
1644 | |
135 | 1645 case MOD.MODimmutable: |
0 | 1646 t = invariantOf(); |
1647 break; | |
1648 | |
1649 case MOD.MODshared: | |
1650 if (isConst()) | |
1651 t = sharedConstOf(); | |
135 | 1652 else if (isWild()) |
1653 t = sharedWildOf(); | |
0 | 1654 else |
1655 t = sharedOf(); | |
1656 break; | |
1657 | |
1658 case MOD.MODshared | MOD.MODconst: | |
1659 t = sharedConstOf(); | |
1660 break; | |
174 | 1661 |
135 | 1662 case MOD.MODwild: |
1663 if (isConst()) | |
1664 {} | |
1665 else if (isShared()) | |
1666 t = sharedWildOf(); | |
1667 else | |
1668 t = wildOf(); | |
1669 break; | |
1670 | |
1671 case MOD.MODshared | MOD.MODwild: | |
1672 t = sharedWildOf(); | |
1673 break; | |
0 | 1674 } |
1675 } | |
1676 return t; | |
1677 } | |
174 | 1678 |
131
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
1679 Type addStorageClass(StorageClass stc) |
0 | 1680 { |
1681 /* Just translate to MOD bits and let addMod() do the work | |
1682 */ | |
1683 MOD mod = MOD.MODundefined; | |
1684 | |
1685 if (stc & STC.STCimmutable) | |
135 | 1686 mod = MOD.MODimmutable; |
0 | 1687 else |
174 | 1688 { |
0 | 1689 if (stc & (STC.STCconst | STC.STCin)) |
1690 mod = MOD.MODconst; | |
1691 if (stc & STC.STCshared) | |
1692 mod |= MOD.MODshared; | |
135 | 1693 if (stc & STC.STCwild) |
1694 mod |= MOD.MODwild; | |
0 | 1695 } |
1696 | |
1697 return addMod(mod); | |
1698 } | |
174 | 1699 |
0 | 1700 Type pointerTo() |
1701 { | |
1702 if (pto is null) | |
1703 { | |
1704 Type t = new TypePointer(this); | |
1705 pto = t.merge(); | |
1706 } | |
1707 | |
1708 return pto; | |
1709 } | |
174 | 1710 |
0 | 1711 Type referenceTo() |
1712 { | |
1713 assert(false); | |
1714 } | |
1715 | |
1716 final Type clone() | |
1717 { | |
178 | 1718 return cloneThis(this); |
0 | 1719 } |
174 | 1720 |
0 | 1721 Type arrayOf() |
1722 { | |
1723 if (!arrayof) | |
174 | 1724 { |
0 | 1725 Type t = new TypeDArray(this); |
1726 arrayof = t.merge(); | |
1727 } | |
1728 return arrayof; | |
1729 } | |
174 | 1730 |
0 | 1731 Type makeConst() |
1732 { | |
1733 //printf("Type.makeConst() %p, %s\n", this, toChars()); | |
1734 if (cto) | |
1735 return cto; | |
1736 | |
1737 Type t = clone(); | |
1738 t.mod = MOD.MODconst; | |
174 | 1739 |
0 | 1740 t.deco = null; |
1741 t.arrayof = null; | |
1742 t.pto = null; | |
1743 t.rto = null; | |
1744 t.cto = null; | |
1745 t.ito = null; | |
1746 t.sto = null; | |
1747 t.scto = null; | |
135 | 1748 t.wto = null; |
1749 t.swto = null; | |
0 | 1750 t.vtinfo = null; |
174 | 1751 |
0 | 1752 //printf("-Type.makeConst() %p, %s\n", t, toChars()); |
1753 return t; | |
1754 } | |
174 | 1755 |
0 | 1756 Type makeInvariant() |
1757 { | |
1758 if (ito) { | |
1759 return ito; | |
1760 } | |
1761 | |
1762 Type t = clone(); | |
135 | 1763 t.mod = MOD.MODimmutable; |
0 | 1764 |
1765 t.deco = null; | |
1766 t.arrayof = null; | |
1767 t.pto = null; | |
1768 t.rto = null; | |
1769 t.cto = null; | |
1770 t.ito = null; | |
1771 t.sto = null; | |
1772 t.scto = null; | |
135 | 1773 t.wto = null; |
1774 t.swto = null; | |
0 | 1775 t.vtinfo = null; |
1776 | |
1777 return t; | |
1778 } | |
174 | 1779 |
0 | 1780 Type makeShared() |
1781 { | |
1782 if (sto) | |
1783 return sto; | |
1784 | |
1785 Type t = clone(); | |
1786 t.mod = MOD.MODshared; | |
1787 | |
1788 t.deco = null; | |
1789 t.arrayof = null; | |
1790 t.pto = null; | |
1791 t.rto = null; | |
1792 t.cto = null; | |
1793 t.ito = null; | |
1794 t.sto = null; | |
1795 t.scto = null; | |
135 | 1796 t.wto = null; |
1797 t.swto = null; | |
0 | 1798 t.vtinfo = null; |
1799 | |
1800 return t; | |
1801 } | |
174 | 1802 |
0 | 1803 Type makeSharedConst() |
1804 { | |
1805 if (scto) | |
1806 return scto; | |
1807 | |
1808 Type t = clone(); | |
1809 t.mod = MODshared | MODconst; | |
1810 | |
1811 t.deco = null; | |
1812 t.arrayof = null; | |
1813 t.pto = null; | |
1814 t.rto = null; | |
1815 t.cto = null; | |
1816 t.ito = null; | |
1817 t.sto = null; | |
1818 t.scto = null; | |
135 | 1819 t.wto = null; |
1820 t.swto = null; | |
0 | 1821 t.vtinfo = null; |
1822 | |
1823 return t; | |
1824 } | |
174 | 1825 |
135 | 1826 Type makeWild() |
1827 { | |
1828 if (wto) | |
1829 return wto; | |
174 | 1830 |
135 | 1831 Type t = clone(); |
1832 t.mod = MOD.MODwild; | |
1833 t.deco = null; | |
1834 t.arrayof = null; | |
1835 t.pto = null; | |
1836 t.rto = null; | |
1837 t.cto = null; | |
1838 t.ito = null; | |
1839 t.sto = null; | |
1840 t.scto = null; | |
1841 t.wto = null; | |
1842 t.swto = null; | |
1843 t.vtinfo = null; | |
1844 return t; | |
1845 } | |
1846 | |
1847 Type makeSharedWild() | |
1848 { | |
1849 if (swto) | |
1850 return swto; | |
174 | 1851 |
135 | 1852 Type t = clone(); |
1853 t.mod = MOD.MODshared | MOD.MODwild; | |
1854 t.deco = null; | |
1855 t.arrayof = null; | |
1856 t.pto = null; | |
1857 t.rto = null; | |
1858 t.cto = null; | |
1859 t.ito = null; | |
1860 t.sto = null; | |
1861 t.scto = null; | |
1862 t.wto = null; | |
1863 t.swto = null; | |
1864 t.vtinfo = null; | |
1865 return t; | |
1866 } | |
1867 | |
1868 Type makeMutable() | |
1869 { | |
1870 Type t = clone(); | |
1871 t.mod = mod & MOD.MODshared; | |
1872 t.deco = null; | |
1873 t.arrayof = null; | |
1874 t.pto = null; | |
1875 t.rto = null; | |
1876 t.cto = null; | |
1877 t.ito = null; | |
1878 t.sto = null; | |
1879 t.scto = null; | |
1880 t.wto = null; | |
1881 t.swto = null; | |
1882 t.vtinfo = null; | |
1883 return t; | |
1884 } | |
174 | 1885 |
0 | 1886 Dsymbol toDsymbol(Scope sc) |
1887 { | |
1888 return null; | |
1889 } | |
1890 | |
1891 /******************************* | |
1892 * If this is a shell around another type, | |
1893 * get that other type. | |
1894 */ | |
174 | 1895 |
0 | 1896 Type toBasetype() |
1897 { | |
1898 return this; | |
1899 } | |
174 | 1900 |
0 | 1901 /************************** |
1902 * Return type with the top level of it being mutable. | |
1903 */ | |
1904 Type toHeadMutable() | |
1905 { | |
1906 if (!mod) | |
1907 return this; | |
1908 | |
1909 return mutableOf(); | |
1910 } | |
174 | 1911 |
0 | 1912 bool isBaseOf(Type t, int* poffset) |
1913 { | |
1914 return false; // assume not | |
1915 } | |
174 | 1916 |
0 | 1917 /******************************* |
1918 * Determine if converting 'this' to 'to' is an identity operation, | |
1919 * a conversion to const operation, or the types aren't the same. | |
1920 * Returns: | |
1921 * MATCHequal 'this' == 'to' | |
1922 * MATCHconst 'to' is const | |
1923 * MATCHnomatch conversion to mutable or invariant | |
1924 */ | |
1925 MATCH constConv(Type to) | |
1926 { | |
1927 if (equals(to)) | |
1928 return MATCH.MATCHexact; | |
135 | 1929 if (ty == to.ty && MODimplicitConv(mod, to.mod)) |
0 | 1930 return MATCH.MATCHconst; |
1931 return MATCH.MATCHnomatch; | |
1932 } | |
174 | 1933 |
0 | 1934 /******************************** |
1935 * Determine if 'this' can be implicitly converted | |
1936 * to type 'to'. | |
1937 * Returns: | |
1938 * MATCHnomatch, MATCHconvert, MATCHconst, MATCHexact | |
1939 */ | |
1940 MATCH implicitConvTo(Type to) | |
1941 { | |
1942 //printf("Type.implicitConvTo(this=%p, to=%p)\n", this, to); | |
1943 //printf("from: %s\n", toChars()); | |
1944 //printf("to : %s\n", to.toChars()); | |
1945 if (this is to) | |
1946 return MATCHexact; | |
1947 | |
1948 return MATCHnomatch; | |
1949 } | |
174 | 1950 |
0 | 1951 ClassDeclaration isClassHandle() |
1952 { | |
1953 return null; | |
1954 } | |
1955 | |
1956 Expression getProperty(Loc loc, Identifier ident) | |
1957 { | |
1958 Expression e; | |
1959 | |
1960 version (LOGDOTEXP) { | |
1961 printf("Type.getProperty(type = '%s', ident = '%s')\n", toChars(), ident.toChars()); | |
1962 } | |
1963 if (ident == Id.__sizeof) | |
1964 { | |
1965 e = new IntegerExp(loc, size(loc), Type.tsize_t); | |
1966 } | |
1967 else if (ident == Id.size) | |
1968 { | |
1969 error(loc, ".size property should be replaced with .sizeof"); | |
1970 e = new ErrorExp(); | |
1971 } | |
1972 else if (ident is Id.alignof_) | |
1973 { | |
1974 e = new IntegerExp(loc, alignsize(), Type.tsize_t); | |
1975 } | |
1976 else if (ident == Id.typeinfo_) | |
1977 { | |
1978 if (!global.params.useDeprecated) | |
1979 error(loc, ".typeinfo deprecated, use typeid(type)"); | |
1980 e = getTypeInfo(null); | |
1981 } | |
1982 else if (ident == Id.init_) | |
1983 { | |
1984 if (ty == TY.Tvoid) | |
1985 error(loc, "void does not have an initializer"); | |
1986 e = defaultInit(loc); | |
1987 } | |
1988 else if (ident is Id.mangleof_) | |
1989 { | |
1990 string s; | |
174 | 1991 if (!deco) { |
0 | 1992 s = toChars(); |
1993 error(loc, "forward reference of type %s.mangleof", s); | |
1994 } else { | |
1995 s = deco; | |
1996 } | |
1997 | |
1998 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
|
1999 scope Scope sc = new Scope(); |
0 | 2000 e = e.semantic(sc); |
2001 } | |
2002 else if (ident is Id.stringof_) | |
174 | 2003 { |
0 | 2004 string s = toChars(); |
2005 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
|
2006 scope Scope sc = new Scope(); |
0 | 2007 e = e.semantic(sc); |
2008 } | |
2009 else | |
2010 { | |
2011 error(loc, "no property '%s' for type '%s'", ident.toChars(), toChars()); | |
2012 e = new ErrorExp(); | |
2013 } | |
2014 return e; | |
2015 } | |
174 | 2016 |
0 | 2017 Expression dotExp(Scope sc, Expression e, Identifier ident) |
2018 { | |
2019 VarDeclaration v = null; | |
2020 | |
2021 version (LOGDOTEXP) { | |
2022 printf("Type.dotExp(e = '%s', ident = '%s')\n", e.toChars(), ident.toChars()); | |
2023 } | |
2024 if (e.op == TOK.TOKdotvar) | |
2025 { | |
2026 DotVarExp dv = cast(DotVarExp)e; | |
2027 v = dv.var.isVarDeclaration(); | |
2028 } | |
2029 else if (e.op == TOK.TOKvar) | |
2030 { | |
2031 VarExp ve = cast(VarExp)e; | |
2032 v = ve.var.isVarDeclaration(); | |
2033 } | |
2034 if (v) | |
2035 { | |
2036 if (ident is Id.offset) | |
2037 { | |
2038 if (!global.params.useDeprecated) | |
2039 error(e.loc, ".offset deprecated, use .offsetof"); | |
2040 goto Loffset; | |
2041 } | |
2042 else if (ident is Id.offsetof) | |
2043 { | |
2044 Loffset: | |
2045 if (v.storage_class & STC.STCfield) | |
2046 { | |
2047 e = new IntegerExp(e.loc, v.offset, Type.tsize_t); | |
2048 return e; | |
2049 } | |
2050 } | |
2051 else if (ident is Id.init_) | |
2052 { | |
2053 static if (false) { | |
2054 if (v.init) | |
2055 { | |
2056 if (v.init.isVoidInitializer()) | |
2057 error(e.loc, "%s.init is void", v.toChars()); | |
2058 else | |
2059 { Loc loc = e.loc; | |
2060 e = v.init.toExpression(); | |
2061 if (e.op == TOK.TOKassign || e.op == TOK.TOKconstruct || e.op == TOK.TOKblit) | |
2062 { | |
2063 e = (cast(AssignExp)e).e2; | |
2064 | |
2065 /* Take care of case where we used a 0 | |
2066 * to initialize the struct. | |
2067 */ | |
2068 if (e.type == Type.tint32 && | |
2069 e.isBool(0) && | |
2070 v.type.toBasetype().ty == TY.Tstruct) | |
2071 { | |
2072 e = v.type.defaultInit(e.loc); | |
2073 } | |
2074 } | |
2075 e = e.optimize(WANTvalue | WANTinterpret); | |
2076 // if (!e.isConst()) | |
2077 // error(loc, ".init cannot be evaluated at compile time"); | |
2078 } | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2079 goto Lreturn; |
0 | 2080 } |
2081 } | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2082 e = defaultInit(e.loc); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2083 goto Lreturn; |
0 | 2084 } |
2085 } | |
2086 if (ident is Id.typeinfo_) | |
2087 { | |
2088 if (!global.params.useDeprecated) | |
2089 error(e.loc, ".typeinfo deprecated, use typeid(type)"); | |
2090 e = getTypeInfo(sc); | |
2091 } | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2092 else if (ident is Id.stringof_) |
174 | 2093 { |
0 | 2094 string s = e.toChars(); |
2095 e = new StringExp(e.loc, s, 'c'); | |
2096 } | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2097 else |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2098 e = getProperty(e.loc, ident); |
174 | 2099 |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2100 Lreturn: |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2101 e = e.semantic(sc); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2102 return e; |
0 | 2103 } |
174 | 2104 |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2105 /*************************************** |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2106 * 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
|
2107 * for classes and structs. |
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 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
|
2110 { |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2111 assert(ty == TY.Tstruct || ty == TY.Tclass); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2112 AggregateDeclaration sym = toDsymbol(sc).isAggregateDeclaration(); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2113 assert(sym); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2114 |
131
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
2115 if (ident !is Id.__sizeof && |
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
2116 ident !is Id.alignof_ && |
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
2117 ident !is Id.init_ && |
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
2118 ident !is Id.mangleof_ && |
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
2119 ident !is Id.stringof_ && |
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
2120 ident !is Id.offsetof) |
130
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 /* 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
|
2123 */ |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2124 if (sym.aliasthis) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2125 { /* Rewrite e.ident as: |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2126 * e.aliasthis.ident |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2127 */ |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2128 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
|
2129 e = new DotIdExp(e.loc, e, ident); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2130 return e.semantic(sc); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2131 } |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2132 |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2133 /* 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
|
2134 * to it. |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2135 */ |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2136 Dsymbol fd = search_function(sym, Id.opDot); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2137 if (fd) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2138 { /* Rewrite e.ident as: |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2139 * e.opDot().ident |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2140 */ |
131
206db751bd4c
dmdfe 2.037 compiles now
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
130
diff
changeset
|
2141 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
|
2142 e = new DotIdExp(e.loc, e, ident); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2143 return e.semantic(sc); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2144 } |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2145 |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2146 /* 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
|
2147 * to it. |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2148 */ |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2149 fd = search_function(sym, Id.opDispatch); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2150 if (fd) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2151 { |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2152 /* Rewrite e.ident as: |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2153 * e.opDispatch!("ident") |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2154 */ |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2155 TemplateDeclaration td = fd.isTemplateDeclaration(); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2156 if (!td) |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2157 { |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2158 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
|
2159 return new ErrorExp(); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2160 } |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2161 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
|
2162 auto tiargs = new Objects(); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2163 tiargs.push(se); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2164 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
|
2165 (cast(DotTemplateInstanceExp)e).ti.tempdecl = td; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2166 return e; |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2167 //return e.semantic(sc); |
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 } |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2170 |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2171 return Type.dotExp(sc, e, ident); |
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
121
diff
changeset
|
2172 } |
174 | 2173 |
0 | 2174 uint memalign(uint salign) |
2175 { | |
2176 return salign; | |
2177 } | |
174 | 2178 |
0 | 2179 Expression defaultInit(Loc loc) |
2180 { | |
170 | 2181 version (LOGDEFAULTINIT) { |
2182 printf("Type.defaultInit() '%.*s'\n", toChars()); | |
2183 } | |
2184 return null; | |
0 | 2185 } |
174 | 2186 |
135 | 2187 /*************************************** |
2188 * Use when we prefer the default initializer to be a literal, | |
2189 * rather than a global immutable variable. | |
2190 */ | |
174 | 2191 //Expression defaultInitLiteral(Loc loc = Loc(0)) |
2192 Expression defaultInitLiteral(Loc loc) | |
135 | 2193 { |
2194 version(LOGDEFAULTINIT) { | |
2195 printf("Type::defaultInitLiteral() '%s'\n", toChars()); | |
2196 } | |
2197 return defaultInit(loc); | |
2198 } | |
2199 | |
0 | 2200 ///bool isZeroInit(Loc loc = Loc(0)) // if initializer is 0 |
2201 bool isZeroInit(Loc loc) // if initializer is 0 | |
2202 { | |
2203 assert(false); | |
2204 } | |
174 | 2205 |
0 | 2206 dt_t** toDt(dt_t** pdt) |
2207 { | |
2208 //printf("Type.toDt()\n"); | |
2209 Expression e = defaultInit(Loc(0)); | |
2210 return e.toDt(pdt); | |
2211 } | |
174 | 2212 |
0 | 2213 Identifier getTypeInfoIdent(int internal) |
2214 { | |
2215 // _init_10TypeInfo_%s | |
2216 scope OutBuffer buf = new OutBuffer(); | |
2217 Identifier id; | |
2218 char* name; | |
2219 int len; | |
2220 | |
2221 if (internal) | |
174 | 2222 { |
0 | 2223 buf.writeByte(mangleChar[ty]); |
2224 if (ty == TY.Tarray) | |
2225 buf.writeByte(mangleChar[(cast(TypeArray)this).next.ty]); | |
2226 } | |
2227 else | |
2228 toDecoBuffer(buf); | |
2229 | |
2230 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
|
2231 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
|
2232 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
|
2233 else |
0 | 2234 name = cast(char*)alloca(19 + len.sizeof * 3 + len + 1); |
2235 buf.writeByte(0); | |
2236 version (TARGET_OSX) { | |
2237 // The LINKc will prepend the _ | |
2238 len = sprintf(name, "D%dTypeInfo_%s6__initZ".ptr, 9 + len, buf.data); | |
2239 } else { | |
2240 len = sprintf(name, "_D%dTypeInfo_%s6__initZ".ptr, 9 + len, buf.data); | |
2241 } | |
2242 if (global.params.isWindows) | |
2243 name++; // C mangling will add it back in | |
2244 //printf("name = %s\n", name); | |
2245 id = Lexer.idPool(name[0..len-1].idup); | |
2246 return id; | |
2247 } | |
174 | 2248 |
0 | 2249 /* These form the heart of template argument deduction. |
2250 * Given 'this' being the type argument to the template instance, | |
2251 * it is matched against the template declaration parameter specialization | |
2252 * 'tparam' to determine the type to be used for the parameter. | |
2253 * Example: | |
2254 * template Foo(T:T*) // template declaration | |
2255 * Foo!(int*) // template instantiation | |
2256 * Input: | |
2257 * this = int* | |
2258 * tparam = T | |
2259 * parameters = [ T:T* ] // Array of TemplateParameter's | |
2260 * Output: | |
2261 * dedtypes = [ int ] // Array of Expression/Type's | |
2262 */ | |
2263 MATCH deduceType(Scope sc, Type tparam, TemplateParameters parameters, Objects dedtypes) | |
2264 { | |
98 | 2265 static if (false) |
2266 { | |
0 | 2267 printf("Type.deduceType()\n"); |
2268 printf("\tthis = %d, ", ty); print(); | |
2269 printf("\ttparam = %d, ", tparam.ty); tparam.print(); | |
2270 } | |
2271 if (!tparam) | |
2272 goto Lnomatch; | |
2273 | |
2274 if (this == tparam) | |
2275 goto Lexact; | |
2276 | |
2277 if (tparam.ty == Tident) | |
2278 { | |
2279 // Determine which parameter tparam is | |
2280 int i = templateParameterLookup(tparam, parameters); | |
2281 if (i == -1) | |
2282 { | |
2283 if (!sc) | |
2284 goto Lnomatch; | |
2285 | |
2286 /* Need a loc to go with the semantic routine. | |
2287 */ | |
2288 Loc loc; | |
2289 if (parameters.dim) | |
2290 { | |
121
347de076ad34
TemplateParameters -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
2291 auto tp = parameters[0]; |
0 | 2292 loc = tp.loc; |
2293 } | |
2294 | |
2295 /* BUG: what if tparam is a template instance, that | |
2296 * has as an argument another Tident? | |
2297 */ | |
2298 tparam = tparam.semantic(loc, sc); | |
2299 assert(tparam.ty != Tident); | |
2300 return deduceType(sc, tparam, parameters, dedtypes); | |
2301 } | |
2302 | |
121
347de076ad34
TemplateParameters -> Vector
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
2303 auto tp = parameters[i]; |
0 | 2304 |
2305 // Found the corresponding parameter tp | |
2306 if (!tp.isTemplateTypeParameter()) | |
2307 goto Lnomatch; | |
2308 Type tt = this; | |
113
3482c73a991b
More cleanup for arrays
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
110
diff
changeset
|
2309 Type at = cast(Type)dedtypes[i]; |
0 | 2310 |
98 | 2311 // 5*5 == 25 cases |
135 | 2312 static pure int X(int U, int T) { return ((U << 4) | T); } |
174 | 2313 |
98 | 2314 switch (X(tparam.mod, mod)) |
2315 { | |
2316 case X(0, 0): | |
2317 case X(0, MODconst): | |
135 | 2318 case X(0, MODimmutable): |
98 | 2319 case X(0, MODshared): |
2320 case X(0, MODconst | MODshared): | |
135 | 2321 case X(0, MODwild): |
2322 case X(0, MODwild | MODshared): | |
98 | 2323 // foo(U:U) T => T |
2324 // foo(U:U) const(T) => const(T) | |
2325 // foo(U:U) immutable(T) => immutable(T) | |
2326 // foo(U:U) shared(T) => shared(T) | |
2327 // foo(U:U) const(shared(T)) => const(shared(T)) | |
135 | 2328 // foo(U:U) wild(T) => wild(T) |
2329 // foo(U:U) wild(shared(T)) => wild(shared(T)) | |
0 | 2330 if (!at) |
110 | 2331 { dedtypes[i] = tt; |
0 | 2332 goto Lexact; |
2333 } | |
98 | 2334 break; |
2335 | |
2336 case X(MODconst, MODconst): | |
135 | 2337 case X(MODimmutable, MODimmutable): |
98 | 2338 case X(MODshared, MODshared): |
2339 case X(MODconst | MODshared, MODconst | MODshared): | |
135 | 2340 case X(MODwild, MODwild): |
2341 case X(MODwild | MODshared, MODwild | MODshared): | |
2342 case X(MODconst, MODwild): | |
2343 case X(MODconst, MODwild | MODshared): | |
98 | 2344 // foo(U:const(U)) const(T) => T |
2345 // foo(U:immutable(U)) immutable(T) => T | |
2346 // foo(U:shared(U)) shared(T) => T | |
2347 // foo(U:const(shared(U)) const(shared(T))=> T | |
135 | 2348 // foo(U:wild(U)) wild(T) => T |
2349 // foo(U:wild(shared(U)) wild(shared(T)) => T | |
2350 // foo(U:const(U)) wild(shared(T)) => shared(T) | |
98 | 2351 tt = mutableOf().unSharedOf(); |
0 | 2352 if (!at) |
110 | 2353 { |
94
3a0b150c9841
Objects -> Vector!Object iteration 1
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
87
diff
changeset
|
2354 dedtypes[i] = tt; |
0 | 2355 goto Lexact; |
2356 } | |
98 | 2357 break; |
2358 | |
2359 case X(MODconst, 0): | |
2360 case X(MODconst, MODimmutable): | |
2361 case X(MODconst, MODconst | MODshared): | |
2362 case X(MODconst | MODshared, MODimmutable): | |
135 | 2363 case X(MODshared, MODwild | MODshared): |
98 | 2364 // foo(U:const(U)) T => T |
2365 // foo(U:const(U)) immutable(T) => T | |
2366 // foo(U:const(U)) const(shared(T)) => shared(T) | |
2367 // foo(U:const(shared(U)) immutable(T) => T | |
135 | 2368 // foo(U:shared(U)) wild(shared(T)) => wild(T) |
0 | 2369 tt = mutableOf(); |
2370 if (!at) | |
110 | 2371 { dedtypes[i] = tt; |
98 | 2372 goto Lconst; |
0 | 2373 } |
98 | 2374 break; |
2375 | |
2376 case X(MODshared, MODconst | MODshared): | |
2377 case X(MODconst | MODshared, MODshared): | |
2378 // foo(U:shared(U)) const(shared(T)) => const(T) | |
2379 // foo(U:const(shared(U)) shared(T) => T | |
2380 tt = unSharedOf(); | |
0 | 2381 if (!at) |
110 | 2382 { dedtypes[i] = tt; |
0 | 2383 goto Lconst; |
2384 } | |
98 | 2385 break; |
2386 | |
2387 case X(MODimmutable, 0): | |
2388 case X(MODimmutable, MODconst): | |
2389 case X(MODimmutable, MODshared): | |
2390 case X(MODimmutable, MODconst | MODshared): | |
2391 case X(MODconst, MODshared): | |
2392 case X(MODshared, 0): | |
2393 case X(MODshared, MODconst): | |
2394 case X(MODshared, MODimmutable): | |
2395 case X(MODconst | MODshared, 0): | |
2396 case X(MODconst | MODshared, MODconst): | |
135 | 2397 case X(MODimmutable, MODwild): |
2398 case X(MODshared, MODwild): | |
2399 case X(MODconst | MODshared, MODwild): | |
2400 case X(MODwild, 0): | |
2401 case X(MODwild, MODconst): | |
2402 case X(MODwild, MODimmutable): | |
2403 case X(MODwild, MODshared): | |
2404 case X(MODwild, MODconst | MODshared): | |
2405 case X(MODwild | MODshared, 0): | |
2406 case X(MODwild | MODshared, MODconst): | |
2407 case X(MODwild | MODshared, MODimmutable): | |
2408 case X(MODwild | MODshared, MODshared): | |
2409 case X(MODwild | MODshared, MODconst | MODshared): | |
2410 case X(MODwild | MODshared, MODwild): | |
2411 case X(MODimmutable, MODwild | MODshared): | |
2412 case X(MODconst | MODshared, MODwild | MODshared): | |
2413 case X(MODwild, MODwild | MODshared): | |
98 | 2414 // foo(U:immutable(U)) T => nomatch |
2415 // foo(U:immutable(U)) const(T) => nomatch | |
2416 // foo(U:immutable(U)) shared(T) => nomatch | |
2417 // foo(U:immutable(U)) const(shared(T)) => nomatch | |
2418 // foo(U:const(U)) shared(T) => nomatch | |
2419 // foo(U:shared(U)) T => nomatch | |
2420 // foo(U:shared(U)) const(T) => nomatch | |
2421 // foo(U:shared(U)) immutable(T) => nomatch | |
2422 // foo(U:const(shared(U)) T => nomatch | |
2423 // foo(U:const(shared(U)) const(T) => nomatch | |
135 | 2424 // foo(U:immutable(U)) wild(T) => nomatch |
2425 // foo(U:shared(U)) wild(T) => nomatch | |
2426 // foo(U:const(shared(U)) wild(T) => nomatch | |
2427 // foo(U:wild(U)) T => nomatch | |
2428 // foo(U:wild(U)) const(T) => nomatch | |
2429 // foo(U:wild(U)) immutable(T) => nomatch | |
2430 // foo(U:wild(U)) shared(T) => nomatch | |
2431 // foo(U:wild(U)) const(shared(T)) => nomatch | |
2432 // foo(U:wild(shared(U)) T => nomatch | |
2433 // foo(U:wild(shared(U)) const(T) => nomatch | |
2434 // foo(U:wild(shared(U)) immutable(T) => nomatch | |
2435 // foo(U:wild(shared(U)) shared(T) => nomatch | |
2436 // foo(U:wild(shared(U)) const(shared(T)) => nomatch | |
2437 // foo(U:wild(shared(U)) wild(T) => nomatch | |
2438 // foo(U:immutable(U)) wild(shared(T)) => nomatch | |
2439 // foo(U:const(shared(U))) wild(shared(T)) => nomatch | |
2440 // foo(U:wild(U)) wild(shared(T)) => nomatch | |
98 | 2441 //if (!at) |
0 | 2442 goto Lnomatch; |
98 | 2443 break; |
2444 | |
2445 default: | |
2446 assert(0); | |
0 | 2447 } |
2448 | |
2449 if (tt.equals(at)) | |
2450 goto Lexact; | |
2451 else if (tt.ty == Tclass && at.ty == Tclass) | |
2452 { | |
2453 return tt.implicitConvTo(at); | |
2454 } | |
2455 else if (tt.ty == Tsarray && at.ty == Tarray && | |
2456 tt.nextOf().implicitConvTo(at.nextOf()) >= MATCHconst) | |
2457 { | |
2458 goto Lexact; | |
2459 } | |
2460 else | |
2461 goto Lnomatch; | |
2462 } | |
2463 | |
2464 if (ty != tparam.ty) | |
2465 return implicitConvTo(tparam); | |
2466 // goto Lnomatch; | |
2467 | |
2468 if (nextOf()) | |
2469 return nextOf().deduceType(sc, tparam.nextOf(), parameters, dedtypes); | |
2470 | |
2471 Lexact: | |
2472 return MATCHexact; | |
2473 | |
2474 Lnomatch: | |
2475 return MATCHnomatch; | |
2476 | |
2477 version (DMDV2) { | |
2478 Lconst: | |
2479 return MATCHconst; | |
2480 } | |
2481 } | |
2482 | |
2483 void resolve(Loc loc, Scope sc, Expression* pe, Type* pt, Dsymbol* ps) | |
2484 { | |
2485 //printf("Type.resolve() %s, %d\n", toChars(), ty); | |
2486 Type t = semantic(loc, sc); | |
2487 *pt = t; | |
2488 *pe = null; | |
2489 *ps = null; | |
2490 } | |
174 | 2491 |
0 | 2492 /******************************************* |
2493 * Get a canonicalized form of the TypeInfo for use with the internal | |
2494 * runtime library routines. Canonicalized in that static arrays are | |
2495 * represented as dynamic arrays, enums are represented by their | |
2496 * underlying type, etc. This reduces the number of TypeInfo's needed, | |
2497 * so we can use the custom internal ones more. | |
2498 */ | |
2499 Expression getInternalTypeInfo(Scope sc) | |
2500 { | |
2501 TypeInfoDeclaration tid; | |
2502 Expression e; | |
2503 Type t; | |
2504 | |
2505 //printf("Type.getInternalTypeInfo() %s\n", toChars()); | |
2506 t = toBasetype(); | |
2507 switch (t.ty) | |
2508 { | |
2509 case Tsarray: | |
2510 static if (false) { | |
2511 // convert to corresponding dynamic array type | |
2512 t = t.nextOf().mutableOf().arrayOf(); | |
2513 } | |
2514 break; | |
2515 | |
2516 case Tclass: | |
2517 if ((cast(TypeClass)t).sym.isInterfaceDeclaration()) | |
2518 break; | |
2519 goto Linternal; | |
2520 | |
2521 case Tarray: | |
2522 // convert to corresponding dynamic array type | |
2523 t = t.nextOf().mutableOf().arrayOf(); | |
2524 if (t.nextOf().ty != Tclass) | |
2525 break; | |
2526 goto Linternal; | |
2527 | |
2528 case Tfunction: | |
2529 case Tdelegate: | |
2530 case Tpointer: | |
2531 Linternal: | |
176 | 2532 tid = global.internalTI[t.ty]; |
0 | 2533 if (!tid) |
174 | 2534 { |
0 | 2535 tid = new TypeInfoDeclaration(t, 1); |
176 | 2536 global.internalTI[t.ty] = tid; |
0 | 2537 } |
2538 e = new VarExp(Loc(0), tid); | |
2539 e = e.addressOf(sc); | |
2540 e.type = tid.type; // do this so we don't get redundant dereference | |
2541 return e; | |
2542 | |
2543 default: | |
2544 break; | |
2545 } | |
2546 //printf("\tcalling getTypeInfo() %s\n", t.toChars()); | |
2547 return t.getTypeInfo(sc); | |
2548 } | |
174 | 2549 |
0 | 2550 /**************************************************** |
2551 * Get the exact TypeInfo. | |
2552 */ | |
2553 Expression getTypeInfo(Scope sc) | |
2554 { | |
2555 Expression e; | |
2556 Type t; | |
2557 | |
2558 //printf("Type.getTypeInfo() %p, %s\n", this, toChars()); | |
2559 t = merge2(); // do this since not all Type's are merge'd | |
2560 if (!t.vtinfo) | |
2561 { | |
2562 version (DMDV2) { | |
2563 if (t.isShared()) // does both 'shared' and 'shared const' | |
2564 t.vtinfo = new TypeInfoSharedDeclaration(t); | |
2565 else if (t.isConst()) | |
2566 t.vtinfo = new TypeInfoConstDeclaration(t); | |
135 | 2567 else if (t.isImmutable()) |
0 | 2568 t.vtinfo = new TypeInfoInvariantDeclaration(t); |
135 | 2569 else if (t.isWild()) |
2570 t.vtinfo = new TypeInfoWildDeclaration(t); | |
2571 | |
0 | 2572 else |
2573 t.vtinfo = t.getTypeInfoDeclaration(); | |
2574 } else { | |
2575 t.vtinfo = t.getTypeInfoDeclaration(); | |
2576 } | |
2577 assert(t.vtinfo); | |
2578 vtinfo = t.vtinfo; | |
2579 | |
2580 /* If this has a custom implementation in std/typeinfo, then | |
2581 * do not generate a COMDAT for it. | |
2582 */ | |
2583 if (!t.builtinTypeInfo()) | |
174 | 2584 { |
0 | 2585 // Generate COMDAT |
2586 if (sc) // if in semantic() pass | |
174 | 2587 { |
0 | 2588 // Find module that will go all the way to an object file |
2589 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
|
2590 m.members.push(t.vtinfo); |
0 | 2591 } |
2592 else // if in obj generation pass | |
2593 { | |
2594 t.vtinfo.toObjFile(global.params.multiobj); | |
2595 } | |
2596 } | |
2597 } | |
2598 e = new VarExp(Loc(0), t.vtinfo); | |
2599 e = e.addressOf(sc); | |
2600 e.type = t.vtinfo.type; // do this so we don't get redundant dereference | |
2601 return e; | |
2602 } | |
174 | 2603 |
0 | 2604 TypeInfoDeclaration getTypeInfoDeclaration() |
2605 { | |
2606 //printf("Type.getTypeInfoDeclaration() %s\n", toChars()); | |
2607 return new TypeInfoDeclaration(this, 0); | |
2608 } | |
174 | 2609 |
0 | 2610 /* These decide if there's an instance for them already in std.typeinfo, |
2611 * because then the compiler doesn't need to build one. | |
2612 */ | |
2613 bool builtinTypeInfo() | |
2614 { | |
2615 return false; | |
2616 } | |
174 | 2617 |
0 | 2618 /******************************* |
2619 * If one of the subtypes of this type is a TypeIdentifier, | |
2620 * i.e. it's an unresolved type, return that type. | |
2621 */ | |
2622 Type reliesOnTident() | |
2623 { | |
2624 return null; | |
2625 } | |
174 | 2626 |
135 | 2627 /*************************************** |
2628 * Return !=0 if the type or any of its subtypes is wild. | |
2629 */ | |
2630 | |
2631 int hasWild() | |
2632 { | |
2633 return mod & MOD.MODwild; | |
2634 } | |
2635 | |
2636 /*************************************** | |
2637 * Return MOD bits matching argument type (targ) to wild parameter type (this). | |
2638 */ | |
2639 | |
2640 uint wildMatch(Type targ) | |
2641 { | |
2642 return 0; | |
2643 } | |
174 | 2644 |
0 | 2645 Expression toExpression() |
2646 { | |
2647 assert(false); | |
2648 } | |
174 | 2649 |
0 | 2650 /*************************************** |
2651 * Return true if type has pointers that need to | |
2652 * be scanned by the GC during a collection cycle. | |
2653 */ | |
2654 bool hasPointers() | |
2655 { | |
2656 return false; | |
2657 } | |
174 | 2658 |
0 | 2659 /************************************* |
2660 * If this is a type of something, return that something. | |
2661 */ | |
2662 Type nextOf() | |
2663 { | |
2664 return null; | |
2665 } | |
174 | 2666 |
53 | 2667 /**************************************** |
2668 * Return the mask that an integral type will | |
2669 * fit into. | |
2670 */ | |
0 | 2671 ulong sizemask() |
2672 { | |
53 | 2673 ulong m; |
2674 | |
2675 switch (toBasetype().ty) | |
2676 { | |
2677 case Tbool: m = 1; break; | |
2678 case Tchar: | |
2679 case Tint8: | |
2680 case Tuns8: m = 0xFF; break; | |
2681 case Twchar: | |
2682 case Tint16: | |
2683 case Tuns16: m = 0xFFFFUL; break; | |
2684 case Tdchar: | |
2685 case Tint32: | |
2686 case Tuns32: m = 0xFFFFFFFFUL; break; | |
2687 case Tint64: | |
2688 case Tuns64: m = 0xFFFFFFFFFFFFFFFFUL; break; | |
2689 default: | |
2690 assert(0); | |
2691 } | |
2692 return m; | |
0 | 2693 } |
174 | 2694 |
0 | 2695 static void error(T...)(Loc loc, string format, T t) |
2696 { | |
2697 .error(loc, format, t); | |
2698 } | |
174 | 2699 |
0 | 2700 static void warning(T...)(Loc loc, string format, T t) |
2701 { | |
2702 assert(false); | |
2703 } | |
2704 | |
2705 // For backend | |
2706 /***************************** | |
2707 * Return back end type corresponding to D front end type. | |
2708 */ | |
2709 TYM totym() | |
2710 { | |
2711 TYM t; | |
2712 | |
2713 switch (ty) | |
2714 { | |
2715 case TY.Tvoid: t = TYM.TYvoid; break; | |
2716 case TY.Tint8: t = TYM.TYschar; break; | |
2717 case TY.Tuns8: t = TYM.TYuchar; break; | |
2718 case TY.Tint16: t = TYM.TYshort; break; | |
2719 case TY.Tuns16: t = TYM.TYushort; break; | |
2720 case TY.Tint32: t = TYM.TYint; break; | |
2721 case TY.Tuns32: t = TYM.TYuint; break; | |
2722 case TY.Tint64: t = TYM.TYllong; break; | |
2723 case TY.Tuns64: t = TYM.TYullong; break; | |
2724 case TY.Tfloat32: t = TYM.TYfloat; break; | |
2725 case TY.Tfloat64: t = TYM.TYdouble; break; | |
2726 case TY.Tfloat80: t = TYM.TYldouble; break; | |
2727 case TY.Timaginary32: t = TYM.TYifloat; break; | |
2728 case TY.Timaginary64: t = TYM.TYidouble; break; | |
2729 case TY.Timaginary80: t = TYM.TYildouble; break; | |
2730 case TY.Tcomplex32: t = TYM.TYcfloat; break; | |
2731 case TY.Tcomplex64: t = TYM.TYcdouble; break; | |
2732 case TY.Tcomplex80: t = TYM.TYcldouble; break; | |
2733 //case Tbit: t = TYM.TYuchar; break; | |
2734 case TY.Tbool: t = TYM.TYbool; break; | |
2735 case TY.Tchar: t = TYM.TYchar; break; | |
2736 version (XXX) { ///TARGET_LINUX || TARGET_OSX || TARGET_FREEBSD || TARGET_SOLARIS | |
2737 case TY.Twchar: t = TYM.TYwchar_t; break; | |
2738 case TY.Tdchar: t = TYM.TYdchar; break; | |
2739 } else { | |
2740 case TY.Twchar: t = TYM.TYwchar_t; break; | |
2741 case TY.Tdchar: | |
2742 t = (global.params.symdebug == 1) ? TYM.TYdchar : TYM.TYulong; | |
2743 break; | |
2744 } | |
2745 | |
2746 case TY.Taarray: t = TYM.TYaarray; break; | |
2747 case TY.Tclass: | |
2748 case TY.Treference: | |
2749 case TY.Tpointer: t = TYM.TYnptr; break; | |
2750 case TY.Tdelegate: t = TYM.TYdelegate; break; | |
2751 case TY.Tarray: t = TYM.TYdarray; break; | |
98 | 2752 version(SARRAYVALUE) |
2753 { case TY.Tsarray: t = TYstruct; break;} | |
2754 else | |
2755 { case TY.Tsarray: t = TYM.TYarray; break;} | |
0 | 2756 case TY.Tstruct: t = TYM.TYstruct; break; |
2757 | |
2758 case TY.Tenum: | |
2759 case TY.Ttypedef: | |
2760 t = toBasetype().totym(); | |
2761 break; | |
2762 | |
2763 case TY.Tident: | |
2764 case TY.Ttypeof: | |
2765 debug { | |
2766 writef("ty = %d, '%s'\n", ty, toChars()); | |
2767 } | |
2768 error (Loc(0), "forward reference of %s", toChars()); | |
2769 t = TYM.TYint; | |
2770 break; | |
2771 | |
2772 default: | |
2773 debug { | |
2774 writef("ty = %d, '%s'\n", ty, toChars()); | |
2775 } | |
2776 assert(0); | |
2777 } | |
2778 | |
2779 version (DMDV2) { | |
2780 // Add modifiers | |
2781 switch (mod) | |
2782 { | |
2783 case MOD.MODundefined: | |
2784 break; | |
2785 case MOD.MODconst: | |
135 | 2786 case MOD.MODwild: |
0 | 2787 t |= mTY.mTYconst; |
2788 break; | |
135 | 2789 case MOD.MODimmutable: |
0 | 2790 t |= mTY.mTYimmutable; |
2791 break; | |
2792 case MOD.MODshared: | |
2793 t |= mTY.mTYshared; | |
2794 break; | |
135 | 2795 case MOD.MODshared | MOD.MODwild: |
0 | 2796 case MOD.MODshared | MOD.MODconst: |
2797 t |= mTY.mTYshared | mTY.mTYconst; | |
2798 break; | |
2799 default: | |
2800 assert(0); | |
2801 } | |
2802 } | |
2803 | |
2804 return t; | |
2805 } | |
174 | 2806 |
0 | 2807 /*************************************** |
2808 * Convert from D type to C type. | |
2809 * This is done so C debug info can be generated. | |
2810 */ | |
2811 type* toCtype() | |
2812 { | |
2813 if (!ctype) | |
2814 { | |
2815 ctype = type_fake(totym()); | |
2816 ctype.Tcount++; | |
2817 } | |
2818 return ctype; | |
2819 } | |
174 | 2820 |
0 | 2821 type* toCParamtype() |
2822 { | |
2823 return toCtype(); | |
2824 } | |
174 | 2825 |
0 | 2826 Symbol* toSymbol() |
2827 { | |
2828 assert(false); | |
2829 } | |
174 | 2830 |
0 | 2831 // For eliminating dynamic_cast |
2832 TypeBasic isTypeBasic() | |
2833 { | |
2834 return null; | |
2835 } | |
178 | 2836 |
176 | 2837 @property |
2838 static ref Type[TY.TMAX] basic() | |
2839 { | |
177 | 2840 return global.basic; |
176 | 2841 } |
0 | 2842 |
2843 static Type tvoid() | |
2844 { | |
2845 return basic[TY.Tvoid]; | |
2846 } | |
2847 | |
2848 static Type tint8() | |
2849 { | |
2850 return basic[TY.Tint8]; | |
2851 } | |
2852 | |
2853 static Type tuns8() | |
2854 { | |
2855 return basic[TY.Tuns8]; | |
2856 } | |
2857 | |
2858 static Type tint16() | |
2859 { | |
2860 return basic[TY.Tint16]; | |
2861 } | |
2862 | |
2863 static Type tuns16() | |
2864 { | |
2865 return basic[TY.Tuns16]; | |
2866 } | |
2867 | |
2868 static Type tint32() | |
2869 { | |
2870 return basic[TY.Tint32]; | |
2871 } | |
2872 | |
2873 static Type tuns32() | |
2874 { | |
2875 return basic[TY.Tuns32]; | |
2876 } | |
2877 | |
2878 static Type tint64() | |
2879 { | |
2880 return basic[TY.Tint64]; | |
2881 } | |
2882 | |
2883 static Type tuns64() | |
2884 { | |
2885 return basic[TY.Tuns64]; | |
2886 } | |
2887 | |
2888 static Type tfloat32() | |
2889 { | |
2890 return basic[TY.Tfloat32]; | |
2891 } | |
2892 | |
2893 static Type tfloat64() | |
2894 { | |
2895 return basic[TY.Tfloat64]; | |
2896 } | |
2897 | |
2898 static Type tfloat80() | |
2899 { | |
2900 return basic[TY.Tfloat80]; | |
2901 } | |
2902 | |
2903 static Type timaginary32() | |
2904 { | |
2905 return basic[TY.Timaginary32]; | |
2906 } | |
2907 | |
2908 static Type timaginary64() | |
2909 { | |
2910 return basic[TY.Timaginary64]; | |
2911 } | |
2912 | |
2913 static Type timaginary80() | |
2914 { | |
2915 return basic[TY.Timaginary80]; | |
2916 } | |
2917 | |
2918 static Type tcomplex32() | |
2919 { | |
2920 return basic[TY.Tcomplex32]; | |
2921 } | |
2922 | |
2923 static Type tcomplex64() | |
2924 { | |
2925 return basic[TY.Tcomplex64]; | |
2926 } | |
2927 | |
2928 static Type tcomplex80() | |
2929 { | |
2930 return basic[TY.Tcomplex80]; | |
2931 } | |
2932 | |
2933 static Type tbit() | |
2934 { | |
2935 return basic[TY.Tbit]; | |
2936 } | |
2937 | |
2938 static Type tbool() | |
2939 { | |
2940 return basic[TY.Tbool]; | |
2941 } | |
2942 | |
2943 static Type tchar() | |
2944 { | |
2945 return basic[TY.Tchar]; | |
2946 } | |
2947 | |
2948 static Type twchar() | |
2949 { | |
2950 return basic[TY.Twchar]; | |
2951 } | |
2952 | |
2953 static Type tdchar() | |
2954 { | |
2955 return basic[TY.Tdchar]; | |
2956 } | |
174 | 2957 |
0 | 2958 // Some special types |
2959 static Type tshiftcnt() | |
2960 { | |
2961 return tint32; // right side of shift expression | |
2962 } | |
2963 | |
2964 // #define tboolean tint32 // result of boolean expression | |
2965 static Type tboolean() | |
2966 { | |
2967 return tbool; // result of boolean expression | |
2968 } | |
174 | 2969 |
0 | 2970 static Type tindex() |
2971 { | |
2972 return tint32; // array/ptr index | |
2973 } | |
174 | 2974 |
0 | 2975 static Type terror() |
2976 { | |
2977 return basic[TY.Terror]; // for error recovery | |
2978 } | |
2979 | |
2980 static Type tsize_t() | |
2981 { | |
2982 return basic[Tsize_t]; // matches size_t alias | |
2983 } | |
174 | 2984 |
0 | 2985 static Type tptrdiff_t() |
2986 { | |
2987 return basic[Tptrdiff_t]; // matches ptrdiff_t alias | |
2988 } | |
174 | 2989 |
0 | 2990 static Type thash_t() |
2991 { | |
2992 return tsize_t; // matches hash_t alias | |
2993 } | |
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
|
2994 } |