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