Ejemplo n.º 1
0
            public RedILNode VisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression, State data)
            {
                var operand = CastUtilities.CastRedILNode <ExpressionNode>(unaryOperatorExpression.Expression.AcceptVisitor(this, data.NewState(unaryOperatorExpression, null)));

                if (OperatorUtilities.IsIncrement(unaryOperatorExpression.Operator))
                {
                    if (data.ParentNode.NodeType != NodeType.Statement)
                    {
                        throw new RedILException($"Incremental operators can only be used within statements");
                    }

                    BinaryExpressionOperator binaryOp = default;
                    switch (unaryOperatorExpression.Operator)
                    {
                    case UnaryOperatorType.Increment:
                    case UnaryOperatorType.PostIncrement:
                        binaryOp = BinaryExpressionOperator.Add;
                        break;

                    case UnaryOperatorType.Decrement:
                    case UnaryOperatorType.PostDecrement:
                        binaryOp = BinaryExpressionOperator.Subtract;
                        break;
                    }

                    var constantOne = new ConstantValueNode(DataValueType.Integer, 1);
                    return(new AssignNode(operand, VisitBinaryOperatorExpression(operand, constantOne, binaryOp, data.NewState(unaryOperatorExpression, null))));
                }

                var op = OperatorUtilities.UnaryOperator(unaryOperatorExpression.Operator);

                return(new UnaryExpressionNode(op, operand));
            }
Ejemplo n.º 2
0
            private ExpressionNode VisitBinaryOperatorExpression(ExpressionNode left, ExpressionNode right, BinaryExpressionOperator op, State data)
            {
                if (OperatorUtilities.IsBoolean(op))
                {
                    return(new BinaryExpressionNode(DataValueType.Boolean, op, left, right));
                }
                else if (OperatorUtilities.IsArithmatic(op))
                {
                    if (left.DataType == DataValueType.String ||
                        right.DataType == DataValueType.String)
                    {
                        return(new BinaryExpressionNode(DataValueType.String, BinaryExpressionOperator.StringConcat, left, right));
                    }
                    else if (left.DataType == DataValueType.Float ||
                             right.DataType == DataValueType.Float)
                    {
                        return(new BinaryExpressionNode(DataValueType.Float, op, left, right));
                    }
                    else if (left.DataType == DataValueType.Integer &&
                             right.DataType == DataValueType.Integer)
                    {
                        return(new BinaryExpressionNode(DataValueType.Integer, op, left, right));
                    }
                }
                else if (op == BinaryExpressionOperator.NullCoalescing)
                {
                    return(new BinaryExpressionNode(left.DataType, op, left, right));
                }

                throw new RedILException($"Unsupported operator '{op}' with data types '{left.DataType}' and '{right.DataType}'");
            }
Ejemplo n.º 3
0
            public RedILNode VisitAssignmentExpression(AssignmentExpression assignmentExpression, State data)
            {
                if (data.ParentNode.NodeType != NodeType.Statement)
                {
                    throw new RedILException("Assigment is only possible within a statement");
                }

                var assignNode = new AssignNode();

                var left  = CastUtilities.CastRedILNode <ExpressionNode>(assignmentExpression.Left.AcceptVisitor(this, data.NewState(assignmentExpression, assignNode)));
                var right = CastUtilities.CastRedILNode <ExpressionNode>(assignmentExpression.Right.AcceptVisitor(this, data.NewState(assignmentExpression, assignNode)));

                if (assignmentExpression.Operator == AssignmentOperatorType.Assign)
                {
                    assignNode.Left  = left;
                    assignNode.Right = right;
                }
                else
                {
                    var op = OperatorUtilities.BinaryOperator(assignmentExpression.Operator);
                    assignNode.Left  = left;
                    assignNode.Right = VisitBinaryOperatorExpression(left, right, op, data);
                }

                return(assignNode);
            }
Ejemplo n.º 4
0
            public RedILNode VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, State data)
            {
                //TODO: send parent node
                var op    = OperatorUtilities.BinaryOperator(binaryOperatorExpression.Operator);
                var left  = CastUtilities.CastRedILNode <ExpressionNode>(binaryOperatorExpression.Left.AcceptVisitor(this, data.NewState(binaryOperatorExpression, null)));
                var right = CastUtilities.CastRedILNode <ExpressionNode>(binaryOperatorExpression.Right.AcceptVisitor(this, data.NewState(binaryOperatorExpression, null)));

                return(VisitBinaryOperatorExpression(left, right, op, data));
            }