comparison 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
comparison
equal deleted inserted replaced
40:caa9bdb08ae6 41:f23312cb6f2e
22 import dmd.TypeDArray; 22 import dmd.TypeDArray;
23 import dmd.TypePointer; 23 import dmd.TypePointer;
24 import dmd.ArrayTypes; 24 import dmd.ArrayTypes;
25 import dmd.WANT; 25 import dmd.WANT;
26 import dmd.TypeInfoDeclaration; 26 import dmd.TypeInfoDeclaration;
27 import dmd.ScopeDsymbol;
28 import dmd.ArrayScopeSymbol;
27 import dmd.TY; 29 import dmd.TY;
28 import dmd.Util; 30 import dmd.Util;
29 import dmd.Id; 31 import dmd.Id;
32 import dmd.IndexExp;
30 33
31 import dmd.type.Util; 34 import dmd.type.Util;
32 35
33 import dmd.backend.dt_t; 36 import dmd.backend.dt_t;
34 import dmd.backend.TYPE; 37 import dmd.backend.TYPE;
56 } 59 }
57 } 60 }
58 61
59 Type syntaxCopy() 62 Type syntaxCopy()
60 { 63 {
61 assert(false); 64 Type t = next.syntaxCopy();
65 Expression e = dim.syntaxCopy();
66 t = new TypeSArray(t, e);
67 t.mod = mod;
68 return t;
62 } 69 }
63 70
64 ulong size(Loc loc) 71 ulong size(Loc loc)
65 { 72 {
66 if (!dim) 73 if (!dim)
213 return merge(); 220 return merge();
214 } 221 }
215 222
216 void resolve(Loc loc, Scope sc, Expression* pe, Type* pt, Dsymbol* ps) 223 void resolve(Loc loc, Scope sc, Expression* pe, Type* pt, Dsymbol* ps)
217 { 224 {
218 assert(false); 225 //printf("TypeSArray.resolve() %s\n", toChars());
226 next.resolve(loc, sc, pe, pt, ps);
227 //printf("s = %p, e = %p, t = %p\n", *ps, *pe, *pt);
228 if (*pe)
229 {
230 // It's really an index expression
231 Expression e = new IndexExp(loc, *pe, dim);
232 *pe = e;
233 }
234 else if (*ps)
235 {
236 Dsymbol s = *ps;
237 TupleDeclaration td = s.isTupleDeclaration();
238 if (td)
239 {
240 ScopeDsymbol sym = new ArrayScopeSymbol(sc, td);
241 sym.parent = sc.scopesym;
242 sc = sc.push(sym);
243
244 dim = dim.semantic(sc);
245 dim = dim.optimize(WANTvalue | WANTinterpret);
246 ulong d = dim.toUInteger();
247
248 sc = sc.pop();
249
250 if (d >= td.objects.dim)
251 {
252 error(loc, "tuple index %ju exceeds %u", d, td.objects.dim);
253 goto Ldefault;
254 }
255 Object o = cast(Object)td.objects.data[cast(size_t)d];
256 if ((*ps = isDsymbol(o)) !is null) /// !
257 {
258 return;
259 }
260 if ((*pe = isExpression(o)) !is null) /// !
261 {
262 return;
263 }
264
265 /* Create a new TupleDeclaration which
266 * is a slice [d..d+1] out of the old one.
267 * Do it this way because TemplateInstance.semanticTiargs()
268 * can handle unresolved Objects this way.
269 */
270 Objects objects = new Objects;
271 objects.setDim(1);
272 objects.data[0] = cast(void*)o;
273
274 TupleDeclaration tds = new TupleDeclaration(loc, td.ident, objects);
275 *ps = tds;
276 }
277 else
278 goto Ldefault;
279 }
280 else
281 {
282 Ldefault:
283 Type.resolve(loc, sc, pe, pt, ps);
284 }
219 } 285 }
220 286
221 void toDecoBuffer(OutBuffer buf, int flag) 287 void toDecoBuffer(OutBuffer buf, int flag)
222 { 288 {
223 Type.toDecoBuffer(buf, flag); 289 Type.toDecoBuffer(buf, flag);