コード例 #1
0
        /// <summary>
        /// Reads a null coalescing 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>
        /// <param name="parentReference">The parent code unit.</param>
        /// <param name="unsafeCode">Indicates whether the code being parsed resides in an unsafe code block.</param>
        /// <returns>Returns the expression.</returns>
        private NullCoalescingExpression GetNullCoalescingExpression(
            Expression leftHandSide, ExpressionPrecedence previousPrecedence, Reference<ICodePart> parentReference, bool unsafeCode)
        {
            Param.AssertNotNull(leftHandSide, "leftHandSide");
            Param.Ignore(previousPrecedence);
            Param.AssertNotNull(parentReference, "parentReference");
            Param.Ignore(unsafeCode);

            NullCoalescingExpression expression = null;
            var expressionReference = new Reference<ICodePart>();

            // Read the details of the expression.
            OperatorSymbol operatorToken = this.PeekOperatorToken(parentReference, expressionReference);
            Debug.Assert(operatorToken.SymbolType == OperatorType.NullCoalescingSymbol, "Expected a null-coalescing symbol");

            // 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();
                this.tokens.Add(operatorToken);

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

                // 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 NullCoalescingExpression(partialTokens, leftHandSide, rightHandSide);
                expressionReference.Target = expression;
            }

            return expression;
        }
コード例 #2
0
ファイル: CodeParser.cs プロジェクト: katerina-marchenkova/my
 private NullCoalescingExpression GetNullCoalescingExpression(Expression leftHandSide, ExpressionPrecedence previousPrecedence, bool unsafeCode)
 {
     NullCoalescingExpression expression = null;
     OperatorSymbol item = this.PeekOperatorToken();
     ExpressionPrecedence operatorPrecedence = GetOperatorPrecedence(item.SymbolType);
     if (CheckPrecedence(previousPrecedence, operatorPrecedence))
     {
         this.symbols.Advance();
         this.tokens.Add(item);
         Expression operatorRightHandExpression = this.GetOperatorRightHandExpression(operatorPrecedence, unsafeCode);
         CsTokenList tokens = new CsTokenList(this.tokens, leftHandSide.Tokens.First, this.tokens.Last);
         expression = new NullCoalescingExpression(tokens, leftHandSide, operatorRightHandExpression);
     }
     return expression;
 }