Exemplo n.º 1
0
        /// <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))
            {
                Reference<ICodePart> 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;
        }
Exemplo n.º 2
0
        /// <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);

            Reference<ICodePart> 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.
            DecrementExpression expression = new DecrementExpression(partialTokens, valueExpression, DecrementExpression.DecrementType.Prefix);
            expressionReference.Target = expression;

            return expression;
        }
 /// <summary>
 /// The save.
 /// </summary>
 /// <param name="decrementExpression">
 /// The decrement expression.
 /// </param>
 private void Save(DecrementExpression decrementExpression)
 {
     if (decrementExpression.Type == DecrementExpression.DecrementType.Prefix)
     {
         this.cppWriter.Write("--");
         @switch(decrementExpression.Value);
     }
     else
     {
         @switch(decrementExpression.Value);
         this.cppWriter.Write("--");
     }
 }