src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java
changeset 58906 d58a21542c04
parent 58713 ad69fd32778e
child 59021 cfc7bb9a5a92
equal deleted inserted replaced
58905:75eedcd30a2a 58906:d58a21542c04
    72 import static com.sun.tools.javac.code.Flags.BLOCK;
    72 import static com.sun.tools.javac.code.Flags.BLOCK;
    73 import static com.sun.tools.javac.code.Kinds.*;
    73 import static com.sun.tools.javac.code.Kinds.*;
    74 import static com.sun.tools.javac.code.Kinds.Kind.*;
    74 import static com.sun.tools.javac.code.Kinds.Kind.*;
    75 import static com.sun.tools.javac.code.TypeTag.*;
    75 import static com.sun.tools.javac.code.TypeTag.*;
    76 import static com.sun.tools.javac.code.TypeTag.WILDCARD;
    76 import static com.sun.tools.javac.code.TypeTag.WILDCARD;
    77 import com.sun.tools.javac.comp.Analyzer.AnalyzerMode;
       
    78 import static com.sun.tools.javac.tree.JCTree.Tag.*;
    77 import static com.sun.tools.javac.tree.JCTree.Tag.*;
    79 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag;
    78 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticFlag;
    80 import com.sun.tools.javac.util.Log.DeferredDiagnosticHandler;
       
    81 import com.sun.tools.javac.util.Log.DiscardDiagnosticHandler;
       
    82 
    79 
    83 /** This is the main context-dependent analysis phase in GJC. It
    80 /** This is the main context-dependent analysis phase in GJC. It
    84  *  encompasses name resolution, type checking and constant folding as
    81  *  encompasses name resolution, type checking and constant folding as
    85  *  subtasks. Some subtasks involve auxiliary classes.
    82  *  subtasks. Some subtasks involve auxiliary classes.
    86  *  @see Check
    83  *  @see Check
   392                                          KindSelector.TYP : KindSelector.TYP_PCK,
   389                                          KindSelector.TYP : KindSelector.TYP_PCK,
   393                        Type.noType));
   390                        Type.noType));
   394     }
   391     }
   395 
   392 
   396     public Env<AttrContext> attribExprToTree(JCTree expr, Env<AttrContext> env, JCTree tree) {
   393     public Env<AttrContext> attribExprToTree(JCTree expr, Env<AttrContext> env, JCTree tree) {
       
   394         return attribToTree(expr, env, tree, unknownExprInfo);
       
   395     }
       
   396 
       
   397     public Env<AttrContext> attribStatToTree(JCTree stmt, Env<AttrContext> env, JCTree tree) {
       
   398         return attribToTree(stmt, env, tree, statInfo);
       
   399     }
       
   400 
       
   401     private Env<AttrContext> attribToTree(JCTree root, Env<AttrContext> env, JCTree tree, ResultInfo resultInfo) {
   397         breakTree = tree;
   402         breakTree = tree;
   398         JavaFileObject prev = log.useSource(env.toplevel.sourcefile);
   403         JavaFileObject prev = log.useSource(env.toplevel.sourcefile);
   399         EnumSet<AnalyzerMode> analyzerModes = EnumSet.copyOf(analyzer.analyzerModes);
       
   400         try {
   404         try {
   401             analyzer.analyzerModes.clear();
   405             deferredAttr.attribSpeculative(root, env, resultInfo,
   402             attribExpr(expr, env);
   406                     null, DeferredAttr.AttributionMode.ANALYZER,
       
   407                     argumentAttr.withLocalCacheContext());
   403         } catch (BreakAttr b) {
   408         } catch (BreakAttr b) {
   404             return b.env;
   409             return b.env;
   405         } catch (AssertionError ae) {
   410         } catch (AssertionError ae) {
   406             if (ae.getCause() instanceof BreakAttr) {
   411             if (ae.getCause() instanceof BreakAttr) {
   407                 return ((BreakAttr)(ae.getCause())).env;
   412                 return ((BreakAttr)(ae.getCause())).env;
   409                 throw ae;
   414                 throw ae;
   410             }
   415             }
   411         } finally {
   416         } finally {
   412             breakTree = null;
   417             breakTree = null;
   413             log.useSource(prev);
   418             log.useSource(prev);
   414             analyzer.analyzerModes.addAll(analyzerModes);
       
   415         }
       
   416         return env;
       
   417     }
       
   418 
       
   419     public Env<AttrContext> attribStatToTree(JCTree stmt, Env<AttrContext> env, JCTree tree) {
       
   420         breakTree = tree;
       
   421         JavaFileObject prev = log.useSource(env.toplevel.sourcefile);
       
   422         EnumSet<AnalyzerMode> analyzerModes = EnumSet.copyOf(analyzer.analyzerModes);
       
   423         try {
       
   424             analyzer.analyzerModes.clear();
       
   425             attribStat(stmt, env);
       
   426         } catch (BreakAttr b) {
       
   427             return b.env;
       
   428         } catch (AssertionError ae) {
       
   429             if (ae.getCause() instanceof BreakAttr) {
       
   430                 return ((BreakAttr)(ae.getCause())).env;
       
   431             } else {
       
   432                 throw ae;
       
   433             }
       
   434         } finally {
       
   435             breakTree = null;
       
   436             log.useSource(prev);
       
   437             analyzer.analyzerModes.addAll(analyzerModes);
       
   438         }
   419         }
   439         return env;
   420         return env;
   440     }
   421     }
   441 
   422 
   442     private JCTree breakTree = null;
   423     private JCTree breakTree = null;
  1271     public void visitSkip(JCSkip tree) {
  1252     public void visitSkip(JCSkip tree) {
  1272         result = null;
  1253         result = null;
  1273     }
  1254     }
  1274 
  1255 
  1275     public void visitBlock(JCBlock tree) {
  1256     public void visitBlock(JCBlock tree) {
  1276         if (env.info.scope.owner.kind == TYP) {
  1257         if (env.info.scope.owner.kind == TYP || env.info.scope.owner.kind == ERR) {
  1277             // Block is a static or instance initializer;
  1258             // Block is a static or instance initializer;
  1278             // let the owner of the environment be a freshly
  1259             // let the owner of the environment be a freshly
  1279             // created BLOCK-method.
  1260             // created BLOCK-method.
  1280             Symbol fakeOwner =
  1261             Symbol fakeOwner =
  1281                 new MethodSymbol(tree.flags | BLOCK |
  1262                 new MethodSymbol(tree.flags | BLOCK |
  1531                     switchEnv.dup(c, env.info.dup(switchEnv.info.scope.dup()));
  1512                     switchEnv.dup(c, env.info.dup(switchEnv.info.scope.dup()));
  1532                 try {
  1513                 try {
  1533                     attribCase.accept(c, caseEnv);
  1514                     attribCase.accept(c, caseEnv);
  1534                 } finally {
  1515                 } finally {
  1535                     caseEnv.info.scope.leave();
  1516                     caseEnv.info.scope.leave();
  1536                     addVars(c.stats, switchEnv.info.scope);
  1517                 }
  1537                 }
  1518                 addVars(c.stats, switchEnv.info.scope);
  1538             }
  1519             }
  1539         } finally {
  1520         } finally {
  1540             switchEnv.info.scope.leave();
  1521             switchEnv.info.scope.leave();
  1541         }
  1522         }
  1542     }
  1523     }