Commits

Artem Melentyev  committed b485228

replace JCTree.translate to WeakHashMap

  • Participants
  • Parent commits 21f8cdb

Comments (0)

Files changed (3)

File src/share/classes/com/sun/tools/javac/comp/Attr.java

         if (owntype.tag != ERROR && pt.tag != METHOD && pt.tag != FORALL) {
             if ((ownkind & ~pkind) == 0) {
                 if (quietCheckType(tree.pos(), owntype, pt, errKey).isErroneous()){ // if not ok
-                    JCExpression t = tryBoxingOverload(tree, pt);
+                    JCExpression t = tryBoxingOverload((JCExpression) tree, pt);
                     if (t != null) {
-                        tree.translate = t;
-                        return tree.type = t.type;
+                        addTranslate(tree, t);
+                        return tree.type = owntype;
                     }
                 }
                 owntype = chk.checkType(tree.pos(), owntype, pt, errKey);
         tree.type = owntype;
         return owntype;
     }
+    private WeakHashMap<JCTree, JCExpression> translatesMap = new WeakHashMap<>();
+    public void addTranslate(JCTree from, JCExpression to) {
+        translatesMap.put(from, to);
+    }
+    public JCExpression removeTranslate(JCTree from) {
+        return translatesMap.remove(from);
+    }
     /** try boxing tree to pt type via #valueOf */
-    JCExpression tryBoxingOverload(JCTree tree, Type pt) {
+    JCExpression tryBoxingOverload(JCExpression tree, Type pt) {
         JCExpression t = make.Select(make.Ident(pt.tsym), names.fromString("valueOf"));
-        t = make.Apply(null, t, List.of((JCExpression)(tree.translate==null ? tree.clone() : tree.translate)));
+        JCExpression param = translatesMap.get(tree);
+        t = make.Apply(null, t, List.of(param == null ? tree : param));
         t.type = attribTree(t, env, pkind, pt);
         return t.type.isErroneous() ? null : t;
     }

File src/share/classes/com/sun/tools/javac/comp/Lower.java

                 Integer endPos = endPositions.remove(tree);
                 if (endPos != null) endPositions.put(result, endPos);
             }
-            if (result.translate!=null) {
-            	T t = (T) result.translate;
-            	result.translate = null;
-            	return translate(t);
-            }
+            JCExpression t = attr.removeTranslate(tree);
+            if (t!=null)
+                return (T) translate(t);
             return result;
         }
     }
     /** Visitor method: Translate a single node, boxing or unboxing if needed.
      */
     public <T extends JCTree> T translate(T tree, Type type) {
+        JCExpression t = attr.removeTranslate(tree);
+        if (t!=null)
+            return (T) translate(t);
         return (tree == null) ? null : boxIfNeeded(translate(tree), type);
     }
 

File src/share/classes/com/sun/tools/javac/tree/JCTree.java

     /* The type of this node.
      */
     public Type type;
-    
-    public JCExpression translate;
 
     /* The tag of this node -- one of the constants declared above.
      */