Esempio n. 1
0
        /// <summary>
        /// Reads a conditional logical expression.
        /// </summary>
        /// <param name="parentProxy">Represents the parent item.</param>
        /// <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 ConditionalLogicalExpression GetConditionalPreprocessorAndOrExpression(
            CodeUnitProxy parentProxy, Expression leftHandSide, ExpressionPrecedence previousPrecedence)
        {
            Param.AssertNotNull(parentProxy, "parentProxy");
            Param.AssertNotNull(leftHandSide, "leftHandSide");
            Param.Ignore(previousPrecedence);

            ConditionalLogicalExpression expression = null;

            this.AdvanceToNextConditionalDirectiveCodeSymbol(parentProxy);
            var expressionProxy = new CodeUnitProxy(this.document);

            // Create the operator symbol.
            OperatorSymbolToken operatorToken = this.PeekOperatorSymbolToken();

            // Check the precedence of the operators to make sure we can gather this statement now.
            ExpressionPrecedence precedence = GetOperatorPrecedence(operatorToken.SymbolType);

            if (CheckPrecedence(previousPrecedence, precedence))
            {
                // Add the operator token to the document and advance the symbol manager up to it.
                this.symbols.Advance();
                expressionProxy.Children.Add(operatorToken);

                // Get the expression on the right-hand side of the operator.
                Expression rightHandSide = this.GetNextConditionalPreprocessorExpression(this.document, expressionProxy, precedence);
                if (rightHandSide == null)
                {
                    throw new SyntaxException(this.document, operatorToken.LineNumber);
                }

                // Get the expression operator type.
                switch (operatorToken.SymbolType)
                {
                case OperatorType.ConditionalAnd:
                    expression = new ConditionalAndExpression(expressionProxy, leftHandSide, rightHandSide);
                    break;

                case OperatorType.ConditionalOr:
                    expression = new ConditionalOrExpression(expressionProxy, leftHandSide, rightHandSide);
                    break;

                default:
                    throw new SyntaxException(this.document, operatorToken.LineNumber);
                }

                parentProxy.Children.Add(expression);
            }

            return(expression);
        }
        /// <summary>
        /// Reads a conditional logical expression.
        /// </summary>
        /// <param name="expressionProxy">Proxy object for the expression being created.</param>
        /// <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>
        /// <param name="unsafeCode">Indicates whether the code being parsed resides in an unsafe code block.</param>
        /// <returns>Returns the expression.</returns>
        private ConditionalLogicalExpression GetConditionalLogicalExpression(
            CodeUnitProxy expressionProxy, Expression leftHandSide, ExpressionPrecedence previousPrecedence, bool unsafeCode)
        {
            Param.AssertNotNull(expressionProxy, "expressionProxy");
            Param.AssertNotNull(leftHandSide, "leftHandSide");
            Param.Ignore(previousPrecedence);
            Param.Ignore(unsafeCode);

            ConditionalLogicalExpression expression = null;

            // Read the details of the expression.
            OperatorSymbolToken operatorToken = this.PeekOperatorSymbolToken();
            CsLanguageService.Debug.Assert(operatorToken.Category == OperatorCategory.Logical, "Expected a logical operator");

            // Check the precedence of the operators to make sure we can gather this statement now.
            ExpressionPrecedence precedence = GetOperatorPrecedence(operatorToken.SymbolType);
            if (CheckPrecedence(previousPrecedence, precedence))
            {
                // Create the operator toke again and save it.
                operatorToken = this.GetOperatorSymbolToken(expressionProxy);

                // Get the expression on the right-hand side of the operator.
                Expression rightHandSide = this.GetOperatorRightHandExpression(expressionProxy, precedence, unsafeCode);

                // Get the expression operator type.
                switch (operatorToken.SymbolType)
                {
                    case OperatorType.ConditionalAnd:
                        expression = new ConditionalAndExpression(expressionProxy, leftHandSide, rightHandSide);
                        break;

                    case OperatorType.ConditionalOr:
                        expression = new ConditionalOrExpression(expressionProxy, leftHandSide, rightHandSide);
                        break;

                    default:
                        CsLanguageService.Debug.Fail("Unexpected operator type");
                        throw new InvalidOperationException();
                }
            }

            return expression;
        }
        /// <summary>
        /// Reads a conditional logical expression.
        /// </summary>
        /// <param name="parentProxy">Represents the parent item.</param>
        /// <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 ConditionalLogicalExpression GetConditionalPreprocessorAndOrExpression(
            CodeUnitProxy parentProxy,  Expression leftHandSide, ExpressionPrecedence previousPrecedence)
        {
            Param.AssertNotNull(parentProxy, "parentProxy");
            Param.AssertNotNull(leftHandSide, "leftHandSide");
            Param.Ignore(previousPrecedence);

            ConditionalLogicalExpression expression = null;

            this.AdvanceToNextConditionalDirectiveCodeSymbol(parentProxy);
            var expressionProxy = new CodeUnitProxy(this.document);

            // Create the operator symbol.
            OperatorSymbolToken operatorToken = this.PeekOperatorSymbolToken();

            // Check the precedence of the operators to make sure we can gather this statement now.
            ExpressionPrecedence precedence = GetOperatorPrecedence(operatorToken.SymbolType);
            if (CheckPrecedence(previousPrecedence, precedence))
            {
                // Add the operator token to the document and advance the symbol manager up to it.
                this.symbols.Advance();
                expressionProxy.Children.Add(operatorToken);

                // Get the expression on the right-hand side of the operator.
                Expression rightHandSide = this.GetNextConditionalPreprocessorExpression(this.document, expressionProxy, precedence);
                if (rightHandSide == null)
                {
                    throw new SyntaxException(this.document, operatorToken.LineNumber);
                }

                // Get the expression operator type.
                switch (operatorToken.SymbolType)
                {
                    case OperatorType.ConditionalAnd:
                        expression = new ConditionalAndExpression(expressionProxy, leftHandSide, rightHandSide);
                        break;

                    case OperatorType.ConditionalOr:
                        expression = new ConditionalOrExpression(expressionProxy, leftHandSide, rightHandSide);
                        break;

                    default:
                        throw new SyntaxException(this.document, operatorToken.LineNumber);
                }

                parentProxy.Children.Add(expression);
            }

            return expression;
        }