Java Code Examples for jdk.nashorn.internal.ir.SwitchNode#setExpression()
The following examples show how to use
jdk.nashorn.internal.ir.SwitchNode#setExpression() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Parser.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
/** * SwitchStatement : * switch ( Expression ) CaseBlock * * CaseBlock : * { CaseClauses? } * { CaseClauses? DefaultClause CaseClauses } * * CaseClauses : * CaseClause * CaseClauses CaseClause * * CaseClause : * case Expression : StatementList? * * DefaultClause : * default : StatementList? * * See 12.11 * * Parse SWITCH statement. */ private void switchStatement() { final int switchLine = line; final long switchToken = token; // SWITCH tested in caller. next(); // Create and add switch statement. SwitchNode switchNode = new SwitchNode(switchLine, switchToken, Token.descPosition(switchToken), null, new ArrayList<CaseNode>(), null); lc.push(switchNode); try { expect(LPAREN); switchNode = switchNode.setExpression(lc, expression()); expect(RPAREN); expect(LBRACE); // Prepare to accumulate cases. final List<CaseNode> cases = new ArrayList<>(); CaseNode defaultCase = null; while (type != RBRACE) { // Prepare for next case. Expression caseExpression = null; final long caseToken = token; switch (type) { case CASE: next(); caseExpression = expression(); break; case DEFAULT: if (defaultCase != null) { throw error(AbstractParser.message("duplicate.default.in.switch")); } next(); break; default: // Force an error. expect(CASE); break; } expect(COLON); // Get CASE body. final Block statements = getBlock(false); final CaseNode caseNode = new CaseNode(caseToken, finish, caseExpression, statements); statements.setFinish(finish); if (caseExpression == null) { defaultCase = caseNode; } cases.add(caseNode); } switchNode = switchNode.setCases(lc, cases, defaultCase); next(); switchNode.setFinish(finish); appendStatement(switchNode); } finally { lc.pop(switchNode); } }
Example 2
Source File: Parser.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
/** * SwitchStatement : * switch ( Expression ) CaseBlock * * CaseBlock : * { CaseClauses? } * { CaseClauses? DefaultClause CaseClauses } * * CaseClauses : * CaseClause * CaseClauses CaseClause * * CaseClause : * case Expression : StatementList? * * DefaultClause : * default : StatementList? * * See 12.11 * * Parse SWITCH statement. */ private void switchStatement() { final int switchLine = line; final long switchToken = token; // SWITCH tested in caller. next(); // Create and add switch statement. SwitchNode switchNode = new SwitchNode(switchLine, switchToken, Token.descPosition(switchToken), null, new ArrayList<CaseNode>(), null); lc.push(switchNode); try { expect(LPAREN); switchNode = switchNode.setExpression(lc, expression()); expect(RPAREN); expect(LBRACE); // Prepare to accumulate cases. final List<CaseNode> cases = new ArrayList<>(); CaseNode defaultCase = null; while (type != RBRACE) { // Prepare for next case. Expression caseExpression = null; final long caseToken = token; switch (type) { case CASE: next(); caseExpression = expression(); break; case DEFAULT: if (defaultCase != null) { throw error(AbstractParser.message("duplicate.default.in.switch")); } next(); break; default: // Force an error. expect(CASE); break; } expect(COLON); // Get CASE body. final Block statements = getBlock(false); final CaseNode caseNode = new CaseNode(caseToken, finish, caseExpression, statements); statements.setFinish(finish); if (caseExpression == null) { defaultCase = caseNode; } cases.add(caseNode); } switchNode = switchNode.setCases(lc, cases, defaultCase); next(); switchNode.setFinish(finish); appendStatement(switchNode); } finally { lc.pop(switchNode); } }
Example 3
Source File: Parser.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
/** * SwitchStatement : * switch ( Expression ) CaseBlock * * CaseBlock : * { CaseClauses? } * { CaseClauses? DefaultClause CaseClauses } * * CaseClauses : * CaseClause * CaseClauses CaseClause * * CaseClause : * case Expression : StatementList? * * DefaultClause : * default : StatementList? * * See 12.11 * * Parse SWITCH statement. */ private void switchStatement() { final int switchLine = line; final long switchToken = token; // SWITCH tested in caller. next(); // Create and add switch statement. SwitchNode switchNode = new SwitchNode(switchLine, switchToken, Token.descPosition(switchToken), null, new ArrayList<CaseNode>(), null); lc.push(switchNode); try { expect(LPAREN); switchNode = switchNode.setExpression(lc, expression()); expect(RPAREN); expect(LBRACE); // Prepare to accumulate cases. final List<CaseNode> cases = new ArrayList<>(); CaseNode defaultCase = null; while (type != RBRACE) { // Prepare for next case. Expression caseExpression = null; final long caseToken = token; switch (type) { case CASE: next(); caseExpression = expression(); break; case DEFAULT: if (defaultCase != null) { throw error(AbstractParser.message("duplicate.default.in.switch")); } next(); break; default: // Force an error. expect(CASE); break; } expect(COLON); // Get CASE body. final Block statements = getBlock(false); final CaseNode caseNode = new CaseNode(caseToken, finish, caseExpression, statements); statements.setFinish(finish); if (caseExpression == null) { defaultCase = caseNode; } cases.add(caseNode); } switchNode = switchNode.setCases(lc, cases, defaultCase); next(); switchNode.setFinish(finish); appendStatement(switchNode); } finally { lc.pop(switchNode); } }
Example 4
Source File: Parser.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
/** * SwitchStatement : * switch ( Expression ) CaseBlock * * CaseBlock : * { CaseClauses? } * { CaseClauses? DefaultClause CaseClauses } * * CaseClauses : * CaseClause * CaseClauses CaseClause * * CaseClause : * case Expression : StatementList? * * DefaultClause : * default : StatementList? * * See 12.11 * * Parse SWITCH statement. */ private void switchStatement() { final int switchLine = line; final long switchToken = token; // SWITCH tested in caller. next(); // Create and add switch statement. SwitchNode switchNode = new SwitchNode(switchLine, switchToken, Token.descPosition(switchToken), null, new ArrayList<CaseNode>(), null); lc.push(switchNode); try { expect(LPAREN); switchNode = switchNode.setExpression(lc, expression()); expect(RPAREN); expect(LBRACE); // Prepare to accumulate cases. final List<CaseNode> cases = new ArrayList<>(); CaseNode defaultCase = null; while (type != RBRACE) { // Prepare for next case. Expression caseExpression = null; final long caseToken = token; switch (type) { case CASE: next(); caseExpression = expression(); break; case DEFAULT: if (defaultCase != null) { throw error(AbstractParser.message("duplicate.default.in.switch")); } next(); break; default: // Force an error. expect(CASE); break; } expect(COLON); // Get CASE body. final Block statements = getBlock(false); final CaseNode caseNode = new CaseNode(caseToken, finish, caseExpression, statements); statements.setFinish(finish); if (caseExpression == null) { defaultCase = caseNode; } cases.add(caseNode); } switchNode = switchNode.setCases(lc, cases, defaultCase); next(); switchNode.setFinish(finish); appendStatement(switchNode); } finally { lc.pop(switchNode); } }
Example 5
Source File: Parser.java From hottub with GNU General Public License v2.0 | 4 votes |
/** * SwitchStatement : * switch ( Expression ) CaseBlock * * CaseBlock : * { CaseClauses? } * { CaseClauses? DefaultClause CaseClauses } * * CaseClauses : * CaseClause * CaseClauses CaseClause * * CaseClause : * case Expression : StatementList? * * DefaultClause : * default : StatementList? * * See 12.11 * * Parse SWITCH statement. */ private void switchStatement() { final int switchLine = line; final long switchToken = token; // SWITCH tested in caller. next(); // Create and add switch statement. SwitchNode switchNode = new SwitchNode(switchLine, switchToken, Token.descPosition(switchToken), null, new ArrayList<CaseNode>(), null); lc.push(switchNode); try { expect(LPAREN); switchNode = switchNode.setExpression(lc, expression()); expect(RPAREN); expect(LBRACE); // Prepare to accumulate cases. final List<CaseNode> cases = new ArrayList<>(); CaseNode defaultCase = null; while (type != RBRACE) { // Prepare for next case. Expression caseExpression = null; final long caseToken = token; switch (type) { case CASE: next(); caseExpression = expression(); break; case DEFAULT: if (defaultCase != null) { throw error(AbstractParser.message("duplicate.default.in.switch")); } next(); break; default: // Force an error. expect(CASE); break; } expect(COLON); // Get CASE body. final Block statements = getBlock(false); final CaseNode caseNode = new CaseNode(caseToken, finish, caseExpression, statements); statements.setFinish(finish); if (caseExpression == null) { defaultCase = caseNode; } cases.add(caseNode); } switchNode = switchNode.setCases(lc, cases, defaultCase); next(); switchNode.setFinish(finish); appendStatement(switchNode); } finally { lc.pop(switchNode); } }
Example 6
Source File: Parser.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
/** * SwitchStatement : * switch ( Expression ) CaseBlock * * CaseBlock : * { CaseClauses? } * { CaseClauses? DefaultClause CaseClauses } * * CaseClauses : * CaseClause * CaseClauses CaseClause * * CaseClause : * case Expression : StatementList? * * DefaultClause : * default : StatementList? * * See 12.11 * * Parse SWITCH statement. */ private void switchStatement() { final int switchLine = line; final long switchToken = token; // SWITCH tested in caller. next(); // Create and add switch statement. SwitchNode switchNode = new SwitchNode(switchLine, switchToken, Token.descPosition(switchToken), null, new ArrayList<CaseNode>(), null); lc.push(switchNode); try { expect(LPAREN); switchNode = switchNode.setExpression(lc, expression()); expect(RPAREN); expect(LBRACE); // Prepare to accumulate cases. final List<CaseNode> cases = new ArrayList<>(); CaseNode defaultCase = null; while (type != RBRACE) { // Prepare for next case. Expression caseExpression = null; final long caseToken = token; switch (type) { case CASE: next(); caseExpression = expression(); break; case DEFAULT: if (defaultCase != null) { throw error(AbstractParser.message("duplicate.default.in.switch")); } next(); break; default: // Force an error. expect(CASE); break; } expect(COLON); // Get CASE body. final Block statements = getBlock(false); final CaseNode caseNode = new CaseNode(caseToken, finish, caseExpression, statements); statements.setFinish(finish); if (caseExpression == null) { defaultCase = caseNode; } cases.add(caseNode); } switchNode = switchNode.setCases(lc, cases, defaultCase); next(); switchNode.setFinish(finish); appendStatement(switchNode); } finally { lc.pop(switchNode); } }
Example 7
Source File: Parser.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
/** * SwitchStatement : * switch ( Expression ) CaseBlock * * CaseBlock : * { CaseClauses? } * { CaseClauses? DefaultClause CaseClauses } * * CaseClauses : * CaseClause * CaseClauses CaseClause * * CaseClause : * case Expression : StatementList? * * DefaultClause : * default : StatementList? * * See 12.11 * * Parse SWITCH statement. */ private void switchStatement() { final int switchLine = line; final long switchToken = token; // SWITCH tested in caller. next(); // Create and add switch statement. SwitchNode switchNode = new SwitchNode(switchLine, switchToken, Token.descPosition(switchToken), null, new ArrayList<CaseNode>(), null); lc.push(switchNode); try { expect(LPAREN); switchNode = switchNode.setExpression(lc, expression()); expect(RPAREN); expect(LBRACE); // Prepare to accumulate cases. final List<CaseNode> cases = new ArrayList<>(); CaseNode defaultCase = null; while (type != RBRACE) { // Prepare for next case. Expression caseExpression = null; final long caseToken = token; switch (type) { case CASE: next(); caseExpression = expression(); break; case DEFAULT: if (defaultCase != null) { throw error(AbstractParser.message("duplicate.default.in.switch")); } next(); break; default: // Force an error. expect(CASE); break; } expect(COLON); // Get CASE body. final Block statements = getBlock(false); final CaseNode caseNode = new CaseNode(caseToken, finish, caseExpression, statements); statements.setFinish(finish); if (caseExpression == null) { defaultCase = caseNode; } cases.add(caseNode); } switchNode = switchNode.setCases(lc, cases, defaultCase); next(); switchNode.setFinish(finish); appendStatement(switchNode); } finally { lc.pop(switchNode); } }
Example 8
Source File: Parser.java From jdk8u_nashorn with GNU General Public License v2.0 | 4 votes |
/** * SwitchStatement : * switch ( Expression ) CaseBlock * * CaseBlock : * { CaseClauses? } * { CaseClauses? DefaultClause CaseClauses } * * CaseClauses : * CaseClause * CaseClauses CaseClause * * CaseClause : * case Expression : StatementList? * * DefaultClause : * default : StatementList? * * See 12.11 * * Parse SWITCH statement. */ private void switchStatement() { final int switchLine = line; final long switchToken = token; // SWITCH tested in caller. next(); // Create and add switch statement. SwitchNode switchNode = new SwitchNode(switchLine, switchToken, Token.descPosition(switchToken), null, new ArrayList<CaseNode>(), null); lc.push(switchNode); try { expect(LPAREN); switchNode = switchNode.setExpression(lc, expression()); expect(RPAREN); expect(LBRACE); // Prepare to accumulate cases. final List<CaseNode> cases = new ArrayList<>(); CaseNode defaultCase = null; while (type != RBRACE) { // Prepare for next case. Expression caseExpression = null; final long caseToken = token; switch (type) { case CASE: next(); caseExpression = expression(); break; case DEFAULT: if (defaultCase != null) { throw error(AbstractParser.message("duplicate.default.in.switch")); } next(); break; default: // Force an error. expect(CASE); break; } expect(COLON); // Get CASE body. final Block statements = getBlock(false); final CaseNode caseNode = new CaseNode(caseToken, finish, caseExpression, statements); statements.setFinish(finish); if (caseExpression == null) { defaultCase = caseNode; } cases.add(caseNode); } switchNode = switchNode.setCases(lc, cases, defaultCase); next(); switchNode.setFinish(finish); appendStatement(switchNode); } finally { lc.pop(switchNode); } }
Example 9
Source File: Parser.java From nashorn with GNU General Public License v2.0 | 4 votes |
/** * SwitchStatement : * switch ( Expression ) CaseBlock * * CaseBlock : * { CaseClauses? } * { CaseClauses? DefaultClause CaseClauses } * * CaseClauses : * CaseClause * CaseClauses CaseClause * * CaseClause : * case Expression : StatementList? * * DefaultClause : * default : StatementList? * * See 12.11 * * Parse SWITCH statement. */ private void switchStatement() { final int switchLine = line; final long switchToken = token; // SWITCH tested in caller. next(); // Create and add switch statement. SwitchNode switchNode = new SwitchNode(switchLine, switchToken, Token.descPosition(switchToken), null, new ArrayList<CaseNode>(), null); lc.push(switchNode); try { expect(LPAREN); switchNode = switchNode.setExpression(lc, expression()); expect(RPAREN); expect(LBRACE); // Prepare to accumulate cases. final List<CaseNode> cases = new ArrayList<>(); CaseNode defaultCase = null; while (type != RBRACE) { // Prepare for next case. Expression caseExpression = null; final long caseToken = token; switch (type) { case CASE: next(); caseExpression = expression(); break; case DEFAULT: if (defaultCase != null) { throw error(AbstractParser.message("duplicate.default.in.switch")); } next(); break; default: // Force an error. expect(CASE); break; } expect(COLON); // Get CASE body. final Block statements = getBlock(false); final CaseNode caseNode = new CaseNode(caseToken, finish, caseExpression, statements); statements.setFinish(finish); if (caseExpression == null) { defaultCase = caseNode; } cases.add(caseNode); } switchNode = switchNode.setCases(lc, cases, defaultCase); next(); switchNode.setFinish(finish); appendStatement(switchNode); } finally { lc.pop(switchNode); } }