--- old/make/build.xml 2015-03-09 18:38:56.127663832 +0530 +++ new/make/build.xml 2015-03-09 18:38:56.043663420 +0530 @@ -314,6 +314,15 @@ permission java.security.AllPermission; }; +grant codeBase "file:/${basedir}/${nashorn.api.tests.jar}" { + permission java.util.PropertyPermission "parserapitest.*", "read"; + permission java.util.PropertyPermission "test.*", "read"; + permission java.util.PropertyPermission "test262.*", "read"; + permission java.io.FilePermission "${basedir}/test/-","read"; + permission java.io.FilePermission "$${user.dir}", "read"; + permission java.util.PropertyPermission "user.dir", "read"; +}; + grant codeBase "file:/${basedir}/${file.reference.testng.jar}" { permission java.security.AllPermission; }; @@ -395,6 +404,7 @@ + --- old/make/nbproject/project.xml 2015-03-09 18:38:56.503665698 +0530 +++ new/make/nbproject/project.xml 2015-03-09 18:38:56.419665278 +0530 @@ -155,7 +155,7 @@ - + ../test/src --- old/make/project.properties 2015-03-09 18:38:56.863667486 +0530 +++ new/make/project.properties 2015-03-09 18:38:56.775667050 +0530 @@ -134,6 +134,10 @@ test-sys-prop.test262.suite.dir=${test262.suite.dir} test-sys-prop.es5conform.testcases.dir=${test.external.dir}/ES5Conform/TestCases test-sys-prop.test.basic.dir=${test.basic.dir} +test-sys-prop.test.external.dir=${test.external.dir} +test-sys-prop.test.maptests.dir=${test.maptests.dir} +test-sys-prop.test.sandbox.dir=${test.sandbox.dir} +test-sys-prop.test.trusted.dir=${test.trusted.dir} test-sys-prop-no-security.test.dir=${test.dir} test-sys-prop-no-security.test.js.roots=${test.nosecurity.dir} @@ -147,9 +151,11 @@ # turn on/off scripting mode for parser tests test-sys-prop.parsertest.scripting=true +test-sys-prop.parserapitest.verbose=false # turn on/off test262 scripts for parser tests test-sys-prop.parsertest.test262=false +test-sys-prop.parserapitest.test262=false # Control the verbosity of the CompilerTest test-sys-prop.compilertest.verbose=false --- old/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/Lower.java 2015-03-09 18:38:57.243669366 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/Lower.java 2015-03-09 18:38:57.155668930 +0530 @@ -45,6 +45,7 @@ import jdk.nashorn.internal.ir.CallNode; import jdk.nashorn.internal.ir.CaseNode; import jdk.nashorn.internal.ir.CatchNode; +import jdk.nashorn.internal.ir.DebuggerNode; import jdk.nashorn.internal.ir.ContinueNode; import jdk.nashorn.internal.ir.EmptyNode; import jdk.nashorn.internal.ir.Expression; @@ -184,6 +185,15 @@ return false; } + @Override + public boolean enterDebuggerNode(final DebuggerNode debuggerNode) { + final int line = debuggerNode.getLineNumber(); + final long token = debuggerNode.getToken(); + final int finish = debuggerNode.getFinish(); + addStatement(new ExpressionStatement(line, token, finish, new RuntimeNode(token, finish, RuntimeNode.Request.DEBUGGER, new ArrayList()))); + return false; + } + @Override public boolean enterJumpToInlinedFinally(final JumpToInlinedFinally jumpToInlinedFinally) { addStatement(jumpToInlinedFinally); --- old/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/ir/Block.java 2015-03-09 18:38:57.603671156 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/ir/Block.java 2015-03-09 18:38:57.515670716 +0530 @@ -56,7 +56,7 @@ /** Break label. */ private final Label breakLabel; - /** Does the block/function need a new scope? */ + /** Does the block/function need a new scope? Is this synthetic? */ protected final int flags; /** @@ -80,6 +80,11 @@ public static final int IS_GLOBAL_SCOPE = 1 << 3; /** + * Is this block a synthetic one introduced by Parser? + */ + public static final int IS_SYNTHETIC = 1 << 4; + + /** * Constructor * * @param token The first token of the block @@ -108,7 +113,7 @@ * @param statements All statements in the block */ public Block(final long token, final int finish, final Statement...statements){ - this(token, finish, 0, statements); + this(token, finish, IS_SYNTHETIC, statements); } /** @@ -119,7 +124,7 @@ * @param statements All statements in the block */ public Block(final long token, final int finish, final List statements){ - this(token, finish, 0, statements); + this(token, finish, IS_SYNTHETIC, statements); } /** @@ -366,6 +371,15 @@ return (flags & NEEDS_SCOPE) == NEEDS_SCOPE; } + /** + * Check whether this block is synthetic or not. + * + * @return true if this is a synthetic block + */ + public boolean isSynthetic() { + return (flags & IS_SYNTHETIC) == IS_SYNTHETIC; + } + @Override public Block setFlags(final LexicalContext lc, final int flags) { if (this.flags == flags) { --- old/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/ir/BlockStatement.java 2015-03-09 18:38:57.959672918 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/ir/BlockStatement.java 2015-03-09 18:38:57.871672484 +0530 @@ -90,6 +90,15 @@ return block.isTerminal(); } + /** + * Tells if this is a synthetic block statement or not. + * + * @return true if this is a synthetic statement + */ + public boolean isSynthetic() { + return block.isSynthetic(); + } + @Override public Node accept(final NodeVisitor visitor) { if (visitor.enterBlockStatement(this)) { --- old/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/ir/LiteralNode.java 2015-03-09 18:38:58.319674706 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/ir/LiteralNode.java 2015-03-09 18:38:58.231674270 +0530 @@ -181,6 +181,28 @@ } /** + * Test if the value is an array + * + * @return True if value is an array + */ + public boolean isArray() { + return false; + } + + public List getElementExpressions() { + return null; + } + + /** + * Test if the value is a boolean. + * + * @return True if value is a boolean. + */ + public boolean isBoolean() { + return value instanceof Boolean; + } + + /** * Test if the value is a string. * * @return True if value is a string. @@ -607,6 +629,12 @@ /** Sub units with indexes ranges, in which to split up code generation, for large literals */ private final List units; + @Override + public boolean isArray() { + return true; + } + + /** * An ArrayUnit is a range in an ArrayLiteral. ArrayLiterals can * be split if they are too large, for bytecode generation reasons @@ -834,6 +862,7 @@ * null. * @return a list of array element expressions. */ + @Override public List getElementExpressions() { return Collections.unmodifiableList(Arrays.asList(value)); } --- old/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/ir/debug/JSONWriter.java 2015-03-09 18:38:58.703676610 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/ir/debug/JSONWriter.java 2015-03-09 18:38:58.619676190 +0530 @@ -38,6 +38,7 @@ 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.Expression; import jdk.nashorn.internal.ir.ExpressionStatement; @@ -289,6 +290,13 @@ } @Override + public boolean enterDebuggerNode(final DebuggerNode debuggerNode) { + enterDefault(debuggerNode); + type("DebuggerStatement"); + return leave(); + } + + @Override public boolean enterEmptyNode(final EmptyNode emptyNode) { enterDefault(emptyNode); @@ -302,7 +310,7 @@ // handle debugger statement final Node expression = expressionStatement.getExpression(); if (expression instanceof RuntimeNode) { - expression.accept(this); + assert false : "should not reach here: RuntimeNode"; return false; } @@ -319,14 +327,18 @@ @Override public boolean enterBlockStatement(final BlockStatement blockStatement) { + if (blockStatement.isSynthetic()) { + final Block blk = blockStatement.getBlock(); + blk.getStatements().get(0).accept(this); + return false; + } + enterDefault(blockStatement); type("BlockStatement"); comma(); - property("block"); - blockStatement.getBlock().accept(this); - + array("body", blockStatement.getBlock().getStatements()); return leave(); } @@ -677,19 +689,13 @@ @Override public boolean enterRuntimeNode(final RuntimeNode runtimeNode) { - final RuntimeNode.Request req = runtimeNode.getRequest(); - - if (req == RuntimeNode.Request.DEBUGGER) { - enterDefault(runtimeNode); - type("DebuggerStatement"); - return leave(); - } - + assert false : "should not reach here: RuntimeNode"; return false; } @Override public boolean enterSplitNode(final SplitNode splitNode) { + assert false : "should not reach here: SplitNode"; return false; } --- old/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/ir/visitor/NodeVisitor.java 2015-03-09 18:38:59.103678594 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/ir/visitor/NodeVisitor.java 2015-03-09 18:38:59.019678178 +0530 @@ -34,7 +34,9 @@ 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.ExpressionStatement; import jdk.nashorn.internal.ir.ForNode; import jdk.nashorn.internal.ir.FunctionNode; @@ -293,6 +295,27 @@ return leaveDefault(continueNode); } + + /** + * Callback for entering a DebuggerNode + * + * @param debuggerNode the node + * @return true if traversal should continue and node children be traversed, false otherwise + */ + public boolean enterDebuggerNode(final DebuggerNode debuggerNode) { + return enterDefault(debuggerNode); + } + + /** + * Callback for leaving a DebuggerNode + * + * @param debuggerNode the node + * @return processed node, which will replace the original one, or the original node + */ + public Node leaveDebuggerNode(final DebuggerNode debuggerNode) { + return leaveDefault(debuggerNode); + } + /** * Callback for entering an EmptyNode * @@ -314,6 +337,26 @@ } /** + * Callback for entering an ErrorNode + * + * @param errorNode the node + * @return true if traversal should continue and node children be traversed, false otherwise + */ + public boolean enterErrorNode(final ErrorNode errorNode) { + return enterDefault(errorNode); + } + + /** + * Callback for leaving an ErrorNode + * + * @param errorNode the node + * @return processed node, which will replace the original one, or the original node + */ + public Node leaveErrorNode(final ErrorNode errorNode) { + return leaveDefault(errorNode); + } + + /** * Callback for entering an ExpressionStatement * * @param expressionStatement the node --- old/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/parser/Parser.java 2015-03-09 18:38:59.507680598 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/parser/Parser.java 2015-03-09 18:38:59.419680158 +0530 @@ -77,7 +77,9 @@ 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; @@ -356,7 +358,8 @@ restoreBlock(body); body.setFlag(Block.NEEDS_SCOPE); - final Block functionBody = new Block(functionToken, source.getLength() - 1, body.getFlags(), body.getStatements()); + final Block functionBody = new Block(functionToken, source.getLength() - 1, + body.getFlags() | Block.IS_SYNTHETIC, body.getStatements()); lc.pop(function); expect(EOF); @@ -540,7 +543,8 @@ expect(RBRACE); } - return new Block(blockToken, finish, newBlock.getFlags(), newBlock.getStatements()); + final int flags = newBlock.getFlags() | (needsBraces? 0 : Block.IS_SYNTHETIC); + return new Block(blockToken, finish, flags, newBlock.getStatements()); } @@ -559,7 +563,7 @@ } finally { restoreBlock(newBlock); } - return new Block(newBlock.getToken(), finish, newBlock.getFlags(), newBlock.getStatements()); + return new Block(newBlock.getToken(), finish, newBlock.getFlags() | Block.IS_SYNTHETIC, newBlock.getStatements()); } /** @@ -712,7 +716,7 @@ restoreBlock(body); body.setFlag(Block.NEEDS_SCOPE); - final Block programBody = new Block(functionToken, functionLine, body.getFlags(), body.getStatements()); + final Block programBody = new Block(functionToken, functionLine, body.getFlags() | Block.IS_SYNTHETIC, body.getStatements()); lc.pop(script); script.setLastToken(token); @@ -826,8 +830,13 @@ } } } 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. @@ -1853,7 +1862,7 @@ appendStatement(catchNode); } finally { restoreBlock(catchBlock); - catchBlocks.add(new Block(catchBlock.getToken(), finish, catchBlock.getFlags(), catchBlock.getStatements())); + catchBlocks.add(new Block(catchBlock.getToken(), finish, catchBlock.getFlags() | Block.IS_SYNTHETIC, catchBlock.getStatements())); } // If unconditional catch then should to be the end. @@ -1883,7 +1892,7 @@ restoreBlock(outer); } - appendStatement(new BlockStatement(startLine, new Block(tryToken, finish, outer.getFlags(), outer.getStatements()))); + appendStatement(new BlockStatement(startLine, new Block(tryToken, finish, outer.getFlags() | Block.IS_SYNTHETIC, outer.getStatements()))); } /** @@ -1901,7 +1910,7 @@ // DEBUGGER tested in caller. next(); endOfLine(); - appendStatement(new ExpressionStatement(debuggerLine, debuggerToken, finish, new RuntimeNode(debuggerToken, finish, RuntimeNode.Request.DEBUGGER, Collections.emptyList()))); + appendStatement(new DebuggerNode(debuggerLine, debuggerToken, finish)); } /** @@ -2882,7 +2891,6 @@ Block functionBody; int bodyFinish = 0; - final boolean parseBody; Object endParserState = null; try { --- old/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Source.java 2015-03-09 18:38:59.955682818 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/Source.java 2015-03-09 18:38:59.867682378 +0530 @@ -484,6 +484,30 @@ * Constructor * * @param name source name + * @param path path from which source can be loaded + * + * @return source instance + * + * @throws IOException if source cannot be loaded + */ + public static Source sourceFor(final String name, final Path path) throws IOException { + File file = null; + try { + file = path.toFile(); + } catch (final UnsupportedOperationException uoe) { + } + + if (file != null) { + return sourceFor(name, file); + } else { + return sourceFor(name, Files.newBufferedReader(path)); + } + } + + /** + * Constructor + * + * @param name source name * @param file file from which source can be loaded * @param cs Charset used to convert bytes to chars * @@ -601,7 +625,7 @@ /** * Get explicit source URL. - * @return URL set vial sourceURL directive + * @return URL set via sourceURL directive */ public String getExplicitURL() { return explicitURL; --- old/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/options/Options.java 2015-03-09 18:39:00.343684736 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/options/Options.java 2015-03-09 18:39:00.259684322 +0530 @@ -429,6 +429,7 @@ while (!argList.isEmpty()) { final String arg = argList.remove(0); + Objects.requireNonNull(arg); // skip empty args if (arg.isEmpty()) { --- old/test/script/basic/parser/tryCatchStat.js.EXPECTED 2015-03-09 18:39:00.723686624 +0530 +++ new/test/script/basic/parser/tryCatchStat.js.EXPECTED 2015-03-09 18:39:00.635686190 +0530 @@ -2,32 +2,24 @@ "type": "Program", "body": [ { - "type": "BlockStatement", + "type": "TryStatement", "block": { "type": "BlockStatement", - "body": [ - { - "type": "TryStatement", - "block": { - "type": "BlockStatement", - "body": [] - }, - "guardedHandlers": [], - "handler": { - "type": "CatchClause", - "param": { - "type": "Identifier", - "name": "e" - }, - "body": { - "type": "BlockStatement", - "body": [] - } - }, - "finalizer": null - } - ] - } + "body": [] + }, + "guardedHandlers": [], + "handler": { + "type": "CatchClause", + "param": { + "type": "Identifier", + "name": "e" + }, + "body": { + "type": "BlockStatement", + "body": [] + } + }, + "finalizer": null } ] } @@ -35,34 +27,26 @@ "type": "Program", "body": [ { - "type": "BlockStatement", + "type": "TryStatement", "block": { "type": "BlockStatement", - "body": [ - { - "type": "TryStatement", - "block": { - "type": "BlockStatement", - "body": [] - }, - "guardedHandlers": [], - "handler": { - "type": "CatchClause", - "param": { - "type": "Identifier", - "name": "e" - }, - "body": { - "type": "BlockStatement", - "body": [] - } - }, - "finalizer": { - "type": "BlockStatement", - "body": [] - } - } - ] + "body": [] + }, + "guardedHandlers": [], + "handler": { + "type": "CatchClause", + "param": { + "type": "Identifier", + "name": "e" + }, + "body": { + "type": "BlockStatement", + "body": [] + } + }, + "finalizer": { + "type": "BlockStatement", + "body": [] } } ] @@ -71,24 +55,16 @@ "type": "Program", "body": [ { - "type": "BlockStatement", + "type": "TryStatement", "block": { "type": "BlockStatement", - "body": [ - { - "type": "TryStatement", - "block": { - "type": "BlockStatement", - "body": [] - }, - "guardedHandlers": [], - "handler": null, - "finalizer": { - "type": "BlockStatement", - "body": [] - } - } - ] + "body": [] + }, + "guardedHandlers": [], + "handler": null, + "finalizer": { + "type": "BlockStatement", + "body": [] } } ] @@ -97,44 +73,36 @@ "type": "Program", "body": [ { - "type": "BlockStatement", + "type": "TryStatement", "block": { "type": "BlockStatement", - "body": [ - { - "type": "TryStatement", - "block": { - "type": "BlockStatement", - "body": [] - }, - "guardedHandlers": [], - "handler": { - "type": "CatchClause", - "param": { - "type": "Identifier", - "name": "e" - }, - "body": { - "type": "BlockStatement", - "body": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "CallExpression", - "callee": { - "type": "Identifier", - "name": "handle" - }, - "arguments": [] - } - } - ] + "body": [] + }, + "guardedHandlers": [], + "handler": { + "type": "CatchClause", + "param": { + "type": "Identifier", + "name": "e" + }, + "body": { + "type": "BlockStatement", + "body": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "handle" + }, + "arguments": [] } - }, - "finalizer": null - } - ] - } + } + ] + } + }, + "finalizer": null } ] } @@ -142,67 +110,59 @@ "type": "Program", "body": [ { - "type": "BlockStatement", + "type": "TryStatement", "block": { "type": "BlockStatement", "body": [ { - "type": "TryStatement", - "block": { - "type": "BlockStatement", - "body": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "CallExpression", - "callee": { - "type": "Identifier", - "name": "that" - }, - "arguments": [] - } - } - ] - }, - "guardedHandlers": [], - "handler": { - "type": "CatchClause", - "param": { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { "type": "Identifier", - "name": "e" + "name": "that" }, - "body": { - "type": "BlockStatement", - "body": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "CallExpression", - "callee": { - "type": "Identifier", - "name": "handle" - }, - "arguments": [] - } - } - ] + "arguments": [] + } + } + ] + }, + "guardedHandlers": [], + "handler": { + "type": "CatchClause", + "param": { + "type": "Identifier", + "name": "e" + }, + "body": { + "type": "BlockStatement", + "body": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "handle" + }, + "arguments": [] } - }, - "finalizer": { - "type": "BlockStatement", - "body": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "CallExpression", - "callee": { - "type": "Identifier", - "name": "clean" - }, - "arguments": [] - } - } - ] + } + ] + } + }, + "finalizer": { + "type": "BlockStatement", + "body": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "clean" + }, + "arguments": [] } } ] @@ -214,92 +174,84 @@ "type": "Program", "body": [ { - "type": "BlockStatement", + "type": "TryStatement", "block": { "type": "BlockStatement", "body": [ { - "type": "TryStatement", - "block": { - "type": "BlockStatement", - "body": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "CallExpression", - "callee": { - "type": "Identifier", - "name": "that" - }, - "arguments": [] - } - } - ] - }, - "guardedHandlers": [ + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "that" + }, + "arguments": [] + } + } + ] + }, + "guardedHandlers": [ + { + "type": "CatchClause", + "param": { + "type": "Identifier", + "name": "e" + }, + "guard": { + "type": "BinaryExpression", + "operator": "instanceof", + "left": { + "type": "Identifier", + "name": "e" + }, + "right": { + "type": "Identifier", + "name": "TypeError" + } + }, + "body": { + "type": "BlockStatement", + "body": [ { - "type": "CatchClause", - "param": { - "type": "Identifier", - "name": "e" - }, - "guard": { - "type": "BinaryExpression", - "operator": "instanceof", - "left": { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { "type": "Identifier", - "name": "e" + "name": "handle" }, - "right": { - "type": "Identifier", - "name": "TypeError" - } - }, - "body": { - "type": "BlockStatement", - "body": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "CallExpression", - "callee": { - "type": "Identifier", - "name": "handle" - }, - "arguments": [] - } - } - ] + "arguments": [] } } - ], - "handler": { - "type": "CatchClause", - "param": { - "type": "Identifier", - "name": "e" - }, - "body": { - "type": "BlockStatement", - "body": [ - { - "type": "ExpressionStatement", - "expression": { - "type": "CallExpression", - "callee": { - "type": "Identifier", - "name": "rest" - }, - "arguments": [] - } - } - ] - } - }, - "finalizer": null + ] } - ] - } + } + ], + "handler": { + "type": "CatchClause", + "param": { + "type": "Identifier", + "name": "e" + }, + "body": { + "type": "BlockStatement", + "body": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "rest" + }, + "arguments": [] + } + } + ] + } + }, + "finalizer": null } ] } --- old/test/script/basic/parser/util.js 2015-03-09 18:39:01.119688584 +0530 +++ new/test/script/basic/parser/util.js 2015-03-09 18:39:01.023688108 +0530 @@ -25,7 +25,7 @@ * @subtest */ -// utilitity for parser tests +// utility for parser tests load("nashorn:parser.js"); function printParse(code) { --- old/test/src/jdk/nashorn/internal/codegen/CompilerTest.java 2015-03-09 18:39:01.495690456 +0530 +++ new/test/src/jdk/nashorn/internal/codegen/CompilerTest.java 2015-03-09 18:39:01.403689996 +0530 @@ -66,7 +66,6 @@ @BeforeClass public void setupTest() { final Options options = new Options("nashorn"); - options.set("anon.functions", true); options.set("compile.only", true); options.set("print.ast", true); options.set("print.parse", true); --- old/test/src/jdk/nashorn/internal/parser/ParserTest.java 2015-03-09 18:39:01.887692396 +0530 +++ new/test/src/jdk/nashorn/internal/parser/ParserTest.java 2015-03-09 18:39:01.783691884 +0530 @@ -62,7 +62,6 @@ @BeforeClass public void setupTest() { final Options options = new Options("nashorn"); - options.set("anon.functions", true); options.set("parse.only", true); options.set("scripting", true); options.set("const.as.var", true); --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/samples/evalcheck.js 2015-03-09 18:39:02.143693664 +0530 @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * - Neither the name of Oracle nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +// Simple demo of Nashorn Parser API + +var Parser = Java.type("jdk.nashorn.api.tree.Parser"); +var SimpleTreeVisitor = Java.type("jdk.nashorn.api.tree.SimpleTreeVisitorES5_1"); +var IdentifierTree = Java.type("jdk.nashorn.api.tree.IdentifierTree"); + +var parser = Parser.create(); +var ast = parser.parse("t", "eval('hello');\n eval(2 + 3)", print); +// locate 'eval' calls in the script +ast.accept(visitor = new (Java.extend(SimpleTreeVisitor)) { + lineMap: null, + visitCompilationUnit: function(node, extra) { + this.lineMap = node.lineMap; + Java.super(visitor).visitCompilationUnit(node, extra); + }, + + visitFunctionCall: function(node, extra) { + var func = node.functionSelect; + if (func instanceof IdentifierTree && func.name == "eval") { + var pos = node.startPosition; + var line = this.lineMap.getLineNumber(pos); + var column = this.lineMap.getColumnNumber(pos); + print("eval call found @ " + line + ":" + column); + } + } +}, null); --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/samples/withcheck.js 2015-03-09 18:39:02.427695070 +0530 @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * - Neither the name of Oracle nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +// Simple demo of Nashorn Parser API + +var Parser = Java.type("jdk.nashorn.api.tree.Parser"); +var parser = Parser.create("-strict"); +// you'll get diagnostic message for 'with' +parser.parse("t", "with({}){}", print); --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/ArrayAccessTree.java 2015-03-09 18:39:02.703696442 +0530 @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +/** + * A tree node for an array access expression. + * + * For example: + *
+ *   expression [ index ]
+ * 
+ * + * @since 1.9 + */ +@jdk.Exported +public interface ArrayAccessTree extends ExpressionTree { + /** + * Returns the array that is accessed. + * + * @return the array that is accessed + */ + ExpressionTree getExpression(); + + /** + * Returns the index of the array element accessed. + * + * @return the index expression + */ + ExpressionTree getIndex(); +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/ArrayAccessTreeImpl.java 2015-03-09 18:39:02.987697850 +0530 @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +import jdk.nashorn.internal.ir.Expression; + +final class ArrayAccessTreeImpl extends ExpressionTreeImpl implements ArrayAccessTree { + + private final ExpressionTree base, index; + + ArrayAccessTreeImpl(final Expression node, final ExpressionTree base, final ExpressionTree index) { + super(node); + this.base = base; + this.index = index; + } + + @Override + public Tree.Kind getKind() { + return Tree.Kind.ARRAY_ACCESS; + } + + @Override + public ExpressionTree getExpression() { + return base; + } + + @Override + public ExpressionTree getIndex() { + return index; + } + + @Override + public R accept(TreeVisitor visitor, D data) { + return visitor.visitArrayAccess(this, data); + } +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/ArrayLiteralTree.java 2015-03-09 18:39:03.267699242 +0530 @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +import java.util.List; + +/** + * Represents ECMAScript array literal expression. + * + * @since 1.9 + */ +@jdk.Exported +public interface ArrayLiteralTree extends ExpressionTree { + /** + * Returns the list of Array element expressions. + * + * @return array element expressions + */ + public List getElements(); +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/ArrayLiteralTreeImpl.java 2015-03-09 18:39:03.547700624 +0530 @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +import java.util.List; +import jdk.nashorn.internal.ir.LiteralNode; + +final class ArrayLiteralTreeImpl extends ExpressionTreeImpl + implements ArrayLiteralTree { + private final List elements; + ArrayLiteralTreeImpl(final LiteralNode node, final List elements) { + super(node); + this.elements = elements; + } + + @Override + public Tree.Kind getKind() { + return Tree.Kind.ARRAY_LITERAL; + } + + @Override + public List getElements() { + return elements; + } + + @Override + public R accept(TreeVisitor visitor, D data) { + return visitor.visitArrayLiteral(this, data); + } +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/AssignmentTree.java 2015-03-09 18:39:03.835702052 +0530 @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +/** + * A tree node for an assignment expression. + * + * For example: + *
+ *   variable = expression
+ * 
+ * + * @since 1.9 + */ +@jdk.Exported +public interface AssignmentTree extends ExpressionTree { + /** + * Returns the left hand side (LHS) of this assignment. + * + * @return left hand side (LHS) expression + */ + ExpressionTree getVariable(); + + /** + * Returns the right hand side (RHS) of this assignment. + * + * @return right hand side (RHS) expression + */ + ExpressionTree getExpression(); +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/AssignmentTreeImpl.java 2015-03-09 18:39:04.115703444 +0530 @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +import jdk.nashorn.internal.ir.BinaryNode; + +final class AssignmentTreeImpl extends ExpressionTreeImpl implements AssignmentTree { + private final Tree.Kind kind; + private final ExpressionTree var, expr; + + AssignmentTreeImpl(final BinaryNode node, final ExpressionTree left, final ExpressionTree right) { + super(node); + assert node.isAssignment() : "assignment node expected"; + this.var = left; + this.expr = right; + this.kind = getOperator(node.tokenType()); + } + + @Override + public Tree.Kind getKind() { + return kind; + } + + @Override + public ExpressionTree getVariable() { + return var; + } + + @Override + public ExpressionTree getExpression() { + return expr; + } + + @Override + public R accept(TreeVisitor visitor, D data) { + return visitor.visitAssignment(this, data); + } +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/BinaryTree.java 2015-03-09 18:39:04.403704876 +0530 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +/** + * A tree node for a binary expression. + * Use {@link #getKind getKind} to determine the kind of operator. + * + * For example: + *
+ *   leftOperand operator rightOperand
+ * 
+ * + * @since 1.9 + */ +@jdk.Exported +public interface BinaryTree extends ExpressionTree { + /** + * Returns left hand side (LHS) of this binary expression. + * + * @return left hand side (LHS) of this binary expression + */ + ExpressionTree getLeftOperand(); + + /** + * Returns right hand side (RHS) of this binary expression. + * + * @return right hand side (RHS) of this binary expression + */ + ExpressionTree getRightOperand(); +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/BinaryTreeImpl.java 2015-03-09 18:39:04.723706462 +0530 @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +import jdk.nashorn.internal.ir.BinaryNode; + +class BinaryTreeImpl extends ExpressionTreeImpl implements BinaryTree { + private final Tree.Kind kind; + private final ExpressionTree left, right; + + BinaryTreeImpl(final BinaryNode node, final ExpressionTree left, final ExpressionTree right) { + super(node); + assert !node.isAssignment() : "assignment node"; + this.left = left; + this.right = right; + this.kind = getOperator(node.tokenType()); + } + + @Override + public Tree.Kind getKind() { + return kind; + } + + @Override + public ExpressionTree getLeftOperand() { + return left; + } + + @Override + public ExpressionTree getRightOperand() { + return right; + } + + @Override + public R accept(TreeVisitor visitor, D data) { + return visitor.visitBinary(this, data); + } +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/BlockTree.java 2015-03-09 18:39:05.079708224 +0530 @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +import java.util.List; + +/** + * A tree node for a statement block. + * + * For example: + *
+ *   { }
+ *
+ *   { statements }
+ * 
+ * + * @since 1.9 + */ +@jdk.Exported +public interface BlockTree extends StatementTree { + /** + * Returns the list of statements in this block. + * + * @return the list of statements in this block + */ + List getStatements(); +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/BlockTreeImpl.java 2015-03-09 18:39:05.363709632 +0530 @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +import java.util.List; +import jdk.nashorn.internal.ir.Block; +import jdk.nashorn.internal.ir.BlockStatement; + +final class BlockTreeImpl extends StatementTreeImpl implements BlockTree { + private final List statements; + + BlockTreeImpl(final BlockStatement node, final List statements) { + super(node); + this.statements = statements; + } + + BlockTreeImpl(final Block node, final List statements) { + super(node); + this.statements = statements; + } + + @Override + public Kind getKind() { + return Kind.BLOCK; + } + + @Override + public List getStatements() { + return statements; + } + + @Override + public R accept(TreeVisitor visitor, D data) { + return visitor.visitBlock(this, data); + } +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/BreakTree.java 2015-03-09 18:39:05.647711044 +0530 @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +/** + * A tree node for a 'break' statement. + * + * For example: + *
+ *   break;
+ *
+ *   break label ;
+ * 
+ * + * @since 1.9 + */ +@jdk.Exported +public interface BreakTree extends GotoTree { + /** + * Label associated with this break statement. This is null + * if there is no label associated with this break statement. + * + * @return label associated with this break statement. + */ + String getLabel(); +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/BreakTreeImpl.java 2015-03-09 18:39:05.935712472 +0530 @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +import jdk.nashorn.internal.ir.BreakNode; +import jdk.nashorn.internal.ir.IdentNode; + +final class BreakTreeImpl extends StatementTreeImpl implements BreakTree { + private final String label; + + BreakTreeImpl(final BreakNode node) { + super(node); + this.label = node.getLabelName(); + } + + @Override + public Tree.Kind getKind() { + return Tree.Kind.BREAK; + } + + @Override + public String getLabel() { + return label; + } + + @Override + public R accept(TreeVisitor visitor, D data) { + return visitor.visitBreak(this, data); + } +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/CaseTree.java 2015-03-09 18:39:06.215713854 +0530 @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +import java.util.List; + +/** + * A tree node for a 'case' in a 'switch' statement. + * + * For example: + *
+ *   case expression :
+ *       statements
+ *
+ *   default :
+ *       statements
+ * 
+ * + * @since 1.9 + */ +@jdk.Exported +public interface CaseTree extends Tree { + /** + * Case expression of this 'case' statement. + * + * @return null if and only if this Case is {@code default:} + */ + ExpressionTree getExpression(); + + /** + * Return the list of statements for this 'case'. + * + * @return list of statements for this 'case' + */ + List getStatements(); +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/CaseTreeImpl.java 2015-03-09 18:39:06.523715384 +0530 @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +import java.util.List; +import jdk.nashorn.internal.ir.CaseNode; + +final class CaseTreeImpl extends TreeImpl implements CaseTree { + private final ExpressionTree expression; + private final List statements; + + public CaseTreeImpl(final CaseNode node, + final ExpressionTree expression, + final List statements) { + super(node); + this.expression = expression; + this.statements = statements; + } + + @Override + public Kind getKind() { + return Kind.CASE; + } + + @Override + public ExpressionTree getExpression() { + return expression; + } + + @Override + public List getStatements() { + return statements; + } + + @Override + public R accept(TreeVisitor visitor, D data) { + return visitor.visitCase(this, data); + } +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/CatchTree.java 2015-03-09 18:39:06.803716772 +0530 @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +/** + * A tree node for a 'catch' block in a 'try' statement. + * + * For example: + *
+ *   catch ( parameter )
+ *       block
+ * 
+ * + * @since 1.9 + */ +@jdk.Exported +public interface CatchTree extends Tree { + /** + * Returns the catch parameter identifier of the exception caught. + * + * @return the catch parameter identifier + */ + IdentifierTree getParameter(); + + /** + * Returns the code block of this catch block. + * + * @return the code block + */ + BlockTree getBlock(); + + /** + * Returns the optional catch condition expression. This is null + * if this is an unconditional catch statement. + * + * @return the optional catch condition expression. + */ + ExpressionTree getCondition(); +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/CatchTreeImpl.java 2015-03-09 18:39:07.083718164 +0530 @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +import jdk.nashorn.internal.ir.CatchNode; + +final class CatchTreeImpl extends TreeImpl implements CatchTree { + private final IdentifierTree param; + private final BlockTree block; + private final ExpressionTree condition; + + CatchTreeImpl(final CatchNode node, + final IdentifierTree param, + final BlockTree block, + final ExpressionTree condition) { + super(node); + this.param = param; + this.block = block; + this.condition = condition; + } + + @Override + public Kind getKind() { + return Kind.CATCH; + } + + @Override + public IdentifierTree getParameter() { + return param; + } + + @Override + public BlockTree getBlock() { + return block; + } + + @Override + public ExpressionTree getCondition() { + return condition; + } + + @Override + public R accept(TreeVisitor visitor, D data) { + return visitor.visitCatch(this, data); + } +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/CompilationUnitTree.java 2015-03-09 18:39:07.367719570 +0530 @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +import java.util.List; + +/** + * Represents the abstract syntax tree for compilation units (source + * files) + * + * @since 1.9 + */ +@jdk.Exported +public interface CompilationUnitTree extends Tree { + /** + * Return the list of source elements in this compilation unit. + * + * @return the list of source elements in this compilation unit + */ + List getSourceElements(); + + /** + * Return the source name of this script compilation unit. + * + * @return the source name of this script compilation unit + */ + String getSourceName(); + + /** + * Returns if this is a ECMAScript "strict" compilation unit or not. + * + * @return true if this compilation unit is declared "strict" + */ + boolean isStrict(); + + /** + * Returns the line map for this compilation unit, if available. + * Returns null if the line map is not available. + * + * @return the line map for this compilation unit + */ + LineMap getLineMap(); +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/CompilationUnitTreeImpl.java 2015-03-09 18:39:07.651720978 +0530 @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +import java.util.List; +import jdk.nashorn.internal.ir.FunctionNode; + +final class CompilationUnitTreeImpl extends TreeImpl + implements CompilationUnitTree { + private final FunctionNode funcNode; + private final List elements; + + CompilationUnitTreeImpl(final FunctionNode node, + final List elements) { + super(node); + this.funcNode = node; + assert funcNode.getKind() == FunctionNode.Kind.SCRIPT : "script function expected"; + this.elements = elements; + } + + @Override + public Tree.Kind getKind() { + return Tree.Kind.COMPILATION_UNIT; + } + + @Override + public List getSourceElements() { + return elements; + } + + @Override + public String getSourceName() { + return funcNode.getSourceName(); + } + + @Override + public boolean isStrict() { + return funcNode.isStrict(); + } + + @Override + public LineMap getLineMap() { + return new LineMapImpl(funcNode.getSource()); + } + + @Override + public R accept(TreeVisitor visitor, D data) { + return visitor.visitCompilationUnit(this, data); + } +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/CompoundAssignmentTree.java 2015-03-09 18:39:07.943722430 +0530 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +/** + * A tree node for compound assignment operator. + * Use {@link #getKind getKind} to determine the kind of operator. + * + * For example: + *
+ *   variable operator expression
+ * 
+ * + * @since 1.9 + */ +@jdk.Exported +public interface CompoundAssignmentTree extends ExpressionTree { + /** + * Returns the left hand side (LHS) of this assignment. + * + * @return left hand side (LHS) expression + */ + ExpressionTree getVariable(); + + /** + * Returns the right hand side (RHS) of this assignment. + * + * @return right hand side (RHS) expression + */ + ExpressionTree getExpression(); +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/CompoundAssignmentTreeImpl.java 2015-03-09 18:39:08.231723858 +0530 @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +import jdk.nashorn.internal.ir.BinaryNode; + +final class CompoundAssignmentTreeImpl extends ExpressionTreeImpl implements CompoundAssignmentTree { + + private final ExpressionTree var, expr; + private final Kind kind; + + CompoundAssignmentTreeImpl(final BinaryNode node, final ExpressionTree left, final ExpressionTree right) { + super(node); + assert node.isAssignment() : "not an assignment node"; + this.var = left; + this.expr = right; + this.kind = getOperator(node.tokenType()); + assert kind != Tree.Kind.ASSIGNMENT : "compound assignment expected"; + } + + @Override + public Kind getKind() { + return kind; + } + + @Override + public ExpressionTree getVariable() { + return var; + } + + @Override + public ExpressionTree getExpression() { + return expr; + } + + @Override + public R accept(TreeVisitor visitor, D data) { + return visitor.visitCompoundAssignment(this, data); + } +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/ConditionalExpressionTree.java 2015-03-09 18:39:08.515725266 +0530 @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +/** + * A tree node for the conditional operator ? :. + * + * For example: + *
+ *   condition ? trueExpression : falseExpression
+ * 
+ * + * @since 1.9 + */ +@jdk.Exported +public interface ConditionalExpressionTree extends ExpressionTree { + /** + * Returns the condition expression of this ternary expression. + * + * @return the condition expression + */ + ExpressionTree getCondition(); + + /** + * Returns the true part of this ternary expression. + * + * @return the 'true' part expression + */ + ExpressionTree getTrueExpression(); + + /** + * Returns the false part of this ternary expression. + * + * @return the 'false' part expression + */ + ExpressionTree getFalseExpression(); +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/ConditionalExpressionTreeImpl.java 2015-03-09 18:39:08.803726690 +0530 @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +import jdk.nashorn.internal.ir.TernaryNode; + +final class ConditionalExpressionTreeImpl extends ExpressionTreeImpl implements ConditionalExpressionTree { + private final ExpressionTree condExpr, trueExpr, falseExpr; + + ConditionalExpressionTreeImpl(final TernaryNode node, + final ExpressionTree condExpr, final ExpressionTree trueExpr, + final ExpressionTree falseExpr) { + super(node); + this.condExpr = condExpr; + this.trueExpr = trueExpr; + this.falseExpr = falseExpr; + + } + + @Override + public Kind getKind() { + return Kind.CONDITIONAL_EXPRESSION; + } + + @Override + public ExpressionTree getCondition() { + return condExpr; + } + + @Override + public ExpressionTree getTrueExpression() { + return trueExpr; + } + + @Override + public ExpressionTree getFalseExpression() { + return falseExpr; + } + + @Override + public R accept(TreeVisitor visitor, D data) { + return visitor.visitConditionalExpression(this, data); + } +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/ConditionalLoopTree.java 2015-03-09 18:39:09.099728158 +0530 @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +/** + * A mixin for conditional "loop" statements. + * + * @since 1.9 + */ +@jdk.Exported +public interface ConditionalLoopTree extends LoopTree { + /** + * Returns the condition expression of this 'loop' statement. + * + * @return the condition expression + */ + ExpressionTree getCondition(); +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/ContinueTree.java 2015-03-09 18:39:09.399729645 +0530 @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +/** + * A tree node for a 'continue' statement. + * + * For example: + *
+ *   continue;
+ *   continue label ;
+ * 
+ * + * @since 1.9 + */ +@jdk.Exported +public interface ContinueTree extends GotoTree { + /** + * Label associated with this continue statement. This is null + * if there is no label associated with this continue statement. + * + * @return label associated with this continue statement. + */ + String getLabel(); +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/ContinueTreeImpl.java 2015-03-09 18:39:09.699731133 +0530 @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +import jdk.nashorn.internal.ir.ContinueNode; +import jdk.nashorn.internal.ir.IdentNode; + +final class ContinueTreeImpl extends StatementTreeImpl implements ContinueTree { + private final String label; + + ContinueTreeImpl(final ContinueNode node) { + super(node); + this.label = node.getLabelName(); + } + + @Override + public Tree.Kind getKind() { + return Tree.Kind.CONTINUE; + } + + @Override + public String getLabel() { + return label; + } + + @Override + public R accept(TreeVisitor visitor, D data) { + return visitor.visitContinue(this, data); + } +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/DebuggerTree.java 2015-03-09 18:39:09.991732585 +0530 @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +/** + * A tree node for a 'debugger' statement. + * + * For example: + *
+ *     debugger;
+ * 
+ * + * @since 1.9 + */ +@jdk.Exported +public interface DebuggerTree extends StatementTree { +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/DebuggerTreeImpl.java 2015-03-09 18:39:10.311734168 +0530 @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +import jdk.nashorn.internal.ir.DebuggerNode; + +final class DebuggerTreeImpl extends StatementTreeImpl implements DebuggerTree { + DebuggerTreeImpl(final DebuggerNode node) { + super(node); + } + + @Override + public Tree.Kind getKind() { + return Tree.Kind.DEBUGGER; + } + + @Override + public R accept(TreeVisitor visitor, D data) { + return visitor.visitDebugger(this, data); + } +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/Diagnostic.java 2015-03-09 18:39:10.611735655 +0530 @@ -0,0 +1,151 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +/** + * Interface for diagnostics from tools. A diagnostic usually reports + * a problem at a specific position in a source file. However, not + * all diagnostics are associated with a position or a file. + * + *

A position is a zero-based character offset from the beginning of + * a file. Negative values (except {@link #NOPOS}) are not valid + * positions. + * + *

Line and column numbers begin at 1. Negative values (except + * {@link #NOPOS}) and 0 are not valid line or column numbers. + * + *

Line terminator is as defined in ECMAScript specification which is one + * of { \u000A, \u000B, \u2028, \u2029 }. + * + * @since 1.9 + */ +@jdk.Exported +public interface Diagnostic { + + /** + * Kinds of diagnostics, for example, error or warning. + * + * The kind of a diagnostic can be used to determine how the + * diagnostic should be presented to the user. For example, + * errors might be colored red or prefixed with the word "Error", + * while warnings might be colored yellow or prefixed with the + * word "Warning". There is no requirement that the Kind + * should imply any inherent semantic meaning to the message + * of the diagnostic: for example, a tool might provide an + * option to report all warnings as errors. + */ + enum Kind { + /** + * Problem which prevents the tool's normal completion. + */ + ERROR, + /** + * Problem which does not usually prevent the tool from + * completing normally. + */ + WARNING, + /** + * Problem similar to a warning, but is mandated by the tool's + * specification. For example, the Java™ Language + * Specification mandates warnings on certain + * unchecked operations and the use of deprecated methods. + */ + MANDATORY_WARNING, + /** + * Informative message from the tool. + */ + NOTE, + /** + * Diagnostic which does not fit within the other kinds. + */ + OTHER, + } + + /** + * Used to signal that no position is available. + */ + public final static long NOPOS = -1; + + /** + * Gets the kind of this diagnostic, for example, error or + * warning. + * @return the kind of this diagnostic + */ + Kind getKind(); + + /** + * Gets a character offset from the beginning of the source object + * associated with this diagnostic that indicates the location of + * the problem. In addition, the following must be true: + * + *

{@code getStartPostion() <= getPosition()} + *

{@code getPosition() <= getEndPosition()} + * + * @return character offset from beginning of source; {@link + * #NOPOS} if no location is suitable + */ + long getPosition(); + + /** + * Gets the source file name. + * + * @return the file name or null if not available + */ + String getFileName(); + + /** + * Gets the line number of the character offset returned by + * {@linkplain #getPosition()}. + * + * @return a line number or {@link #NOPOS} if and only if {@link + * #getPosition()} returns {@link #NOPOS} + */ + long getLineNumber(); + + /** + * Gets the column number of the character offset returned by + * {@linkplain #getPosition()}. + * + * @return a column number or {@link #NOPOS} if and only if {@link + * #getPosition()} returns {@link #NOPOS} + */ + long getColumnNumber(); + + /** + * Gets a diagnostic code indicating the type of diagnostic. The + * code is implementation-dependent and might be {@code null}. + * + * @return a diagnostic code + */ + String getCode(); + + /** + * Gets a message for this diagnostic. + * + * @return a message + */ + String getMessage(); +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/DiagnosticImpl.java 2015-03-09 18:39:10.891737048 +0530 @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +import jdk.nashorn.internal.parser.Token; +import jdk.nashorn.internal.runtime.ParserException; +import jdk.nashorn.internal.runtime.Source; + +final class DiagnosticImpl implements Diagnostic { + private final ParserException exp; + private final Kind kind; + + DiagnosticImpl(final ParserException exp, final Kind kind) { + this.exp = exp; + this.kind = kind; + } + + @Override + public Kind getKind() { + return kind; + } + + @Override + public long getPosition() { + return exp.getPosition(); + } + + @Override + public String getFileName() { + return exp.getFileName(); + } + + @Override + public long getLineNumber() { + return exp.getLineNumber(); + } + + @Override + public long getColumnNumber() { + return exp.getColumnNumber(); + } + + @Override + public String getCode() { + final long token = exp.getToken(); + return (token < 0)? null : Token.toString(null, token, true); + } + + @Override + public String getMessage() { + return exp.getMessage(); + } + + @Override + public String toString() { + return getMessage(); + } +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/DiagnosticListener.java 2015-03-09 18:39:11.183738495 +0530 @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +/** + * Interface for receiving diagnostics from Nashorn parser. + * + * @since 1.9 + */ +@jdk.Exported +@FunctionalInterface +public interface DiagnosticListener { + /** + * Invoked whenever a parsing problem is found. + * + * @param diagnostic additional information errors, warnings detected during parsing. + */ + void report(Diagnostic diagnostic); +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/DoWhileLoopTree.java 2015-03-09 18:39:11.467739902 +0530 @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +/** + * A tree node for a 'do' statement. + * + * For example: + *

+ *   do
+ *       statement
+ *   while ( expression );
+ * 
+ * + * @since 1.9 + */ +@jdk.Exported +public interface DoWhileLoopTree extends ConditionalLoopTree { + /** + * Returns the condition expression of this do-while statement. + * + * @return the condition expression + */ + ExpressionTree getCondition(); + + /** + * The statement contained within this do-while statement. + * + * @return the statement + */ + StatementTree getStatement(); +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/DoWhileLoopTreeImpl.java 2015-03-09 18:39:11.755741328 +0530 @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +import jdk.nashorn.internal.ir.WhileNode; + +final class DoWhileLoopTreeImpl extends StatementTreeImpl implements DoWhileLoopTree { + private final ExpressionTree cond; + private final StatementTree stat; + + DoWhileLoopTreeImpl(final WhileNode node, final ExpressionTree cond, final StatementTree stat) { + super(node); + assert node.isDoWhile() : "do while expected"; + this.cond = cond; + this.stat = stat; + } + + @Override + public Kind getKind() { + return Kind.DO_WHILE_LOOP; + } + + @Override + public ExpressionTree getCondition() { + return cond; + } + + @Override + public StatementTree getStatement() { + return stat; + } + + @Override + public R accept(TreeVisitor visitor, D data) { + return visitor.visitDoWhileLoop(this, data); + } +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/EmptyStatementTree.java 2015-03-09 18:39:12.051742794 +0530 @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +/** + * A tree node for an empty (skip) statement. + * + * For example: + *
+ *    ;
+ * 
+ * + * @since 1.9 + */ +@jdk.Exported +public interface EmptyStatementTree extends StatementTree {} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/EmptyStatementTreeImpl.java 2015-03-09 18:39:12.343744244 +0530 @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +import jdk.nashorn.internal.ir.EmptyNode; + +final class EmptyStatementTreeImpl extends StatementTreeImpl implements EmptyStatementTree { + EmptyStatementTreeImpl(final EmptyNode node) { + super(node); + } + + @Override + public Kind getKind() { + return Kind.EMPTY_STATEMENT; + } + + @Override + public R accept(TreeVisitor visitor, D data) { + return visitor.visitEmptyStatement(this, data); + } +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/ErroneousTree.java 2015-03-09 18:39:12.635745696 +0530 @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +/** + * A tree node to stand in for a malformed expression. + * + * @since 1.9 + */ +@jdk.Exported +public interface ErroneousTree extends ExpressionTree { +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/ErroneousTreeImpl.java 2015-03-09 18:39:12.931747160 +0530 @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +import jdk.nashorn.internal.ir.ErrorNode; + +final class ErroneousTreeImpl extends ExpressionTreeImpl implements ErroneousTree { + ErroneousTreeImpl(final ErrorNode errorNode) { + super(errorNode); + } + + @Override + public Kind getKind() { + return Kind.ERROR; + } + + @Override + public R accept(TreeVisitor visitor, D data) { + return visitor.visitErroneous(this, data); + } +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/ExpressionStatementTree.java 2015-03-09 18:39:13.223748612 +0530 @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +/** + * A tree node for an expression statement. + * + * For example: + *
+ *   expression ;
+ * 
+ * + * @since 1.9 + */ +@jdk.Exported +public interface ExpressionStatementTree extends StatementTree { + /** + * Returns the expression of this expression statement. + * + * @return the expression + */ + ExpressionTree getExpression(); +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/ExpressionStatementTreeImpl.java 2015-03-09 18:39:13.527750113 +0530 @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +import jdk.nashorn.internal.ir.ExpressionStatement; + +final class ExpressionStatementTreeImpl extends StatementTreeImpl implements ExpressionStatementTree { + private final ExpressionTree expr; + + ExpressionStatementTreeImpl(final ExpressionStatement es, final ExpressionTree expr) { + super(es); + this.expr = expr; + } + + @Override + public Kind getKind() { + return Kind.EXPRESSION_STATEMENT; + } + + @Override + public ExpressionTree getExpression() { + return expr; + } + + @Override + public R accept(TreeVisitor visitor, D data) { + return visitor.visitExpressionStatement(this, data); + } +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/ExpressionTree.java 2015-03-09 18:39:13.823751587 +0530 @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +/** + * A tree node used as the base class for the different types of + * expressions. + * + * @since 1.9 + */ +@jdk.Exported +public interface ExpressionTree extends Tree {} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/ExpressionTreeImpl.java 2015-03-09 18:39:14.115753031 +0530 @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +import jdk.nashorn.internal.ir.Expression; + +abstract class ExpressionTreeImpl extends TreeImpl implements ExpressionTree { + ExpressionTreeImpl(final Expression expr) { + super(expr); + } +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/ForInLoopTree.java 2015-03-09 18:39:14.407754479 +0530 @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +/** + * A tree node for for..in statement + * + * For example: + *
+ *   for ( variable in expression )
+ *       statement
+ * 
+ * + * @since 1.9 + */ +@jdk.Exported +public interface ForInLoopTree extends LoopTree { + /** + * The for..in left hand side expression. + * + * @return the left hand side expression + */ + ExpressionTree getVariable(); + + /** + * The object or array being whose properties are iterated. + * + * @return the object or array expression being iterated + */ + ExpressionTree getExpression(); + + /** + * The statement contained in this for..in statement. + * + * @return the statement + */ + StatementTree getStatement(); + + /** + * Returns if this is a for..each..in statement or not. + * + * @return true if this is a for..each..in statement + */ + boolean isForEach(); +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/ForInLoopTreeImpl.java 2015-03-09 18:39:14.699755931 +0530 @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +import jdk.nashorn.internal.ir.ForNode; + +final class ForInLoopTreeImpl extends StatementTreeImpl implements ForInLoopTree { + private final ExpressionTree lhsExpr; + private final ExpressionTree expr; + private final StatementTree stat; + private final boolean forEach; + + ForInLoopTreeImpl(final ForNode node, + final ExpressionTree lhsExpr, + final ExpressionTree expr, + final StatementTree stat) { + super(node); + assert node.isForIn() : "for ..in expected"; + this.lhsExpr = lhsExpr; + this.expr = expr; + this.stat = stat; + this.forEach = node.isForEach(); + } + + @Override + public Kind getKind() { + return Kind.FOR_IN_LOOP; + } + + @Override + public ExpressionTree getVariable() { + return lhsExpr; + } + + @Override + public ExpressionTree getExpression() { + return expr; + } + + @Override + public StatementTree getStatement() { + return stat; + } + + @Override + public boolean isForEach() { + return forEach; + } + + @Override + public R accept(TreeVisitor visitor, D data) { + return visitor.visitForInLoop(this, data); + } +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/ForLoopTree.java 2015-03-09 18:39:14.995757395 +0530 @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +/** + * A tree node for a basic 'for' loop statement. + * + * For example: + *
+ *   for ( initializer ; condition ; update )
+ *       statement
+ * 
+ * + * @since 1.9 + */ +@jdk.Exported +public interface ForLoopTree extends ConditionalLoopTree { + /** + * Returns the initializer expression of this 'for' statement. + * + * @return the initializer expression + */ + ExpressionTree getInitializer(); + + /** + * Returns the condition expression of this 'for' statement. + * + * @return the condition expression + */ + ExpressionTree getCondition(); + + /** + * Returns the update expression of this 'for' statement. + * + * @return the update expression + */ + ExpressionTree getUpdate(); + + /** + * Returns the statement contained in this 'for' statement. + * + * @return the statement + */ + StatementTree getStatement(); +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/ForLoopTreeImpl.java 2015-03-09 18:39:15.311758964 +0530 @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +import java.util.List; +import jdk.nashorn.internal.ir.ForNode; + +final class ForLoopTreeImpl extends StatementTreeImpl implements ForLoopTree { + private final ExpressionTree init; + private final ExpressionTree cond; + private final ExpressionTree update; + private final StatementTree stat; + + ForLoopTreeImpl(final ForNode node, + final ExpressionTree init, + final ExpressionTree cond, + final ExpressionTree update, + final StatementTree stat) { + super(node); + assert !node.isForIn() : "for statement expected"; + this.init = init; + this.cond = cond; + this.update = update; + this.stat = stat; + } + + @Override + public Kind getKind() { + return Kind.FOR_LOOP; + } + + @Override + public ExpressionTree getInitializer() { + return init; + } + + @Override + public ExpressionTree getCondition() { + return cond; + } + + @Override + public ExpressionTree getUpdate() { + return update; + } + + @Override + public StatementTree getStatement() { + return stat; + } + + @Override + public R accept(TreeVisitor visitor, D data) { + return visitor.visitForLoop(this, data); + } +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/FunctionCallTree.java 2015-03-09 18:39:15.607760430 +0530 @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +import java.util.List; + +/** + * A tree node for a function call expression. + * + * For example: + *
+ *   identifier ( arguments )
+ *
+ *   this . identifier ( arguments )
+ * 
+ * + * @since 1.9 + */ +@jdk.Exported +public interface FunctionCallTree extends ExpressionTree { + /** + * Returns the function being called. + * + * @return the function being called + */ + ExpressionTree getFunctionSelect(); + + /** + * Returns the list of arguments being passed to this function call. + * + * @return the list of argument expressions + */ + List getArguments(); +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/FunctionCallTreeImpl.java 2015-03-09 18:39:15.907761917 +0530 @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +import java.util.List; +import jdk.nashorn.internal.ir.CallNode; + +class FunctionCallTreeImpl extends ExpressionTreeImpl implements FunctionCallTree { + private final List arguments; + private final ExpressionTree function; + FunctionCallTreeImpl(final CallNode node, + final ExpressionTree function, + final List arguments) { + super(node); + this.function = function; + this.arguments = arguments; + } + + @Override + public Kind getKind() { + return Kind.FUNCTION_INVOCATION; + } + + @Override + public ExpressionTree getFunctionSelect() { + return function; + } + + @Override + public List getArguments() { + return arguments; + } + + @Override + public R accept(TreeVisitor visitor, D data) { + return visitor.visitFunctionCall(this, data); + } +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/FunctionDeclarationTree.java 2015-03-09 18:39:16.203763385 +0530 @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +import java.util.List; + +/** + * A tree node for a function declaration. + * + * For example: + *
+ *   function name
+ *      ( parameters )
+ *      body
+ * 
+ * + * @since 1.9 + */ +@jdk.Exported +public interface FunctionDeclarationTree extends StatementTree { + /** + * Returns the name of the function being declared. + * + * @return name the function declared + */ + String getName(); + + /** + * Returns the parameters of this function. + * + * @return the list of parameters + */ + List getParameters(); + + /** + * Returns the body of code of this function. + * + * @return the body of code + */ + BlockTree getBody(); + + /** + * Is this a strict function? + * + * @return true if this function is strict + */ + boolean isStrict(); +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/FunctionDeclarationTreeImpl.java 2015-03-09 18:39:16.495764833 +0530 @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +import java.util.List; +import jdk.nashorn.internal.ir.FunctionNode; +import jdk.nashorn.internal.ir.VarNode; + +final class FunctionDeclarationTreeImpl extends StatementTreeImpl + implements FunctionDeclarationTree { + private final FunctionNode funcNode; + private final String funcName; + private final List params; + private final BlockTree body; + + FunctionDeclarationTreeImpl(final VarNode node, + final List params, + final BlockTree body) { + super(node); + assert node.getInit() instanceof FunctionNode : "function expected"; + funcNode = (FunctionNode)node.getInit(); + assert funcNode.isDeclared() : "function declaration expected"; + funcName = node.getName().getName(); + this.params = params; + this.body = body; + } + + @Override + public Kind getKind() { + return Kind.FUNCTION; + } + + @Override + public String getName() { + return funcName; + } + + @Override + public List getParameters() { + return params; + } + + @Override + public BlockTree getBody() { + return body; + } + + @Override + public boolean isStrict() { + return funcNode.isStrict(); + } + + @Override + public R accept(TreeVisitor visitor, D data) { + return visitor.visitFunctionDeclaration(this, data); + } +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/FunctionExpressionTree.java 2015-03-09 18:39:16.795766321 +0530 @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +import java.util.List; + +/** + * A tree node for a function expression. + * + * For example: + *
+ *   var func = function
+ *      ( parameters )
+ *      body
+ * 
+ * + * @since 1.9 + */ +@jdk.Exported +public interface FunctionExpressionTree extends ExpressionTree { + /** + * Returns the name of the function being declared. + * + * @return name the function declared + */ + String getName(); + + /** + * Returns the parameters of this function. + * + * @return the list of parameters + */ + List getParameters(); + + /** + * Returns the body of code of this function. + * + * @return the body of code + */ + BlockTree getBody(); + + /** + * Is this a strict function? + * + * @return true if this function is strict + */ + boolean isStrict(); +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/FunctionExpressionTreeImpl.java 2015-03-09 18:39:17.095767808 +0530 @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +import java.util.List; +import jdk.nashorn.internal.ir.FunctionNode; + +final class FunctionExpressionTreeImpl extends ExpressionTreeImpl + implements FunctionExpressionTree { + private final FunctionNode funcNode; + private final String funcName; + private final List params; + private final BlockTree body; + + FunctionExpressionTreeImpl(final FunctionNode node, + final List params, + final BlockTree body) { + super(node); + funcNode = node; + assert !funcNode.isDeclared() : "function expression expected"; + + final FunctionNode.Kind kind = node.getKind(); + if (node.isAnonymous() || kind == FunctionNode.Kind.GETTER || kind == FunctionNode.Kind.SETTER) { + funcName = null; + } else { + funcName = node.getIdent().getName(); + } + + this.params = params; + this.body = body; + } + + @Override + public Tree.Kind getKind() { + return Tree.Kind.FUNCTION_EXPRESSION; + } + + @Override + public String getName() { + return funcName; + } + + @Override + public List getParameters() { + return params; + } + + @Override + public BlockTree getBody() { + return body; + } + + @Override + public boolean isStrict() { + return funcNode.isStrict(); + } + + @Override + public R accept(TreeVisitor visitor, D data) { + return visitor.visitFunctionExpression(this, data); + } +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/GotoTree.java 2015-03-09 18:39:17.395769296 +0530 @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +/** + * A tree node for a statement that jumps to a target. Note that + * ECMAScript does not support a goto statement. But, this Tree + * type serves as a super interface for {@link BreakTree} and + * {@link ContinueTree}. + * + * @since 1.9 + */ +@jdk.Exported +public interface GotoTree extends StatementTree { + /** + * Label associated with this goto statement. This is null + * if there is no label associated with this goto statement. + * + * @return label associated with this goto statement. + */ + String getLabel(); +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/IRTranslator.java 2015-03-09 18:39:17.691770761 +0530 @@ -0,0 +1,517 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package jdk.nashorn.api.tree; + +import java.util.ArrayList; +import java.util.List; +import jdk.nashorn.internal.ir.AccessNode; +import jdk.nashorn.internal.ir.BinaryNode; +import jdk.nashorn.internal.ir.Block; +import jdk.nashorn.internal.ir.BlockStatement; +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.IdentNode; +import jdk.nashorn.internal.ir.IfNode; +import jdk.nashorn.internal.ir.IndexNode; +import jdk.nashorn.internal.ir.LabelNode; +import jdk.nashorn.internal.ir.LexicalContext; +import jdk.nashorn.internal.ir.LiteralNode; +import jdk.nashorn.internal.ir.Node; +import jdk.nashorn.internal.ir.ObjectNode; +import jdk.nashorn.internal.ir.PropertyNode; +import jdk.nashorn.internal.ir.ReturnNode; +import jdk.nashorn.internal.ir.RuntimeNode; +import jdk.nashorn.internal.ir.SplitNode; +import jdk.nashorn.internal.ir.Statement; +import jdk.nashorn.internal.ir.SwitchNode; +import jdk.nashorn.internal.ir.TernaryNode; +import jdk.nashorn.internal.ir.ThrowNode; +import jdk.nashorn.internal.ir.TryNode; +import jdk.nashorn.internal.ir.UnaryNode; +import jdk.nashorn.internal.ir.VarNode; +import jdk.nashorn.internal.ir.WhileNode; +import jdk.nashorn.internal.ir.WithNode; +import jdk.nashorn.internal.ir.visitor.NodeVisitor; +import jdk.nashorn.internal.parser.Lexer; +import jdk.nashorn.internal.parser.TokenType; + +/** + * This class translates from nashorn IR Node objects + * to nashorn parser API Tree objects. + */ +final class IRTranslator extends NodeVisitor { + + public IRTranslator() { + super(new LexicalContext()); + } + + // currently translated Statement + private StatementTreeImpl curStat; + // currently translated Expression + private ExpressionTreeImpl curExpr; + + // entry point for translator + CompilationUnitTree translate(final FunctionNode node) { + if (node == null) { + return null; + } + + assert (node.getKind() == FunctionNode.Kind.SCRIPT) : "script function expected"; + + final Block body = node.getBody(); + return new CompilationUnitTreeImpl(node, + translateStats(body != null? body.getStatements() : null)); + } + + @Override + public boolean enterAccessNode(final AccessNode accessNode) { + curExpr = new MemberSelectTreeImpl(accessNode, translateExpr(accessNode.getBase())); + return false; + } + + @Override + public boolean enterBlock(final Block block) { + // FIXME: revisit this! + if (block.isSynthetic()) { + final int statCount = block.getStatementCount(); + switch (statCount) { + case 0: { + final EmptyNode emptyNode = new EmptyNode(-1, block.getToken(), block.getFinish()); + curStat = new EmptyStatementTreeImpl(emptyNode); + return false; + } + case 1: { + curStat = translateStat(block.getStatements().get(0)); + return false; + } + } + } + + curStat = new BlockTreeImpl(block, + translateStats(block.getStatements())); + return false; + } + + @Override + public boolean enterBinaryNode(final BinaryNode binaryNode) { + if (binaryNode.isAssignment()) { + final ExpressionTree srcTree = translateExpr(binaryNode.getAssignmentSource()); + final ExpressionTree destTree = translateExpr(binaryNode.getAssignmentDest()); + + if (binaryNode.tokenType() == TokenType.ASSIGN) { + curExpr = new AssignmentTreeImpl(binaryNode, destTree, srcTree); + } else { + curExpr = new CompoundAssignmentTreeImpl(binaryNode, destTree, srcTree); + } + } else { + final ExpressionTree leftTree = translateExpr(binaryNode.lhs()); + final ExpressionTree rightTree = translateExpr(binaryNode.rhs()); + + if (binaryNode.tokenType() == TokenType.INSTANCEOF) { + curExpr = new InstanceOfTreeImpl(binaryNode, leftTree, rightTree); + } else { + curExpr = new BinaryTreeImpl(binaryNode, leftTree, rightTree); + } + } + + return false; + } + + @Override + public boolean enterBreakNode(final BreakNode breakNode) { + curStat = new BreakTreeImpl(breakNode); + return false; + } + + @Override + public boolean enterCallNode(final CallNode callNode) { + curExpr = null; + callNode.getFunction().accept(this); + final ExpressionTree funcTree = curExpr; + final List argTrees = translateExprs(callNode.getArgs()); + curExpr = new FunctionCallTreeImpl(callNode, funcTree, argTrees); + return false; + } + + @Override + public boolean enterCaseNode(final CaseNode caseNode) { + assert false : "should not reach here!"; + return false; + } + + @Override + public boolean enterCatchNode(final CatchNode catchNode) { + assert false : "should not reach here"; + return false; + } + + @Override + public boolean enterContinueNode(final ContinueNode continueNode) { + curStat = new ContinueTreeImpl(continueNode); + return false; + } + + @Override + public boolean enterDebuggerNode(final DebuggerNode debuggerNode) { + curStat = new DebuggerTreeImpl(debuggerNode); + return false; + } + + @Override + public boolean enterEmptyNode(final EmptyNode emptyNode) { + curStat = new EmptyStatementTreeImpl(emptyNode); + return false; + } + + @Override + public boolean enterErrorNode(final ErrorNode errorNode) { + curExpr = new ErroneousTreeImpl(errorNode); + return false; + } + + @Override + public boolean enterExpressionStatement(final ExpressionStatement expressionStatement) { + curStat = new ExpressionStatementTreeImpl(expressionStatement, + translateExpr(expressionStatement.getExpression())); + return false; + } + + @Override + public boolean enterBlockStatement(final BlockStatement blockStatement) { + final Block block = blockStatement.getBlock(); + if (blockStatement.isSynthetic()) { + assert block != null && block.getStatements() != null && block.getStatements().size() == 1; + curStat = translateStat(block.getStatements().get(0)); + } else { + curStat = new BlockTreeImpl(blockStatement, + translateStats(block != null? block.getStatements() : null)); + } + return false; + } + + @Override + public boolean enterForNode(final ForNode forNode) { + if (forNode.isForIn()) { + curStat = new ForInLoopTreeImpl(forNode, + translateExpr(forNode.getInit()), + translateExpr(forNode.getModify()), + translateBlock(forNode.getBody())); + } else { + curStat = new ForLoopTreeImpl(forNode, + translateExpr(forNode.getInit()), + translateExpr(forNode.getTest()), + translateExpr(forNode.getModify()), + translateBlock(forNode.getBody())); + } + + return false; + } + + @Override + public boolean enterFunctionNode(final FunctionNode functionNode) { + assert !functionNode.isDeclared() : "should not reach here for function declaration"; + + final List paramTrees + = translateExprs(functionNode.getParameters()); + final BlockTree blockTree = (BlockTree) translateBlock(functionNode.getBody()); + curExpr = new FunctionExpressionTreeImpl(functionNode, paramTrees, blockTree); + + return false; + } + + @Override + public boolean enterIdentNode(final IdentNode identNode) { + curExpr = new IdentifierTreeImpl(identNode); + return false; + } + + @Override + public boolean enterIfNode(final IfNode ifNode) { + curStat = new IfTreeImpl(ifNode, + translateExpr(ifNode.getTest()), + translateBlock(ifNode.getPass()), + translateBlock(ifNode.getFail())); + return false; + } + + @Override + public boolean enterIndexNode(final IndexNode indexNode) { + curExpr = new ArrayAccessTreeImpl(indexNode, + translateExpr(indexNode.getBase()), + translateExpr(indexNode.getIndex())); + return false; + } + + @Override + public boolean enterLabelNode(final LabelNode labelNode) { + curStat = new LabeledStatementTreeImpl(labelNode, + translateBlock(labelNode.getBody())); + return false; + } + + @Override + public boolean enterLiteralNode(final LiteralNode literalNode) { + final Object value = literalNode.getValue(); + if (value instanceof Lexer.RegexToken) { + curExpr = new RegExpLiteralTreeImpl(literalNode); + } else if (literalNode.isArray()) { + final List exprNodes = literalNode.getElementExpressions(); + final List exprTrees = new ArrayList<>(exprNodes.size()); + for (final Node node : exprNodes) { + if (node == null) { + exprTrees.add(null); + } else { + curExpr = null; + node.accept(this); + assert curExpr != null : "null for " + node; + exprTrees.add(curExpr); + } + } + curExpr = new ArrayLiteralTreeImpl(literalNode, exprTrees); + } else { + curExpr = new LiteralTreeImpl(literalNode); + } + + return false; + } + + @Override + public boolean enterObjectNode(final ObjectNode objectNode) { + final List propNodes = objectNode.getElements(); + final List propTrees = new ArrayList<>(propNodes.size()); + for (final PropertyNode propNode : propNodes) { + propTrees.add(new PropertyTreeImpl(propNode, + translateExpr(propNode.getKey()), + translateExpr(propNode.getValue()), + (FunctionExpressionTree) translateExpr(propNode.getGetter()), + (FunctionExpressionTree) translateExpr(propNode.getSetter()))); + } + curExpr = new ObjectLiteralTreeImpl(objectNode, propTrees); + return false; + } + + @Override + public boolean enterPropertyNode(final PropertyNode propertyNode) { + assert false : "should not reach here!"; + return false; + } + + @Override + public boolean enterReturnNode(final ReturnNode returnNode) { + curStat = new ReturnTreeImpl(returnNode, + translateExpr(returnNode.getExpression())); + return false; + } + + @Override + public boolean enterRuntimeNode(final RuntimeNode runtimeNode) { + assert false : "should not reach here: RuntimeNode"; + return false; + } + + @Override + public boolean enterSplitNode(final SplitNode splitNode) { + assert false : "should not reach here!"; + return false; + } + + @Override + public boolean enterSwitchNode(final SwitchNode switchNode) { + final List caseNodes = switchNode.getCases(); + final List caseTrees = new ArrayList<>(caseNodes.size()); + for (final CaseNode caseNode : caseNodes) { + final Block body = caseNode.getBody(); + caseTrees.add( + new CaseTreeImpl(caseNode, + translateExpr(caseNode.getTest()), + translateStats(body != null? body.getStatements() : null))); + } + + curStat = new SwitchTreeImpl(switchNode, + translateExpr(switchNode.getExpression()), + caseTrees); + return false; + } + + @Override + public boolean enterTernaryNode(final TernaryNode ternaryNode) { + curExpr = new ConditionalExpressionTreeImpl(ternaryNode, + translateExpr(ternaryNode.getTest()), + translateExpr(ternaryNode.getTrueExpression()), + translateExpr(ternaryNode.getFalseExpression())); + return false; + } + + @Override + public boolean enterThrowNode(final ThrowNode throwNode) { + curStat = new ThrowTreeImpl(throwNode, + translateExpr(throwNode.getExpression())); + return false; + } + + @Override + public boolean enterTryNode(final TryNode tryNode) { + final List catchNodes = tryNode.getCatches(); + final List catchTrees = new ArrayList<>(catchNodes.size()); + for (final CatchNode catchNode : catchNodes) { + catchTrees.add(new CatchTreeImpl(catchNode, + translateIdent(catchNode.getException()), + (BlockTree) translateBlock(catchNode.getBody()), + translateExpr(catchNode.getExceptionCondition()))); + } + + curStat = new TryTreeImpl(tryNode, + (BlockTree) translateBlock(tryNode.getBody()), + catchTrees, + (BlockTree) translateBlock(tryNode.getFinallyBody())); + + return false; + } + + @Override + public boolean enterUnaryNode(final UnaryNode unaryNode) { + if (unaryNode.tokenType() == TokenType.NEW) { + curExpr = new NewTreeImpl(unaryNode, + translateExpr(unaryNode.getExpression())); + } else { + curExpr = new UnaryTreeImpl(unaryNode, + translateExpr(unaryNode.getExpression())); + } + return false; + } + + @Override + public boolean enterVarNode(final VarNode varNode) { + final Expression initNode = varNode.getInit(); + if (initNode instanceof FunctionNode && ((FunctionNode)initNode).isDeclared()) { + final FunctionNode funcNode = (FunctionNode) initNode; + + final List paramTrees + = translateExprs(funcNode.getParameters()); + final BlockTree blockTree = (BlockTree) translateBlock(funcNode.getBody()); + curStat = new FunctionDeclarationTreeImpl(varNode, paramTrees, blockTree); + } else { + curStat = new VariableTreeImpl(varNode, translateExpr(initNode)); + } + + return false; + } + + @Override + public boolean enterWhileNode(final WhileNode whileNode) { + final ExpressionTree condTree = translateExpr(whileNode.getTest()); + final StatementTree statTree = translateBlock(whileNode.getBody()); + + if (whileNode.isDoWhile()) { + curStat = new DoWhileLoopTreeImpl(whileNode, condTree, statTree); + } else { + curStat = new WhileLoopTreeImpl(whileNode, condTree, statTree); + } + + return false; + } + + @Override + public boolean enterWithNode(final WithNode withNode) { + curStat = new WithTreeImpl(withNode, + translateExpr(withNode.getExpression()), + translateBlock(withNode.getBody())); + + return false; + } + + private StatementTree translateBlock(final Block blockNode) { + if (blockNode == null) { + return null; + } + curStat = null; + blockNode.accept(this); + return curStat; + } + + private List translateStats(final List stats) { + if (stats == null) { + return null; + } + final List statTrees = new ArrayList<>(stats.size()); + for (final Statement stat : stats) { + curStat = null; + stat.accept(this); + assert curStat != null; + statTrees.add(curStat); + } + return statTrees; + } + + private List translateExprs(final List exprs) { + if (exprs == null) { + return null; + } + final List exprTrees = new ArrayList<>(exprs.size()); + for (final Expression expr : exprs) { + curExpr = null; + expr.accept(this); + assert curExpr != null; + exprTrees.add(curExpr); + } + return exprTrees; + } + + private ExpressionTreeImpl translateExpr(final Expression expr) { + if (expr == null) { + return null; + } + + curExpr = null; + expr.accept(this); + assert curExpr != null : "null for " + expr; + return curExpr; + } + + private StatementTreeImpl translateStat(final Statement stat) { + if (stat == null) { + return null; + } + + curStat = null; + stat.accept(this); + assert curStat != null : "null for " + stat; + return curStat; + } + + private IdentifierTree translateIdent(final IdentNode ident) { + return new IdentifierTreeImpl(ident); + } +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/IdentifierTree.java 2015-03-09 18:39:17.999772295 +0530 @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +/** + * A tree node for an identifier expression. + * + * For example: + *
+ *   name
+ * 
+ * + * @since 1.9 + */ +@jdk.Exported +public interface IdentifierTree extends ExpressionTree { + /** + * Returns the name of this identifier. + * + * @return the name of this identifier + */ + String getName(); +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/IdentifierTreeImpl.java 2015-03-09 18:39:18.299773781 +0530 @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + + +package jdk.nashorn.api.tree; + +import jdk.nashorn.internal.ir.IdentNode; + +final class IdentifierTreeImpl extends ExpressionTreeImpl implements IdentifierTree { + private final String name; + + IdentifierTreeImpl(final IdentNode node) { + super(node); + this.name = node.getName(); + } + + @Override + public Kind getKind() { + return Kind.IDENTIFIER; + } + + @Override + public String getName() { + return name; + } + + @Override + public R accept(TreeVisitor visitor, D data) { + return visitor.visitIdentifier(this, data); + } +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/IfTree.java 2015-03-09 18:39:18.591775224 +0530 @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +/** + * A tree node for an 'if' statement. + * + * For example: + *
+ *   if ( condition )
+ *      thenStatement
+ *
+ *   if ( condition )
+ *       thenStatement
+ *   else
+ *       elseStatement
+ * 
+ * + * @since 1.9 + */ +@jdk.Exported +public interface IfTree extends StatementTree { + /** + * Returns the condition expression of this 'if' statement. + * + * @return the condition expression + */ + ExpressionTree getCondition(); + + /** + * Returns the 'then' statement of this 'if' statement. + * + * @return the 'then' statement + */ + StatementTree getThenStatement(); + + /** + * Returns the then statement of this 'if' statement. + * null if this if statement has no else branch. + * + * @return the 'else' statement + */ + StatementTree getElseStatement(); +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/IfTreeImpl.java 2015-03-09 18:39:19.059777545 +0530 @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +import jdk.nashorn.internal.ir.IfNode; + +final class IfTreeImpl extends StatementTreeImpl implements IfTree { + private final ExpressionTree cond; + private final StatementTree thenStat; + private final StatementTree elseStat; + IfTreeImpl(final IfNode node, final ExpressionTree cond, + final StatementTree thenStat, final StatementTree elseStat) { + super(node); + this.cond = cond; + this.thenStat = thenStat; + this.elseStat = elseStat; + } + + @Override + public Kind getKind() { + return Kind.IF; + } + + @Override + public ExpressionTree getCondition() { + return cond; + } + + @Override + public StatementTree getThenStatement() { + return thenStat; + } + + /** + * @return null if this if statement has no else branch. + */ + @Override + public StatementTree getElseStatement() { + return elseStat; + } + + @Override + public R accept(TreeVisitor visitor, D data) { + return visitor.visitIf(this, data); + } +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/InstanceOfTree.java 2015-03-09 18:39:19.591780185 +0530 @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +/** + * A tree node for an 'instanceof' expression. + * + * For example: + *
+ *   expression instanceof type
+ * 
+ * + * @since 1.9 + */ +@jdk.Exported +public interface InstanceOfTree extends ExpressionTree { + /** + * Returns the expression whose type is being checked. + * + * @return the expression whose type is being checked + */ + ExpressionTree getExpression(); + + /** + * Returns the type expression. + * + * @return the type expression + */ + Tree getType(); +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/InstanceOfTreeImpl.java 2015-03-09 18:39:20.135782887 +0530 @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +import jdk.nashorn.internal.ir.BinaryNode; +import jdk.nashorn.internal.parser.TokenType; + +final class InstanceOfTreeImpl extends BinaryTreeImpl implements InstanceOfTree { + InstanceOfTreeImpl(final BinaryNode node, + final ExpressionTree expr, + final ExpressionTree type) { + super(node, expr, type); + assert node.tokenType() == TokenType.INSTANCEOF : "instanceof expected"; + } + + @Override + public Kind getKind() { + return Kind.INSTANCE_OF; + } + + @Override + public ExpressionTree getExpression() { + return getLeftOperand(); + } + + @Override + public Tree getType() { + return getRightOperand(); + } + + @Override + public R accept(TreeVisitor visitor, D data) { + return visitor.visitInstanceOf(this, data); + } +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/LabeledStatementTree.java 2015-03-09 18:39:20.667785521 +0530 @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +/** + * A tree node for a labeled statement. + * + * For example: + *
+ *   label : statement
+ * 
+ * + * @since 1.9 + */ +@jdk.Exported +public interface LabeledStatementTree extends StatementTree { + /** + * Returns the label associated with this statement. + * + * @return the label + */ + String getLabel(); + + /** + * Returns the statement being labeled. + * + * @return the statement labeled + */ + StatementTree getStatement(); +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/LabeledStatementTreeImpl.java 2015-03-09 18:39:21.195788139 +0530 @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +import jdk.nashorn.internal.ir.LabelNode; + +final class LabeledStatementTreeImpl extends StatementTreeImpl + implements LabeledStatementTree { + private final String name; + private final StatementTree stat; + + LabeledStatementTreeImpl(final LabelNode node, final StatementTree stat) { + super(node); + this.name = node.getLabelName(); + this.stat = stat; + } + + @Override + public Kind getKind() { + return Kind.LABELED_STATEMENT; + } + + @Override + public String getLabel() { + return name; + } + + @Override + public StatementTree getStatement() { + return stat; + } + + @Override + public R accept(TreeVisitor visitor, D data) { + return visitor.visitLabeledStatement(this, data); + } +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/LineMap.java 2015-03-09 18:39:21.727790777 +0530 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +/** + * Provides methods to convert between character positions and line numbers + * for a compilation unit. + * + * @since 1.9 + */ +@jdk.Exported +public interface LineMap { + /** + * Find the line containing a position; a line termination + * character is on the line it terminates. + * + * @param pos character offset of the position + * @return the line number of pos (first line is 1) + */ + long getLineNumber(long pos); + + /** + * Find the column for a character position. + * Tab characters preceding the position on the same line + * will be expanded when calculating the column number. + * + * @param pos character offset of the position + * @return the tab-expanded column number of pos (first column is 1) + */ + long getColumnNumber(long pos); +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/LineMapImpl.java 2015-03-09 18:39:22.259793419 +0530 @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +import jdk.nashorn.internal.runtime.Source; + +final class LineMapImpl implements LineMap { + private final Source source; + + LineMapImpl(final Source source) { + this.source = source; + } + + @Override + public long getLineNumber(long pos) { + return source.getLine((int)pos); + } + + @Override + public long getColumnNumber(long pos) { + return source.getColumn((int)pos); + } +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/LiteralTree.java 2015-03-09 18:39:22.799796097 +0530 @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +/** + * A tree node for a literal expression. + * Use {@link #getKind getKind} to determine the kind of literal. + * + * For example: + *
+ *   value
+ * 
+ * + * @since 1.9 + */ +@jdk.Exported +public interface LiteralTree extends ExpressionTree { + /** + * Returns the value of this literal. + * + * @return the value of this literal + */ + Object getValue(); +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/LiteralTreeImpl.java 2015-03-09 18:39:23.319798669 +0530 @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +import jdk.nashorn.internal.ir.LiteralNode; + +final class LiteralTreeImpl extends ExpressionTreeImpl implements LiteralTree { + private final Object value; + private final Kind kind; + LiteralTreeImpl(final LiteralNode node) { + super(node); + this.kind = literalKind(node); + this.value = node.getValue(); + } + + @Override + public Kind getKind() { + return kind; + } + + @Override + public Object getValue() { + return value; + } + + private static Kind literalKind(final LiteralNode node) { + if (node.isBoolean()) { + return Kind.BOOLEAN_LITERAL; + } else if (node.isNumeric()) { + return Kind.NUMBER_LITERAL; + } else if (node.isString()) { + return Kind.STRING_LITERAL; + } else if (node.isNull()) { + return Kind.NULL_LITERAL; + } else { + throw new AssertionError("should not reach here: " + node.getValue()); + } + } + + @Override + public R accept(TreeVisitor visitor, D data) { + return visitor.visitLiteral(this, data); + } +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/LoopTree.java 2015-03-09 18:39:23.843801274 +0530 @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +/** + * A mixin for "loop" statements. + * + * @since 1.9 + */ +@jdk.Exported +public interface LoopTree extends StatementTree { + /** + * Returns the statement contained in this 'loop' statement. + * + * @return the statement + */ + StatementTree getStatement(); +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/MemberSelectTree.java 2015-03-09 18:39:24.367803865 +0530 @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +/** + * A tree node for a member access expression. + * + * For example: + *
+ *   expression . identifier
+ * 
+ * + * @since 1.9 + */ +@jdk.Exported +public interface MemberSelectTree extends ExpressionTree { + /** + * The object expression whose member is being selected. + * + * @return the object whose member is selected + */ + ExpressionTree getExpression(); + + /** + * Returns the name of the property. + * + * @return the name of the property + */ + String getIdentifier(); +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/MemberSelectTreeImpl.java 2015-03-09 18:39:24.891806467 +0530 @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +import jdk.nashorn.internal.ir.AccessNode; + +final class MemberSelectTreeImpl extends ExpressionTreeImpl + implements MemberSelectTree { + private final String ident; + private final ExpressionTree expr; + MemberSelectTreeImpl(final AccessNode node, final ExpressionTree expr) { + super(node); + this.ident = node.getProperty(); + this.expr = expr; + } + + @Override + public Kind getKind() { + return Kind.MEMBER_SELECT; + } + + @Override + public ExpressionTree getExpression() { + return expr; + } + + @Override + public String getIdentifier() { + return ident; + } + + @Override + public R accept(TreeVisitor visitor, D data) { + return visitor.visitMemberSelect(this, data); + } +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/NewTree.java 2015-03-09 18:39:25.419809082 +0530 @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +import java.util.List; + +/** + * A tree node to declare a new instance of a class. + * + * For example: + *
+ *   new identifier ( )
+ *
+ *   new identifier ( arguments )
+ * 
+ * + * @since 1.9 + */ +@jdk.Exported +public interface NewTree extends ExpressionTree { + /** + * Returns the constructor expression of this 'new' expression. + * + * @return the constructor expression of this 'new' expression + */ + ExpressionTree getConstructorExpression(); +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/NewTreeImpl.java 2015-03-09 18:39:25.951811722 +0530 @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package jdk.nashorn.api.tree; + +import jdk.nashorn.internal.ir.UnaryNode; +import jdk.nashorn.internal.parser.TokenType; + +final class NewTreeImpl extends ExpressionTreeImpl implements NewTree { + private final ExpressionTree constrExpr; + + NewTreeImpl(final UnaryNode node, final ExpressionTree constrExpr) { + super(node); + assert (node.tokenType() == TokenType.NEW) : "new expected"; + this.constrExpr = constrExpr; + } + + @Override + public Kind getKind() { + return Kind.NEW; + } + + @Override + public ExpressionTree getConstructorExpression() { + return constrExpr; + } + + @Override + public R accept(TreeVisitor visitor, D data) { + return visitor.visitNew(this, data); + } +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/ObjectLiteralTree.java 2015-03-09 18:39:26.471814304 +0530 @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +import java.util.List; + +/** + * Represents ECMAScript object literal expression. + * + * @since 1.9 + */ +@jdk.Exported +public interface ObjectLiteralTree extends ExpressionTree { + /** + * Returns the list of properties of this object literal. + * + * @return the list of properties of this object literal + */ + public List getProperties(); +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/ObjectLiteralTreeImpl.java 2015-03-09 18:39:27.011816979 +0530 @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +import java.util.List; +import jdk.nashorn.internal.ir.ObjectNode; + +final class ObjectLiteralTreeImpl extends ExpressionTreeImpl + implements ObjectLiteralTree { + private final List props; + ObjectLiteralTreeImpl(final ObjectNode node, final List props) { + super(node); + this.props = props; + } + + @Override + public Kind getKind() { + return Kind.OBJECT_LITERAL; + } + + @Override + public List getProperties() { + return props; + } + + @Override + public R accept(TreeVisitor visitor, D data) { + return visitor.visitObjectLiteral(this, data); + } +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/ParenthesizedTree.java 2015-03-09 18:39:27.539819594 +0530 @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +/** + * A tree node for a parenthesized expression. Note: parentheses + * not be preserved by the parser. + * + * For example: + *
+ *   ( expression )
+ * 
+ * + * @since 1.9 + */ +@jdk.Exported +public interface ParenthesizedTree extends ExpressionTree { + /** + * Returns the expression within the parenthesis. + * + * @return the expression within the parenthesis + */ + ExpressionTree getExpression(); +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/Parser.java 2015-03-09 18:39:28.075822266 +0530 @@ -0,0 +1,160 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +import java.io.File; +import java.io.IOException; +import java.io.Reader; +import java.net.URL; +import java.nio.file.Path; +import jdk.nashorn.api.scripting.NashornException; +import jdk.nashorn.api.scripting.ScriptObjectMirror; + +/** + * Represents nashorn ECMAScript parser instance. + * + * @since 1.9 + */ +@jdk.Exported +public interface Parser { + /** + * Parses the source file and returns compilation unit tree + * + * @param file source file to parse + * @param listener to receive diagnostic messages from the parser. This can be null. + * if null is passed, a NashornException is thrown on the first parse error. + * @return compilation unit tree + * @throws NullPointerException if file is null + * @throws IOException if parse source read fails + * @throws NashornException is thrown if no listener is supplied and parser encounters error + */ + public CompilationUnitTree parse(final File file, final DiagnosticListener listener) throws IOException, NashornException; + + /** + * Parses the source Path and returns compilation unit tree + * + * @param path source Path to parse + * @param listener to receive diagnostic messages from the parser. This can be null. + * if null is passed, a NashornException is thrown on the first parse error. + * @return compilation unit tree + * @throws NullPointerException if path is null + * @throws IOException if parse source read fails + * @throws NashornException is thrown if no listener is supplied and parser encounters error + */ + public CompilationUnitTree parse(final Path path, final DiagnosticListener listener) throws IOException, NashornException; + + /** + * Parses the source url and returns compilation unit tree + * + * @param url source file to parse + * @param listener to receive diagnostic messages from the parser. This can be null. + * if null is passed, a NashornException is thrown on the first parse error. + * @return compilation unit tree + * @throws NullPointerException if url is null + * @throws IOException if parse source read fails + * @throws NashornException is thrown if no listener is supplied and parser encounters error + */ + public CompilationUnitTree parse(final URL url, final DiagnosticListener listener) throws IOException, NashornException; + + /** + * Parses the readerand returns compilation unit tree + * + * @param name name of the source file to parse + * @param reader from which source is read + * @param listener to receive diagnostic messages from the parser. This can be null. + * if null is passed, a NashornException is thrown on the first parse error. + * @return compilation unit tree + * @throws NullPointerException if name or reader is null + * @throws IOException if parse source read fails + * @throws NashornException is thrown if no listener is supplied and parser encounters error + */ + public CompilationUnitTree parse(final String name, Reader reader, final DiagnosticListener listener) throws IOException, NashornException; + + /** + * Parses the string source and returns compilation unit tree + * + * @param name of the source + * @param code string source + * @param listener to receive diagnostic messages from the parser. This can be null. + * if null is passed, a NashornException is thrown on the first parse error. + * @return compilation unit tree + * @throws NullPointerException if name or code is null + * @throws NashornException is thrown if no listener is supplied and parser encounters error + */ + public CompilationUnitTree parse(final String name, String code, final DiagnosticListener listener) throws NashornException; + + /** + * Parses the source from script object and returns compilation unit tree + * + * @param scriptObj script object whose script and name properties are used for script source + * @param listener to receive diagnostic messages from the parser. This can be null. + * if null is passed, a NashornException is thrown on the first parse error. + * @return compilation unit tree + * @throws NullPointerException if scriptObj is null + * @throws NashornException is thrown if no listener is supplied and parser encounters error + */ + public CompilationUnitTree parse(final ScriptObjectMirror scriptObj, final DiagnosticListener listener) throws NashornException; + + /** + * Factory method to create a new instance of Parser. + * + * @param options configuration options to initialize the Parser. + * Currently the following options are supported: + * + *
+ *
"--const-as-var"
treat "const" declaration as "var"
+ *
"-dump-on-error" or "-doe"
dump stack trace on error
+ *
"--empty-statements"
include empty statement nodes
+ *
"--no-syntax-extensions" or "-nse"
disable ECMAScript syntax extensions
+ *
"-scripting"
enable scripting mode extensions
+ *
"-strict"
enable ECMAScript strict mode
+ *
+ * + * @throws NullPointerException if options arrry or any of it's element is null + * @throws IllegalArgumentException on unsupported option value. + * @return a new Parser instance. + */ + public static Parser create(final String... options) throws IllegalArgumentException { + options.getClass(); + for (String opt : options) { + switch (opt) { + case "--const-as-var": + case "-dump-on-error": + case "-doe": + case "--empty-statements": + case "--no-syntax-extensions": + case "-nse": + case "-scripting": + case "-strict": + break; + default: + throw new IllegalArgumentException(opt); + } + } + + return new ParserImpl(options); + } +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/ParserImpl.java 2015-03-09 18:39:28.603824875 +0530 @@ -0,0 +1,145 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; +import java.io.Reader; +import java.net.URL; +import java.nio.file.Path; +import java.util.Map; +import java.util.Objects; +import jdk.nashorn.api.scripting.NashornException; +import jdk.nashorn.api.scripting.ScriptObjectMirror; +import jdk.nashorn.internal.ir.FunctionNode; +import jdk.nashorn.internal.runtime.Context; +import jdk.nashorn.internal.runtime.ErrorManager; +import jdk.nashorn.internal.runtime.JSType; +import jdk.nashorn.internal.runtime.ParserException; +import jdk.nashorn.internal.runtime.ScriptEnvironment; +import jdk.nashorn.internal.runtime.Source; +import jdk.nashorn.internal.runtime.options.Options; + +final class ParserImpl implements Parser { + + private final ScriptEnvironment env; + + ParserImpl(final String... args) throws IllegalArgumentException { + Objects.requireNonNull(args); + Options options = new Options("nashorn"); + options.process(args); + this.env = new ScriptEnvironment(options, + new PrintWriter(System.out), new PrintWriter(System.err)); + } + + @Override + public CompilationUnitTree parse(final File file, final DiagnosticListener listener) throws IOException, NashornException { + Objects.requireNonNull(file); + final Source src = Source.sourceFor(file.getName(), file); + return translate(makeParser(src, listener).parse()); + } + + @Override + public CompilationUnitTree parse(final Path path, final DiagnosticListener listener) throws IOException, NashornException { + Objects.requireNonNull(path); + final Source src = Source.sourceFor(path.toString(), path); + return translate(makeParser(src, listener).parse()); + } + + @Override + public CompilationUnitTree parse(final URL url, final DiagnosticListener listener) throws IOException, NashornException { + final Source src = Source.sourceFor(url.toString(), url); + return translate(makeParser(src, listener).parse()); + } + + @Override + public CompilationUnitTree parse(final String name, final Reader reader, final DiagnosticListener listener) throws IOException, NashornException { + Objects.requireNonNull(name); + Objects.requireNonNull(reader); + final Source src = Source.sourceFor(name, reader); + return translate(makeParser(src, listener).parse()); + } + + @Override + public CompilationUnitTree parse(final String name, final String code, final DiagnosticListener listener) throws NashornException { + final Source src = Source.sourceFor(name, code); + return translate(makeParser(src, listener).parse()); + } + + @Override + public CompilationUnitTree parse(final ScriptObjectMirror scriptObj, final DiagnosticListener listener) throws NashornException { + Objects.requireNonNull(scriptObj); + final Map map = scriptObj; + if (map.containsKey("script") && map.containsKey("name")) { + final String script = JSType.toString(map.get("script")); + final String name = JSType.toString(map.get("name")); + final Source src = Source.sourceFor(name, script); + return translate(makeParser(src, listener).parse()); + } else { + throw new IllegalArgumentException("can't find 'script' and 'name' properties"); + } + } + + private jdk.nashorn.internal.parser.Parser makeParser(final Source source, final DiagnosticListener listener) { + final ErrorManager errMgr = listener != null? new ListenerErrorManager(listener) : new Context.ThrowErrorManager(); + return new jdk.nashorn.internal.parser.Parser(env, source, errMgr); + } + + private static class ListenerErrorManager extends ErrorManager { + private final DiagnosticListener listener; + + ListenerErrorManager(final DiagnosticListener listener) { + // null check + listener.getClass(); + this.listener = listener; + } + + @Override + public void error(final String msg) { + error(new ParserException(msg)); + } + + @Override + public void error(final ParserException e) { + listener.report(new DiagnosticImpl(e, Diagnostic.Kind.ERROR)); + } + + @Override + public void warning(final String msg) { + warning(new ParserException(msg)); + } + + @Override + public void warning(final ParserException e) { + listener.report(new DiagnosticImpl(e, Diagnostic.Kind.WARNING)); + } + } + + private CompilationUnitTree translate(final FunctionNode node) { + return new IRTranslator().translate(node); + } +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/PropertyTree.java 2015-03-09 18:39:29.131827491 +0530 @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +/** + * To represent property setting in an object literal tree. + * + * @since 1.9 + */ +@jdk.Exported +public interface PropertyTree extends Tree { + /** + * Returns the name of this property. + * + * @return the name of the property + */ + public ExpressionTree getKey(); + + /** + * Returns the value of this property. This is null for accessor properties. + * + * @return the value of the property + */ + public ExpressionTree getValue(); + + /** + * Returns the setter function of this property if this + * is an accessor property. This is null for data properties. + * + * @return the setter function of the property + */ + public FunctionExpressionTree getGetter(); + + /** + * Returns the getter function of this property if this + * is an accessor property. This is null for data properties. + * + * @return the getter function of the property + */ + public FunctionExpressionTree getSetter(); +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/PropertyTreeImpl.java 2015-03-09 18:39:29.663830147 +0530 @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +import jdk.nashorn.internal.ir.PropertyNode; + +final class PropertyTreeImpl extends TreeImpl implements PropertyTree { + private final ExpressionTree key; + private final ExpressionTree value; + private final FunctionExpressionTree getter; + private final FunctionExpressionTree setter; + PropertyTreeImpl(final PropertyNode node, + final ExpressionTree key, + final ExpressionTree value, + final FunctionExpressionTree getter, + final FunctionExpressionTree setter) { + super(node); + this.key = key; + this.value = value; + this.getter = getter; + this.setter = setter; + } + + @Override + public Kind getKind() { + return Kind.PROPERTY; + } + + @Override + public ExpressionTree getKey() { + return key; + } + + @Override + public ExpressionTree getValue() { + return value; + } + + @Override + public FunctionExpressionTree getGetter() { + return getter; + } + + @Override + public FunctionExpressionTree getSetter() { + return setter; + } + + @Override + public R accept(TreeVisitor visitor, D data) { + return visitor.visitProperty(this, data); + } +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/RegExpLiteralTree.java 2015-03-09 18:39:30.195832774 +0530 @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +/** + * Represents regular expression literal in the source code. + * + * @since 1.9 + */ +@jdk.Exported +public interface RegExpLiteralTree extends Tree { + /** + * Regular expression pattern to match. + * + * @return regular expression patten + */ + public String getPattern(); + + /** + * Regular expression matching options. + * + * @return options like "i" for ignoreCase used + */ + public String getOptions(); +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/RegExpLiteralTreeImpl.java 2015-03-09 18:39:30.719835362 +0530 @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +import jdk.nashorn.internal.ir.LiteralNode; +import jdk.nashorn.internal.parser.Lexer; + +final class RegExpLiteralTreeImpl extends ExpressionTreeImpl + implements RegExpLiteralTree { + private final String pattern; + private final String options; + RegExpLiteralTreeImpl(final LiteralNode node) { + super(node); + assert node.getValue() instanceof Lexer.RegexToken : "regexp expected"; + final Lexer.RegexToken regex = (Lexer.RegexToken) node.getValue(); + this.pattern = regex.getExpression(); + this.options = regex.getOptions(); + } + + @Override + public Kind getKind() { + return Kind.REGEXP_LITERAL; + } + + @Override + public String getPattern() { + return pattern; + } + + @Override + public String getOptions() { + return options; + } + + @Override + public R accept(TreeVisitor visitor, D data) { + return visitor.visitRegExpLiteral(this, data); + } +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/ReturnTree.java 2015-03-09 18:39:31.247837989 +0530 @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +/** + * A tree node for a 'return' statement. + * + * For example: + *
+ *   return;
+ *   return expression;
+ * 
+ * + * @since 1.9 + */ +@jdk.Exported +public interface ReturnTree extends StatementTree { + /** + * Returns the expression being returned. This is null if no value + * is being returned. i.e., empty return statement. + * + * @return the returned expression + */ + ExpressionTree getExpression(); +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/ReturnTreeImpl.java 2015-03-09 18:39:31.727840366 +0530 @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +import jdk.nashorn.internal.ir.ReturnNode; + +final class ReturnTreeImpl extends StatementTreeImpl implements ReturnTree { + private final ExpressionTree expr; + + ReturnTreeImpl(final ReturnNode returnNode, final ExpressionTree expr) { + super(returnNode); + this.expr = expr; + } + + @Override + public Tree.Kind getKind() { + return Tree.Kind.RETURN; + } + + @Override + public ExpressionTree getExpression() { + return expr; + } + + @Override + public R accept(TreeVisitor visitor, D data) { + return visitor.visitReturn(this, data); + } +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/SimpleTreeVisitorES5_1.java 2015-03-09 18:39:32.015841790 +0530 @@ -0,0 +1,390 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +/** + * A simple implementation of the TreeVisitor for ECMAScript edition 5.1. + * + *

The visit methods corresponding to ES 5.1 language constructs walk the + * "components" of the given tree by calling accept method passing the + * current visitor and the additional parameter. + * + *

For constructs introduced in later versions, {@code visitUnknown} + * is called instead which throws {@link UnknownTreeException}. + * + *

Methods in this class may be overridden subject to their + * general contract. Note that annotating methods in concrete + * subclasses with {@link java.lang.Override @Override} will help + * ensure that methods are overridden as intended. + * + * @param the return type of this visitor's methods. Use {@link + * Void} for visitors that do not need to return results. + * @param

the type of the additional parameter to this visitor's + * methods. Use {@code Void} for visitors that do not need an + * additional parameter. + */ +public class SimpleTreeVisitorES5_1 implements TreeVisitor { + @Override + public R visitAssignment(AssignmentTree node, P r) { + node.getVariable().accept(this, r); + node.getExpression().accept(this, r); + return null; + } + + @Override + public R visitCompoundAssignment(CompoundAssignmentTree node, P r) { + node.getVariable().accept(this, r); + node.getExpression().accept(this, r); + return null; + } + + @Override + public R visitBinary(BinaryTree node, P r) { + node.getLeftOperand().accept(this, r); + node.getRightOperand().accept(this, r); + return null; + } + + @Override + public R visitBlock(BlockTree node, P r) { + node.getStatements().forEach((tree) -> { + tree.accept(this, r); + }); + return null; + } + + @Override + public R visitBreak(BreakTree node, P r) { + return null; + } + + @Override + public R visitCase(CaseTree node, P r) { + final Tree caseVal = node.getExpression(); + if (caseVal != null) { + caseVal.accept(this, r); + } + + node.getStatements().forEach((tree) -> { + tree.accept(this, r); + }); + return null; + } + + @Override + public R visitCatch(CatchTree node, P r) { + final Tree cond = node.getCondition(); + if (cond != null) { + cond.accept(this, r); + } + node.getParameter().accept(this, r); + node.getBlock().accept(this, r); + return null; + } + + @Override + public R visitConditionalExpression(ConditionalExpressionTree node, P r) { + node.getCondition().accept(this, r); + node.getTrueExpression().accept(this, r); + node.getFalseExpression().accept(this, r); + return null; + } + + @Override + public R visitContinue(ContinueTree node, P r) { + return null; + } + + @Override + public R visitDebugger(DebuggerTree node, P r) { + return null; + } + + @Override + public R visitDoWhileLoop(DoWhileLoopTree node, P r) { + node.getStatement().accept(this, r); + node.getCondition().accept(this, r); + return null; + } + + @Override + public R visitErroneous(ErroneousTree node, P r) { + return null; + } + + @Override + public R visitExpressionStatement(ExpressionStatementTree node, P r) { + node.getExpression().accept(this, r); + return null; + } + + @Override + public R visitForLoop(ForLoopTree node, P r) { + final Tree init = node.getInitializer(); + if (init != null) { + init.accept(this, r); + } + + final Tree cond = node.getCondition(); + if (cond != null) { + cond.accept(this, r); + } + + final Tree update = node.getUpdate(); + if (update != null) { + update.accept(this, r); + } + + node.getStatement().accept(this, r); + return null; + } + + @Override + public R visitForInLoop(ForInLoopTree node, P r) { + node.getVariable().accept(this, r); + node.getExpression().accept(this, r); + final StatementTree stat = node.getStatement(); + if (stat != null) { + stat.accept(this, r); + } + return null; + } + + @Override + public R visitFunctionCall(FunctionCallTree node, P r) { + node.getFunctionSelect().accept(this, r); + node.getArguments().forEach((tree) -> { + tree.accept(this, r); + }); + return null; + } + + @Override + public R visitFunctionDeclaration(FunctionDeclarationTree node, P r) { + node.getParameters().forEach((tree) -> { + tree.accept(this, r); + }); + node.getBody().accept(this, r); + return null; + } + + @Override + public R visitFunctionExpression(FunctionExpressionTree node, P r) { + node.getParameters().forEach((tree) -> { + tree.accept(this, r); + }); + node.getBody().accept(this, r); + return null; + } + + @Override + public R visitIdentifier(IdentifierTree node, P r) { + return null; + } + + @Override + public R visitIf(IfTree node, P r) { + node.getCondition().accept(this, r); + node.getThenStatement().accept(this, r); + final Tree elseStat = node.getElseStatement(); + if (elseStat != null) { + elseStat.accept(this, r); + } + return null; + } + + @Override + public R visitArrayAccess(ArrayAccessTree node, P r) { + node.getExpression().accept(this, r); + node.getIndex().accept(this, r); + return null; + } + + @Override + public R visitArrayLiteral(ArrayLiteralTree node, P r) { + node.getElements().stream().filter((tree) -> (tree != null)).forEach((tree) -> { + tree.accept(this, r); + }); + return null; + } + + @Override + public R visitLabeledStatement(LabeledStatementTree node, P r) { + node.getStatement().accept(this, r); + return null; + } + + @Override + public R visitLiteral(LiteralTree node, P r) { + return null; + } + + @Override + public R visitParenthesized(ParenthesizedTree node, P r) { + node.getExpression().accept(this, r); + return null; + } + + @Override + public R visitReturn(ReturnTree node, P r) { + final Tree retExpr = node.getExpression(); + if (retExpr != null) { + retExpr.accept(this, r); + } + return null; + } + + @Override + public R visitMemberSelect(MemberSelectTree node, P r) { + node.getExpression().accept(this, r); + return null; + } + + @Override + public R visitNew(NewTree node, P r) { + node.getConstructorExpression().accept(this, r); + return null; + } + + @Override + public R visitObjectLiteral(ObjectLiteralTree node, P r) { + node.getProperties().forEach((tree) -> { + tree.accept(this, r); + }); + return null; + } + + @Override + public R visitProperty(PropertyTree node, P r) { + FunctionExpressionTree getter = node.getGetter(); + if (getter != null) { + getter.accept(this, r); + } + ExpressionTree key = node.getKey(); + if (key != null) { + key.accept(this, r); + } + + FunctionExpressionTree setter = node.getSetter(); + if (setter != null) { + setter.accept(this, r); + } + + ExpressionTree value = node.getValue(); + if (value != null) { + value.accept(this, r); + } + return null; + } + + @Override + public R visitRegExpLiteral(RegExpLiteralTree node, P r) { + return null; + } + + @Override + public R visitEmptyStatement(EmptyStatementTree node, P r) { + return null; + } + + @Override + public R visitSwitch(SwitchTree node, P r) { + node.getExpression().accept(this, r); + node.getCases().forEach((tree) -> { + tree.accept(this, r); + }); + return null; + } + + @Override + public R visitThrow(ThrowTree node, P r) { + node.getExpression().accept(this, r); + return null; + } + + @Override + public R visitCompilationUnit(CompilationUnitTree node, P r) { + node.getSourceElements().forEach((tree) -> { + tree.accept(this, r); + }); + return null; + } + + @Override + public R visitTry(TryTree node, P r) { + node.getBlock().accept(this, r); + node.getCatches().forEach((tree) -> { + tree.accept(this, r); + }); + + final Tree finallyBlock = node.getFinallyBlock(); + if (finallyBlock != null) { + finallyBlock.accept(this, r); + } + return null; + } + + @Override + public R visitInstanceOf(InstanceOfTree node, P r) { + node.getType().accept(this, r); + node.getExpression().accept(this, r); + return null; + } + + @Override + public R visitUnary(UnaryTree node, P r) { + node.getExpression().accept(this, r); + return null; + } + + @Override + public R visitVariable(VariableTree node, P r) { + if (node.getInitializer() != null) { + node.getInitializer().accept(this, r); + } + return null; + } + + @Override + public R visitWhileLoop(WhileLoopTree node, P r) { + node.getCondition().accept(this, r); + node.getStatement().accept(this, r); + return null; + } + + @Override + public R visitWith(WithTree node, P r) { + node.getScope().accept(this, r); + node.getStatement().accept(this, r); + return null; + } + + @Override + public R visitUnknown(Tree node, P r) { + // unknown in ECMAScript 5.1 edition + throw new UnknownTreeException(node, r); + } +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/StatementTree.java 2015-03-09 18:39:32.299843194 +0530 @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +/** + * A tree node used as the base class for the different kinds of + * statements. + * + * @since 1.9 + */ +@jdk.Exported +public interface StatementTree extends Tree { +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/StatementTreeImpl.java 2015-03-09 18:39:32.591844653 +0530 @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +import jdk.nashorn.internal.ir.Block; +import jdk.nashorn.internal.ir.Statement; + +abstract class StatementTreeImpl extends TreeImpl implements StatementTree { + StatementTreeImpl(final Statement stat) { + super(stat); + } + + StatementTreeImpl(final Block stat) { + super(stat); + } +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/SwitchTree.java 2015-03-09 18:39:32.891846150 +0530 @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +import java.util.List; + +/** + * A tree node for a 'switch' statement. + * + * For example: + *

+ *   switch ( expression ) {
+ *     cases
+ *   }
+ * 
+ * + * @since 1.9 + */ +@jdk.Exported +public interface SwitchTree extends StatementTree { + /** + * Returns the expression on which this statement switches. + * + * @return the switch expression + */ + ExpressionTree getExpression(); + + + /** + * Returns the list of 'case' statements. + * + * @return the 'case' statements + */ + List getCases(); +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/SwitchTreeImpl.java 2015-03-09 18:39:33.183847589 +0530 @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +import java.util.List; +import jdk.nashorn.internal.ir.SwitchNode; + +final class SwitchTreeImpl extends StatementTreeImpl implements SwitchTree { + private final ExpressionTree expr; + private final List cases; + SwitchTreeImpl(final SwitchNode node, + final ExpressionTree expr, + List cases) { + super(node); + this.expr = expr; + this.cases = cases; + } + + @Override + public Kind getKind() { + return Kind.SWITCH; + } + + @Override + public ExpressionTree getExpression() { + return expr; + } + + @Override + public List getCases() { + return cases; + } + + @Override + public R accept(TreeVisitor visitor, D data) { + return visitor.visitSwitch(this, data); + } +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/ThrowTree.java 2015-03-09 18:39:33.479849052 +0530 @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +/** + * A tree node for a 'throw' statement. + * + * For example: + *
+ *   throw expression;
+ * 
+ * + * @since 1.9 + */ +@jdk.Exported +public interface ThrowTree extends StatementTree { + /** + * Returns the expression being thrown. + * + * @return the expression being thrown. + */ + ExpressionTree getExpression(); +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/ThrowTreeImpl.java 2015-03-09 18:39:33.779850545 +0530 @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +import jdk.nashorn.internal.ir.ThrowNode; + +final class ThrowTreeImpl extends StatementTreeImpl implements ThrowTree { + private final ExpressionTree expr; + ThrowTreeImpl(final ThrowNode node, final ExpressionTree expr) { + super(node); + this.expr = expr; + } + + @Override + public Kind getKind() { + return Kind.THROW; + } + + @Override + public ExpressionTree getExpression() { + return expr; + } + + @Override + public R accept(TreeVisitor visitor, D data) { + return visitor.visitThrow(this, data); + } +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/Tree.java 2015-03-09 18:39:34.079852012 +0530 @@ -0,0 +1,599 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +/** + * Common interface for all nodes in an abstract syntax tree. + * + *

WARNING: This interface and its sub-interfaces are + * subject to change as the ECMAScript programming language evolves. + * + * @since 1.9 + */ +@jdk.Exported +public interface Tree { + + /** + * Enumerates all kinds of trees. + */ + @jdk.Exported + public enum Kind { + /** + * Used for instances of {@link ArrayAccessTree}. + */ + ARRAY_ACCESS(ArrayAccessTree.class), + + /** + * Used for instances of {@link ArrayLiteralTree}. + */ + ARRAY_LITERAL(ArrayLiteralTree.class), + + /** + * Used for instances of {@link AssignmentTree}. + */ + ASSIGNMENT(AssignmentTree.class), + + /** + * Used for instances of {@link BlockTree}. + */ + BLOCK(BlockTree.class), + + /** + * Used for instances of {@link BreakTree}. + */ + BREAK(BreakTree.class), + + /** + * Used for instances of {@link CaseTree}. + */ + CASE(CaseTree.class), + + /** + * Used for instances of {@link CatchTree}. + */ + CATCH(CatchTree.class), + + /** + * Used for instances of {@link CompilationUnitTree}. + */ + COMPILATION_UNIT(CompilationUnitTree.class), + + /** + * Used for instances of {@link ConditionalExpressionTree}. + */ + CONDITIONAL_EXPRESSION(ConditionalExpressionTree.class), + + /** + * Used for instances of {@link ContinueTree}. + */ + CONTINUE(ContinueTree.class), + + /** + * Used for instances of {@link DoWhileLoopTree}. + */ + DO_WHILE_LOOP(DoWhileLoopTree.class), + + /** + * Used for instances of {@link DebuggerTree}. + */ + DEBUGGER(DebuggerTree.class), + + /** + * Used for instances of {@link ForInLoopTree}. + */ + FOR_IN_LOOP(ForInLoopTree.class), + + /** + * Used for instances of {@link FunctionExpressionTree}. + */ + FUNCTION_EXPRESSION(FunctionExpressionTree.class), + + /** + * Used for instances of {@link ErroneousTree}. + */ + ERROR(ErroneousTree.class), + + /** + * Used for instances of {@link ExpressionStatementTree}. + */ + EXPRESSION_STATEMENT(ExpressionStatementTree.class), + + /** + * Used for instances of {@link MemberSelectTree}. + */ + MEMBER_SELECT(MemberSelectTree.class), + + /** + * Used for instances of {@link ForLoopTree}. + */ + FOR_LOOP(ForLoopTree.class), + + /** + * Used for instances of {@link IdentifierTree}. + */ + IDENTIFIER(IdentifierTree.class), + + /** + * Used for instances of {@link IfTree}. + */ + IF(IfTree.class), + + /** + * Used for instances of {@link InstanceOfTree}. + */ + INSTANCE_OF(InstanceOfTree.class), + + /** + * Used for instances of {@link LabeledStatementTree}. + */ + LABELED_STATEMENT(LabeledStatementTree.class), + + /** + * Used for instances of {@link FunctionDeclarationTree}. + */ + FUNCTION(FunctionDeclarationTree.class), + + /** + * Used for instances of {@link FunctionCallTree}. + */ + FUNCTION_INVOCATION(FunctionCallTree.class), + + /** + * Used for instances of {@link NewTree}. + */ + NEW(NewTree.class), + + /** + * Used for instances of {@link ObjectLiteralTree}. + */ + OBJECT_LITERAL(ObjectLiteralTree.class), + + /** + * Used for instances of {@link ParenthesizedTree}. + */ + PARENTHESIZED(ParenthesizedTree.class), + + /** + * Used for instances of {@link PropertyTree}. + */ + PROPERTY(PropertyTree.class), + + /** + * Used for instances of {@link RegExpLiteralTree}. + */ + REGEXP_LITERAL(RegExpLiteralTree.class), + + /** + * Used for instances of {@link ReturnTree}. + */ + RETURN(ReturnTree.class), + + /** + * Used for instances of {@link EmptyStatementTree}. + */ + EMPTY_STATEMENT(EmptyStatementTree.class), + + /** + * Used for instances of {@link SwitchTree}. + */ + SWITCH(SwitchTree.class), + + /** + * Used for instances of {@link ThrowTree}. + */ + THROW(ThrowTree.class), + + /** + * Used for instances of {@link TryTree}. + */ + TRY(TryTree.class), + + /** + * Used for instances of {@link VariableTree}. + */ + VARIABLE(VariableTree.class), + + /** + * Used for instances of {@link WhileLoopTree}. + */ + WHILE_LOOP(WhileLoopTree.class), + + /** + * Used for instances of {@link WithTree}. + */ + WITH(WithTree.class), + + /** + * Used for instances of {@link UnaryTree} representing postfix + * increment operator {@code ++}. + */ + POSTFIX_INCREMENT(UnaryTree.class), + + /** + * Used for instances of {@link UnaryTree} representing postfix + * decrement operator {@code --}. + */ + POSTFIX_DECREMENT(UnaryTree.class), + + /** + * Used for instances of {@link UnaryTree} representing prefix + * increment operator {@code ++}. + */ + PREFIX_INCREMENT(UnaryTree.class), + + /** + * Used for instances of {@link UnaryTree} representing prefix + * decrement operator {@code --}. + */ + PREFIX_DECREMENT(UnaryTree.class), + + /** + * Used for instances of {@link UnaryTree} representing unary plus + * operator {@code +}. + */ + UNARY_PLUS(UnaryTree.class), + + /** + * Used for instances of {@link UnaryTree} representing unary minus + * operator {@code -}. + */ + UNARY_MINUS(UnaryTree.class), + + /** + * Used for instances of {@link UnaryTree} representing bitwise + * complement operator {@code ~}. + */ + BITWISE_COMPLEMENT(UnaryTree.class), + + /** + * Used for instances of {@link UnaryTree} representing logical + * complement operator {@code !}. + */ + LOGICAL_COMPLEMENT(UnaryTree.class), + + /** + * Used for instances of {@link UnaryTree} representing logical + * delete operator {@code delete}. + */ + DELETE(UnaryTree.class), + + /** + * Used for instances of {@link UnaryTree} representing logical + * typeof operator {@code typeof}. + */ + TYPEOF(UnaryTree.class), + + /** + * Used for instances of {@link UnaryTree} representing logical + * void operator {@code typeof}. + */ + VOID(UnaryTree.class), + + /** + * Used for instances of {@link BinaryTree} representing + * comma {@code ,}. + */ + COMMA(BinaryTree.class), + + /** + * Used for instances of {@link BinaryTree} representing + * multiplication {@code *}. + */ + MULTIPLY(BinaryTree.class), + + /** + * Used for instances of {@link BinaryTree} representing + * division {@code /}. + */ + DIVIDE(BinaryTree.class), + + /** + * Used for instances of {@link BinaryTree} representing + * remainder {@code %}. + */ + REMAINDER(BinaryTree.class), + + /** + * Used for instances of {@link BinaryTree} representing + * addition or string concatenation {@code +}. + */ + PLUS(BinaryTree.class), + + /** + * Used for instances of {@link BinaryTree} representing + * subtraction {@code -}. + */ + MINUS(BinaryTree.class), + + /** + * Used for instances of {@link BinaryTree} representing + * left shift {@code <<}. + */ + LEFT_SHIFT(BinaryTree.class), + + /** + * Used for instances of {@link BinaryTree} representing + * right shift {@code >>}. + */ + RIGHT_SHIFT(BinaryTree.class), + + /** + * Used for instances of {@link BinaryTree} representing + * unsigned right shift {@code >>>}. + */ + UNSIGNED_RIGHT_SHIFT(BinaryTree.class), + + /** + * Used for instances of {@link BinaryTree} representing + * less-than {@code <}. + */ + LESS_THAN(BinaryTree.class), + + /** + * Used for instances of {@link BinaryTree} representing + * greater-than {@code >}. + */ + GREATER_THAN(BinaryTree.class), + + /** + * Used for instances of {@link BinaryTree} representing + * less-than-equal {@code <=}. + */ + LESS_THAN_EQUAL(BinaryTree.class), + + /** + * Used for instances of {@link BinaryTree} representing + * greater-than-equal {@code >=}. + */ + GREATER_THAN_EQUAL(BinaryTree.class), + + /** + * Used for instances of {@link BinaryTree} representing + * in operator {@code in}. + */ + IN(BinaryTree.class), + + /** + * Used for instances of {@link BinaryTree} representing + * equal-to {@code ==}. + */ + EQUAL_TO(BinaryTree.class), + + /** + * Used for instances of {@link BinaryTree} representing + * not-equal-to {@code !=}. + */ + NOT_EQUAL_TO(BinaryTree.class), + + /** + * Used for instances of {@link BinaryTree} representing + * equal-to {@code ===}. + */ + STRICT_EQUAL_TO(BinaryTree.class), + + /** + * Used for instances of {@link BinaryTree} representing + * not-equal-to {@code !==}. + */ + STRICT_NOT_EQUAL_TO(BinaryTree.class), + + /** + * Used for instances of {@link BinaryTree} representing + * bitwise and logical "and" {@code &}. + */ + AND(BinaryTree.class), + + /** + * Used for instances of {@link BinaryTree} representing + * bitwise and logical "xor" {@code ^}. + */ + XOR(BinaryTree.class), + + /** + * Used for instances of {@link BinaryTree} representing + * bitwise and logical "or" {@code |}. + */ + OR(BinaryTree.class), + + /** + * Used for instances of {@link BinaryTree} representing + * conditional-and {@code &&}. + */ + CONDITIONAL_AND(BinaryTree.class), + + /** + * Used for instances of {@link BinaryTree} representing + * conditional-or {@code ||}. + */ + CONDITIONAL_OR(BinaryTree.class), + + /** + * Used for instances of {@link CompoundAssignmentTree} representing + * multiplication assignment {@code *=}. + */ + MULTIPLY_ASSIGNMENT(CompoundAssignmentTree.class), + + /** + * Used for instances of {@link CompoundAssignmentTree} representing + * division assignment {@code /=}. + */ + DIVIDE_ASSIGNMENT(CompoundAssignmentTree.class), + + /** + * Used for instances of {@link CompoundAssignmentTree} representing + * remainder assignment {@code %=}. + */ + REMAINDER_ASSIGNMENT(CompoundAssignmentTree.class), + + /** + * Used for instances of {@link CompoundAssignmentTree} representing + * addition or string concatenation assignment {@code +=}. + */ + PLUS_ASSIGNMENT(CompoundAssignmentTree.class), + + /** + * Used for instances of {@link CompoundAssignmentTree} representing + * subtraction assignment {@code -=}. + */ + MINUS_ASSIGNMENT(CompoundAssignmentTree.class), + + /** + * Used for instances of {@link CompoundAssignmentTree} representing + * left shift assignment {@code <<=}. + */ + LEFT_SHIFT_ASSIGNMENT(CompoundAssignmentTree.class), + + /** + * Used for instances of {@link CompoundAssignmentTree} representing + * right shift assignment {@code >>=}. + */ + RIGHT_SHIFT_ASSIGNMENT(CompoundAssignmentTree.class), + + /** + * Used for instances of {@link CompoundAssignmentTree} representing + * unsigned right shift assignment {@code >>>=}. + */ + UNSIGNED_RIGHT_SHIFT_ASSIGNMENT(CompoundAssignmentTree.class), + + /** + * Used for instances of {@link CompoundAssignmentTree} representing + * bitwise and logical "and" assignment {@code &=}. + */ + AND_ASSIGNMENT(CompoundAssignmentTree.class), + + /** + * Used for instances of {@link CompoundAssignmentTree} representing + * bitwise and logical "xor" assignment {@code ^=}. + */ + XOR_ASSIGNMENT(CompoundAssignmentTree.class), + + /** + * Used for instances of {@link CompoundAssignmentTree} representing + * bitwise and logical "or" assignment {@code |=}. + */ + OR_ASSIGNMENT(CompoundAssignmentTree.class), + + /** + * Used for instances of {@link LiteralTree} representing + * a number literal expression of type {@code double}. + */ + NUMBER_LITERAL(LiteralTree.class), + + /** + * Used for instances of {@link LiteralTree} representing + * a boolean literal expression of type {@code boolean}. + */ + BOOLEAN_LITERAL(LiteralTree.class), + + /** + * Used for instances of {@link LiteralTree} representing + * a string literal expression of type {@link String}. + */ + STRING_LITERAL(LiteralTree.class), + + /** + * Used for instances of {@link LiteralTree} representing + * the use of {@code null}. + */ + NULL_LITERAL(LiteralTree.class), + + /** + * An implementation-reserved node. This is the not the node + * you are looking for. + */ + OTHER(null); + + Kind(Class intf) { + associatedInterface = intf; + } + + public Class asInterface() { + return associatedInterface; + } + + /** + * Returns if this is a literal tree kind or not. + * + * @return true if this is a literal tree kind, false otherwise + */ + public boolean isLiteral() { + return associatedInterface == LiteralTree.class; + } + + /** + * Returns if this is an expression tree kind or not. + * + * @return true if this is an expression tree kind, false otherwise + */ + public boolean isExpression() { + return ExpressionTree.class.isAssignableFrom(associatedInterface); + } + + /** + * Returns if this is a statement tree kind or not. + * + * @return true if this is a statement tree kind, false otherwise + */ + public boolean isStatement() { + return StatementTree.class.isAssignableFrom(associatedInterface); + } + + private final Class associatedInterface; + } + + /** + * Start character offset of this Tree within the source. + * + * @return the position + */ + long getStartPosition(); + + /** + * End character offset of this Tree within the source. + * + * @return the position + */ + long getEndPosition(); + + /** + * Gets the kind of this tree. + * + * @return the kind of this tree. + */ + Kind getKind(); + + /** + * Accept method used to implement the visitor pattern. The + * visitor pattern is used to implement operations on trees. + * + * @param result type of this operation. + * @param type of additional data. + * @param visitor tree visitor + * @param data additional data passed to visitor methods + * @return the value from visitor's visit methods + */ + R accept(TreeVisitor visitor, D data); +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/TreeImpl.java 2015-03-09 18:39:34.379853515 +0530 @@ -0,0 +1,154 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +import jdk.nashorn.internal.ir.Node; + +import jdk.nashorn.internal.parser.TokenType; + +abstract class TreeImpl implements Tree { + protected final Node node; + + TreeImpl(final Node node) { + this.node = node; + } + + @Override + public long getStartPosition() { + return node.getStart(); + } + + @Override + public long getEndPosition() { + return node.getFinish(); + } + + @Override + public R accept(TreeVisitor visitor, D data) { + return visitor.visitUnknown(this, data); + } + + static Kind getOperator(final TokenType tt) { + switch(tt) { + case NEW: + return Kind.NEW; + case NOT: + return Kind.LOGICAL_COMPLEMENT; + case NE: + return Kind.NOT_EQUAL_TO; + case NE_STRICT: + return Kind.STRICT_NOT_EQUAL_TO; + case MOD: + return Kind.REMAINDER; + case ASSIGN_MOD: + return Kind.REMAINDER_ASSIGNMENT; + case BIT_AND: + return Kind.AND; + case AND: + return Kind.CONDITIONAL_AND; + case ASSIGN_BIT_AND: + return Kind.AND_ASSIGNMENT; + case MUL: + return Kind.MULTIPLY; + case ASSIGN_MUL: + return Kind.MULTIPLY_ASSIGNMENT; + case ADD: + return Kind.PLUS; + case INCPREFIX: + return Kind.PREFIX_INCREMENT; + case INCPOSTFIX: + return Kind.POSTFIX_INCREMENT; + case ASSIGN_ADD: + return Kind.PLUS_ASSIGNMENT; + case SUB: + return Kind.MINUS; + case DECPREFIX: + return Kind.PREFIX_DECREMENT; + case DECPOSTFIX: + return Kind.POSTFIX_DECREMENT; + case ASSIGN_SUB: + return Kind.MINUS_ASSIGNMENT; + case DIV: + return Kind.DIVIDE; + case ASSIGN_DIV: + return Kind.DIVIDE_ASSIGNMENT; + case LT: + return Kind.LESS_THAN; + case SHL: + return Kind.LEFT_SHIFT; + case ASSIGN_SHL: + return Kind.LEFT_SHIFT_ASSIGNMENT; + case LE: + return Kind.LESS_THAN_EQUAL; + case ASSIGN: + return Kind.ASSIGNMENT; + case EQ: + return Kind.EQUAL_TO; + case EQ_STRICT: + return Kind.STRICT_EQUAL_TO; + case GT: + return Kind.GREATER_THAN; + case GE: + return Kind.GREATER_THAN_EQUAL; + case SAR: + return Kind.RIGHT_SHIFT; + case ASSIGN_SAR: + return Kind.RIGHT_SHIFT_ASSIGNMENT; + case SHR: + return Kind.UNSIGNED_RIGHT_SHIFT; + case ASSIGN_SHR: + return Kind.UNSIGNED_RIGHT_SHIFT_ASSIGNMENT; + case TERNARY: + return Kind.CONDITIONAL_EXPRESSION; + case BIT_XOR: + return Kind.XOR; + case ASSIGN_BIT_XOR: + return Kind.XOR_ASSIGNMENT; + case BIT_OR: + return Kind.OR; + case ASSIGN_BIT_OR: + return Kind.OR_ASSIGNMENT; + case OR: + return Kind.CONDITIONAL_OR; + case BIT_NOT: + return Kind.BITWISE_COMPLEMENT; + case DELETE: + return Kind.DELETE; + case TYPEOF: + return Kind.TYPEOF; + case VOID: + return Kind.VOID; + case IN: + return Kind.IN; + case INSTANCEOF: + return Kind.INSTANCE_OF; + case COMMARIGHT: + return Kind.COMMA; + default: + throw new AssertionError("should not reach here: " + tt); + } + } +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/TreeVisitor.java 2015-03-09 18:39:34.691855058 +0530 @@ -0,0 +1,438 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +/** + * A visitor of trees, in the style of the visitor design pattern. + * Classes implementing this interface are used to operate + * on a tree when the kind of tree is unknown at compile time. + * When a visitor is passed to an tree's {@link Tree#accept + * accept} method, the visitXYZ method most applicable + * to that tree is invoked. + * + *

Classes implementing this interface may or may not throw a + * {@code NullPointerException} if the additional parameter {@code p} + * is {@code null}; see documentation of the implementing class for + * details. + * + *

WARNING: It is possible that methods will be added to + this interface to accommodate new, currently unknown, language + structures added to future versions of the ECMAScript programming + language. When new visit methods are added for new Tree subtypes, + default method bodies will be introduced which will call visitUnknown + method as a fallback. + * + * @param the return type of this visitor's methods. Use {@link + * Void} for visitors that do not need to return results. + * @param

the type of the additional parameter to this visitor's + * methods. Use {@code Void} for visitors that do not need an + * additional parameter. + * + * @since 1.9 + */ +@jdk.Exported +public interface TreeVisitor { + /** + * Visit assignment tree. + * + * @param node node being visited + * @param p extra parameter passed to the visitor + * @return value from the visitor + */ + R visitAssignment(AssignmentTree node, P p); + + /** + * Visit compound assignment tree. + * + * @param node node being visited + * @param p extra parameter passed to the visitor + * @return value from the visitor + */ + R visitCompoundAssignment(CompoundAssignmentTree node, P p); + + /** + * Visit binary expression tree. + * + * @param node node being visited + * @param p extra parameter passed to the visitor + * @return value from the visitor + */ + R visitBinary(BinaryTree node, P p); + + /** + * Visit block statement tree. + * + * @param node node being visited + * @param p extra parameter passed to the visitor + * @return value from the visitor + */ + R visitBlock(BlockTree node, P p); + + /** + * Visit break statement tree. + * + * @param node node being visited + * @param p extra parameter passed to the visitor + * @return value from the visitor + */ + R visitBreak(BreakTree node, P p); + + /** + * Visit case statement tree. + * + * @param node node being visited + * @param p extra parameter passed to the visitor + * @return value from the visitor + */ + R visitCase(CaseTree node, P p); + + /** + * Visit catch block statement tree. + * + * @param node node being visited + * @param p extra parameter passed to the visitor + * @return value from the visitor + */ + R visitCatch(CatchTree node, P p); + + /** + * Visit conditional expression tree. + * + * @param node node being visited + * @param p extra parameter passed to the visitor + * @return value from the visitor + */ + R visitConditionalExpression(ConditionalExpressionTree node, P p); + + /** + * Visit continue statement tree. + * + * @param node node being visited + * @param p extra parameter passed to the visitor + * @return value from the visitor + */ + R visitContinue(ContinueTree node, P p); + + /** + * Visit debugger statement tree. + * + * @param node node being visited + * @param p extra parameter passed to the visitor + * @return value from the visitor + */ + R visitDebugger(DebuggerTree node, P p); + + /** + * Visit do-while statement tree. + * + * @param node node being visited + * @param p extra parameter passed to the visitor + * @return value from the visitor + */ + R visitDoWhileLoop(DoWhileLoopTree node, P p); + + /** + * Visit error expression tree. + * + * @param node node being visited + * @param p extra parameter passed to the visitor + * @return value from the visitor + */ + R visitErroneous(ErroneousTree node, P p); + + /** + * Visit expression statement tree. + * + * @param node node being visited + * @param p extra parameter passed to the visitor + * @return value from the visitor + */ + R visitExpressionStatement(ExpressionStatementTree node, P p); + + /** + * Visit 'for' statement tree. + * + * @param node node being visited + * @param p extra parameter passed to the visitor + * @return value from the visitor + */ + R visitForLoop(ForLoopTree node, P p); + + /** + * Visit for..in statement tree. + * + * @param node node being visited + * @param p extra parameter passed to the visitor + * @return value from the visitor + */ + R visitForInLoop(ForInLoopTree node, P p); + + /** + * Visit function call expression tree. + * + * @param node node being visited + * @param p extra parameter passed to the visitor + * @return value from the visitor + */ + R visitFunctionCall(FunctionCallTree node, P p); + + /** + * Visit function declaration tree. + * + * @param node node being visited + * @param p extra parameter passed to the visitor + * @return value from the visitor + */ + R visitFunctionDeclaration(FunctionDeclarationTree node, P p); + + /** + * Visit function expression tree. + * + * @param node node being visited + * @param p extra parameter passed to the visitor + * @return value from the visitor + */ + R visitFunctionExpression(FunctionExpressionTree node, P p); + + /** + * Visit identifier tree. + * + * @param node node being visited + * @param p extra parameter passed to the visitor + * @return value from the visitor + */ + R visitIdentifier(IdentifierTree node, P p); + + /** + * Visit 'if' statement tree. + * + * @param node node being visited + * @param p extra parameter passed to the visitor + * @return value from the visitor + */ + R visitIf(IfTree node, P p); + + /** + * Visit array access expression tree. + * + * @param node node being visited + * @param p extra parameter passed to the visitor + * @return value from the visitor + */ + R visitArrayAccess(ArrayAccessTree node, P p); + + /** + * Visit array literal expression tree. + * + * @param node node being visited + * @param p extra parameter passed to the visitor + * @return value from the visitor + */ + R visitArrayLiteral(ArrayLiteralTree node, P p); + + /** + * Visit labeled statement tree. + * + * @param node node being visited + * @param p extra parameter passed to the visitor + * @return value from the visitor + */ + R visitLabeledStatement(LabeledStatementTree node, P p); + + /** + * Visit literal expression tree. + * + * @param node node being visited + * @param p extra parameter passed to the visitor + * @return value from the visitor + */ + R visitLiteral(LiteralTree node, P p); + + /** + * Visit parenthesized expression tree. + * + * @param node node being visited + * @param p extra parameter passed to the visitor + * @return value from the visitor + */ + R visitParenthesized(ParenthesizedTree node, P p); + + /** + * Visit return statement tree. + * + * @param node node being visited + * @param p extra parameter passed to the visitor + * @return value from the visitor + */ + R visitReturn(ReturnTree node, P p); + + /** + * Visit member select expression tree. + * + * @param node node being visited + * @param p extra parameter passed to the visitor + * @return value from the visitor + */ + R visitMemberSelect(MemberSelectTree node, P p); + + /** + * Visit 'new' expression tree. + * + * @param node node being visited + * @param p extra parameter passed to the visitor + * @return value from the visitor + */ + R visitNew(NewTree node, P p); + + /** + * Visit object literal tree. + * + * @param node node being visited + * @param p extra parameter passed to the visitor + * @return value from the visitor + */ + R visitObjectLiteral(ObjectLiteralTree node, P p); + + /** + * Visit a property of an object literal expression tree. + * + * @param node node being visited + * @param p extra parameter passed to the visitor + * @return value from the visitor + */ + R visitProperty(PropertyTree node, P p); + + /** + * Visit regular expression literal tree. + * + * @param node node being visited + * @param p extra parameter passed to the visitor + * @return value from the visitor + */ + R visitRegExpLiteral(RegExpLiteralTree node, P p); + + /** + * Visit an empty statement tree. + * + * @param node node being visited + * @param p extra parameter passed to the visitor + * @return value from the visitor + */ + R visitEmptyStatement(EmptyStatementTree node, P p); + + /** + * Visit 'switch' statement tree. + * + * @param node node being visited + * @param p extra parameter passed to the visitor + * @return value from the visitor + */ + R visitSwitch(SwitchTree node, P p); + + /** + * Visit 'throw' expression tree. + * + * @param node node being visited + * @param p extra parameter passed to the visitor + * @return value from the visitor + */ + R visitThrow(ThrowTree node, P p); + + /** + * Visit compilation unit tree. + * + * @param node node being visited + * @param p extra parameter passed to the visitor + * @return value from the visitor + */ + R visitCompilationUnit(CompilationUnitTree node, P p); + + /** + * Visit 'try' statement tree. + * + * @param node node being visited + * @param p extra parameter passed to the visitor + * @return value from the visitor + */ + R visitTry(TryTree node, P p); + + /** + * Visit 'instanceof' expression tree. + * + * @param node node being visited + * @param p extra parameter passed to the visitor + * @return value from the visitor + */ + R visitInstanceOf(InstanceOfTree node, P p); + + /** + * Visit unary expression tree. + * + * @param node node being visited + * @param p extra parameter passed to the visitor + * @return value from the visitor + */ + R visitUnary(UnaryTree node, P p); + + /** + * Visit variable declaration tree. + * + * @param node node being visited + * @param p extra parameter passed to the visitor + * @return value from the visitor + */ + R visitVariable(VariableTree node, P p); + + /** + * Visit 'while' statement tree. + * + * @param node node being visited + * @param p extra parameter passed to the visitor + * @return value from the visitor + */ + R visitWhileLoop(WhileLoopTree node, P p); + + /** + * Visit 'with' statement tree. + * + * @param node node being visited + * @param p extra parameter passed to the visitor + * @return value from the visitor + */ + R visitWith(WithTree node, P p); + + /** + * Visit unknown expression/statement tree. This fallback will be + * called if new Tree subtypes are introduced in future. A specific + * implementation may throw {{@linkplain UnknownTreeException unknown tree exception} + * if the visitor implementation was for an older language version. + * + * @param node node being visited + * @param p extra parameter passed to the visitor + * @return value from the visitor + */ + R visitUnknown(Tree node, P p); +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/TryTree.java 2015-03-09 18:39:35.239857780 +0530 @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +import java.util.List; + +/** + * A tree node for a 'try' statement. + * + * For example: + *

+ *   try
+ *       block
+ *   catches
+ *   finally
+ *       finallyBlock
+ * 
+ * + * @since 1.9 + */ +@jdk.Exported +public interface TryTree extends StatementTree { + /** + * Returns the 'try' block of this 'try' statement. + * + * @return the 'try' block + */ + BlockTree getBlock(); + + /** + * Returns the list of 'catch' statements associated with this 'try'. + * + * @return the list of 'catch' statements associated with this 'try'. + */ + List getCatches(); + + /** + * Returns the 'finally' block associated with this 'try'. This is + * null if there is no 'finally' block associated with this 'try'. + * + * @return the 'finally' block associated with this 'try'. + */ + BlockTree getFinallyBlock(); +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/TryTreeImpl.java 2015-03-09 18:39:35.759860359 +0530 @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +import java.util.List; +import jdk.nashorn.internal.ir.TryNode; + +final class TryTreeImpl extends StatementTreeImpl implements TryTree { + private final BlockTree block; + private final List catches; + private final BlockTree finallyBlock; + TryTreeImpl(final TryNode node, + final BlockTree block, + final List catches, + final BlockTree finallyBlock) { + super(node); + this.block = block; + this.catches = catches; + this.finallyBlock = finallyBlock; + } + + @Override + public Kind getKind() { + return Kind.TRY; + } + + @Override + public BlockTree getBlock() { + return block; + } + + @Override + public List getCatches() { + return catches; + } + + @Override + public BlockTree getFinallyBlock() { + return finallyBlock; + } + + @Override + public R accept(TreeVisitor visitor, D data) { + return visitor.visitTry(this, data); + } +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/UnaryTree.java 2015-03-09 18:39:36.427863680 +0530 @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +/** + * A tree node for postfix and unary expressions. + * Use {@link #getKind getKind} to determine the kind of operator. + * + * For example: + *
+ *   operator expression
+ *
+ *   expression operator
+ * 
+ * + * @since 1.9 + */ +@jdk.Exported +public interface UnaryTree extends ExpressionTree { + /** + * Returns the expression operated by the unary operator. + * + * @return The expression operated by the unary operator. + */ + ExpressionTree getExpression(); +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/UnaryTreeImpl.java 2015-03-09 18:39:36.947866263 +0530 @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +import jdk.nashorn.internal.ir.UnaryNode; + +class UnaryTreeImpl extends ExpressionTreeImpl implements UnaryTree { + private final ExpressionTree expr; + private final Kind kind; + UnaryTreeImpl(final UnaryNode node, final ExpressionTree expr) { + super(node); + this.expr = expr; + this.kind = getOperator(node.tokenType()); + } + + @Override + public Kind getKind() { + return kind; + } + + @Override + public ExpressionTree getExpression() { + return expr; + } + + @Override + public R accept(TreeVisitor visitor, D data) { + return visitor.visitUnary(this, data); + } +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/UnknownTreeException.java 2015-03-09 18:39:37.519869082 +0530 @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + + +/** + * Indicates that an unknown kind of Tree was encountered. This + * can occur if the language evolves and new kinds of Trees are + * added to the {@code Tree} hierarchy. May be thrown by a + * {@linkplain TreeVisitor tree visitor} to indicate that the + * visitor was created for a prior version of the language. + * + * @since 1.9 + */ +@jdk.Exported +public class UnknownTreeException extends RuntimeException { + + private static final long serialVersionUID = 1L; + + private transient final Tree tree; + private transient final Object parameter; + + /** + * Creates a new {@code UnknownTreeException}. The {@code p} + * parameter may be used to pass in an additional argument with + * information about the context in which the unknown element was + * encountered; for example, the visit methods of {@link + * TreeVisitor} may pass in their additional parameter. + * + * @param t the unknown tree, may be {@code null} + * @param p an additional parameter, may be {@code null} + */ + public UnknownTreeException(Tree t, Object p) { + super("Unknown tree: " + t); + this.tree = t; + this.parameter = p; + } + + /** + * Returns the unknown tree. + * The value may be unavailable if this exception has been + * serialized and then read back in. + * + * @return the unknown element, or {@code null} if unavailable + */ + public Tree getUnknownTree() { + return tree; + } + + /** + * Returns the additional argument. + * The value may be unavailable if this exception has been + * serialized and then read back in. + * + * @return the additional argument + */ + public Object getArgument() { + return parameter; + } +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/VariableTree.java 2015-03-09 18:39:38.071871825 +0530 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +/** + * A tree node for a variable declaration. + * + * For example: + *
+ *   var name initializer ;
+ * 
+ * + * @since 1.9 + */ +@jdk.Exported +public interface VariableTree extends StatementTree { + /** + * Returns the name of this variable. + * + * @return the name of this variable + */ + String getName(); + + /** + * Returns the initial value expression for this variable. This is + * null if no initial value for this variable. + * + * @return the initial value expression + */ + ExpressionTree getInitializer(); +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/VariableTreeImpl.java 2015-03-09 18:39:38.627874559 +0530 @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +import jdk.nashorn.internal.ir.VarNode; + +final class VariableTreeImpl extends StatementTreeImpl implements VariableTree { + private final String name; + private final ExpressionTree init; + + VariableTreeImpl(final VarNode node, final ExpressionTree init) { + super(node); + this.name = node.getName().getName(); + this.init = init; + } + + @Override + public Kind getKind() { + return Kind.VARIABLE; + } + + @Override + public String getName() { + return name; + } + + @Override + public ExpressionTree getInitializer() { + return init; + } + + @Override + public R accept(TreeVisitor visitor, D data) { + return visitor.visitVariable(this, data); + } +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/WhileLoopTree.java 2015-03-09 18:39:39.243877653 +0530 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +/** + * A tree node for a 'while' loop statement. + * + * For example: + *
+ *   while ( condition )
+ *     statement
+ * 
+ * + * @since 1.9 + */ +@jdk.Exported +public interface WhileLoopTree extends ConditionalLoopTree { + /** + * The condition expression of this 'while' statement. + * + * @return the condition expression + */ + ExpressionTree getCondition(); + + /** + * The statement contained in this 'while' statement. + * + * @return the statement contained + */ + StatementTree getStatement(); +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/WhileLoopTreeImpl.java 2015-03-09 18:39:39.791880369 +0530 @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +import jdk.nashorn.internal.ir.WhileNode; + +final class WhileLoopTreeImpl extends StatementTreeImpl implements WhileLoopTree { + private final ExpressionTree cond; + private final StatementTree stat; + + WhileLoopTreeImpl(final WhileNode node, final ExpressionTree cond, final StatementTree stat) { + super(node); + assert !node.isDoWhile() : "while expected"; + this.cond = cond; + this.stat = stat; + } + + @Override + public Tree.Kind getKind() { + return Tree.Kind.WHILE_LOOP; + } + + @Override + public ExpressionTree getCondition() { + return cond; + } + + @Override + public StatementTree getStatement() { + return stat; + } + + @Override + public R accept(TreeVisitor visitor, D data) { + return visitor.visitWhileLoop(this, data); + } +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/WithTree.java 2015-03-09 18:39:40.351883127 +0530 @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +/** + * A tree node for a 'with' statement. + * + * For example: + *
+ *   with ( scope )
+ *     statement
+ * 
+ * + * @since 1.9 + */ +@jdk.Exported +public interface WithTree extends StatementTree { + /** + * The scope object expression for this 'with' statement. + * + * @return the scope object + */ + ExpressionTree getScope(); + + /** + * The statement contained in this 'with' statement. + * + * @return the statement contained + */ + StatementTree getStatement(); +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/WithTreeImpl.java 2015-03-09 18:39:40.911885907 +0530 @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.api.tree; + +import jdk.nashorn.internal.ir.WithNode; + +final class WithTreeImpl extends StatementTreeImpl implements WithTree { + private final ExpressionTree scope; + private final StatementTree stat; + WithTreeImpl(final WithNode node, final ExpressionTree scope, + final StatementTree stat) { + super(node); + this.scope = scope; + this.stat = stat; + } + + @Override + public Kind getKind() { + return Kind.WITH; + } + + @Override + public ExpressionTree getScope() { + return scope; + } + + @Override + public StatementTree getStatement() { + return stat; + } + + @Override + public R accept(TreeVisitor visitor, D data) { + return visitor.visitWith(this, data); + } +} --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/api/tree/package-info.java 2015-03-09 18:39:41.451888569 +0530 @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + *

+ * Nashorn parser API provides interfaces to represent ECMAScript source code + * as abstract syntax trees (AST) and Parser to parse ECMAScript source scripts. + *

+ *

+ * Using parser API user can write Java code to access parse tree + * representation of ECMAScript source. Script source may be a file, + * a URL or a String. Unless stated otherwise null argument in methods of this + * package result in NullPointerException being thrown. + *

+ * + *
+ * 
+ * import jdk.nashorn.api.tree.*;
+ * import java.io.File;
+ *
+ * // Simple example that prints warning on 'with' statements
+ * public class Main {
+ *     public static void main(String[] args) throws Exception {
+ *         // Create a new parser instance
+ *         Parser parser = Parser.create();
+ *         File sourceFile = new File(args[0]);
+ *
+ *         // Parse given source File using parse method.
+ *         // Pass a diagnostic listener to print error messages.
+ *         CompilationUnitTree cut = parser.parse(sourceFile,
+ *             (d) -> { System.out.println(d); });
+ *
+ *         if (cut != null) {
+ *             // call Tree.accept method passing a SimpleTreeVisitor
+ *             cut.accept(new SimpleTreeVisitor<Void, Void>() {
+ *                 // visit method for 'with' statement
+ *                 public Void visitWith(WithTree wt, Void v) {
+ *                     // print warning on 'with' statement
+ *                     System.out.println("Warning: using 'with' statement!");
+ *                     return null;
+ *                 }
+ *             }, null);
+ *         }
+ *     }
+ * }
+ * 
+ * 
+ * + * @since 1.9 + */ +@jdk.Exported +package jdk.nashorn.api.tree; + --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/ir/DebuggerNode.java 2015-03-09 18:39:41.991891263 +0530 @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.internal.ir; + +import jdk.nashorn.internal.ir.annotations.Immutable; +import jdk.nashorn.internal.ir.visitor.NodeVisitor; + +/** + * IR representation for a debugger statement. + */ +@Immutable +public final class DebuggerNode extends Statement { + private static final long serialVersionUID = 1L; + + /** + * Constructor + * + * @param lineNumber line number + * @param token token + * @param finish finish + */ + public DebuggerNode(final int lineNumber, final long token, final int finish) { + super(lineNumber, token, finish); + } + + @Override + public Node accept(final NodeVisitor visitor) { + if (visitor.enterDebuggerNode(this)) { + return visitor.leaveDebuggerNode(this); + } + + return this; + } + + @Override + public void toString(final StringBuilder sb, final boolean printType) { + sb.append("debugger"); + } +} + --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/ir/ErrorNode.java 2015-03-09 18:39:42.587894219 +0530 @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package jdk.nashorn.internal.ir; + +import java.util.function.Function; +import jdk.nashorn.internal.codegen.types.Type; +import jdk.nashorn.internal.ir.annotations.Immutable; +import jdk.nashorn.internal.ir.visitor.NodeVisitor; + +/** + * IR representation for an error expression. + */ +@Immutable +public final class ErrorNode extends Expression { + private static final long serialVersionUID = 1L; + + /** + * Constructor + * + * @param token token + * @param finish finish + */ + public ErrorNode(final long token, final int finish) { + super(token, finish); + } + + @Override + public Type getType() { + return Type.OBJECT; + } + + @Override + public Node accept(final NodeVisitor visitor) { + if (visitor.enterErrorNode(this)) { + return visitor.leaveErrorNode(this); + } + + return this; + } + + @Override + public void toString(final StringBuilder sb, final boolean printType) { + sb.append(""); + } +} + --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/test/script/nosecurity/parserapi.js 2015-03-09 18:39:43.143896992 +0530 @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * Nashorn parser API usage. + * + * @test + * @option -scripting + * @run + */ + +function Parser() { + // create nashorn parser + this._parser = Parser.create(); +} + +// Java types used +Parser.Diagnostic = Java.type("jdk.nashorn.api.tree.Diagnostic"); +Parser.SimpleTreeVisitor = Java.type("jdk.nashorn.api.tree.SimpleTreeVisitorES5_1"); +Parser.Tree = Java.type("jdk.nashorn.api.tree.Tree"); +Parser.List = Java.type("java.util.List"); +Parser.Enum = Java.type("java.lang.Enum"); + +// function to parse the script and return script friendly object +Parser.prototype.parse = function(name, script, listener) { + var tree = this._parser.parse(name, script, listener); + tree.accept(new Parser.SimpleTreeVisitor(), null); + return this.convert(tree); +} + +Parser.create = function() { + return Java.type("jdk.nashorn.api.tree.Parser").create(); +} + +// convert Nashorn parser Tree, Diagnostic as a script friendly object +Parser.prototype.convert = function(tree) { + if (!tree || typeof tree != 'object') { + return tree; + } + + var obj = Object.bindProperties({}, tree); + var result = {}; + for (var i in obj) { + var val = obj[i]; + if (val instanceof Parser.Tree) { + result[i] = this.convert(val); + } else if (val instanceof Parser.List) { + var arr = new Array(val.size()); + for (var j in val) { + arr[j] = this.convert(val[j]); + } + + result[i] = arr; + } else { + switch (typeof val) { + case 'number': + case 'string': + case 'boolean': + result[i] = String(val); + default: + if (val instanceof Parser.Enum) { + result[i] = String(val); + } + } + } + } + return result; +} + +function processFiles(subdir) { + var File = Java.type("java.io.File"); + var files = new File(__DIR__ + subdir).listFiles(); + java.util.Arrays.sort(files); + for each (var file in files) { + if (file.name.endsWith(".js")) { + var script = readFully(file); + var parser = new Parser(); + var tree = parser.parse(subdir + "/" + file.name, script, + function(diagnostic) { + print(JSON.stringify(parser.convert(diagnostic), null, 2)); + print(","); + }); + + if (tree != null) { + print(JSON.stringify(tree, null, 2)); + print(","); + } + } + } +} + +// parse files in parsertests directory +function main() { + print("["); + + processFiles("parsertests"); + processFiles("parsernegativetests"); + + // parse this file first! + var script = readFully(__FILE__); + var tree = new Parser().parse("parserapi.js", script, null); + print(JSON.stringify(tree, null, 2)); + print("]"); +} + +main(); --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/test/script/nosecurity/parserapi.js.EXPECTED 2015-03-09 18:39:43.687899684 +0530 @@ -0,0 +1,7015 @@ +[ +{ + "endPosition": "1113", + "kind": "COMPILATION_UNIT", + "sourceElements": [ + { + "endPosition": "1123", + "kind": "VARIABLE", + "name": "x", + "startPosition": "1117", + "initializer": { + "endPosition": "1123", + "kind": "ARRAY_LITERAL", + "elements": [], + "startPosition": "1121" + } + }, + { + "endPosition": "1147", + "kind": "VARIABLE", + "name": "y", + "startPosition": "1129", + "initializer": { + "endPosition": "1147", + "kind": "ARRAY_LITERAL", + "elements": [ + { + "endPosition": "1135", + "kind": "NUMBER_LITERAL", + "value": "1", + "startPosition": "1134" + }, + { + "endPosition": "1139", + "kind": "NUMBER_LITERAL", + "value": "43", + "startPosition": "1137" + }, + { + "endPosition": "1142", + "kind": "NUMBER_LITERAL", + "value": "5", + "startPosition": "1141" + }, + { + "endPosition": "1146", + "kind": "NUMBER_LITERAL", + "value": "45", + "startPosition": "1144" + } + ], + "startPosition": "1133" + } + }, + { + "endPosition": "1165", + "kind": "VARIABLE", + "name": "z", + "startPosition": "1153", + "initializer": { + "endPosition": "1165", + "kind": "ARRAY_LITERAL", + "elements": [ + { + "endPosition": "1160", + "kind": "NUMBER_LITERAL", + "value": "34", + "startPosition": "1158" + }, + null, + null, + { + "endPosition": "1164", + "kind": "NUMBER_LITERAL", + "value": "4", + "startPosition": "1163" + } + ], + "startPosition": "1157" + } + }, + { + "endPosition": "1200", + "kind": "VARIABLE", + "name": "k", + "startPosition": "1171", + "initializer": { + "endPosition": "1200", + "kind": "ARRAY_LITERAL", + "elements": [ + { + "endPosition": "1179", + "kind": "OBJECT_LITERAL", + "startPosition": "1177", + "properties": [] + }, + { + "endPosition": "1189", + "kind": "OBJECT_LITERAL", + "startPosition": "1181", + "properties": [ + { + "endPosition": "1185", + "kind": "PROPERTY", + "value": { + "endPosition": "1187", + "kind": "NUMBER_LITERAL", + "value": "3", + "startPosition": "1186" + }, + "startPosition": "1183", + "key": { + "endPosition": "1184", + "kind": "IDENTIFIER", + "name": "x", + "startPosition": "1183" + } + } + ] + }, + { + "endPosition": "1197", + "kind": "STRING_LITERAL", + "value": "hello", + "startPosition": "1192" + } + ], + "startPosition": "1175" + } + } + ], + "sourceName": "parsertests/array_literal.js", + "strict": "false", + "startPosition": "1113" +} +, +{ + "endPosition": "1126", + "kind": "COMPILATION_UNIT", + "sourceElements": [ + { + "expression": { + "expression": { + "endPosition": "1135", + "kind": "NUMBER_LITERAL", + "value": "314", + "startPosition": "1132" + }, + "endPosition": "1135", + "kind": "ASSIGNMENT", + "variable": { + "endPosition": "1129", + "kind": "IDENTIFIER", + "name": "xyz", + "startPosition": "1126" + }, + "startPosition": "1126" + }, + "endPosition": "1135", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1126" + }, + { + "expression": { + "expression": { + "endPosition": "1147", + "kind": "NUMBER_LITERAL", + "value": "314", + "startPosition": "1144" + }, + "endPosition": "1147", + "kind": "PLUS_ASSIGNMENT", + "variable": { + "endPosition": "1140", + "kind": "IDENTIFIER", + "name": "xyz", + "startPosition": "1137" + }, + "startPosition": "1137" + }, + "endPosition": "1147", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1137" + }, + { + "expression": { + "expression": { + "endPosition": "1159", + "kind": "NUMBER_LITERAL", + "value": "314", + "startPosition": "1156" + }, + "endPosition": "1159", + "kind": "MINUS_ASSIGNMENT", + "variable": { + "endPosition": "1152", + "kind": "IDENTIFIER", + "name": "xyz", + "startPosition": "1149" + }, + "startPosition": "1149" + }, + "endPosition": "1159", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1149" + }, + { + "expression": { + "expression": { + "endPosition": "1171", + "kind": "NUMBER_LITERAL", + "value": "314", + "startPosition": "1168" + }, + "endPosition": "1171", + "kind": "MULTIPLY_ASSIGNMENT", + "variable": { + "endPosition": "1164", + "kind": "IDENTIFIER", + "name": "xyz", + "startPosition": "1161" + }, + "startPosition": "1161" + }, + "endPosition": "1171", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1161" + }, + { + "expression": { + "expression": { + "endPosition": "1183", + "kind": "NUMBER_LITERAL", + "value": "314", + "startPosition": "1180" + }, + "endPosition": "1183", + "kind": "DIVIDE_ASSIGNMENT", + "variable": { + "endPosition": "1176", + "kind": "IDENTIFIER", + "name": "xyz", + "startPosition": "1173" + }, + "startPosition": "1173" + }, + "endPosition": "1183", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1173" + }, + { + "expression": { + "expression": { + "endPosition": "1195", + "kind": "NUMBER_LITERAL", + "value": "314", + "startPosition": "1192" + }, + "endPosition": "1195", + "kind": "REMAINDER_ASSIGNMENT", + "variable": { + "endPosition": "1188", + "kind": "IDENTIFIER", + "name": "xyz", + "startPosition": "1185" + }, + "startPosition": "1185" + }, + "endPosition": "1195", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1185" + }, + { + "expression": { + "expression": { + "endPosition": "1208", + "kind": "NUMBER_LITERAL", + "value": "314", + "startPosition": "1205" + }, + "endPosition": "1208", + "kind": "LEFT_SHIFT_ASSIGNMENT", + "variable": { + "endPosition": "1200", + "kind": "IDENTIFIER", + "name": "xyz", + "startPosition": "1197" + }, + "startPosition": "1197" + }, + "endPosition": "1208", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1197" + }, + { + "expression": { + "expression": { + "endPosition": "1221", + "kind": "NUMBER_LITERAL", + "value": "314", + "startPosition": "1218" + }, + "endPosition": "1221", + "kind": "RIGHT_SHIFT_ASSIGNMENT", + "variable": { + "endPosition": "1213", + "kind": "IDENTIFIER", + "name": "xyz", + "startPosition": "1210" + }, + "startPosition": "1210" + }, + "endPosition": "1221", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1210" + }, + { + "expression": { + "expression": { + "endPosition": "1235", + "kind": "NUMBER_LITERAL", + "value": "314", + "startPosition": "1232" + }, + "endPosition": "1235", + "kind": "UNSIGNED_RIGHT_SHIFT_ASSIGNMENT", + "variable": { + "endPosition": "1226", + "kind": "IDENTIFIER", + "name": "xyz", + "startPosition": "1223" + }, + "startPosition": "1223" + }, + "endPosition": "1235", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1223" + }, + { + "expression": { + "expression": { + "endPosition": "1247", + "kind": "NUMBER_LITERAL", + "value": "314", + "startPosition": "1244" + }, + "endPosition": "1247", + "kind": "AND_ASSIGNMENT", + "variable": { + "endPosition": "1240", + "kind": "IDENTIFIER", + "name": "xyz", + "startPosition": "1237" + }, + "startPosition": "1237" + }, + "endPosition": "1247", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1237" + }, + { + "expression": { + "expression": { + "endPosition": "1259", + "kind": "NUMBER_LITERAL", + "value": "314", + "startPosition": "1256" + }, + "endPosition": "1259", + "kind": "XOR_ASSIGNMENT", + "variable": { + "endPosition": "1252", + "kind": "IDENTIFIER", + "name": "xyz", + "startPosition": "1249" + }, + "startPosition": "1249" + }, + "endPosition": "1259", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1249" + }, + { + "expression": { + "expression": { + "endPosition": "1271", + "kind": "NUMBER_LITERAL", + "value": "314", + "startPosition": "1268" + }, + "endPosition": "1271", + "kind": "OR_ASSIGNMENT", + "variable": { + "endPosition": "1264", + "kind": "IDENTIFIER", + "name": "xyz", + "startPosition": "1261" + }, + "startPosition": "1261" + }, + "endPosition": "1271", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1261" + } + ], + "sourceName": "parsertests/assignmentExpr.js", + "strict": "false", + "startPosition": "1126" +} +, +{ + "endPosition": "1116", + "kind": "COMPILATION_UNIT", + "sourceElements": [ + { + "expression": { + "leftOperand": { + "endPosition": "1117", + "kind": "IDENTIFIER", + "name": "a", + "startPosition": "1116" + }, + "endPosition": "1121", + "kind": "MULTIPLY", + "rightOperand": { + "endPosition": "1121", + "kind": "IDENTIFIER", + "name": "b", + "startPosition": "1120" + }, + "startPosition": "1116" + }, + "endPosition": "1121", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1116" + }, + { + "expression": { + "leftOperand": { + "endPosition": "1123", + "kind": "IDENTIFIER", + "name": "a", + "startPosition": "1122" + }, + "endPosition": "1127", + "kind": "DIVIDE", + "rightOperand": { + "endPosition": "1127", + "kind": "IDENTIFIER", + "name": "b", + "startPosition": "1126" + }, + "startPosition": "1122" + }, + "endPosition": "1127", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1122" + }, + { + "expression": { + "leftOperand": { + "endPosition": "1130", + "kind": "IDENTIFIER", + "name": "a", + "startPosition": "1129" + }, + "endPosition": "1134", + "kind": "REMAINDER", + "rightOperand": { + "endPosition": "1134", + "kind": "IDENTIFIER", + "name": "b", + "startPosition": "1133" + }, + "startPosition": "1129" + }, + "endPosition": "1134", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1129" + }, + { + "expression": { + "leftOperand": { + "endPosition": "1137", + "kind": "IDENTIFIER", + "name": "a", + "startPosition": "1136" + }, + "endPosition": "1141", + "kind": "PLUS", + "rightOperand": { + "endPosition": "1141", + "kind": "IDENTIFIER", + "name": "b", + "startPosition": "1140" + }, + "startPosition": "1136" + }, + "endPosition": "1141", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1136" + }, + { + "expression": { + "leftOperand": { + "endPosition": "1144", + "kind": "IDENTIFIER", + "name": "a", + "startPosition": "1143" + }, + "endPosition": "1148", + "kind": "MINUS", + "rightOperand": { + "endPosition": "1148", + "kind": "IDENTIFIER", + "name": "b", + "startPosition": "1147" + }, + "startPosition": "1143" + }, + "endPosition": "1148", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1143" + }, + { + "expression": { + "leftOperand": { + "endPosition": "1151", + "kind": "IDENTIFIER", + "name": "a", + "startPosition": "1150" + }, + "endPosition": "1156", + "kind": "LEFT_SHIFT", + "rightOperand": { + "endPosition": "1156", + "kind": "IDENTIFIER", + "name": "b", + "startPosition": "1155" + }, + "startPosition": "1150" + }, + "endPosition": "1156", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1150" + }, + { + "expression": { + "leftOperand": { + "endPosition": "1159", + "kind": "IDENTIFIER", + "name": "a", + "startPosition": "1158" + }, + "endPosition": "1164", + "kind": "RIGHT_SHIFT", + "rightOperand": { + "endPosition": "1164", + "kind": "IDENTIFIER", + "name": "b", + "startPosition": "1163" + }, + "startPosition": "1158" + }, + "endPosition": "1164", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1158" + }, + { + "expression": { + "leftOperand": { + "endPosition": "1167", + "kind": "IDENTIFIER", + "name": "a", + "startPosition": "1166" + }, + "endPosition": "1173", + "kind": "UNSIGNED_RIGHT_SHIFT", + "rightOperand": { + "endPosition": "1173", + "kind": "IDENTIFIER", + "name": "b", + "startPosition": "1172" + }, + "startPosition": "1166" + }, + "endPosition": "1173", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1166" + }, + { + "expression": { + "leftOperand": { + "endPosition": "1176", + "kind": "IDENTIFIER", + "name": "a", + "startPosition": "1175" + }, + "endPosition": "1180", + "kind": "LESS_THAN", + "rightOperand": { + "endPosition": "1180", + "kind": "IDENTIFIER", + "name": "b", + "startPosition": "1179" + }, + "startPosition": "1175" + }, + "endPosition": "1180", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1175" + }, + { + "expression": { + "leftOperand": { + "endPosition": "1183", + "kind": "IDENTIFIER", + "name": "a", + "startPosition": "1182" + }, + "endPosition": "1187", + "kind": "GREATER_THAN", + "rightOperand": { + "endPosition": "1187", + "kind": "IDENTIFIER", + "name": "b", + "startPosition": "1186" + }, + "startPosition": "1182" + }, + "endPosition": "1187", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1182" + }, + { + "expression": { + "leftOperand": { + "endPosition": "1190", + "kind": "IDENTIFIER", + "name": "a", + "startPosition": "1189" + }, + "endPosition": "1195", + "kind": "LESS_THAN_EQUAL", + "rightOperand": { + "endPosition": "1195", + "kind": "IDENTIFIER", + "name": "b", + "startPosition": "1194" + }, + "startPosition": "1189" + }, + "endPosition": "1195", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1189" + }, + { + "expression": { + "leftOperand": { + "endPosition": "1198", + "kind": "IDENTIFIER", + "name": "a", + "startPosition": "1197" + }, + "endPosition": "1203", + "kind": "GREATER_THAN_EQUAL", + "rightOperand": { + "endPosition": "1203", + "kind": "IDENTIFIER", + "name": "b", + "startPosition": "1202" + }, + "startPosition": "1197" + }, + "endPosition": "1203", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1197" + }, + { + "expression": { + "leftOperand": { + "endPosition": "1206", + "kind": "IDENTIFIER", + "name": "a", + "startPosition": "1205" + }, + "expression": { + "endPosition": "1206", + "kind": "IDENTIFIER", + "name": "a", + "startPosition": "1205" + }, + "endPosition": "1219", + "kind": "INSTANCE_OF", + "rightOperand": { + "endPosition": "1219", + "kind": "IDENTIFIER", + "name": "b", + "startPosition": "1218" + }, + "type": { + "endPosition": "1219", + "kind": "IDENTIFIER", + "name": "b", + "startPosition": "1218" + }, + "startPosition": "1205" + }, + "endPosition": "1219", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1205" + }, + { + "expression": { + "leftOperand": { + "endPosition": "1222", + "kind": "IDENTIFIER", + "name": "a", + "startPosition": "1221" + }, + "endPosition": "1227", + "kind": "EQUAL_TO", + "rightOperand": { + "endPosition": "1227", + "kind": "IDENTIFIER", + "name": "b", + "startPosition": "1226" + }, + "startPosition": "1221" + }, + "endPosition": "1227", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1221" + }, + { + "expression": { + "leftOperand": { + "endPosition": "1230", + "kind": "IDENTIFIER", + "name": "a", + "startPosition": "1229" + }, + "endPosition": "1235", + "kind": "NOT_EQUAL_TO", + "rightOperand": { + "endPosition": "1235", + "kind": "IDENTIFIER", + "name": "b", + "startPosition": "1234" + }, + "startPosition": "1229" + }, + "endPosition": "1235", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1229" + }, + { + "expression": { + "leftOperand": { + "endPosition": "1238", + "kind": "IDENTIFIER", + "name": "a", + "startPosition": "1237" + }, + "endPosition": "1244", + "kind": "STRICT_EQUAL_TO", + "rightOperand": { + "endPosition": "1244", + "kind": "IDENTIFIER", + "name": "b", + "startPosition": "1243" + }, + "startPosition": "1237" + }, + "endPosition": "1244", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1237" + }, + { + "expression": { + "leftOperand": { + "endPosition": "1247", + "kind": "IDENTIFIER", + "name": "a", + "startPosition": "1246" + }, + "endPosition": "1253", + "kind": "STRICT_NOT_EQUAL_TO", + "rightOperand": { + "endPosition": "1253", + "kind": "IDENTIFIER", + "name": "b", + "startPosition": "1252" + }, + "startPosition": "1246" + }, + "endPosition": "1253", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1246" + }, + { + "expression": { + "leftOperand": { + "endPosition": "1256", + "kind": "IDENTIFIER", + "name": "a", + "startPosition": "1255" + }, + "endPosition": "1260", + "kind": "AND", + "rightOperand": { + "endPosition": "1260", + "kind": "IDENTIFIER", + "name": "b", + "startPosition": "1259" + }, + "startPosition": "1255" + }, + "endPosition": "1260", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1255" + }, + { + "expression": { + "leftOperand": { + "endPosition": "1263", + "kind": "IDENTIFIER", + "name": "a", + "startPosition": "1262" + }, + "endPosition": "1267", + "kind": "XOR", + "rightOperand": { + "endPosition": "1267", + "kind": "IDENTIFIER", + "name": "b", + "startPosition": "1266" + }, + "startPosition": "1262" + }, + "endPosition": "1267", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1262" + }, + { + "expression": { + "leftOperand": { + "endPosition": "1270", + "kind": "IDENTIFIER", + "name": "a", + "startPosition": "1269" + }, + "endPosition": "1274", + "kind": "OR", + "rightOperand": { + "endPosition": "1274", + "kind": "IDENTIFIER", + "name": "b", + "startPosition": "1273" + }, + "startPosition": "1269" + }, + "endPosition": "1274", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1269" + }, + { + "expression": { + "leftOperand": { + "endPosition": "1277", + "kind": "IDENTIFIER", + "name": "a", + "startPosition": "1276" + }, + "endPosition": "1282", + "kind": "CONDITIONAL_AND", + "rightOperand": { + "endPosition": "1282", + "kind": "IDENTIFIER", + "name": "b", + "startPosition": "1281" + }, + "startPosition": "1276" + }, + "endPosition": "1282", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1276" + }, + { + "expression": { + "leftOperand": { + "endPosition": "1285", + "kind": "IDENTIFIER", + "name": "a", + "startPosition": "1284" + }, + "endPosition": "1290", + "kind": "CONDITIONAL_OR", + "rightOperand": { + "endPosition": "1290", + "kind": "IDENTIFIER", + "name": "b", + "startPosition": "1289" + }, + "startPosition": "1284" + }, + "endPosition": "1290", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1284" + } + ], + "sourceName": "parsertests/binaryExpr.js", + "strict": "false", + "startPosition": "1116" +} +, +{ + "endPosition": "1117", + "kind": "COMPILATION_UNIT", + "sourceElements": [ + { + "endPosition": "1119", + "kind": "BLOCK", + "statements": [], + "startPosition": "1117" + }, + { + "endPosition": "1139", + "kind": "BLOCK", + "statements": [ + { + "expression": { + "endPosition": "1136", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "endPosition": "1127", + "kind": "IDENTIFIER", + "name": "print", + "startPosition": "1122" + }, + "arguments": [ + { + "endPosition": "1134", + "kind": "STRING_LITERAL", + "value": "hello", + "startPosition": "1129" + } + ], + "startPosition": "1122" + }, + "endPosition": "1136", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1122" + } + ], + "startPosition": "1120" + } + ], + "sourceName": "parsertests/block.js", + "strict": "false", + "startPosition": "1117" +} +, +{ + "endPosition": "1117", + "kind": "COMPILATION_UNIT", + "sourceElements": [ + { + "condition": { + "endPosition": "1128", + "kind": "BOOLEAN_LITERAL", + "value": "true", + "startPosition": "1124" + }, + "endPosition": "1140", + "kind": "WHILE_LOOP", + "statement": { + "endPosition": "1140", + "kind": "BLOCK", + "statements": [ + { + "endPosition": "1138", + "kind": "BREAK", + "startPosition": "1132" + } + ], + "startPosition": "1130" + }, + "startPosition": "1117" + }, + { + "endPosition": "1179", + "kind": "LABELED_STATEMENT", + "statement": { + "endPosition": "1179", + "kind": "BLOCK", + "statements": [ + { + "condition": { + "endPosition": "1161", + "kind": "BOOLEAN_LITERAL", + "value": "true", + "startPosition": "1157" + }, + "endPosition": "1177", + "kind": "WHILE_LOOP", + "statement": { + "endPosition": "1177", + "kind": "BLOCK", + "statements": [ + { + "endPosition": "1175", + "kind": "BREAK", + "label": "loop", + "startPosition": "1165" + } + ], + "startPosition": "1163" + }, + "startPosition": "1150" + } + ], + "startPosition": "1148" + }, + "label": "loop", + "startPosition": "1142" + }, + { + "endPosition": "1214", + "kind": "LABELED_STATEMENT", + "statement": { + "endPosition": "1214", + "kind": "BLOCK", + "statements": [ + { + "endPosition": "1212", + "kind": "FOR_LOOP", + "statement": { + "endPosition": "1212", + "kind": "BLOCK", + "statements": [ + { + "endPosition": "1210", + "kind": "BREAK", + "label": "loop", + "startPosition": "1200" + } + ], + "startPosition": "1198" + }, + "startPosition": "1189" + } + ], + "startPosition": "1187" + }, + "label": "loop", + "startPosition": "1181" + } + ], + "sourceName": "parsertests/breakStat.js", + "strict": "false", + "startPosition": "1117" +} +, +{ + "endPosition": "1117", + "kind": "COMPILATION_UNIT", + "sourceElements": [ + { + "expression": { + "condition": { + "endPosition": "1118", + "kind": "IDENTIFIER", + "name": "a", + "startPosition": "1117" + }, + "endPosition": "1125", + "kind": "CONDITIONAL_EXPRESSION", + "trueExpression": { + "endPosition": "1121", + "kind": "IDENTIFIER", + "name": "b", + "startPosition": "1120" + }, + "falseExpression": { + "endPosition": "1125", + "kind": "IDENTIFIER", + "name": "c", + "startPosition": "1124" + }, + "startPosition": "1118" + }, + "endPosition": "1125", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1117" + } + ], + "sourceName": "parsertests/condExpr.js", + "strict": "false", + "startPosition": "1117" +} +, +{ + "endPosition": "1120", + "kind": "COMPILATION_UNIT", + "sourceElements": [ + { + "condition": { + "endPosition": "1131", + "kind": "BOOLEAN_LITERAL", + "value": "true", + "startPosition": "1127" + }, + "endPosition": "1146", + "kind": "WHILE_LOOP", + "statement": { + "endPosition": "1146", + "kind": "BLOCK", + "statements": [ + { + "endPosition": "1144", + "kind": "CONTINUE", + "startPosition": "1135" + } + ], + "startPosition": "1133" + }, + "startPosition": "1120" + }, + { + "endPosition": "1191", + "kind": "LABELED_STATEMENT", + "statement": { + "endPosition": "1191", + "kind": "BLOCK", + "statements": [ + { + "condition": { + "endPosition": "1168", + "kind": "BOOLEAN_LITERAL", + "value": "true", + "startPosition": "1164" + }, + "endPosition": "1189", + "kind": "WHILE_LOOP", + "statement": { + "endPosition": "1189", + "kind": "BLOCK", + "statements": [ + { + "endPosition": "1187", + "kind": "CONTINUE", + "label": "begin", + "startPosition": "1172" + } + ], + "startPosition": "1170" + }, + "startPosition": "1157" + } + ], + "startPosition": "1155" + }, + "label": "begin", + "startPosition": "1148" + }, + { + "endPosition": "1231", + "kind": "LABELED_STATEMENT", + "statement": { + "endPosition": "1231", + "kind": "BLOCK", + "statements": [ + { + "endPosition": "1229", + "kind": "FOR_LOOP", + "statement": { + "endPosition": "1229", + "kind": "BLOCK", + "statements": [ + { + "endPosition": "1227", + "kind": "CONTINUE", + "label": "start", + "startPosition": "1212" + } + ], + "startPosition": "1210" + }, + "startPosition": "1202" + } + ], + "startPosition": "1200" + }, + "label": "start", + "startPosition": "1193" + } + ], + "sourceName": "parsertests/continueStat.js", + "strict": "false", + "startPosition": "1120" +} +, +{ + "endPosition": "1118", + "kind": "COMPILATION_UNIT", + "sourceElements": [ + { + "endPosition": "1127", + "kind": "DEBUGGER", + "startPosition": "1118" + } + ], + "sourceName": "parsertests/debuggerStat.js", + "strict": "false", + "startPosition": "1118" +} +, +{ + "endPosition": "1137", + "kind": "COMPILATION_UNIT", + "sourceElements": [ + { + "endPosition": "1172", + "kind": "FUNCTION", + "name": "hello", + "body": { + "endPosition": "1170", + "kind": "BLOCK", + "statements": [ + { + "expression": { + "endPosition": "1170", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "endPosition": "1161", + "kind": "IDENTIFIER", + "name": "print", + "startPosition": "1156" + }, + "arguments": [ + { + "endPosition": "1168", + "kind": "STRING_LITERAL", + "value": "hello", + "startPosition": "1163" + } + ], + "startPosition": "1156" + }, + "endPosition": "1170", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1156" + } + ], + "startPosition": "1154" + }, + "strict": "false", + "startPosition": "1137", + "parameters": [] + }, + { + "endPosition": "1203", + "kind": "FUNCTION", + "name": "hello", + "body": { + "endPosition": "1201", + "kind": "BLOCK", + "statements": [ + { + "expression": { + "endPosition": "1201", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "endPosition": "1198", + "kind": "IDENTIFIER", + "name": "print", + "startPosition": "1193" + }, + "arguments": [ + { + "endPosition": "1200", + "kind": "IDENTIFIER", + "name": "a", + "startPosition": "1199" + } + ], + "startPosition": "1193" + }, + "endPosition": "1201", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1193" + } + ], + "startPosition": "1191" + }, + "strict": "false", + "startPosition": "1173", + "parameters": [ + { + "endPosition": "1189", + "kind": "IDENTIFIER", + "name": "a", + "startPosition": "1188" + } + ] + }, + { + "endPosition": "1240", + "kind": "FUNCTION", + "name": "hello", + "body": { + "endPosition": "1238", + "kind": "BLOCK", + "statements": [ + { + "expression": { + "endPosition": "1238", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "endPosition": "1232", + "kind": "IDENTIFIER", + "name": "print", + "startPosition": "1227" + }, + "arguments": [ + { + "endPosition": "1234", + "kind": "IDENTIFIER", + "name": "a", + "startPosition": "1233" + }, + { + "endPosition": "1237", + "kind": "IDENTIFIER", + "name": "b", + "startPosition": "1236" + } + ], + "startPosition": "1227" + }, + "endPosition": "1238", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1227" + } + ], + "startPosition": "1225" + }, + "strict": "false", + "startPosition": "1204", + "parameters": [ + { + "endPosition": "1220", + "kind": "IDENTIFIER", + "name": "a", + "startPosition": "1219" + }, + { + "endPosition": "1223", + "kind": "IDENTIFIER", + "name": "b", + "startPosition": "1222" + } + ] + }, + { + "endPosition": "1380", + "kind": "FUNCTION", + "name": "test", + "body": { + "endPosition": "1377", + "kind": "BLOCK", + "statements": [ + { + "expression": { + "endPosition": "1377", + "kind": "STRING_LITERAL", + "value": "use strict", + "startPosition": "1367" + }, + "endPosition": "1377", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1367" + } + ], + "startPosition": "1364" + }, + "strict": "true", + "startPosition": "1348", + "parameters": [] + }, + { + "endPosition": "1282", + "kind": "VARIABLE", + "name": "hello", + "startPosition": "1245", + "initializer": { + "endPosition": "1264", + "kind": "FUNCTION_EXPRESSION", + "body": { + "endPosition": "1280", + "kind": "BLOCK", + "statements": [ + { + "expression": { + "endPosition": "1280", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "endPosition": "1271", + "kind": "IDENTIFIER", + "name": "print", + "startPosition": "1266" + }, + "arguments": [ + { + "endPosition": "1278", + "kind": "STRING_LITERAL", + "value": "hello", + "startPosition": "1273" + } + ], + "startPosition": "1266" + }, + "endPosition": "1280", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1266" + } + ], + "startPosition": "1264" + }, + "strict": "false", + "startPosition": "1264", + "parameters": [] + } + }, + { + "endPosition": "1331", + "kind": "VARIABLE", + "name": "hello", + "startPosition": "1288", + "initializer": { + "endPosition": "1313", + "kind": "FUNCTION_EXPRESSION", + "name": "hello", + "body": { + "endPosition": "1329", + "kind": "BLOCK", + "statements": [ + { + "expression": { + "endPosition": "1329", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "endPosition": "1320", + "kind": "IDENTIFIER", + "name": "print", + "startPosition": "1315" + }, + "arguments": [ + { + "endPosition": "1327", + "kind": "STRING_LITERAL", + "value": "hello", + "startPosition": "1322" + } + ], + "startPosition": "1315" + }, + "endPosition": "1329", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1315" + } + ], + "startPosition": "1313" + }, + "strict": "false", + "startPosition": "1313", + "parameters": [] + } + }, + { + "expression": { + "endPosition": "1344", + "kind": "FUNCTION_EXPRESSION", + "body": { + "endPosition": "1345", + "kind": "BLOCK", + "statements": [], + "startPosition": "1344" + }, + "strict": "false", + "startPosition": "1344", + "parameters": [] + }, + "endPosition": "1347", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1333" + } + ], + "sourceName": "parsertests/functions.js", + "strict": "false", + "startPosition": "1137" +} +, +{ + "endPosition": "1114", + "kind": "COMPILATION_UNIT", + "sourceElements": [ + { + "condition": { + "endPosition": "1120", + "kind": "IDENTIFIER", + "name": "js", + "startPosition": "1118" + }, + "endPosition": "1135", + "kind": "IF", + "startPosition": "1114", + "thenStatement": { + "endPosition": "1135", + "kind": "BLOCK", + "statements": [ + { + "expression": { + "endPosition": "1133", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "endPosition": "1131", + "kind": "IDENTIFIER", + "name": "nashorn", + "startPosition": "1124" + }, + "arguments": [], + "startPosition": "1124" + }, + "endPosition": "1133", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1124" + } + ], + "startPosition": "1122" + } + }, + { + "condition": { + "endPosition": "1143", + "kind": "IDENTIFIER", + "name": "js", + "startPosition": "1141" + }, + "elseStatement": { + "endPosition": "1174", + "kind": "BLOCK", + "statements": [ + { + "expression": { + "endPosition": "1172", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "endPosition": "1170", + "kind": "IDENTIFIER", + "name": "java", + "startPosition": "1166" + }, + "arguments": [], + "startPosition": "1166" + }, + "endPosition": "1172", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1166" + } + ], + "startPosition": "1164" + }, + "endPosition": "1174", + "kind": "IF", + "startPosition": "1137", + "thenStatement": { + "endPosition": "1158", + "kind": "BLOCK", + "statements": [ + { + "expression": { + "endPosition": "1156", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "endPosition": "1154", + "kind": "IDENTIFIER", + "name": "nashorn", + "startPosition": "1147" + }, + "arguments": [], + "startPosition": "1147" + }, + "endPosition": "1156", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1147" + } + ], + "startPosition": "1145" + } + } + ], + "sourceName": "parsertests/ifStat.js", + "strict": "false", + "startPosition": "1114" +} +, +{ + "endPosition": "1113", + "kind": "COMPILATION_UNIT", + "sourceElements": [ + { + "endPosition": "1144", + "kind": "LABELED_STATEMENT", + "statement": { + "endPosition": "1144", + "kind": "BLOCK", + "statements": [ + { + "endPosition": "1142", + "kind": "FOR_LOOP", + "statement": { + "endPosition": "1142", + "kind": "BREAK", + "label": "begin", + "startPosition": "1131" + }, + "startPosition": "1122" + } + ], + "startPosition": "1120" + }, + "label": "begin", + "startPosition": "1113" + }, + { + "endPosition": "1181", + "kind": "LABELED_STATEMENT", + "statement": { + "endPosition": "1181", + "kind": "BLOCK", + "statements": [ + { + "condition": { + "endPosition": "1166", + "kind": "BOOLEAN_LITERAL", + "value": "true", + "startPosition": "1162" + }, + "endPosition": "1179", + "kind": "WHILE_LOOP", + "statement": { + "endPosition": "1179", + "kind": "BREAK", + "label": "begin", + "startPosition": "1168" + }, + "startPosition": "1155" + } + ], + "startPosition": "1153" + }, + "label": "begin", + "startPosition": "1146" + } + ], + "sourceName": "parsertests/labelledStat.js", + "strict": "false", + "startPosition": "1113" +} +, +{ + "endPosition": "1125", + "kind": "COMPILATION_UNIT", + "sourceElements": [ + { + "expression": { + "expression": { + "endPosition": "1126", + "kind": "IDENTIFIER", + "name": "a", + "startPosition": "1125" + }, + "endPosition": "1129", + "kind": "ARRAY_ACCESS", + "index": { + "endPosition": "1128", + "kind": "NUMBER_LITERAL", + "value": "3", + "startPosition": "1127" + }, + "startPosition": "1125" + }, + "endPosition": "1129", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1125" + }, + { + "expression": { + "expression": { + "endPosition": "1132", + "kind": "IDENTIFIER", + "name": "a", + "startPosition": "1131" + }, + "endPosition": "1135", + "kind": "ARRAY_ACCESS", + "index": { + "endPosition": "1134", + "kind": "IDENTIFIER", + "name": "b", + "startPosition": "1133" + }, + "startPosition": "1131" + }, + "endPosition": "1135", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1131" + }, + { + "expression": { + "expression": { + "endPosition": "1138", + "kind": "IDENTIFIER", + "name": "a", + "startPosition": "1137" + }, + "endPosition": "1145", + "kind": "ARRAY_ACCESS", + "index": { + "endPosition": "1143", + "kind": "STRING_LITERAL", + "value": "foo", + "startPosition": "1140" + }, + "startPosition": "1137" + }, + "endPosition": "1145", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1137" + }, + { + "expression": { + "identifier": "foo", + "expression": { + "endPosition": "1150", + "kind": "IDENTIFIER", + "name": "obj", + "startPosition": "1147" + }, + "endPosition": "1154", + "kind": "MEMBER_SELECT", + "startPosition": "1147" + }, + "endPosition": "1154", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1147" + }, + { + "expression": { + "identifier": "bar", + "expression": { + "identifier": "foo", + "expression": { + "endPosition": "1159", + "kind": "IDENTIFIER", + "name": "obj", + "startPosition": "1156" + }, + "endPosition": "1163", + "kind": "MEMBER_SELECT", + "startPosition": "1156" + }, + "endPosition": "1167", + "kind": "MEMBER_SELECT", + "startPosition": "1156" + }, + "endPosition": "1167", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1156" + }, + { + "expression": { + "constructorExpression": { + "endPosition": "1177", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "endPosition": "1177", + "kind": "IDENTIFIER", + "name": "Type", + "startPosition": "1173" + }, + "arguments": [], + "startPosition": "1173" + }, + "endPosition": "1177", + "kind": "NEW", + "startPosition": "1169" + }, + "endPosition": "1177", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1169" + }, + { + "expression": { + "constructorExpression": { + "endPosition": "1189", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "endPosition": "1187", + "kind": "IDENTIFIER", + "name": "Type", + "startPosition": "1183" + }, + "arguments": [], + "startPosition": "1183" + }, + "endPosition": "1189", + "kind": "NEW", + "startPosition": "1179" + }, + "endPosition": "1189", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1179" + }, + { + "expression": { + "constructorExpression": { + "endPosition": "1211", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "endPosition": "1199", + "kind": "IDENTIFIER", + "name": "Type", + "startPosition": "1195" + }, + "arguments": [ + { + "endPosition": "1201", + "kind": "IDENTIFIER", + "name": "a", + "startPosition": "1200" + }, + { + "endPosition": "1209", + "kind": "STRING_LITERAL", + "value": "hello", + "startPosition": "1204" + } + ], + "startPosition": "1195" + }, + "endPosition": "1211", + "kind": "NEW", + "startPosition": "1191" + }, + "endPosition": "1211", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1191" + }, + { + "expression": { + "constructorExpression": { + "endPosition": "1225", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "identifier": "Type", + "expression": { + "endPosition": "1220", + "kind": "IDENTIFIER", + "name": "obj", + "startPosition": "1217" + }, + "endPosition": "1225", + "kind": "MEMBER_SELECT", + "startPosition": "1217" + }, + "arguments": [], + "startPosition": "1220" + }, + "endPosition": "1225", + "kind": "NEW", + "startPosition": "1213" + }, + "endPosition": "1225", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1213" + }, + { + "expression": { + "constructorExpression": { + "endPosition": "1241", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "identifier": "Type", + "expression": { + "endPosition": "1234", + "kind": "IDENTIFIER", + "name": "obj", + "startPosition": "1231" + }, + "endPosition": "1239", + "kind": "MEMBER_SELECT", + "startPosition": "1231" + }, + "arguments": [], + "startPosition": "1234" + }, + "endPosition": "1241", + "kind": "NEW", + "startPosition": "1227" + }, + "endPosition": "1241", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1227" + }, + { + "expression": { + "constructorExpression": { + "endPosition": "1267", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "identifier": "Type", + "expression": { + "endPosition": "1250", + "kind": "IDENTIFIER", + "name": "obj", + "startPosition": "1247" + }, + "endPosition": "1255", + "kind": "MEMBER_SELECT", + "startPosition": "1247" + }, + "arguments": [ + { + "endPosition": "1257", + "kind": "IDENTIFIER", + "name": "a", + "startPosition": "1256" + }, + { + "endPosition": "1265", + "kind": "STRING_LITERAL", + "value": "hello", + "startPosition": "1260" + } + ], + "startPosition": "1250" + }, + "endPosition": "1267", + "kind": "NEW", + "startPosition": "1243" + }, + "endPosition": "1267", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1243" + }, + { + "expression": { + "endPosition": "1274", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "endPosition": "1272", + "kind": "IDENTIFIER", + "name": "foo", + "startPosition": "1269" + }, + "arguments": [], + "startPosition": "1269" + }, + "endPosition": "1274", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1269" + }, + { + "expression": { + "endPosition": "1284", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "identifier": "foo", + "expression": { + "endPosition": "1278", + "kind": "IDENTIFIER", + "name": "obj", + "startPosition": "1275" + }, + "endPosition": "1282", + "kind": "MEMBER_SELECT", + "startPosition": "1275" + }, + "arguments": [], + "startPosition": "1275" + }, + "endPosition": "1284", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1275" + }, + { + "expression": { + "endPosition": "1294", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "endPosition": "1289", + "kind": "IDENTIFIER", + "name": "foo", + "startPosition": "1286" + }, + "arguments": [ + { + "endPosition": "1291", + "kind": "IDENTIFIER", + "name": "a", + "startPosition": "1290" + }, + { + "endPosition": "1293", + "kind": "IDENTIFIER", + "name": "b", + "startPosition": "1292" + } + ], + "startPosition": "1286" + }, + "endPosition": "1294", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1286" + }, + { + "expression": { + "endPosition": "1309", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "identifier": "foo", + "expression": { + "endPosition": "1299", + "kind": "IDENTIFIER", + "name": "obj", + "startPosition": "1296" + }, + "endPosition": "1303", + "kind": "MEMBER_SELECT", + "startPosition": "1296" + }, + "arguments": [ + { + "endPosition": "1305", + "kind": "IDENTIFIER", + "name": "a", + "startPosition": "1304" + }, + { + "endPosition": "1308", + "kind": "IDENTIFIER", + "name": "b", + "startPosition": "1307" + } + ], + "startPosition": "1296" + }, + "endPosition": "1309", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1296" + } + ], + "sourceName": "parsertests/lhsExpr.js", + "strict": "false", + "startPosition": "1125" +} +, +{ + "endPosition": "1110", + "kind": "COMPILATION_UNIT", + "sourceElements": [ + { + "condition": { + "endPosition": "1120", + "kind": "BOOLEAN_LITERAL", + "value": "true", + "startPosition": "1116" + }, + "endPosition": "1140", + "kind": "WHILE_LOOP", + "statement": { + "endPosition": "1140", + "kind": "BLOCK", + "statements": [ + { + "expression": { + "endPosition": "1138", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "endPosition": "1129", + "kind": "IDENTIFIER", + "name": "print", + "startPosition": "1124" + }, + "arguments": [ + { + "endPosition": "1136", + "kind": "STRING_LITERAL", + "value": "hello", + "startPosition": "1131" + } + ], + "startPosition": "1124" + }, + "endPosition": "1138", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1124" + } + ], + "startPosition": "1122" + }, + "startPosition": "1110" + }, + { + "condition": { + "endPosition": "1173", + "kind": "BOOLEAN_LITERAL", + "value": "true", + "startPosition": "1169" + }, + "endPosition": "1174", + "kind": "DO_WHILE_LOOP", + "statement": { + "endPosition": "1162", + "kind": "BLOCK", + "statements": [ + { + "expression": { + "endPosition": "1160", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "endPosition": "1151", + "kind": "IDENTIFIER", + "name": "print", + "startPosition": "1146" + }, + "arguments": [ + { + "endPosition": "1158", + "kind": "STRING_LITERAL", + "value": "hello", + "startPosition": "1153" + } + ], + "startPosition": "1146" + }, + "endPosition": "1160", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1146" + } + ], + "startPosition": "1144" + }, + "startPosition": "1141" + }, + { + "expression": { + "endPosition": "1188", + "kind": "IDENTIFIER", + "name": "obj", + "startPosition": "1185" + }, + "endPosition": "1207", + "kind": "FOR_IN_LOOP", + "forEach": "false", + "variable": { + "endPosition": "1181", + "kind": "IDENTIFIER", + "name": "i", + "startPosition": "1180" + }, + "statement": { + "endPosition": "1207", + "kind": "BLOCK", + "statements": [ + { + "expression": { + "endPosition": "1205", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "endPosition": "1197", + "kind": "IDENTIFIER", + "name": "print", + "startPosition": "1192" + }, + "arguments": [ + { + "expression": { + "endPosition": "1201", + "kind": "IDENTIFIER", + "name": "obj", + "startPosition": "1198" + }, + "endPosition": "1204", + "kind": "ARRAY_ACCESS", + "index": { + "endPosition": "1203", + "kind": "IDENTIFIER", + "name": "i", + "startPosition": "1202" + }, + "startPosition": "1198" + } + ], + "startPosition": "1192" + }, + "endPosition": "1205", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1192" + } + ], + "startPosition": "1190" + }, + "startPosition": "1175" + }, + { + "expression": { + "endPosition": "1226", + "kind": "IDENTIFIER", + "name": "obj", + "startPosition": "1223" + }, + "endPosition": "1240", + "kind": "FOR_IN_LOOP", + "forEach": "true", + "variable": { + "endPosition": "1219", + "kind": "IDENTIFIER", + "name": "i", + "startPosition": "1218" + }, + "statement": { + "endPosition": "1240", + "kind": "BLOCK", + "statements": [ + { + "expression": { + "endPosition": "1238", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "endPosition": "1235", + "kind": "IDENTIFIER", + "name": "print", + "startPosition": "1230" + }, + "arguments": [ + { + "endPosition": "1237", + "kind": "IDENTIFIER", + "name": "i", + "startPosition": "1236" + } + ], + "startPosition": "1230" + }, + "endPosition": "1238", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1230" + } + ], + "startPosition": "1228" + }, + "startPosition": "1208" + }, + { + "condition": { + "leftOperand": { + "endPosition": "1254", + "kind": "IDENTIFIER", + "name": "i", + "startPosition": "1253" + }, + "endPosition": "1259", + "kind": "LESS_THAN", + "rightOperand": { + "endPosition": "1259", + "kind": "NUMBER_LITERAL", + "value": "10", + "startPosition": "1257" + }, + "startPosition": "1253" + }, + "endPosition": "1278", + "kind": "FOR_LOOP", + "statement": { + "endPosition": "1278", + "kind": "BLOCK", + "statements": [ + { + "expression": { + "endPosition": "1276", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "endPosition": "1273", + "kind": "IDENTIFIER", + "name": "print", + "startPosition": "1268" + }, + "arguments": [ + { + "endPosition": "1275", + "kind": "IDENTIFIER", + "name": "i", + "startPosition": "1274" + } + ], + "startPosition": "1268" + }, + "endPosition": "1276", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1268" + } + ], + "startPosition": "1266" + }, + "update": { + "expression": { + "endPosition": "1262", + "kind": "IDENTIFIER", + "name": "i", + "startPosition": "1261" + }, + "endPosition": "1264", + "kind": "POSTFIX_INCREMENT", + "startPosition": "1261" + }, + "startPosition": "1241", + "initializer": { + "expression": { + "endPosition": "1251", + "kind": "NUMBER_LITERAL", + "value": "0", + "startPosition": "1250" + }, + "endPosition": "1251", + "kind": "ASSIGNMENT", + "variable": { + "endPosition": "1247", + "kind": "IDENTIFIER", + "name": "i", + "startPosition": "1246" + }, + "startPosition": "1246" + } + } + ], + "sourceName": "parsertests/loopStat.js", + "strict": "false", + "startPosition": "1110" +} +, +{ + "endPosition": "1125", + "kind": "COMPILATION_UNIT", + "sourceElements": [ + { + "expression": { + "expression": { + "endPosition": "1133", + "kind": "OBJECT_LITERAL", + "startPosition": "1131", + "properties": [] + }, + "endPosition": "1133", + "kind": "ASSIGNMENT", + "variable": { + "endPosition": "1128", + "kind": "IDENTIFIER", + "name": "obj", + "startPosition": "1125" + }, + "startPosition": "1125" + }, + "endPosition": "1133", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1125" + }, + { + "expression": { + "expression": { + "endPosition": "1154", + "kind": "OBJECT_LITERAL", + "startPosition": "1139", + "properties": [ + { + "endPosition": "1143", + "kind": "PROPERTY", + "value": { + "endPosition": "1146", + "kind": "NUMBER_LITERAL", + "value": "10", + "startPosition": "1144" + }, + "startPosition": "1141", + "key": { + "endPosition": "1142", + "kind": "IDENTIFIER", + "name": "x", + "startPosition": "1141" + } + }, + { + "endPosition": "1150", + "kind": "PROPERTY", + "value": { + "endPosition": "1152", + "kind": "NUMBER_LITERAL", + "value": "2", + "startPosition": "1151" + }, + "startPosition": "1148", + "key": { + "endPosition": "1149", + "kind": "IDENTIFIER", + "name": "y", + "startPosition": "1148" + } + } + ] + }, + "endPosition": "1154", + "kind": "ASSIGNMENT", + "variable": { + "endPosition": "1136", + "kind": "IDENTIFIER", + "name": "p", + "startPosition": "1135" + }, + "startPosition": "1135" + }, + "endPosition": "1154", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1135" + }, + { + "expression": { + "expression": { + "endPosition": "1179", + "kind": "OBJECT_LITERAL", + "startPosition": "1160", + "properties": [ + { + "endPosition": "1166", + "kind": "PROPERTY", + "value": { + "endPosition": "1169", + "kind": "NUMBER_LITERAL", + "value": "10", + "startPosition": "1167" + }, + "startPosition": "1163", + "key": { + "endPosition": "1164", + "kind": "STRING_LITERAL", + "value": "x", + "startPosition": "1163" + } + }, + { + "endPosition": "1175", + "kind": "PROPERTY", + "value": { + "endPosition": "1177", + "kind": "NUMBER_LITERAL", + "value": "2", + "startPosition": "1176" + }, + "startPosition": "1172", + "key": { + "endPosition": "1173", + "kind": "STRING_LITERAL", + "value": "y", + "startPosition": "1172" + } + } + ] + }, + "endPosition": "1179", + "kind": "ASSIGNMENT", + "variable": { + "endPosition": "1157", + "kind": "IDENTIFIER", + "name": "p", + "startPosition": "1156" + }, + "startPosition": "1156" + }, + "endPosition": "1179", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1156" + }, + { + "expression": { + "expression": { + "endPosition": "1241", + "kind": "OBJECT_LITERAL", + "startPosition": "1185", + "properties": [ + { + "getter": { + "endPosition": "1195", + "kind": "FUNCTION_EXPRESSION", + "body": { + "endPosition": "1210", + "kind": "BLOCK", + "statements": [ + { + "expression": { + "endPosition": "1210", + "kind": "IDENTIFIER", + "name": "xValue", + "startPosition": "1204" + }, + "endPosition": "1210", + "kind": "RETURN", + "startPosition": "1197" + } + ], + "startPosition": "1195" + }, + "strict": "false", + "startPosition": "1195", + "parameters": [] + }, + "endPosition": "1212", + "kind": "PROPERTY", + "startPosition": "1187", + "key": { + "endPosition": "1192", + "kind": "IDENTIFIER", + "name": "x", + "startPosition": "1191" + } + }, + { + "getter": { + "endPosition": "1222", + "kind": "FUNCTION_EXPRESSION", + "body": { + "endPosition": "1237", + "kind": "BLOCK", + "statements": [ + { + "expression": { + "endPosition": "1237", + "kind": "IDENTIFIER", + "name": "yValue", + "startPosition": "1231" + }, + "endPosition": "1237", + "kind": "RETURN", + "startPosition": "1224" + } + ], + "startPosition": "1222" + }, + "strict": "false", + "startPosition": "1222", + "parameters": [] + }, + "endPosition": "1239", + "kind": "PROPERTY", + "startPosition": "1214", + "key": { + "endPosition": "1219", + "kind": "IDENTIFIER", + "name": "y", + "startPosition": "1218" + } + } + ] + }, + "endPosition": "1241", + "kind": "ASSIGNMENT", + "variable": { + "endPosition": "1182", + "kind": "IDENTIFIER", + "name": "p", + "startPosition": "1181" + }, + "startPosition": "1181" + }, + "endPosition": "1241", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1181" + }, + { + "expression": { + "expression": { + "endPosition": "1315", + "kind": "OBJECT_LITERAL", + "startPosition": "1247", + "properties": [ + { + "getter": { + "endPosition": "1259", + "kind": "FUNCTION_EXPRESSION", + "body": { + "endPosition": "1277", + "kind": "BLOCK", + "statements": [ + { + "expression": { + "identifier": "_foo", + "expression": { + "endPosition": "1272", + "kind": "IDENTIFIER", + "name": "this", + "startPosition": "1268" + }, + "endPosition": "1277", + "kind": "MEMBER_SELECT", + "startPosition": "1268" + }, + "endPosition": "1277", + "kind": "RETURN", + "startPosition": "1261" + } + ], + "startPosition": "1259" + }, + "strict": "false", + "startPosition": "1259", + "parameters": [] + }, + "endPosition": "1279", + "kind": "PROPERTY", + "setter": { + "endPosition": "1294", + "kind": "FUNCTION_EXPRESSION", + "body": { + "endPosition": "1311", + "kind": "BLOCK", + "statements": [ + { + "expression": { + "expression": { + "endPosition": "1311", + "kind": "IDENTIFIER", + "name": "val", + "startPosition": "1308" + }, + "endPosition": "1311", + "kind": "ASSIGNMENT", + "variable": { + "identifier": "_foo", + "expression": { + "endPosition": "1300", + "kind": "IDENTIFIER", + "name": "this", + "startPosition": "1296" + }, + "endPosition": "1305", + "kind": "MEMBER_SELECT", + "startPosition": "1296" + }, + "startPosition": "1296" + }, + "endPosition": "1311", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1296" + } + ], + "startPosition": "1294" + }, + "strict": "false", + "startPosition": "1294", + "parameters": [ + { + "endPosition": "1292", + "kind": "IDENTIFIER", + "name": "val", + "startPosition": "1289" + } + ] + }, + "startPosition": "1249", + "key": { + "endPosition": "1256", + "kind": "IDENTIFIER", + "name": "foo", + "startPosition": "1253" + } + } + ] + }, + "endPosition": "1315", + "kind": "ASSIGNMENT", + "variable": { + "endPosition": "1244", + "kind": "IDENTIFIER", + "name": "p", + "startPosition": "1243" + }, + "startPosition": "1243" + }, + "endPosition": "1315", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1243" + } + ], + "sourceName": "parsertests/objectLitExpr.js", + "strict": "false", + "startPosition": "1125" +} +, +{ + "endPosition": "1118", + "kind": "COMPILATION_UNIT", + "sourceElements": [ + { + "expression": { + "leftOperand": { + "leftOperand": { + "endPosition": "1120", + "kind": "NUMBER_LITERAL", + "value": "2", + "startPosition": "1119" + }, + "endPosition": "1126", + "kind": "PLUS", + "rightOperand": { + "endPosition": "1126", + "kind": "NUMBER_LITERAL", + "value": "1", + "startPosition": "1125" + }, + "startPosition": "1119" + }, + "endPosition": "1131", + "kind": "PLUS", + "rightOperand": { + "endPosition": "1131", + "kind": "NUMBER_LITERAL", + "value": "4", + "startPosition": "1130" + }, + "startPosition": "1119" + }, + "endPosition": "1131", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1118" + }, + { + "expression": { + "leftOperand": { + "leftOperand": { + "endPosition": "1134", + "kind": "NUMBER_LITERAL", + "value": "3", + "startPosition": "1133" + }, + "endPosition": "1139", + "kind": "PLUS", + "rightOperand": { + "endPosition": "1139", + "kind": "NUMBER_LITERAL", + "value": "7", + "startPosition": "1138" + }, + "startPosition": "1133" + }, + "endPosition": "1146", + "kind": "LEFT_SHIFT", + "rightOperand": { + "endPosition": "1146", + "kind": "NUMBER_LITERAL", + "value": "5", + "startPosition": "1145" + }, + "startPosition": "1133" + }, + "endPosition": "1147", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1133" + } + ], + "sourceName": "parsertests/parenExpr.js", + "strict": "false", + "startPosition": "1118" +} +, +{ + "endPosition": "1119", + "kind": "COMPILATION_UNIT", + "sourceElements": [ + { + "expression": { + "endPosition": "1123", + "kind": "IDENTIFIER", + "name": "this", + "startPosition": "1119" + }, + "endPosition": "1123", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1119" + }, + { + "expression": { + "endPosition": "1128", + "kind": "IDENTIFIER", + "name": "foo", + "startPosition": "1125" + }, + "endPosition": "1128", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1125" + }, + { + "expression": { + "endPosition": "1134", + "kind": "NULL_LITERAL", + "startPosition": "1130" + }, + "endPosition": "1134", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1130" + }, + { + "expression": { + "endPosition": "1140", + "kind": "BOOLEAN_LITERAL", + "value": "true", + "startPosition": "1136" + }, + "endPosition": "1140", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1136" + }, + { + "expression": { + "endPosition": "1147", + "kind": "BOOLEAN_LITERAL", + "value": "false", + "startPosition": "1142" + }, + "endPosition": "1147", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1142" + }, + { + "expression": { + "endPosition": "1151", + "kind": "NUMBER_LITERAL", + "value": "33", + "startPosition": "1149" + }, + "endPosition": "1151", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1149" + }, + { + "expression": { + "endPosition": "1157", + "kind": "NUMBER_LITERAL", + "value": "3.14", + "startPosition": "1153" + }, + "endPosition": "1157", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1153" + }, + { + "expression": { + "leftOperand": { + "leftOperand": { + "endPosition": "1162", + "kind": "NUMBER_LITERAL", + "value": "10", + "startPosition": "1160" + }, + "endPosition": "1166", + "kind": "PLUS", + "rightOperand": { + "endPosition": "1166", + "kind": "NUMBER_LITERAL", + "value": "3", + "startPosition": "1165" + }, + "startPosition": "1160" + }, + "endPosition": "1169", + "kind": "MULTIPLY", + "rightOperand": { + "endPosition": "1169", + "kind": "NUMBER_LITERAL", + "value": "2", + "startPosition": "1168" + }, + "startPosition": "1160" + }, + "endPosition": "1169", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1159" + }, + { + "expression": { + "endPosition": "1174", + "kind": "OBJECT_LITERAL", + "startPosition": "1172", + "properties": [] + }, + "endPosition": "1175", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1171" + }, + { + "expression": { + "endPosition": "1186", + "kind": "OBJECT_LITERAL", + "startPosition": "1178", + "properties": [ + { + "endPosition": "1182", + "kind": "PROPERTY", + "value": { + "endPosition": "1184", + "kind": "NUMBER_LITERAL", + "value": "3", + "startPosition": "1183" + }, + "startPosition": "1180", + "key": { + "endPosition": "1181", + "kind": "IDENTIFIER", + "name": "x", + "startPosition": "1180" + } + } + ] + }, + "endPosition": "1187", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1177" + }, + { + "expression": { + "endPosition": "1191", + "kind": "ARRAY_LITERAL", + "elements": [], + "startPosition": "1189" + }, + "endPosition": "1191", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1189" + }, + { + "expression": { + "endPosition": "1197", + "kind": "ARRAY_LITERAL", + "elements": [ + null, + null + ], + "startPosition": "1193" + }, + "endPosition": "1197", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1193" + }, + { + "expression": { + "endPosition": "1208", + "kind": "ARRAY_LITERAL", + "elements": [ + { + "endPosition": "1201", + "kind": "NUMBER_LITERAL", + "value": "4", + "startPosition": "1200" + }, + { + "endPosition": "1204", + "kind": "NUMBER_LITERAL", + "value": "5", + "startPosition": "1203" + }, + { + "endPosition": "1207", + "kind": "NUMBER_LITERAL", + "value": "5", + "startPosition": "1206" + } + ], + "startPosition": "1199" + }, + "endPosition": "1208", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1199" + } + ], + "sourceName": "parsertests/primaryExpr.js", + "strict": "false", + "startPosition": "1119" +} +, +{ + "endPosition": "1114", + "kind": "COMPILATION_UNIT", + "sourceElements": [ + { + "endPosition": "1127", + "kind": "VARIABLE", + "name": "x", + "startPosition": "1118", + "initializer": { + "endPosition": "1127", + "kind": "REGEXP_LITERAL", + "options": "", + "pattern": "foo", + "startPosition": "1122" + } + }, + { + "endPosition": "1143", + "kind": "VARIABLE", + "name": "y", + "startPosition": "1133", + "initializer": { + "endPosition": "1143", + "kind": "REGEXP_LITERAL", + "options": "g", + "pattern": "foo", + "startPosition": "1137" + } + }, + { + "endPosition": "1168", + "kind": "VARIABLE", + "name": "z", + "startPosition": "1149", + "initializer": { + "endPosition": "1168", + "kind": "REGEXP_LITERAL", + "options": "", + "pattern": "[a-z]*[1-10]?", + "startPosition": "1153" + } + } + ], + "sourceName": "parsertests/regexp_literal.js", + "strict": "false", + "startPosition": "1114" +} +, +{ + "endPosition": "1118", + "kind": "COMPILATION_UNIT", + "sourceElements": [ + { + "expression": { + "endPosition": "1130", + "kind": "FUNCTION_EXPRESSION", + "body": { + "endPosition": "1138", + "kind": "BLOCK", + "statements": [ + { + "endPosition": "1138", + "kind": "RETURN", + "startPosition": "1132" + } + ], + "startPosition": "1130" + }, + "strict": "false", + "startPosition": "1130", + "parameters": [] + }, + "endPosition": "1141", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1118" + }, + { + "expression": { + "endPosition": "1155", + "kind": "FUNCTION_EXPRESSION", + "body": { + "endPosition": "1167", + "kind": "BLOCK", + "statements": [ + { + "expression": { + "endPosition": "1167", + "kind": "IDENTIFIER", + "name": "res", + "startPosition": "1164" + }, + "endPosition": "1167", + "kind": "RETURN", + "startPosition": "1157" + } + ], + "startPosition": "1155" + }, + "strict": "false", + "startPosition": "1155", + "parameters": [] + }, + "endPosition": "1170", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1143" + }, + { + "expression": { + "endPosition": "1184", + "kind": "FUNCTION_EXPRESSION", + "body": { + "endPosition": "1198", + "kind": "BLOCK", + "statements": [ + { + "expression": { + "endPosition": "1198", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "endPosition": "1196", + "kind": "IDENTIFIER", + "name": "foo", + "startPosition": "1193" + }, + "arguments": [], + "startPosition": "1193" + }, + "endPosition": "1198", + "kind": "RETURN", + "startPosition": "1186" + } + ], + "startPosition": "1184" + }, + "strict": "false", + "startPosition": "1184", + "parameters": [] + }, + "endPosition": "1201", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1172" + } + ], + "sourceName": "parsertests/returnStat.js", + "strict": "false", + "startPosition": "1118" +} +, +{ + "endPosition": "1111", + "kind": "COMPILATION_UNIT", + "sourceElements": [ + { + "cases": [], + "expression": { + "endPosition": "1122", + "kind": "IDENTIFIER", + "name": "key", + "startPosition": "1119" + }, + "endPosition": "1126", + "kind": "SWITCH", + "startPosition": "1111" + }, + { + "cases": [ + { + "expression": { + "endPosition": "1149", + "kind": "NUMBER_LITERAL", + "value": "2", + "startPosition": "1148" + }, + "endPosition": "1166", + "kind": "CASE", + "statements": [ + { + "expression": { + "endPosition": "1158", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "endPosition": "1156", + "kind": "IDENTIFIER", + "name": "hello", + "startPosition": "1151" + }, + "arguments": [], + "startPosition": "1151" + }, + "endPosition": "1158", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1151" + }, + { + "endPosition": "1166", + "kind": "BREAK", + "startPosition": "1160" + } + ], + "startPosition": "1143" + } + ], + "expression": { + "endPosition": "1139", + "kind": "IDENTIFIER", + "name": "key", + "startPosition": "1136" + }, + "endPosition": "1168", + "kind": "SWITCH", + "startPosition": "1128" + }, + { + "cases": [ + { + "expression": { + "endPosition": "1191", + "kind": "NUMBER_LITERAL", + "value": "4", + "startPosition": "1190" + }, + "endPosition": "1208", + "kind": "CASE", + "statements": [ + { + "expression": { + "endPosition": "1200", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "endPosition": "1198", + "kind": "IDENTIFIER", + "name": "hello", + "startPosition": "1193" + }, + "arguments": [], + "startPosition": "1193" + }, + "endPosition": "1200", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1193" + }, + { + "endPosition": "1208", + "kind": "BREAK", + "startPosition": "1202" + } + ], + "startPosition": "1185" + }, + { + "expression": { + "endPosition": "1215", + "kind": "NUMBER_LITERAL", + "value": "2", + "startPosition": "1214" + }, + "endPosition": "1232", + "kind": "CASE", + "statements": [ + { + "expression": { + "endPosition": "1224", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "endPosition": "1222", + "kind": "IDENTIFIER", + "name": "world", + "startPosition": "1217" + }, + "arguments": [], + "startPosition": "1217" + }, + "endPosition": "1224", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1217" + }, + { + "endPosition": "1232", + "kind": "BREAK", + "startPosition": "1226" + } + ], + "startPosition": "1209" + }, + { + "endPosition": "1247", + "kind": "CASE", + "statements": [ + { + "endPosition": "1247", + "kind": "BREAK", + "startPosition": "1242" + } + ], + "startPosition": "1233" + } + ], + "expression": { + "endPosition": "1181", + "kind": "IDENTIFIER", + "name": "key", + "startPosition": "1178" + }, + "endPosition": "1249", + "kind": "SWITCH", + "startPosition": "1170" + } + ], + "sourceName": "parsertests/switchStat.js", + "strict": "false", + "startPosition": "1111" +} +, +{ + "endPosition": "1110", + "kind": "COMPILATION_UNIT", + "sourceElements": [ + { + "expression": { + "endPosition": "1119", + "kind": "IDENTIFIER", + "name": "err", + "startPosition": "1116" + }, + "endPosition": "1120", + "kind": "THROW", + "startPosition": "1110" + }, + { + "expression": { + "endPosition": "1133", + "kind": "STRING_LITERAL", + "value": "wrong", + "startPosition": "1128" + }, + "endPosition": "1135", + "kind": "THROW", + "startPosition": "1121" + }, + { + "expression": { + "constructorExpression": { + "endPosition": "1155", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "endPosition": "1155", + "kind": "IDENTIFIER", + "name": "TypeError", + "startPosition": "1146" + }, + "arguments": [], + "startPosition": "1146" + }, + "endPosition": "1155", + "kind": "NEW", + "startPosition": "1142" + }, + "endPosition": "1156", + "kind": "THROW", + "startPosition": "1136" + }, + { + "expression": { + "constructorExpression": { + "endPosition": "1192", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "endPosition": "1176", + "kind": "IDENTIFIER", + "name": "TypeError", + "startPosition": "1167" + }, + "arguments": [ + { + "endPosition": "1190", + "kind": "STRING_LITERAL", + "value": "not an array", + "startPosition": "1178" + } + ], + "startPosition": "1167" + }, + "endPosition": "1192", + "kind": "NEW", + "startPosition": "1163" + }, + "endPosition": "1193", + "kind": "THROW", + "startPosition": "1157" + }, + { + "expression": { + "endPosition": "1217", + "kind": "OBJECT_LITERAL", + "startPosition": "1200", + "properties": [ + { + "endPosition": "1206", + "kind": "PROPERTY", + "value": { + "endPosition": "1214", + "kind": "STRING_LITERAL", + "value": "wrong!", + "startPosition": "1208" + }, + "startPosition": "1202", + "key": { + "endPosition": "1205", + "kind": "IDENTIFIER", + "name": "msg", + "startPosition": "1202" + } + } + ] + }, + "endPosition": "1218", + "kind": "THROW", + "startPosition": "1194" + } + ], + "sourceName": "parsertests/throwStat.js", + "strict": "false", + "startPosition": "1110" +} +, +{ + "endPosition": "1121", + "kind": "COMPILATION_UNIT", + "sourceElements": [ + { + "endPosition": "1142", + "kind": "TRY", + "catches": [ + { + "endPosition": "1142", + "kind": "CATCH", + "parameter": { + "endPosition": "1137", + "kind": "IDENTIFIER", + "name": "e", + "startPosition": "1136" + }, + "block": { + "endPosition": "1142", + "kind": "BLOCK", + "statements": [], + "startPosition": "1139" + }, + "startPosition": "1129" + } + ], + "block": { + "endPosition": "1128", + "kind": "BLOCK", + "statements": [], + "startPosition": "1125" + }, + "startPosition": "1121" + }, + { + "endPosition": "1175", + "kind": "TRY", + "catches": [ + { + "endPosition": "1164", + "kind": "CATCH", + "parameter": { + "endPosition": "1159", + "kind": "IDENTIFIER", + "name": "e", + "startPosition": "1158" + }, + "block": { + "endPosition": "1164", + "kind": "BLOCK", + "statements": [], + "startPosition": "1161" + }, + "startPosition": "1151" + } + ], + "block": { + "endPosition": "1150", + "kind": "BLOCK", + "statements": [], + "startPosition": "1147" + }, + "finallyBlock": { + "endPosition": "1175", + "kind": "BLOCK", + "statements": [], + "startPosition": "1173" + }, + "startPosition": "1143" + }, + { + "endPosition": "1194", + "kind": "TRY", + "catches": [], + "block": { + "endPosition": "1183", + "kind": "BLOCK", + "statements": [], + "startPosition": "1180" + }, + "finallyBlock": { + "endPosition": "1194", + "kind": "BLOCK", + "statements": [], + "startPosition": "1192" + }, + "startPosition": "1176" + }, + { + "endPosition": "1225", + "kind": "TRY", + "catches": [ + { + "endPosition": "1225", + "kind": "CATCH", + "parameter": { + "endPosition": "1211", + "kind": "IDENTIFIER", + "name": "e", + "startPosition": "1210" + }, + "block": { + "endPosition": "1225", + "kind": "BLOCK", + "statements": [ + { + "expression": { + "endPosition": "1223", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "endPosition": "1221", + "kind": "IDENTIFIER", + "name": "handle", + "startPosition": "1215" + }, + "arguments": [], + "startPosition": "1215" + }, + "endPosition": "1223", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1215" + } + ], + "startPosition": "1213" + }, + "startPosition": "1203" + } + ], + "block": { + "endPosition": "1202", + "kind": "BLOCK", + "statements": [], + "startPosition": "1199" + }, + "startPosition": "1195" + }, + { + "endPosition": "1283", + "kind": "TRY", + "catches": [ + { + "endPosition": "1263", + "kind": "CATCH", + "parameter": { + "endPosition": "1249", + "kind": "IDENTIFIER", + "name": "e", + "startPosition": "1248" + }, + "block": { + "endPosition": "1263", + "kind": "BLOCK", + "statements": [ + { + "expression": { + "endPosition": "1261", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "endPosition": "1259", + "kind": "IDENTIFIER", + "name": "handle", + "startPosition": "1253" + }, + "arguments": [], + "startPosition": "1253" + }, + "endPosition": "1261", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1253" + } + ], + "startPosition": "1251" + }, + "startPosition": "1241" + } + ], + "block": { + "endPosition": "1240", + "kind": "BLOCK", + "statements": [ + { + "expression": { + "endPosition": "1238", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "endPosition": "1236", + "kind": "IDENTIFIER", + "name": "that", + "startPosition": "1232" + }, + "arguments": [], + "startPosition": "1232" + }, + "endPosition": "1238", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1232" + } + ], + "startPosition": "1230" + }, + "finallyBlock": { + "endPosition": "1283", + "kind": "BLOCK", + "statements": [ + { + "expression": { + "endPosition": "1281", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "endPosition": "1279", + "kind": "IDENTIFIER", + "name": "clean", + "startPosition": "1274" + }, + "arguments": [], + "startPosition": "1274" + }, + "endPosition": "1281", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1274" + } + ], + "startPosition": "1272" + }, + "startPosition": "1226" + }, + { + "endPosition": "1368", + "kind": "TRY", + "catches": [ + { + "condition": { + "leftOperand": { + "endPosition": "1312", + "kind": "IDENTIFIER", + "name": "e", + "startPosition": "1311" + }, + "expression": { + "endPosition": "1312", + "kind": "IDENTIFIER", + "name": "e", + "startPosition": "1311" + }, + "endPosition": "1333", + "kind": "INSTANCE_OF", + "rightOperand": { + "endPosition": "1333", + "kind": "IDENTIFIER", + "name": "TypeError", + "startPosition": "1324" + }, + "type": { + "endPosition": "1333", + "kind": "IDENTIFIER", + "name": "TypeError", + "startPosition": "1324" + }, + "startPosition": "1311" + }, + "endPosition": "1347", + "kind": "CATCH", + "parameter": { + "endPosition": "1307", + "kind": "IDENTIFIER", + "name": "e", + "startPosition": "1306" + }, + "block": { + "endPosition": "1347", + "kind": "BLOCK", + "statements": [ + { + "expression": { + "endPosition": "1345", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "endPosition": "1343", + "kind": "IDENTIFIER", + "name": "handle", + "startPosition": "1337" + }, + "arguments": [], + "startPosition": "1337" + }, + "endPosition": "1345", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1337" + } + ], + "startPosition": "1335" + }, + "startPosition": "1299" + }, + { + "endPosition": "1368", + "kind": "CATCH", + "parameter": { + "endPosition": "1356", + "kind": "IDENTIFIER", + "name": "e", + "startPosition": "1355" + }, + "block": { + "endPosition": "1368", + "kind": "BLOCK", + "statements": [ + { + "expression": { + "endPosition": "1366", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "endPosition": "1364", + "kind": "IDENTIFIER", + "name": "rest", + "startPosition": "1360" + }, + "arguments": [], + "startPosition": "1360" + }, + "endPosition": "1366", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1360" + } + ], + "startPosition": "1358" + }, + "startPosition": "1348" + } + ], + "block": { + "endPosition": "1298", + "kind": "BLOCK", + "statements": [ + { + "expression": { + "endPosition": "1296", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "endPosition": "1294", + "kind": "IDENTIFIER", + "name": "that", + "startPosition": "1290" + }, + "arguments": [], + "startPosition": "1290" + }, + "endPosition": "1296", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1290" + } + ], + "startPosition": "1288" + }, + "startPosition": "1284" + } + ], + "sourceName": "parsertests/tryCatchStat.js", + "strict": "false", + "startPosition": "1121" +} +, +{ + "endPosition": "1115", + "kind": "COMPILATION_UNIT", + "sourceElements": [ + { + "expression": { + "expression": { + "endPosition": "1116", + "kind": "IDENTIFIER", + "name": "x", + "startPosition": "1115" + }, + "endPosition": "1118", + "kind": "POSTFIX_INCREMENT", + "startPosition": "1115" + }, + "endPosition": "1118", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1115" + }, + { + "expression": { + "expression": { + "endPosition": "1121", + "kind": "IDENTIFIER", + "name": "x", + "startPosition": "1120" + }, + "endPosition": "1123", + "kind": "POSTFIX_DECREMENT", + "startPosition": "1120" + }, + "endPosition": "1123", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1120" + }, + { + "expression": { + "expression": { + "endPosition": "1133", + "kind": "IDENTIFIER", + "name": "x", + "startPosition": "1132" + }, + "endPosition": "1133", + "kind": "DELETE", + "startPosition": "1125" + }, + "endPosition": "1133", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1125" + }, + { + "expression": { + "expression": { + "endPosition": "1141", + "kind": "IDENTIFIER", + "name": "x", + "startPosition": "1140" + }, + "endPosition": "1141", + "kind": "VOID", + "startPosition": "1135" + }, + "endPosition": "1141", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1135" + }, + { + "expression": { + "expression": { + "endPosition": "1151", + "kind": "IDENTIFIER", + "name": "x", + "startPosition": "1150" + }, + "endPosition": "1151", + "kind": "TYPEOF", + "startPosition": "1143" + }, + "endPosition": "1151", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1143" + }, + { + "expression": { + "expression": { + "endPosition": "1156", + "kind": "IDENTIFIER", + "name": "x", + "startPosition": "1155" + }, + "endPosition": "1156", + "kind": "PREFIX_INCREMENT", + "startPosition": "1153" + }, + "endPosition": "1156", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1153" + }, + { + "expression": { + "expression": { + "endPosition": "1161", + "kind": "IDENTIFIER", + "name": "x", + "startPosition": "1160" + }, + "endPosition": "1161", + "kind": "PREFIX_DECREMENT", + "startPosition": "1158" + }, + "endPosition": "1161", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1158" + }, + { + "expression": { + "expression": { + "endPosition": "1165", + "kind": "IDENTIFIER", + "name": "x", + "startPosition": "1164" + }, + "endPosition": "1165", + "kind": "PLUS", + "startPosition": "1163" + }, + "endPosition": "1165", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1163" + }, + { + "expression": { + "expression": { + "endPosition": "1169", + "kind": "IDENTIFIER", + "name": "x", + "startPosition": "1168" + }, + "endPosition": "1169", + "kind": "MINUS", + "startPosition": "1167" + }, + "endPosition": "1169", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1167" + }, + { + "expression": { + "expression": { + "endPosition": "1173", + "kind": "IDENTIFIER", + "name": "x", + "startPosition": "1172" + }, + "endPosition": "1173", + "kind": "BITWISE_COMPLEMENT", + "startPosition": "1171" + }, + "endPosition": "1173", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1171" + }, + { + "expression": { + "expression": { + "endPosition": "1177", + "kind": "IDENTIFIER", + "name": "x", + "startPosition": "1176" + }, + "endPosition": "1177", + "kind": "LOGICAL_COMPLEMENT", + "startPosition": "1175" + }, + "endPosition": "1177", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1175" + } + ], + "sourceName": "parsertests/unaryExpr.js", + "strict": "false", + "startPosition": "1115" +} +, +{ + "endPosition": "1122", + "kind": "COMPILATION_UNIT", + "sourceElements": [ + { + "endPosition": "1165", + "kind": "FUNCTION", + "name": "f", + "body": { + "endPosition": "1162", + "kind": "BLOCK", + "statements": [ + { + "expression": { + "endPosition": "1162", + "kind": "STRING_LITERAL", + "value": "use strict", + "startPosition": "1152" + }, + "endPosition": "1162", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1152" + } + ], + "startPosition": "1149" + }, + "strict": "true", + "startPosition": "1136", + "parameters": [] + }, + { + "expression": { + "endPosition": "1133", + "kind": "STRING_LITERAL", + "value": "use strict", + "startPosition": "1123" + }, + "endPosition": "1133", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1123" + } + ], + "sourceName": "parsertests/useStrict.js", + "strict": "true", + "startPosition": "1122" +} +, +{ + "endPosition": "1143", + "kind": "COMPILATION_UNIT", + "sourceElements": [ + { + "endPosition": "1148", + "kind": "VARIABLE", + "name": "a", + "startPosition": "1147" + }, + { + "endPosition": "1155", + "kind": "VARIABLE", + "name": "a", + "startPosition": "1154" + }, + { + "endPosition": "1158", + "kind": "VARIABLE", + "name": "b", + "startPosition": "1157" + }, + { + "endPosition": "1200", + "kind": "VARIABLE", + "name": "a", + "startPosition": "1190", + "initializer": { + "endPosition": "1200", + "kind": "STRING_LITERAL", + "value": "hello", + "startPosition": "1195" + } + }, + { + "endPosition": "1212", + "kind": "VARIABLE", + "name": "a", + "startPosition": "1207", + "initializer": { + "endPosition": "1212", + "kind": "NUMBER_LITERAL", + "value": "1", + "startPosition": "1211" + } + }, + { + "endPosition": "1219", + "kind": "VARIABLE", + "name": "b", + "startPosition": "1214", + "initializer": { + "endPosition": "1219", + "kind": "NUMBER_LITERAL", + "value": "2", + "startPosition": "1218" + } + }, + { + "endPosition": "1226", + "kind": "VARIABLE", + "name": "c", + "startPosition": "1221", + "initializer": { + "endPosition": "1226", + "kind": "NUMBER_LITERAL", + "value": "3", + "startPosition": "1225" + } + } + ], + "sourceName": "parsertests/varDecl.js", + "strict": "false", + "startPosition": "1143" +} +, +{ + "endPosition": "1111", + "kind": "COMPILATION_UNIT", + "sourceElements": [ + { + "endPosition": "1133", + "kind": "WITH", + "scope": { + "endPosition": "1122", + "kind": "IDENTIFIER", + "name": "scope", + "startPosition": "1117" + }, + "statement": { + "endPosition": "1133", + "kind": "BLOCK", + "statements": [ + { + "expression": { + "expression": { + "endPosition": "1131", + "kind": "IDENTIFIER", + "name": "y", + "startPosition": "1130" + }, + "endPosition": "1131", + "kind": "ASSIGNMENT", + "variable": { + "endPosition": "1127", + "kind": "IDENTIFIER", + "name": "x", + "startPosition": "1126" + }, + "startPosition": "1126" + }, + "endPosition": "1131", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1126" + } + ], + "startPosition": "1124" + }, + "startPosition": "1111" + } + ], + "sourceName": "parsertests/withStat.js", + "strict": "false", + "startPosition": "1111" +} +, +{ + "fileName": "parsernegativetests/caseoutofswitch.js", + "code": "case (1090, 4)", + "columnNumber": "0", + "kind": "ERROR", + "position": "1090", + "message": "parsernegativetests/caseoutofswitch.js:29:0 Expected an operand but found case\ncase 23:\n^", + "lineNumber": "29" +} +, +{ + "fileName": "parsernegativetests/caseoutofswitch.js", + "code": "default (1112, 7)", + "columnNumber": "0", + "kind": "ERROR", + "position": "1112", + "message": "parsernegativetests/caseoutofswitch.js:31:0 Expected an operand but found default\ndefault:\n^", + "lineNumber": "31" +} +, +{ + "endPosition": "1090", + "kind": "COMPILATION_UNIT", + "sourceElements": [ + { + "expression": { + "endPosition": "1098", + "kind": "ERROR", + "startPosition": "1090" + }, + "endPosition": "1098", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1090" + }, + { + "expression": { + "endPosition": "1110", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "endPosition": "1104", + "kind": "IDENTIFIER", + "name": "print", + "startPosition": "1099" + }, + "arguments": [ + { + "endPosition": "1108", + "kind": "STRING_LITERAL", + "value": "23", + "startPosition": "1106" + } + ], + "startPosition": "1099" + }, + "endPosition": "1110", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1099" + }, + { + "expression": { + "endPosition": "1120", + "kind": "ERROR", + "startPosition": "1112" + }, + "endPosition": "1120", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1112" + }, + { + "expression": { + "endPosition": "1135", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "endPosition": "1126", + "kind": "IDENTIFIER", + "name": "print", + "startPosition": "1121" + }, + "arguments": [ + { + "endPosition": "1133", + "kind": "STRING_LITERAL", + "value": "hello", + "startPosition": "1128" + } + ], + "startPosition": "1121" + }, + "endPosition": "1135", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1121" + } + ], + "sourceName": "parsernegativetests/caseoutofswitch.js", + "strict": "false", + "startPosition": "1090" +} +, +{ + "fileName": "parsernegativetests/illegalbreak.js", + "code": "break (1090, 5)", + "columnNumber": "0", + "kind": "ERROR", + "position": "1090", + "message": "parsernegativetests/illegalbreak.js:29:0 Illegal break statement\nbreak;\n^", + "lineNumber": "29" +} +, +{ + "fileName": "parsernegativetests/illegalbreak.js", + "code": "ident (1103, 3)", + "columnNumber": "6", + "kind": "ERROR", + "position": "1103", + "message": "parsernegativetests/illegalbreak.js:30:6 Undefined Label \"foo\"\nbreak foo;\n ^", + "lineNumber": "30" +} +, +{ + "endPosition": "1090", + "kind": "COMPILATION_UNIT", + "sourceElements": [ + { + "expression": { + "endPosition": "1096", + "kind": "ERROR", + "startPosition": "1095" + }, + "endPosition": "1096", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1095" + }, + { + "expression": { + "endPosition": "1107", + "kind": "ERROR", + "startPosition": "1106" + }, + "endPosition": "1107", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1106" + } + ], + "sourceName": "parsernegativetests/illegalbreak.js", + "strict": "false", + "startPosition": "1090" +} +, +{ + "fileName": "parsernegativetests/illegalcontinue.js", + "code": "continue (1090, 8)", + "columnNumber": "0", + "kind": "ERROR", + "position": "1090", + "message": "parsernegativetests/illegalcontinue.js:29:0 Illegal continue statement\ncontinue;\n^", + "lineNumber": "29" +} +, +{ + "fileName": "parsernegativetests/illegalcontinue.js", + "code": "ident (1109, 3)", + "columnNumber": "9", + "kind": "ERROR", + "position": "1109", + "message": "parsernegativetests/illegalcontinue.js:30:9 Undefined Label \"foo\"\ncontinue foo;\n ^", + "lineNumber": "30" +} +, +{ + "endPosition": "1090", + "kind": "COMPILATION_UNIT", + "sourceElements": [ + { + "expression": { + "endPosition": "1099", + "kind": "ERROR", + "startPosition": "1098" + }, + "endPosition": "1099", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1098" + }, + { + "expression": { + "endPosition": "1113", + "kind": "ERROR", + "startPosition": "1112" + }, + "endPosition": "1113", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1112" + } + ], + "sourceName": "parsernegativetests/illegalcontinue.js", + "strict": "false", + "startPosition": "1090" +} +, +{ + "fileName": "parsernegativetests/illegallvalue.js", + "code": "decimal (1090, 2)", + "columnNumber": "0", + "kind": "ERROR", + "position": "1090", + "message": "parsernegativetests/illegallvalue.js:29:0 Invalid left hand side for assignment\n44 = 54;\n^", + "lineNumber": "29" +} +, +{ + "fileName": "parsernegativetests/illegallvalue.js", + "code": "decimal (1099, 3)", + "columnNumber": "0", + "kind": "ERROR", + "position": "1099", + "message": "parsernegativetests/illegallvalue.js:30:0 Invalid left hand side for assignment\n233 += 33;\n^", + "lineNumber": "30" +} +, +{ + "fileName": "parsernegativetests/illegallvalue.js", + "code": "decimal (1110, 4)", + "columnNumber": "0", + "kind": "ERROR", + "position": "1110", + "message": "parsernegativetests/illegallvalue.js:31:0 Invalid left hand side for assignment\n3423 -= 234;\n^", + "lineNumber": "31" +} +, +{ + "endPosition": "1090", + "kind": "COMPILATION_UNIT", + "sourceElements": [ + { + "expression": { + "endPosition": "1098", + "kind": "ERROR", + "startPosition": "1097" + }, + "endPosition": "1098", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1097" + }, + { + "expression": { + "endPosition": "1109", + "kind": "ERROR", + "startPosition": "1108" + }, + "endPosition": "1109", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1108" + }, + { + "expression": { + "endPosition": "1122", + "kind": "ERROR", + "startPosition": "1121" + }, + "endPosition": "1122", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1121" + } + ], + "sourceName": "parsernegativetests/illegallvalue.js", + "strict": "false", + "startPosition": "1090" +} +, +{ + "fileName": "parsernegativetests/illegaloperator.js", + "code": "* (1093, 1)", + "columnNumber": "3", + "kind": "ERROR", + "position": "1093", + "message": "parsernegativetests/illegaloperator.js:29:3 Expected an operand but found *\nx ** y\n ^", + "lineNumber": "29" +} +, +{ + "endPosition": "1090", + "kind": "COMPILATION_UNIT", + "sourceElements": [ + { + "expression": { + "endPosition": "1096", + "kind": "ERROR", + "startPosition": "1093" + }, + "endPosition": "1096", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1093" + } + ], + "sourceName": "parsernegativetests/illegaloperator.js", + "strict": "false", + "startPosition": "1090" +} +, +{ + "fileName": "parsernegativetests/keywordident.js", + "code": "var (1094, 3)", + "columnNumber": "4", + "kind": "ERROR", + "position": "1094", + "message": "parsernegativetests/keywordident.js:29:4 Expected ident but found var\nvar var = 23;\n ^", + "lineNumber": "29" +} +, +{ + "endPosition": "1090", + "kind": "COMPILATION_UNIT", + "sourceElements": [ + { + "expression": { + "endPosition": "1103", + "kind": "ERROR", + "startPosition": "1094" + }, + "endPosition": "1103", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1094" + }, + { + "endPosition": "1115", + "kind": "VARIABLE", + "name": "x", + "startPosition": "1108", + "initializer": { + "endPosition": "1115", + "kind": "NUMBER_LITERAL", + "value": "223", + "startPosition": "1112" + } + } + ], + "sourceName": "parsernegativetests/keywordident.js", + "strict": "false", + "startPosition": "1090" +} +, +{ + "fileName": "parsernegativetests/parenmissing.js", + "code": "; (1096, 1)", + "columnNumber": "6", + "kind": "ERROR", + "position": "1096", + "message": "parsernegativetests/parenmissing.js:29:6 Expected ) but found ;\n(1 + 2;\n ^", + "lineNumber": "29" +} +, +{ + "fileName": "parsernegativetests/parenmissing.js", + "code": ") (1103, 1)", + "columnNumber": "5", + "kind": "ERROR", + "position": "1103", + "message": "parsernegativetests/parenmissing.js:30:5 Expected ; but found )\nx * y);\n ^", + "lineNumber": "30" +} +, +{ + "endPosition": "1090", + "kind": "COMPILATION_UNIT", + "sourceElements": [ + { + "expression": { + "endPosition": "1097", + "kind": "ERROR", + "startPosition": "1096" + }, + "endPosition": "1097", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1096" + }, + { + "expression": { + "leftOperand": { + "endPosition": "1099", + "kind": "IDENTIFIER", + "name": "x", + "startPosition": "1098" + }, + "endPosition": "1103", + "kind": "MULTIPLY", + "rightOperand": { + "endPosition": "1103", + "kind": "IDENTIFIER", + "name": "y", + "startPosition": "1102" + }, + "startPosition": "1098" + }, + "endPosition": "1103", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1098" + }, + { + "expression": { + "endPosition": "1105", + "kind": "ERROR", + "startPosition": "1103" + }, + "endPosition": "1105", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1103" + } + ], + "sourceName": "parsernegativetests/parenmissing.js", + "strict": "false", + "startPosition": "1090" +} +, +{ + "fileName": "parsernegativetests/repeatedproperty.js", + "code": "ident (1111, 3)", + "columnNumber": "21", + "kind": "ERROR", + "position": "1111", + "message": "parsernegativetests/repeatedproperty.js:29:21 Property \"foo\" already defined\nvar obj = { foo: 34, get foo() { return 'hello' } };\n ^", + "lineNumber": "29" +} +, +{ + "fileName": "parsernegativetests/repeatedproperty.js", + "code": "ident (1165, 3)", + "columnNumber": "22", + "kind": "ERROR", + "position": "1165", + "message": "parsernegativetests/repeatedproperty.js:30:22 Property \"foo\" already defined\nvar obj1 = { foo: 34, set foo(x) { } };\n ^", + "lineNumber": "30" +} +, +{ + "fileName": "parsernegativetests/repeatedproperty.js", + "code": "ident (1205, 3)", + "columnNumber": "22", + "kind": "ERROR", + "position": "1205", + "message": "parsernegativetests/repeatedproperty.js:31:22 Property \"foo\" already defined\nvar obj2 = { foo: 34, set foo(x) { } };\n ^", + "lineNumber": "31" +} +, +{ + "fileName": "parsernegativetests/repeatedproperty.js", + "code": "ident (1251, 3)", + "columnNumber": "28", + "kind": "ERROR", + "position": "1251", + "message": "parsernegativetests/repeatedproperty.js:32:28 Property \"bar\" already defined\nvar obj3 = { get bar() { }, get bar() {} };\n ^", + "lineNumber": "32" +} +, +{ + "fileName": "parsernegativetests/repeatedproperty.js", + "code": "ident (1296, 3)", + "columnNumber": "29", + "kind": "ERROR", + "position": "1296", + "message": "parsernegativetests/repeatedproperty.js:33:29 Property \"bar\" already defined\nvar obj4 = { set bar(x) { }, set bar(x) {} };\n ^", + "lineNumber": "33" +} +, +{ + "endPosition": "1090", + "kind": "COMPILATION_UNIT", + "sourceElements": [ + { + "expression": { + "endPosition": "1141", + "kind": "ERROR", + "startPosition": "1140" + }, + "endPosition": "1141", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1140" + }, + { + "expression": { + "endPosition": "1181", + "kind": "ERROR", + "startPosition": "1180" + }, + "endPosition": "1181", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1180" + }, + { + "expression": { + "endPosition": "1221", + "kind": "ERROR", + "startPosition": "1220" + }, + "endPosition": "1221", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1220" + }, + { + "expression": { + "endPosition": "1265", + "kind": "ERROR", + "startPosition": "1264" + }, + "endPosition": "1265", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1264" + }, + { + "expression": { + "endPosition": "1311", + "kind": "ERROR", + "startPosition": "1310" + }, + "endPosition": "1311", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1310" + } + ], + "sourceName": "parsernegativetests/repeatedproperty.js", + "strict": "false", + "startPosition": "1090" +} +, +{ + "fileName": "parsernegativetests/strict_repeatedproperty.js", + "code": "ident (1126, 3)", + "columnNumber": "21", + "kind": "ERROR", + "position": "1126", + "message": "parsernegativetests/strict_repeatedproperty.js:31:21 Property \"foo\" already defined\nvar obj = { foo: 34, foo: 'hello' };\n ^", + "lineNumber": "31" +} +, +{ + "endPosition": "1090", + "kind": "COMPILATION_UNIT", + "sourceElements": [ + { + "expression": { + "endPosition": "1101", + "kind": "STRING_LITERAL", + "value": "use strict", + "startPosition": "1091" + }, + "endPosition": "1101", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1091" + }, + { + "expression": { + "endPosition": "1140", + "kind": "ERROR", + "startPosition": "1139" + }, + "endPosition": "1140", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1139" + } + ], + "sourceName": "parsernegativetests/strict_repeatedproperty.js", + "strict": "true", + "startPosition": "1090" +} +, +{ + "fileName": "parsernegativetests/strict_repeatparam.js", + "code": "ident (1119, 1)", + "columnNumber": "14", + "kind": "ERROR", + "position": "1119", + "message": "parsernegativetests/strict_repeatparam.js:31:14 strict mode function cannot have duplicate parameter name \"x\"\nfunction func(x, x) {}\n ^", + "lineNumber": "31" +} +, +{ + "endPosition": "1090", + "kind": "COMPILATION_UNIT", + "sourceElements": [ + { + "expression": { + "endPosition": "1101", + "kind": "STRING_LITERAL", + "value": "use strict", + "startPosition": "1091" + }, + "endPosition": "1101", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1091" + }, + { + "expression": { + "endPosition": "1127", + "kind": "ERROR", + "startPosition": "1128" + }, + "endPosition": "1127", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1128" + } + ], + "sourceName": "parsernegativetests/strict_repeatparam.js", + "strict": "true", + "startPosition": "1090" +} +, +{ + "fileName": "parsernegativetests/strict_with.js", + "code": "with (1105, 4)", + "columnNumber": "0", + "kind": "ERROR", + "position": "1105", + "message": "parsernegativetests/strict_with.js:31:0 \"with\" statement cannot be used in strict mode\nwith({}) {}\n^", + "lineNumber": "31" +} +, +{ + "fileName": "parsernegativetests/strict_with.js", + "code": ") (1112, 1)", + "columnNumber": "7", + "kind": "ERROR", + "position": "1112", + "message": "parsernegativetests/strict_with.js:31:7 Expected ; but found )\nwith({}) {}\n ^", + "lineNumber": "31" +} +, +{ + "endPosition": "1090", + "kind": "COMPILATION_UNIT", + "sourceElements": [ + { + "expression": { + "endPosition": "1101", + "kind": "STRING_LITERAL", + "value": "use strict", + "startPosition": "1091" + }, + "endPosition": "1101", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1091" + }, + { + "expression": { + "endPosition": "1112", + "kind": "ERROR", + "startPosition": "1109" + }, + "endPosition": "1112", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1109" + }, + { + "expression": { + "endPosition": "1116", + "kind": "ERROR", + "startPosition": "1112" + }, + "endPosition": "1116", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1112" + } + ], + "sourceName": "parsernegativetests/strict_with.js", + "strict": "true", + "startPosition": "1090" +} +, +{ + "fileName": "parsernegativetests/toplevelreturn.js", + "code": "return (1090, 6)", + "columnNumber": "0", + "kind": "ERROR", + "position": "1090", + "message": "parsernegativetests/toplevelreturn.js:29:0 Invalid return statement\nreturn;\n^", + "lineNumber": "29" +} +, +{ + "fileName": "parsernegativetests/toplevelreturn.js", + "code": "return (1098, 6)", + "columnNumber": "0", + "kind": "ERROR", + "position": "1098", + "message": "parsernegativetests/toplevelreturn.js:30:0 Invalid return statement\nreturn 23;\n^", + "lineNumber": "30" +} +, +{ + "endPosition": "1090", + "kind": "COMPILATION_UNIT", + "sourceElements": [ + { + "expression": { + "endPosition": "1097", + "kind": "ERROR", + "startPosition": "1090" + }, + "endPosition": "1097", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1090" + }, + { + "expression": { + "endPosition": "1108", + "kind": "ERROR", + "startPosition": "1098" + }, + "endPosition": "1108", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1098" + } + ], + "sourceName": "parsernegativetests/toplevelreturn.js", + "strict": "false", + "startPosition": "1090" +} +, +{ + "endPosition": "1136", + "kind": "COMPILATION_UNIT", + "sourceElements": [ + { + "endPosition": "1240", + "kind": "FUNCTION", + "name": "Parser", + "body": { + "endPosition": "1218", + "kind": "BLOCK", + "statements": [ + { + "expression": { + "expression": { + "endPosition": "1217", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "identifier": "create", + "expression": { + "endPosition": "1208", + "kind": "IDENTIFIER", + "name": "Parser", + "startPosition": "1202" + }, + "endPosition": "1215", + "kind": "MEMBER_SELECT", + "startPosition": "1202" + }, + "arguments": [], + "startPosition": "1202" + }, + "endPosition": "1217", + "kind": "ASSIGNMENT", + "variable": { + "identifier": "_parser", + "expression": { + "endPosition": "1191", + "kind": "IDENTIFIER", + "name": "this", + "startPosition": "1187" + }, + "endPosition": "1199", + "kind": "MEMBER_SELECT", + "startPosition": "1187" + }, + "startPosition": "1187" + }, + "endPosition": "1217", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1187" + } + ], + "startPosition": "1154" + }, + "strict": "false", + "startPosition": "1136", + "parameters": [] + }, + { + "endPosition": "3598", + "kind": "FUNCTION", + "name": "processFiles", + "body": { + "endPosition": "3555", + "kind": "BLOCK", + "statements": [ + { + "endPosition": "2938", + "kind": "VARIABLE", + "name": "File", + "startPosition": "2906", + "initializer": { + "endPosition": "2938", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "identifier": "type", + "expression": { + "endPosition": "2917", + "kind": "IDENTIFIER", + "name": "Java", + "startPosition": "2913" + }, + "endPosition": "2922", + "kind": "MEMBER_SELECT", + "startPosition": "2913" + }, + "arguments": [ + { + "endPosition": "2936", + "kind": "STRING_LITERAL", + "value": "java.io.File", + "startPosition": "2924" + } + ], + "startPosition": "2913" + } + }, + { + "endPosition": "2993", + "kind": "VARIABLE", + "name": "files", + "startPosition": "2947", + "initializer": { + "endPosition": "2993", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "identifier": "listFiles", + "expression": { + "constructorExpression": { + "endPosition": "2981", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "endPosition": "2963", + "kind": "IDENTIFIER", + "name": "File", + "startPosition": "2959" + }, + "arguments": [ + { + "leftOperand": { + "endPosition": "2971", + "kind": "IDENTIFIER", + "name": "__DIR__", + "startPosition": "2964" + }, + "endPosition": "2980", + "kind": "PLUS", + "rightOperand": { + "endPosition": "2980", + "kind": "IDENTIFIER", + "name": "subdir", + "startPosition": "2974" + }, + "startPosition": "2964" + } + ], + "startPosition": "2959" + }, + "endPosition": "2981", + "kind": "NEW", + "startPosition": "2955" + }, + "endPosition": "2991", + "kind": "MEMBER_SELECT", + "startPosition": "2955" + }, + "arguments": [], + "startPosition": "2955" + } + }, + { + "expression": { + "endPosition": "3026", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "identifier": "sort", + "expression": { + "identifier": "Arrays", + "expression": { + "identifier": "util", + "expression": { + "endPosition": "3002", + "kind": "IDENTIFIER", + "name": "java", + "startPosition": "2998" + }, + "endPosition": "3007", + "kind": "MEMBER_SELECT", + "startPosition": "2998" + }, + "endPosition": "3014", + "kind": "MEMBER_SELECT", + "startPosition": "2998" + }, + "endPosition": "3019", + "kind": "MEMBER_SELECT", + "startPosition": "2998" + }, + "arguments": [ + { + "endPosition": "3025", + "kind": "IDENTIFIER", + "name": "files", + "startPosition": "3020" + } + ], + "startPosition": "2998" + }, + "endPosition": "3026", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "2998" + }, + { + "endPosition": "3049", + "kind": "VARIABLE", + "name": "file", + "startPosition": "3045" + }, + { + "expression": { + "endPosition": "3058", + "kind": "IDENTIFIER", + "name": "files", + "startPosition": "3053" + }, + "endPosition": "3555", + "kind": "FOR_IN_LOOP", + "forEach": "true", + "variable": { + "endPosition": "3049", + "kind": "IDENTIFIER", + "name": "file", + "startPosition": "3045" + }, + "statement": { + "endPosition": "3555", + "kind": "BLOCK", + "statements": [ + { + "condition": { + "endPosition": "3098", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "identifier": "endsWith", + "expression": { + "identifier": "name", + "expression": { + "endPosition": "3077", + "kind": "IDENTIFIER", + "name": "file", + "startPosition": "3073" + }, + "endPosition": "3082", + "kind": "MEMBER_SELECT", + "startPosition": "3073" + }, + "endPosition": "3091", + "kind": "MEMBER_SELECT", + "startPosition": "3073" + }, + "arguments": [ + { + "endPosition": "3096", + "kind": "STRING_LITERAL", + "value": ".js", + "startPosition": "3093" + } + ], + "startPosition": "3073" + }, + "endPosition": "3550", + "kind": "IF", + "startPosition": "3069", + "thenStatement": { + "endPosition": "3550", + "kind": "BLOCK", + "statements": [ + { + "endPosition": "3141", + "kind": "VARIABLE", + "name": "script", + "startPosition": "3117", + "initializer": { + "endPosition": "3141", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "endPosition": "3135", + "kind": "IDENTIFIER", + "name": "readFully", + "startPosition": "3126" + }, + "arguments": [ + { + "endPosition": "3140", + "kind": "IDENTIFIER", + "name": "file", + "startPosition": "3136" + } + ], + "startPosition": "3126" + } + }, + { + "endPosition": "3179", + "kind": "VARIABLE", + "name": "parser", + "startPosition": "3158", + "initializer": { + "constructorExpression": { + "endPosition": "3179", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "endPosition": "3177", + "kind": "IDENTIFIER", + "name": "Parser", + "startPosition": "3171" + }, + "arguments": [], + "startPosition": "3171" + }, + "endPosition": "3179", + "kind": "NEW", + "startPosition": "3167" + } + }, + { + "endPosition": "3415", + "kind": "VARIABLE", + "name": "tree", + "startPosition": "3196", + "initializer": { + "endPosition": "3415", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "identifier": "parse", + "expression": { + "endPosition": "3209", + "kind": "IDENTIFIER", + "name": "parser", + "startPosition": "3203" + }, + "endPosition": "3215", + "kind": "MEMBER_SELECT", + "startPosition": "3203" + }, + "arguments": [ + { + "leftOperand": { + "leftOperand": { + "endPosition": "3222", + "kind": "IDENTIFIER", + "name": "subdir", + "startPosition": "3216" + }, + "endPosition": "3227", + "kind": "PLUS", + "rightOperand": { + "endPosition": "3227", + "kind": "STRING_LITERAL", + "value": "/", + "startPosition": "3226" + }, + "startPosition": "3216" + }, + "endPosition": "3240", + "kind": "PLUS", + "rightOperand": { + "identifier": "name", + "expression": { + "endPosition": "3235", + "kind": "IDENTIFIER", + "name": "file", + "startPosition": "3231" + }, + "endPosition": "3240", + "kind": "MEMBER_SELECT", + "startPosition": "3231" + }, + "startPosition": "3216" + }, + { + "endPosition": "3248", + "kind": "IDENTIFIER", + "name": "script", + "startPosition": "3242" + }, + { + "endPosition": "3286", + "kind": "FUNCTION_EXPRESSION", + "body": { + "endPosition": "3397", + "kind": "BLOCK", + "statements": [ + { + "expression": { + "endPosition": "3365", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "endPosition": "3312", + "kind": "IDENTIFIER", + "name": "print", + "startPosition": "3307" + }, + "arguments": [ + { + "endPosition": "3364", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "identifier": "stringify", + "expression": { + "endPosition": "3317", + "kind": "IDENTIFIER", + "name": "JSON", + "startPosition": "3313" + }, + "endPosition": "3327", + "kind": "MEMBER_SELECT", + "startPosition": "3313" + }, + "arguments": [ + { + "endPosition": "3354", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "identifier": "convert", + "expression": { + "endPosition": "3334", + "kind": "IDENTIFIER", + "name": "parser", + "startPosition": "3328" + }, + "endPosition": "3342", + "kind": "MEMBER_SELECT", + "startPosition": "3328" + }, + "arguments": [ + { + "endPosition": "3353", + "kind": "IDENTIFIER", + "name": "diagnostic", + "startPosition": "3343" + } + ], + "startPosition": "3328" + }, + { + "endPosition": "3360", + "kind": "NULL_LITERAL", + "startPosition": "3356" + }, + { + "endPosition": "3363", + "kind": "NUMBER_LITERAL", + "value": "2", + "startPosition": "3362" + } + ], + "startPosition": "3313" + } + ], + "startPosition": "3307" + }, + "endPosition": "3365", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "3307" + }, + { + "expression": { + "endPosition": "3396", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "endPosition": "3391", + "kind": "IDENTIFIER", + "name": "print", + "startPosition": "3386" + }, + "arguments": [ + { + "endPosition": "3394", + "kind": "STRING_LITERAL", + "value": ",", + "startPosition": "3393" + } + ], + "startPosition": "3386" + }, + "endPosition": "3396", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "3386" + } + ], + "startPosition": "3286" + }, + "strict": "false", + "startPosition": "3286", + "parameters": [ + { + "endPosition": "3284", + "kind": "IDENTIFIER", + "name": "diagnostic", + "startPosition": "3274" + } + ] + } + ], + "startPosition": "3203" + } + }, + { + "condition": { + "leftOperand": { + "endPosition": "3437", + "kind": "IDENTIFIER", + "name": "tree", + "startPosition": "3433" + }, + "endPosition": "3445", + "kind": "NOT_EQUAL_TO", + "rightOperand": { + "endPosition": "3445", + "kind": "NULL_LITERAL", + "startPosition": "3441" + }, + "startPosition": "3433" + }, + "endPosition": "3541", + "kind": "IF", + "startPosition": "3429", + "thenStatement": { + "endPosition": "3541", + "kind": "BLOCK", + "statements": [ + { + "expression": { + "endPosition": "3500", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "endPosition": "3469", + "kind": "IDENTIFIER", + "name": "print", + "startPosition": "3464" + }, + "arguments": [ + { + "endPosition": "3499", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "identifier": "stringify", + "expression": { + "endPosition": "3474", + "kind": "IDENTIFIER", + "name": "JSON", + "startPosition": "3470" + }, + "endPosition": "3484", + "kind": "MEMBER_SELECT", + "startPosition": "3470" + }, + "arguments": [ + { + "endPosition": "3489", + "kind": "IDENTIFIER", + "name": "tree", + "startPosition": "3485" + }, + { + "endPosition": "3495", + "kind": "NULL_LITERAL", + "startPosition": "3491" + }, + { + "endPosition": "3498", + "kind": "NUMBER_LITERAL", + "value": "2", + "startPosition": "3497" + } + ], + "startPosition": "3470" + } + ], + "startPosition": "3464" + }, + "endPosition": "3500", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "3464" + }, + { + "expression": { + "endPosition": "3527", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "endPosition": "3522", + "kind": "IDENTIFIER", + "name": "print", + "startPosition": "3517" + }, + "arguments": [ + { + "endPosition": "3525", + "kind": "STRING_LITERAL", + "value": ",", + "startPosition": "3524" + } + ], + "startPosition": "3517" + }, + "endPosition": "3527", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "3517" + } + ], + "startPosition": "3447" + } + } + ], + "startPosition": "3100" + } + } + ], + "startPosition": "3060" + }, + "startPosition": "3031" + } + ], + "startPosition": "2897" + }, + "strict": "false", + "startPosition": "2867", + "parameters": [ + { + "endPosition": "2895", + "kind": "IDENTIFIER", + "name": "subdir", + "startPosition": "2889" + } + ] + }, + { + "endPosition": "3901", + "kind": "FUNCTION", + "name": "main", + "body": { + "endPosition": "3899", + "kind": "BLOCK", + "statements": [ + { + "expression": { + "endPosition": "3631", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "endPosition": "3626", + "kind": "IDENTIFIER", + "name": "print", + "startPosition": "3621" + }, + "arguments": [ + { + "endPosition": "3629", + "kind": "STRING_LITERAL", + "value": "[", + "startPosition": "3628" + } + ], + "startPosition": "3621" + }, + "endPosition": "3631", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "3621" + }, + { + "expression": { + "endPosition": "3665", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "endPosition": "3650", + "kind": "IDENTIFIER", + "name": "processFiles", + "startPosition": "3638" + }, + "arguments": [ + { + "endPosition": "3663", + "kind": "STRING_LITERAL", + "value": "parsertests", + "startPosition": "3652" + } + ], + "startPosition": "3638" + }, + "endPosition": "3665", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "3638" + }, + { + "expression": { + "endPosition": "3706", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "endPosition": "3683", + "kind": "IDENTIFIER", + "name": "processFiles", + "startPosition": "3671" + }, + "arguments": [ + { + "endPosition": "3704", + "kind": "STRING_LITERAL", + "value": "parsernegativetests", + "startPosition": "3685" + } + ], + "startPosition": "3671" + }, + "endPosition": "3706", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "3671" + }, + { + "endPosition": "3775", + "kind": "VARIABLE", + "name": "script", + "startPosition": "3747", + "initializer": { + "endPosition": "3775", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "endPosition": "3765", + "kind": "IDENTIFIER", + "name": "readFully", + "startPosition": "3756" + }, + "arguments": [ + { + "endPosition": "3774", + "kind": "IDENTIFIER", + "name": "__FILE__", + "startPosition": "3766" + } + ], + "startPosition": "3756" + } + }, + { + "endPosition": "3840", + "kind": "VARIABLE", + "name": "tree", + "startPosition": "3785", + "initializer": { + "endPosition": "3840", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "identifier": "parse", + "expression": { + "constructorExpression": { + "endPosition": "3804", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "endPosition": "3802", + "kind": "IDENTIFIER", + "name": "Parser", + "startPosition": "3796" + }, + "arguments": [], + "startPosition": "3796" + }, + "endPosition": "3804", + "kind": "NEW", + "startPosition": "3792" + }, + "endPosition": "3810", + "kind": "MEMBER_SELECT", + "startPosition": "3792" + }, + "arguments": [ + { + "endPosition": "3824", + "kind": "STRING_LITERAL", + "value": "parserapi.js", + "startPosition": "3812" + }, + { + "endPosition": "3833", + "kind": "IDENTIFIER", + "name": "script", + "startPosition": "3827" + }, + { + "endPosition": "3839", + "kind": "NULL_LITERAL", + "startPosition": "3835" + } + ], + "startPosition": "3792" + } + }, + { + "expression": { + "endPosition": "3882", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "endPosition": "3851", + "kind": "IDENTIFIER", + "name": "print", + "startPosition": "3846" + }, + "arguments": [ + { + "endPosition": "3881", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "identifier": "stringify", + "expression": { + "endPosition": "3856", + "kind": "IDENTIFIER", + "name": "JSON", + "startPosition": "3852" + }, + "endPosition": "3866", + "kind": "MEMBER_SELECT", + "startPosition": "3852" + }, + "arguments": [ + { + "endPosition": "3871", + "kind": "IDENTIFIER", + "name": "tree", + "startPosition": "3867" + }, + { + "endPosition": "3877", + "kind": "NULL_LITERAL", + "startPosition": "3873" + }, + { + "endPosition": "3880", + "kind": "NUMBER_LITERAL", + "value": "2", + "startPosition": "3879" + } + ], + "startPosition": "3852" + } + ], + "startPosition": "3846" + }, + "endPosition": "3882", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "3846" + }, + { + "expression": { + "endPosition": "3898", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "endPosition": "3893", + "kind": "IDENTIFIER", + "name": "print", + "startPosition": "3888" + }, + "arguments": [ + { + "endPosition": "3896", + "kind": "STRING_LITERAL", + "value": "]", + "startPosition": "3895" + } + ], + "startPosition": "3888" + }, + "endPosition": "3898", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "3888" + } + ], + "startPosition": "3615" + }, + "strict": "false", + "startPosition": "3599", + "parameters": [] + }, + { + "expression": { + "expression": { + "endPosition": "1305", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "identifier": "type", + "expression": { + "endPosition": "1265", + "kind": "IDENTIFIER", + "name": "Java", + "startPosition": "1261" + }, + "endPosition": "1270", + "kind": "MEMBER_SELECT", + "startPosition": "1261" + }, + "arguments": [ + { + "endPosition": "1303", + "kind": "STRING_LITERAL", + "value": "jdk.nashorn.api.tree.Diagnostic", + "startPosition": "1272" + } + ], + "startPosition": "1261" + }, + "endPosition": "1305", + "kind": "ASSIGNMENT", + "variable": { + "identifier": "Diagnostic", + "expression": { + "endPosition": "1247", + "kind": "IDENTIFIER", + "name": "Parser", + "startPosition": "1241" + }, + "endPosition": "1258", + "kind": "MEMBER_SELECT", + "startPosition": "1241" + }, + "startPosition": "1241" + }, + "endPosition": "1305", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1241" + }, + { + "expression": { + "expression": { + "endPosition": "1390", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "identifier": "type", + "expression": { + "endPosition": "1338", + "kind": "IDENTIFIER", + "name": "Java", + "startPosition": "1334" + }, + "endPosition": "1343", + "kind": "MEMBER_SELECT", + "startPosition": "1334" + }, + "arguments": [ + { + "endPosition": "1388", + "kind": "STRING_LITERAL", + "value": "jdk.nashorn.api.tree.SimpleTreeVisitorES5_1", + "startPosition": "1345" + } + ], + "startPosition": "1334" + }, + "endPosition": "1390", + "kind": "ASSIGNMENT", + "variable": { + "identifier": "SimpleTreeVisitor", + "expression": { + "endPosition": "1313", + "kind": "IDENTIFIER", + "name": "Parser", + "startPosition": "1307" + }, + "endPosition": "1331", + "kind": "MEMBER_SELECT", + "startPosition": "1307" + }, + "startPosition": "1307" + }, + "endPosition": "1390", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1307" + }, + { + "expression": { + "expression": { + "endPosition": "1444", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "identifier": "type", + "expression": { + "endPosition": "1410", + "kind": "IDENTIFIER", + "name": "Java", + "startPosition": "1406" + }, + "endPosition": "1415", + "kind": "MEMBER_SELECT", + "startPosition": "1406" + }, + "arguments": [ + { + "endPosition": "1442", + "kind": "STRING_LITERAL", + "value": "jdk.nashorn.api.tree.Tree", + "startPosition": "1417" + } + ], + "startPosition": "1406" + }, + "endPosition": "1444", + "kind": "ASSIGNMENT", + "variable": { + "identifier": "Tree", + "expression": { + "endPosition": "1398", + "kind": "IDENTIFIER", + "name": "Parser", + "startPosition": "1392" + }, + "endPosition": "1403", + "kind": "MEMBER_SELECT", + "startPosition": "1392" + }, + "startPosition": "1392" + }, + "endPosition": "1444", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1392" + }, + { + "expression": { + "expression": { + "endPosition": "1487", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "identifier": "type", + "expression": { + "endPosition": "1464", + "kind": "IDENTIFIER", + "name": "Java", + "startPosition": "1460" + }, + "endPosition": "1469", + "kind": "MEMBER_SELECT", + "startPosition": "1460" + }, + "arguments": [ + { + "endPosition": "1485", + "kind": "STRING_LITERAL", + "value": "java.util.List", + "startPosition": "1471" + } + ], + "startPosition": "1460" + }, + "endPosition": "1487", + "kind": "ASSIGNMENT", + "variable": { + "identifier": "List", + "expression": { + "endPosition": "1452", + "kind": "IDENTIFIER", + "name": "Parser", + "startPosition": "1446" + }, + "endPosition": "1457", + "kind": "MEMBER_SELECT", + "startPosition": "1446" + }, + "startPosition": "1446" + }, + "endPosition": "1487", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1446" + }, + { + "expression": { + "expression": { + "endPosition": "1530", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "identifier": "type", + "expression": { + "endPosition": "1507", + "kind": "IDENTIFIER", + "name": "Java", + "startPosition": "1503" + }, + "endPosition": "1512", + "kind": "MEMBER_SELECT", + "startPosition": "1503" + }, + "arguments": [ + { + "endPosition": "1528", + "kind": "STRING_LITERAL", + "value": "java.lang.Enum", + "startPosition": "1514" + } + ], + "startPosition": "1503" + }, + "endPosition": "1530", + "kind": "ASSIGNMENT", + "variable": { + "identifier": "Enum", + "expression": { + "endPosition": "1495", + "kind": "IDENTIFIER", + "name": "Parser", + "startPosition": "1489" + }, + "endPosition": "1500", + "kind": "MEMBER_SELECT", + "startPosition": "1489" + }, + "startPosition": "1489" + }, + "endPosition": "1530", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1489" + }, + { + "expression": { + "expression": { + "endPosition": "1657", + "kind": "FUNCTION_EXPRESSION", + "body": { + "endPosition": "1803", + "kind": "BLOCK", + "statements": [ + { + "endPosition": "1716", + "kind": "VARIABLE", + "name": "tree", + "startPosition": "1667", + "initializer": { + "endPosition": "1716", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "identifier": "parse", + "expression": { + "identifier": "_parser", + "expression": { + "endPosition": "1678", + "kind": "IDENTIFIER", + "name": "this", + "startPosition": "1674" + }, + "endPosition": "1686", + "kind": "MEMBER_SELECT", + "startPosition": "1674" + }, + "endPosition": "1692", + "kind": "MEMBER_SELECT", + "startPosition": "1674" + }, + "arguments": [ + { + "endPosition": "1697", + "kind": "IDENTIFIER", + "name": "name", + "startPosition": "1693" + }, + { + "endPosition": "1705", + "kind": "IDENTIFIER", + "name": "script", + "startPosition": "1699" + }, + { + "endPosition": "1715", + "kind": "IDENTIFIER", + "name": "listener", + "startPosition": "1707" + } + ], + "startPosition": "1674" + } + }, + { + "expression": { + "endPosition": "1771", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "identifier": "accept", + "expression": { + "endPosition": "1726", + "kind": "IDENTIFIER", + "name": "tree", + "startPosition": "1722" + }, + "endPosition": "1733", + "kind": "MEMBER_SELECT", + "startPosition": "1722" + }, + "arguments": [ + { + "constructorExpression": { + "endPosition": "1764", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "identifier": "SimpleTreeVisitor", + "expression": { + "endPosition": "1744", + "kind": "IDENTIFIER", + "name": "Parser", + "startPosition": "1738" + }, + "endPosition": "1762", + "kind": "MEMBER_SELECT", + "startPosition": "1738" + }, + "arguments": [], + "startPosition": "1744" + }, + "endPosition": "1764", + "kind": "NEW", + "startPosition": "1734" + }, + { + "endPosition": "1770", + "kind": "NULL_LITERAL", + "startPosition": "1766" + } + ], + "startPosition": "1722" + }, + "endPosition": "1771", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1722" + }, + { + "expression": { + "endPosition": "1802", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "identifier": "convert", + "expression": { + "endPosition": "1788", + "kind": "IDENTIFIER", + "name": "this", + "startPosition": "1784" + }, + "endPosition": "1796", + "kind": "MEMBER_SELECT", + "startPosition": "1784" + }, + "arguments": [ + { + "endPosition": "1801", + "kind": "IDENTIFIER", + "name": "tree", + "startPosition": "1797" + } + ], + "startPosition": "1784" + }, + "endPosition": "1803", + "kind": "RETURN", + "startPosition": "1777" + } + ], + "startPosition": "1657" + }, + "strict": "false", + "startPosition": "1657", + "parameters": [ + { + "endPosition": "1637", + "kind": "IDENTIFIER", + "name": "name", + "startPosition": "1633" + }, + { + "endPosition": "1645", + "kind": "IDENTIFIER", + "name": "script", + "startPosition": "1639" + }, + { + "endPosition": "1655", + "kind": "IDENTIFIER", + "name": "listener", + "startPosition": "1647" + } + ] + }, + "endPosition": "1657", + "kind": "ASSIGNMENT", + "variable": { + "identifier": "parse", + "expression": { + "identifier": "prototype", + "expression": { + "endPosition": "1605", + "kind": "IDENTIFIER", + "name": "Parser", + "startPosition": "1599" + }, + "endPosition": "1615", + "kind": "MEMBER_SELECT", + "startPosition": "1599" + }, + "endPosition": "1621", + "kind": "MEMBER_SELECT", + "startPosition": "1599" + }, + "startPosition": "1599" + }, + "endPosition": "1805", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1599" + }, + { + "expression": { + "expression": { + "endPosition": "1834", + "kind": "FUNCTION_EXPRESSION", + "body": { + "endPosition": "1897", + "kind": "BLOCK", + "statements": [ + { + "expression": { + "endPosition": "1896", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "identifier": "create", + "expression": { + "endPosition": "1887", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "identifier": "type", + "expression": { + "endPosition": "1851", + "kind": "IDENTIFIER", + "name": "Java", + "startPosition": "1847" + }, + "endPosition": "1856", + "kind": "MEMBER_SELECT", + "startPosition": "1847" + }, + "arguments": [ + { + "endPosition": "1885", + "kind": "STRING_LITERAL", + "value": "jdk.nashorn.api.tree.Parser", + "startPosition": "1858" + } + ], + "startPosition": "1847" + }, + "endPosition": "1894", + "kind": "MEMBER_SELECT", + "startPosition": "1847" + }, + "arguments": [], + "startPosition": "1894" + }, + "endPosition": "1897", + "kind": "RETURN", + "startPosition": "1840" + } + ], + "startPosition": "1834" + }, + "strict": "false", + "startPosition": "1834", + "parameters": [] + }, + "endPosition": "1834", + "kind": "ASSIGNMENT", + "variable": { + "identifier": "create", + "expression": { + "endPosition": "1813", + "kind": "IDENTIFIER", + "name": "Parser", + "startPosition": "1807" + }, + "endPosition": "1820", + "kind": "MEMBER_SELECT", + "startPosition": "1807" + }, + "startPosition": "1807" + }, + "endPosition": "1971", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1807" + }, + { + "expression": { + "expression": { + "endPosition": "2014", + "kind": "FUNCTION_EXPRESSION", + "body": { + "endPosition": "2863", + "kind": "BLOCK", + "statements": [ + { + "condition": { + "leftOperand": { + "expression": { + "endPosition": "2029", + "kind": "IDENTIFIER", + "name": "tree", + "startPosition": "2025" + }, + "endPosition": "2029", + "kind": "LOGICAL_COMPLEMENT", + "startPosition": "2024" + }, + "endPosition": "2055", + "kind": "CONDITIONAL_OR", + "rightOperand": { + "leftOperand": { + "expression": { + "endPosition": "2044", + "kind": "IDENTIFIER", + "name": "tree", + "startPosition": "2040" + }, + "endPosition": "2044", + "kind": "TYPEOF", + "startPosition": "2033" + }, + "endPosition": "2055", + "kind": "NOT_EQUAL_TO", + "rightOperand": { + "endPosition": "2055", + "kind": "STRING_LITERAL", + "value": "object", + "startPosition": "2049" + }, + "startPosition": "2033" + }, + "startPosition": "2024" + }, + "endPosition": "2086", + "kind": "IF", + "startPosition": "2020", + "thenStatement": { + "endPosition": "2086", + "kind": "BLOCK", + "statements": [ + { + "expression": { + "endPosition": "2079", + "kind": "IDENTIFIER", + "name": "tree", + "startPosition": "2075" + }, + "endPosition": "2080", + "kind": "RETURN", + "startPosition": "2068" + } + ], + "startPosition": "2058" + } + }, + { + "endPosition": "2133", + "kind": "VARIABLE", + "name": "obj", + "startPosition": "2096", + "initializer": { + "endPosition": "2133", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "identifier": "bindProperties", + "expression": { + "endPosition": "2108", + "kind": "IDENTIFIER", + "name": "Object", + "startPosition": "2102" + }, + "endPosition": "2123", + "kind": "MEMBER_SELECT", + "startPosition": "2102" + }, + "arguments": [ + { + "endPosition": "2126", + "kind": "OBJECT_LITERAL", + "startPosition": "2124", + "properties": [] + }, + { + "endPosition": "2132", + "kind": "IDENTIFIER", + "name": "tree", + "startPosition": "2128" + } + ], + "startPosition": "2102" + } + }, + { + "endPosition": "2154", + "kind": "VARIABLE", + "name": "result", + "startPosition": "2143", + "initializer": { + "endPosition": "2154", + "kind": "OBJECT_LITERAL", + "startPosition": "2152", + "properties": [] + } + }, + { + "endPosition": "2170", + "kind": "VARIABLE", + "name": "i", + "startPosition": "2169" + }, + { + "expression": { + "endPosition": "2177", + "kind": "IDENTIFIER", + "name": "obj", + "startPosition": "2174" + }, + "endPosition": "2845", + "kind": "FOR_IN_LOOP", + "forEach": "false", + "variable": { + "endPosition": "2170", + "kind": "IDENTIFIER", + "name": "i", + "startPosition": "2169" + }, + "statement": { + "endPosition": "2845", + "kind": "BLOCK", + "statements": [ + { + "endPosition": "2204", + "kind": "VARIABLE", + "name": "val", + "startPosition": "2192", + "initializer": { + "expression": { + "endPosition": "2201", + "kind": "IDENTIFIER", + "name": "obj", + "startPosition": "2198" + }, + "endPosition": "2204", + "kind": "ARRAY_ACCESS", + "index": { + "endPosition": "2203", + "kind": "IDENTIFIER", + "name": "i", + "startPosition": "2202" + }, + "startPosition": "2198" + } + }, + { + "condition": { + "leftOperand": { + "endPosition": "2220", + "kind": "IDENTIFIER", + "name": "val", + "startPosition": "2217" + }, + "expression": { + "endPosition": "2220", + "kind": "IDENTIFIER", + "name": "val", + "startPosition": "2217" + }, + "endPosition": "2243", + "kind": "INSTANCE_OF", + "rightOperand": { + "identifier": "Tree", + "expression": { + "endPosition": "2238", + "kind": "IDENTIFIER", + "name": "Parser", + "startPosition": "2232" + }, + "endPosition": "2243", + "kind": "MEMBER_SELECT", + "startPosition": "2232" + }, + "type": { + "identifier": "Tree", + "expression": { + "endPosition": "2238", + "kind": "IDENTIFIER", + "name": "Parser", + "startPosition": "2232" + }, + "endPosition": "2243", + "kind": "MEMBER_SELECT", + "startPosition": "2232" + }, + "startPosition": "2217" + }, + "elseStatement": { + "condition": { + "leftOperand": { + "endPosition": "2309", + "kind": "IDENTIFIER", + "name": "val", + "startPosition": "2306" + }, + "expression": { + "endPosition": "2309", + "kind": "IDENTIFIER", + "name": "val", + "startPosition": "2306" + }, + "endPosition": "2332", + "kind": "INSTANCE_OF", + "rightOperand": { + "identifier": "List", + "expression": { + "endPosition": "2327", + "kind": "IDENTIFIER", + "name": "Parser", + "startPosition": "2321" + }, + "endPosition": "2332", + "kind": "MEMBER_SELECT", + "startPosition": "2321" + }, + "type": { + "identifier": "List", + "expression": { + "endPosition": "2327", + "kind": "IDENTIFIER", + "name": "Parser", + "startPosition": "2321" + }, + "endPosition": "2332", + "kind": "MEMBER_SELECT", + "startPosition": "2321" + }, + "startPosition": "2306" + }, + "elseStatement": { + "endPosition": "2840", + "kind": "BLOCK", + "statements": [ + { + "cases": [ + { + "expression": { + "endPosition": "2574", + "kind": "STRING_LITERAL", + "value": "number", + "startPosition": "2568" + }, + "endPosition": "2576", + "kind": "CASE", + "statements": [], + "startPosition": "2562" + }, + { + "expression": { + "endPosition": "2603", + "kind": "STRING_LITERAL", + "value": "string", + "startPosition": "2597" + }, + "endPosition": "2605", + "kind": "CASE", + "statements": [], + "startPosition": "2591" + }, + { + "expression": { + "endPosition": "2633", + "kind": "STRING_LITERAL", + "value": "boolean", + "startPosition": "2626" + }, + "endPosition": "2678", + "kind": "CASE", + "statements": [ + { + "expression": { + "expression": { + "endPosition": "2677", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "endPosition": "2672", + "kind": "IDENTIFIER", + "name": "String", + "startPosition": "2666" + }, + "arguments": [ + { + "endPosition": "2676", + "kind": "IDENTIFIER", + "name": "val", + "startPosition": "2673" + } + ], + "startPosition": "2666" + }, + "endPosition": "2677", + "kind": "ASSIGNMENT", + "variable": { + "expression": { + "endPosition": "2660", + "kind": "IDENTIFIER", + "name": "result", + "startPosition": "2654" + }, + "endPosition": "2663", + "kind": "ARRAY_ACCESS", + "index": { + "endPosition": "2662", + "kind": "IDENTIFIER", + "name": "i", + "startPosition": "2661" + }, + "startPosition": "2654" + }, + "startPosition": "2654" + }, + "endPosition": "2677", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "2654" + } + ], + "startPosition": "2620" + }, + { + "endPosition": "2820", + "kind": "CASE", + "statements": [ + { + "condition": { + "leftOperand": { + "endPosition": "2727", + "kind": "IDENTIFIER", + "name": "val", + "startPosition": "2724" + }, + "expression": { + "endPosition": "2727", + "kind": "IDENTIFIER", + "name": "val", + "startPosition": "2724" + }, + "endPosition": "2750", + "kind": "INSTANCE_OF", + "rightOperand": { + "identifier": "Enum", + "expression": { + "endPosition": "2745", + "kind": "IDENTIFIER", + "name": "Parser", + "startPosition": "2739" + }, + "endPosition": "2750", + "kind": "MEMBER_SELECT", + "startPosition": "2739" + }, + "type": { + "identifier": "Enum", + "expression": { + "endPosition": "2745", + "kind": "IDENTIFIER", + "name": "Parser", + "startPosition": "2739" + }, + "endPosition": "2750", + "kind": "MEMBER_SELECT", + "startPosition": "2739" + }, + "startPosition": "2724" + }, + "endPosition": "2820", + "kind": "IF", + "startPosition": "2720", + "thenStatement": { + "endPosition": "2820", + "kind": "BLOCK", + "statements": [ + { + "expression": { + "expression": { + "endPosition": "2799", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "endPosition": "2794", + "kind": "IDENTIFIER", + "name": "String", + "startPosition": "2788" + }, + "arguments": [ + { + "endPosition": "2798", + "kind": "IDENTIFIER", + "name": "val", + "startPosition": "2795" + } + ], + "startPosition": "2788" + }, + "endPosition": "2799", + "kind": "ASSIGNMENT", + "variable": { + "expression": { + "endPosition": "2782", + "kind": "IDENTIFIER", + "name": "result", + "startPosition": "2776" + }, + "endPosition": "2785", + "kind": "ARRAY_ACCESS", + "index": { + "endPosition": "2784", + "kind": "IDENTIFIER", + "name": "i", + "startPosition": "2783" + }, + "startPosition": "2776" + }, + "startPosition": "2776" + }, + "endPosition": "2799", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "2776" + } + ], + "startPosition": "2752" + } + } + ], + "startPosition": "2693" + } + ], + "expression": { + "expression": { + "endPosition": "2544", + "kind": "IDENTIFIER", + "name": "val", + "startPosition": "2541" + }, + "endPosition": "2544", + "kind": "TYPEOF", + "startPosition": "2534" + }, + "endPosition": "2832", + "kind": "SWITCH", + "startPosition": "2526" + } + ], + "startPosition": "2514" + }, + "endPosition": "2840", + "kind": "IF", + "startPosition": "2302", + "thenStatement": { + "endPosition": "2508", + "kind": "BLOCK", + "statements": [ + { + "endPosition": "2377", + "kind": "VARIABLE", + "name": "arr", + "startPosition": "2350", + "initializer": { + "constructorExpression": { + "endPosition": "2377", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "endPosition": "2365", + "kind": "IDENTIFIER", + "name": "Array", + "startPosition": "2360" + }, + "arguments": [ + { + "endPosition": "2376", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "identifier": "size", + "expression": { + "endPosition": "2369", + "kind": "IDENTIFIER", + "name": "val", + "startPosition": "2366" + }, + "endPosition": "2374", + "kind": "MEMBER_SELECT", + "startPosition": "2366" + }, + "arguments": [], + "startPosition": "2366" + } + ], + "startPosition": "2360" + }, + "endPosition": "2377", + "kind": "NEW", + "startPosition": "2356" + } + }, + { + "endPosition": "2399", + "kind": "VARIABLE", + "name": "j", + "startPosition": "2398" + }, + { + "expression": { + "endPosition": "2406", + "kind": "IDENTIFIER", + "name": "val", + "startPosition": "2403" + }, + "endPosition": "2466", + "kind": "FOR_IN_LOOP", + "forEach": "false", + "variable": { + "endPosition": "2399", + "kind": "IDENTIFIER", + "name": "j", + "startPosition": "2398" + }, + "statement": { + "endPosition": "2466", + "kind": "BLOCK", + "statements": [ + { + "expression": { + "expression": { + "endPosition": "2453", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "identifier": "convert", + "expression": { + "endPosition": "2437", + "kind": "IDENTIFIER", + "name": "this", + "startPosition": "2433" + }, + "endPosition": "2445", + "kind": "MEMBER_SELECT", + "startPosition": "2433" + }, + "arguments": [ + { + "expression": { + "endPosition": "2449", + "kind": "IDENTIFIER", + "name": "val", + "startPosition": "2446" + }, + "endPosition": "2452", + "kind": "ARRAY_ACCESS", + "index": { + "endPosition": "2451", + "kind": "IDENTIFIER", + "name": "j", + "startPosition": "2450" + }, + "startPosition": "2446" + } + ], + "startPosition": "2433" + }, + "endPosition": "2453", + "kind": "ASSIGNMENT", + "variable": { + "expression": { + "endPosition": "2427", + "kind": "IDENTIFIER", + "name": "arr", + "startPosition": "2424" + }, + "endPosition": "2430", + "kind": "ARRAY_ACCESS", + "index": { + "endPosition": "2429", + "kind": "IDENTIFIER", + "name": "j", + "startPosition": "2428" + }, + "startPosition": "2424" + }, + "startPosition": "2424" + }, + "endPosition": "2453", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "2424" + } + ], + "startPosition": "2408" + }, + "startPosition": "2389" + }, + { + "expression": { + "expression": { + "endPosition": "2499", + "kind": "IDENTIFIER", + "name": "arr", + "startPosition": "2496" + }, + "endPosition": "2499", + "kind": "ASSIGNMENT", + "variable": { + "expression": { + "endPosition": "2490", + "kind": "IDENTIFIER", + "name": "result", + "startPosition": "2484" + }, + "endPosition": "2493", + "kind": "ARRAY_ACCESS", + "index": { + "endPosition": "2492", + "kind": "IDENTIFIER", + "name": "i", + "startPosition": "2491" + }, + "startPosition": "2484" + }, + "startPosition": "2484" + }, + "endPosition": "2499", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "2484" + } + ], + "startPosition": "2334" + } + }, + "endPosition": "2840", + "kind": "IF", + "startPosition": "2213", + "thenStatement": { + "endPosition": "2296", + "kind": "BLOCK", + "statements": [ + { + "expression": { + "expression": { + "endPosition": "2286", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "identifier": "convert", + "expression": { + "endPosition": "2273", + "kind": "IDENTIFIER", + "name": "this", + "startPosition": "2269" + }, + "endPosition": "2281", + "kind": "MEMBER_SELECT", + "startPosition": "2269" + }, + "arguments": [ + { + "endPosition": "2285", + "kind": "IDENTIFIER", + "name": "val", + "startPosition": "2282" + } + ], + "startPosition": "2269" + }, + "endPosition": "2286", + "kind": "ASSIGNMENT", + "variable": { + "expression": { + "endPosition": "2263", + "kind": "IDENTIFIER", + "name": "result", + "startPosition": "2257" + }, + "endPosition": "2266", + "kind": "ARRAY_ACCESS", + "index": { + "endPosition": "2265", + "kind": "IDENTIFIER", + "name": "i", + "startPosition": "2264" + }, + "startPosition": "2257" + }, + "startPosition": "2257" + }, + "endPosition": "2286", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "2257" + } + ], + "startPosition": "2245" + } + } + ], + "startPosition": "2179" + }, + "startPosition": "2160" + }, + { + "expression": { + "endPosition": "2862", + "kind": "IDENTIFIER", + "name": "result", + "startPosition": "2856" + }, + "endPosition": "2863", + "kind": "RETURN", + "startPosition": "2849" + } + ], + "startPosition": "2014" + }, + "strict": "false", + "startPosition": "2014", + "parameters": [ + { + "endPosition": "2012", + "kind": "IDENTIFIER", + "name": "tree", + "startPosition": "2008" + } + ] + }, + "endPosition": "2014", + "kind": "ASSIGNMENT", + "variable": { + "identifier": "convert", + "expression": { + "identifier": "prototype", + "expression": { + "endPosition": "1978", + "kind": "IDENTIFIER", + "name": "Parser", + "startPosition": "1972" + }, + "endPosition": "1988", + "kind": "MEMBER_SELECT", + "startPosition": "1972" + }, + "endPosition": "1996", + "kind": "MEMBER_SELECT", + "startPosition": "1972" + }, + "startPosition": "1972" + }, + "endPosition": "2865", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "1972" + }, + { + "expression": { + "endPosition": "3909", + "kind": "FUNCTION_INVOCATION", + "functionSelect": { + "endPosition": "3907", + "kind": "IDENTIFIER", + "name": "main", + "startPosition": "3903" + }, + "arguments": [], + "startPosition": "3903" + }, + "endPosition": "3909", + "kind": "EXPRESSION_STATEMENT", + "startPosition": "3903" + } + ], + "sourceName": "parserapi.js", + "strict": "false", + "startPosition": "1136" +} +] --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/test/script/nosecurity/parserapi_const_as_var.js 2015-03-09 18:39:44.303902737 +0530 @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * Nashorn parser API --const-as-var option test. + * + * @test + * @run + */ + +var Parser = Java.type("jdk.nashorn.api.tree.Parser"); +var constAsVarParser = Parser.create("--const-as-var"); +var parser = Parser.create(); + +var constStr = "const PI = 3.14;"; +// this one should not report error +constAsVarParser.parse("const_as_var.js", constStr, print); +// default parser should report error +parser.parse("const_as_var1.js", constStr, print); --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/test/script/nosecurity/parserapi_const_as_var.js.EXPECTED 2015-03-09 18:39:44.855905464 +0530 @@ -0,0 +1,3 @@ +const_as_var1.js:1:0 Expected an operand but found const +const PI = 3.14; +^ --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/test/script/nosecurity/parserapi_empty_stat.js 2015-03-09 18:39:45.411908203 +0530 @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * Nashorn parser API --empty-statements option test. + * + * @test + * @run + */ + +var SimpleTreeVisitor = Java.type("jdk.nashorn.api.tree.SimpleTreeVisitorES5_1"); +var Parser = Java.type("jdk.nashorn.api.tree.Parser"); + +// with --empty-statements parse tree should contain +// EmptyStatement tree nodes. Without this option, empty +// statement Tree nodes may be optimized away by Parser. +var emptyStatParser = Parser.create("--empty-statements"); + +var emptyStat = ";"; +emptyStatParser.parse("empty.js", emptyStat, print). + accept(new (Java.extend(SimpleTreeVisitor)) { + visitEmptyStatement: function(node, p) { + print("inside EmptyStatement visit"); + } + }, null); --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/test/script/nosecurity/parserapi_empty_stat.js.EXPECTED 2015-03-09 18:39:45.967910977 +0530 @@ -0,0 +1 @@ +inside EmptyStatement visit --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/test/script/nosecurity/parserapi_nse.js 2015-03-09 18:39:46.515913689 +0530 @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * Nashorn parser API -nse option test. + * + * @test + * @option -scripting + * @run + */ + +var Parser = Java.type("jdk.nashorn.api.tree.Parser"); +var noExtParser = Parser.create("-nse"); +var parser = Parser.create(); +var scriptingParser = Parser.create("-scripting"); + +var condCatch = <>= 314; +xyz >>>= 314; +xyz &= 314; +xyz ^= 314; +xyz |= 314; --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/test/script/nosecurity/parsertests/binaryExpr.js 2015-03-09 18:39:57.727969293 +0530 @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * Tests to check binary operators. + * + * @subtest + */ + +a * b +a / b; +a % b; +a + b; +a - b; +a << b; +a >> b; +a >>> b; +a < b; +a > b; +a <= b; +a >= b; +a instanceof b; +a == b; +a != b; +a === b; +a !== b; +a & b; +a ^ b; +a | b; +a && b; +a || b; --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/test/script/nosecurity/parsertests/block.js 2015-03-09 18:39:58.263971954 +0530 @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * Tests to check 'block' statement. + * + * @subtest + */ + +{} +{ print("hello"); } --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/test/script/nosecurity/parsertests/breakStat.js 2015-03-09 18:39:58.803974628 +0530 @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * Tests to check 'break' statement. + * + * @subtest + */ + +while (true) { break; }; +loop: { while (true) { break loop } }; +loop: { for (;;) { break loop } }; --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/test/script/nosecurity/parsertests/condExpr.js 2015-03-09 18:39:59.347977328 +0530 @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * Tests to check ternary operator. + * + * @subtest + */ + + +a? b : c; --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/test/script/nosecurity/parsertests/continueStat.js 2015-03-09 18:39:59.903980078 +0530 @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * Tests to check 'continue' statement. + * + * @subtest + */ + +while (true) { continue; }; +begin: { while (true) { continue begin; } }; +start: { for(;;) { continue start; } }; --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/test/script/nosecurity/parsertests/debuggerStat.js 2015-03-09 18:40:00.443982764 +0530 @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * Tests to check debugger statement. + * + * @subtest + */ + +debugger; --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/test/script/nosecurity/parsertests/functions.js 2015-03-09 18:40:00.995985500 +0530 @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * Tests to check 'function' statements and expressions. + * + * @subtest + */ + +function hello() { print('hello') } +function hello(a) { print(a) } +function hello(a, b) { print(a, b) } +var hello = function() { print('hello') }; +var hello = function hello() { print('hello') }; +(function(){}) +function test() { 'use strict' }; --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/test/script/nosecurity/parsertests/ifStat.js 2015-03-09 18:40:01.547988232 +0530 @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * Tests to check 'if' statement. + * + * @subtest + */ + +if (js) { nashorn() }; +if (js) { nashorn() } else { java() }; --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/test/script/nosecurity/parsertests/labelledStat.js 2015-03-09 18:40:02.095990953 +0530 @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * Test for labelled statements. + * + * @subtest + */ + +begin: { for (;;) break begin }; +begin: { while (true) break begin }; --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/test/script/nosecurity/parsertests/lhsExpr.js 2015-03-09 18:40:02.635993626 +0530 @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * Tests to check left-hand-side expressions + * + * @subtest + */ + +a[3]; +a[b]; +a['foo']; +obj.foo; +obj.foo.bar; +new Type; +new Type(); +new Type(a, 'hello'); +new obj.Type; +new obj.Type(); +new obj.Type(a, 'hello'); +foo() +obj.foo(); +foo(a,b); +obj.foo(a, b); --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/test/script/nosecurity/parsertests/loopStat.js 2015-03-09 18:40:03.163996249 +0530 @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * Tests for loop statements. + * + * @subtest + */ + +while(true) { print('hello') } +do { print('hello') } while(true) +for (i in obj) { print(obj[i]) } +for each (i in obj) { print(i) } +for (i = 0; i < 10; i++) { print(i) } --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/test/script/nosecurity/parsertests/objectLitExpr.js 2015-03-09 18:40:03.707998943 +0530 @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * Tests to check assignment e xyzpressions. + * + * @subtest + */ + +obj = {}; +p = { x: 10, y: 2 }; +p = { 'x': 10, 'y': 2 }; +p = { get x() { return xValue }, get y() { return yValue } }; +p = { get foo() { return this._foo }, set foo(val) { this._foo = val } }; --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/test/script/nosecurity/parsertests/parenExpr.js 2015-03-09 18:40:04.244001608 +0530 @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * Tests for parenthesis expressions. + * + * @subtest + */ + +(2) + (1) + 4; +3 + (7) << (5); --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/test/script/nosecurity/parsertests/primaryExpr.js 2015-03-09 18:40:04.800004362 +0530 @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * Tests to check primary expressions. + * + * @subtest + */ + +this; +foo; +null; +true; +false; +33; +3.14; +(10 + 3)*2; +({}); +({ x: 3 }); +[]; +[,,]; +[4, 5, 5]; --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/test/script/nosecurity/parsertests/regexp_literal.js 2015-03-09 18:40:05.364007150 +0530 @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * Tests to check regexp literal. + * + * @subtest + */ + +var x = /foo/; +var y = /foo/g; +var z = /[a-z]*[1-10]?/; --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/test/script/nosecurity/parsertests/returnStat.js 2015-03-09 18:40:05.908009847 +0530 @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * Tests to check 'return' statement. + * + * @subtest + */ + +(function() { return }); +(function() { return res }); +(function() { return foo() }); --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/test/script/nosecurity/parsertests/switchStat.js 2015-03-09 18:40:06.448012530 +0530 @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * Tests for switch statement. + * + * @subtest + */ + +switch (key) {}; +switch (key) { case 2: hello(); break; }; +switch (key) { case 4: hello(); break; case 2: world(); break; default: break }; --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/test/script/nosecurity/parsertests/throwStat.js 2015-03-09 18:40:06.980015155 +0530 @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * Tests for throw statement. + * + * @subtest + */ + +throw err; +throw 'wrong'; +throw new TypeError; +throw new TypeError('not an array'); +throw { msg: 'wrong!' }; --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/test/script/nosecurity/parsertests/tryCatchStat.js 2015-03-09 18:40:07.532017908 +0530 @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * Tests to check try..catch statements. + * + * @subtest + */ + +try { } catch (e) { } +try { } catch (e) { } finally {} +try { } finally {} +try { } catch (e) { handle() } +try { that() } catch (e) { handle() } finally { clean() } +try { that() } catch (e if e instanceof TypeError) { handle() } catch (e) { rest() } --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/test/script/nosecurity/parsertests/unaryExpr.js 2015-03-09 18:40:08.112020786 +0530 @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * Tests to check unary operators. + * + * @subtest + */ + +x++; +x--; +delete x; +void x; +typeof x; +++x; +--x; ++x; +-x; +~x; +!x; --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/test/script/nosecurity/parsertests/useStrict.js 2015-03-09 18:40:08.660023510 +0530 @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * Tests to check 'use strict' directive. + * + * @subtest + */ + +'use strict'; +function f() { 'use strict' } --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/test/script/nosecurity/parsertests/varDecl.js 2015-03-09 18:40:09.208026229 +0530 @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * Tests to check variable declarations. + * + * @subtest + */ + + +// no initialization +var a; +var a, b; + +// init single, multiple +var a = 'hello'; +var a = 1, b = 2, c = 3; --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/test/script/nosecurity/parsertests/withStat.js 2015-03-09 18:40:09.884029577 +0530 @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * Tests for 'with' statement. + * + * @subtest + */ + +with (scope) { x = y }; --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/test/script/nosecurity/parservisitor.js 2015-03-09 18:40:10.412032184 +0530 @@ -0,0 +1,380 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/** + * Nashorn parser API - Basic TreeVisitor tests. + * + * @test + * @option -scripting + * @run + */ + +// Java types used +var SimpleTreeVisitor = Java.type("jdk.nashorn.api.tree.SimpleTreeVisitorES5_1"); +var Parser = Java.type("jdk.nashorn.api.tree.Parser"); + +function parse(name, script, visitor) { + var parser = Parser.create("--empty-statements"); + var tree = parser.parse(name, script, null); + return tree.accept(visitor, print); +} + +parse("arrayaccess.js", "this['eval']", + new (Java.extend(SimpleTreeVisitor))() { + visitArrayAccess: function(aa) { + print("in visitArrayAccess " + + aa.expression.name + " " + aa.index.value); + } + }); + +parse("arrayliteral.js", "[2, 3, 22]", + new (Java.extend(SimpleTreeVisitor))() { + visitArrayLiteral: function(al) { + print("in visitArrayLiteral"); + for each (var e in al.elements) { + print(e.value); + } + } + }); + +parse("assign.js", "x = 33", + new (Java.extend(SimpleTreeVisitor))() { + visitAssignment: function(an) { + print("in visitAssignment " + + an.variable.name + " " + an.expression.value); + } + }); + +function binaryExpr(name, code) { + parse(name, code, + new (Java.extend(SimpleTreeVisitor))() { + visitBinary: function(bn) { + print("in visitBinary " + bn.kind + " " + + bn.leftOperand.value + ", " + bn.rightOperand.value); + } + }); +} + +binaryExpr("add.js", "3 + 4"); +binaryExpr("sub.js", "3 - 4"); +binaryExpr("mul.js", "3 * 4"); +binaryExpr("div.js", "3 / 4"); +binaryExpr("rem.js", "3 % 4"); +binaryExpr("rshift.js", "3 >> 4"); +binaryExpr("rshift.js", "3 >>> 4"); +binaryExpr("lshift.js", "3 << 4"); +binaryExpr("less.js", "3 < 4"); +binaryExpr("lessOrEq.js", "3 <= 4"); +binaryExpr("greater.js", "3 > 4"); +binaryExpr("greaterOrEq.js", "3 >= 4"); +binaryExpr("in.js", "3 in this"); +binaryExpr("eq.js", "3 == 3"); +binaryExpr("ne.js", "3 != 2"); +binaryExpr("seq.js", "3 === 2"); +binaryExpr("sne.js", "3 !== 2"); +binaryExpr("and.js", "3 & 2"); +binaryExpr("or.js", "3 | 2"); +binaryExpr("xor.js", "3 ^ 2"); +binaryExpr("cond_and.js", "3 && 2"); +binaryExpr("cond_or.js", "3 || 2"); +binaryExpr("comma", "3, 2"); + +parse("block.js", "{ print('hello'); }", + new (Java.extend(SimpleTreeVisitor))() { + visitBlock: function() { + print("in visitBlock"); + } + }); + + +parse("break.js", "while(true) { break; }", + new (Java.extend(SimpleTreeVisitor))() { + visitBreak: function() { + print("in visitBreak"); + } + }); + +function compAssignExpr(name, code) { + parse(name, code, + new (Java.extend(SimpleTreeVisitor))() { + visitCompoundAssignment: function(bn) { + print("in visitCompoundAssignment " + bn.kind + " " + + bn.variable.name + " " + bn.expression.value); + } + }); +} + +compAssignExpr("mult_assign.js", "x *= 3"); +compAssignExpr("div_assign.js", "x /= 3"); +compAssignExpr("rem_assign.js", "x %= 3"); +compAssignExpr("add_assign.js", "x += 3"); +compAssignExpr("sub_assign.js", "x -= 3"); +compAssignExpr("lshift_assign.js", "x <<= 3"); +compAssignExpr("rshift_assign.js", "x >>= 3"); +compAssignExpr("urshift_assign.js", "x >>>= 3"); +compAssignExpr("and_assign.js", "x &= 3"); +compAssignExpr("xor_assign.js", "x ^= 3"); +compAssignExpr("or_assign.js", "x |= 3"); + +parse("condexpr.js", "foo? x : y", + new (Java.extend(SimpleTreeVisitor))() { + visitConditionalExpression: function() { + print("in visitConditionalExpression"); + } + }); + +parse("continue.js", "while(true) { continue; }", + new (Java.extend(SimpleTreeVisitor))() { + visitContinue: function() { + print("in visitContinue"); + } + }); + +parse("debugger.js", "debugger;", + new (Java.extend(SimpleTreeVisitor))() { + visitDebugger: function() { + print("in visitDebugger"); + } + }); + +parse("dowhile.js", "do {} while(true)", + new (Java.extend(SimpleTreeVisitor))() { + visitDoWhileLoop: function() { + print("in visitDoWhileLoop"); + } + }); + +parse("empty.js", ";", + new (Java.extend(SimpleTreeVisitor))() { + visitEmptyStatement: function() { + print("in visitEmptyStatement"); + } + }); + +parse("exprstat.js", "2+3;", + new (Java.extend(SimpleTreeVisitor))() { + visitExpressionStatement: function() { + print("in visitExpressionStatement"); + } + }); + +parse("forin.js", "for(i in this) {}", + new (Java.extend(SimpleTreeVisitor))() { + visitForInLoop: function() { + print("in visitForInLoop"); + } + }); + +parse("for.js", "for(;;) {}", + new (Java.extend(SimpleTreeVisitor))() { + visitForLoop: function() { + print("in visitForLoop"); + } + }); + +parse("funccall.js", "func()", + new (Java.extend(SimpleTreeVisitor))() { + visitFunctionCall: function(fc) { + print("in visitFunctionCall " + fc.functionSelect.name); + } + }); + +parse("funcdecl.js", "function func() {}", + new (Java.extend(SimpleTreeVisitor))() { + visitFunctionDeclaration: function(fd) { + print("in visitFunctionDeclaration " + fd.name); + } + }); + +parse("funcexpr.js", "x = function() {}", + new (Java.extend(SimpleTreeVisitor))() { + visitFunctionExpression: function() { + print("in visitFunctionExpression"); + } + }); + +parse("ident.js", "this", + new (Java.extend(SimpleTreeVisitor))() { + visitIdentifier: function(ident) { + print("in visitIdentifier " + ident.name); + } + }); + +parse("if.js", "if (true) {}", + new (Java.extend(SimpleTreeVisitor))() { + visitIf: function() { + print("in visitIf"); + } + }); + +parse("if2.js", "if (true) print('yes')", + new (visitor = Java.extend(SimpleTreeVisitor))() { + visitBlock: function(node, extra) { + print("ERROR: No block expected here!"); + Error.dumpStack(); + } + }); + +parse("instanceof.js", "this instanceof Object", + new (Java.extend(SimpleTreeVisitor))() { + visitInstanceOf: function() { + print("in visitInstanceOf"); + } + }); + +parse("labeled.js", "foo: print('hello');", + new (Java.extend(SimpleTreeVisitor))() { + visitLabeledStatement: function() { + print("in visitLabeledStatement"); + } + }); + +function literalExpr(name, code) { + parse(name, code, + new (Java.extend(SimpleTreeVisitor))() { + visitLiteral: function(ln) { + print("in visitLiteral " + ln.kind + " " + ln.value); + } + }); +} + +literalExpr("bool.js", "true"); +literalExpr("num.js", "3.14"); +literalExpr("str.js", "'hello'"); +literalExpr("null.js", "null"); + +parse("memselect.js", "this.foo", + new (Java.extend(SimpleTreeVisitor))() { + visitMemberSelect: function(ms) { + print("in visitMemberSelect " + ms.identifier); + } + }); + +parse("new.js", "new Object()", + new (Java.extend(SimpleTreeVisitor))() { + visitNew: function() { + print("in visitNew"); + } + }); + +parse("obj_literal.js", "({ foo: 343 })", + visitor = new (Java.extend(SimpleTreeVisitor))() { + visitObjectLiteral: function(ol) { + print("in visitObjectLiteral"); + Java.super(visitor).visitObjectLiteral(ol, null); + }, + + visitProperty: function(pn) { + print("in visitProperty " + pn.key.name); + } + }); + +parse("regexp.js", "/[a-b]/i", + new (Java.extend(SimpleTreeVisitor))() { + visitRegExpLiteral: function(re) { + print("in visitRegExpLiteral " + re.pattern + " " + re.options); + } + }); + +parse("ret.js", "function func() { return 33 }", + new (Java.extend(SimpleTreeVisitor))() { + visitReturn: function(ret) { + print("in visitReturn " + ret.expression.value); + } + }); + +parse("switch.js", "switch(c) { case '1': break; default: }", + visitor = new (Java.extend(SimpleTreeVisitor))() { + visitSwitch: function(sn) { + print("in visitSwitch"); + Java.super(visitor).visitSwitch(sn, null); + }, + + visitCase: function(cn) { + if (cn.expression) { + print("in visitCase"); + } else { + print("in visitCase (default)"); + } + } + }); + +parse("throw.js", "throw 2", + new (Java.extend(SimpleTreeVisitor))() { + visitThrow: function(tn) { + print("in visitThrow " + tn.expression.value); + } + }); + +parse("try.js", "try { func() } catch(e) {}", + visitor = new (Java.extend(SimpleTreeVisitor))() { + visitTry: function(tn) { + print("in visitTry"); + Java.super(visitor).visitTry(tn, null); + }, + visitCatch: function(cn) { + print("in visitCatch " + cn.parameter.name); + } + }); + +function unaryExpr(name, code) { + parse(name, code, + new (Java.extend(SimpleTreeVisitor))() { + visitUnary: function(un) { + print("in visitUnary " + un.kind + " " + un.expression.name); + } + }); +} + +unaryExpr("postincr.js", "x++"); +unaryExpr("postdecr.js", "x--"); +unaryExpr("preincr.js", "++x"); +unaryExpr("predecr.js", "--x"); +unaryExpr("plus.js", "+x"); +unaryExpr("minus.js", "-x"); +unaryExpr("complement.js", "~x"); +unaryExpr("logical_compl.js", "!x"); +unaryExpr("delete.js", "delete x"); +unaryExpr("typeof.js", "typeof x"); +unaryExpr("void.js", "void x"); + +parse("var.js", "var x = 34;", + new (Java.extend(SimpleTreeVisitor))() { + visitVariable: function(vn) { + print("in visitVariable " + vn.name + " = " + vn.initializer.value); + } + }); + +parse("while.js", "while(true) {}", + new (Java.extend(SimpleTreeVisitor))() { + visitWhileLoop: function() { + print("in visitWhileLoop"); + } + }); + +parse("with.js", "with({}) {}", + new (Java.extend(SimpleTreeVisitor))() { + visitWith: function() { + print("in visitWith"); + } + }); --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/test/script/nosecurity/parservisitor.js.EXPECTED 2015-03-09 18:40:10.984035043 +0530 @@ -0,0 +1,87 @@ +in visitArrayAccess this eval +in visitArrayLiteral +2 +3 +22 +in visitAssignment x 33 +in visitBinary PLUS 3, 4 +in visitBinary MINUS 3, 4 +in visitBinary MULTIPLY 3, 4 +in visitBinary DIVIDE 3, 4 +in visitBinary REMAINDER 3, 4 +in visitBinary RIGHT_SHIFT 3, 4 +in visitBinary UNSIGNED_RIGHT_SHIFT 3, 4 +in visitBinary LEFT_SHIFT 3, 4 +in visitBinary LESS_THAN 3, 4 +in visitBinary LESS_THAN_EQUAL 3, 4 +in visitBinary GREATER_THAN 3, 4 +in visitBinary GREATER_THAN_EQUAL 3, 4 +in visitBinary IN 3, undefined +in visitBinary EQUAL_TO 3, 3 +in visitBinary NOT_EQUAL_TO 3, 2 +in visitBinary STRICT_EQUAL_TO 3, 2 +in visitBinary STRICT_NOT_EQUAL_TO 3, 2 +in visitBinary AND 3, 2 +in visitBinary OR 3, 2 +in visitBinary XOR 3, 2 +in visitBinary CONDITIONAL_AND 3, 2 +in visitBinary CONDITIONAL_OR 3, 2 +in visitBinary COMMA 3, 2 +in visitBlock +in visitBreak +in visitCompoundAssignment MULTIPLY_ASSIGNMENT x 3 +in visitCompoundAssignment DIVIDE_ASSIGNMENT x 3 +in visitCompoundAssignment REMAINDER_ASSIGNMENT x 3 +in visitCompoundAssignment PLUS_ASSIGNMENT x 3 +in visitCompoundAssignment MINUS_ASSIGNMENT x 3 +in visitCompoundAssignment LEFT_SHIFT_ASSIGNMENT x 3 +in visitCompoundAssignment RIGHT_SHIFT_ASSIGNMENT x 3 +in visitCompoundAssignment UNSIGNED_RIGHT_SHIFT_ASSIGNMENT x 3 +in visitCompoundAssignment AND_ASSIGNMENT x 3 +in visitCompoundAssignment XOR_ASSIGNMENT x 3 +in visitCompoundAssignment OR_ASSIGNMENT x 3 +in visitConditionalExpression +in visitContinue +in visitDebugger +in visitDoWhileLoop +in visitEmptyStatement +in visitExpressionStatement +in visitForInLoop +in visitForLoop +in visitFunctionCall func +in visitFunctionDeclaration func +in visitFunctionExpression +in visitIdentifier this +in visitIf +in visitInstanceOf +in visitLabeledStatement +in visitLiteral BOOLEAN_LITERAL true +in visitLiteral NUMBER_LITERAL 3.14 +in visitLiteral STRING_LITERAL hello +in visitLiteral NULL_LITERAL null +in visitMemberSelect foo +in visitNew +in visitObjectLiteral +in visitProperty foo +in visitRegExpLiteral [a-b] i +in visitReturn 33 +in visitSwitch +in visitCase +in visitCase (default) +in visitThrow 2 +in visitTry +in visitCatch e +in visitUnary POSTFIX_INCREMENT x +in visitUnary POSTFIX_DECREMENT x +in visitUnary PREFIX_INCREMENT x +in visitUnary PREFIX_DECREMENT x +in visitUnary PLUS x +in visitUnary MINUS x +in visitUnary BITWISE_COMPLEMENT x +in visitUnary LOGICAL_COMPLEMENT x +in visitUnary DELETE x +in visitUnary TYPEOF x +in visitUnary VOID x +in visitVariable x = 34 +in visitWhileLoop +in visitWith --- /dev/null 2015-03-09 08:23:42.456618816 +0530 +++ new/test/src/jdk/nashorn/api/tree/ParseAPITest.java 2015-03-09 18:40:11.612038137 +0530 @@ -0,0 +1,188 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package jdk.nashorn.api.tree; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import org.testng.Assert; +import org.testng.annotations.Test; + +/** + * Test for nashorn Parser API (jdk.nashorn.api.tree.*) + */ +public class ParseAPITest { + + private static final boolean VERBOSE = Boolean.valueOf(System.getProperty("parserapitest.verbose")); + private static final boolean TEST262 = Boolean.valueOf(System.getProperty("parserapitest.test262")); + + private static final String TEST_BASIC_DIR = System.getProperty("test.basic.dir"); + private static final String TEST_MAPTESTS_DIR = System.getProperty("test.maptests.dir"); + private static final String TEST_SANDBOX_DIR = System.getProperty("test.sandbox.dir"); + private static final String TEST_TRUSTED_DIR = System.getProperty("test.trusted.dir"); + private static final String TEST262_SUITE_DIR = System.getProperty("test262.suite.dir"); + + interface TestFilter { + public boolean exclude(File file, String content); + } + + private void log(String msg) { + org.testng.Reporter.log(msg, true); + } + + private static final String[] options = new String[] { + "-scripting", "--const-as-var" + }; + + @Test + public void parseAllTests() { + if (TEST262) { + parseTestSet(TEST262_SUITE_DIR, new TestFilter() { + @Override + public boolean exclude(final File file, final String content) { + return content.indexOf("@negative") != -1; + } + }); + } + parseTestSet(TEST_BASIC_DIR, new TestFilter() { + @Override + public boolean exclude(final File file, final String content) { + return file.getParentFile().getName().equals("es6"); + } + }); + parseTestSet(TEST_MAPTESTS_DIR, null); + parseTestSet(TEST_SANDBOX_DIR, null); + parseTestSet(TEST_TRUSTED_DIR, null); + } + + private void parseTestSet(final String testSet, final TestFilter filter) { + passed = 0; + failed = 0; + skipped = 0; + + final File testSetDir = new File(testSet); + if (! testSetDir.isDirectory()) { + log("WARNING: " + testSetDir + " not found or not a directory"); + return; + } + log(testSetDir.getAbsolutePath()); + parseJSDirectory(testSetDir, filter); + + log(testSet + " parse API done!"); + log("parse API ok: " + passed); + log("parse API failed: " + failed); + log("parse API skipped: " + skipped); + if (failed != 0) { + Assert.fail(failed + " tests failed to parse in " + testSetDir.getAbsolutePath()); + } + } + + // number of scripts that parsed fine + private int passed; + // number of scripts resulting in parse failure + private int failed; + // scripts that were skipped - all tests with @negative are + // skipped for now. + private int skipped; + + private void parseJSDirectory(final File dir, final TestFilter filter) { + for (final File f : dir.listFiles()) { + if (f.isDirectory()) { + parseJSDirectory(f, filter); + } else if (f.getName().endsWith(".js")) { + parseJSFile(f, filter); + } + } + } + + private void parseJSFile(final File file, final TestFilter filter) { + if (VERBOSE) { + log("Begin parsing " + file.getAbsolutePath()); + } + + try { + final char[] buffer = readFully(file); + final String content = new String(buffer); + boolean excluded = false; + if (filter != null) { + excluded = filter.exclude(file, content); + } + + if (excluded) { + if (VERBOSE) { + log("Skipping " + file.getAbsolutePath()); + } + skipped++; + return; + } + + final Parser parser = Parser.create(options); + final Tree tree = parser.parse(file.getAbsolutePath(), content, null); + tree.accept(new SimpleTreeVisitorES5_1(), null); + passed++; + } catch (final Throwable exp) { + log("Parse API failed: " + file.getAbsolutePath() + " : " + exp); + //if (VERBOSE) { + exp.printStackTrace(System.out); + //} + failed++; + } + + if (VERBOSE) { + log("Done parsing via parser API " + file.getAbsolutePath()); + } + } + + private static char[] byteToCharArray(final byte[] bytes) { + Charset cs = StandardCharsets.UTF_8; + int start = 0; + // BOM detection. + if (bytes.length > 1 && bytes[0] == (byte) 0xFE && bytes[1] == (byte) 0xFF) { + start = 2; + cs = StandardCharsets.UTF_16BE; + } else if (bytes.length > 1 && bytes[0] == (byte) 0xFF && bytes[1] == (byte) 0xFE) { + start = 2; + cs = StandardCharsets.UTF_16LE; + } else if (bytes.length > 2 && bytes[0] == (byte) 0xEF && bytes[1] == (byte) 0xBB && bytes[2] == (byte) 0xBF) { + start = 3; + cs = StandardCharsets.UTF_8; + } else if (bytes.length > 3 && bytes[0] == (byte) 0xFF && bytes[1] == (byte) 0xFE && bytes[2] == 0 && bytes[3] == 0) { + start = 4; + cs = Charset.forName("UTF-32LE"); + } else if (bytes.length > 3 && bytes[0] == 0 && bytes[1] == 0 && bytes[2] == (byte) 0xFE && bytes[3] == (byte) 0xFF) { + start = 4; + cs = Charset.forName("UTF-32BE"); + } + + return new String(bytes, start, bytes.length - start, cs).toCharArray(); + } + + private static char[] readFully(final File file) throws IOException { + final byte[] buf = Files.readAllBytes(file.toPath()); + return byteToCharArray(buf); + } +}