Mercurial > projects > ldc
annotate dmd/mtype.c @ 1157:ee8db0b7bb62
Fix path to llvmasm.di in runtime CMakeList
author | Christian Kamm <kamm incasoftware de> |
---|---|
date | Sat, 28 Mar 2009 10:50:44 +0100 |
parents | dbe4af57b240 |
children | 442ab244c455 |
rev | line source |
---|---|
159 | 1 |
2 // Compiler implementation of the D programming language | |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
3 // Copyright (c) 1999-2009 by Digital Mars |
159 | 4 // All Rights Reserved |
5 // written by Walter Bright | |
6 // http://www.digitalmars.com | |
7 // License for redistribution is by either the Artistic License | |
8 // in artistic.txt, or the GNU General Public License in gnu.txt. | |
9 // See the included readme.txt for details. | |
10 | |
872
aa953cc960b6
Apply BlueZeniX's patch for OpenSolaris compatibility. Fixes #158.
Christian Kamm <kamm incasoftware de>
parents:
846
diff
changeset
|
11 #define __C99FEATURES__ 1 // Needed on Solaris for NaN and more |
159 | 12 #define __USE_ISOC99 1 // so signbit() gets defined |
872
aa953cc960b6
Apply BlueZeniX's patch for OpenSolaris compatibility. Fixes #158.
Christian Kamm <kamm incasoftware de>
parents:
846
diff
changeset
|
13 |
aa953cc960b6
Apply BlueZeniX's patch for OpenSolaris compatibility. Fixes #158.
Christian Kamm <kamm incasoftware de>
parents:
846
diff
changeset
|
14 #if (defined (__SVR4) && defined (__sun)) |
aa953cc960b6
Apply BlueZeniX's patch for OpenSolaris compatibility. Fixes #158.
Christian Kamm <kamm incasoftware de>
parents:
846
diff
changeset
|
15 #include <alloca.h> |
aa953cc960b6
Apply BlueZeniX's patch for OpenSolaris compatibility. Fixes #158.
Christian Kamm <kamm incasoftware de>
parents:
846
diff
changeset
|
16 #endif |
aa953cc960b6
Apply BlueZeniX's patch for OpenSolaris compatibility. Fixes #158.
Christian Kamm <kamm incasoftware de>
parents:
846
diff
changeset
|
17 |
1147
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
18 #ifdef __DMC__ |
1133
eeb8b95ea92e
Cleanup DMD 1.041 merge.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1124
diff
changeset
|
19 #include <math.h> |
1147
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
20 #else |
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
21 #include <cmath> |
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
22 #endif |
159 | 23 |
24 #include <stdio.h> | |
25 #include <assert.h> | |
26 #include <float.h> | |
27 | |
28 #ifdef __DMC__ | |
29 #include <fp.h> | |
30 #endif | |
31 | |
32 #if _MSC_VER | |
33 #include <malloc.h> | |
34 #include <complex> | |
35 #include <limits> | |
36 #elif __DMC__ | |
37 #include <complex.h> | |
285
297690b5d4a5
[svn r306] Fixed: it's now possible to compile and link llvmdc with MinGW32 and msys on Win32 :D I tried it myself ;) Building the runtime still needs some work, but it's a step in the right direction.
lindquist
parents:
270
diff
changeset
|
38 #elif __MINGW32__ |
297690b5d4a5
[svn r306] Fixed: it's now possible to compile and link llvmdc with MinGW32 and msys on Win32 :D I tried it myself ;) Building the runtime still needs some work, but it's a step in the right direction.
lindquist
parents:
270
diff
changeset
|
39 #include <malloc.h> |
159 | 40 #else |
41 //#define signbit 56 | |
42 #endif | |
43 | |
44 #if __APPLE__ | |
45 static double zero = 0; | |
285
297690b5d4a5
[svn r306] Fixed: it's now possible to compile and link llvmdc with MinGW32 and msys on Win32 :D I tried it myself ;) Building the runtime still needs some work, but it's a step in the right direction.
lindquist
parents:
270
diff
changeset
|
46 #elif __MINGW32__ |
297690b5d4a5
[svn r306] Fixed: it's now possible to compile and link llvmdc with MinGW32 and msys on Win32 :D I tried it myself ;) Building the runtime still needs some work, but it's a step in the right direction.
lindquist
parents:
270
diff
changeset
|
47 static double zero = 0; |
159 | 48 #elif __GNUC__ |
900
177afbf5297b
Solaris compatibility and proc map parsing #183, thanks BlueZeniX!
Christian Kamm <kamm incasoftware de>
parents:
881
diff
changeset
|
49 #if !(defined (__SVR4) && defined (__sun)) |
159 | 50 #include <bits/nan.h> |
51 #include <bits/mathdef.h> | |
900
177afbf5297b
Solaris compatibility and proc map parsing #183, thanks BlueZeniX!
Christian Kamm <kamm incasoftware de>
parents:
881
diff
changeset
|
52 #endif |
159 | 53 static double zero = 0; |
54 #endif | |
55 | |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
56 #include "rmem.h" |
159 | 57 |
58 #include "dsymbol.h" | |
59 #include "mtype.h" | |
60 #include "scope.h" | |
61 #include "init.h" | |
62 #include "expression.h" | |
63 #include "attrib.h" | |
64 #include "declaration.h" | |
65 #include "template.h" | |
66 #include "id.h" | |
67 #include "enum.h" | |
68 #include "import.h" | |
69 #include "aggregate.h" | |
70 #include "hdrgen.h" | |
71 | |
1147
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
72 #if IN_LLVM |
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
73 //#include "gen/tollvm.h" |
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
74 Ir* Type::sir = NULL; |
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
75 unsigned GetTypeAlignment(Ir* ir, Type* t); |
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
76 #endif |
1009
b1b23a64ad8c
Use LLVM alignment data instead of hand-picked.
Frits van Bommel <fvbommel wxs.nl>
parents:
1008
diff
changeset
|
77 |
159 | 78 FuncDeclaration *hasThis(Scope *sc); |
79 | |
80 | |
81 #define LOGDOTEXP 0 // log ::dotExp() | |
82 #define LOGDEFAULTINIT 0 // log ::defaultInit() | |
83 | |
84 // Allow implicit conversion of T[] to T* | |
85 #define IMPLICIT_ARRAY_TO_PTR global.params.useDeprecated | |
86 | |
87 /* These have default values for 32 bit code, they get | |
88 * adjusted for 64 bit code. | |
89 */ | |
90 | |
91 int PTRSIZE = 4; | |
92 #if IN_LLVM | |
93 int REALSIZE = 8; | |
94 int REALPAD = 0; | |
95 #elif TARGET_LINUX | |
96 int REALSIZE = 12; | |
97 int REALPAD = 2; | |
98 #else | |
99 int REALSIZE = 10; | |
100 int REALPAD = 0; | |
101 #endif | |
102 int Tsize_t = Tuns32; | |
103 int Tptrdiff_t = Tint32; | |
104 | |
105 /***************************** Type *****************************/ | |
106 | |
107 ClassDeclaration *Type::typeinfo; | |
108 ClassDeclaration *Type::typeinfoclass; | |
109 ClassDeclaration *Type::typeinfointerface; | |
110 ClassDeclaration *Type::typeinfostruct; | |
111 ClassDeclaration *Type::typeinfotypedef; | |
112 ClassDeclaration *Type::typeinfopointer; | |
113 ClassDeclaration *Type::typeinfoarray; | |
114 ClassDeclaration *Type::typeinfostaticarray; | |
115 ClassDeclaration *Type::typeinfoassociativearray; | |
116 ClassDeclaration *Type::typeinfoenum; | |
117 ClassDeclaration *Type::typeinfofunction; | |
118 ClassDeclaration *Type::typeinfodelegate; | |
119 ClassDeclaration *Type::typeinfotypelist; | |
120 | |
121 Type *Type::tvoidptr; | |
122 Type *Type::basic[TMAX]; | |
123 unsigned char Type::mangleChar[TMAX]; | |
124 StringTable Type::stringtable; | |
125 | |
126 | |
127 Type::Type(TY ty, Type *next) | |
128 { | |
129 this->ty = ty; | |
130 this->mod = 0; | |
131 this->next = next; | |
132 this->deco = NULL; | |
336 | 133 #if DMDV2 |
159 | 134 this->cto = NULL; |
135 this->ito = NULL; | |
136 #endif | |
137 this->pto = NULL; | |
138 this->rto = NULL; | |
139 this->arrayof = NULL; | |
140 this->vtinfo = NULL; | |
1146
1860414bf3b7
* Moved ir/irsymbol.cpp/h into ir/irdsymbol.cpp/h.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1133
diff
changeset
|
141 #if IN_DMD |
159 | 142 this->ctype = NULL; |
1146
1860414bf3b7
* Moved ir/irsymbol.cpp/h into ir/irdsymbol.cpp/h.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1133
diff
changeset
|
143 #endif |
159 | 144 } |
145 | |
146 Type *Type::syntaxCopy() | |
147 { | |
148 print(); | |
149 fprintf(stdmsg, "ty = %d\n", ty); | |
150 assert(0); | |
151 return this; | |
152 } | |
153 | |
154 int Type::equals(Object *o) | |
155 { Type *t; | |
156 | |
157 t = (Type *)o; | |
158 //printf("Type::equals(%s, %s)\n", toChars(), t->toChars()); | |
159 if (this == o || | |
160 (t && deco == t->deco) && // deco strings are unique | |
161 deco != NULL) // and semantic() has been run | |
162 { | |
163 //printf("deco = '%s', t->deco = '%s'\n", deco, t->deco); | |
164 return 1; | |
165 } | |
166 //if (deco && t && t->deco) printf("deco = '%s', t->deco = '%s'\n", deco, t->deco); | |
167 return 0; | |
168 } | |
169 | |
170 char Type::needThisPrefix() | |
171 { | |
172 return 'M'; // name mangling prefix for functions needing 'this' | |
173 } | |
174 | |
1147
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
175 #if IN_LLVM |
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
176 void Type::init(Ir* _sir) |
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
177 #else |
159 | 178 void Type::init() |
1147
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
179 #endif |
159 | 180 { int i; |
181 int j; | |
182 | |
183 Lexer::initKeywords(); | |
184 | |
185 mangleChar[Tarray] = 'A'; | |
186 mangleChar[Tsarray] = 'G'; | |
187 mangleChar[Taarray] = 'H'; | |
188 mangleChar[Tpointer] = 'P'; | |
189 mangleChar[Treference] = 'R'; | |
190 mangleChar[Tfunction] = 'F'; | |
191 mangleChar[Tident] = 'I'; | |
192 mangleChar[Tclass] = 'C'; | |
193 mangleChar[Tstruct] = 'S'; | |
194 mangleChar[Tenum] = 'E'; | |
195 mangleChar[Ttypedef] = 'T'; | |
196 mangleChar[Tdelegate] = 'D'; | |
197 | |
198 mangleChar[Tnone] = 'n'; | |
199 mangleChar[Tvoid] = 'v'; | |
200 mangleChar[Tint8] = 'g'; | |
201 mangleChar[Tuns8] = 'h'; | |
202 mangleChar[Tint16] = 's'; | |
203 mangleChar[Tuns16] = 't'; | |
204 mangleChar[Tint32] = 'i'; | |
205 mangleChar[Tuns32] = 'k'; | |
206 mangleChar[Tint64] = 'l'; | |
207 mangleChar[Tuns64] = 'm'; | |
208 mangleChar[Tfloat32] = 'f'; | |
209 mangleChar[Tfloat64] = 'd'; | |
210 mangleChar[Tfloat80] = 'e'; | |
211 | |
212 mangleChar[Timaginary32] = 'o'; | |
213 mangleChar[Timaginary64] = 'p'; | |
214 mangleChar[Timaginary80] = 'j'; | |
215 mangleChar[Tcomplex32] = 'q'; | |
216 mangleChar[Tcomplex64] = 'r'; | |
217 mangleChar[Tcomplex80] = 'c'; | |
218 | |
219 mangleChar[Tbool] = 'b'; | |
220 mangleChar[Tascii] = 'a'; | |
221 mangleChar[Twchar] = 'u'; | |
222 mangleChar[Tdchar] = 'w'; | |
223 | |
224 mangleChar[Tbit] = '@'; | |
225 mangleChar[Tinstance] = '@'; | |
226 mangleChar[Terror] = '@'; | |
227 mangleChar[Ttypeof] = '@'; | |
228 mangleChar[Ttuple] = 'B'; | |
229 mangleChar[Tslice] = '@'; | |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
230 mangleChar[Treturn] = '@'; |
159 | 231 |
232 for (i = 0; i < TMAX; i++) | |
233 { if (!mangleChar[i]) | |
234 fprintf(stdmsg, "ty = %d\n", i); | |
235 assert(mangleChar[i]); | |
236 } | |
237 | |
238 // Set basic types | |
239 static TY basetab[] = | |
240 { Tvoid, Tint8, Tuns8, Tint16, Tuns16, Tint32, Tuns32, Tint64, Tuns64, | |
241 Tfloat32, Tfloat64, Tfloat80, | |
242 Timaginary32, Timaginary64, Timaginary80, | |
243 Tcomplex32, Tcomplex64, Tcomplex80, | |
244 Tbit, Tbool, | |
245 Tascii, Twchar, Tdchar }; | |
246 | |
247 for (i = 0; i < sizeof(basetab) / sizeof(basetab[0]); i++) | |
248 basic[basetab[i]] = new TypeBasic(basetab[i]); | |
249 basic[Terror] = basic[Tint32]; | |
250 | |
251 tvoidptr = tvoid->pointerTo(); | |
252 | |
1147
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
253 // LDC |
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
254 sir = _sir; |
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
255 |
270
d9d5d59873d8
[svn r291] Fixed a bunch of the old Phobos tests to work with Tango.
lindquist
parents:
243
diff
changeset
|
256 // set size_t / ptrdiff_t types and pointer size |
159 | 257 if (global.params.is64bit) |
258 { | |
742
05e7657a7811
Fix REALSIZE, REALPAD and alignment of double and real for x86-64.
Christian Kamm <kamm incasoftware de>
parents:
739
diff
changeset
|
259 Tsize_t = Tuns64; |
05e7657a7811
Fix REALSIZE, REALPAD and alignment of double and real for x86-64.
Christian Kamm <kamm incasoftware de>
parents:
739
diff
changeset
|
260 Tptrdiff_t = Tint64; |
05e7657a7811
Fix REALSIZE, REALPAD and alignment of double and real for x86-64.
Christian Kamm <kamm incasoftware de>
parents:
739
diff
changeset
|
261 PTRSIZE = 8; |
159 | 262 } |
263 else | |
264 { | |
742
05e7657a7811
Fix REALSIZE, REALPAD and alignment of double and real for x86-64.
Christian Kamm <kamm incasoftware de>
parents:
739
diff
changeset
|
265 Tsize_t = Tuns32; |
05e7657a7811
Fix REALSIZE, REALPAD and alignment of double and real for x86-64.
Christian Kamm <kamm incasoftware de>
parents:
739
diff
changeset
|
266 Tptrdiff_t = Tint32; |
05e7657a7811
Fix REALSIZE, REALPAD and alignment of double and real for x86-64.
Christian Kamm <kamm incasoftware de>
parents:
739
diff
changeset
|
267 PTRSIZE = 4; |
243
4d006f7b2ada
[svn r260] Changed some of the LLVMDC specific code in the Tango core and did some minor cleanups.
lindquist
parents:
217
diff
changeset
|
268 } |
4d006f7b2ada
[svn r260] Changed some of the LLVMDC specific code in the Tango core and did some minor cleanups.
lindquist
parents:
217
diff
changeset
|
269 |
4d006f7b2ada
[svn r260] Changed some of the LLVMDC specific code in the Tango core and did some minor cleanups.
lindquist
parents:
217
diff
changeset
|
270 // set real size and padding |
445
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
389
diff
changeset
|
271 if (global.params.cpu == ARCHx86) |
243
4d006f7b2ada
[svn r260] Changed some of the LLVMDC specific code in the Tango core and did some minor cleanups.
lindquist
parents:
217
diff
changeset
|
272 { |
742
05e7657a7811
Fix REALSIZE, REALPAD and alignment of double and real for x86-64.
Christian Kamm <kamm incasoftware de>
parents:
739
diff
changeset
|
273 REALSIZE = 12; |
05e7657a7811
Fix REALSIZE, REALPAD and alignment of double and real for x86-64.
Christian Kamm <kamm incasoftware de>
parents:
739
diff
changeset
|
274 REALPAD = 2; |
05e7657a7811
Fix REALSIZE, REALPAD and alignment of double and real for x86-64.
Christian Kamm <kamm incasoftware de>
parents:
739
diff
changeset
|
275 } |
05e7657a7811
Fix REALSIZE, REALPAD and alignment of double and real for x86-64.
Christian Kamm <kamm incasoftware de>
parents:
739
diff
changeset
|
276 else if (global.params.cpu == ARCHx86_64) |
05e7657a7811
Fix REALSIZE, REALPAD and alignment of double and real for x86-64.
Christian Kamm <kamm incasoftware de>
parents:
739
diff
changeset
|
277 { |
05e7657a7811
Fix REALSIZE, REALPAD and alignment of double and real for x86-64.
Christian Kamm <kamm incasoftware de>
parents:
739
diff
changeset
|
278 REALSIZE = 16; |
05e7657a7811
Fix REALSIZE, REALPAD and alignment of double and real for x86-64.
Christian Kamm <kamm incasoftware de>
parents:
739
diff
changeset
|
279 REALPAD = 6; |
243
4d006f7b2ada
[svn r260] Changed some of the LLVMDC specific code in the Tango core and did some minor cleanups.
lindquist
parents:
217
diff
changeset
|
280 } |
4d006f7b2ada
[svn r260] Changed some of the LLVMDC specific code in the Tango core and did some minor cleanups.
lindquist
parents:
217
diff
changeset
|
281 else |
4d006f7b2ada
[svn r260] Changed some of the LLVMDC specific code in the Tango core and did some minor cleanups.
lindquist
parents:
217
diff
changeset
|
282 { |
742
05e7657a7811
Fix REALSIZE, REALPAD and alignment of double and real for x86-64.
Christian Kamm <kamm incasoftware de>
parents:
739
diff
changeset
|
283 REALSIZE = 8; |
05e7657a7811
Fix REALSIZE, REALPAD and alignment of double and real for x86-64.
Christian Kamm <kamm incasoftware de>
parents:
739
diff
changeset
|
284 REALPAD = 0; |
159 | 285 } |
286 } | |
287 | |
288 d_uns64 Type::size() | |
289 { | |
290 return size(0); | |
291 } | |
292 | |
293 d_uns64 Type::size(Loc loc) | |
294 { | |
295 error(loc, "no size for type %s", toChars()); | |
296 return 1; | |
297 } | |
298 | |
299 unsigned Type::alignsize() | |
300 { | |
301 return size(0); | |
302 } | |
303 | |
304 Type *Type::semantic(Loc loc, Scope *sc) | |
305 { | |
306 if (next) | |
307 next = next->semantic(loc,sc); | |
308 return merge(); | |
309 } | |
310 | |
311 Type *Type::pointerTo() | |
312 { | |
313 if (!pto) | |
314 { Type *t; | |
315 | |
316 t = new TypePointer(this); | |
317 pto = t->merge(); | |
318 } | |
319 return pto; | |
320 } | |
321 | |
322 Type *Type::referenceTo() | |
323 { | |
324 if (!rto) | |
325 { Type *t; | |
326 | |
327 t = new TypeReference(this); | |
328 rto = t->merge(); | |
329 } | |
330 return rto; | |
331 } | |
332 | |
333 Type *Type::arrayOf() | |
334 { | |
335 if (!arrayof) | |
336 { Type *t; | |
337 | |
338 t = new TypeDArray(this); | |
339 arrayof = t->merge(); | |
340 } | |
341 return arrayof; | |
342 } | |
343 | |
344 Dsymbol *Type::toDsymbol(Scope *sc) | |
345 { | |
346 return NULL; | |
347 } | |
348 | |
349 /******************************* | |
350 * If this is a shell around another type, | |
351 * get that other type. | |
352 */ | |
353 | |
354 Type *Type::toBasetype() | |
355 { | |
356 return this; | |
357 } | |
358 | |
359 /******************************** | |
360 * Name mangling. | |
361 */ | |
362 | |
363 void Type::toDecoBuffer(OutBuffer *buf) | |
364 { | |
365 buf->writeByte(mangleChar[ty]); | |
366 if (next) | |
367 { | |
368 assert(next != this); | |
369 //printf("this = %p, ty = %d, next = %p, ty = %d\n", this, this->ty, next, next->ty); | |
370 next->toDecoBuffer(buf); | |
371 } | |
372 } | |
373 | |
374 /******************************** | |
375 * For pretty-printing a type. | |
376 */ | |
377 | |
378 char *Type::toChars() | |
379 { OutBuffer *buf; | |
380 HdrGenState hgs; | |
381 | |
382 buf = new OutBuffer(); | |
383 toCBuffer(buf, NULL, &hgs); | |
384 return buf->toChars(); | |
385 } | |
386 | |
387 void Type::toCBuffer(OutBuffer *buf, Identifier *ident, HdrGenState *hgs) | |
388 { | |
389 toCBuffer2(buf, hgs, 0); | |
390 if (ident) | |
391 { buf->writeByte(' '); | |
392 buf->writestring(ident->toChars()); | |
393 } | |
394 } | |
395 | |
396 void Type::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod) | |
397 { | |
398 if (mod != this->mod) | |
399 { toCBuffer3(buf, hgs, mod); | |
400 return; | |
401 } | |
402 buf->writestring(toChars()); | |
403 } | |
404 | |
405 void Type::toCBuffer3(OutBuffer *buf, HdrGenState *hgs, int mod) | |
406 { | |
407 if (mod != this->mod) | |
408 { char *p; | |
409 | |
410 switch (this->mod) | |
411 { | |
412 case 0: | |
413 toCBuffer2(buf, hgs, this->mod); | |
414 break; | |
415 case MODconst: | |
416 p = "const("; | |
417 goto L1; | |
418 case MODinvariant: | |
419 p = "invariant("; | |
420 L1: buf->writestring(p); | |
421 toCBuffer2(buf, hgs, this->mod); | |
422 buf->writeByte(')'); | |
423 break; | |
424 default: | |
425 assert(0); | |
426 } | |
427 } | |
428 } | |
429 | |
430 | |
431 /************************************ | |
432 */ | |
433 | |
434 Type *Type::merge() | |
435 { Type *t; | |
436 | |
437 //printf("merge(%s)\n", toChars()); | |
438 t = this; | |
439 assert(t); | |
440 if (!deco) | |
441 { | |
442 OutBuffer buf; | |
443 StringValue *sv; | |
444 | |
445 if (next) | |
446 next = next->merge(); | |
447 toDecoBuffer(&buf); | |
448 sv = stringtable.update((char *)buf.data, buf.offset); | |
449 if (sv->ptrvalue) | |
450 { t = (Type *) sv->ptrvalue; | |
451 assert(t->deco); | |
452 //printf("old value, deco = '%s' %p\n", t->deco, t->deco); | |
453 } | |
454 else | |
455 { | |
456 sv->ptrvalue = this; | |
457 deco = sv->lstring.string; | |
458 //printf("new value, deco = '%s' %p\n", t->deco, t->deco); | |
459 } | |
460 } | |
461 return t; | |
462 } | |
463 | |
464 int Type::isbit() | |
465 { | |
466 return FALSE; | |
467 } | |
468 | |
469 int Type::isintegral() | |
470 { | |
471 return FALSE; | |
472 } | |
473 | |
474 int Type::isfloating() | |
475 { | |
476 return FALSE; | |
477 } | |
478 | |
479 int Type::isreal() | |
480 { | |
481 return FALSE; | |
482 } | |
483 | |
484 int Type::isimaginary() | |
485 { | |
486 return FALSE; | |
487 } | |
488 | |
489 int Type::iscomplex() | |
490 { | |
491 return FALSE; | |
492 } | |
493 | |
494 int Type::isscalar() | |
495 { | |
496 return FALSE; | |
497 } | |
498 | |
499 int Type::isunsigned() | |
500 { | |
501 return FALSE; | |
502 } | |
503 | |
504 ClassDeclaration *Type::isClassHandle() | |
505 { | |
506 return NULL; | |
507 } | |
508 | |
509 int Type::isauto() | |
510 { | |
511 return FALSE; | |
512 } | |
513 | |
514 int Type::isString() | |
515 { | |
516 return FALSE; | |
517 } | |
518 | |
519 int Type::checkBoolean() | |
520 { | |
521 return isscalar(); | |
522 } | |
523 | |
524 /********************************* | |
525 * Check type to see if it is based on a deprecated symbol. | |
526 */ | |
527 | |
528 void Type::checkDeprecated(Loc loc, Scope *sc) | |
529 { | |
530 Type *t; | |
531 Dsymbol *s; | |
532 | |
533 for (t = this; t; t = t->next) | |
534 { | |
535 s = t->toDsymbol(sc); | |
536 if (s) | |
537 s->checkDeprecated(loc, sc); | |
538 } | |
539 } | |
540 | |
541 | |
542 Expression *Type::defaultInit(Loc loc) | |
543 { | |
544 #if LOGDEFAULTINIT | |
545 printf("Type::defaultInit() '%s'\n", toChars()); | |
546 #endif | |
547 return NULL; | |
548 } | |
549 | |
550 int Type::isZeroInit() | |
551 { | |
552 return 0; // assume not | |
553 } | |
554 | |
555 int Type::isBaseOf(Type *t, int *poffset) | |
556 { | |
557 return 0; // assume not | |
558 } | |
559 | |
560 /******************************** | |
561 * Determine if 'this' can be implicitly converted | |
562 * to type 'to'. | |
563 * Returns: | |
564 * 0 can't convert | |
565 * 1 can convert using implicit conversions | |
566 * 2 this and to are the same type | |
567 */ | |
568 | |
569 MATCH Type::implicitConvTo(Type *to) | |
570 { | |
571 //printf("Type::implicitConvTo(this=%p, to=%p)\n", this, to); | |
572 //printf("\tthis->next=%p, to->next=%p\n", this->next, to->next); | |
573 if (this == to) | |
574 return MATCHexact; | |
575 // if (to->ty == Tvoid) | |
576 // return 1; | |
577 return MATCHnomatch; | |
578 } | |
579 | |
580 Expression *Type::getProperty(Loc loc, Identifier *ident) | |
581 { Expression *e; | |
582 | |
583 #if LOGDOTEXP | |
584 printf("Type::getProperty(type = '%s', ident = '%s')\n", toChars(), ident->toChars()); | |
585 #endif | |
586 if (ident == Id::__sizeof) | |
587 { | |
588 e = new IntegerExp(loc, size(loc), Type::tsize_t); | |
589 } | |
590 else if (ident == Id::size) | |
591 { | |
592 error(loc, ".size property should be replaced with .sizeof"); | |
593 e = new IntegerExp(loc, size(loc), Type::tsize_t); | |
594 } | |
595 else if (ident == Id::alignof) | |
596 { | |
597 e = new IntegerExp(loc, alignsize(), Type::tsize_t); | |
598 } | |
599 else if (ident == Id::typeinfo) | |
600 { | |
601 if (!global.params.useDeprecated) | |
602 error(loc, ".typeinfo deprecated, use typeid(type)"); | |
603 e = getTypeInfo(NULL); | |
604 } | |
605 else if (ident == Id::init) | |
606 { | |
607 if (ty == Tvoid) | |
608 error(loc, "void does not have an initializer"); | |
609 e = defaultInit(loc); | |
610 } | |
611 else if (ident == Id::mangleof) | |
612 { | |
613 assert(deco); | |
614 e = new StringExp(loc, deco, strlen(deco), 'c'); | |
615 Scope sc; | |
616 e = e->semantic(&sc); | |
617 } | |
618 else if (ident == Id::stringof) | |
619 { char *s = toChars(); | |
620 e = new StringExp(loc, s, strlen(s), 'c'); | |
621 Scope sc; | |
622 e = e->semantic(&sc); | |
623 } | |
624 else | |
625 { | |
626 error(loc, "no property '%s' for type '%s'", ident->toChars(), toChars()); | |
627 e = new IntegerExp(loc, 1, Type::tint32); | |
628 } | |
629 return e; | |
630 } | |
631 | |
632 Expression *Type::dotExp(Scope *sc, Expression *e, Identifier *ident) | |
633 { VarDeclaration *v = NULL; | |
634 | |
635 #if LOGDOTEXP | |
636 printf("Type::dotExp(e = '%s', ident = '%s')\n", e->toChars(), ident->toChars()); | |
637 #endif | |
638 if (e->op == TOKdotvar) | |
639 { | |
640 DotVarExp *dv = (DotVarExp *)e; | |
641 v = dv->var->isVarDeclaration(); | |
642 } | |
643 else if (e->op == TOKvar) | |
644 { | |
645 VarExp *ve = (VarExp *)e; | |
646 v = ve->var->isVarDeclaration(); | |
647 } | |
648 if (v) | |
649 { | |
650 if (ident == Id::offset) | |
651 { | |
652 if (!global.params.useDeprecated) | |
653 error(e->loc, ".offset deprecated, use .offsetof"); | |
654 goto Loffset; | |
655 } | |
656 else if (ident == Id::offsetof) | |
657 { | |
658 Loffset: | |
659 if (v->storage_class & STCfield) | |
660 { | |
661 e = new IntegerExp(e->loc, v->offset, Type::tsize_t); | |
662 return e; | |
663 } | |
664 } | |
665 else if (ident == Id::init) | |
666 { | |
667 #if 0 | |
668 if (v->init) | |
669 { | |
670 if (v->init->isVoidInitializer()) | |
671 error(e->loc, "%s.init is void", v->toChars()); | |
672 else | |
673 { Loc loc = e->loc; | |
674 e = v->init->toExpression(); | |
675 if (e->op == TOKassign || e->op == TOKconstruct) | |
676 { | |
677 e = ((AssignExp *)e)->e2; | |
678 | |
679 /* Take care of case where we used a 0 | |
680 * to initialize the struct. | |
681 */ | |
682 if (e->type == Type::tint32 && | |
683 e->isBool(0) && | |
684 v->type->toBasetype()->ty == Tstruct) | |
685 { | |
686 e = v->type->defaultInit(loc); | |
687 } | |
688 } | |
689 e = e->optimize(WANTvalue | WANTinterpret); | |
690 // if (!e->isConst()) | |
691 // error(loc, ".init cannot be evaluated at compile time"); | |
692 } | |
693 return e; | |
694 } | |
695 #endif | |
696 Expression *ex = defaultInit(e->loc); | |
697 return ex; | |
698 } | |
699 } | |
700 if (ident == Id::typeinfo) | |
701 { | |
702 if (!global.params.useDeprecated) | |
703 error(e->loc, ".typeinfo deprecated, use typeid(type)"); | |
704 e = getTypeInfo(sc); | |
705 return e; | |
706 } | |
707 if (ident == Id::stringof) | |
708 { char *s = e->toChars(); | |
709 e = new StringExp(e->loc, s, strlen(s), 'c'); | |
710 Scope sc; | |
711 e = e->semantic(&sc); | |
712 return e; | |
713 } | |
714 return getProperty(e->loc, ident); | |
715 } | |
716 | |
717 unsigned Type::memalign(unsigned salign) | |
718 { | |
719 return salign; | |
720 } | |
721 | |
722 void Type::error(Loc loc, const char *format, ...) | |
723 { | |
724 va_list ap; | |
725 va_start(ap, format); | |
726 ::verror(loc, format, ap); | |
727 va_end( ap ); | |
728 } | |
729 | |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
730 void Type::warning(Loc loc, const char *format, ...) |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
731 { |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
732 if (global.params.warnings && !global.gag) |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
733 { |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
734 va_list ap; |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
735 va_start(ap, format); |
1124
e7f0c2b48047
Fix a bug where ::warning() was called with a va_list argument instead of an
Frits van Bommel <fvbommel wxs.nl>
parents:
1103
diff
changeset
|
736 ::vwarning(loc, format, ap); |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
737 va_end( ap ); |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
738 } |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
739 } |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
740 |
159 | 741 Identifier *Type::getTypeInfoIdent(int internal) |
742 { | |
743 // _init_10TypeInfo_%s | |
744 OutBuffer buf; | |
745 Identifier *id; | |
746 char *name; | |
747 int len; | |
748 | |
749 //toTypeInfoBuffer(&buf); | |
750 if (internal) | |
751 { buf.writeByte(mangleChar[ty]); | |
752 if (ty == Tarray) | |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
753 buf.writeByte(mangleChar[((TypeArray *)this)->next->ty]); |
159 | 754 } |
755 else | |
756 toDecoBuffer(&buf); | |
757 len = buf.offset; | |
758 name = (char *)alloca(19 + sizeof(len) * 3 + len + 1); | |
759 buf.writeByte(0); | |
760 sprintf(name, "_D%dTypeInfo_%s6__initZ", 9 + len, buf.data); | |
664
eef8ac26c66c
Some missed LLVMDC -> LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
761 // LDC |
375
3c4460b988bd
Do not strip the leading underscore for typeinfo mangles on Windows.
Christian Kamm <kamm incasoftware de>
parents:
336
diff
changeset
|
762 // it is not clear where the underscore that's stripped here is added back in |
3c4460b988bd
Do not strip the leading underscore for typeinfo mangles on Windows.
Christian Kamm <kamm incasoftware de>
parents:
336
diff
changeset
|
763 // if (global.params.isWindows) |
3c4460b988bd
Do not strip the leading underscore for typeinfo mangles on Windows.
Christian Kamm <kamm incasoftware de>
parents:
336
diff
changeset
|
764 // name++; // C mangling will add it back in |
159 | 765 //printf("name = %s\n", name); |
766 id = Lexer::idPool(name); | |
767 return id; | |
768 } | |
769 | |
770 TypeBasic *Type::isTypeBasic() | |
771 { | |
772 return NULL; | |
773 } | |
774 | |
775 | |
776 void Type::resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymbol **ps) | |
777 { | |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
778 //printf("Type::resolve() %s, %d\n", toChars(), ty); |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
779 Type *t = semantic(loc, sc); |
159 | 780 *pt = t; |
781 *pe = NULL; | |
782 *ps = NULL; | |
783 } | |
784 | |
785 /******************************* | |
786 * If one of the subtypes of this type is a TypeIdentifier, | |
787 * i.e. it's an unresolved type, return that type. | |
788 */ | |
789 | |
790 Type *Type::reliesOnTident() | |
791 { | |
792 if (!next) | |
793 return NULL; | |
794 else | |
795 return next->reliesOnTident(); | |
796 } | |
797 | |
798 /******************************** | |
799 * We've mistakenly parsed this as a type. | |
800 * Redo it as an Expression. | |
801 * NULL if cannot. | |
802 */ | |
803 | |
804 Expression *Type::toExpression() | |
805 { | |
806 return NULL; | |
807 } | |
808 | |
809 /*************************************** | |
810 * Return !=0 if type has pointers that need to | |
811 * be scanned by the GC during a collection cycle. | |
812 */ | |
813 | |
814 int Type::hasPointers() | |
815 { | |
816 return FALSE; | |
817 } | |
818 | |
819 /* ============================= TypeBasic =========================== */ | |
820 | |
821 TypeBasic::TypeBasic(TY ty) | |
822 : Type(ty, NULL) | |
658
50383e476c7e
Upgraded frontend to DMD 1.035
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
642
diff
changeset
|
823 { const char *c; |
50383e476c7e
Upgraded frontend to DMD 1.035
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
642
diff
changeset
|
824 const char *d; |
159 | 825 unsigned flags; |
826 | |
827 #define TFLAGSintegral 1 | |
828 #define TFLAGSfloating 2 | |
829 #define TFLAGSunsigned 4 | |
830 #define TFLAGSreal 8 | |
831 #define TFLAGSimaginary 0x10 | |
832 #define TFLAGScomplex 0x20 | |
833 | |
834 flags = 0; | |
835 switch (ty) | |
836 { | |
837 case Tvoid: d = Token::toChars(TOKvoid); | |
838 c = "void"; | |
839 break; | |
840 | |
841 case Tint8: d = Token::toChars(TOKint8); | |
842 c = "byte"; | |
843 flags |= TFLAGSintegral; | |
844 break; | |
845 | |
846 case Tuns8: d = Token::toChars(TOKuns8); | |
847 c = "ubyte"; | |
848 flags |= TFLAGSintegral | TFLAGSunsigned; | |
849 break; | |
850 | |
851 case Tint16: d = Token::toChars(TOKint16); | |
852 c = "short"; | |
853 flags |= TFLAGSintegral; | |
854 break; | |
855 | |
856 case Tuns16: d = Token::toChars(TOKuns16); | |
857 c = "ushort"; | |
858 flags |= TFLAGSintegral | TFLAGSunsigned; | |
859 break; | |
860 | |
861 case Tint32: d = Token::toChars(TOKint32); | |
862 c = "int"; | |
863 flags |= TFLAGSintegral; | |
864 break; | |
865 | |
866 case Tuns32: d = Token::toChars(TOKuns32); | |
867 c = "uint"; | |
868 flags |= TFLAGSintegral | TFLAGSunsigned; | |
869 break; | |
870 | |
871 case Tfloat32: d = Token::toChars(TOKfloat32); | |
872 c = "float"; | |
873 flags |= TFLAGSfloating | TFLAGSreal; | |
874 break; | |
875 | |
876 case Tint64: d = Token::toChars(TOKint64); | |
877 c = "long"; | |
878 flags |= TFLAGSintegral; | |
879 break; | |
880 | |
881 case Tuns64: d = Token::toChars(TOKuns64); | |
882 c = "ulong"; | |
883 flags |= TFLAGSintegral | TFLAGSunsigned; | |
884 break; | |
885 | |
886 case Tfloat64: d = Token::toChars(TOKfloat64); | |
887 c = "double"; | |
888 flags |= TFLAGSfloating | TFLAGSreal; | |
889 break; | |
890 | |
891 case Tfloat80: d = Token::toChars(TOKfloat80); | |
892 c = "real"; | |
893 flags |= TFLAGSfloating | TFLAGSreal; | |
894 break; | |
895 | |
896 case Timaginary32: d = Token::toChars(TOKimaginary32); | |
897 c = "ifloat"; | |
898 flags |= TFLAGSfloating | TFLAGSimaginary; | |
899 break; | |
900 | |
901 case Timaginary64: d = Token::toChars(TOKimaginary64); | |
902 c = "idouble"; | |
903 flags |= TFLAGSfloating | TFLAGSimaginary; | |
904 break; | |
905 | |
906 case Timaginary80: d = Token::toChars(TOKimaginary80); | |
907 c = "ireal"; | |
908 flags |= TFLAGSfloating | TFLAGSimaginary; | |
909 break; | |
910 | |
911 case Tcomplex32: d = Token::toChars(TOKcomplex32); | |
912 c = "cfloat"; | |
913 flags |= TFLAGSfloating | TFLAGScomplex; | |
914 break; | |
915 | |
916 case Tcomplex64: d = Token::toChars(TOKcomplex64); | |
917 c = "cdouble"; | |
918 flags |= TFLAGSfloating | TFLAGScomplex; | |
919 break; | |
920 | |
921 case Tcomplex80: d = Token::toChars(TOKcomplex80); | |
922 c = "creal"; | |
923 flags |= TFLAGSfloating | TFLAGScomplex; | |
924 break; | |
925 | |
926 | |
927 case Tbit: d = Token::toChars(TOKbit); | |
928 c = "bit"; | |
929 flags |= TFLAGSintegral | TFLAGSunsigned; | |
930 break; | |
931 | |
932 case Tbool: d = "bool"; | |
933 c = d; | |
934 flags |= TFLAGSintegral | TFLAGSunsigned; | |
935 break; | |
936 | |
937 case Tascii: d = Token::toChars(TOKchar); | |
938 c = "char"; | |
939 flags |= TFLAGSintegral | TFLAGSunsigned; | |
940 break; | |
941 | |
942 case Twchar: d = Token::toChars(TOKwchar); | |
943 c = "wchar"; | |
944 flags |= TFLAGSintegral | TFLAGSunsigned; | |
945 break; | |
946 | |
947 case Tdchar: d = Token::toChars(TOKdchar); | |
948 c = "dchar"; | |
949 flags |= TFLAGSintegral | TFLAGSunsigned; | |
950 break; | |
951 | |
952 default: assert(0); | |
953 } | |
954 this->dstring = d; | |
955 this->cstring = c; | |
956 this->flags = flags; | |
957 merge(); | |
958 } | |
959 | |
960 Type *TypeBasic::syntaxCopy() | |
961 { | |
962 // No semantic analysis done on basic types, no need to copy | |
963 return this; | |
964 } | |
965 | |
966 | |
967 char *TypeBasic::toChars() | |
968 { | |
658
50383e476c7e
Upgraded frontend to DMD 1.035
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
642
diff
changeset
|
969 return (char *)dstring; |
159 | 970 } |
971 | |
972 void TypeBasic::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod) | |
973 { | |
974 //printf("TypeBasic::toCBuffer2(mod = %d, this->mod = %d)\n", mod, this->mod); | |
975 if (mod != this->mod) | |
976 { toCBuffer3(buf, hgs, mod); | |
977 return; | |
978 } | |
979 buf->writestring(dstring); | |
980 } | |
981 | |
982 d_uns64 TypeBasic::size(Loc loc) | |
983 { unsigned size; | |
984 | |
985 //printf("TypeBasic::size()\n"); | |
986 switch (ty) | |
987 { | |
988 case Tint8: | |
989 case Tuns8: size = 1; break; | |
990 case Tint16: | |
991 case Tuns16: size = 2; break; | |
992 case Tint32: | |
993 case Tuns32: | |
994 case Tfloat32: | |
995 case Timaginary32: | |
996 size = 4; break; | |
997 case Tint64: | |
998 case Tuns64: | |
999 case Tfloat64: | |
1000 case Timaginary64: | |
1001 size = 8; break; | |
1002 case Tfloat80: | |
1003 case Timaginary80: | |
1004 size = REALSIZE; break; | |
1005 case Tcomplex32: | |
1006 size = 8; break; | |
1007 case Tcomplex64: | |
1008 size = 16; break; | |
1009 case Tcomplex80: | |
1010 size = REALSIZE * 2; break; | |
1011 | |
1012 case Tvoid: | |
1013 //size = Type::size(); // error message | |
1014 size = 1; | |
1015 break; | |
1016 | |
1017 case Tbit: size = 1; break; | |
1018 case Tbool: size = 1; break; | |
1019 case Tascii: size = 1; break; | |
1020 case Twchar: size = 2; break; | |
1021 case Tdchar: size = 4; break; | |
1022 | |
1023 default: | |
1024 assert(0); | |
1025 break; | |
1026 } | |
1027 //printf("TypeBasic::size() = %d\n", size); | |
1028 return size; | |
1029 } | |
1030 | |
1031 unsigned TypeBasic::alignsize() | |
1009
b1b23a64ad8c
Use LLVM alignment data instead of hand-picked.
Frits van Bommel <fvbommel wxs.nl>
parents:
1008
diff
changeset
|
1032 { |
1014
47f8b54f90b3
Fixed alignsize for void types. (it's one byte)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1009
diff
changeset
|
1033 if (ty == Tvoid) |
47f8b54f90b3
Fixed alignsize for void types. (it's one byte)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1009
diff
changeset
|
1034 return 1; |
1147
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
1035 return GetTypeAlignment(sir, this); |
159 | 1036 } |
1037 | |
1038 | |
1039 Expression *TypeBasic::getProperty(Loc loc, Identifier *ident) | |
1040 { | |
1041 Expression *e; | |
1042 d_int64 ivalue; | |
1043 #ifdef IN_GCC | |
1044 real_t fvalue; | |
1045 #else | |
1046 d_float80 fvalue; | |
1047 #endif | |
1048 | |
1049 //printf("TypeBasic::getProperty('%s')\n", ident->toChars()); | |
1050 if (ident == Id::max) | |
1051 { | |
1052 switch (ty) | |
1053 { | |
1054 case Tint8: ivalue = 0x7F; goto Livalue; | |
1055 case Tuns8: ivalue = 0xFF; goto Livalue; | |
1056 case Tint16: ivalue = 0x7FFFUL; goto Livalue; | |
1057 case Tuns16: ivalue = 0xFFFFUL; goto Livalue; | |
1058 case Tint32: ivalue = 0x7FFFFFFFUL; goto Livalue; | |
1059 case Tuns32: ivalue = 0xFFFFFFFFUL; goto Livalue; | |
1060 case Tint64: ivalue = 0x7FFFFFFFFFFFFFFFLL; goto Livalue; | |
1061 case Tuns64: ivalue = 0xFFFFFFFFFFFFFFFFULL; goto Livalue; | |
1062 case Tbit: ivalue = 1; goto Livalue; | |
1063 case Tbool: ivalue = 1; goto Livalue; | |
1064 case Tchar: ivalue = 0xFF; goto Livalue; | |
1065 case Twchar: ivalue = 0xFFFFUL; goto Livalue; | |
1066 case Tdchar: ivalue = 0x10FFFFUL; goto Livalue; | |
1067 | |
1068 case Tcomplex32: | |
1069 case Timaginary32: | |
1070 case Tfloat32: fvalue = FLT_MAX; goto Lfvalue; | |
1071 case Tcomplex64: | |
1072 case Timaginary64: | |
1073 case Tfloat64: fvalue = DBL_MAX; goto Lfvalue; | |
1074 case Tcomplex80: | |
1075 case Timaginary80: | |
1076 case Tfloat80: fvalue = LDBL_MAX; goto Lfvalue; | |
1077 } | |
1078 } | |
1079 else if (ident == Id::min) | |
1080 { | |
1081 switch (ty) | |
1082 { | |
1083 case Tint8: ivalue = -128; goto Livalue; | |
1084 case Tuns8: ivalue = 0; goto Livalue; | |
1085 case Tint16: ivalue = -32768; goto Livalue; | |
1086 case Tuns16: ivalue = 0; goto Livalue; | |
1087 case Tint32: ivalue = -2147483647L - 1; goto Livalue; | |
1088 case Tuns32: ivalue = 0; goto Livalue; | |
1089 case Tint64: ivalue = (-9223372036854775807LL-1LL); goto Livalue; | |
1090 case Tuns64: ivalue = 0; goto Livalue; | |
1091 case Tbit: ivalue = 0; goto Livalue; | |
1092 case Tbool: ivalue = 0; goto Livalue; | |
1093 case Tchar: ivalue = 0; goto Livalue; | |
1094 case Twchar: ivalue = 0; goto Livalue; | |
1095 case Tdchar: ivalue = 0; goto Livalue; | |
1096 | |
1097 case Tcomplex32: | |
1098 case Timaginary32: | |
1099 case Tfloat32: fvalue = FLT_MIN; goto Lfvalue; | |
1100 case Tcomplex64: | |
1101 case Timaginary64: | |
1102 case Tfloat64: fvalue = DBL_MIN; goto Lfvalue; | |
1103 case Tcomplex80: | |
1104 case Timaginary80: | |
1105 case Tfloat80: fvalue = LDBL_MIN; goto Lfvalue; | |
1106 } | |
1107 } | |
1108 else if (ident == Id::nan) | |
1109 { | |
1110 switch (ty) | |
1111 { | |
1112 case Tcomplex32: | |
1113 case Tcomplex64: | |
1114 case Tcomplex80: | |
1115 case Timaginary32: | |
1116 case Timaginary64: | |
1117 case Timaginary80: | |
1118 case Tfloat32: | |
1119 case Tfloat64: | |
1120 case Tfloat80: | |
1121 { | |
1122 #if IN_GCC | |
1123 // mode doesn't matter, will be converted in RealExp anyway | |
1124 fvalue = real_t::getnan(real_t::LongDouble); | |
1125 #elif __GNUC__ | |
1126 // gcc nan's have the sign bit set by default, so turn it off | |
1127 // Need the volatile to prevent gcc from doing incorrect | |
1128 // constant folding. | |
1129 volatile d_float80 foo; | |
1130 foo = NAN; | |
1008
4c20df3837f9
Preparation for next patch. Don't ask about why this is needed.
Frits van Bommel <fvbommel wxs.nl>
parents:
1006
diff
changeset
|
1131 if (std::signbit(foo)) // signbit sometimes, not always, set |
159 | 1132 foo = -foo; // turn off sign bit |
1133 fvalue = foo; | |
1134 #elif _MSC_VER | |
1135 unsigned long nan[2]= { 0xFFFFFFFF, 0x7FFFFFFF }; | |
1136 fvalue = *(double*)nan; | |
1137 #else | |
1138 fvalue = NAN; | |
1139 #endif | |
1140 goto Lfvalue; | |
1141 } | |
1142 } | |
1143 } | |
1144 else if (ident == Id::infinity) | |
1145 { | |
1146 switch (ty) | |
1147 { | |
1148 case Tcomplex32: | |
1149 case Tcomplex64: | |
1150 case Tcomplex80: | |
1151 case Timaginary32: | |
1152 case Timaginary64: | |
1153 case Timaginary80: | |
1154 case Tfloat32: | |
1155 case Tfloat64: | |
1156 case Tfloat80: | |
1157 #if IN_GCC | |
1158 fvalue = real_t::getinfinity(); | |
1159 #elif __GNUC__ | |
1160 fvalue = 1 / zero; | |
1161 #elif _MSC_VER | |
1162 fvalue = std::numeric_limits<long double>::infinity(); | |
1163 #else | |
1164 fvalue = INFINITY; | |
1165 #endif | |
1166 goto Lfvalue; | |
1167 } | |
1168 } | |
1169 else if (ident == Id::dig) | |
1170 { | |
1171 switch (ty) | |
1172 { | |
1173 case Tcomplex32: | |
1174 case Timaginary32: | |
1175 case Tfloat32: ivalue = FLT_DIG; goto Lint; | |
1176 case Tcomplex64: | |
1177 case Timaginary64: | |
1178 case Tfloat64: ivalue = DBL_DIG; goto Lint; | |
1179 case Tcomplex80: | |
1180 case Timaginary80: | |
1181 case Tfloat80: ivalue = LDBL_DIG; goto Lint; | |
1182 } | |
1183 } | |
1184 else if (ident == Id::epsilon) | |
1185 { | |
1186 switch (ty) | |
1187 { | |
1188 case Tcomplex32: | |
1189 case Timaginary32: | |
1190 case Tfloat32: fvalue = FLT_EPSILON; goto Lfvalue; | |
1191 case Tcomplex64: | |
1192 case Timaginary64: | |
1193 case Tfloat64: fvalue = DBL_EPSILON; goto Lfvalue; | |
1194 case Tcomplex80: | |
1195 case Timaginary80: | |
1196 case Tfloat80: fvalue = LDBL_EPSILON; goto Lfvalue; | |
1197 } | |
1198 } | |
1199 else if (ident == Id::mant_dig) | |
1200 { | |
1201 switch (ty) | |
1202 { | |
1203 case Tcomplex32: | |
1204 case Timaginary32: | |
1205 case Tfloat32: ivalue = FLT_MANT_DIG; goto Lint; | |
1206 case Tcomplex64: | |
1207 case Timaginary64: | |
1208 case Tfloat64: ivalue = DBL_MANT_DIG; goto Lint; | |
1209 case Tcomplex80: | |
1210 case Timaginary80: | |
1211 case Tfloat80: ivalue = LDBL_MANT_DIG; goto Lint; | |
1212 } | |
1213 } | |
1214 else if (ident == Id::max_10_exp) | |
1215 { | |
1216 switch (ty) | |
1217 { | |
1218 case Tcomplex32: | |
1219 case Timaginary32: | |
1220 case Tfloat32: ivalue = FLT_MAX_10_EXP; goto Lint; | |
1221 case Tcomplex64: | |
1222 case Timaginary64: | |
1223 case Tfloat64: ivalue = DBL_MAX_10_EXP; goto Lint; | |
1224 case Tcomplex80: | |
1225 case Timaginary80: | |
1226 case Tfloat80: ivalue = LDBL_MAX_10_EXP; goto Lint; | |
1227 } | |
1228 } | |
1229 else if (ident == Id::max_exp) | |
1230 { | |
1231 switch (ty) | |
1232 { | |
1233 case Tcomplex32: | |
1234 case Timaginary32: | |
1235 case Tfloat32: ivalue = FLT_MAX_EXP; goto Lint; | |
1236 case Tcomplex64: | |
1237 case Timaginary64: | |
1238 case Tfloat64: ivalue = DBL_MAX_EXP; goto Lint; | |
1239 case Tcomplex80: | |
1240 case Timaginary80: | |
1241 case Tfloat80: ivalue = LDBL_MAX_EXP; goto Lint; | |
1242 } | |
1243 } | |
1244 else if (ident == Id::min_10_exp) | |
1245 { | |
1246 switch (ty) | |
1247 { | |
1248 case Tcomplex32: | |
1249 case Timaginary32: | |
1250 case Tfloat32: ivalue = FLT_MIN_10_EXP; goto Lint; | |
1251 case Tcomplex64: | |
1252 case Timaginary64: | |
1253 case Tfloat64: ivalue = DBL_MIN_10_EXP; goto Lint; | |
1254 case Tcomplex80: | |
1255 case Timaginary80: | |
1256 case Tfloat80: ivalue = LDBL_MIN_10_EXP; goto Lint; | |
1257 } | |
1258 } | |
1259 else if (ident == Id::min_exp) | |
1260 { | |
1261 switch (ty) | |
1262 { | |
1263 case Tcomplex32: | |
1264 case Timaginary32: | |
1265 case Tfloat32: ivalue = FLT_MIN_EXP; goto Lint; | |
1266 case Tcomplex64: | |
1267 case Timaginary64: | |
1268 case Tfloat64: ivalue = DBL_MIN_EXP; goto Lint; | |
1269 case Tcomplex80: | |
1270 case Timaginary80: | |
1271 case Tfloat80: ivalue = LDBL_MIN_EXP; goto Lint; | |
1272 } | |
1273 } | |
1274 | |
1275 Ldefault: | |
1276 return Type::getProperty(loc, ident); | |
1277 | |
1278 Livalue: | |
1279 e = new IntegerExp(loc, ivalue, this); | |
1280 return e; | |
1281 | |
1282 Lfvalue: | |
1283 if (isreal() || isimaginary()) | |
1284 e = new RealExp(loc, fvalue, this); | |
1285 else | |
1286 { | |
1287 complex_t cvalue; | |
1288 | |
1289 #if __DMC__ | |
1290 //((real_t *)&cvalue)[0] = fvalue; | |
1291 //((real_t *)&cvalue)[1] = fvalue; | |
1292 cvalue = fvalue + fvalue * I; | |
1293 #else | |
1294 cvalue.re = fvalue; | |
1295 cvalue.im = fvalue; | |
1296 #endif | |
1297 //for (int i = 0; i < 20; i++) | |
1298 // printf("%02x ", ((unsigned char *)&cvalue)[i]); | |
1299 //printf("\n"); | |
1300 e = new ComplexExp(loc, cvalue, this); | |
1301 } | |
1302 return e; | |
1303 | |
1304 Lint: | |
1305 e = new IntegerExp(loc, ivalue, Type::tint32); | |
1306 return e; | |
1307 } | |
1308 | |
1309 Expression *TypeBasic::dotExp(Scope *sc, Expression *e, Identifier *ident) | |
1310 { | |
1311 #if LOGDOTEXP | |
1312 printf("TypeBasic::dotExp(e = '%s', ident = '%s')\n", e->toChars(), ident->toChars()); | |
1313 #endif | |
1314 Type *t; | |
1315 | |
1316 if (ident == Id::re) | |
1317 { | |
1318 switch (ty) | |
1319 { | |
1320 case Tcomplex32: t = tfloat32; goto L1; | |
1321 case Tcomplex64: t = tfloat64; goto L1; | |
1322 case Tcomplex80: t = tfloat80; goto L1; | |
1323 L1: | |
1324 e = e->castTo(sc, t); | |
1325 break; | |
1326 | |
1327 case Tfloat32: | |
1328 case Tfloat64: | |
1329 case Tfloat80: | |
1330 break; | |
1331 | |
1332 case Timaginary32: t = tfloat32; goto L2; | |
1333 case Timaginary64: t = tfloat64; goto L2; | |
1334 case Timaginary80: t = tfloat80; goto L2; | |
1335 L2: | |
1336 e = new RealExp(0, 0.0, t); | |
1337 break; | |
1338 | |
1339 default: | |
1340 return Type::getProperty(e->loc, ident); | |
1341 } | |
1342 } | |
1343 else if (ident == Id::im) | |
1344 { Type *t2; | |
1345 | |
1346 switch (ty) | |
1347 { | |
1348 case Tcomplex32: t = timaginary32; t2 = tfloat32; goto L3; | |
1349 case Tcomplex64: t = timaginary64; t2 = tfloat64; goto L3; | |
1350 case Tcomplex80: t = timaginary80; t2 = tfloat80; goto L3; | |
1351 L3: | |
1352 e = e->castTo(sc, t); | |
1353 e->type = t2; | |
1354 break; | |
1355 | |
1356 case Timaginary32: t = tfloat32; goto L4; | |
1357 case Timaginary64: t = tfloat64; goto L4; | |
1358 case Timaginary80: t = tfloat80; goto L4; | |
1359 L4: | |
1360 e->type = t; | |
1361 break; | |
1362 | |
1363 case Tfloat32: | |
1364 case Tfloat64: | |
1365 case Tfloat80: | |
1366 e = new RealExp(0, 0.0, this); | |
1367 break; | |
1368 | |
1369 default: | |
1370 return Type::getProperty(e->loc, ident); | |
1371 } | |
1372 } | |
1373 else | |
1374 { | |
1375 return Type::dotExp(sc, e, ident); | |
1376 } | |
1377 return e; | |
1378 } | |
1379 | |
1380 Expression *TypeBasic::defaultInit(Loc loc) | |
1381 { integer_t value = 0; | |
1382 | |
1383 #if LOGDEFAULTINIT | |
1384 printf("TypeBasic::defaultInit() '%s'\n", toChars()); | |
1385 #endif | |
1386 switch (ty) | |
1387 { | |
591
e6bcc4d9e5ff
Add _d_newarrayvT and _d_newarraymvT to create arrays without initialization.
Christian Kamm <kamm incasoftware de>
parents:
585
diff
changeset
|
1388 case Tvoid: |
e6bcc4d9e5ff
Add _d_newarrayvT and _d_newarraymvT to create arrays without initialization.
Christian Kamm <kamm incasoftware de>
parents:
585
diff
changeset
|
1389 return new IntegerExp(loc, value, Type::tbool); |
e6bcc4d9e5ff
Add _d_newarrayvT and _d_newarraymvT to create arrays without initialization.
Christian Kamm <kamm incasoftware de>
parents:
585
diff
changeset
|
1390 |
159 | 1391 case Tchar: |
1392 value = 0xFF; | |
1393 break; | |
1394 | |
1395 case Twchar: | |
1396 case Tdchar: | |
1397 value = 0xFFFF; | |
1398 break; | |
1399 | |
1400 case Timaginary32: | |
1401 case Timaginary64: | |
1402 case Timaginary80: | |
1403 case Tfloat32: | |
1404 case Tfloat64: | |
1405 case Tfloat80: | |
1406 case Tcomplex32: | |
1407 case Tcomplex64: | |
1408 case Tcomplex80: | |
1409 return getProperty(loc, Id::nan); | |
1410 } | |
1411 return new IntegerExp(loc, value, this); | |
1412 } | |
1413 | |
1414 int TypeBasic::isZeroInit() | |
1415 { | |
1416 switch (ty) | |
1417 { | |
1418 case Tchar: | |
1419 case Twchar: | |
1420 case Tdchar: | |
1421 case Timaginary32: | |
1422 case Timaginary64: | |
1423 case Timaginary80: | |
1424 case Tfloat32: | |
1425 case Tfloat64: | |
1426 case Tfloat80: | |
1427 case Tcomplex32: | |
1428 case Tcomplex64: | |
1429 case Tcomplex80: | |
1430 return 0; // no | |
1431 } | |
1432 return 1; // yes | |
1433 } | |
1434 | |
1435 int TypeBasic::isbit() | |
1436 { | |
1437 return (ty == Tbit); | |
1438 } | |
1439 | |
1440 int TypeBasic::isintegral() | |
1441 { | |
1442 //printf("TypeBasic::isintegral('%s') x%x\n", toChars(), flags); | |
1443 return flags & TFLAGSintegral; | |
1444 } | |
1445 | |
1446 int TypeBasic::isfloating() | |
1447 { | |
1448 return flags & TFLAGSfloating; | |
1449 } | |
1450 | |
1451 int TypeBasic::isreal() | |
1452 { | |
1453 return flags & TFLAGSreal; | |
1454 } | |
1455 | |
1456 int TypeBasic::isimaginary() | |
1457 { | |
1458 return flags & TFLAGSimaginary; | |
1459 } | |
1460 | |
1461 int TypeBasic::iscomplex() | |
1462 { | |
1463 return flags & TFLAGScomplex; | |
1464 } | |
1465 | |
1466 int TypeBasic::isunsigned() | |
1467 { | |
1468 return flags & TFLAGSunsigned; | |
1469 } | |
1470 | |
1471 int TypeBasic::isscalar() | |
1472 { | |
1473 return flags & (TFLAGSintegral | TFLAGSfloating); | |
1474 } | |
1475 | |
1476 MATCH TypeBasic::implicitConvTo(Type *to) | |
1477 { | |
1478 //printf("TypeBasic::implicitConvTo(%s) from %s\n", to->toChars(), toChars()); | |
1479 if (this == to) | |
1480 return MATCHexact; | |
1481 | |
1482 if (ty == Tvoid || to->ty == Tvoid) | |
1483 return MATCHnomatch; | |
1484 if (1 || global.params.Dversion == 1) | |
1485 { | |
1486 if (to->ty == Tbool) | |
1487 return MATCHnomatch; | |
1488 } | |
1489 else | |
1490 { | |
1491 if (ty == Tbool || to->ty == Tbool) | |
1492 return MATCHnomatch; | |
1493 } | |
1494 if (!to->isTypeBasic()) | |
1495 return MATCHnomatch; | |
1496 | |
1497 TypeBasic *tob = (TypeBasic *)to; | |
1498 if (flags & TFLAGSintegral) | |
1499 { | |
1500 // Disallow implicit conversion of integers to imaginary or complex | |
1501 if (tob->flags & (TFLAGSimaginary | TFLAGScomplex)) | |
1502 return MATCHnomatch; | |
1503 | |
1504 // If converting to integral | |
1505 if (0 && global.params.Dversion > 1 && tob->flags & TFLAGSintegral) | |
1506 { d_uns64 sz = size(0); | |
1507 d_uns64 tosz = tob->size(0); | |
1508 | |
1509 /* Can't convert to smaller size or, if same size, change sign | |
1510 */ | |
1511 if (sz > tosz) | |
1512 return MATCHnomatch; | |
1513 | |
1514 /*if (sz == tosz && (flags ^ tob->flags) & TFLAGSunsigned) | |
1515 return MATCHnomatch;*/ | |
1516 } | |
1517 } | |
1518 else if (flags & TFLAGSfloating) | |
1519 { | |
1520 // Disallow implicit conversion of floating point to integer | |
1521 if (tob->flags & TFLAGSintegral) | |
1522 return MATCHnomatch; | |
1523 | |
1524 assert(tob->flags & TFLAGSfloating); | |
1525 | |
1526 // Disallow implicit conversion from complex to non-complex | |
1527 if (flags & TFLAGScomplex && !(tob->flags & TFLAGScomplex)) | |
1528 return MATCHnomatch; | |
1529 | |
1530 // Disallow implicit conversion of real or imaginary to complex | |
1531 if (flags & (TFLAGSreal | TFLAGSimaginary) && | |
1532 tob->flags & TFLAGScomplex) | |
1533 return MATCHnomatch; | |
1534 | |
1535 // Disallow implicit conversion to-from real and imaginary | |
1536 if ((flags & (TFLAGSreal | TFLAGSimaginary)) != | |
1537 (tob->flags & (TFLAGSreal | TFLAGSimaginary))) | |
1538 return MATCHnomatch; | |
1539 } | |
1540 return MATCHconvert; | |
1541 } | |
1542 | |
1543 TypeBasic *TypeBasic::isTypeBasic() | |
1544 { | |
1545 return (TypeBasic *)this; | |
1546 } | |
1547 | |
1548 /***************************** TypeArray *****************************/ | |
1549 | |
1550 TypeArray::TypeArray(TY ty, Type *next) | |
1551 : Type(ty, next) | |
1552 { | |
1553 } | |
1554 | |
1555 Expression *TypeArray::dotExp(Scope *sc, Expression *e, Identifier *ident) | |
1556 { | |
1557 Type *n = this->next->toBasetype(); // uncover any typedef's | |
1558 | |
1559 #if LOGDOTEXP | |
1560 printf("TypeArray::dotExp(e = '%s', ident = '%s')\n", e->toChars(), ident->toChars()); | |
1561 #endif | |
1562 if (ident == Id::reverse && (n->ty == Tchar || n->ty == Twchar)) | |
1563 { | |
1564 Expression *ec; | |
1565 Expressions *arguments; | |
389
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1566 |
664
eef8ac26c66c
Some missed LLVMDC -> LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
1567 //LDC: Build arguments. |
389
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1568 static FuncDeclaration *adReverseChar_fd = NULL; |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1569 if(!adReverseChar_fd) { |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1570 Arguments* args = new Arguments; |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1571 Type* arrty = Type::tchar->arrayOf(); |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1572 args->push(new Argument(STCin, arrty, NULL, NULL)); |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1573 adReverseChar_fd = FuncDeclaration::genCfunc(args, arrty, "_adReverseChar"); |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1574 } |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1575 static FuncDeclaration *adReverseWchar_fd = NULL; |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1576 if(!adReverseWchar_fd) { |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1577 Arguments* args = new Arguments; |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1578 Type* arrty = Type::twchar->arrayOf(); |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1579 args->push(new Argument(STCin, arrty, NULL, NULL)); |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1580 adReverseWchar_fd = FuncDeclaration::genCfunc(args, arrty, "_adReverseWchar"); |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1581 } |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1582 |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1583 if(n->ty == Twchar) |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1584 ec = new VarExp(0, adReverseWchar_fd); |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1585 else |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1586 ec = new VarExp(0, adReverseChar_fd); |
159 | 1587 e = e->castTo(sc, n->arrayOf()); // convert to dynamic array |
1588 arguments = new Expressions(); | |
1589 arguments->push(e); | |
1590 e = new CallExp(e->loc, ec, arguments); | |
1591 e->type = next->arrayOf(); | |
1592 } | |
1593 else if (ident == Id::sort && (n->ty == Tchar || n->ty == Twchar)) | |
1594 { | |
1595 Expression *ec; | |
1596 Expressions *arguments; | |
389
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1597 |
664
eef8ac26c66c
Some missed LLVMDC -> LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
1598 //LDC: Build arguments. |
389
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1599 static FuncDeclaration *adSortChar_fd = NULL; |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1600 if(!adSortChar_fd) { |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1601 Arguments* args = new Arguments; |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1602 Type* arrty = Type::tchar->arrayOf(); |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1603 args->push(new Argument(STCin, arrty, NULL, NULL)); |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1604 adSortChar_fd = FuncDeclaration::genCfunc(args, arrty, "_adSortChar"); |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1605 } |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1606 static FuncDeclaration *adSortWchar_fd = NULL; |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1607 if(!adSortWchar_fd) { |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1608 Arguments* args = new Arguments; |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1609 Type* arrty = Type::twchar->arrayOf(); |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1610 args->push(new Argument(STCin, arrty, NULL, NULL)); |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1611 adSortWchar_fd = FuncDeclaration::genCfunc(args, arrty, "_adSortWchar"); |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1612 } |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1613 |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1614 if(n->ty == Twchar) |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1615 ec = new VarExp(0, adSortWchar_fd); |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1616 else |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1617 ec = new VarExp(0, adSortChar_fd); |
159 | 1618 e = e->castTo(sc, n->arrayOf()); // convert to dynamic array |
1619 arguments = new Expressions(); | |
1620 arguments->push(e); | |
1621 e = new CallExp(e->loc, ec, arguments); | |
1622 e->type = next->arrayOf(); | |
1623 } | |
1624 else if (ident == Id::reverse || ident == Id::dup) | |
1625 { | |
1626 Expression *ec; | |
1627 Expressions *arguments; | |
1628 int size = next->size(e->loc); | |
1629 int dup; | |
1630 | |
1631 assert(size); | |
1632 dup = (ident == Id::dup); | |
664
eef8ac26c66c
Some missed LLVMDC -> LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
1633 //LDC: Build arguments. |
389
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1634 static FuncDeclaration *adDup_fd = NULL; |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1635 if(!adDup_fd) { |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1636 Arguments* args = new Arguments; |
378
d8234836b40f
Get rid of runTimeHack and instead add proper argument info to the frontend
Christian Kamm <kamm incasoftware de>
parents:
375
diff
changeset
|
1637 args->push(new Argument(STCin, Type::typeinfo->type, NULL, NULL)); |
715
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
1638 args->push(new Argument(STCin, Type::tvoid->arrayOf(), NULL, NULL)); |
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
1639 adDup_fd = FuncDeclaration::genCfunc(args, Type::tvoid->arrayOf(), Id::adDup); |
389
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1640 } |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1641 static FuncDeclaration *adReverse_fd = NULL; |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1642 if(!adReverse_fd) { |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1643 Arguments* args = new Arguments; |
715
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
1644 args->push(new Argument(STCin, Type::tvoid->arrayOf(), NULL, NULL)); |
378
d8234836b40f
Get rid of runTimeHack and instead add proper argument info to the frontend
Christian Kamm <kamm incasoftware de>
parents:
375
diff
changeset
|
1645 args->push(new Argument(STCin, Type::tsize_t, NULL, NULL)); |
715
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
1646 adReverse_fd = FuncDeclaration::genCfunc(args, Type::tvoid->arrayOf(), Id::adReverse); |
378
d8234836b40f
Get rid of runTimeHack and instead add proper argument info to the frontend
Christian Kamm <kamm incasoftware de>
parents:
375
diff
changeset
|
1647 } |
389
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1648 |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1649 if(dup) |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1650 ec = new VarExp(0, adDup_fd); |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1651 else |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1652 ec = new VarExp(0, adReverse_fd); |
159 | 1653 e = e->castTo(sc, n->arrayOf()); // convert to dynamic array |
1654 arguments = new Expressions(); | |
1655 if (dup) | |
1656 arguments->push(getTypeInfo(sc)); | |
715
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
1657 |
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
1658 // LDC repaint array type to void[] |
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
1659 if (n->ty != Tvoid) { |
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
1660 e = new CastExp(e->loc, e, e->type); |
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
1661 e->type = Type::tvoid->arrayOf(); |
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
1662 } |
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
1663 arguments->push(e); |
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
1664 |
159 | 1665 if (!dup) |
881
1c2faa8325d1
Fixed 64bit problem in mtype.c with _adReverse runtime call, fixes #161 .
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
875
diff
changeset
|
1666 arguments->push(new IntegerExp(0, size, Type::tsize_t)); |
159 | 1667 e = new CallExp(e->loc, ec, arguments); |
1668 e->type = next->arrayOf(); | |
1669 } | |
1670 else if (ident == Id::sort) | |
1671 { | |
1672 Expression *ec; | |
1673 Expressions *arguments; | |
389
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1674 bool isBit = (n->ty == Tbit); |
159 | 1675 |
664
eef8ac26c66c
Some missed LLVMDC -> LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
1676 //LDC: Build arguments. |
389
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1677 static FuncDeclaration *adSort_fd = NULL; |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1678 if(!adSort_fd) { |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1679 Arguments* args = new Arguments; |
715
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
1680 args->push(new Argument(STCin, Type::tvoid->arrayOf(), NULL, NULL)); |
389
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1681 args->push(new Argument(STCin, Type::typeinfo->type, NULL, NULL)); |
715
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
1682 adSort_fd = FuncDeclaration::genCfunc(args, Type::tvoid->arrayOf(), "_adSort"); |
389
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1683 } |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1684 static FuncDeclaration *adSortBit_fd = NULL; |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1685 if(!adSortBit_fd) { |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1686 Arguments* args = new Arguments; |
715
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
1687 args->push(new Argument(STCin, Type::tvoid->arrayOf(), NULL, NULL)); |
389
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1688 args->push(new Argument(STCin, Type::typeinfo->type, NULL, NULL)); |
715
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
1689 adSortBit_fd = FuncDeclaration::genCfunc(args, Type::tvoid->arrayOf(), "_adSortBit"); |
389
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1690 } |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1691 |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1692 if(isBit) |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1693 ec = new VarExp(0, adSortBit_fd); |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1694 else |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
1695 ec = new VarExp(0, adSort_fd); |
159 | 1696 e = e->castTo(sc, n->arrayOf()); // convert to dynamic array |
1697 arguments = new Expressions(); | |
715
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
1698 |
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
1699 // LDC repaint array type to void[] |
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
1700 if (n->ty != Tvoid) { |
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
1701 e = new CastExp(e->loc, e, e->type); |
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
1702 e->type = Type::tvoid->arrayOf(); |
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
1703 } |
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
1704 arguments->push(e); |
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
1705 |
509
337554fd34f1
Fixed mini/missingti.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
489
diff
changeset
|
1706 if (next->ty != Tbit) |
664
eef8ac26c66c
Some missed LLVMDC -> LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
1707 arguments->push(n->getTypeInfo(sc)); // LDC, we don't support the getInternalTypeInfo |
509
337554fd34f1
Fixed mini/missingti.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
489
diff
changeset
|
1708 // optimization arbitrarily, not yet at least... |
159 | 1709 e = new CallExp(e->loc, ec, arguments); |
1710 e->type = next->arrayOf(); | |
1711 } | |
1712 else | |
1713 { | |
1714 e = Type::dotExp(sc, e, ident); | |
1715 } | |
1716 return e; | |
1717 } | |
1718 | |
1719 | |
1720 /***************************** TypeSArray *****************************/ | |
1721 | |
1722 TypeSArray::TypeSArray(Type *t, Expression *dim) | |
1723 : TypeArray(Tsarray, t) | |
1724 { | |
1725 //printf("TypeSArray(%s)\n", dim->toChars()); | |
1726 this->dim = dim; | |
1727 } | |
1728 | |
1729 Type *TypeSArray::syntaxCopy() | |
1730 { | |
1731 Type *t = next->syntaxCopy(); | |
1732 Expression *e = dim->syntaxCopy(); | |
1733 t = new TypeSArray(t, e); | |
1734 return t; | |
1735 } | |
1736 | |
1737 d_uns64 TypeSArray::size(Loc loc) | |
1738 { integer_t sz; | |
1739 | |
1740 if (!dim) | |
1741 return Type::size(loc); | |
1742 sz = dim->toInteger(); | |
1743 if (next->toBasetype()->ty == Tbit) // if array of bits | |
1744 { | |
1745 if (sz + 31 < sz) | |
1746 goto Loverflow; | |
1747 sz = ((sz + 31) & ~31) / 8; // size in bytes, rounded up to 32 bit dwords | |
1748 } | |
1749 else | |
1750 { integer_t n, n2; | |
1751 | |
1752 n = next->size(); | |
1753 n2 = n * sz; | |
1754 if (n && (n2 / n) != sz) | |
1755 goto Loverflow; | |
1756 sz = n2; | |
1757 } | |
1758 return sz; | |
1759 | |
1760 Loverflow: | |
1133
eeb8b95ea92e
Cleanup DMD 1.041 merge.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1124
diff
changeset
|
1761 error(loc, "index %jd overflow for static array", sz); |
159 | 1762 return 1; |
1763 } | |
1764 | |
1765 unsigned TypeSArray::alignsize() | |
1766 { | |
1767 return next->alignsize(); | |
1768 } | |
1769 | |
1770 /************************** | |
1771 * This evaluates exp while setting length to be the number | |
1772 * of elements in the tuple t. | |
1773 */ | |
1774 Expression *semanticLength(Scope *sc, Type *t, Expression *exp) | |
1775 { | |
1776 if (t->ty == Ttuple) | |
1777 { ScopeDsymbol *sym = new ArrayScopeSymbol((TypeTuple *)t); | |
1778 sym->parent = sc->scopesym; | |
1779 sc = sc->push(sym); | |
1780 | |
1781 exp = exp->semantic(sc); | |
1782 | |
1783 sc->pop(); | |
1784 } | |
1785 else | |
1786 exp = exp->semantic(sc); | |
1787 return exp; | |
1788 } | |
1789 | |
1790 Expression *semanticLength(Scope *sc, TupleDeclaration *s, Expression *exp) | |
1791 { | |
1792 ScopeDsymbol *sym = new ArrayScopeSymbol(s); | |
1793 sym->parent = sc->scopesym; | |
1794 sc = sc->push(sym); | |
1795 | |
1796 exp = exp->semantic(sc); | |
1797 | |
1798 sc->pop(); | |
1799 return exp; | |
1800 } | |
1801 | |
1802 void TypeSArray::resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymbol **ps) | |
1803 { | |
1804 //printf("TypeSArray::resolve() %s\n", toChars()); | |
1805 next->resolve(loc, sc, pe, pt, ps); | |
1806 //printf("s = %p, e = %p, t = %p\n", *ps, *pe, *pt); | |
1807 if (*pe) | |
1808 { // It's really an index expression | |
1809 Expression *e; | |
1810 e = new IndexExp(loc, *pe, dim); | |
1811 *pe = e; | |
1812 } | |
1813 else if (*ps) | |
1814 { Dsymbol *s = *ps; | |
1815 TupleDeclaration *td = s->isTupleDeclaration(); | |
1816 if (td) | |
1817 { | |
1818 ScopeDsymbol *sym = new ArrayScopeSymbol(td); | |
1819 sym->parent = sc->scopesym; | |
1820 sc = sc->push(sym); | |
1821 | |
1822 dim = dim->semantic(sc); | |
1823 dim = dim->optimize(WANTvalue | WANTinterpret); | |
1824 uinteger_t d = dim->toUInteger(); | |
1825 | |
1826 sc = sc->pop(); | |
1827 | |
1828 if (d >= td->objects->dim) | |
1133
eeb8b95ea92e
Cleanup DMD 1.041 merge.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1124
diff
changeset
|
1829 { error(loc, "tuple index %ju exceeds %u", d, td->objects->dim); |
159 | 1830 goto Ldefault; |
1831 } | |
1832 Object *o = (Object *)td->objects->data[(size_t)d]; | |
1833 if (o->dyncast() == DYNCAST_DSYMBOL) | |
1834 { | |
1835 *ps = (Dsymbol *)o; | |
1836 return; | |
1837 } | |
1838 if (o->dyncast() == DYNCAST_EXPRESSION) | |
1839 { | |
1840 *ps = NULL; | |
1841 *pe = (Expression *)o; | |
1842 return; | |
1843 } | |
1844 | |
1845 /* Create a new TupleDeclaration which | |
1846 * is a slice [d..d+1] out of the old one. | |
1847 * Do it this way because TemplateInstance::semanticTiargs() | |
1848 * can handle unresolved Objects this way. | |
1849 */ | |
1850 Objects *objects = new Objects; | |
1851 objects->setDim(1); | |
1852 objects->data[0] = o; | |
1853 | |
1854 TupleDeclaration *tds = new TupleDeclaration(loc, td->ident, objects); | |
1855 *ps = tds; | |
1856 } | |
1857 else | |
1858 goto Ldefault; | |
1859 } | |
1860 else | |
1861 { | |
1862 Ldefault: | |
1863 Type::resolve(loc, sc, pe, pt, ps); | |
1864 } | |
1865 } | |
1866 | |
1867 Type *TypeSArray::semantic(Loc loc, Scope *sc) | |
1868 { | |
1869 //printf("TypeSArray::semantic() %s\n", toChars()); | |
1870 | |
1871 Type *t; | |
1872 Expression *e; | |
1873 Dsymbol *s; | |
1874 next->resolve(loc, sc, &e, &t, &s); | |
1875 if (dim && s && s->isTupleDeclaration()) | |
1876 { TupleDeclaration *sd = s->isTupleDeclaration(); | |
1877 | |
1878 dim = semanticLength(sc, sd, dim); | |
1879 dim = dim->optimize(WANTvalue | WANTinterpret); | |
1880 uinteger_t d = dim->toUInteger(); | |
1881 | |
1882 if (d >= sd->objects->dim) | |
1133
eeb8b95ea92e
Cleanup DMD 1.041 merge.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1124
diff
changeset
|
1883 { error(loc, "tuple index %ju exceeds %u", d, sd->objects->dim); |
159 | 1884 return Type::terror; |
1885 } | |
1886 Object *o = (Object *)sd->objects->data[(size_t)d]; | |
1887 if (o->dyncast() != DYNCAST_TYPE) | |
1888 { error(loc, "%s is not a type", toChars()); | |
1889 return Type::terror; | |
1890 } | |
1891 t = (Type *)o; | |
1892 return t; | |
1893 } | |
1894 | |
1895 next = next->semantic(loc,sc); | |
1896 Type *tbn = next->toBasetype(); | |
1897 | |
1898 if (dim) | |
1899 { integer_t n, n2; | |
1900 | |
1901 dim = semanticLength(sc, tbn, dim); | |
1902 | |
1903 dim = dim->optimize(WANTvalue | WANTinterpret); | |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
1904 if (sc && sc->parameterSpecialization && dim->op == TOKvar && |
159 | 1905 ((VarExp *)dim)->var->storage_class & STCtemplateparameter) |
1906 { | |
1907 /* It could be a template parameter N which has no value yet: | |
1908 * template Foo(T : T[N], size_t N); | |
1909 */ | |
1910 return this; | |
1911 } | |
1912 integer_t d1 = dim->toInteger(); | |
1913 dim = dim->castTo(sc, tsize_t); | |
1914 dim = dim->optimize(WANTvalue); | |
1915 integer_t d2 = dim->toInteger(); | |
1916 | |
1917 if (d1 != d2) | |
1918 goto Loverflow; | |
1919 | |
1920 if (tbn->isintegral() || | |
1921 tbn->isfloating() || | |
1922 tbn->ty == Tpointer || | |
1923 tbn->ty == Tarray || | |
1924 tbn->ty == Tsarray || | |
1925 tbn->ty == Taarray || | |
1926 tbn->ty == Tclass) | |
1927 { | |
1928 /* Only do this for types that don't need to have semantic() | |
1929 * run on them for the size, since they may be forward referenced. | |
1930 */ | |
1931 n = tbn->size(loc); | |
1932 n2 = n * d2; | |
1933 if ((int)n2 < 0) | |
1934 goto Loverflow; | |
1935 if (n2 >= 0x1000000) // put a 'reasonable' limit on it | |
1936 goto Loverflow; | |
1937 if (n && n2 / n != d2) | |
1938 { | |
1939 Loverflow: | |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
1940 error(loc, "index %jd overflow for static array", d1); |
159 | 1941 dim = new IntegerExp(0, 1, tsize_t); |
1942 } | |
1943 } | |
1944 } | |
1945 switch (tbn->ty) | |
1946 { | |
1947 case Ttuple: | |
1948 { // Index the tuple to get the type | |
1949 assert(dim); | |
1950 TypeTuple *tt = (TypeTuple *)tbn; | |
1951 uinteger_t d = dim->toUInteger(); | |
1952 | |
1953 if (d >= tt->arguments->dim) | |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
1954 { error(loc, "tuple index %ju exceeds %u", d, tt->arguments->dim); |
159 | 1955 return Type::terror; |
1956 } | |
1957 Argument *arg = (Argument *)tt->arguments->data[(size_t)d]; | |
1958 return arg->type; | |
1959 } | |
1960 case Tfunction: | |
1961 case Tnone: | |
1962 error(loc, "can't have array of %s", tbn->toChars()); | |
1963 tbn = next = tint32; | |
1964 break; | |
1965 } | |
1966 if (tbn->isauto()) | |
1967 error(loc, "cannot have array of auto %s", tbn->toChars()); | |
1968 return merge(); | |
1969 } | |
1970 | |
1971 void TypeSArray::toDecoBuffer(OutBuffer *buf) | |
1972 { | |
1973 buf->writeByte(mangleChar[ty]); | |
1974 if (dim) | |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
1975 buf->printf("%ju", dim->toInteger()); |
159 | 1976 if (next) |
1977 next->toDecoBuffer(buf); | |
1978 } | |
1979 | |
1980 void TypeSArray::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod) | |
1981 { | |
1982 if (mod != this->mod) | |
1983 { toCBuffer3(buf, hgs, mod); | |
1984 return; | |
1985 } | |
1986 next->toCBuffer2(buf, hgs, this->mod); | |
1987 buf->printf("[%s]", dim->toChars()); | |
1988 } | |
1989 | |
1990 Expression *TypeSArray::dotExp(Scope *sc, Expression *e, Identifier *ident) | |
1991 { | |
1992 #if LOGDOTEXP | |
1993 printf("TypeSArray::dotExp(e = '%s', ident = '%s')\n", e->toChars(), ident->toChars()); | |
1994 #endif | |
1995 if (ident == Id::length) | |
1996 { | |
1997 e = dim; | |
1998 } | |
1999 else if (ident == Id::ptr) | |
2000 { | |
2001 e = e->castTo(sc, next->pointerTo()); | |
2002 } | |
2003 else | |
2004 { | |
2005 e = TypeArray::dotExp(sc, e, ident); | |
2006 } | |
2007 return e; | |
2008 } | |
2009 | |
2010 int TypeSArray::isString() | |
2011 { | |
2012 TY nty = next->toBasetype()->ty; | |
2013 return nty == Tchar || nty == Twchar || nty == Tdchar; | |
2014 } | |
2015 | |
2016 unsigned TypeSArray::memalign(unsigned salign) | |
2017 { | |
2018 return next->memalign(salign); | |
2019 } | |
2020 | |
2021 MATCH TypeSArray::implicitConvTo(Type *to) | |
2022 { | |
2023 //printf("TypeSArray::implicitConvTo()\n"); | |
2024 | |
2025 // Allow implicit conversion of static array to pointer or dynamic array | |
2026 if ((IMPLICIT_ARRAY_TO_PTR && to->ty == Tpointer) && | |
2027 (to->next->ty == Tvoid || next->equals(to->next) | |
2028 /*|| to->next->isBaseOf(next)*/)) | |
2029 { | |
2030 return MATCHconvert; | |
2031 } | |
2032 if (to->ty == Tarray) | |
2033 { int offset = 0; | |
2034 | |
2035 if (next->equals(to->next) || | |
2036 (to->next->isBaseOf(next, &offset) && offset == 0) || | |
2037 to->next->ty == Tvoid) | |
2038 return MATCHconvert; | |
2039 } | |
2040 #if 0 | |
2041 if (to->ty == Tsarray) | |
2042 { | |
2043 TypeSArray *tsa = (TypeSArray *)to; | |
2044 | |
2045 if (next->equals(tsa->next) && dim->equals(tsa->dim)) | |
2046 { | |
2047 return MATCHconvert; | |
2048 } | |
2049 } | |
2050 #endif | |
2051 return Type::implicitConvTo(to); | |
2052 } | |
2053 | |
2054 Expression *TypeSArray::defaultInit(Loc loc) | |
2055 { | |
2056 #if LOGDEFAULTINIT | |
2057 printf("TypeSArray::defaultInit() '%s'\n", toChars()); | |
2058 #endif | |
2059 return next->defaultInit(loc); | |
2060 } | |
2061 | |
2062 int TypeSArray::isZeroInit() | |
2063 { | |
2064 return next->isZeroInit(); | |
2065 } | |
2066 | |
2067 | |
2068 Expression *TypeSArray::toExpression() | |
2069 { | |
2070 Expression *e = next->toExpression(); | |
2071 if (e) | |
2072 { Expressions *arguments = new Expressions(); | |
2073 arguments->push(dim); | |
2074 e = new ArrayExp(dim->loc, e, arguments); | |
2075 } | |
2076 return e; | |
2077 } | |
2078 | |
2079 int TypeSArray::hasPointers() | |
2080 { | |
2081 return next->hasPointers(); | |
2082 } | |
2083 | |
2084 /***************************** TypeDArray *****************************/ | |
2085 | |
2086 TypeDArray::TypeDArray(Type *t) | |
2087 : TypeArray(Tarray, t) | |
2088 { | |
2089 //printf("TypeDArray(t = %p)\n", t); | |
2090 } | |
2091 | |
2092 Type *TypeDArray::syntaxCopy() | |
2093 { | |
2094 Type *t = next->syntaxCopy(); | |
2095 if (t == next) | |
2096 t = this; | |
2097 else | |
2098 t = new TypeDArray(t); | |
2099 return t; | |
2100 } | |
2101 | |
2102 d_uns64 TypeDArray::size(Loc loc) | |
2103 { | |
2104 //printf("TypeDArray::size()\n"); | |
2105 return PTRSIZE * 2; | |
2106 } | |
2107 | |
2108 unsigned TypeDArray::alignsize() | |
2109 { | |
2110 // A DArray consists of two ptr-sized values, so align it on pointer size | |
2111 // boundary | |
2112 return PTRSIZE; | |
2113 } | |
2114 | |
2115 Type *TypeDArray::semantic(Loc loc, Scope *sc) | |
2116 { Type *tn = next; | |
2117 | |
2118 tn = next->semantic(loc,sc); | |
2119 Type *tbn = tn->toBasetype(); | |
2120 switch (tbn->ty) | |
2121 { | |
2122 case Tfunction: | |
2123 case Tnone: | |
2124 case Ttuple: | |
2125 error(loc, "can't have array of %s", tbn->toChars()); | |
2126 tn = next = tint32; | |
2127 break; | |
2128 } | |
2129 if (tn->isauto()) | |
2130 error(loc, "cannot have array of auto %s", tn->toChars()); | |
2131 if (next != tn) | |
2132 //deco = NULL; // redo | |
2133 return tn->arrayOf(); | |
2134 return merge(); | |
2135 } | |
2136 | |
2137 void TypeDArray::toDecoBuffer(OutBuffer *buf) | |
2138 { | |
2139 buf->writeByte(mangleChar[ty]); | |
2140 if (next) | |
2141 next->toDecoBuffer(buf); | |
2142 } | |
2143 | |
2144 void TypeDArray::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod) | |
2145 { | |
2146 if (mod != this->mod) | |
2147 { toCBuffer3(buf, hgs, mod); | |
2148 return; | |
2149 } | |
2150 next->toCBuffer2(buf, hgs, this->mod); | |
2151 buf->writestring("[]"); | |
2152 } | |
2153 | |
2154 Expression *TypeDArray::dotExp(Scope *sc, Expression *e, Identifier *ident) | |
2155 { | |
2156 #if LOGDOTEXP | |
2157 printf("TypeDArray::dotExp(e = '%s', ident = '%s')\n", e->toChars(), ident->toChars()); | |
2158 #endif | |
2159 if (ident == Id::length) | |
2160 { | |
2161 if (e->op == TOKstring) | |
2162 { StringExp *se = (StringExp *)e; | |
2163 | |
2164 return new IntegerExp(se->loc, se->len, Type::tindex); | |
2165 } | |
2166 e = new ArrayLengthExp(e->loc, e); | |
2167 e->type = Type::tsize_t; | |
2168 return e; | |
2169 } | |
2170 else if (ident == Id::ptr) | |
2171 { | |
2172 e = e->castTo(sc, next->pointerTo()); | |
2173 return e; | |
2174 } | |
2175 else | |
2176 { | |
2177 e = TypeArray::dotExp(sc, e, ident); | |
2178 } | |
2179 return e; | |
2180 } | |
2181 | |
2182 int TypeDArray::isString() | |
2183 { | |
2184 TY nty = next->toBasetype()->ty; | |
2185 return nty == Tchar || nty == Twchar || nty == Tdchar; | |
2186 } | |
2187 | |
2188 MATCH TypeDArray::implicitConvTo(Type *to) | |
2189 { | |
2190 //printf("TypeDArray::implicitConvTo()\n"); | |
2191 | |
2192 // Allow implicit conversion of array to pointer | |
2193 if (IMPLICIT_ARRAY_TO_PTR && | |
2194 to->ty == Tpointer && | |
2195 (to->next->ty == Tvoid || next->equals(to->next) /*|| to->next->isBaseOf(next)*/)) | |
2196 { | |
2197 return MATCHconvert; | |
2198 } | |
2199 | |
2200 if (to->ty == Tarray) | |
2201 { int offset = 0; | |
2202 | |
2203 if ((to->next->isBaseOf(next, &offset) && offset == 0) || | |
2204 to->next->ty == Tvoid) | |
2205 return MATCHconvert; | |
2206 } | |
2207 return Type::implicitConvTo(to); | |
2208 } | |
2209 | |
2210 Expression *TypeDArray::defaultInit(Loc loc) | |
2211 { | |
2212 #if LOGDEFAULTINIT | |
2213 printf("TypeDArray::defaultInit() '%s'\n", toChars()); | |
2214 #endif | |
2215 Expression *e; | |
2216 e = new NullExp(loc); | |
2217 e->type = this; | |
2218 return e; | |
2219 } | |
2220 | |
2221 int TypeDArray::isZeroInit() | |
2222 { | |
2223 return 1; | |
2224 } | |
2225 | |
2226 int TypeDArray::checkBoolean() | |
2227 { | |
2228 return TRUE; | |
2229 } | |
2230 | |
2231 int TypeDArray::hasPointers() | |
2232 { | |
2233 return TRUE; | |
2234 } | |
2235 | |
2236 /***************************** TypeAArray *****************************/ | |
2237 | |
2238 TypeAArray::TypeAArray(Type *t, Type *index) | |
2239 : TypeArray(Taarray, t) | |
2240 { | |
2241 this->index = index; | |
2242 this->key = NULL; | |
2243 } | |
2244 | |
2245 Type *TypeAArray::syntaxCopy() | |
2246 { | |
2247 Type *t = next->syntaxCopy(); | |
2248 Type *ti = index->syntaxCopy(); | |
2249 if (t == next && ti == index) | |
2250 t = this; | |
2251 else | |
2252 t = new TypeAArray(t, ti); | |
2253 return t; | |
2254 } | |
2255 | |
2256 d_uns64 TypeAArray::size(Loc loc) | |
2257 { | |
2258 return PTRSIZE /* * 2*/; | |
2259 } | |
2260 | |
2261 | |
2262 Type *TypeAArray::semantic(Loc loc, Scope *sc) | |
2263 { | |
2264 //printf("TypeAArray::semantic() %s index->ty = %d\n", toChars(), index->ty); | |
2265 | |
2266 // Deal with the case where we thought the index was a type, but | |
2267 // in reality it was an expression. | |
2268 if (index->ty == Tident || index->ty == Tinstance || index->ty == Tsarray) | |
2269 { | |
2270 Expression *e; | |
2271 Type *t; | |
2272 Dsymbol *s; | |
2273 | |
2274 index->resolve(loc, sc, &e, &t, &s); | |
2275 if (e) | |
2276 { // It was an expression - | |
2277 // Rewrite as a static array | |
2278 TypeSArray *tsa; | |
2279 | |
2280 tsa = new TypeSArray(next, e); | |
2281 return tsa->semantic(loc,sc); | |
2282 } | |
2283 else if (t) | |
2284 index = t; | |
2285 else | |
2286 index->error(loc, "index is not a type or an expression"); | |
2287 } | |
2288 else | |
2289 index = index->semantic(loc,sc); | |
2290 | |
2291 // Compute key type; the purpose of the key type is to | |
2292 // minimize the permutations of runtime library | |
2293 // routines as much as possible. | |
2294 key = index->toBasetype(); | |
2295 switch (key->ty) | |
2296 { | |
2297 #if 0 | |
2298 case Tint8: | |
2299 case Tuns8: | |
2300 case Tint16: | |
2301 case Tuns16: | |
2302 key = tint32; | |
2303 break; | |
2304 #endif | |
2305 | |
2306 case Tsarray: | |
2307 #if 0 | |
2308 // Convert to Tarray | |
2309 key = key->next->arrayOf(); | |
2310 #endif | |
2311 break; | |
2312 case Tbit: | |
2313 case Tbool: | |
2314 case Tfunction: | |
2315 case Tvoid: | |
2316 case Tnone: | |
2317 error(loc, "can't have associative array key of %s", key->toChars()); | |
2318 break; | |
2319 } | |
2320 next = next->semantic(loc,sc); | |
2321 switch (next->toBasetype()->ty) | |
2322 { | |
2323 case Tfunction: | |
2324 case Tnone: | |
2325 error(loc, "can't have associative array of %s", next->toChars()); | |
2326 break; | |
2327 } | |
2328 if (next->isauto()) | |
2329 error(loc, "cannot have array of auto %s", next->toChars()); | |
2330 | |
2331 return merge(); | |
2332 } | |
2333 | |
336 | 2334 void TypeAArray::resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymbol **ps) |
2335 { | |
2336 //printf("TypeAArray::resolve() %s\n", toChars()); | |
2337 | |
2338 // Deal with the case where we thought the index was a type, but | |
2339 // in reality it was an expression. | |
2340 if (index->ty == Tident || index->ty == Tinstance || index->ty == Tsarray) | |
2341 { | |
2342 Expression *e; | |
2343 Type *t; | |
2344 Dsymbol *s; | |
2345 | |
2346 index->resolve(loc, sc, &e, &t, &s); | |
2347 if (e) | |
2348 { // It was an expression - | |
2349 // Rewrite as a static array | |
2350 | |
2351 TypeSArray *tsa = new TypeSArray(next, e); | |
2352 return tsa->resolve(loc, sc, pe, pt, ps); | |
2353 } | |
2354 else if (t) | |
2355 index = t; | |
2356 else | |
2357 index->error(loc, "index is not a type or an expression"); | |
2358 } | |
2359 Type::resolve(loc, sc, pe, pt, ps); | |
2360 } | |
2361 | |
2362 | |
159 | 2363 Expression *TypeAArray::dotExp(Scope *sc, Expression *e, Identifier *ident) |
2364 { | |
2365 #if LOGDOTEXP | |
2366 printf("TypeAArray::dotExp(e = '%s', ident = '%s')\n", e->toChars(), ident->toChars()); | |
2367 #endif | |
2368 if (ident == Id::length) | |
2369 { | |
2370 Expression *ec; | |
2371 Expressions *arguments; | |
2372 | |
664
eef8ac26c66c
Some missed LLVMDC -> LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
2373 //LDC: Build arguments. |
389
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
2374 static FuncDeclaration *aaLen_fd = NULL; |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
2375 if(!aaLen_fd) { |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
2376 Arguments* args = new Arguments; |
715
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
2377 args->push(new Argument(STCin, Type::tvoid->pointerTo(), NULL, NULL)); |
389
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
2378 aaLen_fd = FuncDeclaration::genCfunc(args, Type::tsize_t, Id::aaLen); |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
2379 } |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
2380 |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
2381 ec = new VarExp(0, aaLen_fd); |
159 | 2382 arguments = new Expressions(); |
2383 arguments->push(e); | |
2384 e = new CallExp(e->loc, ec, arguments); | |
389
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
2385 e->type = aaLen_fd->type->next; |
159 | 2386 } |
2387 else if (ident == Id::keys) | |
2388 { | |
2389 Expression *ec; | |
2390 Expressions *arguments; | |
2391 int size = key->size(e->loc); | |
2392 | |
2393 assert(size); | |
664
eef8ac26c66c
Some missed LLVMDC -> LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
2394 //LDC: Build arguments. |
389
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
2395 static FuncDeclaration *aaKeys_fd = NULL; |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
2396 if(!aaKeys_fd) { |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
2397 Arguments* args = new Arguments; |
715
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
2398 args->push(new Argument(STCin, Type::tvoid->pointerTo(), NULL, NULL)); |
389
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
2399 args->push(new Argument(STCin, Type::tsize_t, NULL, NULL)); |
715
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
2400 aaKeys_fd = FuncDeclaration::genCfunc(args, Type::tvoid->arrayOf(), Id::aaKeys); |
389
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
2401 } |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
2402 |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
2403 ec = new VarExp(0, aaKeys_fd); |
159 | 2404 arguments = new Expressions(); |
2405 arguments->push(e); | |
2406 arguments->push(new IntegerExp(0, size, Type::tsize_t)); | |
2407 e = new CallExp(e->loc, ec, arguments); | |
2408 e->type = index->arrayOf(); | |
2409 } | |
2410 else if (ident == Id::values) | |
2411 { | |
2412 Expression *ec; | |
2413 Expressions *arguments; | |
2414 | |
664
eef8ac26c66c
Some missed LLVMDC -> LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
2415 //LDC: Build arguments. |
389
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
2416 static FuncDeclaration *aaValues_fd = NULL; |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
2417 if(!aaValues_fd) { |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
2418 Arguments* args = new Arguments; |
715
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
2419 args->push(new Argument(STCin, Type::tvoid->pointerTo(), NULL, NULL)); |
389
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
2420 args->push(new Argument(STCin, Type::tsize_t, NULL, NULL)); |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
2421 args->push(new Argument(STCin, Type::tsize_t, NULL, NULL)); |
715
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
2422 aaValues_fd = FuncDeclaration::genCfunc(args, Type::tvoid->arrayOf(), Id::aaValues); |
389
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
2423 } |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
2424 |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
2425 ec = new VarExp(0, aaValues_fd); |
159 | 2426 arguments = new Expressions(); |
2427 arguments->push(e); | |
2428 size_t keysize = key->size(e->loc); | |
771
bfabbac8e705
Fixed 64bit problem with aaValues runtime calls (assumed 32bits)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
742
diff
changeset
|
2429 keysize = (keysize + PTRSIZE - 1) & ~(PTRSIZE - 1); |
159 | 2430 arguments->push(new IntegerExp(0, keysize, Type::tsize_t)); |
2431 arguments->push(new IntegerExp(0, next->size(e->loc), Type::tsize_t)); | |
2432 e = new CallExp(e->loc, ec, arguments); | |
2433 e->type = next->arrayOf(); | |
2434 } | |
2435 else if (ident == Id::rehash) | |
2436 { | |
2437 Expression *ec; | |
2438 Expressions *arguments; | |
2439 | |
664
eef8ac26c66c
Some missed LLVMDC -> LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
2440 //LDC: Build arguments. |
389
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
2441 static FuncDeclaration *aaRehash_fd = NULL; |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
2442 if(!aaRehash_fd) { |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
2443 Arguments* args = new Arguments; |
715
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
664
diff
changeset
|
2444 args->push(new Argument(STCin, Type::tvoid->pointerTo(), NULL, NULL)); |
389
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
2445 args->push(new Argument(STCin, Type::typeinfo->type, NULL, NULL)); |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
2446 aaRehash_fd = FuncDeclaration::genCfunc(args, Type::tvoidptr, Id::aaRehash); |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
2447 } |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
2448 |
722f5e90c39c
Made setup for runtime calls in dmd frontend allocate less.
Christian Kamm <kamm incasoftware de>
parents:
387
diff
changeset
|
2449 ec = new VarExp(0, aaRehash_fd); |
159 | 2450 arguments = new Expressions(); |
2451 arguments->push(e->addressOf(sc)); | |
975
067bb8f19c36
Fix #217. getInternalTypeInfo doesn't work with LDC.
Christian Kamm <kamm incasoftware de>
parents:
938
diff
changeset
|
2452 arguments->push(key->getTypeInfo(sc)); // LDC doesn't support getInternalTypeInfo, see above |
159 | 2453 e = new CallExp(e->loc, ec, arguments); |
2454 e->type = this; | |
2455 } | |
2456 else | |
2457 { | |
2458 e = Type::dotExp(sc, e, ident); | |
2459 } | |
2460 return e; | |
2461 } | |
2462 | |
2463 void TypeAArray::toDecoBuffer(OutBuffer *buf) | |
2464 { | |
2465 buf->writeByte(mangleChar[ty]); | |
2466 index->toDecoBuffer(buf); | |
2467 next->toDecoBuffer(buf); | |
2468 } | |
2469 | |
2470 void TypeAArray::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod) | |
2471 { | |
2472 if (mod != this->mod) | |
2473 { toCBuffer3(buf, hgs, mod); | |
2474 return; | |
2475 } | |
2476 next->toCBuffer2(buf, hgs, this->mod); | |
2477 buf->writeByte('['); | |
2478 index->toCBuffer2(buf, hgs, 0); | |
2479 buf->writeByte(']'); | |
2480 } | |
2481 | |
2482 Expression *TypeAArray::defaultInit(Loc loc) | |
2483 { | |
2484 #if LOGDEFAULTINIT | |
2485 printf("TypeAArray::defaultInit() '%s'\n", toChars()); | |
2486 #endif | |
2487 Expression *e; | |
2488 e = new NullExp(loc); | |
2489 e->type = this; | |
2490 return e; | |
2491 } | |
2492 | |
211
f66219e0d530
[svn r227] Fixed: crash in lifetime.d when resizing array of AAs by .length assignment.
lindquist
parents:
162
diff
changeset
|
2493 int TypeAArray::isZeroInit() |
f66219e0d530
[svn r227] Fixed: crash in lifetime.d when resizing array of AAs by .length assignment.
lindquist
parents:
162
diff
changeset
|
2494 { |
846
bc982f1ad106
Merged DMD 1.037 frontend
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
822
diff
changeset
|
2495 return TRUE; |
211
f66219e0d530
[svn r227] Fixed: crash in lifetime.d when resizing array of AAs by .length assignment.
lindquist
parents:
162
diff
changeset
|
2496 } |
f66219e0d530
[svn r227] Fixed: crash in lifetime.d when resizing array of AAs by .length assignment.
lindquist
parents:
162
diff
changeset
|
2497 |
159 | 2498 int TypeAArray::checkBoolean() |
2499 { | |
2500 return TRUE; | |
2501 } | |
2502 | |
2503 int TypeAArray::hasPointers() | |
2504 { | |
2505 return TRUE; | |
2506 } | |
2507 | |
2508 /***************************** TypePointer *****************************/ | |
2509 | |
2510 TypePointer::TypePointer(Type *t) | |
2511 : Type(Tpointer, t) | |
2512 { | |
2513 } | |
2514 | |
2515 Type *TypePointer::syntaxCopy() | |
2516 { | |
2517 Type *t = next->syntaxCopy(); | |
2518 if (t == next) | |
2519 t = this; | |
2520 else | |
2521 t = new TypePointer(t); | |
2522 return t; | |
2523 } | |
2524 | |
2525 Type *TypePointer::semantic(Loc loc, Scope *sc) | |
2526 { | |
2527 //printf("TypePointer::semantic()\n"); | |
2528 Type *n = next->semantic(loc, sc); | |
2529 switch (n->toBasetype()->ty) | |
2530 { | |
2531 case Ttuple: | |
2532 error(loc, "can't have pointer to %s", n->toChars()); | |
2533 n = tint32; | |
2534 break; | |
2535 } | |
2536 if (n != next) | |
2537 deco = NULL; | |
2538 next = n; | |
2539 return merge(); | |
2540 } | |
2541 | |
2542 | |
2543 d_uns64 TypePointer::size(Loc loc) | |
2544 { | |
2545 return PTRSIZE; | |
2546 } | |
2547 | |
2548 void TypePointer::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod) | |
2549 { | |
2550 //printf("TypePointer::toCBuffer2() next = %d\n", next->ty); | |
2551 if (mod != this->mod) | |
2552 { toCBuffer3(buf, hgs, mod); | |
2553 return; | |
2554 } | |
2555 next->toCBuffer2(buf, hgs, this->mod); | |
2556 if (next->ty != Tfunction) | |
2557 buf->writeByte('*'); | |
2558 } | |
2559 | |
2560 MATCH TypePointer::implicitConvTo(Type *to) | |
2561 { | |
2562 //printf("TypePointer::implicitConvTo()\n"); | |
2563 | |
2564 if (this == to) | |
2565 return MATCHexact; | |
2566 if (to->ty == Tpointer && to->next) | |
2567 { | |
2568 if (to->next->ty == Tvoid) | |
2569 return MATCHconvert; | |
2570 | |
2571 #if 0 | |
2572 if (to->next->isBaseOf(next)) | |
2573 return MATCHconvert; | |
2574 #endif | |
2575 | |
2576 if (next->ty == Tfunction && to->next->ty == Tfunction) | |
2577 { TypeFunction *tf; | |
2578 TypeFunction *tfto; | |
2579 | |
2580 tf = (TypeFunction *)(next); | |
2581 tfto = (TypeFunction *)(to->next); | |
2582 return tfto->equals(tf) ? MATCHexact : MATCHnomatch; | |
2583 } | |
2584 } | |
2585 // if (to->ty == Tvoid) | |
2586 // return MATCHconvert; | |
2587 return MATCHnomatch; | |
2588 } | |
2589 | |
2590 int TypePointer::isscalar() | |
2591 { | |
2592 return TRUE; | |
2593 } | |
2594 | |
2595 Expression *TypePointer::defaultInit(Loc loc) | |
2596 { | |
2597 #if LOGDEFAULTINIT | |
2598 printf("TypePointer::defaultInit() '%s'\n", toChars()); | |
2599 #endif | |
2600 Expression *e; | |
2601 e = new NullExp(loc); | |
2602 e->type = this; | |
2603 return e; | |
2604 } | |
2605 | |
2606 int TypePointer::isZeroInit() | |
2607 { | |
2608 return 1; | |
2609 } | |
2610 | |
2611 int TypePointer::hasPointers() | |
2612 { | |
2613 return TRUE; | |
2614 } | |
2615 | |
2616 | |
2617 /***************************** TypeReference *****************************/ | |
2618 | |
2619 TypeReference::TypeReference(Type *t) | |
2620 : Type(Treference, t) | |
2621 { | |
2622 if (t->ty == Tbit) | |
2623 error(0,"cannot make reference to a bit"); | |
2624 // BUG: what about references to static arrays? | |
2625 } | |
2626 | |
2627 Type *TypeReference::syntaxCopy() | |
2628 { | |
2629 Type *t = next->syntaxCopy(); | |
2630 if (t == next) | |
2631 t = this; | |
2632 else | |
2633 t = new TypeReference(t); | |
2634 return t; | |
2635 } | |
2636 | |
2637 d_uns64 TypeReference::size(Loc loc) | |
2638 { | |
2639 return PTRSIZE; | |
2640 } | |
2641 | |
2642 void TypeReference::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod) | |
2643 { | |
2644 if (mod != this->mod) | |
2645 { toCBuffer3(buf, hgs, mod); | |
2646 return; | |
2647 } | |
2648 next->toCBuffer2(buf, hgs, this->mod); | |
2649 buf->writeByte('&'); | |
2650 } | |
2651 | |
2652 Expression *TypeReference::dotExp(Scope *sc, Expression *e, Identifier *ident) | |
2653 { | |
2654 #if LOGDOTEXP | |
2655 printf("TypeReference::dotExp(e = '%s', ident = '%s')\n", e->toChars(), ident->toChars()); | |
2656 #endif | |
2657 | |
2658 // References just forward things along | |
2659 return next->dotExp(sc, e, ident); | |
2660 } | |
2661 | |
2662 Expression *TypeReference::defaultInit(Loc loc) | |
2663 { | |
2664 #if LOGDEFAULTINIT | |
2665 printf("TypeReference::defaultInit() '%s'\n", toChars()); | |
2666 #endif | |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
2667 Expression *e = new NullExp(loc); |
159 | 2668 e->type = this; |
2669 return e; | |
2670 } | |
2671 | |
2672 int TypeReference::isZeroInit() | |
2673 { | |
2674 return 1; | |
2675 } | |
2676 | |
2677 | |
2678 /***************************** TypeFunction *****************************/ | |
2679 | |
2680 TypeFunction::TypeFunction(Arguments *parameters, Type *treturn, int varargs, enum LINK linkage) | |
2681 : Type(Tfunction, treturn) | |
2682 { | |
2683 //if (!treturn) *(char*)0=0; | |
2684 // assert(treturn); | |
2685 this->parameters = parameters; | |
2686 this->varargs = varargs; | |
2687 this->linkage = linkage; | |
2688 this->inuse = 0; | |
2689 } | |
2690 | |
2691 Type *TypeFunction::syntaxCopy() | |
2692 { | |
2693 Type *treturn = next ? next->syntaxCopy() : NULL; | |
2694 Arguments *params = Argument::arraySyntaxCopy(parameters); | |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
211
diff
changeset
|
2695 TypeFunction *t = new TypeFunction(params, treturn, varargs, linkage); |
159 | 2696 return t; |
2697 } | |
2698 | |
2699 /******************************* | |
2700 * Returns: | |
2701 * 0 types are distinct | |
2702 * 1 this is covariant with t | |
2703 * 2 arguments match as far as overloading goes, | |
2704 * but types are not covariant | |
2705 * 3 cannot determine covariance because of forward references | |
2706 */ | |
2707 | |
2708 int Type::covariant(Type *t) | |
2709 { | |
2710 #if 0 | |
2711 printf("Type::covariant(t = %s) %s\n", t->toChars(), toChars()); | |
2712 printf("deco = %p, %p\n", deco, t->deco); | |
2713 printf("ty = %d\n", next->ty); | |
2714 #endif | |
2715 | |
2716 int inoutmismatch = 0; | |
2717 | |
2718 if (equals(t)) | |
2719 goto Lcovariant; | |
2720 if (ty != Tfunction || t->ty != Tfunction) | |
2721 goto Ldistinct; | |
2722 | |
2723 { | |
2724 TypeFunction *t1 = (TypeFunction *)this; | |
2725 TypeFunction *t2 = (TypeFunction *)t; | |
2726 | |
2727 if (t1->varargs != t2->varargs) | |
2728 goto Ldistinct; | |
2729 | |
2730 if (t1->parameters && t2->parameters) | |
2731 { | |
2732 size_t dim = Argument::dim(t1->parameters); | |
2733 if (dim != Argument::dim(t2->parameters)) | |
2734 goto Ldistinct; | |
2735 | |
2736 for (size_t i = 0; i < dim; i++) | |
2737 { Argument *arg1 = Argument::getNth(t1->parameters, i); | |
2738 Argument *arg2 = Argument::getNth(t2->parameters, i); | |
2739 | |
2740 if (!arg1->type->equals(arg2->type)) | |
2741 goto Ldistinct; | |
2742 if (arg1->storageClass != arg2->storageClass) | |
2743 inoutmismatch = 1; | |
2744 } | |
2745 } | |
2746 else if (t1->parameters != t2->parameters) | |
2747 goto Ldistinct; | |
2748 | |
2749 // The argument lists match | |
2750 if (inoutmismatch) | |
2751 goto Lnotcovariant; | |
2752 if (t1->linkage != t2->linkage) | |
2753 goto Lnotcovariant; | |
2754 | |
2755 Type *t1n = t1->next; | |
2756 Type *t2n = t2->next; | |
2757 | |
2758 if (t1n->equals(t2n)) | |
2759 goto Lcovariant; | |
2760 if (t1n->ty != Tclass || t2n->ty != Tclass) | |
2761 goto Lnotcovariant; | |
2762 | |
2763 // If t1n is forward referenced: | |
2764 ClassDeclaration *cd = ((TypeClass *)t1n)->sym; | |
2765 if (!cd->baseClass && cd->baseclasses.dim && !cd->isInterfaceDeclaration()) | |
2766 { | |
2767 return 3; | |
2768 } | |
2769 | |
2770 if (t1n->implicitConvTo(t2n)) | |
2771 goto Lcovariant; | |
2772 goto Lnotcovariant; | |
2773 } | |
2774 | |
2775 Lcovariant: | |
2776 //printf("\tcovaraint: 1\n"); | |
2777 return 1; | |
2778 | |
2779 Ldistinct: | |
2780 //printf("\tcovaraint: 0\n"); | |
2781 return 0; | |
2782 | |
2783 Lnotcovariant: | |
2784 //printf("\tcovaraint: 2\n"); | |
2785 return 2; | |
2786 } | |
2787 | |
2788 void TypeFunction::toDecoBuffer(OutBuffer *buf) | |
2789 { unsigned char mc; | |
2790 | |
2791 //printf("TypeFunction::toDecoBuffer() this = %p %s\n", this, toChars()); | |
2792 //static int nest; if (++nest == 50) *(char*)0=0; | |
2793 if (inuse) | |
2794 { inuse = 2; // flag error to caller | |
2795 return; | |
2796 } | |
2797 inuse++; | |
2798 switch (linkage) | |
2799 { | |
2800 case LINKd: mc = 'F'; break; | |
2801 case LINKc: mc = 'U'; break; | |
2802 case LINKwindows: mc = 'W'; break; | |
2803 case LINKpascal: mc = 'V'; break; | |
2804 case LINKcpp: mc = 'R'; break; | |
723
55f6c2e454d7
Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
720
diff
changeset
|
2805 |
55f6c2e454d7
Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
720
diff
changeset
|
2806 // LDC |
55f6c2e454d7
Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
720
diff
changeset
|
2807 case LINKintrinsic: mc = 'Q'; break; |
55f6c2e454d7
Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
720
diff
changeset
|
2808 |
159 | 2809 default: |
2810 assert(0); | |
2811 } | |
2812 buf->writeByte(mc); | |
2813 // Write argument types | |
2814 Argument::argsToDecoBuffer(buf, parameters); | |
2815 //if (buf->data[buf->offset - 1] == '@') halt(); | |
2816 buf->writeByte('Z' - varargs); // mark end of arg list | |
2817 next->toDecoBuffer(buf); | |
2818 inuse--; | |
2819 } | |
2820 | |
2821 void TypeFunction::toCBuffer(OutBuffer *buf, Identifier *ident, HdrGenState *hgs) | |
2822 { | |
2823 char *p = NULL; | |
2824 | |
2825 if (inuse) | |
2826 { inuse = 2; // flag error to caller | |
2827 return; | |
2828 } | |
2829 inuse++; | |
2830 if (next && (!ident || ident->toHChars2() == ident->toChars())) | |
2831 next->toCBuffer2(buf, hgs, 0); | |
2832 if (hgs->ddoc != 1) | |
2833 { | |
2834 switch (linkage) | |
2835 { | |
2836 case LINKd: p = NULL; break; | |
2837 case LINKc: p = "C "; break; | |
2838 case LINKwindows: p = "Windows "; break; | |
2839 case LINKpascal: p = "Pascal "; break; | |
2840 case LINKcpp: p = "C++ "; break; | |
723
55f6c2e454d7
Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
720
diff
changeset
|
2841 |
55f6c2e454d7
Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
720
diff
changeset
|
2842 // LDC |
55f6c2e454d7
Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
720
diff
changeset
|
2843 case LINKintrinsic: p = "Intrinsic"; break; |
55f6c2e454d7
Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
720
diff
changeset
|
2844 |
159 | 2845 default: |
2846 assert(0); | |
2847 } | |
2848 } | |
2849 | |
2850 if (!hgs->hdrgen && p) | |
2851 buf->writestring(p); | |
2852 if (ident) | |
2853 { buf->writeByte(' '); | |
2854 buf->writestring(ident->toHChars2()); | |
2855 } | |
2856 Argument::argsToCBuffer(buf, hgs, parameters, varargs); | |
2857 inuse--; | |
2858 } | |
2859 | |
2860 void TypeFunction::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod) | |
2861 { | |
2862 char *p = NULL; | |
2863 | |
2864 if (inuse) | |
2865 { inuse = 2; // flag error to caller | |
2866 return; | |
2867 } | |
2868 inuse++; | |
2869 if (next) | |
2870 next->toCBuffer2(buf, hgs, 0); | |
2871 if (hgs->ddoc != 1) | |
2872 { | |
2873 switch (linkage) | |
2874 { | |
2875 case LINKd: p = NULL; break; | |
2876 case LINKc: p = "C "; break; | |
2877 case LINKwindows: p = "Windows "; break; | |
2878 case LINKpascal: p = "Pascal "; break; | |
2879 case LINKcpp: p = "C++ "; break; | |
723
55f6c2e454d7
Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
720
diff
changeset
|
2880 |
55f6c2e454d7
Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
720
diff
changeset
|
2881 // LDC |
55f6c2e454d7
Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
720
diff
changeset
|
2882 case LINKintrinsic: p = "Intrinsic"; break; |
55f6c2e454d7
Implemented correct parameter order according to x86-32 ABI documentation.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
720
diff
changeset
|
2883 |
159 | 2884 default: |
2885 assert(0); | |
2886 } | |
2887 } | |
2888 | |
2889 if (!hgs->hdrgen && p) | |
2890 buf->writestring(p); | |
2891 buf->writestring(" function"); | |
2892 Argument::argsToCBuffer(buf, hgs, parameters, varargs); | |
2893 inuse--; | |
2894 } | |
2895 | |
2896 Type *TypeFunction::semantic(Loc loc, Scope *sc) | |
2897 { | |
2898 if (deco) // if semantic() already run | |
2899 { | |
2900 //printf("already done\n"); | |
2901 return this; | |
2902 } | |
2903 //printf("TypeFunction::semantic() this = %p\n", this); | |
2904 | |
2905 TypeFunction *tf = (TypeFunction *)mem.malloc(sizeof(TypeFunction)); | |
2906 memcpy(tf, this, sizeof(TypeFunction)); | |
2907 if (parameters) | |
2908 { tf->parameters = (Arguments *)parameters->copy(); | |
2909 for (size_t i = 0; i < parameters->dim; i++) | |
2910 { Argument *arg = (Argument *)parameters->data[i]; | |
2911 Argument *cpy = (Argument *)mem.malloc(sizeof(Argument)); | |
2912 memcpy(cpy, arg, sizeof(Argument)); | |
2913 tf->parameters->data[i] = (void *)cpy; | |
2914 } | |
2915 } | |
2916 | |
2917 tf->linkage = sc->linkage; | |
2918 if (!tf->next) | |
2919 { | |
2920 assert(global.errors); | |
2921 tf->next = tvoid; | |
2922 } | |
2923 tf->next = tf->next->semantic(loc,sc); | |
2924 if (tf->next->toBasetype()->ty == Tsarray) | |
2925 { error(loc, "functions cannot return static array %s", tf->next->toChars()); | |
2926 tf->next = Type::terror; | |
2927 } | |
2928 if (tf->next->toBasetype()->ty == Tfunction) | |
2929 { error(loc, "functions cannot return a function"); | |
2930 tf->next = Type::terror; | |
2931 } | |
2932 if (tf->next->toBasetype()->ty == Ttuple) | |
2933 { error(loc, "functions cannot return a tuple"); | |
2934 tf->next = Type::terror; | |
2935 } | |
2936 if (tf->next->isauto() && !(sc->flags & SCOPEctor)) | |
2937 error(loc, "functions cannot return auto %s", tf->next->toChars()); | |
2938 | |
2939 if (tf->parameters) | |
2940 { size_t dim = Argument::dim(tf->parameters); | |
2941 | |
2942 for (size_t i = 0; i < dim; i++) | |
2943 { Argument *arg = Argument::getNth(tf->parameters, i); | |
2944 Type *t; | |
2945 | |
2946 tf->inuse++; | |
2947 arg->type = arg->type->semantic(loc,sc); | |
2948 if (tf->inuse == 1) tf->inuse--; | |
780
2cf440d511bb
Move tuple syntax copy for function arguments after semantic, to make sure
Christian Kamm <kamm incasoftware de>
parents:
772
diff
changeset
|
2949 |
2cf440d511bb
Move tuple syntax copy for function arguments after semantic, to make sure
Christian Kamm <kamm incasoftware de>
parents:
772
diff
changeset
|
2950 // each function needs its own copy of a tuple arg, since |
2cf440d511bb
Move tuple syntax copy for function arguments after semantic, to make sure
Christian Kamm <kamm incasoftware de>
parents:
772
diff
changeset
|
2951 // they mustn't share arg flags like inreg, ... |
2cf440d511bb
Move tuple syntax copy for function arguments after semantic, to make sure
Christian Kamm <kamm incasoftware de>
parents:
772
diff
changeset
|
2952 if (arg->type->ty == Ttuple) { |
2cf440d511bb
Move tuple syntax copy for function arguments after semantic, to make sure
Christian Kamm <kamm incasoftware de>
parents:
772
diff
changeset
|
2953 arg->type = arg->type->syntaxCopy(); |
2cf440d511bb
Move tuple syntax copy for function arguments after semantic, to make sure
Christian Kamm <kamm incasoftware de>
parents:
772
diff
changeset
|
2954 tf->inuse++; |
2cf440d511bb
Move tuple syntax copy for function arguments after semantic, to make sure
Christian Kamm <kamm incasoftware de>
parents:
772
diff
changeset
|
2955 arg->type = arg->type->semantic(loc,sc); |
2cf440d511bb
Move tuple syntax copy for function arguments after semantic, to make sure
Christian Kamm <kamm incasoftware de>
parents:
772
diff
changeset
|
2956 if (tf->inuse == 1) tf->inuse--; |
2cf440d511bb
Move tuple syntax copy for function arguments after semantic, to make sure
Christian Kamm <kamm incasoftware de>
parents:
772
diff
changeset
|
2957 } |
2cf440d511bb
Move tuple syntax copy for function arguments after semantic, to make sure
Christian Kamm <kamm incasoftware de>
parents:
772
diff
changeset
|
2958 |
159 | 2959 t = arg->type->toBasetype(); |
2960 | |
2961 if (arg->storageClass & (STCout | STCref | STClazy)) | |
2962 { | |
2963 if (t->ty == Tsarray) | |
2964 error(loc, "cannot have out or ref parameter of type %s", t->toChars()); | |
2965 } | |
2966 if (!(arg->storageClass & STClazy) && t->ty == Tvoid) | |
2967 error(loc, "cannot have parameter of type %s", arg->type->toChars()); | |
2968 | |
2969 if (arg->defaultArg) | |
2970 { | |
2971 arg->defaultArg = arg->defaultArg->semantic(sc); | |
2972 arg->defaultArg = resolveProperties(sc, arg->defaultArg); | |
2973 arg->defaultArg = arg->defaultArg->implicitCastTo(sc, arg->type); | |
2974 } | |
2975 | |
2976 /* If arg turns out to be a tuple, the number of parameters may | |
2977 * change. | |
2978 */ | |
2979 if (t->ty == Ttuple) | |
2980 { dim = Argument::dim(tf->parameters); | |
2981 i--; | |
2982 } | |
2983 } | |
2984 } | |
2985 tf->deco = tf->merge()->deco; | |
2986 | |
2987 if (tf->inuse) | |
2988 { error(loc, "recursive type"); | |
2989 tf->inuse = 0; | |
2990 return terror; | |
2991 } | |
2992 | |
2993 if (tf->varargs == 1 && tf->linkage != LINKd && Argument::dim(tf->parameters) == 0) | |
2994 error(loc, "variadic functions with non-D linkage must have at least one parameter"); | |
2995 | |
2996 /* Don't return merge(), because arg identifiers and default args | |
2997 * can be different | |
2998 * even though the types match | |
2999 */ | |
3000 return tf; | |
3001 } | |
3002 | |
3003 /******************************** | |
3004 * 'args' are being matched to function 'this' | |
3005 * Determine match level. | |
3006 * Returns: | |
3007 * MATCHxxxx | |
3008 */ | |
3009 | |
3010 int TypeFunction::callMatch(Expressions *args) | |
3011 { | |
3012 //printf("TypeFunction::callMatch()\n"); | |
3013 int match = MATCHexact; // assume exact match | |
3014 | |
3015 size_t nparams = Argument::dim(parameters); | |
3016 size_t nargs = args ? args->dim : 0; | |
3017 if (nparams == nargs) | |
3018 ; | |
3019 else if (nargs > nparams) | |
3020 { | |
3021 if (varargs == 0) | |
3022 goto Nomatch; // too many args; no match | |
3023 match = MATCHconvert; // match ... with a "conversion" match level | |
3024 } | |
3025 | |
3026 for (size_t u = 0; u < nparams; u++) | |
3027 { int m; | |
3028 Expression *arg; | |
3029 | |
3030 // BUG: what about out and ref? | |
3031 | |
3032 Argument *p = Argument::getNth(parameters, u); | |
3033 assert(p); | |
3034 if (u >= nargs) | |
3035 { | |
3036 if (p->defaultArg) | |
3037 continue; | |
3038 if (varargs == 2 && u + 1 == nparams) | |
3039 goto L1; | |
3040 goto Nomatch; // not enough arguments | |
3041 } | |
3042 arg = (Expression *)args->data[u]; | |
3043 assert(arg); | |
3044 if (p->storageClass & STClazy && p->type->ty == Tvoid && arg->type->ty != Tvoid) | |
3045 m = MATCHconvert; | |
3046 else | |
3047 m = arg->implicitConvTo(p->type); | |
3048 //printf("\tm = %d\n", m); | |
3049 if (m == MATCHnomatch) // if no match | |
3050 { | |
3051 L1: | |
3052 if (varargs == 2 && u + 1 == nparams) // if last varargs param | |
3053 { Type *tb = p->type->toBasetype(); | |
3054 TypeSArray *tsa; | |
3055 integer_t sz; | |
3056 | |
3057 switch (tb->ty) | |
3058 { | |
3059 case Tsarray: | |
3060 tsa = (TypeSArray *)tb; | |
3061 sz = tsa->dim->toInteger(); | |
3062 if (sz != nargs - u) | |
3063 goto Nomatch; | |
3064 case Tarray: | |
3065 for (; u < nargs; u++) | |
3066 { | |
3067 arg = (Expression *)args->data[u]; | |
3068 assert(arg); | |
3069 #if 1 | |
3070 /* If lazy array of delegates, | |
3071 * convert arg(s) to delegate(s) | |
3072 */ | |
3073 Type *tret = p->isLazyArray(); | |
3074 if (tret) | |
3075 { | |
3076 if (tb->next->equals(arg->type)) | |
3077 { m = MATCHexact; | |
3078 } | |
3079 else | |
3080 { | |
3081 m = arg->implicitConvTo(tret); | |
3082 if (m == MATCHnomatch) | |
3083 { | |
3084 if (tret->toBasetype()->ty == Tvoid) | |
3085 m = MATCHconvert; | |
3086 } | |
3087 } | |
3088 } | |
3089 else | |
3090 m = arg->implicitConvTo(tb->next); | |
3091 #else | |
3092 m = arg->implicitConvTo(tb->next); | |
3093 #endif | |
3094 if (m == 0) | |
3095 goto Nomatch; | |
3096 if (m < match) | |
3097 match = m; | |
3098 } | |
3099 goto Ldone; | |
3100 | |
3101 case Tclass: | |
3102 // Should see if there's a constructor match? | |
3103 // Or just leave it ambiguous? | |
3104 goto Ldone; | |
3105 | |
3106 default: | |
3107 goto Nomatch; | |
3108 } | |
3109 } | |
3110 goto Nomatch; | |
3111 } | |
3112 if (m < match) | |
3113 match = m; // pick worst match | |
3114 } | |
3115 | |
3116 Ldone: | |
3117 //printf("match = %d\n", match); | |
3118 return match; | |
3119 | |
3120 Nomatch: | |
3121 //printf("no match\n"); | |
3122 return MATCHnomatch; | |
3123 } | |
3124 | |
3125 Type *TypeFunction::reliesOnTident() | |
3126 { | |
3127 if (parameters) | |
3128 { | |
3129 for (size_t i = 0; i < parameters->dim; i++) | |
3130 { Argument *arg = (Argument *)parameters->data[i]; | |
3131 Type *t = arg->type->reliesOnTident(); | |
3132 if (t) | |
3133 return t; | |
3134 } | |
3135 } | |
3136 return next->reliesOnTident(); | |
3137 } | |
3138 | |
3139 /***************************** TypeDelegate *****************************/ | |
3140 | |
3141 TypeDelegate::TypeDelegate(Type *t) | |
3142 : Type(Tfunction, t) | |
3143 { | |
3144 ty = Tdelegate; | |
3145 } | |
3146 | |
3147 Type *TypeDelegate::syntaxCopy() | |
3148 { | |
3149 Type *t = next->syntaxCopy(); | |
3150 if (t == next) | |
3151 t = this; | |
3152 else | |
3153 t = new TypeDelegate(t); | |
3154 return t; | |
3155 } | |
3156 | |
3157 Type *TypeDelegate::semantic(Loc loc, Scope *sc) | |
3158 { | |
3159 if (deco) // if semantic() already run | |
3160 { | |
3161 //printf("already done\n"); | |
3162 return this; | |
3163 } | |
3164 next = next->semantic(loc,sc); | |
3165 return merge(); | |
3166 } | |
3167 | |
3168 d_uns64 TypeDelegate::size(Loc loc) | |
3169 { | |
3170 return PTRSIZE * 2; | |
3171 } | |
3172 | |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
780
diff
changeset
|
3173 // LDC added, no reason to align to 2*PTRSIZE |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
780
diff
changeset
|
3174 unsigned TypeDelegate::alignsize() |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
780
diff
changeset
|
3175 { |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
780
diff
changeset
|
3176 // A Delegate consists of two ptr values, so align it on pointer size |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
780
diff
changeset
|
3177 // boundary |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
780
diff
changeset
|
3178 return PTRSIZE; |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
780
diff
changeset
|
3179 } |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
780
diff
changeset
|
3180 |
159 | 3181 void TypeDelegate::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod) |
3182 { | |
3183 if (mod != this->mod) | |
3184 { toCBuffer3(buf, hgs, mod); | |
3185 return; | |
3186 } | |
3187 TypeFunction *tf = (TypeFunction *)next; | |
3188 | |
3189 tf->next->toCBuffer2(buf, hgs, 0); | |
3190 buf->writestring(" delegate"); | |
3191 Argument::argsToCBuffer(buf, hgs, tf->parameters, tf->varargs); | |
3192 } | |
3193 | |
3194 Expression *TypeDelegate::defaultInit(Loc loc) | |
3195 { | |
3196 #if LOGDEFAULTINIT | |
3197 printf("TypeDelegate::defaultInit() '%s'\n", toChars()); | |
3198 #endif | |
3199 Expression *e; | |
3200 e = new NullExp(loc); | |
3201 e->type = this; | |
3202 return e; | |
3203 } | |
3204 | |
3205 int TypeDelegate::isZeroInit() | |
3206 { | |
3207 return 1; | |
3208 } | |
3209 | |
3210 int TypeDelegate::checkBoolean() | |
3211 { | |
3212 return TRUE; | |
3213 } | |
3214 | |
3215 Expression *TypeDelegate::dotExp(Scope *sc, Expression *e, Identifier *ident) | |
3216 { | |
3217 #if LOGDOTEXP | |
3218 printf("TypeDelegate::dotExp(e = '%s', ident = '%s')\n", e->toChars(), ident->toChars()); | |
3219 #endif | |
3220 if (ident == Id::ptr) | |
3221 { | |
599
4435f57956e7
Fixed .funcptr property of delegates, no longer uses the infamous DMD rewrites to pointer arithmetic, instead a GEPExp has been introduced.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
591
diff
changeset
|
3222 e = new GEPExp(e->loc, e, ident, 0); |
159 | 3223 e->type = tvoidptr; |
3224 return e; | |
3225 } | |
3226 else if (ident == Id::funcptr) | |
3227 { | |
599
4435f57956e7
Fixed .funcptr property of delegates, no longer uses the infamous DMD rewrites to pointer arithmetic, instead a GEPExp has been introduced.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
591
diff
changeset
|
3228 e = new GEPExp(e->loc, e, ident, 1); |
4435f57956e7
Fixed .funcptr property of delegates, no longer uses the infamous DMD rewrites to pointer arithmetic, instead a GEPExp has been introduced.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
591
diff
changeset
|
3229 e->type = tvoidptr; |
159 | 3230 return e; |
3231 } | |
3232 else | |
3233 { | |
3234 e = Type::dotExp(sc, e, ident); | |
3235 } | |
3236 return e; | |
3237 } | |
3238 | |
3239 int TypeDelegate::hasPointers() | |
3240 { | |
3241 return TRUE; | |
3242 } | |
3243 | |
3244 | |
3245 | |
3246 /***************************** TypeQualified *****************************/ | |
3247 | |
3248 TypeQualified::TypeQualified(TY ty, Loc loc) | |
3249 : Type(ty, NULL) | |
3250 { | |
3251 this->loc = loc; | |
3252 } | |
3253 | |
3254 void TypeQualified::syntaxCopyHelper(TypeQualified *t) | |
3255 { | |
3256 //printf("TypeQualified::syntaxCopyHelper(%s) %s\n", t->toChars(), toChars()); | |
3257 idents.setDim(t->idents.dim); | |
3258 for (int i = 0; i < idents.dim; i++) | |
3259 { | |
3260 Identifier *id = (Identifier *)t->idents.data[i]; | |
3261 if (id->dyncast() == DYNCAST_DSYMBOL) | |
3262 { | |
3263 TemplateInstance *ti = (TemplateInstance *)id; | |
3264 | |
3265 ti = (TemplateInstance *)ti->syntaxCopy(NULL); | |
3266 id = (Identifier *)ti; | |
3267 } | |
3268 idents.data[i] = id; | |
3269 } | |
3270 } | |
3271 | |
3272 | |
3273 void TypeQualified::addIdent(Identifier *ident) | |
3274 { | |
3275 idents.push(ident); | |
3276 } | |
3277 | |
3278 void TypeQualified::toCBuffer2Helper(OutBuffer *buf, HdrGenState *hgs) | |
3279 { | |
3280 int i; | |
3281 | |
3282 for (i = 0; i < idents.dim; i++) | |
3283 { Identifier *id = (Identifier *)idents.data[i]; | |
3284 | |
3285 buf->writeByte('.'); | |
3286 | |
3287 if (id->dyncast() == DYNCAST_DSYMBOL) | |
3288 { | |
3289 TemplateInstance *ti = (TemplateInstance *)id; | |
3290 ti->toCBuffer(buf, hgs); | |
3291 } | |
3292 else | |
3293 buf->writestring(id->toChars()); | |
3294 } | |
3295 } | |
3296 | |
3297 d_uns64 TypeQualified::size(Loc loc) | |
3298 { | |
3299 error(this->loc, "size of type %s is not known", toChars()); | |
3300 return 1; | |
3301 } | |
3302 | |
3303 /************************************* | |
3304 * Takes an array of Identifiers and figures out if | |
3305 * it represents a Type or an Expression. | |
3306 * Output: | |
3307 * if expression, *pe is set | |
3308 * if type, *pt is set | |
3309 */ | |
3310 | |
3311 void TypeQualified::resolveHelper(Loc loc, Scope *sc, | |
3312 Dsymbol *s, Dsymbol *scopesym, | |
3313 Expression **pe, Type **pt, Dsymbol **ps) | |
3314 { | |
3315 Identifier *id = NULL; | |
3316 int i; | |
3317 VarDeclaration *v; | |
3318 EnumMember *em; | |
3319 TupleDeclaration *td; | |
3320 Type *t; | |
3321 Expression *e; | |
3322 | |
3323 #if 0 | |
3324 printf("TypeQualified::resolveHelper(sc = %p, idents = '%s')\n", sc, toChars()); | |
3325 if (scopesym) | |
3326 printf("\tscopesym = '%s'\n", scopesym->toChars()); | |
3327 #endif | |
3328 *pe = NULL; | |
3329 *pt = NULL; | |
3330 *ps = NULL; | |
3331 if (s) | |
3332 { | |
3333 //printf("\t1: s = '%s' %p, kind = '%s'\n",s->toChars(), s, s->kind()); | |
336 | 3334 s->checkDeprecated(loc, sc); // check for deprecated aliases |
159 | 3335 s = s->toAlias(); |
3336 //printf("\t2: s = '%s' %p, kind = '%s'\n",s->toChars(), s, s->kind()); | |
3337 for (i = 0; i < idents.dim; i++) | |
3338 { Dsymbol *sm; | |
3339 | |
3340 id = (Identifier *)idents.data[i]; | |
3341 sm = s->searchX(loc, sc, id); | |
3342 //printf("\t3: s = '%s' %p, kind = '%s'\n",s->toChars(), s, s->kind()); | |
3343 //printf("getType = '%s'\n", s->getType()->toChars()); | |
3344 if (!sm) | |
3345 { | |
3346 v = s->isVarDeclaration(); | |
3347 if (v && id == Id::length) | |
3348 { | |
3349 if (v->isConst() && v->getExpInitializer()) | |
3350 { e = v->getExpInitializer()->exp; | |
3351 } | |
3352 else | |
3353 e = new VarExp(loc, v); | |
3354 t = e->type; | |
3355 if (!t) | |
3356 goto Lerror; | |
3357 goto L3; | |
3358 } | |
3359 t = s->getType(); | |
3360 if (!t && s->isDeclaration()) | |
3361 t = s->isDeclaration()->type; | |
3362 if (t) | |
3363 { | |
3364 sm = t->toDsymbol(sc); | |
3365 if (sm) | |
3366 { sm = sm->search(loc, id, 0); | |
3367 if (sm) | |
3368 goto L2; | |
3369 } | |
3370 //e = t->getProperty(loc, id); | |
3371 e = new TypeExp(loc, t); | |
3372 e = t->dotExp(sc, e, id); | |
3373 i++; | |
3374 L3: | |
3375 for (; i < idents.dim; i++) | |
3376 { | |
3377 id = (Identifier *)idents.data[i]; | |
3378 //printf("e: '%s', id: '%s', type = %p\n", e->toChars(), id->toChars(), e->type); | |
3379 e = e->type->dotExp(sc, e, id); | |
3380 } | |
3381 *pe = e; | |
3382 } | |
3383 else | |
3384 Lerror: | |
3385 error(loc, "identifier '%s' of '%s' is not defined", id->toChars(), toChars()); | |
3386 return; | |
3387 } | |
3388 L2: | |
3389 s = sm->toAlias(); | |
3390 } | |
3391 | |
3392 v = s->isVarDeclaration(); | |
3393 if (v) | |
3394 { | |
3395 // It's not a type, it's an expression | |
3396 if (v->isConst() && v->getExpInitializer()) | |
3397 { | |
3398 ExpInitializer *ei = v->getExpInitializer(); | |
3399 assert(ei); | |
3400 *pe = ei->exp->copy(); // make copy so we can change loc | |
3401 (*pe)->loc = loc; | |
3402 } | |
3403 else | |
3404 { | |
3405 #if 0 | |
3406 WithScopeSymbol *withsym; | |
3407 if (scopesym && (withsym = scopesym->isWithScopeSymbol()) != NULL) | |
3408 { | |
3409 // Same as wthis.ident | |
3410 e = new VarExp(loc, withsym->withstate->wthis); | |
3411 e = new DotIdExp(loc, e, ident); | |
3412 //assert(0); // BUG: should handle this | |
3413 } | |
3414 else | |
3415 #endif | |
3416 *pe = new VarExp(loc, v); | |
3417 } | |
3418 return; | |
3419 } | |
3420 em = s->isEnumMember(); | |
3421 if (em) | |
3422 { | |
3423 // It's not a type, it's an expression | |
3424 *pe = em->value->copy(); | |
3425 return; | |
3426 } | |
3427 | |
3428 L1: | |
3429 t = s->getType(); | |
3430 if (!t) | |
3431 { | |
3432 // If the symbol is an import, try looking inside the import | |
3433 Import *si; | |
3434 | |
3435 si = s->isImport(); | |
3436 if (si) | |
3437 { | |
3438 s = si->search(loc, s->ident, 0); | |
3439 if (s && s != si) | |
3440 goto L1; | |
3441 s = si; | |
3442 } | |
3443 *ps = s; | |
3444 return; | |
3445 } | |
3446 if (t->ty == Tinstance && t != this && !t->deco) | |
3447 { error(loc, "forward reference to '%s'", t->toChars()); | |
3448 return; | |
3449 } | |
3450 | |
3451 if (t != this) | |
3452 { | |
3453 if (t->reliesOnTident()) | |
3454 { | |
3455 Scope *scx; | |
3456 | |
3457 for (scx = sc; 1; scx = scx->enclosing) | |
3458 { | |
3459 if (!scx) | |
3460 { error(loc, "forward reference to '%s'", t->toChars()); | |
3461 return; | |
3462 } | |
3463 if (scx->scopesym == scopesym) | |
3464 break; | |
3465 } | |
3466 t = t->semantic(loc, scx); | |
3467 //((TypeIdentifier *)t)->resolve(loc, scx, pe, &t, ps); | |
3468 } | |
3469 } | |
3470 if (t->ty == Ttuple) | |
772
cd7da2ba14d1
Fix bug reported by downs. Related to delegate types within tuple template parameters.
Christian Kamm <kamm incasoftware de>
parents:
771
diff
changeset
|
3471 *pt = t; |
159 | 3472 else |
3473 *pt = t->merge(); | |
3474 } | |
3475 if (!s) | |
3476 { | |
3477 error(loc, "identifier '%s' is not defined", toChars()); | |
3478 } | |
3479 } | |
3480 | |
3481 /***************************** TypeIdentifier *****************************/ | |
3482 | |
3483 TypeIdentifier::TypeIdentifier(Loc loc, Identifier *ident) | |
3484 : TypeQualified(Tident, loc) | |
3485 { | |
3486 this->ident = ident; | |
3487 } | |
3488 | |
3489 | |
3490 Type *TypeIdentifier::syntaxCopy() | |
3491 { | |
3492 TypeIdentifier *t; | |
3493 | |
3494 t = new TypeIdentifier(loc, ident); | |
3495 t->syntaxCopyHelper(this); | |
3496 return t; | |
3497 } | |
3498 | |
3499 void TypeIdentifier::toDecoBuffer(OutBuffer *buf) | |
3500 { unsigned len; | |
3501 char *name; | |
3502 | |
3503 name = ident->toChars(); | |
3504 len = strlen(name); | |
3505 buf->printf("%c%d%s", mangleChar[ty], len, name); | |
3506 //buf->printf("%c%s", mangleChar[ty], name); | |
3507 } | |
3508 | |
3509 void TypeIdentifier::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod) | |
3510 { | |
3511 if (mod != this->mod) | |
3512 { toCBuffer3(buf, hgs, mod); | |
3513 return; | |
3514 } | |
3515 buf->writestring(this->ident->toChars()); | |
3516 toCBuffer2Helper(buf, hgs); | |
3517 } | |
3518 | |
3519 /************************************* | |
3520 * Takes an array of Identifiers and figures out if | |
3521 * it represents a Type or an Expression. | |
3522 * Output: | |
3523 * if expression, *pe is set | |
3524 * if type, *pt is set | |
3525 */ | |
3526 | |
3527 void TypeIdentifier::resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymbol **ps) | |
3528 { Dsymbol *s; | |
3529 Dsymbol *scopesym; | |
3530 | |
3531 //printf("TypeIdentifier::resolve(sc = %p, idents = '%s')\n", sc, toChars()); | |
3532 s = sc->search(loc, ident, &scopesym); | |
3533 resolveHelper(loc, sc, s, scopesym, pe, pt, ps); | |
3534 } | |
3535 | |
3536 /***************************************** | |
3537 * See if type resolves to a symbol, if so, | |
3538 * return that symbol. | |
3539 */ | |
3540 | |
3541 Dsymbol *TypeIdentifier::toDsymbol(Scope *sc) | |
3542 { | |
3543 //printf("TypeIdentifier::toDsymbol('%s')\n", toChars()); | |
3544 if (!sc) | |
3545 return NULL; | |
3546 //printf("ident = '%s'\n", ident->toChars()); | |
3547 | |
3548 Dsymbol *scopesym; | |
3549 Dsymbol *s = sc->search(loc, ident, &scopesym); | |
3550 if (s) | |
3551 { | |
3552 for (int i = 0; i < idents.dim; i++) | |
3553 { | |
3554 Identifier *id = (Identifier *)idents.data[i]; | |
3555 s = s->searchX(loc, sc, id); | |
3556 if (!s) // failed to find a symbol | |
3557 { //printf("\tdidn't find a symbol\n"); | |
3558 break; | |
3559 } | |
3560 } | |
3561 } | |
3562 return s; | |
3563 } | |
3564 | |
3565 Type *TypeIdentifier::semantic(Loc loc, Scope *sc) | |
3566 { | |
3567 Type *t; | |
3568 Expression *e; | |
3569 Dsymbol *s; | |
3570 | |
3571 //printf("TypeIdentifier::semantic(%s)\n", toChars()); | |
3572 resolve(loc, sc, &e, &t, &s); | |
3573 if (t) | |
3574 { | |
3575 //printf("\tit's a type %d, %s, %s\n", t->ty, t->toChars(), t->deco); | |
3576 | |
3577 if (t->ty == Ttypedef) | |
3578 { TypeTypedef *tt = (TypeTypedef *)t; | |
3579 | |
3580 if (tt->sym->sem == 1) | |
3581 error(loc, "circular reference of typedef %s", tt->toChars()); | |
3582 } | |
3583 } | |
3584 else | |
3585 { | |
3586 #ifdef DEBUG | |
3587 if (!global.gag) | |
3588 printf("1: "); | |
3589 #endif | |
3590 if (s) | |
3591 { | |
3592 s->error(loc, "is used as a type"); | |
3593 } | |
3594 else | |
3595 error(loc, "%s is used as a type", toChars()); | |
3596 t = tvoid; | |
3597 } | |
3598 //t->print(); | |
3599 return t; | |
3600 } | |
3601 | |
3602 Type *TypeIdentifier::reliesOnTident() | |
3603 { | |
3604 return this; | |
3605 } | |
3606 | |
3607 Expression *TypeIdentifier::toExpression() | |
3608 { | |
3609 Expression *e = new IdentifierExp(loc, ident); | |
3610 for (int i = 0; i < idents.dim; i++) | |
3611 { | |
3612 Identifier *id = (Identifier *)idents.data[i]; | |
3613 e = new DotIdExp(loc, e, id); | |
3614 } | |
3615 | |
3616 return e; | |
3617 } | |
3618 | |
3619 /***************************** TypeInstance *****************************/ | |
3620 | |
3621 TypeInstance::TypeInstance(Loc loc, TemplateInstance *tempinst) | |
3622 : TypeQualified(Tinstance, loc) | |
3623 { | |
3624 this->tempinst = tempinst; | |
3625 } | |
3626 | |
3627 Type *TypeInstance::syntaxCopy() | |
3628 { | |
3629 //printf("TypeInstance::syntaxCopy() %s, %d\n", toChars(), idents.dim); | |
3630 TypeInstance *t; | |
3631 | |
3632 t = new TypeInstance(loc, (TemplateInstance *)tempinst->syntaxCopy(NULL)); | |
3633 t->syntaxCopyHelper(this); | |
3634 return t; | |
3635 } | |
3636 | |
3637 | |
3638 void TypeInstance::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod) | |
3639 { | |
3640 if (mod != this->mod) | |
3641 { toCBuffer3(buf, hgs, mod); | |
3642 return; | |
3643 } | |
3644 tempinst->toCBuffer(buf, hgs); | |
3645 toCBuffer2Helper(buf, hgs); | |
3646 } | |
3647 | |
3648 void TypeInstance::resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymbol **ps) | |
3649 { | |
3650 // Note close similarity to TypeIdentifier::resolve() | |
3651 | |
3652 Dsymbol *s; | |
3653 | |
3654 *pe = NULL; | |
3655 *pt = NULL; | |
3656 *ps = NULL; | |
3657 | |
3658 #if 0 | |
3659 if (!idents.dim) | |
3660 { | |
3661 error(loc, "template instance '%s' has no identifier", toChars()); | |
3662 return; | |
3663 } | |
3664 #endif | |
3665 //id = (Identifier *)idents.data[0]; | |
3666 //printf("TypeInstance::resolve(sc = %p, idents = '%s')\n", sc, id->toChars()); | |
3667 s = tempinst; | |
3668 if (s) | |
3669 s->semantic(sc); | |
3670 resolveHelper(loc, sc, s, NULL, pe, pt, ps); | |
3671 //printf("pt = '%s'\n", (*pt)->toChars()); | |
3672 } | |
3673 | |
3674 Type *TypeInstance::semantic(Loc loc, Scope *sc) | |
3675 { | |
3676 Type *t; | |
3677 Expression *e; | |
3678 Dsymbol *s; | |
3679 | |
3680 //printf("TypeInstance::semantic(%s)\n", toChars()); | |
3681 | |
3682 if (sc->parameterSpecialization) | |
3683 { | |
3684 unsigned errors = global.errors; | |
3685 global.gag++; | |
3686 | |
3687 resolve(loc, sc, &e, &t, &s); | |
3688 | |
3689 global.gag--; | |
3690 if (errors != global.errors) | |
3691 { if (global.gag == 0) | |
3692 global.errors = errors; | |
3693 return this; | |
3694 } | |
3695 } | |
3696 else | |
3697 resolve(loc, sc, &e, &t, &s); | |
3698 | |
3699 if (!t) | |
3700 { | |
3701 #ifdef DEBUG | |
3702 printf("2: "); | |
3703 #endif | |
3704 error(loc, "%s is used as a type", toChars()); | |
3705 t = tvoid; | |
3706 } | |
3707 return t; | |
3708 } | |
3709 | |
875
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
3710 Dsymbol *TypeInstance::toDsymbol(Scope *sc) |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
3711 { |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
3712 Type *t; |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
3713 Expression *e; |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
3714 Dsymbol *s; |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
3715 |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
3716 //printf("TypeInstance::semantic(%s)\n", toChars()); |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
3717 |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
3718 if (sc->parameterSpecialization) |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
3719 { |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
3720 unsigned errors = global.errors; |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
3721 global.gag++; |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
3722 |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
3723 resolve(loc, sc, &e, &t, &s); |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
3724 |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
3725 global.gag--; |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
3726 if (errors != global.errors) |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
3727 { if (global.gag == 0) |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
3728 global.errors = errors; |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
3729 return NULL; |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
3730 } |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
3731 } |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
3732 else |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
3733 resolve(loc, sc, &e, &t, &s); |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
3734 |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
3735 return s; |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
3736 } |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
3737 |
159 | 3738 |
3739 /***************************** TypeTypeof *****************************/ | |
3740 | |
3741 TypeTypeof::TypeTypeof(Loc loc, Expression *exp) | |
3742 : TypeQualified(Ttypeof, loc) | |
3743 { | |
3744 this->exp = exp; | |
3745 } | |
3746 | |
3747 Type *TypeTypeof::syntaxCopy() | |
3748 { | |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
3749 //printf("TypeTypeof::syntaxCopy() %s\n", toChars()); |
159 | 3750 TypeTypeof *t; |
3751 | |
3752 t = new TypeTypeof(loc, exp->syntaxCopy()); | |
3753 t->syntaxCopyHelper(this); | |
3754 return t; | |
3755 } | |
3756 | |
3757 Dsymbol *TypeTypeof::toDsymbol(Scope *sc) | |
3758 { | |
3759 Type *t; | |
3760 | |
336 | 3761 t = semantic(loc, sc); |
159 | 3762 if (t == this) |
3763 return NULL; | |
3764 return t->toDsymbol(sc); | |
3765 } | |
3766 | |
3767 void TypeTypeof::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod) | |
3768 { | |
3769 if (mod != this->mod) | |
3770 { toCBuffer3(buf, hgs, mod); | |
3771 return; | |
3772 } | |
3773 buf->writestring("typeof("); | |
3774 exp->toCBuffer(buf, hgs); | |
3775 buf->writeByte(')'); | |
3776 toCBuffer2Helper(buf, hgs); | |
3777 } | |
3778 | |
3779 Type *TypeTypeof::semantic(Loc loc, Scope *sc) | |
3780 { Expression *e; | |
3781 Type *t; | |
3782 | |
3783 //printf("TypeTypeof::semantic() %p\n", this); | |
3784 | |
3785 //static int nest; if (++nest == 50) *(char*)0=0; | |
3786 | |
3787 #if 0 | |
3788 /* Special case for typeof(this) and typeof(super) since both | |
3789 * should work even if they are not inside a non-static member function | |
3790 */ | |
3791 if (exp->op == TOKthis || exp->op == TOKsuper) | |
3792 { | |
3793 // Find enclosing struct or class | |
3794 for (Dsymbol *s = sc->parent; 1; s = s->parent) | |
3795 { | |
3796 ClassDeclaration *cd; | |
3797 StructDeclaration *sd; | |
3798 | |
3799 if (!s) | |
3800 { | |
3801 error(loc, "%s is not in a struct or class scope", exp->toChars()); | |
3802 goto Lerr; | |
3803 } | |
3804 cd = s->isClassDeclaration(); | |
3805 if (cd) | |
3806 { | |
3807 if (exp->op == TOKsuper) | |
3808 { | |
3809 cd = cd->baseClass; | |
3810 if (!cd) | |
3811 { error(loc, "class %s has no 'super'", s->toChars()); | |
3812 goto Lerr; | |
3813 } | |
3814 } | |
3815 t = cd->type; | |
3816 break; | |
3817 } | |
3818 sd = s->isStructDeclaration(); | |
3819 if (sd) | |
3820 { | |
3821 if (exp->op == TOKsuper) | |
3822 { | |
3823 error(loc, "struct %s has no 'super'", sd->toChars()); | |
3824 goto Lerr; | |
3825 } | |
3826 t = sd->type->pointerTo(); | |
3827 break; | |
3828 } | |
3829 } | |
3830 } | |
3831 else | |
3832 #endif | |
3833 { | |
3834 sc->intypeof++; | |
3835 exp = exp->semantic(sc); | |
3836 sc->intypeof--; | |
336 | 3837 if (exp->op == TOKtype) |
3838 { | |
3839 error(loc, "argument %s to typeof is not an expression", exp->toChars()); | |
3840 } | |
159 | 3841 t = exp->type; |
3842 if (!t) | |
3843 { | |
3844 error(loc, "expression (%s) has no type", exp->toChars()); | |
3845 goto Lerr; | |
3846 } | |
3847 } | |
3848 | |
3849 if (idents.dim) | |
3850 { | |
3851 Dsymbol *s = t->toDsymbol(sc); | |
3852 for (size_t i = 0; i < idents.dim; i++) | |
3853 { | |
3854 if (!s) | |
3855 break; | |
3856 Identifier *id = (Identifier *)idents.data[i]; | |
3857 s = s->searchX(loc, sc, id); | |
3858 } | |
3859 if (s) | |
3860 { | |
3861 t = s->getType(); | |
3862 if (!t) | |
3863 { error(loc, "%s is not a type", s->toChars()); | |
3864 goto Lerr; | |
3865 } | |
3866 } | |
3867 else | |
3868 { error(loc, "cannot resolve .property for %s", toChars()); | |
3869 goto Lerr; | |
3870 } | |
3871 } | |
3872 return t; | |
3873 | |
3874 Lerr: | |
3875 return tvoid; | |
3876 } | |
3877 | |
3878 d_uns64 TypeTypeof::size(Loc loc) | |
3879 { | |
3880 if (exp->type) | |
3881 return exp->type->size(loc); | |
3882 else | |
3883 return TypeQualified::size(loc); | |
3884 } | |
3885 | |
3886 | |
3887 | |
3888 /***************************** TypeEnum *****************************/ | |
3889 | |
3890 TypeEnum::TypeEnum(EnumDeclaration *sym) | |
3891 : Type(Tenum, NULL) | |
3892 { | |
3893 this->sym = sym; | |
3894 } | |
3895 | |
3896 char *TypeEnum::toChars() | |
3897 { | |
3898 return sym->toChars(); | |
3899 } | |
3900 | |
486
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
445
diff
changeset
|
3901 Type *TypeEnum::syntaxCopy() |
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
445
diff
changeset
|
3902 { |
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
445
diff
changeset
|
3903 return this; |
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
445
diff
changeset
|
3904 } |
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
445
diff
changeset
|
3905 |
159 | 3906 Type *TypeEnum::semantic(Loc loc, Scope *sc) |
3907 { | |
3908 sym->semantic(sc); | |
3909 return merge(); | |
3910 } | |
3911 | |
3912 d_uns64 TypeEnum::size(Loc loc) | |
3913 { | |
3914 if (!sym->memtype) | |
3915 { | |
3916 error(loc, "enum %s is forward referenced", sym->toChars()); | |
3917 return 4; | |
3918 } | |
3919 return sym->memtype->size(loc); | |
3920 } | |
3921 | |
3922 unsigned TypeEnum::alignsize() | |
3923 { | |
3924 if (!sym->memtype) | |
3925 { | |
3926 #ifdef DEBUG | |
3927 printf("1: "); | |
3928 #endif | |
3929 error(0, "enum %s is forward referenced", sym->toChars()); | |
3930 return 4; | |
3931 } | |
3932 return sym->memtype->alignsize(); | |
3933 } | |
3934 | |
3935 Dsymbol *TypeEnum::toDsymbol(Scope *sc) | |
3936 { | |
3937 return sym; | |
3938 } | |
3939 | |
3940 Type *TypeEnum::toBasetype() | |
3941 { | |
3942 if (!sym->memtype) | |
3943 { | |
3944 #ifdef DEBUG | |
3945 printf("2: "); | |
3946 #endif | |
3947 error(sym->loc, "enum %s is forward referenced", sym->toChars()); | |
3948 return tint32; | |
3949 } | |
3950 return sym->memtype->toBasetype(); | |
3951 } | |
3952 | |
3953 void TypeEnum::toDecoBuffer(OutBuffer *buf) | |
3954 { char *name; | |
3955 | |
3956 name = sym->mangle(); | |
3957 // if (name[0] == '_' && name[1] == 'D') | |
3958 // name += 2; | |
3959 buf->printf("%c%s", mangleChar[ty], name); | |
3960 } | |
3961 | |
3962 void TypeEnum::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod) | |
3963 { | |
3964 if (mod != this->mod) | |
3965 { toCBuffer3(buf, hgs, mod); | |
3966 return; | |
3967 } | |
3968 buf->writestring(sym->toChars()); | |
3969 } | |
3970 | |
3971 Expression *TypeEnum::dotExp(Scope *sc, Expression *e, Identifier *ident) | |
3972 { | |
3973 EnumMember *m; | |
3974 Dsymbol *s; | |
3975 Expression *em; | |
3976 | |
3977 #if LOGDOTEXP | |
3978 printf("TypeEnum::dotExp(e = '%s', ident = '%s') '%s'\n", e->toChars(), ident->toChars(), toChars()); | |
3979 #endif | |
3980 if (!sym->symtab) | |
3981 goto Lfwd; | |
3982 s = sym->symtab->lookup(ident); | |
3983 if (!s) | |
3984 { | |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
3985 if (ident == Id::max || |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
3986 ident == Id::min || |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
3987 ident == Id::init || |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
3988 ident == Id::stringof || |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
3989 !sym->memtype |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
3990 ) |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
3991 { |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
3992 return getProperty(e->loc, ident); |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
3993 } |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
3994 return sym->memtype->dotExp(sc, e, ident); |
159 | 3995 } |
3996 m = s->isEnumMember(); | |
3997 em = m->value->copy(); | |
3998 em->loc = e->loc; | |
3999 return em; | |
4000 | |
4001 Lfwd: | |
4002 error(e->loc, "forward reference of %s.%s", toChars(), ident->toChars()); | |
4003 return new IntegerExp(0, 0, this); | |
4004 } | |
4005 | |
4006 Expression *TypeEnum::getProperty(Loc loc, Identifier *ident) | |
4007 { Expression *e; | |
4008 | |
4009 if (ident == Id::max) | |
4010 { | |
4011 if (!sym->symtab) | |
4012 goto Lfwd; | |
4013 e = new IntegerExp(0, sym->maxval, this); | |
4014 } | |
4015 else if (ident == Id::min) | |
4016 { | |
4017 if (!sym->symtab) | |
4018 goto Lfwd; | |
4019 e = new IntegerExp(0, sym->minval, this); | |
4020 } | |
4021 else if (ident == Id::init) | |
4022 { | |
4023 if (!sym->symtab) | |
4024 goto Lfwd; | |
4025 e = defaultInit(loc); | |
4026 } | |
846
bc982f1ad106
Merged DMD 1.037 frontend
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
822
diff
changeset
|
4027 else if (ident == Id::stringof) |
bc982f1ad106
Merged DMD 1.037 frontend
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
822
diff
changeset
|
4028 { char *s = toChars(); |
bc982f1ad106
Merged DMD 1.037 frontend
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
822
diff
changeset
|
4029 e = new StringExp(loc, s, strlen(s), 'c'); |
bc982f1ad106
Merged DMD 1.037 frontend
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
822
diff
changeset
|
4030 Scope sc; |
bc982f1ad106
Merged DMD 1.037 frontend
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
822
diff
changeset
|
4031 e = e->semantic(&sc); |
bc982f1ad106
Merged DMD 1.037 frontend
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
822
diff
changeset
|
4032 } |
159 | 4033 else |
4034 { | |
4035 if (!sym->memtype) | |
4036 goto Lfwd; | |
4037 e = sym->memtype->getProperty(loc, ident); | |
4038 } | |
4039 return e; | |
4040 | |
4041 Lfwd: | |
4042 error(loc, "forward reference of %s.%s", toChars(), ident->toChars()); | |
4043 return new IntegerExp(0, 0, this); | |
4044 } | |
4045 | |
4046 int TypeEnum::isintegral() | |
4047 { | |
4048 return 1; | |
4049 } | |
4050 | |
4051 int TypeEnum::isfloating() | |
4052 { | |
4053 return 0; | |
4054 } | |
4055 | |
4056 int TypeEnum::isunsigned() | |
4057 { | |
4058 return sym->memtype->isunsigned(); | |
4059 } | |
4060 | |
4061 int TypeEnum::isscalar() | |
4062 { | |
4063 return 1; | |
4064 //return sym->memtype->isscalar(); | |
4065 } | |
4066 | |
4067 MATCH TypeEnum::implicitConvTo(Type *to) | |
4068 { MATCH m; | |
4069 | |
4070 //printf("TypeEnum::implicitConvTo()\n"); | |
4071 if (this->equals(to)) | |
4072 m = MATCHexact; // exact match | |
4073 else if (sym->memtype->implicitConvTo(to)) | |
4074 m = MATCHconvert; // match with conversions | |
4075 else | |
4076 m = MATCHnomatch; // no match | |
4077 return m; | |
4078 } | |
4079 | |
4080 Expression *TypeEnum::defaultInit(Loc loc) | |
4081 { | |
4082 #if LOGDEFAULTINIT | |
4083 printf("TypeEnum::defaultInit() '%s'\n", toChars()); | |
4084 #endif | |
4085 // Initialize to first member of enum | |
4086 Expression *e; | |
4087 e = new IntegerExp(loc, sym->defaultval, this); | |
4088 return e; | |
4089 } | |
4090 | |
4091 int TypeEnum::isZeroInit() | |
4092 { | |
4093 return (sym->defaultval == 0); | |
4094 } | |
4095 | |
4096 int TypeEnum::hasPointers() | |
4097 { | |
4098 return toBasetype()->hasPointers(); | |
4099 } | |
4100 | |
4101 /***************************** TypeTypedef *****************************/ | |
4102 | |
4103 TypeTypedef::TypeTypedef(TypedefDeclaration *sym) | |
4104 : Type(Ttypedef, NULL) | |
4105 { | |
4106 this->sym = sym; | |
4107 } | |
4108 | |
4109 Type *TypeTypedef::syntaxCopy() | |
4110 { | |
4111 return this; | |
4112 } | |
4113 | |
4114 char *TypeTypedef::toChars() | |
4115 { | |
4116 return sym->toChars(); | |
4117 } | |
4118 | |
4119 Type *TypeTypedef::semantic(Loc loc, Scope *sc) | |
4120 { | |
4121 //printf("TypeTypedef::semantic(%s), sem = %d\n", toChars(), sym->sem); | |
4122 sym->semantic(sc); | |
4123 return merge(); | |
4124 } | |
4125 | |
4126 d_uns64 TypeTypedef::size(Loc loc) | |
4127 { | |
4128 return sym->basetype->size(loc); | |
4129 } | |
4130 | |
4131 unsigned TypeTypedef::alignsize() | |
4132 { | |
4133 return sym->basetype->alignsize(); | |
4134 } | |
4135 | |
4136 Dsymbol *TypeTypedef::toDsymbol(Scope *sc) | |
4137 { | |
4138 return sym; | |
4139 } | |
4140 | |
4141 void TypeTypedef::toDecoBuffer(OutBuffer *buf) | |
4142 { unsigned len; | |
4143 char *name; | |
4144 | |
4145 name = sym->mangle(); | |
4146 // if (name[0] == '_' && name[1] == 'D') | |
4147 // name += 2; | |
4148 //len = strlen(name); | |
4149 //buf->printf("%c%d%s", mangleChar[ty], len, name); | |
4150 buf->printf("%c%s", mangleChar[ty], name); | |
4151 } | |
4152 | |
4153 void TypeTypedef::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod) | |
4154 { | |
4155 //printf("TypeTypedef::toCBuffer2() '%s'\n", sym->toChars()); | |
4156 if (mod != this->mod) | |
4157 { toCBuffer3(buf, hgs, mod); | |
4158 return; | |
4159 } | |
4160 buf->writestring(sym->toChars()); | |
4161 } | |
4162 | |
4163 Expression *TypeTypedef::dotExp(Scope *sc, Expression *e, Identifier *ident) | |
4164 { | |
4165 #if LOGDOTEXP | |
4166 printf("TypeTypedef::dotExp(e = '%s', ident = '%s') '%s'\n", e->toChars(), ident->toChars(), toChars()); | |
4167 #endif | |
4168 if (ident == Id::init) | |
4169 { | |
4170 return Type::dotExp(sc, e, ident); | |
4171 } | |
4172 return sym->basetype->dotExp(sc, e, ident); | |
4173 } | |
4174 | |
4175 Expression *TypeTypedef::getProperty(Loc loc, Identifier *ident) | |
4176 { | |
4177 if (ident == Id::init) | |
4178 { | |
4179 return Type::getProperty(loc, ident); | |
4180 } | |
4181 return sym->basetype->getProperty(loc, ident); | |
4182 } | |
4183 | |
4184 int TypeTypedef::isbit() | |
4185 { | |
4186 return sym->basetype->isbit(); | |
4187 } | |
4188 | |
4189 int TypeTypedef::isintegral() | |
4190 { | |
4191 //printf("TypeTypedef::isintegral()\n"); | |
4192 //printf("sym = '%s'\n", sym->toChars()); | |
4193 //printf("basetype = '%s'\n", sym->basetype->toChars()); | |
4194 return sym->basetype->isintegral(); | |
4195 } | |
4196 | |
4197 int TypeTypedef::isfloating() | |
4198 { | |
4199 return sym->basetype->isfloating(); | |
4200 } | |
4201 | |
4202 int TypeTypedef::isreal() | |
4203 { | |
4204 return sym->basetype->isreal(); | |
4205 } | |
4206 | |
4207 int TypeTypedef::isimaginary() | |
4208 { | |
4209 return sym->basetype->isimaginary(); | |
4210 } | |
4211 | |
4212 int TypeTypedef::iscomplex() | |
4213 { | |
4214 return sym->basetype->iscomplex(); | |
4215 } | |
4216 | |
4217 int TypeTypedef::isunsigned() | |
4218 { | |
4219 return sym->basetype->isunsigned(); | |
4220 } | |
4221 | |
4222 int TypeTypedef::isscalar() | |
4223 { | |
4224 return sym->basetype->isscalar(); | |
4225 } | |
4226 | |
4227 int TypeTypedef::checkBoolean() | |
4228 { | |
4229 return sym->basetype->checkBoolean(); | |
4230 } | |
4231 | |
4232 Type *TypeTypedef::toBasetype() | |
4233 { | |
4234 if (sym->inuse) | |
4235 { | |
4236 sym->error("circular definition"); | |
4237 sym->basetype = Type::terror; | |
4238 return Type::terror; | |
4239 } | |
4240 sym->inuse = 1; | |
4241 Type *t = sym->basetype->toBasetype(); | |
4242 sym->inuse = 0; | |
4243 return t; | |
4244 } | |
4245 | |
4246 MATCH TypeTypedef::implicitConvTo(Type *to) | |
4247 { MATCH m; | |
4248 | |
4249 //printf("TypeTypedef::implicitConvTo()\n"); | |
4250 if (this->equals(to)) | |
4251 m = MATCHexact; // exact match | |
4252 else if (sym->basetype->implicitConvTo(to)) | |
4253 m = MATCHconvert; // match with conversions | |
4254 else | |
4255 m = MATCHnomatch; // no match | |
4256 return m; | |
4257 } | |
4258 | |
4259 Expression *TypeTypedef::defaultInit(Loc loc) | |
4260 { Expression *e; | |
4261 Type *bt; | |
4262 | |
4263 #if LOGDEFAULTINIT | |
4264 printf("TypeTypedef::defaultInit() '%s'\n", toChars()); | |
4265 #endif | |
4266 if (sym->init) | |
4267 { | |
4268 //sym->init->toExpression()->print(); | |
4269 return sym->init->toExpression(); | |
4270 } | |
4271 bt = sym->basetype; | |
4272 e = bt->defaultInit(loc); | |
4273 e->type = this; | |
4274 while (bt->ty == Tsarray) | |
4275 { | |
4276 e->type = bt->next; | |
4277 bt = bt->next->toBasetype(); | |
4278 } | |
4279 return e; | |
4280 } | |
4281 | |
4282 int TypeTypedef::isZeroInit() | |
4283 { | |
4284 if (sym->init) | |
4285 { | |
4286 if (sym->init->isVoidInitializer()) | |
4287 return 1; // initialize voids to 0 | |
4288 Expression *e = sym->init->toExpression(); | |
4289 if (e && e->isBool(FALSE)) | |
4290 return 1; | |
4291 return 0; // assume not | |
4292 } | |
4293 if (sym->inuse) | |
4294 { | |
4295 sym->error("circular definition"); | |
4296 sym->basetype = Type::terror; | |
4297 } | |
4298 sym->inuse = 1; | |
4299 int result = sym->basetype->isZeroInit(); | |
4300 sym->inuse = 0; | |
4301 return result; | |
4302 } | |
4303 | |
4304 int TypeTypedef::hasPointers() | |
4305 { | |
4306 return toBasetype()->hasPointers(); | |
4307 } | |
4308 | |
4309 /***************************** TypeStruct *****************************/ | |
4310 | |
4311 TypeStruct::TypeStruct(StructDeclaration *sym) | |
4312 : Type(Tstruct, NULL) | |
4313 { | |
4314 this->sym = sym; | |
1029
4d366a75d95f
Added hasUnalignedFields helper to check if a type has unaligned fields - as per request from fvbommel. Result is cached in TypeStruct.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1024
diff
changeset
|
4315 |
4d366a75d95f
Added hasUnalignedFields helper to check if a type has unaligned fields - as per request from fvbommel. Result is cached in TypeStruct.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1024
diff
changeset
|
4316 // LDC |
4d366a75d95f
Added hasUnalignedFields helper to check if a type has unaligned fields - as per request from fvbommel. Result is cached in TypeStruct.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1024
diff
changeset
|
4317 this->unaligned = 0; |
159 | 4318 } |
4319 | |
4320 char *TypeStruct::toChars() | |
4321 { | |
4322 //printf("sym.parent: %s, deco = %s\n", sym->parent->toChars(), deco); | |
4323 TemplateInstance *ti = sym->parent->isTemplateInstance(); | |
4324 if (ti && ti->toAlias() == sym) | |
4325 return ti->toChars(); | |
4326 return sym->toChars(); | |
4327 } | |
4328 | |
4329 Type *TypeStruct::syntaxCopy() | |
4330 { | |
4331 return this; | |
4332 } | |
4333 | |
4334 Type *TypeStruct::semantic(Loc loc, Scope *sc) | |
4335 { | |
4336 //printf("TypeStruct::semantic('%s')\n", sym->toChars()); | |
4337 | |
4338 /* Cannot do semantic for sym because scope chain may not | |
4339 * be right. | |
4340 */ | |
4341 //sym->semantic(sc); | |
4342 | |
4343 return merge(); | |
4344 } | |
4345 | |
4346 d_uns64 TypeStruct::size(Loc loc) | |
4347 { | |
4348 return sym->size(loc); | |
4349 } | |
4350 | |
4351 unsigned TypeStruct::alignsize() | |
4352 { unsigned sz; | |
4353 | |
4354 sym->size(0); // give error for forward references | |
4355 sz = sym->alignsize; | |
4356 if (sz > sym->structalign) | |
4357 sz = sym->structalign; | |
4358 return sz; | |
4359 } | |
4360 | |
4361 Dsymbol *TypeStruct::toDsymbol(Scope *sc) | |
4362 { | |
4363 return sym; | |
4364 } | |
4365 | |
4366 void TypeStruct::toDecoBuffer(OutBuffer *buf) | |
4367 { unsigned len; | |
4368 char *name; | |
4369 | |
4370 name = sym->mangle(); | |
4371 //printf("TypeStruct::toDecoBuffer('%s') = '%s'\n", toChars(), name); | |
4372 // if (name[0] == '_' && name[1] == 'D') | |
4373 // name += 2; | |
4374 //len = strlen(name); | |
4375 //buf->printf("%c%d%s", mangleChar[ty], len, name); | |
4376 buf->printf("%c%s", mangleChar[ty], name); | |
4377 } | |
4378 | |
4379 void TypeStruct::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod) | |
4380 { | |
4381 if (mod != this->mod) | |
4382 { toCBuffer3(buf, hgs, mod); | |
4383 return; | |
4384 } | |
4385 TemplateInstance *ti = sym->parent->isTemplateInstance(); | |
4386 if (ti && ti->toAlias() == sym) | |
4387 buf->writestring(ti->toChars()); | |
4388 else | |
4389 buf->writestring(sym->toChars()); | |
4390 } | |
4391 | |
4392 Expression *TypeStruct::dotExp(Scope *sc, Expression *e, Identifier *ident) | |
4393 { unsigned offset; | |
4394 | |
4395 Expression *b; | |
4396 VarDeclaration *v; | |
4397 Dsymbol *s; | |
4398 DotVarExp *de; | |
4399 Declaration *d; | |
4400 | |
4401 #if LOGDOTEXP | |
4402 printf("TypeStruct::dotExp(e = '%s', ident = '%s')\n", e->toChars(), ident->toChars()); | |
4403 #endif | |
4404 if (!sym->members) | |
4405 { | |
4406 error(e->loc, "struct %s is forward referenced", sym->toChars()); | |
4407 return new IntegerExp(e->loc, 0, Type::tint32); | |
4408 } | |
4409 | |
875
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
4410 /* If e.tupleof |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
4411 */ |
159 | 4412 if (ident == Id::tupleof) |
4413 { | |
875
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
4414 /* Create a TupleExp out of the fields of the struct e: |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
4415 * (e.field0, e.field1, e.field2, ...) |
159 | 4416 */ |
336 | 4417 e = e->semantic(sc); // do this before turning on noaccesscheck |
159 | 4418 Expressions *exps = new Expressions; |
4419 exps->reserve(sym->fields.dim); | |
4420 for (size_t i = 0; i < sym->fields.dim; i++) | |
4421 { VarDeclaration *v = (VarDeclaration *)sym->fields.data[i]; | |
4422 Expression *fe = new DotVarExp(e->loc, e, v); | |
4423 exps->push(fe); | |
4424 } | |
4425 e = new TupleExp(e->loc, exps); | |
336 | 4426 sc = sc->push(); |
4427 sc->noaccesscheck = 1; | |
159 | 4428 e = e->semantic(sc); |
336 | 4429 sc->pop(); |
159 | 4430 return e; |
4431 } | |
4432 | |
4433 if (e->op == TOKdotexp) | |
4434 { DotExp *de = (DotExp *)e; | |
4435 | |
4436 if (de->e1->op == TOKimport) | |
4437 { | |
4438 ScopeExp *se = (ScopeExp *)de->e1; | |
4439 | |
4440 s = se->sds->search(e->loc, ident, 0); | |
4441 e = de->e1; | |
4442 goto L1; | |
4443 } | |
4444 } | |
4445 | |
4446 s = sym->search(e->loc, ident, 0); | |
4447 L1: | |
4448 if (!s) | |
4449 { | |
4450 //return getProperty(e->loc, ident); | |
4451 return Type::dotExp(sc, e, ident); | |
4452 } | |
336 | 4453 if (!s->isFuncDeclaration()) // because of overloading |
4454 s->checkDeprecated(e->loc, sc); | |
159 | 4455 s = s->toAlias(); |
4456 | |
4457 v = s->isVarDeclaration(); | |
717
a26b0c5d5942
Merged DMD 1.036.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
715
diff
changeset
|
4458 if (v && v->isConst() && v->type->toBasetype()->ty != Tsarray) |
159 | 4459 { ExpInitializer *ei = v->getExpInitializer(); |
4460 | |
4461 if (ei) | |
4462 { e = ei->exp->copy(); // need to copy it if it's a StringExp | |
4463 e = e->semantic(sc); | |
4464 return e; | |
4465 } | |
4466 } | |
4467 | |
4468 if (s->getType()) | |
4469 { | |
4470 //return new DotTypeExp(e->loc, e, s); | |
4471 return new TypeExp(e->loc, s->getType()); | |
4472 } | |
4473 | |
4474 EnumMember *em = s->isEnumMember(); | |
4475 if (em) | |
4476 { | |
4477 assert(em->value); | |
4478 return em->value->copy(); | |
4479 } | |
4480 | |
4481 TemplateMixin *tm = s->isTemplateMixin(); | |
4482 if (tm) | |
4483 { Expression *de; | |
4484 | |
4485 de = new DotExp(e->loc, e, new ScopeExp(e->loc, tm)); | |
4486 de->type = e->type; | |
4487 return de; | |
4488 } | |
4489 | |
4490 TemplateDeclaration *td = s->isTemplateDeclaration(); | |
4491 if (td) | |
4492 { | |
4493 e = new DotTemplateExp(e->loc, e, td); | |
4494 e->semantic(sc); | |
4495 return e; | |
4496 } | |
4497 | |
4498 TemplateInstance *ti = s->isTemplateInstance(); | |
4499 if (ti) | |
4500 { if (!ti->semanticdone) | |
4501 ti->semantic(sc); | |
4502 s = ti->inst->toAlias(); | |
4503 if (!s->isTemplateInstance()) | |
4504 goto L1; | |
4505 Expression *de = new DotExp(e->loc, e, new ScopeExp(e->loc, ti)); | |
4506 de->type = e->type; | |
4507 return de; | |
4508 } | |
4509 | |
875
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
4510 Import *timp = s->isImport(); |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
4511 if (timp) |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
4512 { |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
4513 e = new DsymbolExp(e->loc, s); |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
4514 e = e->semantic(sc); |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
4515 return e; |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
4516 } |
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
4517 |
159 | 4518 d = s->isDeclaration(); |
4519 #ifdef DEBUG | |
4520 if (!d) | |
4521 printf("d = %s '%s'\n", s->kind(), s->toChars()); | |
4522 #endif | |
4523 assert(d); | |
4524 | |
4525 if (e->op == TOKtype) | |
4526 { FuncDeclaration *fd = sc->func; | |
4527 | |
4528 if (d->needThis() && fd && fd->vthis) | |
4529 { | |
4530 e = new DotVarExp(e->loc, new ThisExp(e->loc), d); | |
4531 e = e->semantic(sc); | |
4532 return e; | |
4533 } | |
4534 if (d->isTupleDeclaration()) | |
4535 { | |
4536 e = new TupleExp(e->loc, d->isTupleDeclaration()); | |
4537 e = e->semantic(sc); | |
4538 return e; | |
4539 } | |
4540 return new VarExp(e->loc, d); | |
4541 } | |
4542 | |
4543 if (d->isDataseg()) | |
4544 { | |
4545 // (e, d) | |
4546 VarExp *ve; | |
4547 | |
4548 accessCheck(e->loc, sc, e, d); | |
4549 ve = new VarExp(e->loc, d); | |
4550 e = new CommaExp(e->loc, e, ve); | |
4551 e->type = d->type; | |
4552 return e; | |
4553 } | |
4554 | |
4555 if (v) | |
4556 { | |
4557 if (v->toParent() != sym) | |
4558 sym->error(e->loc, "'%s' is not a member", v->toChars()); | |
4559 | |
4560 // *(&e + offset) | |
4561 accessCheck(e->loc, sc, e, d); | |
875
330f999ade44
Merged DMD 1.038
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
872
diff
changeset
|
4562 #if 0 |
159 | 4563 b = new AddrExp(e->loc, e); |
4564 b->type = e->type->pointerTo(); | |
4565 b = new AddExp(e->loc, b, new IntegerExp(e->loc, v->offset, Type::tint32)); | |
4566 b->type = v->type->pointerTo(); | |
4567 e = new PtrExp(e->loc, b); | |
4568 e->type = v->type; | |
4569 return e; | |
585
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
509
diff
changeset
|
4570 #endif |
159 | 4571 } |
4572 | |
4573 de = new DotVarExp(e->loc, e, d); | |
4574 return de->semantic(sc); | |
4575 } | |
4576 | |
4577 unsigned TypeStruct::memalign(unsigned salign) | |
4578 { | |
4579 sym->size(0); // give error for forward references | |
4580 return sym->structalign; | |
4581 } | |
4582 | |
4583 Expression *TypeStruct::defaultInit(Loc loc) | |
913
29c0d1194033
Fix #198 and #199 by making CTFE on static struct initializers work.
Christian Kamm <kamm incasoftware de>
parents:
900
diff
changeset
|
4584 { Declaration *d; |
159 | 4585 |
4586 #if LOGDEFAULTINIT | |
4587 printf("TypeStruct::defaultInit() '%s'\n", toChars()); | |
4588 #endif | |
913
29c0d1194033
Fix #198 and #199 by making CTFE on static struct initializers work.
Christian Kamm <kamm incasoftware de>
parents:
900
diff
changeset
|
4589 d = new StaticStructInitDeclaration(sym->loc, sym); |
159 | 4590 assert(d); |
4591 d->type = this; | |
4592 return new VarExp(sym->loc, d); | |
4593 } | |
4594 | |
4595 int TypeStruct::isZeroInit() | |
4596 { | |
4597 return sym->zeroInit; | |
4598 } | |
4599 | |
4600 int TypeStruct::checkBoolean() | |
4601 { | |
4602 return FALSE; | |
4603 } | |
4604 | |
4605 int TypeStruct::hasPointers() | |
4606 { | |
4607 StructDeclaration *s = sym; | |
4608 | |
4609 sym->size(0); // give error for forward references | |
4610 if (s->members) | |
4611 { | |
4612 for (size_t i = 0; i < s->members->dim; i++) | |
4613 { | |
4614 Dsymbol *sm = (Dsymbol *)s->members->data[i]; | |
4615 if (sm->hasPointers()) | |
4616 return TRUE; | |
4617 } | |
4618 } | |
4619 return FALSE; | |
4620 } | |
4621 | |
4622 | |
4623 /***************************** TypeClass *****************************/ | |
4624 | |
4625 TypeClass::TypeClass(ClassDeclaration *sym) | |
4626 : Type(Tclass, NULL) | |
4627 { | |
4628 this->sym = sym; | |
4629 } | |
4630 | |
4631 char *TypeClass::toChars() | |
4632 { | |
4633 return sym->toPrettyChars(); | |
4634 } | |
4635 | |
4636 Type *TypeClass::syntaxCopy() | |
4637 { | |
4638 return this; | |
4639 } | |
4640 | |
4641 Type *TypeClass::semantic(Loc loc, Scope *sc) | |
4642 { | |
4643 //printf("TypeClass::semantic(%s)\n", sym->toChars()); | |
4644 if (sym->scope) | |
4645 sym->semantic(sym->scope); | |
4646 return merge(); | |
4647 } | |
4648 | |
4649 d_uns64 TypeClass::size(Loc loc) | |
4650 { | |
4651 return PTRSIZE; | |
4652 } | |
4653 | |
4654 Dsymbol *TypeClass::toDsymbol(Scope *sc) | |
4655 { | |
4656 return sym; | |
4657 } | |
4658 | |
4659 void TypeClass::toDecoBuffer(OutBuffer *buf) | |
4660 { unsigned len; | |
4661 char *name; | |
4662 | |
4663 name = sym->mangle(); | |
4664 // if (name[0] == '_' && name[1] == 'D') | |
4665 // name += 2; | |
4666 //printf("TypeClass::toDecoBuffer('%s') = '%s'\n", toChars(), name); | |
4667 //len = strlen(name); | |
4668 //buf->printf("%c%d%s", mangleChar[ty], len, name); | |
4669 buf->printf("%c%s", mangleChar[ty], name); | |
4670 } | |
4671 | |
4672 void TypeClass::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod) | |
4673 { | |
4674 if (mod != this->mod) | |
4675 { toCBuffer3(buf, hgs, mod); | |
4676 return; | |
4677 } | |
4678 buf->writestring(sym->toChars()); | |
4679 } | |
4680 | |
4681 Expression *TypeClass::dotExp(Scope *sc, Expression *e, Identifier *ident) | |
4682 { unsigned offset; | |
4683 | |
4684 Expression *b; | |
4685 VarDeclaration *v; | |
4686 Dsymbol *s; | |
4687 DotVarExp *de; | |
4688 Declaration *d; | |
4689 | |
4690 #if LOGDOTEXP | |
4691 printf("TypeClass::dotExp(e='%s', ident='%s')\n", e->toChars(), ident->toChars()); | |
4692 #endif | |
4693 | |
4694 if (e->op == TOKdotexp) | |
4695 { DotExp *de = (DotExp *)e; | |
4696 | |
4697 if (de->e1->op == TOKimport) | |
4698 { | |
4699 ScopeExp *se = (ScopeExp *)de->e1; | |
4700 | |
4701 s = se->sds->search(e->loc, ident, 0); | |
4702 e = de->e1; | |
4703 goto L1; | |
4704 } | |
4705 } | |
4706 | |
4707 if (ident == Id::tupleof) | |
4708 { | |
4709 /* Create a TupleExp | |
4710 */ | |
336 | 4711 e = e->semantic(sc); // do this before turning on noaccesscheck |
159 | 4712 Expressions *exps = new Expressions; |
4713 exps->reserve(sym->fields.dim); | |
4714 for (size_t i = 0; i < sym->fields.dim; i++) | |
4715 { VarDeclaration *v = (VarDeclaration *)sym->fields.data[i]; | |
4716 Expression *fe = new DotVarExp(e->loc, e, v); | |
4717 exps->push(fe); | |
4718 } | |
4719 e = new TupleExp(e->loc, exps); | |
336 | 4720 sc = sc->push(); |
4721 sc->noaccesscheck = 1; | |
159 | 4722 e = e->semantic(sc); |
336 | 4723 sc->pop(); |
159 | 4724 return e; |
4725 } | |
4726 | |
4727 s = sym->search(e->loc, ident, 0); | |
4728 L1: | |
4729 if (!s) | |
4730 { | |
4731 // See if it's a base class | |
4732 ClassDeclaration *cbase; | |
4733 for (cbase = sym->baseClass; cbase; cbase = cbase->baseClass) | |
4734 { | |
4735 if (cbase->ident->equals(ident)) | |
4736 { | |
4737 e = new DotTypeExp(0, e, cbase); | |
4738 return e; | |
4739 } | |
4740 } | |
4741 | |
4742 if (ident == Id::classinfo) | |
4743 { | |
4744 Type *t; | |
4745 | |
4746 assert(ClassDeclaration::classinfo); | |
4747 t = ClassDeclaration::classinfo->type; | |
4748 if (e->op == TOKtype || e->op == TOKdottype) | |
4749 { | |
4750 /* For type.classinfo, we know the classinfo | |
4751 * at compile time. | |
4752 */ | |
4753 if (!sym->vclassinfo) | |
4754 sym->vclassinfo = new ClassInfoDeclaration(sym); | |
4755 e = new VarExp(e->loc, sym->vclassinfo); | |
4756 e = e->addressOf(sc); | |
4757 e->type = t; // do this so we don't get redundant dereference | |
4758 } | |
4759 else | |
4760 { | |
4761 /* For class objects, the classinfo reference is the first | |
4762 * entry in the vtbl[] | |
4763 */ | |
4764 #if IN_LLVM | |
4765 | |
4766 Type* ct; | |
4767 if (sym->isInterfaceDeclaration()) { | |
4768 ct = t->pointerTo()->pointerTo()->pointerTo(); | |
4769 } | |
4770 else { | |
4771 ct = t->pointerTo()->pointerTo(); | |
4772 } | |
4773 | |
4774 e = e->castTo(sc, ct); | |
4775 e = new PtrExp(e->loc, e); | |
4776 e->type = ct->next; | |
4777 e = new PtrExp(e->loc, e); | |
4778 e->type = ct->next->next; | |
4779 | |
4780 if (sym->isInterfaceDeclaration()) | |
4781 { | |
4782 if (sym->isCOMinterface()) | |
4783 { /* COM interface vtbl[]s are different in that the | |
4784 * first entry is always pointer to QueryInterface(). | |
4785 * We can't get a .classinfo for it. | |
4786 */ | |
4787 error(e->loc, "no .classinfo for COM interface objects"); | |
4788 } | |
4789 /* For an interface, the first entry in the vtbl[] | |
4790 * is actually a pointer to an instance of struct Interface. | |
4791 * The first member of Interface is the .classinfo, | |
4792 * so add an extra pointer indirection. | |
4793 */ | |
4794 e = new PtrExp(e->loc, e); | |
4795 e->type = ct->next->next->next; | |
4796 } | |
336 | 4797 } |
159 | 4798 |
4799 #else | |
4800 | |
4801 e = new PtrExp(e->loc, e); | |
4802 e->type = t->pointerTo(); | |
4803 if (sym->isInterfaceDeclaration()) | |
4804 { | |
4805 if (sym->isCOMinterface()) | |
4806 { /* COM interface vtbl[]s are different in that the | |
4807 * first entry is always pointer to QueryInterface(). | |
4808 * We can't get a .classinfo for it. | |
4809 */ | |
4810 error(e->loc, "no .classinfo for COM interface objects"); | |
4811 } | |
4812 /* For an interface, the first entry in the vtbl[] | |
4813 * is actually a pointer to an instance of struct Interface. | |
4814 * The first member of Interface is the .classinfo, | |
4815 * so add an extra pointer indirection. | |
4816 */ | |
4817 e->type = e->type->pointerTo(); | |
4818 e = new PtrExp(e->loc, e); | |
4819 e->type = t->pointerTo(); | |
4820 } | |
4821 e = new PtrExp(e->loc, e, t); | |
336 | 4822 } |
4823 | |
664
eef8ac26c66c
Some missed LLVMDC -> LDC.
Christian Kamm <kamm incasoftware de>
parents:
658
diff
changeset
|
4824 #endif // !LDC |
336 | 4825 |
4826 return e; | |
4827 } | |
4828 | |
4829 if (ident == Id::__vptr) | |
4830 { /* The pointer to the vtbl[] | |
4831 * *cast(void***)e | |
4832 */ | |
4833 e = e->castTo(sc, tvoidptr->pointerTo()->pointerTo()); | |
4834 e = new PtrExp(e->loc, e); | |
4835 e = e->semantic(sc); | |
4836 return e; | |
4837 } | |
4838 | |
4839 if (ident == Id::__monitor) | |
4840 { /* The handle to the monitor (call it a void*) | |
4841 * *(cast(void**)e + 1) | |
4842 */ | |
4843 e = e->castTo(sc, tvoidptr->pointerTo()); | |
4844 e = new AddExp(e->loc, e, new IntegerExp(1)); | |
4845 e = new PtrExp(e->loc, e); | |
4846 e = e->semantic(sc); | |
159 | 4847 return e; |
4848 } | |
4849 | |
4850 if (ident == Id::typeinfo) | |
4851 { | |
4852 if (!global.params.useDeprecated) | |
4853 error(e->loc, ".typeinfo deprecated, use typeid(type)"); | |
4854 return getTypeInfo(sc); | |
4855 } | |
4856 if (ident == Id::outer && sym->vthis) | |
4857 { | |
4858 s = sym->vthis; | |
4859 } | |
4860 else | |
4861 { | |
4862 //return getProperty(e->loc, ident); | |
4863 return Type::dotExp(sc, e, ident); | |
4864 } | |
4865 } | |
336 | 4866 if (!s->isFuncDeclaration()) // because of overloading |
4867 s->checkDeprecated(e->loc, sc); | |
159 | 4868 s = s->toAlias(); |
4869 v = s->isVarDeclaration(); | |
717
a26b0c5d5942
Merged DMD 1.036.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
715
diff
changeset
|
4870 if (v && v->isConst() && v->type->toBasetype()->ty != Tsarray) |
159 | 4871 { ExpInitializer *ei = v->getExpInitializer(); |
4872 | |
4873 if (ei) | |
4874 { e = ei->exp->copy(); // need to copy it if it's a StringExp | |
4875 e = e->semantic(sc); | |
4876 return e; | |
4877 } | |
4878 } | |
4879 | |
4880 if (s->getType()) | |
4881 { | |
4882 // if (e->op == TOKtype) | |
4883 return new TypeExp(e->loc, s->getType()); | |
4884 // return new DotTypeExp(e->loc, e, s); | |
4885 } | |
4886 | |
4887 EnumMember *em = s->isEnumMember(); | |
4888 if (em) | |
4889 { | |
4890 assert(em->value); | |
4891 return em->value->copy(); | |
4892 } | |
4893 | |
4894 TemplateMixin *tm = s->isTemplateMixin(); | |
4895 if (tm) | |
4896 { Expression *de; | |
4897 | |
4898 de = new DotExp(e->loc, e, new ScopeExp(e->loc, tm)); | |
4899 de->type = e->type; | |
4900 return de; | |
4901 } | |
4902 | |
4903 TemplateDeclaration *td = s->isTemplateDeclaration(); | |
4904 if (td) | |
4905 { | |
4906 e = new DotTemplateExp(e->loc, e, td); | |
4907 e->semantic(sc); | |
4908 return e; | |
4909 } | |
4910 | |
4911 TemplateInstance *ti = s->isTemplateInstance(); | |
4912 if (ti) | |
4913 { if (!ti->semanticdone) | |
4914 ti->semantic(sc); | |
4915 s = ti->inst->toAlias(); | |
4916 if (!s->isTemplateInstance()) | |
4917 goto L1; | |
4918 Expression *de = new DotExp(e->loc, e, new ScopeExp(e->loc, ti)); | |
4919 de->type = e->type; | |
4920 return de; | |
4921 } | |
4922 | |
4923 d = s->isDeclaration(); | |
4924 if (!d) | |
4925 { | |
4926 e->error("%s.%s is not a declaration", e->toChars(), ident->toChars()); | |
4927 return new IntegerExp(e->loc, 1, Type::tint32); | |
4928 } | |
4929 | |
4930 if (e->op == TOKtype) | |
4931 { | |
4932 VarExp *ve; | |
4933 | |
4934 if (d->needThis() && (hasThis(sc) || !d->isFuncDeclaration())) | |
4935 { | |
4936 if (sc->func) | |
4937 { | |
4938 ClassDeclaration *thiscd; | |
4939 thiscd = sc->func->toParent()->isClassDeclaration(); | |
4940 | |
4941 if (thiscd) | |
4942 { | |
4943 ClassDeclaration *cd = e->type->isClassHandle(); | |
4944 | |
4945 if (cd == thiscd) | |
4946 { | |
4947 e = new ThisExp(e->loc); | |
4948 e = new DotTypeExp(e->loc, e, cd); | |
4949 de = new DotVarExp(e->loc, e, d); | |
4950 e = de->semantic(sc); | |
4951 return e; | |
4952 } | |
4953 else if ((!cd || !cd->isBaseOf(thiscd, NULL)) && | |
4954 !d->isFuncDeclaration()) | |
4955 e->error("'this' is required, but %s is not a base class of %s", e->type->toChars(), thiscd->toChars()); | |
4956 } | |
4957 } | |
4958 | |
4959 de = new DotVarExp(e->loc, new ThisExp(e->loc), d); | |
4960 e = de->semantic(sc); | |
4961 return e; | |
4962 } | |
4963 else if (d->isTupleDeclaration()) | |
4964 { | |
4965 e = new TupleExp(e->loc, d->isTupleDeclaration()); | |
4966 e = e->semantic(sc); | |
4967 return e; | |
4968 } | |
4969 else | |
4970 ve = new VarExp(e->loc, d); | |
4971 return ve; | |
4972 } | |
4973 | |
4974 if (d->isDataseg()) | |
4975 { | |
4976 // (e, d) | |
4977 VarExp *ve; | |
4978 | |
4979 accessCheck(e->loc, sc, e, d); | |
4980 ve = new VarExp(e->loc, d); | |
4981 e = new CommaExp(e->loc, e, ve); | |
4982 e->type = d->type; | |
4983 return e; | |
4984 } | |
4985 | |
4986 if (d->parent && d->toParent()->isModule()) | |
4987 { | |
4988 // (e, d) | |
4989 VarExp *ve; | |
4990 | |
4991 ve = new VarExp(e->loc, d); | |
4992 e = new CommaExp(e->loc, e, ve); | |
4993 e->type = d->type; | |
4994 return e; | |
4995 } | |
4996 | |
4997 de = new DotVarExp(e->loc, e, d); | |
4998 return de->semantic(sc); | |
4999 } | |
5000 | |
5001 ClassDeclaration *TypeClass::isClassHandle() | |
5002 { | |
5003 return sym; | |
5004 } | |
5005 | |
5006 int TypeClass::isauto() | |
5007 { | |
5008 return sym->isauto; | |
5009 } | |
5010 | |
5011 int TypeClass::isBaseOf(Type *t, int *poffset) | |
5012 { | |
5013 if (t->ty == Tclass) | |
5014 { ClassDeclaration *cd; | |
5015 | |
5016 cd = ((TypeClass *)t)->sym; | |
5017 if (sym->isBaseOf(cd, poffset)) | |
5018 return 1; | |
5019 } | |
5020 return 0; | |
5021 } | |
5022 | |
5023 MATCH TypeClass::implicitConvTo(Type *to) | |
5024 { | |
5025 //printf("TypeClass::implicitConvTo('%s')\n", to->toChars()); | |
5026 if (this == to) | |
5027 return MATCHexact; | |
5028 | |
5029 ClassDeclaration *cdto = to->isClassHandle(); | |
5030 if (cdto && cdto->isBaseOf(sym, NULL)) | |
5031 { //printf("is base\n"); | |
5032 return MATCHconvert; | |
5033 } | |
5034 | |
5035 if (global.params.Dversion == 1) | |
5036 { | |
5037 // Allow conversion to (void *) | |
5038 if (to->ty == Tpointer && to->next->ty == Tvoid) | |
5039 return MATCHconvert; | |
5040 } | |
5041 | |
5042 return MATCHnomatch; | |
5043 } | |
5044 | |
5045 Expression *TypeClass::defaultInit(Loc loc) | |
5046 { | |
5047 #if LOGDEFAULTINIT | |
5048 printf("TypeClass::defaultInit() '%s'\n", toChars()); | |
5049 #endif | |
5050 Expression *e; | |
5051 e = new NullExp(loc); | |
5052 e->type = this; | |
5053 return e; | |
5054 } | |
5055 | |
5056 int TypeClass::isZeroInit() | |
5057 { | |
5058 return 1; | |
5059 } | |
5060 | |
5061 int TypeClass::checkBoolean() | |
5062 { | |
5063 return TRUE; | |
5064 } | |
5065 | |
5066 int TypeClass::hasPointers() | |
5067 { | |
5068 return TRUE; | |
5069 } | |
5070 | |
5071 /***************************** TypeTuple *****************************/ | |
5072 | |
5073 TypeTuple::TypeTuple(Arguments *arguments) | |
5074 : Type(Ttuple, NULL) | |
5075 { | |
5076 //printf("TypeTuple(this = %p)\n", this); | |
5077 this->arguments = arguments; | |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
5078 //printf("TypeTuple() %s\n", toChars()); |
159 | 5079 #ifdef DEBUG |
5080 if (arguments) | |
5081 { | |
5082 for (size_t i = 0; i < arguments->dim; i++) | |
5083 { | |
5084 Argument *arg = (Argument *)arguments->data[i]; | |
5085 assert(arg && arg->type); | |
5086 } | |
5087 } | |
5088 #endif | |
5089 } | |
5090 | |
5091 /**************** | |
5092 * Form TypeTuple from the types of the expressions. | |
5093 * Assume exps[] is already tuple expanded. | |
5094 */ | |
5095 | |
5096 TypeTuple::TypeTuple(Expressions *exps) | |
5097 : Type(Ttuple, NULL) | |
5098 { | |
5099 Arguments *arguments = new Arguments; | |
5100 if (exps) | |
5101 { | |
5102 arguments->setDim(exps->dim); | |
5103 for (size_t i = 0; i < exps->dim; i++) | |
5104 { Expression *e = (Expression *)exps->data[i]; | |
5105 if (e->type->ty == Ttuple) | |
5106 e->error("cannot form tuple of tuples"); | |
5107 Argument *arg = new Argument(STCin, e->type, NULL, NULL); | |
5108 arguments->data[i] = (void *)arg; | |
5109 } | |
5110 } | |
5111 this->arguments = arguments; | |
5112 } | |
5113 | |
5114 Type *TypeTuple::syntaxCopy() | |
5115 { | |
5116 Arguments *args = Argument::arraySyntaxCopy(arguments); | |
5117 Type *t = new TypeTuple(args); | |
5118 return t; | |
5119 } | |
5120 | |
5121 Type *TypeTuple::semantic(Loc loc, Scope *sc) | |
5122 { | |
5123 //printf("TypeTuple::semantic(this = %p)\n", this); | |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
5124 //printf("TypeTuple::semantic() %s\n", toChars()); |
159 | 5125 if (!deco) |
5126 deco = merge()->deco; | |
5127 | |
5128 /* Don't return merge(), because a tuple with one type has the | |
5129 * same deco as that type. | |
5130 */ | |
5131 return this; | |
5132 } | |
5133 | |
5134 int TypeTuple::equals(Object *o) | |
5135 { Type *t; | |
5136 | |
5137 t = (Type *)o; | |
5138 //printf("TypeTuple::equals(%s, %s)\n", toChars(), t->toChars()); | |
5139 if (this == t) | |
5140 { | |
5141 return 1; | |
5142 } | |
5143 if (t->ty == Ttuple) | |
5144 { TypeTuple *tt = (TypeTuple *)t; | |
5145 | |
5146 if (arguments->dim == tt->arguments->dim) | |
5147 { | |
5148 for (size_t i = 0; i < tt->arguments->dim; i++) | |
5149 { Argument *arg1 = (Argument *)arguments->data[i]; | |
5150 Argument *arg2 = (Argument *)tt->arguments->data[i]; | |
5151 | |
5152 if (!arg1->type->equals(arg2->type)) | |
5153 return 0; | |
5154 } | |
5155 return 1; | |
5156 } | |
5157 } | |
5158 return 0; | |
5159 } | |
5160 | |
5161 Type *TypeTuple::reliesOnTident() | |
5162 { | |
5163 if (arguments) | |
5164 { | |
5165 for (size_t i = 0; i < arguments->dim; i++) | |
5166 { | |
5167 Argument *arg = (Argument *)arguments->data[i]; | |
5168 Type *t = arg->type->reliesOnTident(); | |
5169 if (t) | |
5170 return t; | |
5171 } | |
5172 } | |
5173 return NULL; | |
5174 } | |
5175 | |
5176 void TypeTuple::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod) | |
5177 { | |
5178 Argument::argsToCBuffer(buf, hgs, arguments, 0); | |
5179 } | |
5180 | |
5181 void TypeTuple::toDecoBuffer(OutBuffer *buf) | |
5182 { | |
5183 //printf("TypeTuple::toDecoBuffer() this = %p\n", this); | |
5184 OutBuffer buf2; | |
5185 Argument::argsToDecoBuffer(&buf2, arguments); | |
5186 unsigned len = buf2.offset; | |
5187 buf->printf("%c%d%.*s", mangleChar[ty], len, len, (char *)buf2.extractData()); | |
5188 } | |
5189 | |
5190 Expression *TypeTuple::getProperty(Loc loc, Identifier *ident) | |
5191 { Expression *e; | |
5192 | |
5193 #if LOGDOTEXP | |
5194 printf("TypeTuple::getProperty(type = '%s', ident = '%s')\n", toChars(), ident->toChars()); | |
5195 #endif | |
5196 if (ident == Id::length) | |
5197 { | |
5198 e = new IntegerExp(loc, arguments->dim, Type::tsize_t); | |
5199 } | |
5200 else | |
5201 { | |
5202 error(loc, "no property '%s' for tuple '%s'", ident->toChars(), toChars()); | |
5203 e = new IntegerExp(loc, 1, Type::tint32); | |
5204 } | |
5205 return e; | |
5206 } | |
5207 | |
5208 /***************************** TypeSlice *****************************/ | |
5209 | |
5210 /* This is so we can slice a TypeTuple */ | |
5211 | |
5212 TypeSlice::TypeSlice(Type *next, Expression *lwr, Expression *upr) | |
5213 : Type(Tslice, next) | |
5214 { | |
5215 //printf("TypeSlice[%s .. %s]\n", lwr->toChars(), upr->toChars()); | |
5216 this->lwr = lwr; | |
5217 this->upr = upr; | |
5218 } | |
5219 | |
5220 Type *TypeSlice::syntaxCopy() | |
5221 { | |
5222 Type *t = new TypeSlice(next->syntaxCopy(), lwr->syntaxCopy(), upr->syntaxCopy()); | |
5223 return t; | |
5224 } | |
5225 | |
5226 Type *TypeSlice::semantic(Loc loc, Scope *sc) | |
5227 { | |
5228 //printf("TypeSlice::semantic() %s\n", toChars()); | |
5229 next = next->semantic(loc, sc); | |
5230 //printf("next: %s\n", next->toChars()); | |
5231 | |
5232 Type *tbn = next->toBasetype(); | |
5233 if (tbn->ty != Ttuple) | |
5234 { error(loc, "can only slice tuple types, not %s", tbn->toChars()); | |
5235 return Type::terror; | |
5236 } | |
5237 TypeTuple *tt = (TypeTuple *)tbn; | |
5238 | |
5239 lwr = semanticLength(sc, tbn, lwr); | |
5240 lwr = lwr->optimize(WANTvalue); | |
5241 uinteger_t i1 = lwr->toUInteger(); | |
5242 | |
5243 upr = semanticLength(sc, tbn, upr); | |
5244 upr = upr->optimize(WANTvalue); | |
5245 uinteger_t i2 = upr->toUInteger(); | |
5246 | |
5247 if (!(i1 <= i2 && i2 <= tt->arguments->dim)) | |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
5248 { error(loc, "slice [%ju..%ju] is out of range of [0..%u]", i1, i2, tt->arguments->dim); |
159 | 5249 return Type::terror; |
5250 } | |
5251 | |
5252 Arguments *args = new Arguments; | |
5253 args->reserve(i2 - i1); | |
5254 for (size_t i = i1; i < i2; i++) | |
5255 { Argument *arg = (Argument *)tt->arguments->data[i]; | |
5256 args->push(arg); | |
5257 } | |
5258 | |
5259 return new TypeTuple(args); | |
5260 } | |
5261 | |
5262 void TypeSlice::resolve(Loc loc, Scope *sc, Expression **pe, Type **pt, Dsymbol **ps) | |
5263 { | |
5264 next->resolve(loc, sc, pe, pt, ps); | |
5265 if (*pe) | |
5266 { // It's really a slice expression | |
5267 Expression *e; | |
5268 e = new SliceExp(loc, *pe, lwr, upr); | |
5269 *pe = e; | |
5270 } | |
5271 else if (*ps) | |
5272 { Dsymbol *s = *ps; | |
5273 TupleDeclaration *td = s->isTupleDeclaration(); | |
5274 if (td) | |
5275 { | |
5276 /* It's a slice of a TupleDeclaration | |
5277 */ | |
5278 ScopeDsymbol *sym = new ArrayScopeSymbol(td); | |
5279 sym->parent = sc->scopesym; | |
5280 sc = sc->push(sym); | |
5281 | |
5282 lwr = lwr->semantic(sc); | |
5283 lwr = lwr->optimize(WANTvalue); | |
5284 uinteger_t i1 = lwr->toUInteger(); | |
5285 | |
5286 upr = upr->semantic(sc); | |
5287 upr = upr->optimize(WANTvalue); | |
5288 uinteger_t i2 = upr->toUInteger(); | |
5289 | |
5290 sc = sc->pop(); | |
5291 | |
5292 if (!(i1 <= i2 && i2 <= td->objects->dim)) | |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1051
diff
changeset
|
5293 { error(loc, "slice [%ju..%ju] is out of range of [0..%u]", i1, i2, td->objects->dim); |
159 | 5294 goto Ldefault; |
5295 } | |
5296 | |
5297 if (i1 == 0 && i2 == td->objects->dim) | |
5298 { | |
5299 *ps = td; | |
5300 return; | |
5301 } | |
5302 | |
5303 /* Create a new TupleDeclaration which | |
5304 * is a slice [i1..i2] out of the old one. | |
5305 */ | |
5306 Objects *objects = new Objects; | |
5307 objects->setDim(i2 - i1); | |
5308 for (size_t i = 0; i < objects->dim; i++) | |
5309 { | |
5310 objects->data[i] = td->objects->data[(size_t)i1 + i]; | |
5311 } | |
5312 | |
5313 TupleDeclaration *tds = new TupleDeclaration(loc, td->ident, objects); | |
5314 *ps = tds; | |
5315 } | |
5316 else | |
5317 goto Ldefault; | |
5318 } | |
5319 else | |
5320 { | |
5321 Ldefault: | |
5322 Type::resolve(loc, sc, pe, pt, ps); | |
5323 } | |
5324 } | |
5325 | |
5326 void TypeSlice::toCBuffer2(OutBuffer *buf, HdrGenState *hgs, int mod) | |
5327 { | |
5328 if (mod != this->mod) | |
5329 { toCBuffer3(buf, hgs, mod); | |
5330 return; | |
5331 } | |
5332 next->toCBuffer2(buf, hgs, this->mod); | |
5333 | |
5334 buf->printf("[%s .. ", lwr->toChars()); | |
5335 buf->printf("%s]", upr->toChars()); | |
5336 } | |
5337 | |
5338 /***************************** Argument *****************************/ | |
5339 | |
5340 Argument::Argument(unsigned storageClass, Type *type, Identifier *ident, Expression *defaultArg) | |
5341 { | |
5342 this->type = type; | |
5343 this->ident = ident; | |
5344 this->storageClass = storageClass; | |
5345 this->defaultArg = defaultArg; | |
5346 } | |
5347 | |
5348 Argument *Argument::syntaxCopy() | |
5349 { | |
5350 Argument *a = new Argument(storageClass, | |
5351 type ? type->syntaxCopy() : NULL, | |
5352 ident, | |
5353 defaultArg ? defaultArg->syntaxCopy() : NULL); | |
5354 return a; | |
5355 } | |
5356 | |
5357 Arguments *Argument::arraySyntaxCopy(Arguments *args) | |
5358 { Arguments *a = NULL; | |
5359 | |
5360 if (args) | |
5361 { | |
5362 a = new Arguments(); | |
5363 a->setDim(args->dim); | |
5364 for (size_t i = 0; i < a->dim; i++) | |
5365 { Argument *arg = (Argument *)args->data[i]; | |
5366 | |
5367 arg = arg->syntaxCopy(); | |
5368 a->data[i] = (void *)arg; | |
5369 } | |
5370 } | |
5371 return a; | |
5372 } | |
5373 | |
5374 char *Argument::argsTypesToChars(Arguments *args, int varargs) | |
5375 { OutBuffer *buf; | |
5376 | |
5377 buf = new OutBuffer(); | |
5378 | |
5379 buf->writeByte('('); | |
5380 if (args) | |
5381 { int i; | |
5382 OutBuffer argbuf; | |
5383 HdrGenState hgs; | |
5384 | |
5385 for (i = 0; i < args->dim; i++) | |
5386 { Argument *arg; | |
5387 | |
5388 if (i) | |
5389 buf->writeByte(','); | |
5390 arg = (Argument *)args->data[i]; | |
5391 argbuf.reset(); | |
5392 arg->type->toCBuffer2(&argbuf, &hgs, 0); | |
5393 buf->write(&argbuf); | |
5394 } | |
5395 if (varargs) | |
5396 { | |
5397 if (i && varargs == 1) | |
5398 buf->writeByte(','); | |
5399 buf->writestring("..."); | |
5400 } | |
5401 } | |
5402 buf->writeByte(')'); | |
5403 | |
5404 return buf->toChars(); | |
5405 } | |
5406 | |
5407 void Argument::argsToCBuffer(OutBuffer *buf, HdrGenState *hgs, Arguments *arguments, int varargs) | |
5408 { | |
5409 buf->writeByte('('); | |
5410 if (arguments) | |
5411 { int i; | |
5412 OutBuffer argbuf; | |
5413 | |
5414 for (i = 0; i < arguments->dim; i++) | |
5415 { Argument *arg; | |
5416 | |
5417 if (i) | |
5418 buf->writestring(", "); | |
5419 arg = (Argument *)arguments->data[i]; | |
5420 if (arg->storageClass & STCout) | |
5421 buf->writestring("out "); | |
5422 else if (arg->storageClass & STCref) | |
5423 buf->writestring((global.params.Dversion == 1) | |
5424 ? (char *)"inout " : (char *)"ref "); | |
5425 else if (arg->storageClass & STClazy) | |
5426 buf->writestring("lazy "); | |
5427 argbuf.reset(); | |
5428 arg->type->toCBuffer(&argbuf, arg->ident, hgs); | |
5429 if (arg->defaultArg) | |
5430 { | |
5431 argbuf.writestring(" = "); | |
5432 arg->defaultArg->toCBuffer(&argbuf, hgs); | |
5433 } | |
5434 buf->write(&argbuf); | |
5435 } | |
5436 if (varargs) | |
5437 { | |
5438 if (i && varargs == 1) | |
5439 buf->writeByte(','); | |
5440 buf->writestring("..."); | |
5441 } | |
5442 } | |
5443 buf->writeByte(')'); | |
5444 } | |
5445 | |
5446 | |
5447 void Argument::argsToDecoBuffer(OutBuffer *buf, Arguments *arguments) | |
5448 { | |
5449 //printf("Argument::argsToDecoBuffer()\n"); | |
5450 | |
5451 // Write argument types | |
5452 if (arguments) | |
5453 { | |
5454 size_t dim = Argument::dim(arguments); | |
5455 for (size_t i = 0; i < dim; i++) | |
5456 { | |
5457 Argument *arg = Argument::getNth(arguments, i); | |
5458 arg->toDecoBuffer(buf); | |
5459 } | |
5460 } | |
5461 } | |
5462 | |
5463 /**************************************************** | |
5464 * Determine if parameter is a lazy array of delegates. | |
5465 * If so, return the return type of those delegates. | |
5466 * If not, return NULL. | |
5467 */ | |
5468 | |
5469 Type *Argument::isLazyArray() | |
5470 { | |
5471 // if (inout == Lazy) | |
5472 { | |
5473 Type *tb = type->toBasetype(); | |
5474 if (tb->ty == Tsarray || tb->ty == Tarray) | |
5475 { | |
5476 Type *tel = tb->next->toBasetype(); | |
5477 if (tel->ty == Tdelegate) | |
5478 { | |
5479 TypeDelegate *td = (TypeDelegate *)tel; | |
5480 TypeFunction *tf = (TypeFunction *)td->next; | |
5481 | |
5482 if (!tf->varargs && Argument::dim(tf->parameters) == 0) | |
5483 { | |
5484 return tf->next; // return type of delegate | |
5485 } | |
5486 } | |
5487 } | |
5488 } | |
5489 return NULL; | |
5490 } | |
5491 | |
5492 void Argument::toDecoBuffer(OutBuffer *buf) | |
5493 { | |
5494 switch (storageClass & (STCin | STCout | STCref | STClazy)) | |
5495 { case 0: | |
5496 case STCin: | |
5497 break; | |
5498 case STCout: | |
5499 buf->writeByte('J'); | |
5500 break; | |
5501 case STCref: | |
5502 buf->writeByte('K'); | |
5503 break; | |
5504 case STClazy: | |
5505 buf->writeByte('L'); | |
5506 break; | |
5507 default: | |
5508 #ifdef DEBUG | |
5509 halt(); | |
5510 #endif | |
5511 assert(0); | |
5512 } | |
5513 type->toDecoBuffer(buf); | |
5514 } | |
5515 | |
5516 /*************************************** | |
5517 * Determine number of arguments, folding in tuples. | |
5518 */ | |
5519 | |
5520 size_t Argument::dim(Arguments *args) | |
5521 { | |
5522 size_t n = 0; | |
5523 if (args) | |
5524 { | |
5525 for (size_t i = 0; i < args->dim; i++) | |
5526 { Argument *arg = (Argument *)args->data[i]; | |
5527 Type *t = arg->type->toBasetype(); | |
5528 | |
5529 if (t->ty == Ttuple) | |
5530 { TypeTuple *tu = (TypeTuple *)t; | |
5531 n += dim(tu->arguments); | |
5532 } | |
5533 else | |
5534 n++; | |
5535 } | |
5536 } | |
5537 return n; | |
5538 } | |
5539 | |
5540 /*************************************** | |
5541 * Get nth Argument, folding in tuples. | |
5542 * Returns: | |
5543 * Argument* nth Argument | |
5544 * NULL not found, *pn gets incremented by the number | |
5545 * of Arguments | |
5546 */ | |
5547 | |
5548 Argument *Argument::getNth(Arguments *args, size_t nth, size_t *pn) | |
5549 { | |
5550 if (!args) | |
5551 return NULL; | |
5552 | |
5553 size_t n = 0; | |
5554 for (size_t i = 0; i < args->dim; i++) | |
5555 { Argument *arg = (Argument *)args->data[i]; | |
5556 Type *t = arg->type->toBasetype(); | |
5557 | |
5558 if (t->ty == Ttuple) | |
5559 { TypeTuple *tu = (TypeTuple *)t; | |
5560 arg = getNth(tu->arguments, nth - n, &n); | |
5561 if (arg) | |
5562 return arg; | |
5563 } | |
5564 else if (n == nth) | |
5565 return arg; | |
5566 else | |
5567 n++; | |
5568 } | |
5569 | |
5570 if (pn) | |
5571 *pn += n; | |
5572 return NULL; | |
5573 } |