Exemplo n.º 1
0
 void ILSLSyntaxErrorListener.PostfixOperationOnNonVariable(LSLSourceCodeRange location,
                                                            LSLPostfixOperationType type)
 {
     _errorActionQueue.Enqueue(location.StartIndex,
                               () =>
                               SyntaxErrorListener.PostfixOperationOnNonVariable(location, type));
 }
        /// <summary>
        ///     Converts the provided  <see cref="LSLPostfixOperationType" /> to its source code string representation.
        /// </summary>
        /// <param name="type">The <see cref="LSLPostfixOperationType" /> to convert to a string.</param>
        /// <exception cref="ArgumentException">
        ///     Thrown if the <see cref="LSLPostfixOperationType" /> provided was equal to
        ///     <see cref="LSLPostfixOperationType.Error" />.
        /// </exception>
        /// <returns>The source code string representation of the <see cref="LSLPostfixOperationType" />.</returns>
        public static string ToOperatorString(this LSLPostfixOperationType type)
        {
            switch (type)
            {
            case LSLPostfixOperationType.Decrement:
                return("--");

            case LSLPostfixOperationType.Increment:
                return("++");
            }

            throw new ArgumentException(
                      string.Format("Could not convert LSLPostfixOperationType.{0} enum value to operator string", type),
                      "type");
        }
Exemplo n.º 3
0
        /// <summary>
        ///     Construct an <see cref="LSLPostfixOperationNode" /> from a given <see cref="ILSLExprNode" /> and
        ///     <see cref="LSLPostfixOperationType" />.
        /// </summary>
        /// <param name="resultType">The return type of the postfix operation on the given expression.</param>
        /// <param name="leftExpression">The expression the postfix operation occurs on.</param>
        /// <param name="operationType">The postfix operation type.</param>
        /// <exception cref="ArgumentNullException"><paramref name="leftExpression" /> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException"><paramref name="operationType" /> is <see cref="LSLPostfixOperationType.Error" />.</exception>
        public LSLPostfixOperationNode(LSLType resultType, ILSLExprNode leftExpression,
                                       LSLPostfixOperationType operationType)
        {
            if (leftExpression == null)
            {
                throw new ArgumentNullException("leftExpression");
            }

            if (operationType == LSLPostfixOperationType.Error)
            {
                throw new ArgumentException("operationType cannot be LSLPostfixOperationType.Error.");
            }

            Type                  = resultType;
            LeftExpression        = leftExpression;
            LeftExpression.Parent = this;

            Operation       = operationType;
            OperationString = Operation.ToOperatorString();
        }
Exemplo n.º 4
0
        /// <summary>
        ///     Validates and returns the type resulting from a postfix operation.
        /// </summary>
        /// <param name="left">The expression to preform the postfix operation on.</param>
        /// <param name="operation">The postfix operation preformed.</param>
        /// <returns>An <see cref="LSLExpressionValidatorResult" /> object</returns>
        /// <exception cref="ArgumentNullException"><paramref name="left"/> is <c>null</c>.</exception>
        public LSLExpressionValidatorResult ValidatePostfixOperation(ILSLReadOnlyExprNode left,
                                                                     LSLPostfixOperationType operation)
        {
            if (left == null)
            {
                throw new ArgumentNullException("left");
            }

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

            LSLType t;

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

            return(LSLExpressionValidatorResult.Error);
        }
 /// <summary>
 ///     Determines whether the given postfix operation is a modifying operation.
 ///     Both <see cref="LSLPostfixOperationType.Decrement" /> and <see cref="LSLPostfixOperationType.Increment" /> are
 ///     modifying operations.
 /// </summary>
 /// <param name="type">If the postfix operation modifies the expression to its left.</param>
 /// <returns><c>true</c> if <paramref name="type"/> is <see cref="LSLPrefixOperationType.Decrement" /> or <see cref="LSLPrefixOperationType.Increment" />.</returns>
 public static bool IsModifying(this LSLPostfixOperationType type)
 {
     return(type == LSLPostfixOperationType.Decrement || type == LSLPostfixOperationType.Increment);
 }
Exemplo n.º 6
0
 private void AddPostfixOperation(LSLType left, LSLPostfixOperationType operation, LSLType result)
 {
     _operations.Add(left + operation.ToOperatorString(), result);
 }