protected override NodeValue VisitUnaryExpression(UnaryExpressionNode node) { NodeValue expressionValue = Visit(node.ExpressionNode); if (expressionValue is UndefinedValue) { return(new UndefinedValue()); } try { NodeValue nodeValue = ConstEvaluationHelper.EvaluateUnaryOperation(node.Operator, expressionValue); if (nodeValue is IntValue intValue) { if (intValue.Value < Int32.MinValue || intValue.Value > Int32.MaxValue) { node.Annotations.Add(new ArithmeticOperationOverflowError(node.OperatorLocation)); return(new UndefinedValue()); } } return(nodeValue); } catch (InvalidUnaryOperationException) { node.Annotations.Add(new InvalidUnaryOperationError()); return(new UndefinedValue()); } }
protected override NodeValue VisitBinaryExpression(BinaryExpressionNode node) { NodeValue leftNodeValue = Visit(node.LeftSideNode); NodeValue rightNodeValue = Visit(node.RightSideNode); if (leftNodeValue is UndefinedValue || rightNodeValue is UndefinedValue) { return(new UndefinedValue()); } try { NodeValue nodeValue = ConstEvaluationHelper.EvaluateBinaryOperation(node.Operator, leftNodeValue, rightNodeValue); if (nodeValue is IntValue intValue) { if (intValue.Value < Int32.MinValue || intValue.Value > Int32.MaxValue) { node.Annotations.Add(new ArithmeticOperationOverflowError(node.OperatorLocation)); return(new UndefinedValue()); } } return(nodeValue); } catch (InvalidBinaryOperationException) { node.Annotations.Add(new InvalidBinaryOperationError(node.OperatorLocation, node.LeftSideNode.Location, node.RightSideNode.Location)); return(new UndefinedValue()); } catch (DivideByZeroException) { node.Annotations.Add(new DivideByZeroError(node.OperatorLocation, node.RightSideNode.Location)); return(new UndefinedValue()); } catch (OverflowException) { node.Annotations.Add(new ArithmeticOperationOverflowError(node.OperatorLocation)); return(new UndefinedValue()); } }