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