Skip to content

Commit

Permalink
Merge pull request #5106 from WalterBright/fix15089
Browse files Browse the repository at this point in the history
fix Issue 15089 - Marks wrong line as where error occurs.
  • Loading branch information
andralex committed Sep 21, 2015
2 parents 1fe9d18 + e2a7a3a commit d26cf5f
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 64 deletions.
69 changes: 29 additions & 40 deletions src/constfold.d
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
module ddmd.constfold;

import core.stdc.string;
import core.stdc.stdio;
import ddmd.arraytypes;
import ddmd.builtin;
import ddmd.complex;
Expand Down Expand Up @@ -111,10 +112,9 @@ extern (C++) UnionExp Bool(Type type, Expression e1)
return ue;
}

extern (C++) UnionExp Add(Type type, Expression e1, Expression e2)
extern (C++) UnionExp Add(Loc loc, Type type, Expression e1, Expression e2)
{
UnionExp ue;
Loc loc = e1.loc;
static if (LOG)
{
printf("Add(e1 = %s, e2 = %s)\n", e1.toChars(), e2.toChars());
Expand Down Expand Up @@ -219,10 +219,9 @@ extern (C++) UnionExp Add(Type type, Expression e1, Expression e2)
return ue;
}

extern (C++) UnionExp Min(Type type, Expression e1, Expression e2)
extern (C++) UnionExp Min(Loc loc, Type type, Expression e1, Expression e2)
{
UnionExp ue;
Loc loc = e1.loc;
if (type.isreal())
{
emplaceExp!(RealExp)(&ue, loc, e1.toReal() - e2.toReal(), type);
Expand Down Expand Up @@ -319,10 +318,9 @@ extern (C++) UnionExp Min(Type type, Expression e1, Expression e2)
return ue;
}

extern (C++) UnionExp Mul(Type type, Expression e1, Expression e2)
extern (C++) UnionExp Mul(Loc loc, Type type, Expression e1, Expression e2)
{
UnionExp ue;
Loc loc = e1.loc;
if (type.isfloating())
{
complex_t c;
Expand Down Expand Up @@ -369,10 +367,9 @@ extern (C++) UnionExp Mul(Type type, Expression e1, Expression e2)
return ue;
}

extern (C++) UnionExp Div(Type type, Expression e1, Expression e2)
extern (C++) UnionExp Div(Loc loc, Type type, Expression e1, Expression e2)
{
UnionExp ue;
Loc loc = e1.loc;
if (type.isfloating())
{
complex_t c;
Expand Down Expand Up @@ -430,10 +427,9 @@ extern (C++) UnionExp Div(Type type, Expression e1, Expression e2)
return ue;
}

extern (C++) UnionExp Mod(Type type, Expression e1, Expression e2)
extern (C++) UnionExp Mod(Loc loc, Type type, Expression e1, Expression e2)
{
UnionExp ue;
Loc loc = e1.loc;
if (type.isfloating())
{
complex_t c;
Expand Down Expand Up @@ -493,10 +489,9 @@ extern (C++) UnionExp Mod(Type type, Expression e1, Expression e2)
return ue;
}

extern (C++) UnionExp Pow(Type type, Expression e1, Expression e2)
extern (C++) UnionExp Pow(Loc loc, Type type, Expression e1, Expression e2)
{
UnionExp ue;
Loc loc = e1.loc;
// Handle integer power operations.
if (e2.type.isintegral())
{
Expand Down Expand Up @@ -538,18 +533,18 @@ extern (C++) UnionExp Pow(Type type, Expression e1, Expression e2)
if (n & 1)
{
// v = v * r;
uv = Mul(v.type, v, r);
uv = Mul(loc, v.type, v, r);
}
n >>= 1;
// r = r * r
ur = Mul(r.type, r, r);
ur = Mul(loc, r.type, r, r);
}
if (neg)
{
// ue = 1.0 / v
UnionExp one;
emplaceExp!(RealExp)(&one, loc, ldouble(1.0), v.type);
uv = Div(v.type, one.exp(), v);
uv = Div(loc, v.type, one.exp(), v);
}
if (type.iscomplex())
emplaceExp!(ComplexExp)(&ue, loc, v.toComplex(), type);
Expand All @@ -573,18 +568,16 @@ extern (C++) UnionExp Pow(Type type, Expression e1, Expression e2)
return ue;
}

extern (C++) UnionExp Shl(Type type, Expression e1, Expression e2)
extern (C++) UnionExp Shl(Loc loc, Type type, Expression e1, Expression e2)
{
UnionExp ue;
Loc loc = e1.loc;
emplaceExp!(IntegerExp)(&ue, loc, e1.toInteger() << e2.toInteger(), type);
return ue;
}

extern (C++) UnionExp Shr(Type type, Expression e1, Expression e2)
extern (C++) UnionExp Shr(Loc loc, Type type, Expression e1, Expression e2)
{
UnionExp ue;
Loc loc = e1.loc;
dinteger_t value = e1.toInteger();
dinteger_t dcount = e2.toInteger();
assert(dcount <= 0xFFFFFFFF);
Expand Down Expand Up @@ -628,10 +621,9 @@ extern (C++) UnionExp Shr(Type type, Expression e1, Expression e2)
return ue;
}

extern (C++) UnionExp Ushr(Type type, Expression e1, Expression e2)
extern (C++) UnionExp Ushr(Loc loc, Type type, Expression e1, Expression e2)
{
UnionExp ue;
Loc loc = e1.loc;
dinteger_t value = e1.toInteger();
dinteger_t dcount = e2.toInteger();
assert(dcount <= 0xFFFFFFFF);
Expand Down Expand Up @@ -669,33 +661,33 @@ extern (C++) UnionExp Ushr(Type type, Expression e1, Expression e2)
return ue;
}

extern (C++) UnionExp And(Type type, Expression e1, Expression e2)
extern (C++) UnionExp And(Loc loc, Type type, Expression e1, Expression e2)
{
UnionExp ue;
emplaceExp!(IntegerExp)(&ue, e1.loc, e1.toInteger() & e2.toInteger(), type);
emplaceExp!(IntegerExp)(&ue, loc, e1.toInteger() & e2.toInteger(), type);
return ue;
}

extern (C++) UnionExp Or(Type type, Expression e1, Expression e2)
extern (C++) UnionExp Or(Loc loc, Type type, Expression e1, Expression e2)
{
UnionExp ue;
emplaceExp!(IntegerExp)(&ue, e1.loc, e1.toInteger() | e2.toInteger(), type);
emplaceExp!(IntegerExp)(&ue, loc, e1.toInteger() | e2.toInteger(), type);
return ue;
}

extern (C++) UnionExp Xor(Type type, Expression e1, Expression e2)
extern (C++) UnionExp Xor(Loc loc, Type type, Expression e1, Expression e2)
{
//printf("Xor(linnum = %d, e1 = %s, e2 = %s)\n", loc.linnum, e1.toChars(), e2.toChars());
UnionExp ue;
emplaceExp!(IntegerExp)(&ue, e1.loc, e1.toInteger() ^ e2.toInteger(), type);
emplaceExp!(IntegerExp)(&ue, loc, e1.toInteger() ^ e2.toInteger(), type);
return ue;
}

/* Also returns TOKcantexp if cannot be computed.
*/
extern (C++) UnionExp Equal(TOK op, Type type, Expression e1, Expression e2)
extern (C++) UnionExp Equal(TOK op, Loc loc, Type type, Expression e1, Expression e2)
{
UnionExp ue;
Loc loc = e1.loc;
int cmp = 0;
real_t r1;
real_t r2;
Expand Down Expand Up @@ -770,7 +762,7 @@ extern (C++) UnionExp Equal(TOK op, Type type, Expression e1, Expression e2)
{
Expression ee1 = (*es1.elements)[i];
Expression ee2 = (*es2.elements)[i];
ue = Equal(TOKequal, Type.tint32, ee1, ee2);
ue = Equal(TOKequal, loc, Type.tint32, ee1, ee2);
if (CTFEExp.isCantExp(ue.exp()))
return ue;
cmp = cast(int)ue.exp().toInteger();
Expand Down Expand Up @@ -840,7 +832,7 @@ extern (C++) UnionExp Equal(TOK op, Type type, Expression e1, Expression e2)
cmp = 0;
break;
}
ue = Equal(TOKequal, Type.tint32, ee1, ee2);
ue = Equal(TOKequal, loc, Type.tint32, ee1, ee2);
if (ue.exp().op == TOKcantexp)
return ue;
cmp = cast(int)ue.exp().toInteger();
Expand Down Expand Up @@ -898,10 +890,9 @@ extern (C++) UnionExp Equal(TOK op, Type type, Expression e1, Expression e2)
return ue;
}

extern (C++) UnionExp Identity(TOK op, Type type, Expression e1, Expression e2)
extern (C++) UnionExp Identity(TOK op, Loc loc, Type type, Expression e1, Expression e2)
{
UnionExp ue;
Loc loc = e1.loc;
int cmp;
if (e1.op == TOKnull)
{
Expand Down Expand Up @@ -935,7 +926,7 @@ extern (C++) UnionExp Identity(TOK op, Type type, Expression e1, Expression e2)
}
else
{
ue = Equal((op == TOKidentity) ? TOKequal : TOKnotequal, type, e1, e2);
ue = Equal((op == TOKidentity) ? TOKequal : TOKnotequal, loc, type, e1, e2);
return ue;
}
}
Expand All @@ -945,10 +936,9 @@ extern (C++) UnionExp Identity(TOK op, Type type, Expression e1, Expression e2)
return ue;
}

extern (C++) UnionExp Cmp(TOK op, Type type, Expression e1, Expression e2)
extern (C++) UnionExp Cmp(TOK op, Loc loc, Type type, Expression e1, Expression e2)
{
UnionExp ue;
Loc loc = e1.loc;
dinteger_t n;
real_t r1;
real_t r2;
Expand Down Expand Up @@ -1221,10 +1211,9 @@ extern (C++) UnionExp Cmp(TOK op, Type type, Expression e1, Expression e2)
* to: type to cast to
* type: type to paint the result
*/
extern (C++) UnionExp Cast(Type type, Type to, Expression e1)
extern (C++) UnionExp Cast(Loc loc, Type type, Type to, Expression e1)
{
UnionExp ue;
Loc loc = e1.loc;
Type tb = to.toBasetype();
Type typeb = type.toBasetype();
//printf("Cast(type = %s, to = %s, e1 = %s)\n", type->toChars(), to->toChars(), e1->toChars());
Expand Down Expand Up @@ -1354,7 +1343,7 @@ extern (C++) UnionExp Cast(Type type, Type to, Expression e1)
VarDeclaration v = sd.fields[i];
UnionExp zero;
emplaceExp!(IntegerExp)(&zero, 0);
ue = Cast(v.type, v.type, zero.exp());
ue = Cast(loc, v.type, v.type, zero.exp());
if (ue.exp().op == TOKcantexp)
return ue;
elements.push(ue.exp().copy());
Expand Down Expand Up @@ -1486,7 +1475,7 @@ extern (C++) UnionExp Index(Type type, Expression e1, Expression e2)
{
i--;
Expression ekey = (*ae.keys)[i];
ue = Equal(TOKequal, Type.tbool, ekey, e2);
ue = Equal(TOKequal, loc, Type.tbool, ekey, e2);
if (CTFEExp.isCantExp(ue.exp()))
return ue;
if (ue.exp().isBool(true))
Expand Down
5 changes: 2 additions & 3 deletions src/ctfeexpr.d
Original file line number Diff line number Diff line change
Expand Up @@ -1779,9 +1779,8 @@ extern (C++) int ctfeCmp(Loc loc, TOK op, Expression e1, Expression e2)
return n;
}

extern (C++) UnionExp ctfeCat(Type type, Expression e1, Expression e2)
extern (C++) UnionExp ctfeCat(Loc loc, Type type, Expression e1, Expression e2)
{
Loc loc = e1.loc;
Type t1 = e1.type.toBasetype();
Type t2 = e2.type.toBasetype();
UnionExp ue;
Expand Down Expand Up @@ -1957,7 +1956,7 @@ extern (C++) Expression ctfeCast(Loc loc, Type type, Type to, Expression e)
}
else
{
r = Cast(type, to, e).copy();
r = Cast(loc, type, to, e).copy();
}
if (CTFEExp.isCantExp(r))
error(loc, "cannot cast %s to %s at compile time", e.toChars(), to.toChars());
Expand Down
6 changes: 3 additions & 3 deletions src/dinterpret.d
Original file line number Diff line number Diff line change
Expand Up @@ -3102,7 +3102,7 @@ public:
return;
}
}
result = (*fp)(e.type, e1, e2).copy();
result = (*fp)(e.loc, e.type, e1, e2).copy();
if (CTFEExp.isCantExp(result))
e.error("%s cannot be interpreted at compile time", e.toChars());
}
Expand Down Expand Up @@ -3535,7 +3535,7 @@ public:
}
}
oldval = resolveSlice(oldval);
newval = (*fp)(e.type, oldval, newval).copy();
newval = (*fp)(e.loc, e.type, oldval, newval).copy();
}
else if (e.e2.type.isintegral() && (e.op == TOKaddass || e.op == TOKminass || e.op == TOKplusplus || e.op == TOKminusminus))
{
Expand Down Expand Up @@ -5347,7 +5347,7 @@ public:
return;
e1 = resolveSlice(e1);
e2 = resolveSlice(e2);
result = ctfeCat(e.type, e1, e2).copy();
result = ctfeCat(e.loc, e.type, e1, e2).copy();
if (CTFEExp.isCantExp(result))
{
e.error("%s cannot be interpreted at compile time", e.toChars());
Expand Down
2 changes: 1 addition & 1 deletion src/expression.d
Original file line number Diff line number Diff line change
Expand Up @@ -6977,7 +6977,7 @@ public:
}
}

extern (C++) alias fp_t = UnionExp function(Type, Expression, Expression);
extern (C++) alias fp_t = UnionExp function(Loc loc, Type, Expression, Expression);
extern (C++) alias fp2_t = int function(Loc loc, TOK, Expression, Expression);

extern (C++) class BinExp : Expression
Expand Down
Loading

0 comments on commit d26cf5f

Please sign in to comment.