Skip to content

Commit

Permalink
fix Issue 15089 - Marks wrong line as where error occurs.
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Sep 20, 2015
1 parent 2c94b22 commit e2a7a3a
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 @@ -112,10 +113,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 @@ -220,10 +220,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 @@ -320,10 +319,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 @@ -370,10 +368,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 @@ -431,10 +428,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 @@ -494,10 +490,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 @@ -539,18 +534,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 @@ -574,18 +569,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 @@ -629,10 +622,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 @@ -670,33 +662,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 @@ -771,7 +763,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 @@ -841,7 +833,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 @@ -899,10 +891,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 @@ -936,7 +927,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 @@ -946,10 +937,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 @@ -1222,10 +1212,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 @@ -1355,7 +1344,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 @@ -1487,7 +1476,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 @@ -1785,9 +1785,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 @@ -1963,7 +1962,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 @@ -3105,7 +3105,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 @@ -3539,7 +3539,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 @@ -5355,7 +5355,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 @@ -6978,7 +6978,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 e2a7a3a

Please sign in to comment.