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