< prev index next >

src/jdk/nashorn/internal/codegen/SplitIntoFunctions.java

Print this page




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




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




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


< prev index next >