コード例 #1
0
        private IList <BlockStatementTranslation> GetBlockStatements(
            BlockExpression block,
            ITranslationContext context,
            out bool hasMultiStatementStatement,
            out int estimatedStatementsSize,
            out bool hasGoto)
        {
            var expressions     = block.Expressions;
            var expressionCount = expressions.Count;
            var translations    = new BlockStatementTranslation[expressionCount];
            var statementIndex  = 0;

            hasMultiStatementStatement = false;
            estimatedStatementsSize    = 0;
            hasGoto = false;

            for (int i = 0, lastExpressionIndex = expressionCount - 1; ; ++i)
            {
                var isFinalStatement = i == lastExpressionIndex;
                var expression       = expressions[i];

                if (Include(expression, block, context))
                {
                    var statementTranslation = context.IsNotJoinedAssignment(expression)
                        ? new BlockStatementTranslation(expression, context)
                        : new BlockAssignmentStatementTranslation((BinaryExpression)expression, context);

                    translations[statementIndex++] = statementTranslation;
                    estimatedStatementsSize       += statementTranslation.EstimatedSize;
                    hasMultiStatementStatement     = hasMultiStatementStatement || statementTranslation.IsMultiStatement;

                    if (statementIndex == 1)
                    {
                        statementTranslation.IsFirstStatement();
                    }

                    if (isFinalStatement)
                    {
                        var isReturnable = block.IsReturnable();

                        if (isReturnable)
                        {
                            ConfigureFinalStatementReturn(statementTranslation, statementIndex, ref hasGoto);
                        }

                        var addBlankLineBefore =
                            isReturnable && AddBlankLineBeforeFinalStatement(statementIndex, translations);

                        statementTranslation.IsFinalStatement(addBlankLineBefore);
                        break;
                    }

                    continue;
                }

                if (isFinalStatement)
                {
                    break;
                }
            }

            if (statementIndex == expressionCount)
            {
                return(translations);
            }

            // Statements were skipped; resize the translations array
            var includedTranslations = new BlockStatementTranslation[statementIndex];

            for (var i = 0; i < statementIndex; ++i)
            {
                includedTranslations[i] = translations[i];
            }

            return(includedTranslations);
        }