Skip to content

Commit db0bd4e

Browse files
committed
[Truffle] Share logic between visitWhileNode and visitUntilNode.
1 parent f90af5a commit db0bd4e

File tree

1 file changed

+10
-29
lines changed

1 file changed

+10
-29
lines changed

truffle/src/main/java/org/jruby/truffle/translator/BodyTranslator.java

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2625,31 +2625,8 @@ public RubyNode visitUndefNode(org.jruby.ast.UndefNode node) {
26252625

26262626
@Override
26272627
public RubyNode visitUntilNode(org.jruby.ast.UntilNode node) {
2628-
final SourceSection sourceSection = translate(node.getPosition());
2629-
2630-
RubyNode condition = node.getConditionNode().accept(this);
2631-
RubyNode conditionInversed = new NotNode(context, sourceSection, condition);
2632-
2633-
final boolean oldTranslatingWhile = translatingWhile;
2634-
translatingWhile = true;
2635-
2636-
final RubyNode body;
2637-
2638-
try {
2639-
body = node.getBodyNode().accept(this);
2640-
} finally {
2641-
translatingWhile = oldTranslatingWhile;
2642-
}
2643-
2644-
final RubyNode loop;
2645-
2646-
if (node.evaluateAtStart()) {
2647-
loop = WhileNode.createWhile(context, sourceSection, conditionInversed, body);
2648-
} else {
2649-
loop = WhileNode.createDoWhile(context, sourceSection, conditionInversed, body);
2650-
}
2651-
2652-
return new CatchBreakFromCallNode(context, sourceSection, loop, environment.getBlockID());
2628+
org.jruby.ast.WhileNode whileNode = new org.jruby.ast.WhileNode(node.getPosition(), node.getConditionNode(), node.getBodyNode(), node.evaluateAtStart());
2629+
return visitWhileNode(whileNode, true);
26532630
}
26542631

26552632
@Override
@@ -2666,23 +2643,27 @@ public RubyNode visitVCallNode(org.jruby.ast.VCallNode node) {
26662643

26672644
@Override
26682645
public RubyNode visitWhileNode(org.jruby.ast.WhileNode node) {
2646+
return visitWhileNode(node, false);
2647+
}
2648+
2649+
private RubyNode visitWhileNode(org.jruby.ast.WhileNode node, boolean conditionInversed) {
26692650
final SourceSection sourceSection = translate(node.getPosition());
26702651

26712652
RubyNode condition = node.getConditionNode().accept(this);
2653+
if (conditionInversed) {
2654+
condition = new NotNode(context, sourceSection, condition);
2655+
}
26722656

2657+
final RubyNode body;
26732658
final boolean oldTranslatingWhile = translatingWhile;
26742659
translatingWhile = true;
2675-
2676-
final RubyNode body;
2677-
26782660
try {
26792661
body = node.getBodyNode().accept(this);
26802662
} finally {
26812663
translatingWhile = oldTranslatingWhile;
26822664
}
26832665

26842666
final RubyNode loop;
2685-
26862667
if (node.evaluateAtStart()) {
26872668
loop = WhileNode.createWhile(context, sourceSection, condition, body);
26882669
} else {

0 commit comments

Comments
 (0)