Mercurial > projects > ddmd
diff dmd/TypeAArray.d @ 51:b7d29f613539
StaticAssertStatement.syntaxCopy
IfStatement.syntaxCopy
CompoundDeclarationStatement.syntaxCopy
VoidInitializer.syntaxCopy
TypeAArray.syntaxCopy
TypeTypeof.syntaxCopy
TypeAArray.resolve
TypeSArray.deduceType
TypeAArray.deduceType
TypeAArray.implicitConvTo
TemplateDeclaration.leastAsSpecialized
TemplateTypeParameter.dummyArg
TypeIdentifier.deduceType
TemplateTypeParameter.syntaxCopy
Lexer.hexStringConstant
Lexer.delimitedStringConstant
GotoDefaultStatement.ctor
CaseRangeStatement.ctor
Type.castMod
StorageClassDeclaration.syntaxCopy
TemplateDeclaration.syntaxCopy
author | korDen |
---|---|
date | Sat, 21 Aug 2010 11:17:42 +0400 |
parents | 2cc604139636 |
children | f708f0452e81 |
line wrap: on
line diff
--- a/dmd/TypeAArray.d Sat Aug 21 10:38:26 2010 +0400 +++ b/dmd/TypeAArray.d Sat Aug 21 11:17:42 2010 +0400 @@ -49,7 +49,16 @@ Type syntaxCopy() { - assert(false); + Type t = next.syntaxCopy(); + Type ti = index.syntaxCopy(); + if (t == next && ti == index) + t = this; + else + { + t = new TypeAArray(t, ti); + t.mod = mod; + } + return t; } version (DumbClone) { @@ -137,7 +146,30 @@ void resolve(Loc loc, Scope sc, Expression* pe, Type* pt, Dsymbol* ps) { - assert(false); + //printf("TypeAArray.resolve() %s\n", toChars()); + + // Deal with the case where we thought the index was a type, but + // in reality it was an expression. + if (index.ty == Tident || index.ty == Tinstance || index.ty == Tsarray) + { + Expression e; + Type t; + Dsymbol s; + + index.resolve(loc, sc, &e, &t, &s); + if (e) + { // It was an expression - + // Rewrite as a static array + + TypeSArray tsa = new TypeSArray(next, e); + return tsa.resolve(loc, sc, pe, pt, ps); + } + else if (t) + index = t; + else + index.error(loc, "index is not a type or an expression"); + } + Type.resolve(loc, sc, pe, pt, ps); } void toDecoBuffer(OutBuffer buf, int flag) @@ -236,7 +268,22 @@ MATCH deduceType(Scope sc, Type tparam, TemplateParameters parameters, Objects dedtypes) { - assert(false); +static if (false) { + printf("TypeAArray.deduceType()\n"); + printf("\tthis = %d, ", ty); print(); + printf("\ttparam = %d, ", tparam.ty); tparam.print(); +} + + // Extra check that index type must match + if (tparam && tparam.ty == Taarray) + { + TypeAArray tp = cast(TypeAArray)tparam; + if (!index.deduceType(sc, tp.index, parameters, dedtypes)) + { + return MATCHnomatch; + } + } + return Type.deduceType(sc, tparam, parameters, dedtypes); } bool isZeroInit(Loc loc) @@ -261,7 +308,32 @@ MATCH implicitConvTo(Type to) { - assert(false); + //printf("TypeAArray.implicitConvTo(to = %s) this = %s\n", to.toChars(), toChars()); + if (equals(to)) + return MATCHexact; + + if (to.ty == Taarray) + { + TypeAArray ta = cast(TypeAArray)to; + + if (!(next.mod == ta.next.mod || ta.next.mod == MODconst)) + return MATCHnomatch; // not const-compatible + + if (!(index.mod == ta.index.mod || ta.index.mod == MODconst)) + return MATCHnomatch; // not const-compatible + + MATCH m = next.constConv(ta.next); + MATCH mi = index.constConv(ta.index); + if (m != MATCHnomatch && mi != MATCHnomatch) + { + if (m == MATCHexact && mod != to.mod) + m = MATCHconst; + if (mi < m) + m = mi; + return m; + } + } + return Type.implicitConvTo(to); } MATCH constConv(Type to)