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

changeset 2566
58e7e71b302e
parent 2408
716f2466ddd0
child 2591
fc1b69dce787
equal deleted inserted replaced
2565:4ac623ddd8d0 2566:58e7e71b302e
206 return instance; 206 return instance;
207 } 207 }
208 208
209 public void analyzeTree(Env<AttrContext> env, TreeMaker make) { 209 public void analyzeTree(Env<AttrContext> env, TreeMaker make) {
210 new AliveAnalyzer().analyzeTree(env, make); 210 new AliveAnalyzer().analyzeTree(env, make);
211 new AssignAnalyzer(log, syms, lint, names, enforceThisDotInit).analyzeTree(env); 211 new AssignAnalyzer().analyzeTree(env);
212 new FlowAnalyzer().analyzeTree(env, make); 212 new FlowAnalyzer().analyzeTree(env, make);
213 new CaptureAnalyzer().analyzeTree(env, make); 213 new CaptureAnalyzer().analyzeTree(env, make);
214 } 214 }
215 215
216 public void analyzeLambda(Env<AttrContext> env, JCLambda that, TreeMaker make, boolean speculative) { 216 public void analyzeLambda(Env<AttrContext> env, JCLambda that, TreeMaker make, boolean speculative) {
239 //message will be reported and will cause compilation to skip the flow analyis 239 //message will be reported and will cause compilation to skip the flow analyis
240 //step - if we suppress diagnostics, we won't stop at Attr for flow-analysis 240 //step - if we suppress diagnostics, we won't stop at Attr for flow-analysis
241 //related errors, which will allow for more errors to be detected 241 //related errors, which will allow for more errors to be detected
242 Log.DiagnosticHandler diagHandler = new Log.DiscardDiagnosticHandler(log); 242 Log.DiagnosticHandler diagHandler = new Log.DiscardDiagnosticHandler(log);
243 try { 243 try {
244 new AssignAnalyzer(log, syms, lint, names, enforceThisDotInit) { 244 new AssignAnalyzer() {
245 @Override 245 @Override
246 protected boolean trackable(VarSymbol sym) { 246 protected boolean trackable(VarSymbol sym) {
247 return !env.info.scope.includes(sym) && 247 return !env.info.scope.includes(sym) &&
248 sym.owner.kind == MTH; 248 sym.owner.kind == MTH;
249 } 249 }
1371 * which ensures that no final variable is assigned more than once. This visitor 1371 * which ensures that no final variable is assigned more than once. This visitor
1372 * depends on the results of the liveliness analyzer. This pass is also used to mark 1372 * depends on the results of the liveliness analyzer. This pass is also used to mark
1373 * effectively-final local variables/parameters. 1373 * effectively-final local variables/parameters.
1374 */ 1374 */
1375 1375
1376 public abstract static class AbstractAssignAnalyzer<P extends AbstractAssignAnalyzer.AbstractAssignPendingExit> 1376 public abstract class AbstractAssignAnalyzer<P extends AbstractAssignAnalyzer<P>.AbstractAssignPendingExit>
1377 extends BaseAnalyzer<P> { 1377 extends BaseAnalyzer<P> {
1378 1378
1379 /** The set of definitely assigned variables. 1379 /** The set of definitely assigned variables.
1380 */ 1380 */
1381 protected final Bits inits; 1381 protected Bits inits;
1382 1382
1383 /** The set of definitely unassigned variables. 1383 /** The set of definitely unassigned variables.
1384 */ 1384 */
1385 final Bits uninits; 1385 final Bits uninits;
1386 1386
1430 FlowKind flowKind = FlowKind.NORMAL; 1430 FlowKind flowKind = FlowKind.NORMAL;
1431 1431
1432 /** The starting position of the analysed tree */ 1432 /** The starting position of the analysed tree */
1433 int startPos; 1433 int startPos;
1434 1434
1435 final Symtab syms; 1435 public class AbstractAssignPendingExit extends BaseAnalyzer.PendingExit {
1436
1437 protected Names names;
1438
1439 final boolean enforceThisDotInit;
1440
1441 public static class AbstractAssignPendingExit extends BaseAnalyzer.PendingExit {
1442 1436
1443 final Bits inits; 1437 final Bits inits;
1444 final Bits uninits; 1438 final Bits uninits;
1445 final Bits exit_inits = new Bits(true); 1439 final Bits exit_inits = new Bits(true);
1446 final Bits exit_uninits = new Bits(true); 1440 final Bits exit_uninits = new Bits(true);
1458 inits.andSet(exit_inits); 1452 inits.andSet(exit_inits);
1459 uninits.andSet(exit_uninits); 1453 uninits.andSet(exit_uninits);
1460 } 1454 }
1461 } 1455 }
1462 1456
1463 public AbstractAssignAnalyzer(Bits inits, Symtab syms, Names names, boolean enforceThisDotInit) { 1457 public AbstractAssignAnalyzer() {
1464 this.inits = inits; 1458 this.inits = new Bits();
1465 uninits = new Bits(); 1459 uninits = new Bits();
1466 uninitsTry = new Bits(); 1460 uninitsTry = new Bits();
1467 initsWhenTrue = new Bits(true); 1461 initsWhenTrue = new Bits(true);
1468 initsWhenFalse = new Bits(true); 1462 initsWhenFalse = new Bits(true);
1469 uninitsWhenTrue = new Bits(true); 1463 uninitsWhenTrue = new Bits(true);
1470 uninitsWhenFalse = new Bits(true); 1464 uninitsWhenFalse = new Bits(true);
1471 this.syms = syms;
1472 this.names = names;
1473 this.enforceThisDotInit = enforceThisDotInit;
1474 } 1465 }
1475 1466
1476 private boolean isInitialConstructor = false; 1467 private boolean isInitialConstructor = false;
1477 1468
1478 @Override 1469 @Override
2437 unrefdResources = null; 2428 unrefdResources = null;
2438 } 2429 }
2439 } 2430 }
2440 } 2431 }
2441 2432
2442 public static class AssignAnalyzer 2433 public class AssignAnalyzer extends AbstractAssignAnalyzer<AssignAnalyzer.AssignPendingExit> {
2443 extends AbstractAssignAnalyzer<AssignAnalyzer.AssignPendingExit> { 2434
2444 2435 public class AssignPendingExit extends AbstractAssignAnalyzer<AssignPendingExit>.AbstractAssignPendingExit {
2445 Log log;
2446 Lint lint;
2447
2448 public static class AssignPendingExit
2449 extends AbstractAssignAnalyzer.AbstractAssignPendingExit {
2450 2436
2451 public AssignPendingExit(JCTree tree, final Bits inits, final Bits uninits) { 2437 public AssignPendingExit(JCTree tree, final Bits inits, final Bits uninits) {
2452 super(tree, inits, uninits); 2438 super(tree, inits, uninits);
2453 } 2439 }
2454 }
2455
2456 public AssignAnalyzer(Log log, Symtab syms, Lint lint, Names names, boolean enforceThisDotInit) {
2457 super(new Bits(), syms, names, enforceThisDotInit);
2458 this.log = log;
2459 this.lint = lint;
2460 } 2440 }
2461 2441
2462 @Override 2442 @Override
2463 protected AssignPendingExit createNewPendingExit(JCTree tree, 2443 protected AssignPendingExit createNewPendingExit(JCTree tree,
2464 Bits inits, Bits uninits) { 2444 Bits inits, Bits uninits) {

mercurial