8020125: PrintVisitor wasn't printing bodies of FunctionNode within UnaryNode
authorattila
Thu, 11 Jul 2013 22:01:55 +0200
changeset 18869 b8ddb7296bae
parent 18868 f5359cad148c
child 18870 aa4fceda2fba
8020125: PrintVisitor wasn't printing bodies of FunctionNode within UnaryNode Reviewed-by: jlaskey, lagergren
nashorn/src/jdk/nashorn/internal/ir/UnaryNode.java
nashorn/src/jdk/nashorn/internal/ir/debug/PrintVisitor.java
--- a/nashorn/src/jdk/nashorn/internal/ir/UnaryNode.java	Thu Jul 11 22:58:37 2013 +0530
+++ b/nashorn/src/jdk/nashorn/internal/ir/UnaryNode.java	Thu Jul 11 22:01:55 2013 +0200
@@ -131,6 +131,22 @@
 
     @Override
     public void toString(final StringBuilder sb) {
+        toString(sb, new Runnable() {
+            @Override
+            public void run() {
+                sb.append(rhs().toString());
+            }
+        });
+    }
+
+    /**
+     * Creates the string representation of this unary node, delegating the creation of the string representation of its
+     * operand to a specified runnable.
+     * @param sb the string builder to use
+     * @param rhsStringBuilder the runnable that appends the string representation of the operand to the string builder
+     * when invoked.
+     */
+    public void toString(final StringBuilder sb, final Runnable rhsStringBuilder) {
         final TokenType type      = tokenType();
         final String    name      = type.getName();
         final boolean   isPostfix = type == DECPOSTFIX || type == INCPOSTFIX;
@@ -162,7 +178,7 @@
         if (rhsParen) {
             sb.append('(');
         }
-        rhs().toString(sb);
+        rhsStringBuilder.run();
         if (rhsParen) {
             sb.append(')');
         }
--- a/nashorn/src/jdk/nashorn/internal/ir/debug/PrintVisitor.java	Thu Jul 11 22:58:37 2013 +0530
+++ b/nashorn/src/jdk/nashorn/internal/ir/debug/PrintVisitor.java	Thu Jul 11 22:01:55 2013 +0200
@@ -41,6 +41,7 @@
 import jdk.nashorn.internal.ir.Statement;
 import jdk.nashorn.internal.ir.SwitchNode;
 import jdk.nashorn.internal.ir.TryNode;
+import jdk.nashorn.internal.ir.UnaryNode;
 import jdk.nashorn.internal.ir.VarNode;
 import jdk.nashorn.internal.ir.WhileNode;
 import jdk.nashorn.internal.ir.WithNode;
@@ -205,6 +206,17 @@
     }
 
     @Override
+    public boolean enterUnaryNode(final UnaryNode unaryNode) {
+        unaryNode.toString(sb, new Runnable() {
+            @Override
+            public void run() {
+                unaryNode.rhs().accept(PrintVisitor.this);
+            }
+        });
+        return false;
+    }
+
+    @Override
     public boolean enterExpressionStatement(final ExpressionStatement expressionStatement) {
         expressionStatement.getExpression().accept(this);
         return false;