nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/ir/debug/PrintVisitor.java
author attila
Wed, 28 Jan 2015 17:58:08 +0100
changeset 28690 78317797ab62
parent 25865 d38d876f1654
child 32888 24f99be3d5ab
permissions -rw-r--r--
8067139: Finally blocks inlined incorrectly Reviewed-by: hannesw, lagergren
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     1
/*
16151
97c1e756ae1e 8005663: Update copyright year to 2013
jlaskey
parents: 16147
diff changeset
     2
 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     4
 *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    10
 *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    15
 * accompanied this code).
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    16
 *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    20
 *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    23
 * questions.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    24
 */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    25
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    26
package jdk.nashorn.internal.ir.debug;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    27
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    28
import java.util.List;
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
    29
import jdk.nashorn.internal.ir.BinaryNode;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    30
import jdk.nashorn.internal.ir.Block;
21868
f3cd4fa7f8b9 8028434: Line number nodes were off for while nodes and do while nodes - the line number of a loop node should be treated as the location of the test expression
lagergren
parents: 18869
diff changeset
    31
import jdk.nashorn.internal.ir.BlockStatement;
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24719
diff changeset
    32
import jdk.nashorn.internal.ir.BreakNode;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    33
import jdk.nashorn.internal.ir.CaseNode;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    34
import jdk.nashorn.internal.ir.CatchNode;
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24719
diff changeset
    35
import jdk.nashorn.internal.ir.ContinueNode;
18867
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 17769
diff changeset
    36
import jdk.nashorn.internal.ir.ExpressionStatement;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    37
import jdk.nashorn.internal.ir.ForNode;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    38
import jdk.nashorn.internal.ir.FunctionNode;
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24719
diff changeset
    39
import jdk.nashorn.internal.ir.IdentNode;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    40
import jdk.nashorn.internal.ir.IfNode;
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24719
diff changeset
    41
import jdk.nashorn.internal.ir.JoinPredecessor;
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24719
diff changeset
    42
import jdk.nashorn.internal.ir.JoinPredecessorExpression;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    43
import jdk.nashorn.internal.ir.LabelNode;
17769
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents: 17524
diff changeset
    44
import jdk.nashorn.internal.ir.LexicalContext;
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24719
diff changeset
    45
import jdk.nashorn.internal.ir.LocalVariableConversion;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    46
import jdk.nashorn.internal.ir.Node;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    47
import jdk.nashorn.internal.ir.SplitNode;
17524
703643aeb0d6 8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents: 17233
diff changeset
    48
import jdk.nashorn.internal.ir.Statement;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    49
import jdk.nashorn.internal.ir.SwitchNode;
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24719
diff changeset
    50
import jdk.nashorn.internal.ir.ThrowNode;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    51
import jdk.nashorn.internal.ir.TryNode;
18869
b8ddb7296bae 8020125: PrintVisitor wasn't printing bodies of FunctionNode within UnaryNode
attila
parents: 18867
diff changeset
    52
import jdk.nashorn.internal.ir.UnaryNode;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    53
import jdk.nashorn.internal.ir.VarNode;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    54
import jdk.nashorn.internal.ir.WhileNode;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    55
import jdk.nashorn.internal.ir.WithNode;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    56
import jdk.nashorn.internal.ir.visitor.NodeVisitor;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    57
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    58
/**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    59
 * Print out the AST as human readable source code.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    60
 * This works both on lowered and unlowered ASTs
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    61
 *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    62
 * see the flags --print-parse and --print-lower-parse
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    63
 */
17769
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents: 17524
diff changeset
    64
public final class PrintVisitor extends NodeVisitor<LexicalContext> {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    65
    /** Tab width */
17524
703643aeb0d6 8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents: 17233
diff changeset
    66
    private static final int TABWIDTH = 4;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    67
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    68
    /** Composing buffer. */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    69
    private final StringBuilder sb;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    70
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    71
    /** Indentation factor. */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    72
    private int indent;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    73
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    74
    /** Line separator. */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    75
    private final String EOLN;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    76
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    77
    /** Print line numbers */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    78
    private final boolean printLineNumbers;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    79
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
    80
    /** Print inferred and optimistic types */
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
    81
    private final boolean printTypes;
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
    82
17524
703643aeb0d6 8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents: 17233
diff changeset
    83
    private int lastLineNumber = -1;
703643aeb0d6 8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents: 17233
diff changeset
    84
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    85
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    86
     * Constructor.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    87
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    88
    public PrintVisitor() {
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
    89
        this(true, true);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    90
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    91
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    92
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    93
     * Constructor
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    94
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    95
     * @param printLineNumbers  should line number nodes be included in the output?
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
    96
     * @param printTypes        should we print optimistic and inferred types?
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    97
     */
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
    98
    public PrintVisitor(final boolean printLineNumbers, final boolean printTypes) {
17769
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents: 17524
diff changeset
    99
        super(new LexicalContext());
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   100
        this.EOLN             = System.lineSeparator();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   101
        this.sb               = new StringBuilder();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   102
        this.printLineNumbers = printLineNumbers;
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   103
        this.printTypes       = printTypes;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   104
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   105
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   106
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   107
     * Constructor
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   108
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   109
     * @param root  a node from which to start printing code
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   110
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   111
    public PrintVisitor(final Node root) {
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   112
        this(root, true, true);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   113
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   114
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   115
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   116
     * Constructor
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   117
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   118
     * @param root              a node from which to start printing code
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   119
     * @param printLineNumbers  should line numbers nodes be included in the output?
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   120
     * @param printTypes        should we print optimistic and inferred types?
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   121
     */
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   122
    public PrintVisitor(final Node root, final boolean printLineNumbers, final boolean printTypes) {
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   123
        this(printLineNumbers, printTypes);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   124
        visit(root);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   125
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   126
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   127
    private void visit(final Node root) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   128
        root.accept(this);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   129
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   130
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   131
    @Override
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   132
    public String toString() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   133
        return sb.append(EOLN).toString();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   134
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   135
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   136
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   137
     * Insert spaces before a statement.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   138
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   139
    private void indent() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   140
        for (int i = indent; i > 0; i--) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   141
            sb.append(' ');
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   142
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   143
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   144
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   145
    /*
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   146
     * Visits.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   147
     */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   148
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   149
    @Override
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   150
    public boolean enterDefault(final Node node) {
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   151
        node.toString(sb, printTypes);
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   152
        return false;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   153
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   154
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   155
    @Override
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24719
diff changeset
   156
    public boolean enterContinueNode(final ContinueNode node) {
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   157
        node.toString(sb, printTypes);
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24719
diff changeset
   158
        printLocalVariableConversion(node);
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24719
diff changeset
   159
        return false;
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24719
diff changeset
   160
    }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24719
diff changeset
   161
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24719
diff changeset
   162
    @Override
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24719
diff changeset
   163
    public boolean enterBreakNode(final BreakNode node) {
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   164
        node.toString(sb, printTypes);
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24719
diff changeset
   165
        printLocalVariableConversion(node);
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24719
diff changeset
   166
        return false;
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24719
diff changeset
   167
    }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24719
diff changeset
   168
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24719
diff changeset
   169
    @Override
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24719
diff changeset
   170
    public boolean enterThrowNode(final ThrowNode node) {
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   171
        node.toString(sb, printTypes);
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24719
diff changeset
   172
        printLocalVariableConversion(node);
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24719
diff changeset
   173
        return false;
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24719
diff changeset
   174
    }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24719
diff changeset
   175
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24719
diff changeset
   176
    @Override
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   177
    public boolean enterBlock(final Block block) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   178
        sb.append(' ');
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   179
        sb.append('{');
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   180
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   181
        indent += TABWIDTH;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   182
17524
703643aeb0d6 8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents: 17233
diff changeset
   183
        final List<Statement> statements = block.getStatements();
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   184
25244
627d7e86f3b5 8047357: More precise synthetic return + unreachable throw
attila
parents: 24759
diff changeset
   185
        for (final Statement statement : statements) {
627d7e86f3b5 8047357: More precise synthetic return + unreachable throw
attila
parents: 24759
diff changeset
   186
            if (printLineNumbers) {
627d7e86f3b5 8047357: More precise synthetic return + unreachable throw
attila
parents: 24759
diff changeset
   187
                final int lineNumber = statement.getLineNumber();
17524
703643aeb0d6 8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents: 17233
diff changeset
   188
                sb.append('\n');
703643aeb0d6 8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents: 17233
diff changeset
   189
                if (lineNumber != lastLineNumber) {
703643aeb0d6 8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents: 17233
diff changeset
   190
                    indent();
703643aeb0d6 8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents: 17233
diff changeset
   191
                    sb.append("[|").append(lineNumber).append("|];").append('\n');
703643aeb0d6 8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents: 17233
diff changeset
   192
                }
703643aeb0d6 8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents: 17233
diff changeset
   193
                lastLineNumber = lineNumber;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   194
            }
17524
703643aeb0d6 8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents: 17233
diff changeset
   195
            indent();
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   196
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   197
            statement.accept(this);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   198
17524
703643aeb0d6 8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents: 17233
diff changeset
   199
            int  lastIndex = sb.length() - 1;
703643aeb0d6 8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents: 17233
diff changeset
   200
            char lastChar  = sb.charAt(lastIndex);
703643aeb0d6 8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents: 17233
diff changeset
   201
            while (Character.isWhitespace(lastChar) && lastIndex >= 0) {
703643aeb0d6 8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents: 17233
diff changeset
   202
                lastChar = sb.charAt(--lastIndex);
703643aeb0d6 8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents: 17233
diff changeset
   203
            }
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   204
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   205
            if (lastChar != '}' && lastChar != ';') {
17524
703643aeb0d6 8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents: 17233
diff changeset
   206
                sb.append(';');
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   207
            }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   208
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   209
            if (statement.hasGoto()) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   210
                sb.append(" [GOTO]");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   211
            }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   212
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   213
            if (statement.isTerminal()) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   214
                sb.append(" [TERMINAL]");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   215
            }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   216
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   217
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   218
        indent -= TABWIDTH;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   219
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   220
        sb.append(EOLN);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   221
        indent();
17524
703643aeb0d6 8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents: 17233
diff changeset
   222
        sb.append('}');
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24719
diff changeset
   223
        printLocalVariableConversion(block);
21868
f3cd4fa7f8b9 8028434: Line number nodes were off for while nodes and do while nodes - the line number of a loop node should be treated as the location of the test expression
lagergren
parents: 18869
diff changeset
   224
f3cd4fa7f8b9 8028434: Line number nodes were off for while nodes and do while nodes - the line number of a loop node should be treated as the location of the test expression
lagergren
parents: 18869
diff changeset
   225
        return false;
f3cd4fa7f8b9 8028434: Line number nodes were off for while nodes and do while nodes - the line number of a loop node should be treated as the location of the test expression
lagergren
parents: 18869
diff changeset
   226
    }
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   227
21868
f3cd4fa7f8b9 8028434: Line number nodes were off for while nodes and do while nodes - the line number of a loop node should be treated as the location of the test expression
lagergren
parents: 18869
diff changeset
   228
    @Override
f3cd4fa7f8b9 8028434: Line number nodes were off for while nodes and do while nodes - the line number of a loop node should be treated as the location of the test expression
lagergren
parents: 18869
diff changeset
   229
    public boolean enterBlockStatement(final BlockStatement statement) {
f3cd4fa7f8b9 8028434: Line number nodes were off for while nodes and do while nodes - the line number of a loop node should be treated as the location of the test expression
lagergren
parents: 18869
diff changeset
   230
        statement.getBlock().accept(this);
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   231
        return false;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   232
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   233
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   234
    @Override
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   235
    public boolean enterBinaryNode(final BinaryNode binaryNode) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   236
        binaryNode.lhs().accept(this);
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   237
        sb.append(' ');
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   238
        sb.append(binaryNode.tokenType());
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   239
        sb.append(' ');
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   240
        binaryNode.rhs().accept(this);
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   241
        return false;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   242
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   243
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   244
    @Override
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   245
    public boolean enterJoinPredecessorExpression(final JoinPredecessorExpression expr) {
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24719
diff changeset
   246
        expr.getExpression().accept(this);
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24719
diff changeset
   247
        printLocalVariableConversion(expr);
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24719
diff changeset
   248
        return false;
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24719
diff changeset
   249
    }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24719
diff changeset
   250
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24719
diff changeset
   251
    @Override
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   252
    public boolean enterIdentNode(final IdentNode identNode) {
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   253
        identNode.toString(sb, printTypes);
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24719
diff changeset
   254
        printLocalVariableConversion(identNode);
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24719
diff changeset
   255
        return true;
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24719
diff changeset
   256
    }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24719
diff changeset
   257
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24719
diff changeset
   258
    private void printLocalVariableConversion(final JoinPredecessor joinPredecessor) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24719
diff changeset
   259
        LocalVariableConversion.toString(joinPredecessor.getLocalVariableConversion(), sb);
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24719
diff changeset
   260
    }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24719
diff changeset
   261
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24719
diff changeset
   262
    @Override
18869
b8ddb7296bae 8020125: PrintVisitor wasn't printing bodies of FunctionNode within UnaryNode
attila
parents: 18867
diff changeset
   263
    public boolean enterUnaryNode(final UnaryNode unaryNode) {
b8ddb7296bae 8020125: PrintVisitor wasn't printing bodies of FunctionNode within UnaryNode
attila
parents: 18867
diff changeset
   264
        unaryNode.toString(sb, new Runnable() {
b8ddb7296bae 8020125: PrintVisitor wasn't printing bodies of FunctionNode within UnaryNode
attila
parents: 18867
diff changeset
   265
            @Override
b8ddb7296bae 8020125: PrintVisitor wasn't printing bodies of FunctionNode within UnaryNode
attila
parents: 18867
diff changeset
   266
            public void run() {
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 21868
diff changeset
   267
                unaryNode.getExpression().accept(PrintVisitor.this);
18869
b8ddb7296bae 8020125: PrintVisitor wasn't printing bodies of FunctionNode within UnaryNode
attila
parents: 18867
diff changeset
   268
            }
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   269
        }, printTypes);
18869
b8ddb7296bae 8020125: PrintVisitor wasn't printing bodies of FunctionNode within UnaryNode
attila
parents: 18867
diff changeset
   270
        return false;
b8ddb7296bae 8020125: PrintVisitor wasn't printing bodies of FunctionNode within UnaryNode
attila
parents: 18867
diff changeset
   271
    }
b8ddb7296bae 8020125: PrintVisitor wasn't printing bodies of FunctionNode within UnaryNode
attila
parents: 18867
diff changeset
   272
b8ddb7296bae 8020125: PrintVisitor wasn't printing bodies of FunctionNode within UnaryNode
attila
parents: 18867
diff changeset
   273
    @Override
18867
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 17769
diff changeset
   274
    public boolean enterExpressionStatement(final ExpressionStatement expressionStatement) {
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 17769
diff changeset
   275
        expressionStatement.getExpression().accept(this);
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   276
        return false;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   277
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   278
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   279
    @Override
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   280
    public boolean enterForNode(final ForNode forNode) {
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   281
        forNode.toString(sb, printTypes);
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   282
        forNode.getBody().accept(this);
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   283
        return false;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   284
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   285
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   286
    @Override
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   287
    public boolean enterFunctionNode(final FunctionNode functionNode) {
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   288
        functionNode.toString(sb, printTypes);
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   289
        enterBlock(functionNode.getBody());
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   290
        return false;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   291
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   292
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   293
    @Override
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   294
    public boolean enterIfNode(final IfNode ifNode) {
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   295
        ifNode.toString(sb, printTypes);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   296
        ifNode.getPass().accept(this);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   297
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   298
        final Block fail = ifNode.getFail();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   299
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   300
        if (fail != null) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   301
            sb.append(" else ");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   302
            fail.accept(this);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   303
        }
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24719
diff changeset
   304
        if(ifNode.getLocalVariableConversion() != null) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24719
diff changeset
   305
            assert fail == null;
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24719
diff changeset
   306
            sb.append(" else ");
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24719
diff changeset
   307
            printLocalVariableConversion(ifNode);
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24719
diff changeset
   308
            sb.append(";");
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24719
diff changeset
   309
        }
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   310
        return false;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   311
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   312
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   313
    @Override
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   314
    public boolean enterLabelNode(final LabelNode labeledNode) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   315
        indent -= TABWIDTH;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   316
        indent();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   317
        indent += TABWIDTH;
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   318
        labeledNode.toString(sb, printTypes);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   319
        labeledNode.getBody().accept(this);
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24719
diff changeset
   320
        printLocalVariableConversion(labeledNode);
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   321
        return false;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   322
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   323
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   324
    @Override
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   325
    public boolean enterSplitNode(final SplitNode splitNode) {
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   326
        splitNode.toString(sb, printTypes);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   327
        sb.append(EOLN);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   328
        indent += TABWIDTH;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   329
        indent();
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   330
        return true;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   331
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   332
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   333
    @Override
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16151
diff changeset
   334
    public Node leaveSplitNode(final SplitNode splitNode) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   335
        sb.append("</split>");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   336
        sb.append(EOLN);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   337
        indent -= TABWIDTH;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   338
        indent();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   339
        return splitNode;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   340
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   341
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   342
    @Override
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   343
    public boolean enterSwitchNode(final SwitchNode switchNode) {
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   344
        switchNode.toString(sb, printTypes);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   345
        sb.append(" {");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   346
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   347
        final List<CaseNode> cases = switchNode.getCases();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   348
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   349
        for (final CaseNode caseNode : cases) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   350
            sb.append(EOLN);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   351
            indent();
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   352
            caseNode.toString(sb, printTypes);
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24719
diff changeset
   353
            printLocalVariableConversion(caseNode);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   354
            indent += TABWIDTH;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   355
            caseNode.getBody().accept(this);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   356
            indent -= TABWIDTH;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   357
            sb.append(EOLN);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   358
        }
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24719
diff changeset
   359
        if(switchNode.getLocalVariableConversion() != null) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24719
diff changeset
   360
            sb.append(EOLN);
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24719
diff changeset
   361
            indent();
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24719
diff changeset
   362
            sb.append("default: ");
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24719
diff changeset
   363
            printLocalVariableConversion(switchNode);
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24719
diff changeset
   364
            sb.append("{}");
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24719
diff changeset
   365
        }
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   366
        sb.append(EOLN);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   367
        indent();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   368
        sb.append("}");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   369
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   370
        return false;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   371
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   372
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   373
    @Override
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   374
    public boolean enterTryNode(final TryNode tryNode) {
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   375
        tryNode.toString(sb, printTypes);
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24719
diff changeset
   376
        printLocalVariableConversion(tryNode);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   377
        tryNode.getBody().accept(this);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   378
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   379
        final List<Block> catchBlocks = tryNode.getCatchBlocks();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   380
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   381
        for (final Block catchBlock : catchBlocks) {
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   382
            final CatchNode catchNode = (CatchNode)catchBlock.getStatements().get(0);
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   383
            catchNode.toString(sb, printTypes);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   384
            catchNode.getBody().accept(this);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   385
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   386
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   387
        final Block finallyBody = tryNode.getFinallyBody();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   388
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   389
        if (finallyBody != null) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   390
            sb.append(" finally ");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   391
            finallyBody.accept(this);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   392
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   393
28690
78317797ab62 8067139: Finally blocks inlined incorrectly
attila
parents: 25865
diff changeset
   394
        for (final Block inlinedFinally : tryNode.getInlinedFinallies()) {
78317797ab62 8067139: Finally blocks inlined incorrectly
attila
parents: 25865
diff changeset
   395
            inlinedFinally.accept(this);
78317797ab62 8067139: Finally blocks inlined incorrectly
attila
parents: 25865
diff changeset
   396
        }
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   397
        return false;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   398
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   399
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   400
    @Override
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   401
    public boolean enterVarNode(final VarNode varNode) {
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16151
diff changeset
   402
        sb.append("var ");
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   403
        varNode.getName().toString(sb, printTypes);
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24719
diff changeset
   404
        printLocalVariableConversion(varNode.getName());
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16151
diff changeset
   405
        final Node init = varNode.getInit();
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   406
        if (init != null) {
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16151
diff changeset
   407
            sb.append(" = ");
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16151
diff changeset
   408
            init.accept(this);
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16151
diff changeset
   409
        }
17524
703643aeb0d6 8013914: Removed explicit LineNumberNodes that were too brittle when code moves around, and also introduced unnecessary footprint. Introduced the Statement node and fixed dead code elimination issues that were discovered by the absense of labels for LineNumberNodes.
lagergren
parents: 17233
diff changeset
   410
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   411
        return false;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   412
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   413
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   414
    @Override
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   415
    public boolean enterWhileNode(final WhileNode whileNode) {
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24719
diff changeset
   416
        printLocalVariableConversion(whileNode);
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   417
        if (whileNode.isDoWhile()) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   418
            sb.append("do");
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   419
            whileNode.getBody().accept(this);
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   420
            sb.append(' ');
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   421
            whileNode.toString(sb, printTypes);
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   422
        } else {
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   423
            whileNode.toString(sb, printTypes);
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   424
            whileNode.getBody().accept(this);
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   425
        }
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   426
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   427
        return false;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   428
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   429
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   430
    @Override
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   431
    public boolean enterWithNode(final WithNode withNode) {
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   432
        withNode.toString(sb, printTypes);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   433
        withNode.getBody().accept(this);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   434
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   435
        return false;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   436
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   437
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   438
}