@Override
public Value caseAPlusNumericBinaryExp(APlusNumericBinaryExp node,
Context ctxt) throws AnalysisException
{
node.getLocation().hit();
try
{
Value l = node.getLeft().apply(VdmRuntime.getExpressionEvaluator(), ctxt);
Value r = node.getRight().apply(VdmRuntime.getExpressionEvaluator(), ctxt);
if (NumericValue.areIntegers(l, r))
{
long lv = l.intValue(ctxt);
long rv = r.intValue(ctxt);
long sum = addExact(lv, rv, ctxt);
return NumericValue.valueOf(sum, ctxt);
}
else
{
double lv = l.realValue(ctxt);
double rv = r.realValue(ctxt);
return NumericValue.valueOf(lv + rv, ctxt);
}
} catch (ValueException e)
{
return VdmRuntimeError.abort(node.getLocation(), e);
}
}