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