Java源码示例:com.sun.tools.javac.tree.JCTree.JCForLoop

示例1
public void visitForLoop(JCForLoop tree) {
    ListBuffer<PendingExit> prevPendingExits = pendingExits;
    scanStats(tree.init);
    pendingExits = new ListBuffer<>();
    if (tree.cond != null) {
        scan(tree.cond);
        alive = !tree.cond.type.isFalse();
    } else {
        alive = true;
    }
    scanStat(tree.body);
    alive |= resolveContinues(tree);
    scan(tree.step);
    alive = resolveBreaks(tree, prevPendingExits) ||
        tree.cond != null && !tree.cond.type.isTrue();
}
 
示例2
private ForStatement convertForLoop(JCForLoop statement) {
  return ForStatement.newBuilder()
      // The order here is important since initializers can define new variables
      // These can be used in the expression, updaters or the body
      // This is why we need to process initializers first
      .setInitializers(convertInitializers(statement.getInitializer()))
      .setConditionExpression(convertExpressionOrNull(statement.getCondition()))
      .setBody(convertStatement(statement.getStatement()))
      .setUpdates(
          convertExpressions(
              statement.getUpdate().stream()
                  .map(JCExpressionStatement::getExpression)
                  .collect(toImmutableList())))
      .setSourcePosition(getSourcePosition(statement))
      .build();
}
 
示例3
public void visitForLoop(JCForLoop tree) {
	try {
		print("for (");
		if (tree.init.nonEmpty()) {
			if (VARDEF.equals(treeTag(tree.init.head))) {
				printExpr(tree.init.head);
				for (List<JCStatement> l = tree.init.tail; l.nonEmpty(); l = l.tail) {
					JCVariableDecl vdef = (JCVariableDecl)l.head;
					print(", " + vdef.name + " = ");
					printExpr(vdef.init);
				}
			} else {
				printExprs(tree.init);
			}
		}
		print("; ");
		if (tree.cond != null) printExpr(tree.cond);
		print("; ");
		printExprs(tree.step);
		print(") ");
		printStat(tree.body);
	} catch (IOException e) {
		throw new UncheckedIOException(e);
	}
}
 
示例4
public void visitForLoop(JCForLoop tree) {
    SourceRange sr = new SourceRange(startPos(tree), endPos(tree));
    sr.mergeWith(csp(tree.init));
    sr.mergeWith(csp(tree.cond));
    sr.mergeWith(csp(tree.step));
    sr.mergeWith(csp(tree.body));
    result = sr;
}
 
示例5
public void visitForLoop(JCForLoop tree) {
    tree.init = translate(tree.init, null);
    if (tree.cond != null)
        tree.cond = translate(tree.cond, syms.booleanType);
    tree.step = translate(tree.step, null);
    tree.body = translate(tree.body);
    result = tree;
}
 
示例6
public void visitForLoop(JCForLoop tree) {
    ListBuffer<FlowPendingExit> prevPendingExits = pendingExits;
    scan(tree.init);
    pendingExits = new ListBuffer<>();
    if (tree.cond != null) {
        scan(tree.cond);
    }
    scan(tree.body);
    resolveContinues(tree);
    scan(tree.step);
    resolveBreaks(tree, prevPendingExits);
}
 
示例7
public void visitForLoop(JCForLoop tree) {
    tree.init = translate(tree.init);
    if (tree.cond != null)
        tree.cond = translate(tree.cond, syms.booleanType);
    tree.step = translate(tree.step);
    tree.body = translate(tree.body);
    result = tree;
}
 
示例8
@Override
public JCForLoop inline(Inliner inliner) throws CouldNotResolveImportException {
  return inliner.maker().ForLoop(
      inliner.inlineList(getInitializer()),
      (getCondition() == null) ? null : getCondition().inline(inliner), 
      com.sun.tools.javac.util.List.convert(
          JCExpressionStatement.class, inliner.inlineList(getUpdate())), 
      getStatement().inline(inliner));
}
 
示例9
public void visitForLoop(JCForLoop tree) {
    ListBuffer<AssignPendingExit> prevPendingExits = pendingExits;
    FlowKind prevFlowKind = flowKind;
    flowKind = FlowKind.NORMAL;
    int nextadrPrev = nextadr;
    scan(tree.init);
    final Bits initsSkip = new Bits(true);
    final Bits uninitsSkip = new Bits(true);
    pendingExits = new ListBuffer<>();
    int prevErrors = log.nerrors;
    do {
        final Bits uninitsEntry = new Bits(uninits);
        uninitsEntry.excludeFrom(nextadr);
        if (tree.cond != null) {
            scanCond(tree.cond);
            if (!flowKind.isFinal()) {
                initsSkip.assign(initsWhenFalse);
                uninitsSkip.assign(uninitsWhenFalse);
            }
            inits.assign(initsWhenTrue);
            uninits.assign(uninitsWhenTrue);
        } else if (!flowKind.isFinal()) {
            initsSkip.assign(inits);
            initsSkip.inclRange(firstadr, nextadr);
            uninitsSkip.assign(uninits);
            uninitsSkip.inclRange(firstadr, nextadr);
        }
        scan(tree.body);
        resolveContinues(tree);
        scan(tree.step);
        if (log.nerrors != prevErrors ||
            flowKind.isFinal() ||
            new Bits(uninitsEntry).diffSet(uninits).nextBit(firstadr) == -1)
            break;
        uninits.assign(uninitsEntry.andSet(uninits));
        flowKind = FlowKind.SPECULATIVE_LOOP;
    } while (true);
    flowKind = prevFlowKind;
    //a variable is DA/DU after a for loop, if it's DA/DU assuming the
    //branch is not taken AND if it's DA/DU before any break statement
    inits.assign(initsSkip);
    uninits.assign(uninitsSkip);
    resolveBreaks(tree, prevPendingExits);
    nextadr = nextadrPrev;
}
 
示例10
@Override
public void visitForLoop(JCForLoop tree) {
    //skip body and var decl (to prevents same statements to be analyzed twice)
    scan(tree.getCondition());
    scan(tree.getUpdate());
}
 
示例11
private Statement convertStatement(JCStatement jcStatement) {
  switch (jcStatement.getKind()) {
    case ASSERT:
      return convertAssert((JCAssert) jcStatement);
    case BLOCK:
      return convertBlock((JCBlock) jcStatement);
    case BREAK:
      return convertBreak((JCBreak) jcStatement);
    case CLASS:
      convertClassDeclaration((JCClassDecl) jcStatement);
      return null;
    case CONTINUE:
      return convertContinue((JCContinue) jcStatement);
    case DO_WHILE_LOOP:
      return convertDoWhileLoop((JCDoWhileLoop) jcStatement);
    case EMPTY_STATEMENT:
      return new EmptyStatement(getSourcePosition(jcStatement));
    case ENHANCED_FOR_LOOP:
      return convertEnhancedForLoop((JCEnhancedForLoop) jcStatement);
    case EXPRESSION_STATEMENT:
      return convertExpressionStatement((JCExpressionStatement) jcStatement);
    case FOR_LOOP:
      return convertForLoop((JCForLoop) jcStatement);
    case IF:
      return convertIf((JCIf) jcStatement);
    case LABELED_STATEMENT:
      return convertLabeledStatement((JCLabeledStatement) jcStatement);
    case RETURN:
      return convertReturn((JCReturn) jcStatement);
    case SWITCH:
      return convertSwitch((JCSwitch) jcStatement);
    case THROW:
      return convertThrow((JCThrow) jcStatement);
    case TRY:
      return convertTry((JCTry) jcStatement);
    case VARIABLE:
      return convertVariableDeclaration((JCVariableDecl) jcStatement);
    case WHILE_LOOP:
      return convertWhileLoop((JCWhileLoop) jcStatement);
    case SYNCHRONIZED:
      return convertSynchronized((JCSynchronized) jcStatement);
    default:
      throw new AssertionError("Unknown statement node type: " + jcStatement.getKind());
  }
}
 
示例12
@Override
public void visitForLoop(JCForLoop tree) {
    scan(tree.getInitializer());
    scan(tree.getCondition());
    scan(tree.getUpdate());
}
 
示例13
public JCForLoop ForLoop(List<JCStatement> init, JCExpression cond, List<JCExpressionStatement> step, JCStatement body) {
	return invoke(ForLoop, init, cond, step, body);
}