Java Code Examples for jdk.nashorn.internal.ir.Block#setStatements()

The following examples show how to use jdk.nashorn.internal.ir.Block#setStatements() . 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-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static Block createFinallyBlock(final Block finallyBody) {
    final List<Statement> newStatements = new ArrayList<>();
    for (final Statement statement : finallyBody.getStatements()) {
        newStatements.add(statement);
        if (statement.hasTerminalFlags()) {
            break;
        }
    }
    return finallyBody.setStatements(null, newStatements);
}
 
Example 2
Source File: Splitter.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Split a block into sub methods.
 *
 * @param block Block or function to split.
 *
 * @return new weight for the resulting block.
 */
private Block splitBlock(final Block block, final FunctionNode function) {

    final List<Statement> splits = new ArrayList<>();
    List<Statement> statements = new ArrayList<>();
    long statementsWeight = 0;

    for (final Statement statement : block.getStatements()) {
        final long weight = WeighNodes.weigh(statement, weightCache);

        if (statementsWeight + weight >= SPLIT_THRESHOLD || statement.isTerminal()) {
            if (!statements.isEmpty()) {
                splits.add(createBlockSplitNode(block, function, statements, statementsWeight));
                statements = new ArrayList<>();
                statementsWeight = 0;
            }
        }

        if (statement.isTerminal()) {
            splits.add(statement);
        } else {
            statements.add(statement);
            statementsWeight += weight;
        }
    }

    if (!statements.isEmpty()) {
        splits.add(createBlockSplitNode(block, function, statements, statementsWeight));
    }

    return block.setStatements(lc, splits);
}
 
Example 3
Source File: Splitter.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Split a block into sub methods.
 *
 * @param block Block or function to split.
 *
 * @return new weight for the resulting block.
 */
private Block splitBlock(final Block block, final FunctionNode function) {

    final List<Statement> splits = new ArrayList<>();
    List<Statement> statements = new ArrayList<>();
    long statementsWeight = 0;

    for (final Statement statement : block.getStatements()) {
        final long weight = WeighNodes.weigh(statement, weightCache);

        if (statementsWeight + weight >= SPLIT_THRESHOLD || statement.isTerminal()) {
            if (!statements.isEmpty()) {
                splits.add(createBlockSplitNode(block, function, statements, statementsWeight));
                statements = new ArrayList<>();
                statementsWeight = 0;
            }
        }

        if (statement.isTerminal()) {
            splits.add(statement);
        } else {
            statements.add(statement);
            statementsWeight += weight;
        }
    }

    if (!statements.isEmpty()) {
        splits.add(createBlockSplitNode(block, function, statements, statementsWeight));
    }

    return block.setStatements(lc, splits);
}
 
Example 4
Source File: Lower.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
private static Block createFinallyBlock(final Block finallyBody) {
    final List<Statement> newStatements = new ArrayList<>();
    for (final Statement statement : finallyBody.getStatements()) {
        newStatements.add(statement);
        if (statement.hasTerminalFlags()) {
            break;
        }
    }
    return finallyBody.setStatements(null, newStatements);
}
 
Example 5
Source File: Splitter.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Split a block into sub methods.
 *
 * @param block Block or function to split.
 *
 * @return new weight for the resulting block.
 */
private Block splitBlock(final Block block, final FunctionNode function) {

    final List<Statement> splits = new ArrayList<>();
    List<Statement> statements = new ArrayList<>();
    long statementsWeight = 0;

    for (final Statement statement : block.getStatements()) {
        final long weight = WeighNodes.weigh(statement, weightCache);

        if (statementsWeight + weight >= SPLIT_THRESHOLD || statement.isTerminal()) {
            if (!statements.isEmpty()) {
                splits.add(createBlockSplitNode(block, function, statements, statementsWeight));
                statements = new ArrayList<>();
                statementsWeight = 0;
            }
        }

        if (statement.isTerminal()) {
            splits.add(statement);
        } else {
            statements.add(statement);
            statementsWeight += weight;
        }
    }

    if (!statements.isEmpty()) {
        splits.add(createBlockSplitNode(block, function, statements, statementsWeight));
    }

    return block.setStatements(lc, splits);
}
 
Example 6
Source File: Splitter.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Split a block into sub methods.
 *
 * @param block Block or function to split.
 *
 * @return new weight for the resulting block.
 */
private Block splitBlock(final Block block, final FunctionNode function) {

    final List<Statement> splits = new ArrayList<>();
    List<Statement> statements = new ArrayList<>();
    long statementsWeight = 0;

    for (final Statement statement : block.getStatements()) {
        final long weight = WeighNodes.weigh(statement, weightCache);

        if (statementsWeight + weight >= SPLIT_THRESHOLD || statement.isTerminal()) {
            if (!statements.isEmpty()) {
                splits.add(createBlockSplitNode(block, function, statements, statementsWeight));
                statements = new ArrayList<>();
                statementsWeight = 0;
            }
        }

        if (statement.isTerminal()) {
            splits.add(statement);
        } else {
            statements.add(statement);
            statementsWeight += weight;
        }
    }

    if (!statements.isEmpty()) {
        splits.add(createBlockSplitNode(block, function, statements, statementsWeight));
    }

    return block.setStatements(lc, splits);
}
 
Example 7
Source File: Splitter.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Split a block into sub methods.
 *
 * @param block Block or function to split.
 *
 * @return new weight for the resulting block.
 */
private Block splitBlock(final Block block, final FunctionNode function) {

    final List<Statement> splits = new ArrayList<>();
    List<Statement> statements = new ArrayList<>();
    long statementsWeight = 0;

    for (final Statement statement : block.getStatements()) {
        final long weight = WeighNodes.weigh(statement, weightCache);

        if (statementsWeight + weight >= SPLIT_THRESHOLD || statement.isTerminal()) {
            if (!statements.isEmpty()) {
                splits.add(createBlockSplitNode(block, function, statements, statementsWeight));
                statements = new ArrayList<>();
                statementsWeight = 0;
            }
        }

        if (statement.isTerminal()) {
            splits.add(statement);
        } else {
            statements.add(statement);
            statementsWeight += weight;
        }
    }

    if (!statements.isEmpty()) {
        splits.add(createBlockSplitNode(block, function, statements, statementsWeight));
    }

    return block.setStatements(lc, splits);
}
 
Example 8
Source File: Lower.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private static Block createFinallyBlock(final Block finallyBody) {
    final List<Statement> newStatements = new ArrayList<>();
    for (final Statement statement : finallyBody.getStatements()) {
        newStatements.add(statement);
        if (statement.hasTerminalFlags()) {
            break;
        }
    }
    return finallyBody.setStatements(null, newStatements);
}
 
Example 9
Source File: Splitter.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Split a block into sub methods.
 *
 * @param block Block or function to split.
 *
 * @return new weight for the resulting block.
 */
private Block splitBlock(final Block block, final FunctionNode function) {

    final List<Statement> splits = new ArrayList<>();
    List<Statement> statements = new ArrayList<>();
    long statementsWeight = 0;

    for (final Statement statement : block.getStatements()) {
        final long weight = WeighNodes.weigh(statement, weightCache);

        if (statementsWeight + weight >= SPLIT_THRESHOLD || statement.isTerminal()) {
            if (!statements.isEmpty()) {
                splits.add(createBlockSplitNode(block, function, statements, statementsWeight));
                statements = new ArrayList<>();
                statementsWeight = 0;
            }
        }

        if (statement.isTerminal()) {
            splits.add(statement);
        } else {
            statements.add(statement);
            statementsWeight += weight;
        }
    }

    if (!statements.isEmpty()) {
        splits.add(createBlockSplitNode(block, function, statements, statementsWeight));
    }

    return block.setStatements(lc, splits);
}
 
Example 10
Source File: Lower.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static Block createFinallyBlock(final Block finallyBody) {
    final List<Statement> newStatements = new ArrayList<>();
    for (final Statement statement : finallyBody.getStatements()) {
        newStatements.add(statement);
        if (statement.hasTerminalFlags()) {
            break;
        }
    }
    return finallyBody.setStatements(null, newStatements);
}
 
Example 11
Source File: Splitter.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Split a block into sub methods.
 *
 * @param block Block or function to split.
 *
 * @return new weight for the resulting block.
 */
private Block splitBlock(final Block block, final FunctionNode function) {

    final List<Statement> splits = new ArrayList<>();
    List<Statement> statements = new ArrayList<>();
    long statementsWeight = 0;

    for (final Statement statement : block.getStatements()) {
        final long weight = WeighNodes.weigh(statement, weightCache);

        if (statementsWeight + weight >= SPLIT_THRESHOLD || statement.isTerminal()) {
            if (!statements.isEmpty()) {
                splits.add(createBlockSplitNode(block, function, statements, statementsWeight));
                statements = new ArrayList<>();
                statementsWeight = 0;
            }
        }

        if (statement.isTerminal()) {
            splits.add(statement);
        } else {
            statements.add(statement);
            statementsWeight += weight;
        }
    }

    if (!statements.isEmpty()) {
        splits.add(createBlockSplitNode(block, function, statements, statementsWeight));
    }

    return block.setStatements(lc, splits);
}
 
Example 12
Source File: Lower.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private static Block createFinallyBlock(final Block finallyBody) {
    final List<Statement> newStatements = new ArrayList<>();
    for (final Statement statement : finallyBody.getStatements()) {
        newStatements.add(statement);
        if (statement.hasTerminalFlags()) {
            break;
        }
    }
    return finallyBody.setStatements(null, newStatements);
}
 
Example 13
Source File: Splitter.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Split a block into sub methods.
 *
 * @param block Block or function to split.
 *
 * @return new weight for the resulting block.
 */
private Block splitBlock(final Block block, final FunctionNode function) {

    final List<Statement> splits = new ArrayList<>();
    List<Statement> statements = new ArrayList<>();
    long statementsWeight = 0;

    for (final Statement statement : block.getStatements()) {
        final long weight = WeighNodes.weigh(statement, weightCache);

        if (statementsWeight + weight >= SPLIT_THRESHOLD || statement.isTerminal()) {
            if (!statements.isEmpty()) {
                splits.add(createBlockSplitNode(block, function, statements, statementsWeight));
                statements = new ArrayList<>();
                statementsWeight = 0;
            }
        }

        if (statement.isTerminal()) {
            splits.add(statement);
        } else {
            statements.add(statement);
            statementsWeight += weight;
        }
    }

    if (!statements.isEmpty()) {
        splits.add(createBlockSplitNode(block, function, statements, statementsWeight));
    }

    return block.setStatements(lc, splits);
}
 
Example 14
Source File: Lower.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static Block createFinallyBlock(final Block finallyBody) {
    final List<Statement> newStatements = new ArrayList<>();
    for (final Statement statement : finallyBody.getStatements()) {
        newStatements.add(statement);
        if (statement.hasTerminalFlags()) {
            break;
        }
    }
    return finallyBody.setStatements(null, newStatements);
}
 
Example 15
Source File: Splitter.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Split a block into sub methods.
 *
 * @param block Block or function to split.
 *
 * @return new weight for the resulting block.
 */
private Block splitBlock(final Block block, final FunctionNode function) {

    final List<Statement> splits = new ArrayList<>();
    List<Statement> statements = new ArrayList<>();
    long statementsWeight = 0;

    for (final Statement statement : block.getStatements()) {
        final long weight = WeighNodes.weigh(statement, weightCache);

        if (statementsWeight + weight >= SPLIT_THRESHOLD || statement.isTerminal()) {
            if (!statements.isEmpty()) {
                splits.add(createBlockSplitNode(block, function, statements, statementsWeight));
                statements = new ArrayList<>();
                statementsWeight = 0;
            }
        }

        if (statement.isTerminal()) {
            splits.add(statement);
        } else {
            statements.add(statement);
            statementsWeight += weight;
        }
    }

    if (!statements.isEmpty()) {
        splits.add(createBlockSplitNode(block, function, statements, statementsWeight));
    }

    return block.setStatements(lc, splits);
}
 
Example 16
Source File: Lower.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private static Block createFinallyBlock(final Block finallyBody) {
    final List<Statement> newStatements = new ArrayList<>();
    for (final Statement statement : finallyBody.getStatements()) {
        newStatements.add(statement);
        if (statement.hasTerminalFlags()) {
            break;
        }
    }
    return finallyBody.setStatements(null, newStatements);
}
 
Example 17
Source File: Splitter.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Split a block into sub methods.
 *
 * @param block Block or function to split.
 *
 * @return new weight for the resulting block.
 */
private Block splitBlock(final Block block, final FunctionNode function) {

    final List<Statement> splits = new ArrayList<>();
    List<Statement> statements = new ArrayList<>();
    long statementsWeight = 0;

    for (final Statement statement : block.getStatements()) {
        final long weight = WeighNodes.weigh(statement, weightCache);

        if (statementsWeight + weight >= SPLIT_THRESHOLD || statement.isTerminal()) {
            if (!statements.isEmpty()) {
                splits.add(createBlockSplitNode(block, function, statements, statementsWeight));
                statements = new ArrayList<>();
                statementsWeight = 0;
            }
        }

        if (statement.isTerminal()) {
            splits.add(statement);
        } else {
            statements.add(statement);
            statementsWeight += weight;
        }
    }

    if (!statements.isEmpty()) {
        splits.add(createBlockSplitNode(block, function, statements, statementsWeight));
    }

    return block.setStatements(lc, splits);
}