< prev index next >

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

Print this page




 238     }
 239 
 240     public List<Type> analyzeLambdaThrownTypes(final Env<AttrContext> env,
 241             JCLambda that, TreeMaker make) {
 242         //we need to disable diagnostics temporarily; the problem is that if
 243         //a lambda expression contains e.g. an unreachable statement, an error
 244         //message will be reported and will cause compilation to skip the flow analyis
 245         //step - if we suppress diagnostics, we won't stop at Attr for flow-analysis
 246         //related errors, which will allow for more errors to be detected
 247         Log.DiagnosticHandler diagHandler = new Log.DiscardDiagnosticHandler(log);
 248         try {
 249             new LambdaAssignAnalyzer(env).analyzeTree(env, that, make);
 250             LambdaFlowAnalyzer flowAnalyzer = new LambdaFlowAnalyzer();
 251             flowAnalyzer.analyzeTree(env, that, make);
 252             return flowAnalyzer.inferredThrownTypes;
 253         } finally {
 254             log.popDiagnosticHandler(diagHandler);
 255         }
 256     }
 257 








































 258     /**
 259      * Definite assignment scan mode
 260      */
 261     enum FlowKind {
 262         /**
 263          * This is the normal DA/DU analysis mode
 264          */
 265         NORMAL("var.might.already.be.assigned", false),
 266         /**
 267          * This is the speculative DA/DU analysis mode used to speculatively
 268          * derive assertions within loop bodies
 269          */
 270         SPECULATIVE_LOOP("var.might.be.assigned.in.loop", true);
 271 
 272         final String errKey;
 273         final boolean isFinal;
 274 
 275         FlowKind(String errKey, boolean isFinal) {
 276             this.errKey = errKey;
 277             this.isFinal = isFinal;


1446             //ignore lambda return expression (which might not even be attributed)
1447             recordExit(new PendingExit(tree));
1448         }
1449 
1450         @Override
1451         public void visitLambda(JCLambda tree) {
1452             if (inLambda || tree.getBodyKind() == BodyKind.EXPRESSION) {
1453                 return;
1454             }
1455             inLambda = true;
1456             try {
1457                 super.visitLambda(tree);
1458             } finally {
1459                 inLambda = false;
1460             }
1461         }
1462 
1463         @Override
1464         public void visitClassDef(JCClassDecl tree) {
1465             //skip













1466         }
1467     }
1468 
1469     /**
1470      * Specialized pass that performs DA/DU on a lambda
1471      */
1472     class LambdaAssignAnalyzer extends AssignAnalyzer {
1473         WriteableScope enclosedSymbols;
1474         boolean inLambda;
1475 
1476         LambdaAssignAnalyzer(Env<AttrContext> env) {
1477             enclosedSymbols = WriteableScope.create(env.enclClass.sym);
1478         }
1479 
1480         @Override
1481         public void visitLambda(JCLambda tree) {
1482             if (inLambda) {
1483                 return;
1484             }
1485             inLambda = true;




 238     }
 239 
 240     public List<Type> analyzeLambdaThrownTypes(final Env<AttrContext> env,
 241             JCLambda that, TreeMaker make) {
 242         //we need to disable diagnostics temporarily; the problem is that if
 243         //a lambda expression contains e.g. an unreachable statement, an error
 244         //message will be reported and will cause compilation to skip the flow analyis
 245         //step - if we suppress diagnostics, we won't stop at Attr for flow-analysis
 246         //related errors, which will allow for more errors to be detected
 247         Log.DiagnosticHandler diagHandler = new Log.DiscardDiagnosticHandler(log);
 248         try {
 249             new LambdaAssignAnalyzer(env).analyzeTree(env, that, make);
 250             LambdaFlowAnalyzer flowAnalyzer = new LambdaFlowAnalyzer();
 251             flowAnalyzer.analyzeTree(env, that, make);
 252             return flowAnalyzer.inferredThrownTypes;
 253         } finally {
 254             log.popDiagnosticHandler(diagHandler);
 255         }
 256     }
 257 
 258     public boolean aliveAfter(Env<AttrContext> env, JCTree that, TreeMaker make) {
 259         //we need to disable diagnostics temporarily; the problem is that if
 260         //"that" contains e.g. an unreachable statement, an error
 261         //message will be reported and will cause compilation to skip the flow analyis
 262         //step - if we suppress diagnostics, we won't stop at Attr for flow-analysis
 263         //related errors, which will allow for more errors to be detected
 264         Log.DiagnosticHandler diagHandler = new Log.DiscardDiagnosticHandler(log);
 265         try {
 266             SnippetAliveAnalyzer analyzer = new SnippetAliveAnalyzer();
 267 
 268             analyzer.analyzeTree(env, that, make);
 269             return analyzer.isAlive();
 270         } finally {
 271             log.popDiagnosticHandler(diagHandler);
 272         }
 273     }
 274 
 275     public boolean breaksOutOf(Env<AttrContext> env, JCTree loop, JCTree body, TreeMaker make) {
 276         //we need to disable diagnostics temporarily; the problem is that if
 277         //"that" contains e.g. an unreachable statement, an error
 278         //message will be reported and will cause compilation to skip the flow analyis
 279         //step - if we suppress diagnostics, we won't stop at Attr for flow-analysis
 280         //related errors, which will allow for more errors to be detected
 281         Log.DiagnosticHandler diagHandler = new Log.DiscardDiagnosticHandler(log);
 282         try {
 283             boolean[] breaksOut = new boolean[1];
 284             new AliveAnalyzer() {
 285                 @Override
 286                 public void visitBreak(JCBreak tree) {
 287                     breaksOut[0] |= (super.alive == Liveness.ALIVE && tree.target == loop);
 288                     super.visitBreak(tree);
 289                 }
 290             }.analyzeTree(env, body, make);
 291 
 292             return breaksOut[0];
 293         } finally {
 294             log.popDiagnosticHandler(diagHandler);
 295         }
 296     }
 297 
 298     /**
 299      * Definite assignment scan mode
 300      */
 301     enum FlowKind {
 302         /**
 303          * This is the normal DA/DU analysis mode
 304          */
 305         NORMAL("var.might.already.be.assigned", false),
 306         /**
 307          * This is the speculative DA/DU analysis mode used to speculatively
 308          * derive assertions within loop bodies
 309          */
 310         SPECULATIVE_LOOP("var.might.be.assigned.in.loop", true);
 311 
 312         final String errKey;
 313         final boolean isFinal;
 314 
 315         FlowKind(String errKey, boolean isFinal) {
 316             this.errKey = errKey;
 317             this.isFinal = isFinal;


1486             //ignore lambda return expression (which might not even be attributed)
1487             recordExit(new PendingExit(tree));
1488         }
1489 
1490         @Override
1491         public void visitLambda(JCLambda tree) {
1492             if (inLambda || tree.getBodyKind() == BodyKind.EXPRESSION) {
1493                 return;
1494             }
1495             inLambda = true;
1496             try {
1497                 super.visitLambda(tree);
1498             } finally {
1499                 inLambda = false;
1500             }
1501         }
1502 
1503         @Override
1504         public void visitClassDef(JCClassDecl tree) {
1505             //skip
1506         }
1507     }
1508 
1509     /**
1510      * Determine if alive after the given tree.
1511      */
1512     class SnippetAliveAnalyzer extends AliveAnalyzer {
1513         @Override
1514         public void visitClassDef(JCClassDecl tree) {
1515             //skip
1516         }
1517         public boolean isAlive() {
1518             return super.alive != Liveness.DEAD;
1519         }
1520     }
1521 
1522     /**
1523      * Specialized pass that performs DA/DU on a lambda
1524      */
1525     class LambdaAssignAnalyzer extends AssignAnalyzer {
1526         WriteableScope enclosedSymbols;
1527         boolean inLambda;
1528 
1529         LambdaAssignAnalyzer(Env<AttrContext> env) {
1530             enclosedSymbols = WriteableScope.create(env.enclClass.sym);
1531         }
1532 
1533         @Override
1534         public void visitLambda(JCLambda tree) {
1535             if (inLambda) {
1536                 return;
1537             }
1538             inLambda = true;


< prev index next >