Пример #1
0
        private void DesugarConstPatternCase(expression matchingExpression, pattern_case patternCase)
        {
            Debug.Assert(patternCase.pattern is const_pattern);
            var patternExpressionNode = patternCase.pattern as const_pattern;

            var statementsToAdd = new List <statement>();
            var equalCalls      = new List <bin_expr>();

            foreach (var patternExpression in patternExpressionNode.pattern_expressions.expressions)
            {
                statementsToAdd.Add(GetTypeCompatibilityCheck(matchingExpression, patternExpression));

                equalCalls.Add(
                    new bin_expr(matchingExpression, patternExpression, Operators.Equal, patternCase.source_context
                                 )
                    );
            }
            typeChecks.AddRange(statementsToAdd);

            expression orPatternCases = equalCalls[0];

            for (int i = 1; i < equalCalls.Count; ++i)
            {
                orPatternCases = bin_expr.LogicalOr(orPatternCases, equalCalls[i]);
            }
            var ifCondition = patternCase.condition == null ? orPatternCases : bin_expr.LogicalAnd(orPatternCases, patternCase.condition);
            var ifCheck     = SubtreeCreator.CreateIf(ifCondition, patternCase.case_action);

            // Добавляем полученные statements в результат
            AddDesugaredCaseToResult(ifCheck, ifCheck);
        }
        void DesugarDeconstructorPatternCase(expression matchingExpression, pattern_case patternCase)
        {
            Debug.Assert(patternCase.pattern is deconstructor_pattern);

            var isExpression = new is_pattern_expr(matchingExpression, patternCase.pattern);
            var ifCondition  = patternCase.condition == null ? (expression)isExpression : bin_expr.LogicalAnd(isExpression, patternCase.condition);
            var ifCheck      = SubtreeCreator.CreateIf(ifCondition, patternCase.case_action);

            // Добавляем полученные statements в результат
            AddDesugaredCaseToResult(ifCheck, ifCheck);
        }
Пример #3
0
        private void DefaultDesugarPattern(expression matchingExpression, pattern_case patternCase)
        {
            //var paramCheckExpr = DesugarDeconstructorPatternParameters(patternCase.pattern as deconstructor_pattern);

            var isExpression = new is_pattern_expr(matchingExpression, patternCase.pattern, patternCase.source_context);
            var ifCondition  = patternCase.condition == null ? (expression)isExpression : bin_expr.LogicalAnd(isExpression, patternCase.condition);
            var ifCheck      = SubtreeCreator.CreateIf(ifCondition, patternCase.case_action);

            // Добавляем полученные statements в результат
            AddDesugaredCaseToResult(ifCheck, ifCheck);
        }
 public if_node GetPatternCheckWithDeconstrunctorCall()
 {
     return(SubtreeCreator.CreateIf(
                TypeCastCheck,
                new statement_list(new assign(SuccessVariable.name, true), DeconstructCall)));
 }