src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/parser/Parser.java
Print this page
*** 75,85 ****
--- 75,87 ----
import jdk.nashorn.internal.ir.BreakNode;
import jdk.nashorn.internal.ir.CallNode;
import jdk.nashorn.internal.ir.CaseNode;
import jdk.nashorn.internal.ir.CatchNode;
import jdk.nashorn.internal.ir.ContinueNode;
+ import jdk.nashorn.internal.ir.DebuggerNode;
import jdk.nashorn.internal.ir.EmptyNode;
+ import jdk.nashorn.internal.ir.ErrorNode;
import jdk.nashorn.internal.ir.Expression;
import jdk.nashorn.internal.ir.ExpressionStatement;
import jdk.nashorn.internal.ir.ForNode;
import jdk.nashorn.internal.ir.FunctionNode;
import jdk.nashorn.internal.ir.FunctionNode.CompilationState;
*** 354,364 ****
functionDeclarations = null;
restoreBlock(body);
body.setFlag(Block.NEEDS_SCOPE);
! final Block functionBody = new Block(functionToken, source.getLength() - 1, body.getFlags(), body.getStatements());
lc.pop(function);
expect(EOF);
final FunctionNode functionNode = createFunctionNode(
--- 356,367 ----
functionDeclarations = null;
restoreBlock(body);
body.setFlag(Block.NEEDS_SCOPE);
! final Block functionBody = new Block(functionToken, source.getLength() - 1,
! body.getFlags() | Block.IS_SYNTHETIC, body.getStatements());
lc.pop(function);
expect(EOF);
final FunctionNode functionNode = createFunctionNode(
*** 538,548 ****
// Block closing brace.
if (needsBraces) {
expect(RBRACE);
}
! return new Block(blockToken, finish, newBlock.getFlags(), newBlock.getStatements());
}
/**
* Get all the statements generated by a single statement.
--- 541,552 ----
// Block closing brace.
if (needsBraces) {
expect(RBRACE);
}
! final int flags = newBlock.getFlags() | (needsBraces? 0 : Block.IS_SYNTHETIC);
! return new Block(blockToken, finish, flags, newBlock.getStatements());
}
/**
* Get all the statements generated by a single statement.
*** 557,567 ****
try {
statement(false, false, true);
} finally {
restoreBlock(newBlock);
}
! return new Block(newBlock.getToken(), finish, newBlock.getFlags(), newBlock.getStatements());
}
/**
* Detect calls to special functions.
* @param ident Called function.
--- 561,571 ----
try {
statement(false, false, true);
} finally {
restoreBlock(newBlock);
}
! return new Block(newBlock.getToken(), finish, newBlock.getFlags() | Block.IS_SYNTHETIC, newBlock.getStatements());
}
/**
* Detect calls to special functions.
* @param ident Called function.
*** 710,720 ****
addFunctionDeclarations(script);
functionDeclarations = null;
restoreBlock(body);
body.setFlag(Block.NEEDS_SCOPE);
! final Block programBody = new Block(functionToken, functionLine, body.getFlags(), body.getStatements());
lc.pop(script);
script.setLastToken(token);
expect(EOF);
--- 714,724 ----
addFunctionDeclarations(script);
functionDeclarations = null;
restoreBlock(body);
body.setFlag(Block.NEEDS_SCOPE);
! final Block programBody = new Block(functionToken, functionLine, body.getFlags() | Block.IS_SYNTHETIC, body.getStatements());
lc.pop(script);
script.setLastToken(token);
expect(EOF);
*** 824,835 ****
--- 828,844 ----
}
}
}
}
} catch (final Exception e) {
+ final int errorLine = line;
+ final long errorToken = token;
//recover parsing
recover(e);
+ final ErrorNode errorExpr = new ErrorNode(errorToken, finish);
+ final ExpressionStatement expressionStatement = new ExpressionStatement(errorLine, errorToken, finish, errorExpr);
+ appendStatement(expressionStatement);
}
// No backtracking from here on.
stream.commit(k);
}
*** 1851,1861 ****
final Block catchBody = getBlock(true);
final CatchNode catchNode = new CatchNode(catchLine, catchToken, finish, exception, ifExpression, catchBody, false);
appendStatement(catchNode);
} finally {
restoreBlock(catchBlock);
! catchBlocks.add(new Block(catchBlock.getToken(), finish, catchBlock.getFlags(), catchBlock.getStatements()));
}
// If unconditional catch then should to be the end.
if (ifExpression == null) {
break;
--- 1860,1870 ----
final Block catchBody = getBlock(true);
final CatchNode catchNode = new CatchNode(catchLine, catchToken, finish, exception, ifExpression, catchBody, false);
appendStatement(catchNode);
} finally {
restoreBlock(catchBlock);
! catchBlocks.add(new Block(catchBlock.getToken(), finish, catchBlock.getFlags() | Block.IS_SYNTHETIC, catchBlock.getStatements()));
}
// If unconditional catch then should to be the end.
if (ifExpression == null) {
break;
*** 1881,1891 ****
appendStatement(tryNode);
} finally {
restoreBlock(outer);
}
! appendStatement(new BlockStatement(startLine, new Block(tryToken, finish, outer.getFlags(), outer.getStatements())));
}
/**
* DebuggerStatement :
* debugger ;
--- 1890,1900 ----
appendStatement(tryNode);
} finally {
restoreBlock(outer);
}
! appendStatement(new BlockStatement(startLine, new Block(tryToken, finish, outer.getFlags() | Block.IS_SYNTHETIC, outer.getStatements())));
}
/**
* DebuggerStatement :
* debugger ;
*** 1899,1909 ****
final int debuggerLine = line;
final long debuggerToken = token;
// DEBUGGER tested in caller.
next();
endOfLine();
! appendStatement(new ExpressionStatement(debuggerLine, debuggerToken, finish, new RuntimeNode(debuggerToken, finish, RuntimeNode.Request.DEBUGGER, Collections.<Expression>emptyList())));
}
/**
* PrimaryExpression :
* this
--- 1908,1918 ----
final int debuggerLine = line;
final long debuggerToken = token;
// DEBUGGER tested in caller.
next();
endOfLine();
! appendStatement(new DebuggerNode(debuggerLine, debuggerToken, finish));
}
/**
* PrimaryExpression :
* this
*** 2880,2890 ****
ParserContextBlockNode body = null;
final long bodyToken = token;
Block functionBody;
int bodyFinish = 0;
-
final boolean parseBody;
Object endParserState = null;
try {
// Create a new function block.
body = newBlock();
--- 2889,2898 ----