Skip to content

Commit

Permalink
[Truffle] Share logic between visitWhileNode and visitUntilNode.
Browse files Browse the repository at this point in the history
  • Loading branch information
eregon committed Apr 22, 2015
1 parent f90af5a commit db0bd4e
Showing 1 changed file with 10 additions and 29 deletions.
Expand Up @@ -2625,31 +2625,8 @@ public RubyNode visitUndefNode(org.jruby.ast.UndefNode node) {

@Override
public RubyNode visitUntilNode(org.jruby.ast.UntilNode node) {
final SourceSection sourceSection = translate(node.getPosition());

RubyNode condition = node.getConditionNode().accept(this);
RubyNode conditionInversed = new NotNode(context, sourceSection, condition);

final boolean oldTranslatingWhile = translatingWhile;
translatingWhile = true;

final RubyNode body;

try {
body = node.getBodyNode().accept(this);
} finally {
translatingWhile = oldTranslatingWhile;
}

final RubyNode loop;

if (node.evaluateAtStart()) {
loop = WhileNode.createWhile(context, sourceSection, conditionInversed, body);
} else {
loop = WhileNode.createDoWhile(context, sourceSection, conditionInversed, body);
}

return new CatchBreakFromCallNode(context, sourceSection, loop, environment.getBlockID());
org.jruby.ast.WhileNode whileNode = new org.jruby.ast.WhileNode(node.getPosition(), node.getConditionNode(), node.getBodyNode(), node.evaluateAtStart());
return visitWhileNode(whileNode, true);
}

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

@Override
public RubyNode visitWhileNode(org.jruby.ast.WhileNode node) {
return visitWhileNode(node, false);
}

private RubyNode visitWhileNode(org.jruby.ast.WhileNode node, boolean conditionInversed) {
final SourceSection sourceSection = translate(node.getPosition());

RubyNode condition = node.getConditionNode().accept(this);
if (conditionInversed) {
condition = new NotNode(context, sourceSection, condition);
}

final RubyNode body;
final boolean oldTranslatingWhile = translatingWhile;
translatingWhile = true;

final RubyNode body;

try {
body = node.getBodyNode().accept(this);
} finally {
translatingWhile = oldTranslatingWhile;
}

final RubyNode loop;

if (node.evaluateAtStart()) {
loop = WhileNode.createWhile(context, sourceSection, condition, body);
} else {
Expand Down

0 comments on commit db0bd4e

Please sign in to comment.