# HG changeset patch # User Trass3r # Date 1283285332 -7200 # Node ID ceda59b4d2557be595ec852e2b58187056cfefa7 # Parent 6da99741178e2d582cb4f477ea9d6d26675d8ae4 expression.c changes, now only ddoc should be left diff -r 6da99741178e -r ceda59b4d255 dmd/AddrExp.d --- a/dmd/AddrExp.d Tue Aug 31 21:41:01 2010 +0200 +++ b/dmd/AddrExp.d Tue Aug 31 22:08:52 2010 +0200 @@ -65,7 +65,6 @@ return new ErrorExp(); } - //printf("test3 deco = %p\n", e1.type.deco); type = e1.type.pointerTo(); // See if this should really be a delegate diff -r 6da99741178e -r ceda59b4d255 dmd/AndExp.d --- a/dmd/AndExp.d Tue Aug 31 21:41:01 2010 +0200 +++ b/dmd/AndExp.d Tue Aug 31 22:08:52 2010 +0200 @@ -49,11 +49,10 @@ else { typeCombine(sc); - if (e1.op != TOK.TOKslice && e2.op != TOK.TOKslice) - { + if (!e1.isArrayOperand()) e1.checkIntegral(); + if (!e2.isArrayOperand()) e2.checkIntegral(); - } } } return this; diff -r 6da99741178e -r ceda59b4d255 dmd/AssocArrayLiteralExp.d --- a/dmd/AssocArrayLiteralExp.d Tue Aug 31 21:41:01 2010 +0200 +++ b/dmd/AssocArrayLiteralExp.d Tue Aug 31 22:08:52 2010 +0200 @@ -57,6 +57,9 @@ printf("AssocArrayLiteralExp.semantic('%s')\n", toChars()); } + if (type) + return this; + // Run semantic() on each element for (size_t i = 0; i < keys.dim; i++) { auto key = keys[i]; diff -r 6da99741178e -r ceda59b4d255 dmd/CallExp.d --- a/dmd/CallExp.d Tue Aug 31 21:41:01 2010 +0200 +++ b/dmd/CallExp.d Tue Aug 31 22:08:52 2010 +0200 @@ -184,7 +184,8 @@ return new RemoveExp(loc, dotid.e1, key); } - else if (e1ty == TY.Tarray || e1ty == TY.Tsarray || e1ty == TY.Taarray) + else if (e1ty == TY.Tarray || e1ty == TY.Tsarray || + (e1ty == Taarray && dotid.ident != Id.apply && dotid.ident != Id.applyReverse)) { if (!arguments) arguments = new Expressions(); diff -r 6da99741178e -r ceda59b4d255 dmd/CastExp.d --- a/dmd/CastExp.d Tue Aug 31 21:41:01 2010 +0200 +++ b/dmd/CastExp.d Tue Aug 31 22:08:52 2010 +0200 @@ -106,6 +106,12 @@ } } + if (e1.op == TOKtemplate) + { + error("cannot cast template %s to type %s", e1.toChars(), to.toChars()); + return new ErrorExp(); + } + Type t1b = e1.type.toBasetype(); Type tob = to.toBasetype(); if (tob.ty == TY.Tstruct && diff -r 6da99741178e -r ceda59b4d255 dmd/DivExp.d --- a/dmd/DivExp.d Tue Aug 31 21:41:01 2010 +0200 +++ b/dmd/DivExp.d Tue Aug 31 22:08:52 2010 +0200 @@ -41,11 +41,11 @@ return e; typeCombine(sc); - if (e1.op != TOK.TOKslice && e2.op != TOK.TOKslice) - { + if (!e1.isArrayOperand()) e1.checkArithmetic(); + if (!e2.isArrayOperand()) e2.checkArithmetic(); - } + if (type.isfloating()) { Type t1 = e1.type; diff -r 6da99741178e -r ceda59b4d255 dmd/DotIdExp.d --- a/dmd/DotIdExp.d Tue Aug 31 21:41:01 2010 +0200 +++ b/dmd/DotIdExp.d Tue Aug 31 22:08:52 2010 +0200 @@ -337,11 +337,13 @@ */ uint errors = global.errors; global.gag++; + Type t1 = e1.type; e = e1.type.dotExp(sc, e1, ident); global.gag--; if (errors != global.errors) // if failed to find the property { global.errors = errors; + e1.type = t1; // kludge to restore type e = new DotIdExp(loc, new IdentifierExp(loc, Id.empty), ident); e = new CallExp(loc, e, e1); } diff -r 6da99741178e -r ceda59b4d255 dmd/Expression.d --- a/dmd/Expression.d Tue Aug 31 21:41:01 2010 +0200 +++ b/dmd/Expression.d Tue Aug 31 22:08:52 2010 +0200 @@ -135,6 +135,11 @@ if (t.ty == TY.Tfunction || e.op == TOK.TOKoverloadset) { +static if(false) +{ + if (t.ty == Tfunction && !(cast(TypeFunction)t).isproperty) + error(e.loc, "not a property %s\n", e.toChars()); +} e = new CallExp(e.loc, e); e = e.semantic(sc); } @@ -737,14 +742,13 @@ Expression checkToPointer() { - Expression e; - Type tb; + //writef("Expression::checkToPointer()\n"); + Expression e = this; - //printf("Expression::checkToPointer()\n"); - e = this; - +version(SARRAYVALUE) {} else +{ // If C static array, convert to pointer - tb = type.toBasetype(); + Type tb = type.toBasetype(); if (tb.ty == Tsarray) { TypeSArray ts = cast(TypeSArray)tb; @@ -754,6 +758,7 @@ e = new AddrExp(loc, this); e.type = ts.next.pointerTo(); } +} return e; } diff -r 6da99741178e -r ceda59b4d255 dmd/IntegerExp.d --- a/dmd/IntegerExp.d Tue Aug 31 21:41:01 2010 +0200 +++ b/dmd/IntegerExp.d Tue Aug 31 22:08:52 2010 +0200 @@ -168,11 +168,7 @@ */ if (!global.errors) { - printf("ty = %d, %d\n", type.ty, t.ty); - if (type.ty == Tenum) { - printf("test1\n"); - } - ///type.print(); + writef("%s %p\n", type.toChars(), type); assert(0); } break; diff -r 6da99741178e -r ceda59b4d255 dmd/IsExp.d --- a/dmd/IsExp.d Tue Aug 31 21:41:01 2010 +0200 +++ b/dmd/IsExp.d Tue Aug 31 22:08:52 2010 +0200 @@ -83,6 +83,7 @@ Type tded; /* is(targ id tok tspec) + * is(targ id : tok2) * is(targ id == tok2) */ @@ -238,14 +239,13 @@ * If true, declare id as an alias for the specialized type. */ - MATCH m; assert(parameters && parameters.dim); scope Objects dedtypes = new Objects(); dedtypes.setDim(parameters.dim); dedtypes.zero(); - m = targ.deduceType(null, tspec, parameters, dedtypes); + MATCH m = targ.deduceType(null, tspec, parameters, dedtypes); if (m == MATCHnomatch || (m != MATCHexact && tok == TOKequal)) { diff -r 6da99741178e -r ceda59b4d255 dmd/ModExp.d --- a/dmd/ModExp.d Tue Aug 31 21:41:01 2010 +0200 +++ b/dmd/ModExp.d Tue Aug 31 22:08:52 2010 +0200 @@ -40,11 +40,11 @@ return e; typeCombine(sc); - if (e1.op != TOKslice && e2.op != TOKslice) - { + if (!e1.isArrayOperand()) e1.checkArithmetic(); + if (!e2.isArrayOperand()) e2.checkArithmetic(); - } + if (type.isfloating()) { type = e1.type; diff -r 6da99741178e -r ceda59b4d255 dmd/MulExp.d --- a/dmd/MulExp.d Tue Aug 31 21:41:01 2010 +0200 +++ b/dmd/MulExp.d Tue Aug 31 22:08:52 2010 +0200 @@ -46,11 +46,11 @@ return e; typeCombine(sc); - if (e1.op != TOKslice && e2.op != TOKslice) - { + if (!e1.isArrayOperand()) e1.checkArithmetic(); + if (!e2.isArrayOperand()) e2.checkArithmetic(); - } + if (type.isfloating()) { Type t1 = e1.type; diff -r 6da99741178e -r ceda59b4d255 dmd/NegExp.d --- a/dmd/NegExp.d Tue Aug 31 21:41:01 2010 +0200 +++ b/dmd/NegExp.d Tue Aug 31 22:08:52 2010 +0200 @@ -41,7 +41,7 @@ return e; e1.checkNoBool(); - if (e1.op != TOKslice) + if (!e1.isArrayOperand()) e1.checkArithmetic(); type = e1.type; diff -r 6da99741178e -r ceda59b4d255 dmd/OrExp.d --- a/dmd/OrExp.d Tue Aug 31 21:41:01 2010 +0200 +++ b/dmd/OrExp.d Tue Aug 31 22:08:52 2010 +0200 @@ -48,11 +48,10 @@ else { typeCombine(sc); - if (e1.op != TOK.TOKslice && e2.op != TOK.TOKslice) - { + if (!e1.isArrayOperand()) e1.checkIntegral(); + if (!e2.isArrayOperand()) e2.checkIntegral(); - } } } diff -r 6da99741178e -r ceda59b4d255 dmd/StructLiteralExp.d --- a/dmd/StructLiteralExp.d Tue Aug 31 21:41:01 2010 +0200 +++ b/dmd/StructLiteralExp.d Tue Aug 31 22:08:52 2010 +0200 @@ -20,6 +20,7 @@ import dmd.OutBuffer; import dmd.Loc; import dmd.Scope; +import dmd.Initializer; import dmd.InlineCostState; import dmd.IRState; import dmd.InlineDoState; @@ -138,7 +139,18 @@ { e = v.init.toExpression(); if (!e) + { error("cannot make expression out of initializer for %s", v.toChars()); + e = new ErrorExp(); + } + else if (v.scope_) + { + // Do deferred semantic anaylsis + Initializer i2 = v.init.syntaxCopy(); + i2 = i2.semantic(v.scope_, v.type); + e = i2.toExpression(); + v.scope_ = null; + } } else { @@ -154,6 +166,10 @@ return this; } + /************************************** + * Gets expression at offset of type. + * Returns null if not found. + */ Expression getField(Type type, uint offset) { //printf("StructLiteralExp.getField(this = %s, type = %s, offset = %u)\n", diff -r 6da99741178e -r ceda59b4d255 dmd/VarExp.d --- a/dmd/VarExp.d Tue Aug 31 21:41:01 2010 +0200 +++ b/dmd/VarExp.d Tue Aug 31 22:08:52 2010 +0200 @@ -216,8 +216,8 @@ override Expression modifiableLvalue(Scope sc, Expression e) { //printf("VarExp::modifiableLvalue('%s')\n", var.toChars()); - if (type && type.toBasetype().ty == TY.Tsarray) - error("cannot change reference to static array '%s'", var.toChars()); + //if (type && type.toBasetype().ty == TY.Tsarray) + // error("cannot change reference to static array '%s'", var.toChars()); var.checkModify(loc, sc, type); diff -r 6da99741178e -r ceda59b4d255 dmd/XorExp.d --- a/dmd/XorExp.d Tue Aug 31 21:41:01 2010 +0200 +++ b/dmd/XorExp.d Tue Aug 31 22:08:52 2010 +0200 @@ -47,11 +47,10 @@ else { typeCombine(sc); - if (e1.op != TOKslice && e2.op != TOKslice) - { + if (!e1.isArrayOperand()) e1.checkIntegral(); + if (!e2.isArrayOperand()) e2.checkIntegral(); - } } } return this; diff -r 6da99741178e -r ceda59b4d255 dmd/expression/Util.d --- a/dmd/expression/Util.d Tue Aug 31 21:41:01 2010 +0200 +++ b/dmd/expression/Util.d Tue Aug 31 22:08:52 2010 +0200 @@ -631,6 +631,8 @@ if (p.type != arg.type) { //printf("arg.type = %s, p.type = %s\n", arg.type.toChars(), p.type.toChars()); + if (arg.op == TOKtype) + arg.error("cannot pass type %s as function argument", arg.toChars()); arg = arg.implicitCastTo(sc, p.type); arg = arg.optimize(WANT.WANTvalue); } @@ -644,12 +646,15 @@ arg = arg.modifiableLvalue(sc, arg); } + tb = arg.type.toBasetype(); +version(SARRAYVALUE) {} else +{ // Convert static arrays to pointers - tb = arg.type.toBasetype(); if (tb.ty == TY.Tsarray) { arg = arg.checkToPointer(); } +} version (DMDV2) { if (tb.ty == TY.Tstruct && !(p.storageClass & (STC.STCref | STC.STCout))) {