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