langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Flow.java
changeset 26537 026471c1a12b
parent 26536 730984f89f90
child 27224 228abfa87080
equal deleted inserted replaced
26536:730984f89f90 26537:026471c1a12b
   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                 }
  1367      * which ensures that no final variable is assigned more than once. This visitor
  1367      * which ensures that no final variable is assigned more than once. This visitor
  1368      * depends on the results of the liveliness analyzer. This pass is also used to mark
  1368      * depends on the results of the liveliness analyzer. This pass is also used to mark
  1369      * effectively-final local variables/parameters.
  1369      * effectively-final local variables/parameters.
  1370      */
  1370      */
  1371 
  1371 
  1372     public abstract static class AbstractAssignAnalyzer<P extends AbstractAssignAnalyzer.AbstractAssignPendingExit>
  1372     public abstract class AbstractAssignAnalyzer<P extends AbstractAssignAnalyzer<P>.AbstractAssignPendingExit>
  1373         extends BaseAnalyzer<P> {
  1373         extends BaseAnalyzer<P> {
  1374 
  1374 
  1375         /** The set of definitely assigned variables.
  1375         /** The set of definitely assigned variables.
  1376          */
  1376          */
  1377         protected final Bits inits;
  1377         protected Bits inits;
  1378 
  1378 
  1379         /** The set of definitely unassigned variables.
  1379         /** The set of definitely unassigned variables.
  1380          */
  1380          */
  1381         final Bits uninits;
  1381         final Bits uninits;
  1382 
  1382 
  1426         FlowKind flowKind = FlowKind.NORMAL;
  1426         FlowKind flowKind = FlowKind.NORMAL;
  1427 
  1427 
  1428         /** The starting position of the analysed tree */
  1428         /** The starting position of the analysed tree */
  1429         int startPos;
  1429         int startPos;
  1430 
  1430 
  1431         final Symtab syms;
  1431         public class AbstractAssignPendingExit extends BaseAnalyzer.PendingExit {
  1432 
       
  1433         protected Names names;
       
  1434 
       
  1435         final boolean enforceThisDotInit;
       
  1436 
       
  1437         public static class AbstractAssignPendingExit extends BaseAnalyzer.PendingExit {
       
  1438 
  1432 
  1439             final Bits inits;
  1433             final Bits inits;
  1440             final Bits uninits;
  1434             final Bits uninits;
  1441             final Bits exit_inits = new Bits(true);
  1435             final Bits exit_inits = new Bits(true);
  1442             final Bits exit_uninits = new Bits(true);
  1436             final Bits exit_uninits = new Bits(true);
  1454                 inits.andSet(exit_inits);
  1448                 inits.andSet(exit_inits);
  1455                 uninits.andSet(exit_uninits);
  1449                 uninits.andSet(exit_uninits);
  1456             }
  1450             }
  1457         }
  1451         }
  1458 
  1452 
  1459         public AbstractAssignAnalyzer(Bits inits, Symtab syms, Names names, boolean enforceThisDotInit) {
  1453         public AbstractAssignAnalyzer() {
  1460             this.inits = inits;
  1454             this.inits = new Bits();
  1461             uninits = new Bits();
  1455             uninits = new Bits();
  1462             uninitsTry = new Bits();
  1456             uninitsTry = new Bits();
  1463             initsWhenTrue = new Bits(true);
  1457             initsWhenTrue = new Bits(true);
  1464             initsWhenFalse = new Bits(true);
  1458             initsWhenFalse = new Bits(true);
  1465             uninitsWhenTrue = new Bits(true);
  1459             uninitsWhenTrue = new Bits(true);
  1466             uninitsWhenFalse = new Bits(true);
  1460             uninitsWhenFalse = new Bits(true);
  1467             this.syms = syms;
       
  1468             this.names = names;
       
  1469             this.enforceThisDotInit = enforceThisDotInit;
       
  1470         }
  1461         }
  1471 
  1462 
  1472         private boolean isInitialConstructor = false;
  1463         private boolean isInitialConstructor = false;
  1473 
  1464 
  1474         @Override
  1465         @Override
  2429                 unrefdResources = null;
  2420                 unrefdResources = null;
  2430             }
  2421             }
  2431         }
  2422         }
  2432     }
  2423     }
  2433 
  2424 
  2434     public static class AssignAnalyzer
  2425     public class AssignAnalyzer extends AbstractAssignAnalyzer<AssignAnalyzer.AssignPendingExit> {
  2435         extends AbstractAssignAnalyzer<AssignAnalyzer.AssignPendingExit> {
  2426 
  2436 
  2427         public class AssignPendingExit extends AbstractAssignAnalyzer<AssignPendingExit>.AbstractAssignPendingExit {
  2437         Log log;
       
  2438         Lint lint;
       
  2439 
       
  2440         public static class AssignPendingExit
       
  2441             extends AbstractAssignAnalyzer.AbstractAssignPendingExit {
       
  2442 
  2428 
  2443             public AssignPendingExit(JCTree tree, final Bits inits, final Bits uninits) {
  2429             public AssignPendingExit(JCTree tree, final Bits inits, final Bits uninits) {
  2444                 super(tree, inits, uninits);
  2430                 super(tree, inits, uninits);
  2445             }
  2431             }
  2446         }
       
  2447 
       
  2448         public AssignAnalyzer(Log log, Symtab syms, Lint lint, Names names, boolean enforceThisDotInit) {
       
  2449             super(new Bits(), syms, names, enforceThisDotInit);
       
  2450             this.log = log;
       
  2451             this.lint = lint;
       
  2452         }
  2432         }
  2453 
  2433 
  2454         @Override
  2434         @Override
  2455         protected AssignPendingExit createNewPendingExit(JCTree tree,
  2435         protected AssignPendingExit createNewPendingExit(JCTree tree,
  2456             Bits inits, Bits uninits) {
  2436             Bits inits, Bits uninits) {