# HG changeset patch # User korDen # Date 1282378547 -14400 # Node ID a8b50ff7f201f971ec813f60ebb850c0073263b0 # Parent 69d078c417c6d3b958d3f5a9c103dc1b5071ee32 ForeachStatement.syntaxCopy SliceExp.syntaxCopy AnonDeclaration.syntaxCopy SwitchStatement.syntaxCopy CaseStatement.syntaxCopy BreakStatement.syntaxCopy ThrowStatement.syntaxCopy NewExp.syntaxCopy DefaultStatement.syntaxCopy AssertExp.syntaxCopy ClassDeclaration.syntaxCopy TypeTypedef.constConv eval_builtin ComplexExp.isConst DVCondition.syntaxCopy OrExp.getIntRange AndExp.getIntRange getMask IntegerExp.getIntRange Type.sizemask CastExp.getIntRange Expression.getIntRange diff -r 69d078c417c6 -r a8b50ff7f201 dmd/AndExp.d --- a/dmd/AndExp.d Sat Aug 21 11:50:50 2010 +0400 +++ b/dmd/AndExp.d Sat Aug 21 12:15:47 2010 +0400 @@ -95,7 +95,35 @@ IntRange getIntRange() { - assert(false); + IntRange ir; + IntRange ir1 = e1.getIntRange(); + IntRange ir2 = e2.getIntRange(); + + ir.imin = ir1.imin; + if (ir2.imin < ir.imin) + ir.imin = ir2.imin; + + ir.imax = ir1.imax; + if (ir2.imax > ir.imax) + ir.imax = ir2.imax; + + ulong u; + + u = getMask(ir1.imax); + ir.imin &= u; + ir.imax &= u; + + u = getMask(ir2.imax); + ir.imin &= u; + ir.imax &= u; + + ir.imin &= type.sizemask(); + ir.imax &= type.sizemask(); + + //printf("AndExp: imin = x%llx, imax = x%llx\n", ir.imin, ir.imax); + //e1.dump(0); + + return ir; } bool isCommutative() diff -r 69d078c417c6 -r a8b50ff7f201 dmd/AnonDeclaration.d --- a/dmd/AnonDeclaration.d Sat Aug 21 11:50:50 2010 +0400 +++ b/dmd/AnonDeclaration.d Sat Aug 21 12:15:47 2010 +0400 @@ -27,7 +27,11 @@ Dsymbol syntaxCopy(Dsymbol s) { - assert(false); + AnonDeclaration ad; + + assert(!s); + ad = new AnonDeclaration(loc, isunion, Dsymbol.arraySyntaxCopy(decl)); + return ad; } void semantic(Scope sc) diff -r 69d078c417c6 -r a8b50ff7f201 dmd/AssertExp.d --- a/dmd/AssertExp.d Sat Aug 21 11:50:50 2010 +0400 +++ b/dmd/AssertExp.d Sat Aug 21 12:15:47 2010 +0400 @@ -52,7 +52,9 @@ Expression syntaxCopy() { - assert(false); + AssertExp ae = new AssertExp(loc, e1.syntaxCopy(), + msg ? msg.syntaxCopy() : null); + return ae; } Expression semantic(Scope sc) diff -r 69d078c417c6 -r a8b50ff7f201 dmd/BUILTIN.d --- a/dmd/BUILTIN.d Sat Aug 21 11:50:50 2010 +0400 +++ b/dmd/BUILTIN.d Sat Aug 21 12:15:47 2010 +0400 @@ -9,4 +9,7 @@ BUILTINtan, // std.math.tan BUILTINsqrt, // std.math.sqrt BUILTINfabs, // std.math.fabs -} \ No newline at end of file +} + +import dmd.EnumUtils; +mixin(BringToCurrentScope!(BUILTIN)); \ No newline at end of file diff -r 69d078c417c6 -r a8b50ff7f201 dmd/BreakStatement.d --- a/dmd/BreakStatement.d Sat Aug 21 11:50:50 2010 +0400 +++ b/dmd/BreakStatement.d Sat Aug 21 12:15:47 2010 +0400 @@ -32,7 +32,8 @@ Statement syntaxCopy() { - assert(false); + BreakStatement s = new BreakStatement(loc, ident); + return s; } Statement semantic(Scope sc) diff -r 69d078c417c6 -r a8b50ff7f201 dmd/CaseStatement.d --- a/dmd/CaseStatement.d Sat Aug 21 11:50:50 2010 +0400 +++ b/dmd/CaseStatement.d Sat Aug 21 12:15:47 2010 +0400 @@ -44,7 +44,8 @@ Statement syntaxCopy() { - assert(false); + CaseStatement s = new CaseStatement(loc, exp.syntaxCopy(), statement.syntaxCopy()); + return s; } Statement semantic(Scope sc) diff -r 69d078c417c6 -r a8b50ff7f201 dmd/CastExp.d --- a/dmd/CastExp.d Sat Aug 21 11:50:50 2010 +0400 +++ b/dmd/CastExp.d Sat Aug 21 12:15:47 2010 +0400 @@ -193,7 +193,29 @@ IntRange getIntRange() { - assert(false); + IntRange ir; + ir = e1.getIntRange(); + // Do sign extension + switch (e1.type.toBasetype().ty) + { + case Tint8: + if (ir.imax & 0x80) + ir.imax |= 0xFFFFFFFFFFFFFF00UL; + break; + case Tint16: + if (ir.imax & 0x8000) + ir.imax |= 0xFFFFFFFFFFFF0000UL; + break; + case Tint32: + if (ir.imax & 0x80000000) + ir.imax |= 0xFFFFFFFF00000000UL; + break; + default: + } + ir.imin &= type.sizemask(); + ir.imax &= type.sizemask(); + //printf("CastExp: imin = x%llx, imax = x%llx\n", ir.imin, ir.imax); + return ir; } Expression optimize(int result) diff -r 69d078c417c6 -r a8b50ff7f201 dmd/ClassDeclaration.d --- a/dmd/ClassDeclaration.d Sat Aug 21 11:50:50 2010 +0400 +++ b/dmd/ClassDeclaration.d Sat Aug 21 12:15:47 2010 +0400 @@ -283,7 +283,26 @@ Dsymbol syntaxCopy(Dsymbol s) { - assert(false); + ClassDeclaration cd; + + //printf("ClassDeclaration.syntaxCopy('%s')\n", toChars()); + if (s) + cd = cast(ClassDeclaration)s; + else + cd = new ClassDeclaration(loc, ident, null); + + cd.storage_class |= storage_class; + + cd.baseclasses.setDim(this.baseclasses.dim); + for (int i = 0; i < cd.baseclasses.dim; i++) + { + BaseClass b = cast(BaseClass)this.baseclasses.data[i]; + BaseClass b2 = new BaseClass(b.type.syntaxCopy(), b.protection); + cd.baseclasses.data[i] = cast(void*)b2; + } + + ScopeDsymbol.syntaxCopy(cd); + return cd; } void semantic(Scope sc) diff -r 69d078c417c6 -r a8b50ff7f201 dmd/ComplexExp.d --- a/dmd/ComplexExp.d Sat Aug 21 11:50:50 2010 +0400 +++ b/dmd/ComplexExp.d Sat Aug 21 12:15:47 2010 +0400 @@ -99,7 +99,7 @@ int isConst() { - assert(false); + return 1; } bool isBool(bool result) diff -r 69d078c417c6 -r a8b50ff7f201 dmd/DVCondition.d --- a/dmd/DVCondition.d Sat Aug 21 11:50:50 2010 +0400 +++ b/dmd/DVCondition.d Sat Aug 21 12:15:47 2010 +0400 @@ -21,6 +21,6 @@ Condition syntaxCopy() { - assert(false); + return this; // don't need to copy } } \ No newline at end of file diff -r 69d078c417c6 -r a8b50ff7f201 dmd/DefaultStatement.d --- a/dmd/DefaultStatement.d Sat Aug 21 11:50:50 2010 +0400 +++ b/dmd/DefaultStatement.d Sat Aug 21 12:15:47 2010 +0400 @@ -32,7 +32,8 @@ Statement syntaxCopy() { - assert(false); + DefaultStatement s = new DefaultStatement(loc, statement.syntaxCopy()); + return s; } Statement semantic(Scope sc) diff -r 69d078c417c6 -r a8b50ff7f201 dmd/Expression.d --- a/dmd/Expression.d Sat Aug 21 11:50:50 2010 +0400 +++ b/dmd/Expression.d Sat Aug 21 12:15:47 2010 +0400 @@ -515,7 +515,10 @@ IntRange getIntRange() { - assert(false); + IntRange ir; + ir.imin = 0; + ir.imax = type.sizemask(); + return ir; } /************************************** diff -r 69d078c417c6 -r a8b50ff7f201 dmd/ForeachStatement.d --- a/dmd/ForeachStatement.d Sat Aug 21 11:50:50 2010 +0400 +++ b/dmd/ForeachStatement.d Sat Aug 21 12:15:47 2010 +0400 @@ -99,7 +99,11 @@ Statement syntaxCopy() { - assert(false); + Arguments args = Argument.arraySyntaxCopy(arguments); + Expression exp = aggr.syntaxCopy(); + ForeachStatement s = new ForeachStatement(loc, op, args, exp, + body_ ? body_.syntaxCopy() : null); + return s; } Statement semantic(Scope sc) diff -r 69d078c417c6 -r a8b50ff7f201 dmd/IntegerExp.d --- a/dmd/IntegerExp.d Sat Aug 21 11:50:50 2010 +0400 +++ b/dmd/IntegerExp.d Sat Aug 21 12:15:47 2010 +0400 @@ -107,7 +107,10 @@ IntRange getIntRange() { - assert(false); + IntRange ir; + ir.imin = value & type.sizemask(); + ir.imax = ir.imin; + return ir; } ulong toInteger() diff -r 69d078c417c6 -r a8b50ff7f201 dmd/NewExp.d --- a/dmd/NewExp.d Sat Aug 21 11:50:50 2010 +0400 +++ b/dmd/NewExp.d Sat Aug 21 12:15:47 2010 +0400 @@ -68,7 +68,10 @@ Expression syntaxCopy() { - assert(false); + return new NewExp(loc, + thisexp ? thisexp.syntaxCopy() : null, + arraySyntaxCopy(newargs), + newtype.syntaxCopy(), arraySyntaxCopy(arguments)); } Expression semantic(Scope sc) diff -r 69d078c417c6 -r a8b50ff7f201 dmd/OrExp.d --- a/dmd/OrExp.d Sat Aug 21 11:50:50 2010 +0400 +++ b/dmd/OrExp.d Sat Aug 21 12:15:47 2010 +0400 @@ -107,7 +107,25 @@ IntRange getIntRange() { - assert(false); + IntRange ir; + IntRange ir1 = e1.getIntRange(); + IntRange ir2 = e2.getIntRange(); + + ir.imin = ir1.imin; + if (ir2.imin < ir.imin) + ir.imin = ir2.imin; + + ir.imax = ir1.imax; + if (ir2.imax > ir.imax) + ir.imax = ir2.imax; + + ir.imin &= type.sizemask(); + ir.imax &= type.sizemask(); + + //printf("OrExp: imin = x%llx, imax = x%llx\n", ir.imin, ir.imax); + //e1.dump(0); + + return ir; } bool isCommutative() diff -r 69d078c417c6 -r a8b50ff7f201 dmd/SliceExp.d --- a/dmd/SliceExp.d Sat Aug 21 11:50:50 2010 +0400 +++ b/dmd/SliceExp.d Sat Aug 21 12:15:47 2010 +0400 @@ -69,7 +69,15 @@ Expression syntaxCopy() { - assert(false); + Expression lwr = null; + if (this.lwr) + lwr = this.lwr.syntaxCopy(); + + Expression upr = null; + if (this.upr) + upr = this.upr.syntaxCopy(); + + return new SliceExp(loc, e1.syntaxCopy(), lwr, upr); } Expression semantic(Scope sc) diff -r 69d078c417c6 -r a8b50ff7f201 dmd/SwitchStatement.d --- a/dmd/SwitchStatement.d Sat Aug 21 11:50:50 2010 +0400 +++ b/dmd/SwitchStatement.d Sat Aug 21 12:15:47 2010 +0400 @@ -77,7 +77,9 @@ Statement syntaxCopy() { - assert(false); + SwitchStatement s = new SwitchStatement(loc, + condition.syntaxCopy(), body_.syntaxCopy(), isFinal); + return s; } Statement semantic(Scope sc) diff -r 69d078c417c6 -r a8b50ff7f201 dmd/ThrowStatement.d --- a/dmd/ThrowStatement.d Sat Aug 21 11:50:50 2010 +0400 +++ b/dmd/ThrowStatement.d Sat Aug 21 12:15:47 2010 +0400 @@ -31,7 +31,8 @@ Statement syntaxCopy() { - assert(false); + ThrowStatement s = new ThrowStatement(loc, exp.syntaxCopy()); + return s; } Statement semantic(Scope sc) diff -r 69d078c417c6 -r a8b50ff7f201 dmd/Type.d --- a/dmd/Type.d Sat Aug 21 11:50:50 2010 +0400 +++ b/dmd/Type.d Sat Aug 21 12:15:47 2010 +0400 @@ -2182,9 +2182,32 @@ return null; } + /**************************************** + * Return the mask that an integral type will + * fit into. + */ ulong sizemask() { - assert(false); + ulong m; + + switch (toBasetype().ty) + { + case Tbool: m = 1; break; + case Tchar: + case Tint8: + case Tuns8: m = 0xFF; break; + case Twchar: + case Tint16: + case Tuns16: m = 0xFFFFUL; break; + case Tdchar: + case Tint32: + case Tuns32: m = 0xFFFFFFFFUL; break; + case Tint64: + case Tuns64: m = 0xFFFFFFFFFFFFFFFFUL; break; + default: + assert(0); + } + return m; } static void error(T...)(Loc loc, string format, T t) diff -r 69d078c417c6 -r a8b50ff7f201 dmd/TypeTypedef.d --- a/dmd/TypeTypedef.d Sat Aug 21 11:50:50 2010 +0400 +++ b/dmd/TypeTypedef.d Sat Aug 21 12:15:47 2010 +0400 @@ -189,7 +189,11 @@ MATCH constConv(Type to) { - assert(false); + if (equals(to)) + return MATCHexact; + if (ty == to.ty && sym == (cast(TypeTypedef)to).sym) + return sym.basetype.implicitConvTo((cast(TypeTypedef)to).sym.basetype); + return MATCHnomatch; } Expression defaultInit(Loc loc) diff -r 69d078c417c6 -r a8b50ff7f201 dmd/VarDeclaration.d --- a/dmd/VarDeclaration.d Sat Aug 21 11:50:50 2010 +0400 +++ b/dmd/VarDeclaration.d Sat Aug 21 12:15:47 2010 +0400 @@ -247,7 +247,8 @@ { Argument arg = Argument.getNth(tt.arguments, i); OutBuffer buf = new OutBuffer(); - buf.printf("_%s_field_%zu", ident.toChars(), i); + ///buf.printf("_%s_field_%zu", ident.toChars(), i); + buf.printf("_%s_field_%s", ident.toChars(), i); buf.writeByte(0); string name = buf.extractString(); Identifier id = new Identifier(name, TOK.TOKidentifier); diff -r 69d078c417c6 -r a8b50ff7f201 dmd/expression/Util.d --- a/dmd/expression/Util.d Sat Aug 21 11:50:50 2010 +0400 +++ b/dmd/expression/Util.d Sat Aug 21 12:15:47 2010 +0400 @@ -2,7 +2,7 @@ import dmd.Expression; import dmd.Loc; -import dmd.BUILTIN; +import dmd.RealExp; import dmd.Scope; import dmd.FuncExp; import dmd.DelegateExp; @@ -34,6 +34,7 @@ import dmd.CallExp; import dmd.TY; import dmd.MATCH; +import dmd.BUILTIN; import dmd.TypeFunction; import dmd.declaration.Match; import dmd.ArrayTypes; @@ -945,9 +946,45 @@ * Return result: null if cannot evaluate it. */ +extern(C) extern real sinl(real); +extern(C) extern real cosl(real); +extern(C) extern real tanl(real); +extern(C) extern real sqrtl(real); +extern(C) extern real fabsl(real); + Expression eval_builtin(BUILTIN builtin, Expressions arguments) { - assert(false); + assert(arguments && arguments.dim); + Expression arg0 = cast(Expression)arguments.data[0]; + Expression e = null; + switch (builtin) + { + case BUILTINsin: + if (arg0.op == TOKfloat64) + e = new RealExp(Loc(0), sinl(arg0.toReal()), arg0.type); + break; + + case BUILTINcos: + if (arg0.op == TOKfloat64) + e = new RealExp(Loc(0), cosl(arg0.toReal()), arg0.type); + break; + + case BUILTINtan: + if (arg0.op == TOKfloat64) + e = new RealExp(Loc(0), tanl(arg0.toReal()), arg0.type); + break; + + case BUILTINsqrt: + if (arg0.op == TOKfloat64) + e = new RealExp(Loc(0), sqrtl(arg0.toReal()), arg0.type); + break; + + case BUILTINfabs: + if (arg0.op == TOKfloat64) + e = new RealExp(Loc(0), fabsl(arg0.toReal()), arg0.type); + break; + } + return e; } Expression fromConstInitializer(int result, Expression e1) @@ -1380,3 +1417,13 @@ } } } + +ulong getMask(ulong v) +{ + ulong u = 0; + if (v >= 0x80) + u = 0xFF; + while (u < v) + u = (u << 1) | 1; + return u; +} \ No newline at end of file