# HG changeset patch # User korDen # Date 1282360633 -14400 # Node ID f23312cb6f2e7cd0dc34eccbf5f8f588ba925cba # Parent caa9bdb08ae601bb4112e0a76f2e790f08063ff2 TypeSArray.syntaxCopy & TypeSArray.resolve implemented diff -r caa9bdb08ae6 -r f23312cb6f2e dmd/TypeSArray.d --- a/dmd/TypeSArray.d Sat Aug 21 07:10:53 2010 +0400 +++ b/dmd/TypeSArray.d Sat Aug 21 07:17:13 2010 +0400 @@ -24,9 +24,12 @@ import dmd.ArrayTypes; import dmd.WANT; import dmd.TypeInfoDeclaration; +import dmd.ScopeDsymbol; +import dmd.ArrayScopeSymbol; import dmd.TY; import dmd.Util; import dmd.Id; +import dmd.IndexExp; import dmd.type.Util; @@ -58,7 +61,11 @@ Type syntaxCopy() { - assert(false); + Type t = next.syntaxCopy(); + Expression e = dim.syntaxCopy(); + t = new TypeSArray(t, e); + t.mod = mod; + return t; } ulong size(Loc loc) @@ -215,7 +222,66 @@ void resolve(Loc loc, Scope sc, Expression* pe, Type* pt, Dsymbol* ps) { - assert(false); + //printf("TypeSArray.resolve() %s\n", toChars()); + next.resolve(loc, sc, pe, pt, ps); + //printf("s = %p, e = %p, t = %p\n", *ps, *pe, *pt); + if (*pe) + { + // It's really an index expression + Expression e = new IndexExp(loc, *pe, dim); + *pe = e; + } + else if (*ps) + { + Dsymbol s = *ps; + TupleDeclaration td = s.isTupleDeclaration(); + if (td) + { + ScopeDsymbol sym = new ArrayScopeSymbol(sc, td); + sym.parent = sc.scopesym; + sc = sc.push(sym); + + dim = dim.semantic(sc); + dim = dim.optimize(WANTvalue | WANTinterpret); + ulong d = dim.toUInteger(); + + sc = sc.pop(); + + if (d >= td.objects.dim) + { + error(loc, "tuple index %ju exceeds %u", d, td.objects.dim); + goto Ldefault; + } + Object o = cast(Object)td.objects.data[cast(size_t)d]; + if ((*ps = isDsymbol(o)) !is null) /// ! + { + return; + } + if ((*pe = isExpression(o)) !is null) /// ! + { + return; + } + + /* Create a new TupleDeclaration which + * is a slice [d..d+1] out of the old one. + * Do it this way because TemplateInstance.semanticTiargs() + * can handle unresolved Objects this way. + */ + Objects objects = new Objects; + objects.setDim(1); + objects.data[0] = cast(void*)o; + + TupleDeclaration tds = new TupleDeclaration(loc, td.ident, objects); + *ps = tds; + } + else + goto Ldefault; + } + else + { + Ldefault: + Type.resolve(loc, sc, pe, pt, ps); + } } void toDecoBuffer(OutBuffer buf, int flag)