예제 #1
0
  @SuppressWarnings("rawtypes")
  @Override
  public Node leaveLiteralNode(final LiteralNode literal) {
    long weight = WeighNodes.weigh(literal);

    if (weight < SPLIT_THRESHOLD) {
      return literal;
    }

    final FunctionNode functionNode = lc.getCurrentFunction();

    lc.setFlag(functionNode, FunctionNode.IS_SPLIT);

    if (literal instanceof ArrayLiteralNode) {
      final ArrayLiteralNode arrayLiteralNode = (ArrayLiteralNode) literal;
      final Node[] value = arrayLiteralNode.getValue();
      final int[] postsets = arrayLiteralNode.getPostsets();
      final List<ArrayUnit> units = new ArrayList<>();

      long totalWeight = 0;
      int lo = 0;

      for (int i = 0; i < postsets.length; i++) {
        final int postset = postsets[i];
        final Node element = value[postset];

        weight = WeighNodes.weigh(element);
        totalWeight += WeighNodes.AASTORE_WEIGHT + weight;

        if (totalWeight >= SPLIT_THRESHOLD) {
          final CompileUnit unit = compiler.findUnit(totalWeight - weight);
          units.add(new ArrayUnit(unit, lo, i));
          lo = i;
          totalWeight = weight;
        }
      }

      if (lo != postsets.length) {
        final CompileUnit unit = compiler.findUnit(totalWeight);
        units.add(new ArrayUnit(unit, lo, postsets.length));
      }

      return arrayLiteralNode.setUnits(lc, units);
    }

    return literal;
  }
예제 #2
0
  /**
   * Create a new split node from statements contained in a parent block.
   *
   * @param parent Parent block.
   * @param statements Statements to include.
   * @return New split node.
   */
  private SplitNode createBlockSplitNode(
      final Block parent,
      final FunctionNode function,
      final List<Statement> statements,
      final long weight) {
    final long token = parent.getToken();
    final int finish = parent.getFinish();
    final String name = function.uniqueName(SPLIT_PREFIX.symbolName());

    final Block newBlock = new Block(token, finish, statements);

    return new SplitNode(name, newBlock, compiler.findUnit(weight + WeighNodes.FUNCTION_WEIGHT));
  }
예제 #3
0
 /**
  * Override this logic to look up compile units in a different way
  *
  * @param weight weight needed
  * @return compile unit
  */
 protected CompileUnit findUnit(final long weight) {
   return compiler.findUnit(weight);
 }