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