/// <summary>
        ///     Create a <see cref="LSLBinaryExpressionNode" /> from two <see cref="ILSLExprNode" />'s and an operator description.
        /// </summary>
        /// <param name="resultType">
        ///     The resulting type of the binary operation between <paramref name="leftExpression" /> and
        ///     <paramref name="rightExpression" />.
        /// </param>
        /// <param name="leftExpression">The left expression.</param>
        /// <param name="operation">The operator.</param>
        /// <param name="rightExpression">The right expression.</param>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="leftExpression" /> or <paramref name="rightExpression" /> is
        ///     <c>null</c>.
        /// </exception>
        /// <exception cref="ArgumentException">
        ///     Thrown if <paramref name="resultType" /> is equal to <see cref="LSLType.Void" /> or
        ///     <paramref name="operation" /> is equal to <see cref="LSLBinaryOperationType.Error" />
        /// </exception>
        public LSLBinaryExpressionNode(LSLType resultType, ILSLExprNode leftExpression, LSLBinaryOperationType operation,
                                       ILSLExprNode rightExpression)
        {
            if (leftExpression == null)
            {
                throw new ArgumentNullException("leftExpression");
            }
            if (rightExpression == null)
            {
                throw new ArgumentNullException("rightExpression");
            }
            if (resultType == LSLType.Void)
            {
                throw new ArgumentException("Binary operation resultType cannot be LSLType.Void.", "resultType");
            }


            Type = resultType;

            LeftExpression        = leftExpression;
            LeftExpression.Parent = this;

            Operation       = operation;
            OperationString = operation.ToOperatorString();

            RightExpression        = rightExpression;
            RightExpression.Parent = this;
        }
示例#2
0
        /// <summary>
        ///     Validates and returns the type resulting from a binary operation.
        /// </summary>
        /// <param name="left">The expression to on the left of the binary operation.</param>
        /// <param name="operation">The binary operation to preform.</param>
        /// <param name="right">The expression to on the right of the binary operation.</param>
        /// <returns>An <see cref="LSLExpressionValidatorResult" /> object</returns>
        /// <exception cref="ArgumentNullException"><paramref name="left"/> or <paramref name="right"/> is <c>null</c>.</exception>
        public LSLExpressionValidatorResult ValidateBinaryOperation(ILSLReadOnlyExprNode left, LSLBinaryOperationType operation,
                                                                    ILSLReadOnlyExprNode right)
        {
            if (left == null)
            {
                throw new ArgumentNullException("left");
            }
            if (right == null)
            {
                throw new ArgumentNullException("right");
            }

            if (left.HasErrors || right.HasErrors)
            {
                return(LSLExpressionValidatorResult.Error);
            }


            if (left.Type == LSLType.List && operation == LSLBinaryOperationType.AddAssign)
            {
                return(LSLExpressionValidatorResult.List);
            }


            if (left.Type == LSLType.List || right.Type == LSLType.List)
            {
                if (operation == LSLBinaryOperationType.Add)
                {
                    return(LSLExpressionValidatorResult.List);
                }
            }


            if (left.Type == LSLType.List && right.Type == LSLType.List)
            {
                if (operation == LSLBinaryOperationType.Equals || operation == LSLBinaryOperationType.NotEquals)
                {
                    return(LSLExpressionValidatorResult.Integer);
                }
                if (operation == LSLBinaryOperationType.Assign)
                {
                    return(LSLExpressionValidatorResult.List);
                }
            }


            LSLType t;

            if (_operations.TryGetValue(left.Type + operation.ToOperatorString() + right.Type, out t))
            {
                return(new LSLExpressionValidatorResult(t, true));
            }

            return(new LSLExpressionValidatorResult(t, false));
        }
示例#3
0
 private void AddBinaryOperation(LSLType left, LSLBinaryOperationType operation, LSLType right, LSLType result)
 {
     _operations.Add(left + operation.ToOperatorString() + right, result);
 }