private void visitYieldThrows(Node n, Node parent) { Node ifThrows = IR.ifNode( IR.shne(IR.name(GENERATOR_THROW_ARG), IR.name("undefined")), IR.block(IR.throwNode(IR.name(GENERATOR_THROW_ARG)))); parent.addChildAfter(ifThrows, n); compiler.reportCodeChange(); }
/** Transpiles "do while" statement. */ void transpileDo( Node n, @Nullable TranspilationContext.Case breakCase, @Nullable TranspilationContext.Case continueCase) { TranspilationContext.Case startCase = context.createCase(); breakCase = context.maybeCreateCase(breakCase); continueCase = context.maybeCreateCase(continueCase); context.switchCaseTo(startCase); // Transpile body Node body = n.removeFirstChild(); context.pushBreakContinueContext(breakCase, continueCase); transpileStatement(body); context.popBreakContinueContext(); // Transpile condition context.switchCaseTo(continueCase); Node condition = prepareNodeForWrite(maybeDecomposeExpression(n.removeFirstChild())); context.writeGeneratedNode( IR.ifNode(condition, context.createJumpToBlock(startCase, /** allowEmbedding=*/ false, n)) .useSourceInfoFrom(n)); context.switchCaseTo(breakCase); }
/** Transpiles "while" statement. */ void transpileWhile( Node n, @Nullable TranspilationContext.Case breakCase, @Nullable TranspilationContext.Case continueCase) { TranspilationContext.Case startCase = context.maybeCreateCase(continueCase); TranspilationContext.Case endCase = context.maybeCreateCase(breakCase); context.switchCaseTo(startCase); // Transpile condition Node condition = prepareNodeForWrite(maybeDecomposeExpression(n.removeFirstChild())); Node body = n.removeFirstChild(); context.writeGeneratedNode( IR.ifNode( withType(IR.not(condition), booleanType).useSourceInfoFrom(condition), context.createJumpToBlock( endCase, /** allowEmbedding= */ true, n)) .useSourceInfoFrom(n)); // Transpile "while" body context.pushBreakContinueContext(endCase, startCase); transpileStatement(body); context.popBreakContinueContext(); context.writeJumpTo(startCase, n); context.switchCaseTo(endCase); }
} else { equivBlock = IR.ifNode( IR.or( didEnter.cloneTree(),
ifBlock.addChildToBack(jumpToNode); transpileUnmarkedNode(IR.ifNode(condition, ifBlock).useSourceInfoFrom(n)); transpileStatement(elseBlock); context.switchCaseTo(endCase); Node newIfBlock = context.createJumpToBlock(ifCase, /** allowEmbedding=*/ true, n); context.writeGeneratedNode( IR.ifNode(prepareNodeForWrite(condition), newIfBlock).useSourceInfoFrom(n)); transpileStatement(elseBlock); context.writeJumpTo(endCase, elseBlock);
/** * Uses a case statement to jump over the body if the condition of the * if statement is false. Additionally, lift the body of the {@code if} * statement to the top level. */ private void visitIf() { Node condition = currentStatement.removeFirstChild(); Node ifBody = currentStatement.removeFirstChild(); boolean hasElse = currentStatement.hasChildren(); int ifEndState = generatorCaseCount++; Node invertedConditional = IR.ifNode(IR.not(condition), IR.block(createStateUpdate(ifEndState), createSafeBreak())); invertedConditional.setGeneratorSafe(true); Node endIf = makeGeneratorMarker(ifEndState); originalGeneratorBody.addChildToFront(invertedConditional); originalGeneratorBody.addChildAfter(ifBody, invertedConditional); originalGeneratorBody.addChildAfter(endIf, ifBody); if (hasElse) { Node elseBlock = currentStatement.removeFirstChild(); int elseEndState = generatorCaseCount++; Node endElse = makeGeneratorMarker(elseEndState); ifBody.addChildToBack(createStateUpdate(elseEndState)); ifBody.addChildToBack(createSafeBreak()); originalGeneratorBody.addChildAfter(elseBlock, endIf); originalGeneratorBody.addChildAfter(endElse, elseBlock); } }
IR.constNode(IR.name(resultTempName), constructAwaitNextResult(ctx, iteratorTempName)); Node breakIfDone = IR.ifNode(getprop(IR.name(resultTempName), "done"), IR.block(IR.breakNode()));
condition = prepareNodeForWrite(maybeDecomposeExpression(condition.detach())); context.writeGeneratedNode( IR.ifNode( withType(IR.not(condition), booleanType).useSourceInfoFrom(condition), context.createJumpToBlock(
Node conditionalBranch = IR.ifNode(condition.isEmpty() ? IR.trueNode() : condition, body); Node setStateLoopStart = createStateUpdate(loopBeginState); Node breakToStart = createSafeBreak();
IR.ifNode( IR.not(IR.in(variable.cloneTree(), iterableName.cloneTree())), IR.block(IR.continueNode())));