コード例 #1
0
        /// <summary>
        /// Reads a relational 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 previous expression.</param>
        /// <returns>Returns the expression.</returns>
        private RelationalExpression GetConditionalPreprocessorEqualityExpression(
            CodeUnitProxy parentProxy, Expression leftHandSide, ExpressionPrecedence previousPrecedence)
        {
            Param.AssertNotNull(parentProxy, "parentProxy");
            Param.AssertNotNull(leftHandSide, "leftHandSide");
            Param.Ignore(previousPrecedence);

            RelationalExpression 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.ConditionalEquals:
                    expression = new EqualToExpression(expressionProxy, leftHandSide, rightHandSide);
                    break;

                case OperatorType.NotEquals:
                    expression = new NotEqualToExpression(expressionProxy, leftHandSide, rightHandSide);
                    break;

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

                parentProxy.Children.Add(expression);
            }

            return(expression);
        }
コード例 #2
0
        /// <summary>
        /// Reads a relational 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 RelationalExpression GetRelationalExpression(
            CodeUnitProxy expressionProxy, Expression leftHandSide, ExpressionPrecedence previousPrecedence, bool unsafeCode)
        {
            Param.AssertNotNull(expressionProxy, "expressionProxy");
            Param.AssertNotNull(leftHandSide, "leftHandSide");
            Param.Ignore(previousPrecedence);
            Param.Ignore(unsafeCode);

            RelationalExpression expression = null;

            // Read the details of the expression.
            OperatorSymbolToken operatorToken = this.PeekOperatorSymbolToken();
            CsLanguageService.Debug.Assert(operatorToken.Category == OperatorCategory.Relational, "Expected a relational 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.ConditionalEquals:
                        expression = new EqualToExpression(expressionProxy, leftHandSide, rightHandSide);
                        break;

                    case OperatorType.NotEquals:
                        expression = new NotEqualToExpression(expressionProxy, leftHandSide, rightHandSide);
                        break;

                    case OperatorType.GreaterThan:
                        expression = new GreaterThanExpression(expressionProxy, leftHandSide, rightHandSide);
                        break;

                    case OperatorType.GreaterThanOrEquals:
                        expression = new GreaterThanOrEqualToExpression(expressionProxy, leftHandSide, rightHandSide);
                        break;

                    case OperatorType.LessThan:
                        expression = new LessThanExpression(expressionProxy, leftHandSide, rightHandSide);
                        break;

                    case OperatorType.LessThanOrEquals:
                        expression = new LessThanOrEqualToExpression(expressionProxy, leftHandSide, rightHandSide);
                        break;

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

            return expression;
        }
コード例 #3
0
        /// <summary>
        /// Reads a relational 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 previous expression.</param>
        /// <returns>Returns the expression.</returns>
        private RelationalExpression GetConditionalPreprocessorEqualityExpression(
            CodeUnitProxy parentProxy, Expression leftHandSide, ExpressionPrecedence previousPrecedence)
        {
            Param.AssertNotNull(parentProxy, "parentProxy");
            Param.AssertNotNull(leftHandSide, "leftHandSide");
            Param.Ignore(previousPrecedence);

            RelationalExpression 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.ConditionalEquals:
                        expression = new EqualToExpression(expressionProxy, leftHandSide, rightHandSide);
                        break;

                    case OperatorType.NotEquals:
                        expression = new NotEqualToExpression(expressionProxy, leftHandSide, rightHandSide);
                        break;

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

                parentProxy.Children.Add(expression);
            }

            return expression;
        }