Пример #1
0
    protected override BoundExpression RewriteWhileExpression(BoundWhileExpression node)
    {
        /*
         * while <condition>
         *     <body>
         *
         * <whileLabel>
         * gotoIfFalse <condition> <endLabel>
         *     <body>
         *     goto <whileLabel>
         * <endLabel>
         */

        var body      = RewriteExpression(node.Body);
        var condition = RewriteExpression(node.Condition);

        return(RewriteExpression(
                   new BoundBlockExpression(
                       node.Syntax,
                       ImmutableArray.Create <BoundStatement>(
                           new BoundLabelStatement(node.Syntax, node.ContinueLabel),
                           new BoundConditionalGotoStatement(node.Syntax, node.BreakLabel, condition),
                           new BoundExpressionStatement(node.Syntax, body),
                           new BoundGotoStatement(node.Syntax, node.ContinueLabel),
                           new BoundLabelStatement(node.Syntax, node.BreakLabel)
                           ),
                       new BoundUnitExpression(node.Syntax)
                       )
                   ));
    }
Пример #2
0
 public override void VisitWhileExpression(BoundWhileExpression node)
 {
     _writer.WriteKeyword("while ");
     _writer.WritePunctuation("(");
     node.Condition.Accept(this);
     _writer.WritePunctuation(") ");
     _writer.WriteLine();
     WriteNestedExpression(node.Body);
 }
Пример #3
0
 public virtual void VisitWhileExpression(BoundWhileExpression node) =>
 this.DefaultVisit(node);
Пример #4
0
 protected override BoundExpression RewriteWhileExpression(BoundWhileExpression node)
 {
     throw new InvalidProgramException("No `while` expression should exist at this stage");
 }