Exemplo n.º 1
0
        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());
            }
        }
Exemplo n.º 2
0
        protected override void VisitUnaryExpression(UnaryExpressionNode node)
        {
            base.VisitUnaryExpression(node);

            if (IsInsideFloatExpression())
            {
                node.DoGenerateOperatorInstruction = false;
            }


            switch (node.ExpressionNode.BuiltinType)
            {
            case SymbolType.Uninitialized:
            case SymbolType.Undefined:
                node.BuiltinType = SymbolType.Undefined;
                break;

            case SymbolType.Int:
                node.BuiltinType = SymbolType.Int;
                // TODO think about changing !int type to bool
                break;

            case SymbolType.Float:
                switch (node.Operator)
                {
                case UnaryOperator.Plus:
                case UnaryOperator.Minus:
                case UnaryOperator.Not:
                    node.BuiltinType = SymbolType.Float;
                    break;

                default:
                    node.BuiltinType = SymbolType.Undefined;
                    node.Annotations.Add(new InvalidArgumentTypeToUnaryExpressionError(node.ExpressionNode.BuiltinType.ToString()));
                    break;
                }
                break;

            default:
                node.BuiltinType = SymbolType.Undefined;
                node.Annotations.Add(new InvalidArgumentTypeToUnaryExpressionError(node.ExpressionNode.BuiltinType.ToString()));
                break;
            }
        }
Exemplo n.º 3
0
 protected virtual T VisitUnaryExpression(UnaryExpressionNode node)
 {
     Visit(node.ExpressionNode);
     return(DefaultResult);
 }
 protected virtual void VisitUnaryExpression(UnaryExpressionNode node)
 {
     Visit(node.ExpressionNode);
 }