< prev index next >

src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Flow.java

Print this page
rev 52724 : imported patch 8214031
rev 52725 : [mq]: 8214031-review1

*** 298,308 **** /** * Base visitor class for all visitors implementing dataflow analysis logic. * This class define the shared logic for handling jumps (break/continue statements). */ ! static abstract class BaseAnalyzer<P extends BaseAnalyzer.PendingExit> extends TreeScanner { enum JumpKind { BREAK(JCTree.Tag.BREAK) { @Override JCTree getTarget(JCTree tree) { --- 298,308 ---- /** * Base visitor class for all visitors implementing dataflow analysis logic. * This class define the shared logic for handling jumps (break/continue statements). */ ! static abstract class BaseAnalyzer extends TreeScanner { enum JumpKind { BREAK(JCTree.Tag.BREAK) { @Override JCTree getTarget(JCTree tree) {
*** 326,336 **** } /** The currently pending exits that go from current inner blocks * to an enclosing block, in source order. */ ! ListBuffer<P> pendingExits; /** A pending exit. These are the statements return, break, and * continue. In addition, exception-throwing expressions or * statements are put here when not known to be caught. This * will typically result in an error unless it is within a --- 326,336 ---- } /** The currently pending exits that go from current inner blocks * to an enclosing block, in source order. */ ! ListBuffer<PendingExit> pendingExits; /** A pending exit. These are the statements return, break, and * continue. In addition, exception-throwing expressions or * statements are put here when not known to be caught. This * will typically result in an error unless it is within a
*** 349,372 **** } abstract void markDead(); /** Record an outward transfer of control. */ ! void recordExit(P pe) { pendingExits.append(pe); markDead(); } /** Resolve all jumps of this statement. */ private Liveness resolveJump(JCTree tree, ! ListBuffer<P> oldPendingExits, JumpKind jk) { boolean resolved = false; ! List<P> exits = pendingExits.toList(); pendingExits = oldPendingExits; for (; exits.nonEmpty(); exits = exits.tail) { ! P exit = exits.head; if (exit.tree.hasTag(jk.treeTag) && jk.getTarget(exit.tree) == tree) { exit.resolveJump(); resolved = true; } else { --- 349,372 ---- } abstract void markDead(); /** Record an outward transfer of control. */ ! void recordExit(PendingExit pe) { pendingExits.append(pe); markDead(); } /** Resolve all jumps of this statement. */ private Liveness resolveJump(JCTree tree, ! ListBuffer<PendingExit> oldPendingExits, JumpKind jk) { boolean resolved = false; ! List<PendingExit> exits = pendingExits.toList(); pendingExits = oldPendingExits; for (; exits.nonEmpty(); exits = exits.tail) { ! PendingExit exit = exits.head; if (exit.tree.hasTag(jk.treeTag) && jk.getTarget(exit.tree) == tree) { exit.resolveJump(); resolved = true; } else {
*** 376,390 **** return Liveness.from(resolved); } /** Resolve all continues of this statement. */ Liveness resolveContinues(JCTree tree) { ! return resolveJump(tree, new ListBuffer<P>(), JumpKind.CONTINUE); } /** Resolve all breaks of this statement. */ ! Liveness resolveBreaks(JCTree tree, ListBuffer<P> oldPendingExits) { return resolveJump(tree, oldPendingExits, JumpKind.BREAK); } @Override public void scan(JCTree tree) { --- 376,390 ---- return Liveness.from(resolved); } /** Resolve all continues of this statement. */ Liveness resolveContinues(JCTree tree) { ! return resolveJump(tree, new ListBuffer<PendingExit>(), JumpKind.CONTINUE); } /** Resolve all breaks of this statement. */ ! Liveness resolveBreaks(JCTree tree, ListBuffer<PendingExit> oldPendingExits) { return resolveJump(tree, oldPendingExits, JumpKind.BREAK); } @Override public void scan(JCTree tree) {
*** 410,420 **** * This pass implements the first step of the dataflow analysis, namely * the liveness analysis check. This checks that every statement is reachable. * The output of this analysis pass are used by other analyzers. This analyzer * sets the 'finallyCanCompleteNormally' field in the JCTry class. */ ! class AliveAnalyzer extends BaseAnalyzer<BaseAnalyzer.PendingExit> { /** A flag that indicates whether the last statement could * complete normally. */ private Liveness alive; --- 410,420 ---- * This pass implements the first step of the dataflow analysis, namely * the liveness analysis check. This checks that every statement is reachable. * The output of this analysis pass are used by other analyzers. This analyzer * sets the 'finallyCanCompleteNormally' field in the JCTry class. */ ! class AliveAnalyzer extends BaseAnalyzer { /** A flag that indicates whether the last statement could * complete normally. */ private Liveness alive;
*** 829,839 **** * This pass implements the second step of the dataflow analysis, namely * the exception analysis. This is to ensure that every checked exception that is * thrown is declared or caught. The analyzer uses some info that has been set by * the liveliness analyzer. */ ! class FlowAnalyzer extends BaseAnalyzer<FlowAnalyzer.FlowPendingExit> { /** A flag that indicates whether the last statement could * complete normally. */ HashMap<Symbol, List<Type>> preciseRethrowTypes; --- 829,839 ---- * This pass implements the second step of the dataflow analysis, namely * the exception analysis. This is to ensure that every checked exception that is * thrown is declared or caught. The analyzer uses some info that has been set by * the liveliness analyzer. */ ! class FlowAnalyzer extends BaseAnalyzer { /** A flag that indicates whether the last statement could * complete normally. */ HashMap<Symbol, List<Type>> preciseRethrowTypes;
*** 849,863 **** /** The list of exceptions that are either caught or declared to be * thrown. */ List<Type> caught; ! class FlowPendingExit extends BaseAnalyzer.PendingExit { Type thrown; ! FlowPendingExit(JCTree tree, Type thrown) { super(tree); this.thrown = thrown; } } --- 849,863 ---- /** The list of exceptions that are either caught or declared to be * thrown. */ List<Type> caught; ! class ThrownPendingExit extends BaseAnalyzer.PendingExit { Type thrown; ! ThrownPendingExit(JCTree tree, Type thrown) { super(tree); this.thrown = thrown; } }
*** 869,904 **** /*-------------------- Exceptions ----------------------*/ /** Complain that pending exceptions are not caught. */ void errorUncaught() { ! for (FlowPendingExit exit = pendingExits.next(); exit != null; exit = pendingExits.next()) { if (classDef != null && classDef.pos == exit.tree.pos) { log.error(exit.tree.pos(), ! Errors.UnreportedExceptionDefaultConstructor(exit.thrown)); } else if (exit.tree.hasTag(VARDEF) && ((JCVariableDecl)exit.tree).sym.isResourceVariable()) { log.error(exit.tree.pos(), ! Errors.UnreportedExceptionImplicitClose(exit.thrown, ((JCVariableDecl)exit.tree).sym.name)); } else { log.error(exit.tree.pos(), ! Errors.UnreportedExceptionNeedToCatchOrThrow(exit.thrown)); } } } /** Record that exception is potentially thrown and check that it * is caught. */ void markThrown(JCTree tree, Type exc) { if (!chk.isUnchecked(tree.pos(), exc)) { if (!chk.isHandled(exc, caught)) { ! pendingExits.append(new FlowPendingExit(tree, exc)); } thrown = chk.incl(exc, thrown); } } --- 869,906 ---- /*-------------------- Exceptions ----------------------*/ /** Complain that pending exceptions are not caught. */ void errorUncaught() { ! for (PendingExit exit = pendingExits.next(); exit != null; exit = pendingExits.next()) { + Assert.check(exit instanceof ThrownPendingExit); + ThrownPendingExit thrownExit = (ThrownPendingExit) exit; if (classDef != null && classDef.pos == exit.tree.pos) { log.error(exit.tree.pos(), ! Errors.UnreportedExceptionDefaultConstructor(thrownExit.thrown)); } else if (exit.tree.hasTag(VARDEF) && ((JCVariableDecl)exit.tree).sym.isResourceVariable()) { log.error(exit.tree.pos(), ! Errors.UnreportedExceptionImplicitClose(thrownExit.thrown, ((JCVariableDecl)exit.tree).sym.name)); } else { log.error(exit.tree.pos(), ! Errors.UnreportedExceptionNeedToCatchOrThrow(thrownExit.thrown)); } } } /** Record that exception is potentially thrown and check that it * is caught. */ void markThrown(JCTree tree, Type exc) { if (!chk.isUnchecked(tree.pos(), exc)) { if (!chk.isHandled(exc, caught)) { ! pendingExits.append(new ThrownPendingExit(tree, exc)); } thrown = chk.incl(exc, thrown); } }
*** 912,922 **** if (tree.sym == null) return; JCClassDecl classDefPrev = classDef; List<Type> thrownPrev = thrown; List<Type> caughtPrev = caught; ! ListBuffer<FlowPendingExit> pendingExitsPrev = pendingExits; Lint lintPrev = lint; boolean anonymousClass = tree.name == names.empty; pendingExits = new ListBuffer<>(); if (!anonymousClass) { caught = List.nil(); --- 914,924 ---- if (tree.sym == null) return; JCClassDecl classDefPrev = classDef; List<Type> thrownPrev = thrown; List<Type> caughtPrev = caught; ! ListBuffer<PendingExit> pendingExitsPrev = pendingExits; Lint lintPrev = lint; boolean anonymousClass = tree.name == names.empty; pendingExits = new ListBuffer<>(); if (!anonymousClass) { caught = List.nil();
*** 1022,1037 **** // else we are in an instance initializer block; // leave caught unchanged. scan(tree.body); ! List<FlowPendingExit> exits = pendingExits.toList(); pendingExits = new ListBuffer<>(); while (exits.nonEmpty()) { ! FlowPendingExit exit = exits.head; exits = exits.tail; ! if (exit.thrown == null) { Assert.check(exit.tree.hasTag(RETURN)); } else { // uncaught throws will be reported later pendingExits.append(exit); } --- 1024,1039 ---- // else we are in an instance initializer block; // leave caught unchanged. scan(tree.body); ! List<PendingExit> exits = pendingExits.toList(); pendingExits = new ListBuffer<>(); while (exits.nonEmpty()) { ! PendingExit exit = exits.head; exits = exits.tail; ! if (!(exit instanceof ThrownPendingExit)) { Assert.check(exit.tree.hasTag(RETURN)); } else { // uncaught throws will be reported later pendingExits.append(exit); }
*** 1057,1085 **** public void visitBlock(JCBlock tree) { scan(tree.stats); } public void visitDoLoop(JCDoWhileLoop tree) { ! ListBuffer<FlowPendingExit> prevPendingExits = pendingExits; pendingExits = new ListBuffer<>(); scan(tree.body); resolveContinues(tree); scan(tree.cond); resolveBreaks(tree, prevPendingExits); } public void visitWhileLoop(JCWhileLoop tree) { ! ListBuffer<FlowPendingExit> prevPendingExits = pendingExits; pendingExits = new ListBuffer<>(); scan(tree.cond); scan(tree.body); resolveContinues(tree); resolveBreaks(tree, prevPendingExits); } public void visitForLoop(JCForLoop tree) { ! ListBuffer<FlowPendingExit> prevPendingExits = pendingExits; scan(tree.init); pendingExits = new ListBuffer<>(); if (tree.cond != null) { scan(tree.cond); } --- 1059,1087 ---- public void visitBlock(JCBlock tree) { scan(tree.stats); } public void visitDoLoop(JCDoWhileLoop tree) { ! ListBuffer<PendingExit> prevPendingExits = pendingExits; pendingExits = new ListBuffer<>(); scan(tree.body); resolveContinues(tree); scan(tree.cond); resolveBreaks(tree, prevPendingExits); } public void visitWhileLoop(JCWhileLoop tree) { ! ListBuffer<PendingExit> prevPendingExits = pendingExits; pendingExits = new ListBuffer<>(); scan(tree.cond); scan(tree.body); resolveContinues(tree); resolveBreaks(tree, prevPendingExits); } public void visitForLoop(JCForLoop tree) { ! ListBuffer<PendingExit> prevPendingExits = pendingExits; scan(tree.init); pendingExits = new ListBuffer<>(); if (tree.cond != null) { scan(tree.cond); }
*** 1089,1108 **** resolveBreaks(tree, prevPendingExits); } public void visitForeachLoop(JCEnhancedForLoop tree) { visitVarDef(tree.var); ! ListBuffer<FlowPendingExit> prevPendingExits = pendingExits; scan(tree.expr); pendingExits = new ListBuffer<>(); scan(tree.body); resolveContinues(tree); resolveBreaks(tree, prevPendingExits); } public void visitLabelled(JCLabeledStatement tree) { ! ListBuffer<FlowPendingExit> prevPendingExits = pendingExits; pendingExits = new ListBuffer<>(); scan(tree.body); resolveBreaks(tree, prevPendingExits); } --- 1091,1110 ---- resolveBreaks(tree, prevPendingExits); } public void visitForeachLoop(JCEnhancedForLoop tree) { visitVarDef(tree.var); ! ListBuffer<PendingExit> prevPendingExits = pendingExits; scan(tree.expr); pendingExits = new ListBuffer<>(); scan(tree.body); resolveContinues(tree); resolveBreaks(tree, prevPendingExits); } public void visitLabelled(JCLabeledStatement tree) { ! ListBuffer<PendingExit> prevPendingExits = pendingExits; pendingExits = new ListBuffer<>(); scan(tree.body); resolveBreaks(tree, prevPendingExits); }
*** 1114,1124 **** public void visitSwitchExpression(JCSwitchExpression tree) { handleSwitch(tree, tree.selector, tree.cases); } private void handleSwitch(JCTree tree, JCExpression selector, List<JCCase> cases) { ! ListBuffer<FlowPendingExit> prevPendingExits = pendingExits; pendingExits = new ListBuffer<>(); scan(selector); for (List<JCCase> l = cases; l.nonEmpty(); l = l.tail) { JCCase c = l.head; scan(c.pats); --- 1116,1126 ---- public void visitSwitchExpression(JCSwitchExpression tree) { handleSwitch(tree, tree.selector, tree.cases); } private void handleSwitch(JCTree tree, JCExpression selector, List<JCCase> cases) { ! ListBuffer<PendingExit> prevPendingExits = pendingExits; pendingExits = new ListBuffer<>(); scan(selector); for (List<JCCase> l = cases; l.nonEmpty(); l = l.tail) { JCCase c = l.head; scan(c.pats);
*** 1138,1148 **** for (JCExpression ct : subClauses) { caught = chk.incl(ct.type, caught); } } ! ListBuffer<FlowPendingExit> prevPendingExits = pendingExits; pendingExits = new ListBuffer<>(); for (JCTree resource : tree.resources) { if (resource instanceof JCVariableDecl) { JCVariableDecl vdecl = (JCVariableDecl) resource; visitVarDef(vdecl); --- 1140,1150 ---- for (JCExpression ct : subClauses) { caught = chk.incl(ct.type, caught); } } ! ListBuffer<PendingExit> prevPendingExits = pendingExits; pendingExits = new ListBuffer<>(); for (JCTree resource : tree.resources) { if (resource instanceof JCVariableDecl) { JCVariableDecl vdecl = (JCVariableDecl) resource; visitVarDef(vdecl);
*** 1202,1212 **** preciseRethrowTypes.remove(param.sym); } if (tree.finalizer != null) { List<Type> savedThrown = thrown; thrown = List.nil(); ! ListBuffer<FlowPendingExit> exits = pendingExits; pendingExits = prevPendingExits; scan(tree.finalizer); if (!tree.finallyCanCompleteNormally) { // discard exits and exceptions from try and finally thrown = chk.union(thrown, thrownPrev); --- 1204,1214 ---- preciseRethrowTypes.remove(param.sym); } if (tree.finalizer != null) { List<Type> savedThrown = thrown; thrown = List.nil(); ! ListBuffer<PendingExit> exits = pendingExits; pendingExits = prevPendingExits; scan(tree.finalizer); if (!tree.finallyCanCompleteNormally) { // discard exits and exceptions from try and finally thrown = chk.union(thrown, thrownPrev);
*** 1219,1229 **** pendingExits.append(exits.next()); } } } else { thrown = chk.union(thrown, chk.diff(thrownInTry, caughtInTry)); ! ListBuffer<FlowPendingExit> exits = pendingExits; pendingExits = prevPendingExits; while (exits.nonEmpty()) pendingExits.append(exits.next()); } } --- 1221,1231 ---- pendingExits.append(exits.next()); } } } else { thrown = chk.union(thrown, chk.diff(thrownInTry, caughtInTry)); ! ListBuffer<PendingExit> exits = pendingExits; pendingExits = prevPendingExits; while (exits.nonEmpty()) pendingExits.append(exits.next()); } }
*** 1265,1284 **** } public void visitBreak(JCBreak tree) { if (tree.isValueBreak()) scan(tree.value); ! recordExit(new FlowPendingExit(tree, null)); } public void visitContinue(JCContinue tree) { ! recordExit(new FlowPendingExit(tree, null)); } public void visitReturn(JCReturn tree) { scan(tree.expr); ! recordExit(new FlowPendingExit(tree, null)); } public void visitThrow(JCThrow tree) { scan(tree.expr); Symbol sym = TreeInfo.symbol(tree.expr); --- 1267,1286 ---- } public void visitBreak(JCBreak tree) { if (tree.isValueBreak()) scan(tree.value); ! recordExit(new PendingExit(tree)); } public void visitContinue(JCContinue tree) { ! recordExit(new PendingExit(tree)); } public void visitReturn(JCReturn tree) { scan(tree.expr); ! recordExit(new PendingExit(tree)); } public void visitThrow(JCThrow tree) { scan(tree.expr); Symbol sym = TreeInfo.symbol(tree.expr);
*** 1341,1362 **** tree.type.isErroneous()) { return; } List<Type> prevCaught = caught; List<Type> prevThrown = thrown; ! ListBuffer<FlowPendingExit> prevPending = pendingExits; try { pendingExits = new ListBuffer<>(); caught = tree.getDescriptorType(types).getThrownTypes(); thrown = List.nil(); scan(tree.body); ! List<FlowPendingExit> exits = pendingExits.toList(); pendingExits = new ListBuffer<>(); while (exits.nonEmpty()) { ! FlowPendingExit exit = exits.head; exits = exits.tail; ! if (exit.thrown == null) { Assert.check(exit.tree.hasTag(RETURN)); } else { // uncaught throws will be reported later pendingExits.append(exit); } --- 1343,1364 ---- tree.type.isErroneous()) { return; } List<Type> prevCaught = caught; List<Type> prevThrown = thrown; ! ListBuffer<PendingExit> prevPending = pendingExits; try { pendingExits = new ListBuffer<>(); caught = tree.getDescriptorType(types).getThrownTypes(); thrown = List.nil(); scan(tree.body); ! List<PendingExit> exits = pendingExits.toList(); pendingExits = new ListBuffer<>(); while (exits.nonEmpty()) { ! PendingExit exit = exits.head; exits = exits.tail; ! if (!(exit instanceof ThrownPendingExit)) { Assert.check(exit.tree.hasTag(RETURN)); } else { // uncaught throws will be reported later pendingExits.append(exit); }
*** 1486,1496 **** tree.type.isErroneous()) || inLambda) { return; } List<Type> prevCaught = caught; List<Type> prevThrown = thrown; ! ListBuffer<FlowPendingExit> prevPending = pendingExits; inLambda = true; try { pendingExits = new ListBuffer<>(); caught = List.of(syms.throwableType); thrown = List.nil(); --- 1488,1498 ---- tree.type.isErroneous()) || inLambda) { return; } List<Type> prevCaught = caught; List<Type> prevThrown = thrown; ! ListBuffer<PendingExit> prevPending = pendingExits; inLambda = true; try { pendingExits = new ListBuffer<>(); caught = List.of(syms.throwableType); thrown = List.nil();
*** 1515,1525 **** * which ensures that no final variable is assigned more than once. This visitor * depends on the results of the liveliness analyzer. This pass is also used to mark * effectively-final local variables/parameters. */ ! public class AssignAnalyzer extends BaseAnalyzer<AssignAnalyzer.AssignPendingExit> { /** The set of definitely assigned variables. */ final Bits inits; --- 1517,1527 ---- * which ensures that no final variable is assigned more than once. This visitor * depends on the results of the liveliness analyzer. This pass is also used to mark * effectively-final local variables/parameters. */ ! public class AssignAnalyzer extends BaseAnalyzer { /** The set of definitely assigned variables. */ final Bits inits;
*** 1833,1843 **** } JCClassDecl classDefPrev = classDef; int firstadrPrev = firstadr; int nextadrPrev = nextadr; ! ListBuffer<AssignPendingExit> pendingExitsPrev = pendingExits; pendingExits = new ListBuffer<>(); if (tree.name != names.empty) { firstadr = nextadr; } --- 1835,1845 ---- } JCClassDecl classDefPrev = classDef; int firstadrPrev = firstadr; int nextadrPrev = nextadr; ! ListBuffer<PendingExit> pendingExitsPrev = pendingExits; pendingExits = new ListBuffer<>(); if (tree.name != names.empty) { firstadr = nextadr; }
*** 1968,1985 **** checkInit(TreeInfo.diagEndPos(tree.body), var); } } } } ! List<AssignPendingExit> exits = pendingExits.toList(); pendingExits = new ListBuffer<>(); while (exits.nonEmpty()) { ! AssignPendingExit exit = exits.head; exits = exits.tail; Assert.check(exit.tree.hasTag(RETURN), exit.tree); if (isInitialConstructor) { ! inits.assign(exit.exit_inits); for (int i = firstadr; i < nextadr; i++) { checkInit(exit.tree.pos(), vardecls[i].sym); } } } --- 1970,1988 ---- checkInit(TreeInfo.diagEndPos(tree.body), var); } } } } ! List<PendingExit> exits = pendingExits.toList(); pendingExits = new ListBuffer<>(); while (exits.nonEmpty()) { ! PendingExit exit = exits.head; exits = exits.tail; Assert.check(exit.tree.hasTag(RETURN), exit.tree); if (isInitialConstructor) { ! Assert.check(exit instanceof AssignPendingExit); ! inits.assign(((AssignPendingExit) exit).exit_inits); for (int i = firstadr; i < nextadr; i++) { checkInit(exit.tree.pos(), vardecls[i].sym); } } }
*** 2025,2035 **** scan(tree.stats); nextadr = nextadrPrev; } public void visitDoLoop(JCDoWhileLoop tree) { ! ListBuffer<AssignPendingExit> prevPendingExits = pendingExits; FlowKind prevFlowKind = flowKind; flowKind = FlowKind.NORMAL; final Bits initsSkip = new Bits(true); final Bits uninitsSkip = new Bits(true); pendingExits = new ListBuffer<>(); --- 2028,2038 ---- scan(tree.stats); nextadr = nextadrPrev; } public void visitDoLoop(JCDoWhileLoop tree) { ! ListBuffer<PendingExit> prevPendingExits = pendingExits; FlowKind prevFlowKind = flowKind; flowKind = FlowKind.NORMAL; final Bits initsSkip = new Bits(true); final Bits uninitsSkip = new Bits(true); pendingExits = new ListBuffer<>();
*** 2057,2067 **** uninits.assign(uninitsSkip); resolveBreaks(tree, prevPendingExits); } public void visitWhileLoop(JCWhileLoop tree) { ! ListBuffer<AssignPendingExit> prevPendingExits = pendingExits; FlowKind prevFlowKind = flowKind; flowKind = FlowKind.NORMAL; final Bits initsSkip = new Bits(true); final Bits uninitsSkip = new Bits(true); pendingExits = new ListBuffer<>(); --- 2060,2070 ---- uninits.assign(uninitsSkip); resolveBreaks(tree, prevPendingExits); } public void visitWhileLoop(JCWhileLoop tree) { ! ListBuffer<PendingExit> prevPendingExits = pendingExits; FlowKind prevFlowKind = flowKind; flowKind = FlowKind.NORMAL; final Bits initsSkip = new Bits(true); final Bits uninitsSkip = new Bits(true); pendingExits = new ListBuffer<>();
*** 2093,2103 **** uninits.assign(uninitsSkip); resolveBreaks(tree, prevPendingExits); } 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); --- 2096,2106 ---- uninits.assign(uninitsSkip); resolveBreaks(tree, prevPendingExits); } public void visitForLoop(JCForLoop tree) { ! ListBuffer<PendingExit> prevPendingExits = pendingExits; FlowKind prevFlowKind = flowKind; flowKind = FlowKind.NORMAL; int nextadrPrev = nextadr; scan(tree.init); final Bits initsSkip = new Bits(true);
*** 2141,2151 **** } public void visitForeachLoop(JCEnhancedForLoop tree) { visitVarDef(tree.var); ! ListBuffer<AssignPendingExit> prevPendingExits = pendingExits; FlowKind prevFlowKind = flowKind; flowKind = FlowKind.NORMAL; int nextadrPrev = nextadr; scan(tree.expr); final Bits initsStart = new Bits(inits); --- 2144,2154 ---- } public void visitForeachLoop(JCEnhancedForLoop tree) { visitVarDef(tree.var); ! ListBuffer<PendingExit> prevPendingExits = pendingExits; FlowKind prevFlowKind = flowKind; flowKind = FlowKind.NORMAL; int nextadrPrev = nextadr; scan(tree.expr); final Bits initsStart = new Bits(inits);
*** 2172,2182 **** resolveBreaks(tree, prevPendingExits); nextadr = nextadrPrev; } public void visitLabelled(JCLabeledStatement tree) { ! ListBuffer<AssignPendingExit> prevPendingExits = pendingExits; pendingExits = new ListBuffer<>(); scan(tree.body); resolveBreaks(tree, prevPendingExits); } --- 2175,2185 ---- resolveBreaks(tree, prevPendingExits); nextadr = nextadrPrev; } public void visitLabelled(JCLabeledStatement tree) { ! ListBuffer<PendingExit> prevPendingExits = pendingExits; pendingExits = new ListBuffer<>(); scan(tree.body); resolveBreaks(tree, prevPendingExits); }
*** 2187,2197 **** public void visitSwitchExpression(JCSwitchExpression tree) { handleSwitch(tree, tree.selector, tree.cases); } private void handleSwitch(JCTree tree, JCExpression selector, List<JCCase> cases) { ! ListBuffer<AssignPendingExit> prevPendingExits = pendingExits; pendingExits = new ListBuffer<>(); int nextadrPrev = nextadr; scanExpr(selector); final Bits initsSwitch = new Bits(inits); final Bits uninitsSwitch = new Bits(uninits); --- 2190,2200 ---- public void visitSwitchExpression(JCSwitchExpression tree) { handleSwitch(tree, tree.selector, tree.cases); } private void handleSwitch(JCTree tree, JCExpression selector, List<JCCase> cases) { ! ListBuffer<PendingExit> prevPendingExits = pendingExits; pendingExits = new ListBuffer<>(); int nextadrPrev = nextadr; scanExpr(selector); final Bits initsSwitch = new Bits(inits); final Bits uninitsSwitch = new Bits(uninits);
*** 2243,2253 **** } public void visitTry(JCTry tree) { ListBuffer<JCVariableDecl> resourceVarDecls = new ListBuffer<>(); final Bits uninitsTryPrev = new Bits(uninitsTry); ! ListBuffer<AssignPendingExit> prevPendingExits = pendingExits; pendingExits = new ListBuffer<>(); final Bits initsTry = new Bits(inits); uninitsTry.assign(uninits); for (JCTree resource : tree.resources) { if (resource instanceof JCVariableDecl) { --- 2246,2256 ---- } public void visitTry(JCTry tree) { ListBuffer<JCVariableDecl> resourceVarDecls = new ListBuffer<>(); final Bits uninitsTryPrev = new Bits(uninitsTry); ! ListBuffer<PendingExit> prevPendingExits = pendingExits; pendingExits = new ListBuffer<>(); final Bits initsTry = new Bits(inits); uninitsTry.assign(uninits); for (JCTree resource : tree.resources) { if (resource instanceof JCVariableDecl) {
*** 2300,2332 **** nextadr = nextadrCatch; } if (tree.finalizer != null) { inits.assign(initsTry); uninits.assign(uninitsTry); ! ListBuffer<AssignPendingExit> exits = pendingExits; pendingExits = prevPendingExits; scan(tree.finalizer); if (!tree.finallyCanCompleteNormally) { // discard exits and exceptions from try and finally } else { uninits.andSet(uninitsEnd); // FIX: this doesn't preserve source order of exits in catch // versus finally! while (exits.nonEmpty()) { ! AssignPendingExit exit = exits.next(); ! if (exit.exit_inits != null) { ! exit.exit_inits.orSet(inits); ! exit.exit_uninits.andSet(uninits); } pendingExits.append(exit); } inits.orSet(initsEnd); } } else { inits.assign(initsEnd); uninits.assign(uninitsEnd); ! ListBuffer<AssignPendingExit> exits = pendingExits; pendingExits = prevPendingExits; while (exits.nonEmpty()) pendingExits.append(exits.next()); } uninitsTry.andSet(uninitsTryPrev).andSet(uninits); } --- 2303,2335 ---- nextadr = nextadrCatch; } if (tree.finalizer != null) { inits.assign(initsTry); uninits.assign(uninitsTry); ! ListBuffer<PendingExit> exits = pendingExits; pendingExits = prevPendingExits; scan(tree.finalizer); if (!tree.finallyCanCompleteNormally) { // discard exits and exceptions from try and finally } else { uninits.andSet(uninitsEnd); // FIX: this doesn't preserve source order of exits in catch // versus finally! while (exits.nonEmpty()) { ! PendingExit exit = exits.next(); ! if (exit instanceof AssignPendingExit) { ! ((AssignPendingExit) exit).exit_inits.orSet(inits); ! ((AssignPendingExit) exit).exit_uninits.andSet(uninits); } pendingExits.append(exit); } inits.orSet(initsEnd); } } else { inits.assign(initsEnd); uninits.assign(uninitsEnd); ! ListBuffer<PendingExit> exits = pendingExits; pendingExits = prevPendingExits; while (exits.nonEmpty()) pendingExits.append(exits.next()); } uninitsTry.andSet(uninitsTryPrev).andSet(uninits); }
*** 2388,2399 **** } } @Override public void visitBreak(JCBreak tree) { ! if (tree.isValueBreak()) scan(tree.value); recordExit(new AssignPendingExit(tree, inits, uninits)); } @Override public void visitContinue(JCContinue tree) { --- 2391,2428 ---- } } @Override public void visitBreak(JCBreak tree) { ! if (tree.isValueBreak()) { ! if (tree.target.hasTag(SWITCH_EXPRESSION)) { ! JCSwitchExpression expr = (JCSwitchExpression) tree.target; ! if (expr.type.hasTag(BOOLEAN)) { ! scanCond(tree.value); ! Bits initsAfterBreakWhenTrue = new Bits(initsWhenTrue); ! Bits initsAfterBreakWhenFalse = new Bits(initsWhenFalse); ! Bits uninitsAfterBreakWhenTrue = new Bits(uninitsWhenTrue); ! Bits uninitsAfterBreakWhenFalse = new Bits(uninitsWhenFalse); ! PendingExit exit = new PendingExit(tree) { ! @Override ! void resolveJump() { ! if (!inits.isReset()) { ! split(true); ! } ! initsWhenTrue.andSet(initsAfterBreakWhenTrue); ! initsWhenFalse.andSet(initsAfterBreakWhenFalse); ! uninitsWhenTrue.andSet(uninitsAfterBreakWhenTrue); ! uninitsWhenFalse.andSet(uninitsAfterBreakWhenFalse); ! } ! }; ! merge(); ! recordExit(exit); ! return ; ! } ! } scan(tree.value); + } recordExit(new AssignPendingExit(tree, inits, uninits)); } @Override public void visitContinue(JCContinue tree) {
*** 2426,2436 **** public void visitLambda(JCLambda tree) { final Bits prevUninits = new Bits(uninits); final Bits prevInits = new Bits(inits); int returnadrPrev = returnadr; int nextadrPrev = nextadr; ! ListBuffer<AssignPendingExit> prevPending = pendingExits; try { returnadr = nextadr; pendingExits = new ListBuffer<>(); for (List<JCVariableDecl> l = tree.params; l.nonEmpty(); l = l.tail) { JCVariableDecl def = l.head; --- 2455,2465 ---- public void visitLambda(JCLambda tree) { final Bits prevUninits = new Bits(uninits); final Bits prevInits = new Bits(inits); int returnadrPrev = returnadr; int nextadrPrev = nextadr; ! ListBuffer<PendingExit> prevPending = pendingExits; try { returnadr = nextadr; pendingExits = new ListBuffer<>(); for (List<JCVariableDecl> l = tree.params; l.nonEmpty(); l = l.tail) { JCVariableDecl def = l.head;
*** 2616,2626 **** * Additional this also checks that every variable that is used as an operand to * try-with-resources is final or effectively final. * As effectively final variables are marked as such during DA/DU, this pass must run after * AssignAnalyzer. */ ! class CaptureAnalyzer extends BaseAnalyzer<BaseAnalyzer.PendingExit> { JCTree currentTree; //local class or lambda @Override void markDead() { --- 2645,2655 ---- * Additional this also checks that every variable that is used as an operand to * try-with-resources is final or effectively final. * As effectively final variables are marked as such during DA/DU, this pass must run after * AssignAnalyzer. */ ! class CaptureAnalyzer extends BaseAnalyzer { JCTree currentTree; //local class or lambda @Override void markDead() {
< prev index next >