Java Code Examples for jdk.nashorn.internal.ir.Statement#getLineNumber()

The following examples show how to use jdk.nashorn.internal.ir.Statement#getLineNumber() . 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: Lower.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Node leaveBlock(final Block block) {
    //now we have committed the entire statement list to the block, but we need to truncate
    //whatever is after the last terminal. block append won't append past it


    if (lc.isFunctionBody()) {
        final FunctionNode currentFunction = lc.getCurrentFunction();
        final boolean isProgram = currentFunction.isProgram();
        final Statement last = lc.getLastStatement();
        final ReturnNode returnNode = new ReturnNode(
            last == null ? currentFunction.getLineNumber() : last.getLineNumber(), //TODO?
            currentFunction.getToken(),
            currentFunction.getFinish(),
            isProgram ?
                compilerConstant(RETURN) :
                LiteralNode.newInstance(block, ScriptRuntime.UNDEFINED));

        returnNode.accept(this);
    }

    return block;
}
 
Example 2
Source File: Lower.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Node leaveBlock(final Block block) {
    //now we have committed the entire statement list to the block, but we need to truncate
    //whatever is after the last terminal. block append won't append past it


    if (lc.isFunctionBody()) {
        final FunctionNode currentFunction = lc.getCurrentFunction();
        final boolean isProgram = currentFunction.isProgram();
        final Statement last = lc.getLastStatement();
        final ReturnNode returnNode = new ReturnNode(
            last == null ? currentFunction.getLineNumber() : last.getLineNumber(), //TODO?
            currentFunction.getToken(),
            currentFunction.getFinish(),
            isProgram ?
                compilerConstant(RETURN) :
                LiteralNode.newInstance(block, ScriptRuntime.UNDEFINED));

        returnNode.accept(this);
    }

    return block;
}
 
Example 3
Source File: Lower.java    From nashorn with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Node leaveBlock(final Block block) {
    //now we have committed the entire statement list to the block, but we need to truncate
    //whatever is after the last terminal. block append won't append past it


    if (lc.isFunctionBody()) {
        final FunctionNode currentFunction = lc.getCurrentFunction();
        final boolean isProgram = currentFunction.isProgram();
        final Statement last = lc.getLastStatement();
        final ReturnNode returnNode = new ReturnNode(
            last == null ? currentFunction.getLineNumber() : last.getLineNumber(), //TODO?
            currentFunction.getToken(),
            currentFunction.getFinish(),
            isProgram ?
                compilerConstant(RETURN) :
                LiteralNode.newInstance(block, ScriptRuntime.UNDEFINED));

        returnNode.accept(this);
    }

    return block;
}
 
Example 4
Source File: PrintVisitor.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean enterBlock(final Block block) {
    sb.append(' ');
    sb.append('{');

    indent += TABWIDTH;

    final List<Statement> statements = block.getStatements();

    for (final Statement statement : statements) {
        if (printLineNumbers) {
            final int lineNumber = statement.getLineNumber();
            sb.append('\n');
            if (lineNumber != lastLineNumber) {
                indent();
                sb.append("[|").append(lineNumber).append("|];").append('\n');
            }
            lastLineNumber = lineNumber;
        }
        indent();

        statement.accept(this);

        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('}');
    printLocalVariableConversion(block);

    return false;
}
 
Example 5
Source File: PrintVisitor.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean enterBlock(final Block block) {
    sb.append(' ');
    sb.append('{');

    indent += TABWIDTH;

    final List<Statement> statements = block.getStatements();

    for (final Statement statement : statements) {
        if (printLineNumbers) {
            final int lineNumber = statement.getLineNumber();
            sb.append('\n');
            if (lineNumber != lastLineNumber) {
                indent();
                sb.append("[|").append(lineNumber).append("|];").append('\n');
            }
            lastLineNumber = lineNumber;
        }
        indent();

        statement.accept(this);

        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('}');
    printLocalVariableConversion(block);

    return false;
}
 
Example 6
Source File: PrintVisitor.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean enterBlock(final Block block) {
    sb.append(' ');
    sb.append('{');

    indent += TABWIDTH;

    final List<Statement> statements = block.getStatements();

    for (final Statement statement : statements) {
        if (printLineNumbers) {
            final int lineNumber = statement.getLineNumber();
            sb.append('\n');
            if (lineNumber != lastLineNumber) {
                indent();
                sb.append("[|").append(lineNumber).append("|];").append('\n');
            }
            lastLineNumber = lineNumber;
        }
        indent();

        statement.accept(this);

        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('}');
    printLocalVariableConversion(block);

    return false;
}
 
Example 7
Source File: PrintVisitor.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean enterBlock(final Block block) {
    sb.append(' ');
    sb.append('{');

    indent += TABWIDTH;

    final List<Statement> statements = block.getStatements();

    for (final Statement statement : statements) {
        if (printLineNumbers) {
            final int lineNumber = statement.getLineNumber();
            sb.append('\n');
            if (lineNumber != lastLineNumber) {
                indent();
                sb.append("[|").append(lineNumber).append("|];").append('\n');
            }
            lastLineNumber = lineNumber;
        }
        indent();

        statement.accept(this);

        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('}');
    printLocalVariableConversion(block);

    return false;
}
 
Example 8
Source File: PrintVisitor.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean enterBlock(final Block block) {
    sb.append(' ');
    sb.append('{');

    indent += TABWIDTH;

    final List<Statement> statements = block.getStatements();

    for (final Statement statement : statements) {
        if (printLineNumbers) {
            final int lineNumber = statement.getLineNumber();
            sb.append('\n');
            if (lineNumber != lastLineNumber) {
                indent();
                sb.append("[|").append(lineNumber).append("|];").append('\n');
            }
            lastLineNumber = lineNumber;
        }
        indent();

        statement.accept(this);

        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('}');
    printLocalVariableConversion(block);

    return false;
}
 
Example 9
Source File: PrintVisitor.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean enterBlock(final Block block) {
    sb.append(' ');
    sb.append('{');

    indent += TABWIDTH;

    final List<Statement> statements = block.getStatements();

    for (final Statement statement : statements) {
        if (printLineNumbers) {
            final int lineNumber = statement.getLineNumber();
            sb.append('\n');
            if (lineNumber != lastLineNumber) {
                indent();
                sb.append("[|").append(lineNumber).append("|];").append('\n');
            }
            lastLineNumber = lineNumber;
        }
        indent();

        statement.accept(this);

        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('}');
    printLocalVariableConversion(block);

    return false;
}
 
Example 10
Source File: PrintVisitor.java    From jdk8u_nashorn with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean enterBlock(final Block block) {
    sb.append(' ');
    sb.append('{');

    indent += TABWIDTH;

    final List<Statement> statements = block.getStatements();

    for (final Statement statement : statements) {
        if (printLineNumbers) {
            final int lineNumber = statement.getLineNumber();
            sb.append('\n');
            if (lineNumber != lastLineNumber) {
                indent();
                sb.append("[|").append(lineNumber).append("|];").append('\n');
            }
            lastLineNumber = lineNumber;
        }
        indent();

        statement.accept(this);

        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('}');
    printLocalVariableConversion(block);

    return false;
}