Mercurial > projects > ddmd
view dmd/TypeSlice.d @ 8:d42cd5917df4
wysiwyg strings, alias this, templates, TypeSlice implementation
author | dkoroskin <> |
---|---|
date | Mon, 14 Dec 2009 17:43:43 +0300 |
parents | 10317f0c89a5 |
children | 38a17310d587 |
line wrap: on
line source
module dmd.TypeSlice; import dmd.Type; import dmd.TypeNext; import dmd.MOD; import dmd.Expression; import dmd.Loc; import dmd.Scope; import dmd.Dsymbol; import dmd.OutBuffer; import dmd.HdrGenState; import dmd.TY; import dmd.TypeTuple; import dmd.WANT; import dmd.ArrayTypes; import dmd.Argument; import dmd.type.Util; class TypeSlice : TypeNext { Expression lwr; Expression upr; this(Type next, Expression lwr, Expression upr) { super(TY.Tslice, next); //printf("TypeSlice[%s .. %s]\n", lwr.toChars(), upr.toChars()); this.lwr = lwr; this.upr = upr; } version (DumbClone) { } else { Type clone() { assert(false); } } Type syntaxCopy() { Type t = new TypeSlice(next.syntaxCopy(), lwr.syntaxCopy(), upr.syntaxCopy()); t.mod = mod; return t; } Type semantic(Loc loc, Scope sc) { //printf("TypeSlice.semantic() %s\n", toChars()); next = next.semantic(loc, sc); transitive(); //printf("next: %s\n", next.toChars()); Type tbn = next.toBasetype(); if (tbn.ty != Ttuple) { error(loc, "can only slice tuple types, not %s", tbn.toChars()); return Type.terror; } TypeTuple tt = cast(TypeTuple)tbn; lwr = semanticLength(sc, tbn, lwr); lwr = lwr.optimize(WANTvalue); ulong i1 = lwr.toUInteger(); upr = semanticLength(sc, tbn, upr); upr = upr.optimize(WANTvalue); ulong i2 = upr.toUInteger(); if (!(i1 <= i2 && i2 <= tt.arguments.dim)) { error(loc, "slice [%ju..%ju] is out of range of [0..%u]", i1, i2, tt.arguments.dim); return Type.terror; } Arguments args = new Arguments; args.reserve(cast(size_t)(i2 - i1)); for (size_t i = cast(size_t)i1; i < cast(size_t)i2; i++) { Argument arg = cast(Argument)tt.arguments.data[i]; args.push(cast(void*)arg); } return new TypeTuple(args); } void resolve(Loc loc, Scope sc, Expression* pe, Type* pt, Dsymbol* ps) { assert(false); } void toCBuffer2(OutBuffer buf, HdrGenState* hgs, MOD mod) { assert(false); } }