1
0

fix constant folding

This commit is contained in:
otya128
2016-12-02 21:56:28 +09:00
parent f37089d675
commit a6a205c4c0

View File

@@ -1705,14 +1705,18 @@ class Parser
if (op.item1.type == NodeType.Constant && op.item2.type == NodeType.Constant) if (op.item1.type == NodeType.Constant && op.item2.type == NodeType.Constant)
{ {
double result; double result;
if (constcalc((cast(Constant)op.item1).value, (cast(Constant)op.item2).value, op.operator, result)) Constant leftconst = (cast(Constant)op.item1), rightconst = (cast(Constant)op.item2);
if (rightconst.value.isNumber && leftconst.value.isNumber)
{ {
auto l = new Constant(Value(result), lex.location); if (constcalc(leftconst.value, rightconst.value, op.operator, result))
constexpr = true; {
if(order != getOPRank(token.type)) auto l = new Constant(Value(result), lex.location);
return l; constexpr = true;
op = new BinaryOperator(l, lex.location); if(order != getOPRank(token.type))
continue; return l;
op = new BinaryOperator(l, lex.location);
continue;
}
} }
} }
version(none) version(none)