Esempio n. 1
0
        protected override BoundStatement RewriteForStatement(BoundForStatement node)
        {
            // for <var> = <lower> to <upper>
            //      <body>
            //
            // ---->
            //
            // {
            //      var <var> = <lower>
            //      while (<var> <= <upper>)
            //      {
            //          <body>
            //          <var> = <var> + 1
            //      }
            // }

            var variableDeclaration   = new BoundVeriableDeclaration(node.Variable, node.LowerBound);
            var variableExpression    = new BoundVariableExpression(node.Variable);
            var upperBoundSybmle      = new VariableSymble("upperBound", true, typeof(int));
            var upperBoundDeclaration = new BoundVeriableDeclaration(upperBoundSybmle, node.UpperBound);
            var condition             = new BoundBinaryExpression(
                variableExpression,
                BoundBinaryOperator.Bind(SyntaxKind.LessOrEqualToken, typeof(int), typeof(int)),
                new BoundVariableExpression(upperBoundSybmle)
                );
            var increment = new BoundExpressionStatemnet(
                new BoundAssignmentExpression(
                    node.Variable,
                    new BoundBinaryExpression(
                        variableExpression,
                        BoundBinaryOperator.Bind(SyntaxKind.PlusToken, typeof(int), typeof(int)),
                        new BoundLiteralExpression(1)
                        )
                    )
                );
            var whileBody      = new BoundBlockStatemnet(ImmutableArray.Create <BoundStatement>(node.Body, increment));
            var whileStatement = new BoundWhileStatement(condition, whileBody);
            var result         = new BoundBlockStatemnet(ImmutableArray.Create <BoundStatement>(
                                                             variableDeclaration, upperBoundDeclaration, whileStatement));

            return(RewriteStatement(result));
        }
Esempio n. 2
0
        protected override BoundStatement RewriteForStatement(BoundForStatement node)
        {
            // for <var> = <lower> to <upper> by <incriment>
            //      <body>
            //
            // ---->
            //
            // {
            //      var <var> = <lower>
            //      while (<var> <= <upper>)
            //      {
            //          <body>
            //          continue:
            //          <var> = <var> + 1
            //      }
            // }



            var variableDeclaration = new BoundVeriableDeclaration(node.Variable, node.LowerBound);
            var variableExpression  = new BoundVariableExpression(node.Variable);


            var upperBoundSybmle      = new LocalVariableSymbol("upperBound", true, TypeSymbol.Int);
            var upperBoundDeclaration = new BoundVeriableDeclaration(upperBoundSybmle, node.UpperBound);

            var condition = new BoundBinaryExpression(
                variableExpression,
                BoundBinaryOperator.Bind(SyntaxKind.LessOrEqualToken, TypeSymbol.Int, TypeSymbol.Int),
                new BoundVariableExpression(upperBoundSybmle)
                );

            var Ittertator = node.Itterator;
            var Operator   = SyntaxKind.PlusToken;

            if (Ittertator == null)
            {
                Ittertator = new BoundLiteralExpression(1);
            }
            var continueLabelStatement = new BoundLabelStatement(node.ContinueLabel);
            var increment = new BoundExpressionStatemnet(
                new BoundAssignmentExpression(
                    node.Variable,
                    new BoundBinaryExpression(
                        variableExpression,
                        BoundBinaryOperator.Bind(Operator, TypeSymbol.Int, TypeSymbol.Int),
                        Ittertator
                        )
                    )
                );
            var whileBody = new BoundBlockStatemnet(ImmutableArray.Create <BoundStatement>(
                                                        node.Body,
                                                        continueLabelStatement,
                                                        increment)
                                                    );
            var whileStatement = new BoundWhileStatement(condition, whileBody, node.BodyLabel, node.BreakLabel, GenerateLabel());
            var result         = new BoundBlockStatemnet(ImmutableArray.Create <BoundStatement>(
                                                             variableDeclaration,
                                                             upperBoundDeclaration,
                                                             whileStatement));

            return(RewriteStatement(result));
        }
Esempio n. 3
0
 private void EvaluateExpressiontatement(BoundExpressionStatemnet node)
 {
     _lastValue = EvaluateExpression(node.Expression);
 }