Mercurial > projects > ddmd
annotate dmd/TypeSArray.d @ 41:f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
author | korDen |
---|---|
date | Sat, 21 Aug 2010 07:17:13 +0400 |
parents | 832f71e6f96c |
children | b7d29f613539 |
rev | line source |
---|---|
0 | 1 module dmd.TypeSArray; |
2 | |
3 import dmd.TypeArray; | |
4 import dmd.MOD; | |
5 import dmd.Argument; | |
6 import dmd.TypeStruct; | |
7 import dmd.TypeTuple; | |
8 import dmd.VarExp; | |
9 import dmd.IntegerExp; | |
10 import dmd.Expression; | |
11 import dmd.Type; | |
12 import dmd.TupleDeclaration; | |
13 import dmd.TOK; | |
14 import dmd.Loc; | |
15 import dmd.STC; | |
16 import dmd.Scope; | |
17 import dmd.Dsymbol; | |
18 import dmd.OutBuffer; | |
19 import dmd.HdrGenState; | |
20 import dmd.Identifier; | |
21 import dmd.MATCH; | |
22 import dmd.TypeDArray; | |
23 import dmd.TypePointer; | |
24 import dmd.ArrayTypes; | |
25 import dmd.WANT; | |
26 import dmd.TypeInfoDeclaration; | |
41
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
27 import dmd.ScopeDsymbol; |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
28 import dmd.ArrayScopeSymbol; |
0 | 29 import dmd.TY; |
30 import dmd.Util; | |
31 import dmd.Id; | |
41
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
32 import dmd.IndexExp; |
0 | 33 |
34 import dmd.type.Util; | |
35 | |
36 import dmd.backend.dt_t; | |
37 import dmd.backend.TYPE; | |
38 import dmd.backend.Util; | |
39 import dmd.backend.TYM; | |
40 import dmd.backend.DT; | |
41 | |
42 // Static array, one with a fixed dimension | |
43 class TypeSArray : TypeArray | |
44 { | |
45 Expression dim; | |
46 | |
47 this(Type t, Expression dim) | |
48 { | |
49 super(TY.Tsarray, t); | |
50 //printf("TypeSArray(%s)\n", dim.toChars()); | |
51 this.dim = dim; | |
52 } | |
53 | |
54 version (DumbClone) { | |
55 } else { | |
56 Type clone() | |
57 { | |
58 assert(false); | |
59 } | |
60 } | |
61 | |
62 Type syntaxCopy() | |
63 { | |
41
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
64 Type t = next.syntaxCopy(); |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
65 Expression e = dim.syntaxCopy(); |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
66 t = new TypeSArray(t, e); |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
67 t.mod = mod; |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
68 return t; |
0 | 69 } |
70 | |
71 ulong size(Loc loc) | |
72 { | |
73 if (!dim) | |
74 return Type.size(loc); | |
75 | |
76 long sz = dim.toInteger(); | |
77 | |
78 { | |
79 long n, n2; | |
80 n = next.size(); | |
81 n2 = n * sz; | |
82 if (n && (n2 / n) != sz) | |
83 goto Loverflow; | |
84 | |
85 sz = n2; | |
86 } | |
87 return sz; | |
88 | |
89 Loverflow: | |
90 error(loc, "index %jd overflow for static array", sz); | |
91 return 1; | |
92 } | |
93 | |
94 uint alignsize() | |
95 { | |
96 return next.alignsize(); | |
97 } | |
98 | |
99 Type semantic(Loc loc, Scope sc) | |
100 { | |
101 //printf("TypeSArray.semantic() %s\n", toChars()); | |
102 | |
103 Type t; | |
104 Expression e; | |
105 Dsymbol s; | |
106 next.resolve(loc, sc, &e, &t, &s); | |
107 if (dim && s && s.isTupleDeclaration()) | |
108 { | |
109 TupleDeclaration sd = s.isTupleDeclaration(); | |
110 | |
111 dim = semanticLength(sc, sd, dim); | |
112 dim = dim.optimize(WANT.WANTvalue | WANT.WANTinterpret); | |
113 ulong d = dim.toUInteger(); | |
114 | |
115 if (d >= sd.objects.dim) | |
116 { error(loc, "tuple index %ju exceeds %u", d, sd.objects.dim); | |
117 return Type.terror; | |
118 } | |
119 ///Object o = cast(Object)sd.objects.data[(size_t)d]; | |
120 ///if (o.dyncast() != DYNCAST_TYPE) | |
121 ///{ | |
122 /// error(loc, "%s is not a type", toChars()); | |
123 /// return Type.terror; | |
124 ///} | |
125 ///t = cast(Type)o; | |
126 | |
127 t = cast(Type)sd.objects.data[cast(size_t)d]; | |
128 if (t is null) { | |
129 error(loc, "%s is not a type", toChars()); | |
130 return Type.terror; | |
131 } | |
132 return t; | |
133 } | |
134 | |
135 next = next.semantic(loc,sc); | |
136 transitive(); | |
137 | |
138 Type tbn = next.toBasetype(); | |
139 | |
140 if (dim) | |
141 { | |
142 long n, n2; | |
143 | |
144 dim = semanticLength(sc, tbn, dim); | |
145 | |
146 dim = dim.optimize(WANT.WANTvalue | WANT.WANTinterpret); | |
147 if (sc && sc.parameterSpecialization && dim.op == TOK.TOKvar && | |
148 (cast(VarExp)dim).var.storage_class & STC.STCtemplateparameter) | |
149 { | |
150 /* It could be a template parameter N which has no value yet: | |
151 * template Foo(T : T[N], size_t N); | |
152 */ | |
153 return this; | |
154 } | |
155 long d1 = dim.toInteger(); | |
156 dim = dim.castTo(sc, tsize_t); | |
157 dim = dim.optimize(WANT.WANTvalue); | |
158 long d2 = dim.toInteger(); | |
159 | |
160 if (d1 != d2) | |
161 goto Loverflow; | |
162 | |
163 if (tbn.isintegral() || | |
164 tbn.isfloating() || | |
165 tbn.ty == TY.Tpointer || | |
166 tbn.ty == TY.Tarray || | |
167 tbn.ty == TY.Tsarray || | |
168 tbn.ty == TY.Taarray || | |
169 tbn.ty == TY.Tclass) | |
170 { | |
171 /* Only do this for types that don't need to have semantic() | |
172 * run on them for the size, since they may be forward referenced. | |
173 */ | |
174 n = tbn.size(loc); | |
175 n2 = n * d2; | |
176 if (cast(int)n2 < 0) | |
177 goto Loverflow; | |
178 if (n2 >= 0x1000000) // put a 'reasonable' limit on it | |
179 goto Loverflow; | |
180 if (n && n2 / n != d2) | |
181 { | |
182 Loverflow: | |
183 error(loc, "index %jd overflow for static array", d1); | |
184 dim = new IntegerExp(Loc(0), 1, tsize_t); | |
185 } | |
186 } | |
187 } | |
188 switch (tbn.ty) | |
189 { | |
190 case TY.Ttuple: | |
191 { // Index the tuple to get the type | |
192 assert(dim); | |
193 TypeTuple tt = cast(TypeTuple)tbn; | |
194 ulong d = dim.toUInteger(); | |
195 | |
196 if (d >= tt.arguments.dim) | |
197 { | |
198 error(loc, "tuple index %ju exceeds %u", d, tt.arguments.dim); | |
199 return Type.terror; | |
200 } | |
201 Argument arg = cast(Argument)tt.arguments.data[cast(size_t)d]; | |
202 return arg.type; | |
203 } | |
204 case TY.Tstruct: | |
205 { TypeStruct ts = cast(TypeStruct)tbn; | |
206 if (ts.sym.isnested) | |
207 error(loc, "cannot have array of inner structs %s", ts.toChars()); | |
208 break; | |
209 } | |
210 case TY.Tfunction: | |
211 case TY.Tnone: | |
212 error(loc, "can't have array of %s", tbn.toChars()); | |
213 tbn = next = tint32; | |
214 break; | |
215 default: /// | |
216 break; | |
217 } | |
218 if (tbn.isauto()) | |
219 error(loc, "cannot have array of auto %s", tbn.toChars()); | |
220 return merge(); | |
221 } | |
222 | |
223 void resolve(Loc loc, Scope sc, Expression* pe, Type* pt, Dsymbol* ps) | |
224 { | |
41
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
225 //printf("TypeSArray.resolve() %s\n", toChars()); |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
226 next.resolve(loc, sc, pe, pt, ps); |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
227 //printf("s = %p, e = %p, t = %p\n", *ps, *pe, *pt); |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
228 if (*pe) |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
229 { |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
230 // It's really an index expression |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
231 Expression e = new IndexExp(loc, *pe, dim); |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
232 *pe = e; |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
233 } |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
234 else if (*ps) |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
235 { |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
236 Dsymbol s = *ps; |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
237 TupleDeclaration td = s.isTupleDeclaration(); |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
238 if (td) |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
239 { |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
240 ScopeDsymbol sym = new ArrayScopeSymbol(sc, td); |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
241 sym.parent = sc.scopesym; |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
242 sc = sc.push(sym); |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
243 |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
244 dim = dim.semantic(sc); |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
245 dim = dim.optimize(WANTvalue | WANTinterpret); |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
246 ulong d = dim.toUInteger(); |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
247 |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
248 sc = sc.pop(); |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
249 |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
250 if (d >= td.objects.dim) |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
251 { |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
252 error(loc, "tuple index %ju exceeds %u", d, td.objects.dim); |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
253 goto Ldefault; |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
254 } |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
255 Object o = cast(Object)td.objects.data[cast(size_t)d]; |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
256 if ((*ps = isDsymbol(o)) !is null) /// ! |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
257 { |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
258 return; |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
259 } |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
260 if ((*pe = isExpression(o)) !is null) /// ! |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
261 { |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
262 return; |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
263 } |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
264 |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
265 /* Create a new TupleDeclaration which |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
266 * is a slice [d..d+1] out of the old one. |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
267 * Do it this way because TemplateInstance.semanticTiargs() |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
268 * can handle unresolved Objects this way. |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
269 */ |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
270 Objects objects = new Objects; |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
271 objects.setDim(1); |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
272 objects.data[0] = cast(void*)o; |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
273 |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
274 TupleDeclaration tds = new TupleDeclaration(loc, td.ident, objects); |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
275 *ps = tds; |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
276 } |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
277 else |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
278 goto Ldefault; |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
279 } |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
280 else |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
281 { |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
282 Ldefault: |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
283 Type.resolve(loc, sc, pe, pt, ps); |
f23312cb6f2e
TypeSArray.syntaxCopy & TypeSArray.resolve implemented
korDen
parents:
12
diff
changeset
|
284 } |
0 | 285 } |
286 | |
287 void toDecoBuffer(OutBuffer buf, int flag) | |
288 { | |
289 Type.toDecoBuffer(buf, flag); | |
290 if (dim) | |
291 //buf.printf("%ju", dim.toInteger()); /// | |
292 buf.printf("%s", dim.toInteger()); | |
293 if (next) | |
294 /* Note that static arrays are value types, so | |
295 * for a parameter, propagate the 0x100 to the next | |
296 * level, since for T[4][3], any const should apply to the T, | |
297 * not the [4]. | |
298 */ | |
299 next.toDecoBuffer(buf, (flag & 0x100) ? flag : mod); | |
300 } | |
301 | |
302 void toCBuffer2(OutBuffer buf, HdrGenState* hgs, MOD mod) | |
303 { | |
304 assert(false); | |
305 } | |
306 | |
307 Expression dotExp(Scope sc, Expression e, Identifier ident) | |
308 { | |
309 version (LOGDOTEXP) { | |
310 printf("TypeSArray.dotExp(e = '%s', ident = '%s')\n", e.toChars(), ident.toChars()); | |
311 } | |
312 if (ident == Id.length) | |
313 { | |
314 e = dim; | |
315 } | |
316 else if (ident == Id.ptr) | |
317 { | |
318 e = e.castTo(sc, next.pointerTo()); | |
319 } | |
320 else | |
321 { | |
322 e = TypeArray.dotExp(sc, e, ident); | |
323 } | |
324 return e; | |
325 } | |
326 | |
12
832f71e6f96c
*Exp and *AssignExp arrayOp implementation added (might be a bit incomplete)
korDen
parents:
0
diff
changeset
|
327 bool isString() |
0 | 328 { |
329 assert(false); | |
330 } | |
331 | |
332 bool isZeroInit(Loc loc) | |
333 { | |
334 return next.isZeroInit(loc); | |
335 } | |
336 | |
337 uint memalign(uint salign) | |
338 { | |
339 return next.memalign(salign); | |
340 } | |
341 | |
342 MATCH constConv(Type to) | |
343 { | |
344 assert(false); | |
345 } | |
346 | |
347 MATCH implicitConvTo(Type to) | |
348 { | |
349 //printf("TypeSArray.implicitConvTo(to = %s) this = %s\n", to.toChars(), toChars()); | |
350 | |
351 // Allow implicit conversion of static array to pointer or dynamic array | |
352 if (IMPLICIT_ARRAY_TO_PTR && to.ty == Tpointer) | |
353 { | |
354 TypePointer tp = cast(TypePointer)to; | |
355 | |
356 if (next.mod != tp.next.mod && tp.next.mod != MODconst) | |
357 return MATCHnomatch; | |
358 | |
359 if (tp.next.ty == Tvoid || next.constConv(tp.next) != MATCHnomatch) | |
360 { | |
361 return MATCHconvert; | |
362 } | |
363 return MATCHnomatch; | |
364 } | |
365 if (to.ty == Tarray) | |
366 { | |
367 int offset = 0; | |
368 TypeDArray ta = cast(TypeDArray)to; | |
369 | |
370 if (next.mod != ta.next.mod && ta.next.mod != MODconst) | |
371 return MATCHnomatch; | |
372 | |
373 if (next.equals(ta.next) || | |
374 next.implicitConvTo(ta.next) >= MATCHconst || | |
375 (ta.next.isBaseOf(next, &offset) && offset == 0) || | |
376 ta.next.ty == Tvoid | |
377 ) | |
378 return MATCHconvert; | |
379 | |
380 return MATCHnomatch; | |
381 } | |
382 if (to.ty == Tsarray) | |
383 { | |
384 if (this == to) | |
385 return MATCHexact; | |
386 | |
387 TypeSArray tsa = cast(TypeSArray)to; | |
388 | |
389 if (dim.equals(tsa.dim)) | |
390 { | |
391 /* Since static arrays are value types, allow | |
392 * conversions from const elements to non-const | |
393 * ones, just like we allow conversion from const int | |
394 * to int. | |
395 */ | |
396 MATCH m = next.implicitConvTo(tsa.next); | |
397 if (m >= MATCHconst) | |
398 { | |
399 if (mod != to.mod) | |
400 m = MATCHconst; | |
401 return m; | |
402 } | |
403 } | |
404 } | |
405 return MATCHnomatch; | |
406 } | |
407 | |
408 Expression defaultInit(Loc loc) | |
409 { | |
410 version (LOGDEFAULTINIT) { | |
411 printf("TypeSArray.defaultInit() '%s'\n", toChars()); | |
412 } | |
413 return next.defaultInit(loc); | |
414 } | |
415 | |
416 dt_t** toDt(dt_t** pdt) | |
417 { | |
418 return toDtElem(pdt, null); | |
419 } | |
420 | |
421 dt_t** toDtElem(dt_t** pdt, Expression e) | |
422 { | |
423 int i; | |
424 | |
425 //printf("TypeSArray::toDtElem()\n"); | |
426 uint len = cast(uint)dim.toInteger(); | |
427 if (len) | |
428 { | |
429 while (*pdt) | |
430 pdt = &((*pdt).DTnext); | |
431 Type tnext = next; | |
432 Type tbn = tnext.toBasetype(); | |
433 while (tbn.ty == Tsarray) | |
434 { | |
435 TypeSArray tsa = cast(TypeSArray)tbn; | |
436 | |
437 len *= tsa.dim.toInteger(); | |
438 tnext = tbn.nextOf(); | |
439 tbn = tnext.toBasetype(); | |
440 } | |
441 if (!e) // if not already supplied | |
442 e = tnext.defaultInit(Loc(0)); // use default initializer | |
443 if (tbn.ty == Tstruct) | |
444 tnext.toDt(pdt); | |
445 else | |
446 e.toDt(pdt); | |
447 dt_optimize(*pdt); | |
448 if ((*pdt).dt == DT_azeros && !(*pdt).DTnext) | |
449 { | |
450 (*pdt).DTazeros *= len; | |
451 pdt = &((*pdt).DTnext); | |
452 } | |
453 else if ((*pdt).dt == DT_1byte && (*pdt).DTonebyte == 0 && !(*pdt).DTnext) | |
454 { | |
455 (*pdt).dt = DT_azeros; | |
456 (*pdt).DTazeros = len; | |
457 pdt = &((*pdt).DTnext); | |
458 } | |
459 else if (e.op != TOKstring) | |
460 { | |
461 for (i = 1; i < len; i++) | |
462 { | |
463 if (tbn.ty == Tstruct) | |
464 { | |
465 pdt = tnext.toDt(pdt); | |
466 while (*pdt) | |
467 pdt = &((*pdt).DTnext); | |
468 } | |
469 else | |
470 pdt = e.toDt(pdt); | |
471 } | |
472 } | |
473 } | |
474 return pdt; | |
475 } | |
476 | |
477 MATCH deduceType(Scope sc, Type tparam, TemplateParameters parameters, Objects dedtypes) | |
478 { | |
479 assert(false); | |
480 } | |
481 | |
482 TypeInfoDeclaration getTypeInfoDeclaration() | |
483 { | |
484 assert(false); | |
485 } | |
486 | |
487 Expression toExpression() | |
488 { | |
489 assert(false); | |
490 } | |
491 | |
492 bool hasPointers() | |
493 { | |
494 return next.hasPointers(); | |
495 } | |
496 | |
497 version (CPP_MANGLE) { | |
498 void toCppMangle(OutBuffer buf, CppMangleState* cms) | |
499 { | |
500 assert(false); | |
501 } | |
502 } | |
503 | |
504 type* toCtype() | |
505 { | |
506 if (!ctype) | |
507 { | |
508 type* tn = next.toCtype(); | |
509 ctype = type_allocn(TYarray, tn); | |
510 ctype.Tdim = cast(uint)dim.toInteger(); | |
511 } | |
512 | |
513 return ctype; | |
514 } | |
515 | |
516 type* toCParamtype() | |
517 { | |
518 // arrays are passed as pointers | |
519 return next.pointerTo().toCtype(); | |
520 } | |
521 } |