/// <summary>
        /// Reads a primary decrement expression.
        /// </summary>
        /// <param name="leftHandSide">The expression on the left hand side of the operator.</param>
        /// <param name="previousPrecedence">The precedence of the expression just before this one.</param>
        /// <returns>Returns the expression.</returns>
        private DecrementExpression GetPrimaryDecrementExpression(
            Expression leftHandSide, ExpressionPrecedence previousPrecedence)
        {
            Param.AssertNotNull(leftHandSide, "leftHandSide");
            Param.Ignore(previousPrecedence);

            DecrementExpression expression = null;

            // Check the previous precedence to see if we are allowed to gather up the as expression.
            if (CheckPrecedence(previousPrecedence, ExpressionPrecedence.Primary))
            {
                var expressionReference = new Reference<ICodePart>();

                // Make sure the left hand side has at least one token.
                Debug.Assert(leftHandSide.Tokens.First != null, "The left hand side should not be empty");

                // Get the decrement symbol.
                this.tokens.Add(this.GetOperatorToken(OperatorType.Decrement, expressionReference));

                // Create the partial token list for the expression.
                CsTokenList partialTokens = new CsTokenList(this.tokens, leftHandSide.Tokens.First, this.tokens.Last);

                // Create and return the expression.
                expression = new DecrementExpression(partialTokens, leftHandSide, DecrementExpression.DecrementType.Postfix);
                expressionReference.Target = expression;
            }

            return expression;
        }
        /// <summary>
        /// Reads a unary decrement expression.
        /// </summary>
        /// <param name="unsafeCode">Indicates whether the code being parsed resides in an unsafe code block.</param>
        /// <returns>Returns the expression.</returns>
        private DecrementExpression GetUnaryDecrementExpression(bool unsafeCode)
        {
            Param.Ignore(unsafeCode);

            var expressionReference = new Reference<ICodePart>();

            // Get the decrement symbol.
            Node<CsToken> tokenNode = this.tokens.InsertLast(this.GetOperatorToken(OperatorType.Decrement, expressionReference));

            // Get the expression being decremented.
            Expression valueExpression = this.GetNextExpression(ExpressionPrecedence.Unary, expressionReference, unsafeCode);
            if (valueExpression == null || valueExpression.Tokens.First == null)
            {
                throw this.CreateSyntaxException();
            }

            // Create the partial token list for the expression.
            CsTokenList partialTokens = new CsTokenList(this.tokens, tokenNode, this.tokens.Last);

            // Create and return the expression.
            var expression = new DecrementExpression(partialTokens, valueExpression, DecrementExpression.DecrementType.Prefix);
            expressionReference.Target = expression;

            return expression;
        }
Exemplo n.º 3
0
 private DecrementExpression GetPrimaryDecrementExpression(Expression leftHandSide, ExpressionPrecedence previousPrecedence)
 {
     DecrementExpression expression = null;
     if (CheckPrecedence(previousPrecedence, ExpressionPrecedence.Primary))
     {
         this.tokens.Add(this.GetOperatorToken(OperatorType.Decrement));
         CsTokenList tokens = new CsTokenList(this.tokens, leftHandSide.Tokens.First, this.tokens.Last);
         expression = new DecrementExpression(tokens, leftHandSide, DecrementExpression.DecrementType.Postfix);
     }
     return expression;
 }