src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/ir/Block.java
author hannesw
Wed, 07 Mar 2018 18:36:21 +0100
changeset 49145 2854589fd853
parent 47216 71c04702a3d5
permissions -rw-r--r--
8199236: Nashorn uses deprecated HTML tags in Javadoc Reviewed-by: jlaskey, sundar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     1
/*
47038
f57fa7f112a0 8177691: Labeled break in catch and finally works wrongly, when invoked through nashorn
sdama
parents: 37732
diff changeset
     2
 * Copyright (c) 2010, 2017, 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;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    27
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    28
import java.io.PrintWriter;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    29
import java.util.ArrayList;
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
    30
import java.util.Arrays;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    31
import java.util.Collections;
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents: 16168
diff changeset
    32
import java.util.Comparator;
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
    33
import java.util.LinkedHashMap;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    34
import java.util.List;
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
    35
import java.util.Map;
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
    36
import jdk.nashorn.internal.codegen.Label;
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
    37
import jdk.nashorn.internal.ir.annotations.Immutable;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    38
import jdk.nashorn.internal.ir.visitor.NodeVisitor;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    39
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    40
/**
18867
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 17769
diff changeset
    41
 * IR representation for a list of statements.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    42
 */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
    43
@Immutable
25244
627d7e86f3b5 8047357: More precise synthetic return + unreachable throw
attila
parents: 24759
diff changeset
    44
public class Block extends Node implements BreakableNode, Terminal, Flags<Block> {
27204
06ec78f29a56 8059843: Make AST serializable
attila
parents: 27102
diff changeset
    45
    private static final long serialVersionUID = 1L;
06ec78f29a56 8059843: Make AST serializable
attila
parents: 27102
diff changeset
    46
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    47
    /** List of statements */
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: 17523
diff changeset
    48
    protected final List<Statement> statements;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    49
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
    50
    /** Symbol table - keys must be returned in the order they were put in. */
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
    51
    protected final Map<String, Symbol> symbols;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    52
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    53
    /** Entry label. */
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 19100
diff changeset
    54
    private final Label entryLabel;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    55
18867
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 17769
diff changeset
    56
    /** Break label. */
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 17769
diff changeset
    57
    private final Label breakLabel;
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 17769
diff changeset
    58
29407
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents: 28690
diff changeset
    59
    /** Does the block/function need a new scope? Is this synthetic? */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
    60
    protected final int flags;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
    61
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24738
diff changeset
    62
    /**
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24738
diff changeset
    63
     * @see JoinPredecessor
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24738
diff changeset
    64
     */
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24738
diff changeset
    65
    private final LocalVariableConversion conversion;
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24738
diff changeset
    66
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
    67
    /** Flag indicating that this block needs scope */
37732
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 36690
diff changeset
    68
    public static final int NEEDS_SCOPE        = 1 << 0;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    69
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
    70
    /**
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
    71
     * Is this block tagged as terminal based on its contents
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
    72
     * (usually the last statement)
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
    73
     */
37732
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 36690
diff changeset
    74
    public static final int IS_TERMINAL        = 1 << 2;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    75
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    76
    /**
24725
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24719
diff changeset
    77
     * Is this block the eager global scope - i.e. the original program. This isn't true for the
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24719
diff changeset
    78
     * outermost level of recompiles
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24719
diff changeset
    79
     */
37732
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 36690
diff changeset
    80
    public static final int IS_GLOBAL_SCOPE    = 1 << 3;
24725
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24719
diff changeset
    81
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24719
diff changeset
    82
    /**
29407
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents: 28690
diff changeset
    83
     * Is this block a synthetic one introduced by Parser?
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents: 28690
diff changeset
    84
     */
37732
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 36690
diff changeset
    85
    public static final int IS_SYNTHETIC       = 1 << 4;
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 36690
diff changeset
    86
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 36690
diff changeset
    87
    /**
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 36690
diff changeset
    88
     * Is this the function body block? May not be the first, if parameter list contains expressions.
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 36690
diff changeset
    89
     */
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 36690
diff changeset
    90
    public static final int IS_BODY            = 1 << 5;
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 36690
diff changeset
    91
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 36690
diff changeset
    92
    /**
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 36690
diff changeset
    93
     * Is this the parameter initialization block? If present, must be the first block, immediately wrapping the function body block.
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 36690
diff changeset
    94
     */
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 36690
diff changeset
    95
    public static final int IS_PARAMETER_BLOCK = 1 << 6;
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 36690
diff changeset
    96
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 36690
diff changeset
    97
    /**
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 36690
diff changeset
    98
     * Marks the variable declaration block for case clauses of a switch statement.
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 36690
diff changeset
    99
     */
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 36690
diff changeset
   100
    public static final int IS_SWITCH_BLOCK    = 1 << 7;
29407
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents: 28690
diff changeset
   101
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents: 28690
diff changeset
   102
    /**
47038
f57fa7f112a0 8177691: Labeled break in catch and finally works wrongly, when invoked through nashorn
sdama
parents: 37732
diff changeset
   103
     * Is this block tagged as breakable based on its contents
f57fa7f112a0 8177691: Labeled break in catch and finally works wrongly, when invoked through nashorn
sdama
parents: 37732
diff changeset
   104
     * (block having labelled break statement)
f57fa7f112a0 8177691: Labeled break in catch and finally works wrongly, when invoked through nashorn
sdama
parents: 37732
diff changeset
   105
     */
f57fa7f112a0 8177691: Labeled break in catch and finally works wrongly, when invoked through nashorn
sdama
parents: 37732
diff changeset
   106
    public static final int IS_BREAKABLE       = 1 << 8;
f57fa7f112a0 8177691: Labeled break in catch and finally works wrongly, when invoked through nashorn
sdama
parents: 37732
diff changeset
   107
f57fa7f112a0 8177691: Labeled break in catch and finally works wrongly, when invoked through nashorn
sdama
parents: 37732
diff changeset
   108
    /**
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   109
     * Constructor
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   110
     *
27102
c64b3468d51d 8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents: 26503
diff changeset
   111
     * @param token      The first token of the block
c64b3468d51d 8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents: 26503
diff changeset
   112
     * @param finish     The index of the last character
c64b3468d51d 8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents: 26503
diff changeset
   113
     * @param flags      The flags of the block
c64b3468d51d 8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents: 26503
diff changeset
   114
     * @param statements All statements in the block
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   115
     */
27102
c64b3468d51d 8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents: 26503
diff changeset
   116
    public Block(final long token, final int finish, final int flags, final Statement... statements) {
18867
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 17769
diff changeset
   117
        super(token, finish);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   118
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   119
        this.statements = Arrays.asList(statements);
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   120
        this.symbols    = new LinkedHashMap<>();
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   121
        this.entryLabel = new Label("block_entry");
18867
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 17769
diff changeset
   122
        this.breakLabel = new Label("block_break");
19100
62d400be5b44 8021244: Inconsistent stackmap with splitter threshold set very low
hannesw
parents: 19095
diff changeset
   123
        final int len = statements.length;
27102
c64b3468d51d 8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents: 26503
diff changeset
   124
        final int terminalFlags = len > 0 && statements[len - 1].hasTerminalFlags() ? IS_TERMINAL : 0;
c64b3468d51d 8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents: 26503
diff changeset
   125
        this.flags = terminalFlags | flags;
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24738
diff changeset
   126
        this.conversion = null;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   127
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   128
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   129
    /**
27102
c64b3468d51d 8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents: 26503
diff changeset
   130
     * Constructs a new block
c64b3468d51d 8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents: 26503
diff changeset
   131
     *
c64b3468d51d 8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents: 26503
diff changeset
   132
     * @param token The first token of the block
c64b3468d51d 8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents: 26503
diff changeset
   133
     * @param finish The index of the last character
c64b3468d51d 8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents: 26503
diff changeset
   134
     * @param statements All statements in the block
c64b3468d51d 8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents: 26503
diff changeset
   135
     */
c64b3468d51d 8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents: 26503
diff changeset
   136
    public Block(final long token, final int finish, final Statement...statements){
29407
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents: 28690
diff changeset
   137
        this(token, finish, IS_SYNTHETIC, statements);
27102
c64b3468d51d 8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents: 26503
diff changeset
   138
    }
c64b3468d51d 8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents: 26503
diff changeset
   139
c64b3468d51d 8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents: 26503
diff changeset
   140
    /**
c64b3468d51d 8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents: 26503
diff changeset
   141
     * Constructs a new block
c64b3468d51d 8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents: 26503
diff changeset
   142
     *
c64b3468d51d 8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents: 26503
diff changeset
   143
     * @param token The first token of the block
c64b3468d51d 8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents: 26503
diff changeset
   144
     * @param finish The index of the last character
c64b3468d51d 8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents: 26503
diff changeset
   145
     * @param statements All statements in the block
c64b3468d51d 8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents: 26503
diff changeset
   146
     */
c64b3468d51d 8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents: 26503
diff changeset
   147
    public Block(final long token, final int finish, final List<Statement> statements){
29407
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents: 28690
diff changeset
   148
        this(token, finish, IS_SYNTHETIC, statements);
27102
c64b3468d51d 8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents: 26503
diff changeset
   149
    }
c64b3468d51d 8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents: 26503
diff changeset
   150
c64b3468d51d 8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents: 26503
diff changeset
   151
    /**
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   152
     * Constructor
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   153
     *
27102
c64b3468d51d 8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents: 26503
diff changeset
   154
     * @param token      The first token of the block
c64b3468d51d 8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents: 26503
diff changeset
   155
     * @param finish     The index of the last character
c64b3468d51d 8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents: 26503
diff changeset
   156
     * @param flags      The flags of the block
c64b3468d51d 8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents: 26503
diff changeset
   157
     * @param statements All statements in the block
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   158
     */
27102
c64b3468d51d 8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents: 26503
diff changeset
   159
    public Block(final long token, final int finish, final int flags, final List<Statement> statements) {
35407
204abe4d8cbc 8147591: Revisit Collection.toArray(new T[size]) calls in nashorn and dynalink code
mhaupt
parents: 32435
diff changeset
   160
        this(token, finish, flags, statements.toArray(new Statement[0]));
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   161
    }
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   162
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   163
    private Block(final Block block, final int finish, final List<Statement> statements, final int flags, final Map<String, Symbol> symbols, final LocalVariableConversion conversion) {
27102
c64b3468d51d 8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents: 26503
diff changeset
   164
        super(block, finish);
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   165
        this.statements = statements;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   166
        this.flags      = flags;
17518
2225a4f929c0 8013477: Node.setSymbol needs to be copy on write - enable IR snapshots for recompilation based on callsite type specialization. [not enabled by default, hidden by a flag for now]
lagergren
parents: 17233
diff changeset
   167
        this.symbols    = new LinkedHashMap<>(symbols); //todo - symbols have no dependencies on any IR node and can as far as we understand it be shallow copied now
16240
e1468b33e201 8008239: Unpublicized parts of the code generator package that were only package internal.
lagergren
parents: 16234
diff changeset
   168
        this.entryLabel = new Label(block.entryLabel);
18867
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 17769
diff changeset
   169
        this.breakLabel = new Label(block.breakLabel);
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24738
diff changeset
   170
        this.conversion = conversion;
17518
2225a4f929c0 8013477: Node.setSymbol needs to be copy on write - enable IR snapshots for recompilation based on callsite type specialization. [not enabled by default, hidden by a flag for now]
lagergren
parents: 17233
diff changeset
   171
    }
2225a4f929c0 8013477: Node.setSymbol needs to be copy on write - enable IR snapshots for recompilation based on callsite type specialization. [not enabled by default, hidden by a flag for now]
lagergren
parents: 17233
diff changeset
   172
2225a4f929c0 8013477: Node.setSymbol needs to be copy on write - enable IR snapshots for recompilation based on callsite type specialization. [not enabled by default, hidden by a flag for now]
lagergren
parents: 17233
diff changeset
   173
    /**
24725
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24719
diff changeset
   174
     * Is this block the outermost eager global scope - i.e. the primordial program?
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24719
diff changeset
   175
     * Used for global anchor point for scope depth computation for recompilation code
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24719
diff changeset
   176
     * @return true if outermost eager global scope
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24719
diff changeset
   177
     */
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24719
diff changeset
   178
    public boolean isGlobalScope() {
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24719
diff changeset
   179
        return getFlag(IS_GLOBAL_SCOPE);
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24719
diff changeset
   180
    }
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24719
diff changeset
   181
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24719
diff changeset
   182
    /**
32435
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 29407
diff changeset
   183
     * Returns true if this block defines any symbols.
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 29407
diff changeset
   184
     * @return true if this block defines any symbols.
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 29407
diff changeset
   185
     */
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 29407
diff changeset
   186
    public boolean hasSymbols() {
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 29407
diff changeset
   187
        return !symbols.isEmpty();
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 29407
diff changeset
   188
    }
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 29407
diff changeset
   189
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 29407
diff changeset
   190
    /**
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 29407
diff changeset
   191
     * Replaces symbols defined in this block with different symbols. Used to ensure symbol tables are
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 29407
diff changeset
   192
     * immutable upon construction and have copy-on-write semantics. Note that this method only replaces the
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 29407
diff changeset
   193
     * symbols in the symbol table, it does not act on any contained AST nodes that might reference the symbols.
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 29407
diff changeset
   194
     * Those should be updated separately as this method is meant to be used as part of such an update pass.
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 29407
diff changeset
   195
     * @param lc the current lexical context
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 29407
diff changeset
   196
     * @param replacements the map of symbol replacements
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 29407
diff changeset
   197
     * @return a new block with replaced symbols, or this block if none of the replacements modified the symbol
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 29407
diff changeset
   198
     * table.
17518
2225a4f929c0 8013477: Node.setSymbol needs to be copy on write - enable IR snapshots for recompilation based on callsite type specialization. [not enabled by default, hidden by a flag for now]
lagergren
parents: 17233
diff changeset
   199
     */
32435
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 29407
diff changeset
   200
    public Block replaceSymbols(final LexicalContext lc, final Map<Symbol, Symbol> replacements) {
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 29407
diff changeset
   201
        if (symbols.isEmpty()) {
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 29407
diff changeset
   202
            return this;
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 29407
diff changeset
   203
        }
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 29407
diff changeset
   204
        final LinkedHashMap<String, Symbol> newSymbols = new LinkedHashMap<>(symbols);
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 29407
diff changeset
   205
        for (final Map.Entry<String, Symbol> entry: newSymbols.entrySet()) {
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 29407
diff changeset
   206
            final Symbol newSymbol = replacements.get(entry.getValue());
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 29407
diff changeset
   207
            assert newSymbol != null : "Missing replacement for " + entry.getKey();
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 29407
diff changeset
   208
            entry.setValue(newSymbol);
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 29407
diff changeset
   209
        }
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 29407
diff changeset
   210
        return Node.replaceInLexicalContext(lc, this, new Block(this, finish, statements, flags, newSymbols, conversion));
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 29407
diff changeset
   211
    }
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 29407
diff changeset
   212
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 29407
diff changeset
   213
    /**
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 29407
diff changeset
   214
     * Returns a copy of this block with a shallow copy of the symbol table.
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 29407
diff changeset
   215
     * @return a copy of this block with a shallow copy of the symbol table.
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 29407
diff changeset
   216
     */
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 29407
diff changeset
   217
    public Block copyWithNewSymbols() {
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 29407
diff changeset
   218
        return new Block(this, finish, statements, flags, new LinkedHashMap<>(symbols), conversion);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   219
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   220
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   221
    @Override
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   222
    public Node ensureUniqueLabels(final LexicalContext lc) {
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24738
diff changeset
   223
        return Node.replaceInLexicalContext(lc, this, new Block(this, finish, statements, flags, symbols, conversion));
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   224
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   225
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   226
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   227
     * Assist in IR navigation.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   228
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   229
     * @param visitor IR navigating visitor.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   230
     * @return new or same node
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   231
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   232
    @Override
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
   233
    public Node accept(final LexicalContext lc, final NodeVisitor<? extends LexicalContext> visitor) {
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   234
        if (visitor.enterBlock(this)) {
25821
fbb51e67d2a7 8048869: Reduce compile time by about 5% by removing the Class.casts from the AST nodes
lagergren
parents: 25244
diff changeset
   235
            return visitor.leaveBlock(setStatements(lc, Node.accept(visitor, statements)));
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   236
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   237
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   238
        return this;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   239
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   240
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   241
    /**
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24738
diff changeset
   242
     * Get a copy of the list for all the symbols defined in this block
16523
af8b30edebce 8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents: 16240
diff changeset
   243
     * @return symbol iterator
af8b30edebce 8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents: 16240
diff changeset
   244
     */
17518
2225a4f929c0 8013477: Node.setSymbol needs to be copy on write - enable IR snapshots for recompilation based on callsite type specialization. [not enabled by default, hidden by a flag for now]
lagergren
parents: 17233
diff changeset
   245
    public List<Symbol> getSymbols() {
32435
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 29407
diff changeset
   246
        return symbols.isEmpty() ? Collections.emptyList() : Collections.unmodifiableList(new ArrayList<>(symbols.values()));
16523
af8b30edebce 8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents: 16240
diff changeset
   247
    }
af8b30edebce 8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents: 16240
diff changeset
   248
af8b30edebce 8009718: Lazy execution architecture continued - ScriptFunctionData is either final or recompilable. Moved ScriptFunctionData creation logic away from runtime to compile time. Prepared for method generation/specialization. Got rid of ScriptFunctionImplTrampoline whose semantics could be done as part of the relinking anyway. Merge with the lookup package change.
lagergren
parents: 16240
diff changeset
   249
    /**
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
   250
     * Retrieves an existing symbol defined in the current block.
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
   251
     * @param name the name of the symbol
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
   252
     * @return an existing symbol with the specified name defined in the current block, or null if this block doesn't
17518
2225a4f929c0 8013477: Node.setSymbol needs to be copy on write - enable IR snapshots for recompilation based on callsite type specialization. [not enabled by default, hidden by a flag for now]
lagergren
parents: 17233
diff changeset
   253
     * define a symbol with this name.T
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   254
     */
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
   255
    public Symbol getExistingSymbol(final String name) {
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
   256
        return symbols.get(name);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   257
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   258
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   259
    /**
49145
2854589fd853 8199236: Nashorn uses deprecated HTML tags in Javadoc
hannesw
parents: 47216
diff changeset
   260
     * Test if this block represents a <code>catch</code> block in a <code>try</code> statement.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   261
     * This is used by the Splitter as catch blocks are not be subject to splitting.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   262
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   263
     * @return true if this block represents a catch block in a try statement.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   264
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   265
    public boolean isCatchBlock() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   266
        return statements.size() == 1 && statements.get(0) instanceof CatchNode;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   267
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   268
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   269
    @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
   270
    public void toString(final StringBuilder sb, final boolean printType) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   271
        for (final Node statement : statements) {
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   272
            statement.toString(sb, printType);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   273
            sb.append(';');
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   274
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   275
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   276
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   277
    /**
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents: 16168
diff changeset
   278
     * Print symbols in block in alphabetical order, sorted on name
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents: 16168
diff changeset
   279
     * Used for debugging, see the --print-symbols flag
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   280
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   281
     * @param stream print writer to output symbols to
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   282
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   283
     * @return true if symbols were found
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   284
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   285
    public boolean printSymbols(final PrintWriter stream) {
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents: 16168
diff changeset
   286
        final List<Symbol> values = new ArrayList<>(symbols.values());
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents: 16168
diff changeset
   287
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents: 16168
diff changeset
   288
        Collections.sort(values, new Comparator<Symbol>() {
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents: 16168
diff changeset
   289
            @Override
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents: 16168
diff changeset
   290
            public int compare(final Symbol s0, final Symbol s1) {
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents: 16168
diff changeset
   291
                return s0.getName().compareTo(s1.getName());
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents: 16168
diff changeset
   292
            }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents: 16168
diff changeset
   293
        });
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   294
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   295
        for (final Symbol symbol : values) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   296
            symbol.print(stream);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   297
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   298
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   299
        return !values.isEmpty();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   300
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   301
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   302
    /**
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   303
     * Tag block as terminal or non terminal
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   304
     * @param lc          lexical context
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   305
     * @param isTerminal is block terminal
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   306
     * @return same block, or new if flag changed
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   307
     */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   308
    public Block setIsTerminal(final LexicalContext lc, final boolean isTerminal) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   309
        return isTerminal ? setFlag(lc, IS_TERMINAL) : clearFlag(lc, IS_TERMINAL);
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   310
    }
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   311
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   312
    @Override
24738
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24725
diff changeset
   313
    public int getFlags() {
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24725
diff changeset
   314
        return flags;
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24725
diff changeset
   315
    }
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24725
diff changeset
   316
25244
627d7e86f3b5 8047357: More precise synthetic return + unreachable throw
attila
parents: 24759
diff changeset
   317
    /**
627d7e86f3b5 8047357: More precise synthetic return + unreachable throw
attila
parents: 24759
diff changeset
   318
     * Is this a terminal block, i.e. does it end control flow like ending with a throw or return?
627d7e86f3b5 8047357: More precise synthetic return + unreachable throw
attila
parents: 24759
diff changeset
   319
     *
627d7e86f3b5 8047357: More precise synthetic return + unreachable throw
attila
parents: 24759
diff changeset
   320
     * @return true if this node statement is terminal
627d7e86f3b5 8047357: More precise synthetic return + unreachable throw
attila
parents: 24759
diff changeset
   321
     */
24738
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24725
diff changeset
   322
    @Override
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   323
    public boolean isTerminal() {
47038
f57fa7f112a0 8177691: Labeled break in catch and finally works wrongly, when invoked through nashorn
sdama
parents: 37732
diff changeset
   324
        return getFlag(IS_TERMINAL) && !getFlag(IS_BREAKABLE);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   325
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   326
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   327
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   328
     * Get the entry label for this block
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   329
     * @return the entry label
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   330
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   331
    public Label getEntryLabel() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   332
        return entryLabel;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   333
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   334
18867
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 17769
diff changeset
   335
    @Override
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 17769
diff changeset
   336
    public Label getBreakLabel() {
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 17769
diff changeset
   337
        return breakLabel;
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 17769
diff changeset
   338
    }
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 17769
diff changeset
   339
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24738
diff changeset
   340
    @Override
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24738
diff changeset
   341
    public Block setLocalVariableConversion(final LexicalContext lc, final LocalVariableConversion conversion) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24738
diff changeset
   342
        if(this.conversion == conversion) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24738
diff changeset
   343
            return this;
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24738
diff changeset
   344
        }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24738
diff changeset
   345
        return Node.replaceInLexicalContext(lc, this, new Block(this, finish, statements, flags, symbols, conversion));
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24738
diff changeset
   346
    }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24738
diff changeset
   347
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24738
diff changeset
   348
    @Override
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24738
diff changeset
   349
    public LocalVariableConversion getLocalVariableConversion() {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24738
diff changeset
   350
        return conversion;
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24738
diff changeset
   351
    }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24738
diff changeset
   352
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   353
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   354
     * Get the list of statements in this block
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   355
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   356
     * @return a list of statements
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   357
     */
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: 17523
diff changeset
   358
    public List<Statement> getStatements() {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   359
        return Collections.unmodifiableList(statements);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   360
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   361
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   362
    /**
26503
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 25865
diff changeset
   363
     * Returns the number of statements in the block.
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 25865
diff changeset
   364
     * @return the number of statements in the block.
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 25865
diff changeset
   365
     */
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 25865
diff changeset
   366
    public int getStatementCount() {
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 25865
diff changeset
   367
        return statements.size();
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 25865
diff changeset
   368
    }
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 25865
diff changeset
   369
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 25865
diff changeset
   370
    /**
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24738
diff changeset
   371
     * Returns the line number of the first statement in the block.
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24738
diff changeset
   372
     * @return the line number of the first statement in the block, or -1 if the block has no statements.
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24738
diff changeset
   373
     */
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24738
diff changeset
   374
    public int getFirstStatementLineNumber() {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24738
diff changeset
   375
        if(statements == null || statements.isEmpty()) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24738
diff changeset
   376
            return -1;
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24738
diff changeset
   377
        }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24738
diff changeset
   378
        return statements.get(0).getLineNumber();
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24738
diff changeset
   379
    }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24738
diff changeset
   380
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24738
diff changeset
   381
    /**
28690
78317797ab62 8067139: Finally blocks inlined incorrectly
attila
parents: 27204
diff changeset
   382
     * Returns the last statement in the block.
78317797ab62 8067139: Finally blocks inlined incorrectly
attila
parents: 27204
diff changeset
   383
     * @return the last statement in the block, or null if the block has no statements.
78317797ab62 8067139: Finally blocks inlined incorrectly
attila
parents: 27204
diff changeset
   384
     */
78317797ab62 8067139: Finally blocks inlined incorrectly
attila
parents: 27204
diff changeset
   385
    public Statement getLastStatement() {
78317797ab62 8067139: Finally blocks inlined incorrectly
attila
parents: 27204
diff changeset
   386
        return statements.isEmpty() ? null : statements.get(statements.size() - 1);
78317797ab62 8067139: Finally blocks inlined incorrectly
attila
parents: 27204
diff changeset
   387
    }
78317797ab62 8067139: Finally blocks inlined incorrectly
attila
parents: 27204
diff changeset
   388
78317797ab62 8067139: Finally blocks inlined incorrectly
attila
parents: 27204
diff changeset
   389
    /**
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   390
     * Reset the statement list for this block
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   391
     *
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   392
     * @param lc lexical context
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   393
     * @param statements new statement list
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   394
     * @return new block if statements changed, identity of statements == block.statements
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   395
     */
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: 17523
diff changeset
   396
    public Block setStatements(final LexicalContext lc, final List<Statement> statements) {
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   397
        if (this.statements == statements) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   398
            return this;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   399
        }
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   400
        int lastFinish = 0;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   401
        if (!statements.isEmpty()) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   402
            lastFinish = statements.get(statements.size() - 1).getFinish();
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   403
        }
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24738
diff changeset
   404
        return Node.replaceInLexicalContext(lc, this, new Block(this, Math.max(finish, lastFinish), statements, flags, symbols, conversion));
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   405
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   406
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   407
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   408
     * Add or overwrite an existing symbol in the block
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   409
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   410
     * @param symbol symbol
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   411
     */
32435
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 29407
diff changeset
   412
    public void putSymbol(final Symbol symbol) {
17518
2225a4f929c0 8013477: Node.setSymbol needs to be copy on write - enable IR snapshots for recompilation based on callsite type specialization. [not enabled by default, hidden by a flag for now]
lagergren
parents: 17233
diff changeset
   413
        symbols.put(symbol.getName(), symbol);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   414
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   415
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   416
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   417
     * Check whether scope is necessary for this Block
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   418
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   419
     * @return true if this function needs a scope
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   420
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   421
    public boolean needsScope() {
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   422
        return (flags & NEEDS_SCOPE) == NEEDS_SCOPE;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   423
    }
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   424
29407
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents: 28690
diff changeset
   425
    /**
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents: 28690
diff changeset
   426
     * Check whether this block is synthetic or not.
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents: 28690
diff changeset
   427
     *
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents: 28690
diff changeset
   428
     * @return true if this is a synthetic block
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents: 28690
diff changeset
   429
     */
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents: 28690
diff changeset
   430
    public boolean isSynthetic() {
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents: 28690
diff changeset
   431
        return (flags & IS_SYNTHETIC) == IS_SYNTHETIC;
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents: 28690
diff changeset
   432
    }
3fd4ede1581e 8074671: Nashorn Parser API
sundar
parents: 28690
diff changeset
   433
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   434
    @Override
24725
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24719
diff changeset
   435
    public Block setFlags(final LexicalContext lc, final int flags) {
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   436
        if (this.flags == flags) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   437
            return this;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   438
        }
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24738
diff changeset
   439
        return Node.replaceInLexicalContext(lc, this, new Block(this, finish, statements, flags, symbols, conversion));
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   440
    }
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   441
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   442
    @Override
24725
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24719
diff changeset
   443
    public Block clearFlag(final LexicalContext lc, final int flag) {
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   444
        return setFlags(lc, flags & ~flag);
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   445
    }
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   446
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   447
    @Override
24725
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24719
diff changeset
   448
    public Block setFlag(final LexicalContext lc, final int flag) {
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   449
        return setFlags(lc, flags | flag);
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   450
    }
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   451
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   452
    @Override
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   453
    public boolean getFlag(final int flag) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   454
        return (flags & flag) == flag;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   455
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   456
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   457
    /**
16168
f0c208287983 8005976: Break out AccessSpecializer into one pass before CodeGenerator instead of iterative applications from CodeGenerator
lagergren
parents: 16160
diff changeset
   458
     * Set the needs scope flag.
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   459
     * @param lc lexicalContext
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   460
     * @return new block if state changed, otherwise this
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   461
     */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   462
    public Block setNeedsScope(final LexicalContext lc) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   463
        if (needsScope()) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   464
            return this;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   465
        }
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   466
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24738
diff changeset
   467
        return Node.replaceInLexicalContext(lc, this, new Block(this, finish, statements, flags | NEEDS_SCOPE, symbols, conversion));
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   468
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   469
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
   470
    /**
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   471
     * Computationally determine the next slot for this block,
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   472
     * indexed from 0. Use this as a relative base when computing
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   473
     * frames
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   474
     * @return next slot
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
   475
     */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   476
    public int nextSlot() {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   477
        int next = 0;
17518
2225a4f929c0 8013477: Node.setSymbol needs to be copy on write - enable IR snapshots for recompilation based on callsite type specialization. [not enabled by default, hidden by a flag for now]
lagergren
parents: 17233
diff changeset
   478
        for (final Symbol symbol : getSymbols()) {
2225a4f929c0 8013477: Node.setSymbol needs to be copy on write - enable IR snapshots for recompilation based on callsite type specialization. [not enabled by default, hidden by a flag for now]
lagergren
parents: 17233
diff changeset
   479
            if (symbol.hasSlot()) {
2225a4f929c0 8013477: Node.setSymbol needs to be copy on write - enable IR snapshots for recompilation based on callsite type specialization. [not enabled by default, hidden by a flag for now]
lagergren
parents: 17233
diff changeset
   480
                next += symbol.slotCount();
2225a4f929c0 8013477: Node.setSymbol needs to be copy on write - enable IR snapshots for recompilation based on callsite type specialization. [not enabled by default, hidden by a flag for now]
lagergren
parents: 17233
diff changeset
   481
            }
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   482
        }
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   483
        return next;
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
   484
    }
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
   485
36690
06b714373aa4 8151810: for-in iteration does not provide per-iteration scope
hannesw
parents: 35407
diff changeset
   486
    /**
06b714373aa4 8151810: for-in iteration does not provide per-iteration scope
hannesw
parents: 35407
diff changeset
   487
     * Determine whether this block needs to provide its scope object creator for use by its child nodes.
06b714373aa4 8151810: for-in iteration does not provide per-iteration scope
hannesw
parents: 35407
diff changeset
   488
     * This is only necessary for synthetic parent blocks of for-in loops with lexical declarations.
06b714373aa4 8151810: for-in iteration does not provide per-iteration scope
hannesw
parents: 35407
diff changeset
   489
     *
06b714373aa4 8151810: for-in iteration does not provide per-iteration scope
hannesw
parents: 35407
diff changeset
   490
     * @see ForNode#needsScopeCreator()
06b714373aa4 8151810: for-in iteration does not provide per-iteration scope
hannesw
parents: 35407
diff changeset
   491
     * @return true if child nodes need access to this block's scope creator
06b714373aa4 8151810: for-in iteration does not provide per-iteration scope
hannesw
parents: 35407
diff changeset
   492
     */
06b714373aa4 8151810: for-in iteration does not provide per-iteration scope
hannesw
parents: 35407
diff changeset
   493
    public boolean providesScopeCreator() {
06b714373aa4 8151810: for-in iteration does not provide per-iteration scope
hannesw
parents: 35407
diff changeset
   494
        return needsScope() && isSynthetic()
06b714373aa4 8151810: for-in iteration does not provide per-iteration scope
hannesw
parents: 35407
diff changeset
   495
                && (getLastStatement() instanceof ForNode)
06b714373aa4 8151810: for-in iteration does not provide per-iteration scope
hannesw
parents: 35407
diff changeset
   496
                && ((ForNode) getLastStatement()).needsScopeCreator();
06b714373aa4 8151810: for-in iteration does not provide per-iteration scope
hannesw
parents: 35407
diff changeset
   497
    }
06b714373aa4 8151810: for-in iteration does not provide per-iteration scope
hannesw
parents: 35407
diff changeset
   498
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   499
    @Override
18867
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 17769
diff changeset
   500
    public boolean isBreakableWithoutLabel() {
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   501
        return false;
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
   502
    }
18867
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 17769
diff changeset
   503
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 17769
diff changeset
   504
    @Override
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 17769
diff changeset
   505
    public List<Label> getLabels() {
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   506
        return Collections.unmodifiableList(Arrays.asList(entryLabel, breakLabel));
18867
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 17769
diff changeset
   507
    }
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 17769
diff changeset
   508
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 17769
diff changeset
   509
    @Override
24725
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24719
diff changeset
   510
    public Node accept(final NodeVisitor<? extends LexicalContext> visitor) {
18867
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 17769
diff changeset
   511
        return Acceptor.accept(this, visitor);
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 17769
diff changeset
   512
    }
37732
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 36690
diff changeset
   513
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 36690
diff changeset
   514
    /**
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 36690
diff changeset
   515
     * Checks if this is a function body.
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 36690
diff changeset
   516
     *
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 36690
diff changeset
   517
     * @return true if the function body flag is set
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 36690
diff changeset
   518
     */
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 36690
diff changeset
   519
    public boolean isFunctionBody() {
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 36690
diff changeset
   520
        return getFlag(IS_BODY);
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 36690
diff changeset
   521
    }
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 36690
diff changeset
   522
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 36690
diff changeset
   523
    /**
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 36690
diff changeset
   524
     * Checks if this is a parameter block.
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 36690
diff changeset
   525
     *
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 36690
diff changeset
   526
     * @return true if the parameter block flag is set
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 36690
diff changeset
   527
     */
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 36690
diff changeset
   528
    public boolean isParameterBlock() {
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 36690
diff changeset
   529
        return getFlag(IS_PARAMETER_BLOCK);
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 36690
diff changeset
   530
    }
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 36690
diff changeset
   531
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 36690
diff changeset
   532
    /**
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 36690
diff changeset
   533
     * Checks whether this is a switch block.
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 36690
diff changeset
   534
     *
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 36690
diff changeset
   535
     * @return true if this is a switch block
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 36690
diff changeset
   536
     */
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 36690
diff changeset
   537
    public boolean isSwitchBlock() {
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 36690
diff changeset
   538
        return getFlag(IS_SWITCH_BLOCK);
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 36690
diff changeset
   539
    }
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   540
}