langtools/src/share/classes/com/sun/tools/javac/comp/Lower.java
changeset 14721 071e3587f212
parent 14547 86d8d242b0c4
child 15385 ee1eebe7e210
equal deleted inserted replaced
14720:c24c61d0d9a6 14721:071e3587f212
   135  *************************************************************************/
   135  *************************************************************************/
   136 
   136 
   137     /** A hash table mapping local classes to their definitions.
   137     /** A hash table mapping local classes to their definitions.
   138      */
   138      */
   139     Map<ClassSymbol, JCClassDecl> classdefs;
   139     Map<ClassSymbol, JCClassDecl> classdefs;
       
   140 
       
   141     /** A hash table mapping local classes to a list of pruned trees.
       
   142      */
       
   143     public Map<ClassSymbol, List<JCTree>> prunedTree = new WeakHashMap<ClassSymbol, List<JCTree>>();
   140 
   144 
   141     /** A hash table mapping virtual accessed symbols in outer subclasses
   145     /** A hash table mapping virtual accessed symbols in outer subclasses
   142      *  to the actually referred symbol in superclasses.
   146      *  to the actually referred symbol in superclasses.
   143      */
   147      */
   144     Map<Symbol,Symbol> actualSymbols;
   148     Map<Symbol,Symbol> actualSymbols;
  1037             // the symbol is private
  1041             // the symbol is private
  1038             return sym.owner.enclClass();
  1042             return sym.owner.enclClass();
  1039         }
  1043         }
  1040     }
  1044     }
  1041 
  1045 
       
  1046     private void addPrunedInfo(JCTree tree) {
       
  1047         List<JCTree> infoList = prunedTree.get(currentClass);
       
  1048         infoList = (infoList == null) ? List.of(tree) : infoList.prepend(tree);
       
  1049         prunedTree.put(currentClass, infoList);
       
  1050     }
       
  1051 
  1042     /** Ensure that identifier is accessible, return tree accessing the identifier.
  1052     /** Ensure that identifier is accessible, return tree accessing the identifier.
  1043      *  @param sym      The accessed symbol.
  1053      *  @param sym      The accessed symbol.
  1044      *  @param tree     The tree referring to the symbol.
  1054      *  @param tree     The tree referring to the symbol.
  1045      *  @param enclOp   The closest enclosing operation node of tree,
  1055      *  @param enclOp   The closest enclosing operation node of tree,
  1046      *                  null if tree is not a subtree of an operation.
  1056      *                  null if tree is not a subtree of an operation.
  1109                     make.at(tree.pos);
  1119                     make.at(tree.pos);
  1110 
  1120 
  1111                     // Constants are replaced by their constant value.
  1121                     // Constants are replaced by their constant value.
  1112                     if (sym.kind == VAR) {
  1122                     if (sym.kind == VAR) {
  1113                         Object cv = ((VarSymbol)sym).getConstValue();
  1123                         Object cv = ((VarSymbol)sym).getConstValue();
  1114                         if (cv != null) return makeLit(sym.type, cv);
  1124                         if (cv != null) {
       
  1125                             addPrunedInfo(tree);
       
  1126                             return makeLit(sym.type, cv);
       
  1127                         }
  1115                     }
  1128                     }
  1116 
  1129 
  1117                     // Private variables and methods are replaced by calls
  1130                     // Private variables and methods are replaced by calls
  1118                     // to their access methods.
  1131                     // to their access methods.
  1119                     if (accReq) {
  1132                     if (accReq) {
  2744     // constant propagation would require that we take care to
  2757     // constant propagation would require that we take care to
  2745     // preserve possible side-effects in the condition expression.
  2758     // preserve possible side-effects in the condition expression.
  2746 
  2759 
  2747     /** Visitor method for conditional expressions.
  2760     /** Visitor method for conditional expressions.
  2748      */
  2761      */
       
  2762     @Override
  2749     public void visitConditional(JCConditional tree) {
  2763     public void visitConditional(JCConditional tree) {
  2750         JCTree cond = tree.cond = translate(tree.cond, syms.booleanType);
  2764         JCTree cond = tree.cond = translate(tree.cond, syms.booleanType);
  2751         if (cond.type.isTrue()) {
  2765         if (cond.type.isTrue()) {
  2752             result = convert(translate(tree.truepart, tree.type), tree.type);
  2766             result = convert(translate(tree.truepart, tree.type), tree.type);
       
  2767             addPrunedInfo(cond);
  2753         } else if (cond.type.isFalse()) {
  2768         } else if (cond.type.isFalse()) {
  2754             result = convert(translate(tree.falsepart, tree.type), tree.type);
  2769             result = convert(translate(tree.falsepart, tree.type), tree.type);
       
  2770             addPrunedInfo(cond);
  2755         } else {
  2771         } else {
  2756             // Condition is not a compile-time constant.
  2772             // Condition is not a compile-time constant.
  2757             tree.truepart = translate(tree.truepart, tree.type);
  2773             tree.truepart = translate(tree.truepart, tree.type);
  2758             tree.falsepart = translate(tree.falsepart, tree.type);
  2774             tree.falsepart = translate(tree.falsepart, tree.type);
  2759             result = tree;
  2775             result = tree;
  2760         }
  2776         }
  2761     }
  2777     }
  2762 //where
  2778 //where
  2763         private JCTree convert(JCTree tree, Type pt) {
  2779     private JCTree convert(JCTree tree, Type pt) {
  2764             if (tree.type == pt || tree.type.hasTag(BOT))
  2780         if (tree.type == pt || tree.type.hasTag(BOT))
  2765                 return tree;
  2781             return tree;
  2766             JCTree result = make_at(tree.pos()).TypeCast(make.Type(pt), (JCExpression)tree);
  2782         JCTree result = make_at(tree.pos()).TypeCast(make.Type(pt), (JCExpression)tree);
  2767             result.type = (tree.type.constValue() != null) ? cfolder.coerce(tree.type, pt)
  2783         result.type = (tree.type.constValue() != null) ? cfolder.coerce(tree.type, pt)
  2768                                                            : pt;
  2784                                                        : pt;
  2769             return result;
  2785         return result;
  2770         }
  2786     }
  2771 
  2787 
  2772     /** Visitor method for if statements.
  2788     /** Visitor method for if statements.
  2773      */
  2789      */
  2774     public void visitIf(JCIf tree) {
  2790     public void visitIf(JCIf tree) {
  2775         JCTree cond = tree.cond = translate(tree.cond, syms.booleanType);
  2791         JCTree cond = tree.cond = translate(tree.cond, syms.booleanType);
  2776         if (cond.type.isTrue()) {
  2792         if (cond.type.isTrue()) {
  2777             result = translate(tree.thenpart);
  2793             result = translate(tree.thenpart);
       
  2794             addPrunedInfo(cond);
  2778         } else if (cond.type.isFalse()) {
  2795         } else if (cond.type.isFalse()) {
  2779             if (tree.elsepart != null) {
  2796             if (tree.elsepart != null) {
  2780                 result = translate(tree.elsepart);
  2797                 result = translate(tree.elsepart);
  2781             } else {
  2798             } else {
  2782                 result = make.Skip();
  2799                 result = make.Skip();
  2783             }
  2800             }
       
  2801             addPrunedInfo(cond);
  2784         } else {
  2802         } else {
  2785             // Condition is not a compile-time constant.
  2803             // Condition is not a compile-time constant.
  2786             tree.thenpart = translate(tree.thenpart);
  2804             tree.thenpart = translate(tree.thenpart);
  2787             tree.elsepart = translate(tree.elsepart);
  2805             tree.elsepart = translate(tree.elsepart);
  2788             result = tree;
  2806             result = tree;