Java Code Examples for jdk.nashorn.internal.ir.Node#isTerminal()
The following examples show how to use
jdk.nashorn.internal.ir.Node#isTerminal() .
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: PrintVisitor.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
@Override public boolean enterBlock(final Block block) { sb.append(' '); sb.append('{'); indent += TABWIDTH; final List<Statement> statements = block.getStatements(); for (final Node statement : statements) { if (printLineNumbers && (statement instanceof Statement)) { final int lineNumber = ((Statement)statement).getLineNumber(); sb.append('\n'); if (lineNumber != lastLineNumber) { indent(); sb.append("[|").append(lineNumber).append("|];").append('\n'); } lastLineNumber = lineNumber; } indent(); statement.accept(this); if (statement instanceof FunctionNode) { continue; } int lastIndex = sb.length() - 1; char lastChar = sb.charAt(lastIndex); while (Character.isWhitespace(lastChar) && lastIndex >= 0) { lastChar = sb.charAt(--lastIndex); } if (lastChar != '}' && lastChar != ';') { sb.append(';'); } if (statement.hasGoto()) { sb.append(" [GOTO]"); } if (statement.isTerminal()) { sb.append(" [TERMINAL]"); } } indent -= TABWIDTH; sb.append(EOLN); indent(); sb.append('}'); return false; }
Example 2
Source File: CodeGenerator.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
@Override public boolean enterWithNode(final WithNode withNode) { final Expression expression = withNode.getExpression(); final Node body = withNode.getBody(); // It is possible to have a "pathological" case where the with block does not reference *any* identifiers. It's // pointless, but legal. In that case, if nothing else in the method forced the assignment of a slot to the // scope object, its' possible that it won't have a slot assigned. In this case we'll only evaluate expression // for its side effect and visit the body, and not bother opening and closing a WithObject. final boolean hasScope = method.hasScope(); final Label tryLabel; if (hasScope) { tryLabel = new Label("with_try"); method.label(tryLabel); method.loadCompilerConstant(SCOPE); } else { tryLabel = null; } load(expression, Type.OBJECT); if (hasScope) { // Construct a WithObject if we have a scope method.invoke(ScriptRuntime.OPEN_WITH); method.storeCompilerConstant(SCOPE); } else { // We just loaded the expression for its side effect and to check // for null or undefined value. globalCheckObjectCoercible(); } // Always process body body.accept(this); if (hasScope) { // Ensure we always close the WithObject final Label endLabel = new Label("with_end"); final Label catchLabel = new Label("with_catch"); final Label exitLabel = new Label("with_exit"); if (!body.isTerminal()) { closeWith(); method._goto(exitLabel); } method.label(endLabel); method._catch(catchLabel); closeWith(); method.athrow(); method.label(exitLabel); method._try(tryLabel, endLabel, catchLabel); } return false; }
Example 3
Source File: PrintVisitor.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
@Override public boolean enterBlock(final Block block) { sb.append(' '); sb.append('{'); indent += TABWIDTH; final List<Statement> statements = block.getStatements(); for (final Node statement : statements) { if (printLineNumbers && (statement instanceof Statement)) { final int lineNumber = ((Statement)statement).getLineNumber(); sb.append('\n'); if (lineNumber != lastLineNumber) { indent(); sb.append("[|").append(lineNumber).append("|];").append('\n'); } lastLineNumber = lineNumber; } indent(); statement.accept(this); if (statement instanceof FunctionNode) { continue; } int lastIndex = sb.length() - 1; char lastChar = sb.charAt(lastIndex); while (Character.isWhitespace(lastChar) && lastIndex >= 0) { lastChar = sb.charAt(--lastIndex); } if (lastChar != '}' && lastChar != ';') { sb.append(';'); } if (statement.hasGoto()) { sb.append(" [GOTO]"); } if (statement.isTerminal()) { sb.append(" [TERMINAL]"); } } indent -= TABWIDTH; sb.append(EOLN); indent(); sb.append('}'); return false; }
Example 4
Source File: CodeGenerator.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
@Override public boolean enterWithNode(final WithNode withNode) { final Expression expression = withNode.getExpression(); final Node body = withNode.getBody(); // It is possible to have a "pathological" case where the with block does not reference *any* identifiers. It's // pointless, but legal. In that case, if nothing else in the method forced the assignment of a slot to the // scope object, its' possible that it won't have a slot assigned. In this case we'll only evaluate expression // for its side effect and visit the body, and not bother opening and closing a WithObject. final boolean hasScope = method.hasScope(); final Label tryLabel; if (hasScope) { tryLabel = new Label("with_try"); method.label(tryLabel); method.loadCompilerConstant(SCOPE); } else { tryLabel = null; } load(expression, Type.OBJECT); if (hasScope) { // Construct a WithObject if we have a scope method.invoke(ScriptRuntime.OPEN_WITH); method.storeCompilerConstant(SCOPE); } else { // We just loaded the expression for its side effect and to check // for null or undefined value. globalCheckObjectCoercible(); } // Always process body body.accept(this); if (hasScope) { // Ensure we always close the WithObject final Label endLabel = new Label("with_end"); final Label catchLabel = new Label("with_catch"); final Label exitLabel = new Label("with_exit"); if (!body.isTerminal()) { closeWith(); method._goto(exitLabel); } method.label(endLabel); method._catch(catchLabel); closeWith(); method.athrow(); method.label(exitLabel); method._try(tryLabel, endLabel, catchLabel); } return false; }
Example 5
Source File: PrintVisitor.java From nashorn with GNU General Public License v2.0 | 4 votes |
@Override public boolean enterBlock(final Block block) { sb.append(' '); //sb.append(Debug.id(block)); sb.append('{'); indent += TABWIDTH; final List<Statement> statements = block.getStatements(); for (final Node statement : statements) { if (printLineNumbers && (statement instanceof Statement)) { final int lineNumber = ((Statement)statement).getLineNumber(); sb.append('\n'); if (lineNumber != lastLineNumber) { indent(); sb.append("[|").append(lineNumber).append("|];").append('\n'); } lastLineNumber = lineNumber; } indent(); statement.accept(this); if (statement instanceof FunctionNode) { continue; } int lastIndex = sb.length() - 1; char lastChar = sb.charAt(lastIndex); while (Character.isWhitespace(lastChar) && lastIndex >= 0) { lastChar = sb.charAt(--lastIndex); } if (lastChar != '}' && lastChar != ';') { sb.append(';'); } if (statement.hasGoto()) { sb.append(" [GOTO]"); } if (statement.isTerminal()) { sb.append(" [TERMINAL]"); } } indent -= TABWIDTH; sb.append(EOLN); indent(); sb.append('}'); // sb.append(Debug.id(block)); return false; }