com.sun.tools.javac.tree.JCTree.JCForLoop Java Examples

The following examples show how to use com.sun.tools.javac.tree.JCTree.JCForLoop. 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: Flow.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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();
}
 
Example #2
Source File: CompilationUnitBuilder.java    From j2cl with Apache License 2.0 6 votes vote down vote up
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();
}
 
Example #3
Source File: PrettyCommentsPrinter.java    From EasyMPermission with MIT License 6 votes vote down vote up
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);
	}
}
 
Example #4
Source File: CRTable.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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;
}
 
Example #5
Source File: TransTypes.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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;
}
 
Example #6
Source File: Flow.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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);
}
 
Example #7
Source File: Lower.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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;
}
 
Example #8
Source File: UForLoop.java    From Refaster with Apache License 2.0 5 votes vote down vote up
@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));
}
 
Example #9
Source File: Flow.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
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;
}
 
Example #10
Source File: Analyzer.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@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());
}
 
Example #11
Source File: CompilationUnitBuilder.java    From j2cl with Apache License 2.0 4 votes vote down vote up
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());
  }
}
 
Example #12
Source File: Analyzer.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void visitForLoop(JCForLoop tree) {
    scan(tree.getInitializer());
    scan(tree.getCondition());
    scan(tree.getUpdate());
}
 
Example #13
Source File: JavacTreeMaker.java    From EasyMPermission with MIT License 4 votes vote down vote up
public JCForLoop ForLoop(List<JCStatement> init, JCExpression cond, List<JCExpressionStatement> step, JCStatement body) {
	return invoke(ForLoop, init, cond, step, body);
}