< prev index next >

src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/SplitIntoFunctions.java

Print this page




 295         return block;
 296     }
 297 
 298     private static IfNode makeIfStateEquals(final int lineNumber, final long token, final int finish,
 299             final int value, final Block pass, final Statement fail) {
 300         return new IfNode(lineNumber, token, finish,
 301                 new BinaryNode(Token.recast(token, TokenType.EQ_STRICT),
 302                         GetSplitState.INSTANCE, intLiteral(value)),
 303                 pass,
 304                 fail == null ? null : new Block(NO_TOKEN, NO_FINISH, fail));
 305     }
 306 
 307     @Override
 308     public boolean enterVarNode(final VarNode varNode) {
 309         if (!inSplitNode()) {
 310             return super.enterVarNode(varNode);
 311         }
 312         assert !varNode.isBlockScoped(); //TODO: we must handle these too, but we currently don't
 313 
 314         final Expression init = varNode.getInit();
 315         if (varNode.isAnonymousFunctionDeclaration()) {
 316             // We ain't moving anonymous function declarations.
 317             return super.enterVarNode(varNode);
 318         }
 319 
 320         // Move a declaration-only var statement to the top of the outermost function.
 321         getCurrentFunctionState().varStatements.add(varNode.setInit(null));
 322         // If it had an initializer, replace it with an assignment expression statement. Note that "var" is a
 323         // statement, so it doesn't contribute to :return of the programs, therefore we are _not_ adding a
 324         // ":return = ..." assignment around the original assignment.
 325         if (init != null) {
 326             final long token = Token.recast(varNode.getToken(), TokenType.ASSIGN);
 327             new ExpressionStatement(varNode.getLineNumber(), token, varNode.getFinish(),
 328                     new BinaryNode(token, varNode.getName(), varNode.getInit())).accept(this);
 329         }
 330 
 331         return false;
 332     }
 333 
 334     @Override
 335     public Node leaveBlock(final Block block) {
 336         if (!artificialBlock) {
 337             if (lc.isFunctionBody()) {
 338                 // Prepend declaration-only var statements to the top of the statement list.




 295         return block;
 296     }
 297 
 298     private static IfNode makeIfStateEquals(final int lineNumber, final long token, final int finish,
 299             final int value, final Block pass, final Statement fail) {
 300         return new IfNode(lineNumber, token, finish,
 301                 new BinaryNode(Token.recast(token, TokenType.EQ_STRICT),
 302                         GetSplitState.INSTANCE, intLiteral(value)),
 303                 pass,
 304                 fail == null ? null : new Block(NO_TOKEN, NO_FINISH, fail));
 305     }
 306 
 307     @Override
 308     public boolean enterVarNode(final VarNode varNode) {
 309         if (!inSplitNode()) {
 310             return super.enterVarNode(varNode);
 311         }
 312         assert !varNode.isBlockScoped(); //TODO: we must handle these too, but we currently don't
 313 
 314         final Expression init = varNode.getInit();




 315 
 316         // Move a declaration-only var statement to the top of the outermost function.
 317         getCurrentFunctionState().varStatements.add(varNode.setInit(null));
 318         // If it had an initializer, replace it with an assignment expression statement. Note that "var" is a
 319         // statement, so it doesn't contribute to :return of the programs, therefore we are _not_ adding a
 320         // ":return = ..." assignment around the original assignment.
 321         if (init != null) {
 322             final long token = Token.recast(varNode.getToken(), TokenType.ASSIGN);
 323             new ExpressionStatement(varNode.getLineNumber(), token, varNode.getFinish(),
 324                     new BinaryNode(token, varNode.getName(), varNode.getInit())).accept(this);
 325         }
 326 
 327         return false;
 328     }
 329 
 330     @Override
 331     public Node leaveBlock(final Block block) {
 332         if (!artificialBlock) {
 333             if (lc.isFunctionBody()) {
 334                 // Prepend declaration-only var statements to the top of the statement list.


< prev index next >