508 newCatchBlocks.add(catchAllBlock(tryNode));
509 return tryNode.setCatchBlocks(newCatchBlocks);
510 }
511
512 @Override
513 public Node leaveVarNode(final VarNode varNode) {
514 addStatement(varNode);
515 if (varNode.getFlag(VarNode.IS_LAST_FUNCTION_DECLARATION) && lc.getCurrentFunction().isProgram()) {
516 new ExpressionStatement(varNode.getLineNumber(), varNode.getToken(), varNode.getFinish(), new IdentNode(varNode.getName())).accept(this);
517 }
518 return varNode;
519 }
520
521 @Override
522 public Node leaveWhileNode(final WhileNode whileNode) {
523 final Expression test = whileNode.getTest();
524 final Block body = whileNode.getBody();
525
526 if (isAlwaysTrue(test)) {
527 //turn it into a for node without a test.
528 final ForNode forNode = (ForNode)new ForNode(whileNode.getLineNumber(), whileNode.getToken(), whileNode.getFinish(), body, ForNode.IS_FOR).accept(this);
529 lc.replace(whileNode, forNode);
530 return forNode;
531 }
532
533 return addStatement(checkEscape(whileNode));
534 }
535
536 @Override
537 public Node leaveWithNode(final WithNode withNode) {
538 return addStatement(withNode);
539 }
540
541 /**
542 * Given a function node that is a callee in a CallNode, replace it with
543 * the appropriate marker function. This is used by {@link CodeGenerator}
544 * for fast scope calls
545 *
546 * @param function function called by a CallNode
547 * @return transformed node to marker function or identity if not ident/access/indexnode
548 */
|
508 newCatchBlocks.add(catchAllBlock(tryNode));
509 return tryNode.setCatchBlocks(newCatchBlocks);
510 }
511
512 @Override
513 public Node leaveVarNode(final VarNode varNode) {
514 addStatement(varNode);
515 if (varNode.getFlag(VarNode.IS_LAST_FUNCTION_DECLARATION) && lc.getCurrentFunction().isProgram()) {
516 new ExpressionStatement(varNode.getLineNumber(), varNode.getToken(), varNode.getFinish(), new IdentNode(varNode.getName())).accept(this);
517 }
518 return varNode;
519 }
520
521 @Override
522 public Node leaveWhileNode(final WhileNode whileNode) {
523 final Expression test = whileNode.getTest();
524 final Block body = whileNode.getBody();
525
526 if (isAlwaysTrue(test)) {
527 //turn it into a for node without a test.
528 final ForNode forNode = (ForNode)new ForNode(whileNode.getLineNumber(), whileNode.getToken(), whileNode.getFinish(), body, 0).accept(this);
529 lc.replace(whileNode, forNode);
530 return forNode;
531 }
532
533 return addStatement(checkEscape(whileNode));
534 }
535
536 @Override
537 public Node leaveWithNode(final WithNode withNode) {
538 return addStatement(withNode);
539 }
540
541 /**
542 * Given a function node that is a callee in a CallNode, replace it with
543 * the appropriate marker function. This is used by {@link CodeGenerator}
544 * for fast scope calls
545 *
546 * @param function function called by a CallNode
547 * @return transformed node to marker function or identity if not ident/access/indexnode
548 */
|