nashorn/src/jdk/nashorn/internal/codegen/Attr.java
author lagergren
Fri, 05 Jul 2013 19:35:39 +0200
changeset 18854 8dd3bfd73623
parent 18853 25ba8264b427
child 18859 7c4d0146ccd5
permissions -rw-r--r--
8019983: Void returns combined with return with expression picked the wrong return type Reviewed-by: sundar, jlaskey
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
     1
/*
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
     2
 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
     4
 *
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    10
 *
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    15
 * accompanied this code).
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    16
 *
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    20
 *
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    23
 * questions.
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    24
 */
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    25
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    26
package jdk.nashorn.internal.codegen;
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    27
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
    28
import static jdk.nashorn.internal.codegen.CompilerConstants.ARGUMENTS;
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    29
import static jdk.nashorn.internal.codegen.CompilerConstants.CALLEE;
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    30
import static jdk.nashorn.internal.codegen.CompilerConstants.EXCEPTION_PREFIX;
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    31
import static jdk.nashorn.internal.codegen.CompilerConstants.ITERATOR_PREFIX;
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: 17255
diff changeset
    32
import static jdk.nashorn.internal.codegen.CompilerConstants.LITERAL_PREFIX;
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
    33
import static jdk.nashorn.internal.codegen.CompilerConstants.RETURN;
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    34
import static jdk.nashorn.internal.codegen.CompilerConstants.SCOPE;
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    35
import static jdk.nashorn.internal.codegen.CompilerConstants.SWITCH_TAG_PREFIX;
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    36
import static jdk.nashorn.internal.codegen.CompilerConstants.THIS;
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    37
import static jdk.nashorn.internal.codegen.CompilerConstants.VARARGS;
18333
2a89c3938a00 8016235: Use in catch block that may not have been executed in try block caused illegal byte code to be generated
lagergren
parents: 18319
diff changeset
    38
import static jdk.nashorn.internal.ir.Symbol.IS_ALWAYS_DEFINED;
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: 17255
diff changeset
    39
import static jdk.nashorn.internal.ir.Symbol.IS_CONSTANT;
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
    40
import static jdk.nashorn.internal.ir.Symbol.IS_FUNCTION_SELF;
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    41
import static jdk.nashorn.internal.ir.Symbol.IS_GLOBAL;
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    42
import static jdk.nashorn.internal.ir.Symbol.IS_INTERNAL;
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    43
import static jdk.nashorn.internal.ir.Symbol.IS_LET;
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    44
import static jdk.nashorn.internal.ir.Symbol.IS_PARAM;
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
    45
import static jdk.nashorn.internal.ir.Symbol.IS_SCOPE;
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    46
import static jdk.nashorn.internal.ir.Symbol.IS_THIS;
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    47
import static jdk.nashorn.internal.ir.Symbol.IS_VAR;
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
    48
import static jdk.nashorn.internal.ir.Symbol.KINDMASK;
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    49
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
    50
import java.util.ArrayDeque;
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    51
import java.util.ArrayList;
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
    52
import java.util.Deque;
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    53
import java.util.HashSet;
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: 16262
diff changeset
    54
import java.util.Iterator;
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    55
import java.util.List;
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    56
import java.util.Set;
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    57
import jdk.nashorn.internal.codegen.types.Type;
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    58
import jdk.nashorn.internal.ir.AccessNode;
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    59
import jdk.nashorn.internal.ir.BinaryNode;
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    60
import jdk.nashorn.internal.ir.Block;
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    61
import jdk.nashorn.internal.ir.CallNode;
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    62
import jdk.nashorn.internal.ir.CaseNode;
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    63
import jdk.nashorn.internal.ir.CatchNode;
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    64
import jdk.nashorn.internal.ir.ForNode;
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    65
import jdk.nashorn.internal.ir.FunctionNode;
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
    66
import jdk.nashorn.internal.ir.FunctionNode.CompilationState;
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    67
import jdk.nashorn.internal.ir.IdentNode;
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    68
import jdk.nashorn.internal.ir.IndexNode;
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
    69
import jdk.nashorn.internal.ir.LexicalContext;
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
    70
import jdk.nashorn.internal.ir.LexicalContextNode;
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    71
import jdk.nashorn.internal.ir.LiteralNode;
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    72
import jdk.nashorn.internal.ir.LiteralNode.ArrayLiteralNode;
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    73
import jdk.nashorn.internal.ir.Node;
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    74
import jdk.nashorn.internal.ir.ObjectNode;
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    75
import jdk.nashorn.internal.ir.PropertyNode;
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    76
import jdk.nashorn.internal.ir.ReturnNode;
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    77
import jdk.nashorn.internal.ir.RuntimeNode;
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    78
import jdk.nashorn.internal.ir.RuntimeNode.Request;
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
    79
import jdk.nashorn.internal.ir.Statement;
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    80
import jdk.nashorn.internal.ir.SwitchNode;
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    81
import jdk.nashorn.internal.ir.Symbol;
17525
6582a7788183 8013912: Nashorn needs to reuse temporary symbols
attila
parents: 17524
diff changeset
    82
import jdk.nashorn.internal.ir.TemporarySymbols;
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    83
import jdk.nashorn.internal.ir.TernaryNode;
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    84
import jdk.nashorn.internal.ir.TryNode;
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    85
import jdk.nashorn.internal.ir.UnaryNode;
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    86
import jdk.nashorn.internal.ir.VarNode;
17255
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17249
diff changeset
    87
import jdk.nashorn.internal.ir.WithNode;
17970
a85557027014 8015673: Type for :e symbol is wrong
attila
parents: 17769
diff changeset
    88
import jdk.nashorn.internal.ir.visitor.NodeOperatorVisitor;
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: 17527
diff changeset
    89
import jdk.nashorn.internal.ir.visitor.NodeVisitor;
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    90
import jdk.nashorn.internal.parser.TokenType;
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    91
import jdk.nashorn.internal.runtime.Context;
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    92
import jdk.nashorn.internal.runtime.Debug;
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    93
import jdk.nashorn.internal.runtime.DebugLogger;
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    94
import jdk.nashorn.internal.runtime.JSType;
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    95
import jdk.nashorn.internal.runtime.Property;
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    96
import jdk.nashorn.internal.runtime.PropertyMap;
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    97
import jdk.nashorn.internal.runtime.ScriptObject;
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    98
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
    99
/**
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   100
 * This is the attribution pass of the code generator. Attr takes Lowered IR,
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   101
 * that is, IR where control flow has been computed and high level to low level
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   102
 * substitions for operations have been performed.
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   103
 *
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   104
 * After Attr, every symbol will have a conservative correct type.
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   105
 *
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   106
 * Any expression that requires temporary storage as part of computation will
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   107
 * also be detected here and give a temporary symbol
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   108
 *
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   109
 * Types can be narrowed after Attr by Access Specialization in FinalizeTypes,
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   110
 * but in general, this is where the main symbol type information is
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   111
 * computed.
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   112
 */
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   113
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: 17527
diff changeset
   114
final class Attr extends NodeOperatorVisitor<LexicalContext> {
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   115
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   116
    /**
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   117
     * Local definitions in current block (to discriminate from function
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   118
     * declarations always defined in the function scope. This is for
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   119
     * "can be undefined" analysis.
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   120
     */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   121
    private final Deque<Set<String>> localDefs;
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   122
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   123
    /**
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   124
     * Local definitions in current block to guard against cases like
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   125
     * NASHORN-467 when things can be undefined as they are used before
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   126
     * their local var definition. *sigh* JavaScript...
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   127
     */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   128
    private final Deque<Set<String>> localUses;
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   129
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   130
    private final Deque<Type> returnTypes;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   131
18333
2a89c3938a00 8016235: Use in catch block that may not have been executed in try block caused illegal byte code to be generated
lagergren
parents: 18319
diff changeset
   132
    private int catchNestingLevel;
2a89c3938a00 8016235: Use in catch block that may not have been executed in try block caused illegal byte code to be generated
lagergren
parents: 18319
diff changeset
   133
16233
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   134
    private static final DebugLogger LOG   = new DebugLogger("attr");
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
   135
    private static final boolean     DEBUG = LOG.isEnabled();
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   136
17525
6582a7788183 8013912: Nashorn needs to reuse temporary symbols
attila
parents: 17524
diff changeset
   137
    private final TemporarySymbols temporarySymbols;
6582a7788183 8013912: Nashorn needs to reuse temporary symbols
attila
parents: 17524
diff changeset
   138
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   139
    /**
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   140
     * Constructor.
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   141
     */
17525
6582a7788183 8013912: Nashorn needs to reuse temporary symbols
attila
parents: 17524
diff changeset
   142
    Attr(final TemporarySymbols temporarySymbols) {
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: 17527
diff changeset
   143
        super(new LexicalContext());
17525
6582a7788183 8013912: Nashorn needs to reuse temporary symbols
attila
parents: 17524
diff changeset
   144
        this.temporarySymbols = temporarySymbols;
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: 17255
diff changeset
   145
        this.localDefs   = new ArrayDeque<>();
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: 17255
diff changeset
   146
        this.localUses   = new ArrayDeque<>();
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: 17255
diff changeset
   147
        this.returnTypes = new ArrayDeque<>();
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   148
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   149
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   150
    @Override
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   151
    protected boolean enterDefault(final Node node) {
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   152
        return start(node);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   153
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   154
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   155
    @Override
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   156
    protected Node leaveDefault(final Node node) {
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   157
        return end(node);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   158
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   159
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   160
    @Override
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
   161
    public Node leaveAccessNode(final AccessNode accessNode) {
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
   162
        //While Object type is assigned here, Access Specialization in FinalizeTypes may narrow this, that
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
   163
        //is why we can't set the access node base to be an object here, that will ruin access specialization
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
   164
        //for example for a.x | 17.
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: 17255
diff changeset
   165
        return end(ensureSymbol(Type.OBJECT, accessNode));
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   166
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   167
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: 17255
diff changeset
   168
    private void initFunctionWideVariables(final FunctionNode functionNode, final Block body) {
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: 17255
diff changeset
   169
        initCompileConstant(CALLEE, body, IS_PARAM | IS_INTERNAL, FunctionNode.FUNCTION_TYPE);
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: 17255
diff changeset
   170
        initCompileConstant(THIS, body, IS_PARAM | IS_THIS, Type.OBJECT);
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   171
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   172
        if (functionNode.isVarArg()) {
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: 17255
diff changeset
   173
            initCompileConstant(VARARGS, body, IS_PARAM | IS_INTERNAL, Type.OBJECT_ARRAY);
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: 17255
diff changeset
   174
            if (functionNode.needsArguments()) {
18333
2a89c3938a00 8016235: Use in catch block that may not have been executed in try block caused illegal byte code to be generated
lagergren
parents: 18319
diff changeset
   175
                initCompileConstant(ARGUMENTS, body, IS_VAR | IS_INTERNAL | IS_ALWAYS_DEFINED, Type.typeFor(ScriptObject.class));
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: 17255
diff changeset
   176
                addLocalDef(ARGUMENTS.symbolName());
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: 17255
diff changeset
   177
            }
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
   178
        }
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
   179
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   180
        initParameters(functionNode, body);
18333
2a89c3938a00 8016235: Use in catch block that may not have been executed in try block caused illegal byte code to be generated
lagergren
parents: 18319
diff changeset
   181
        initCompileConstant(SCOPE, body, IS_VAR | IS_INTERNAL | IS_ALWAYS_DEFINED, Type.typeFor(ScriptObject.class));
2a89c3938a00 8016235: Use in catch block that may not have been executed in try block caused illegal byte code to be generated
lagergren
parents: 18319
diff changeset
   182
        initCompileConstant(RETURN, body, IS_VAR | IS_INTERNAL | IS_ALWAYS_DEFINED, Type.OBJECT);
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: 17255
diff changeset
   183
    }
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   184
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   185
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: 17255
diff changeset
   186
    /**
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: 17255
diff changeset
   187
     * This pushes all declarations (except for non-statements, i.e. for
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: 17255
diff changeset
   188
     * node temporaries) to the top of the function scope. This way we can
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: 17255
diff changeset
   189
     * get around problems like
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: 17255
diff changeset
   190
     *
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: 17255
diff changeset
   191
     * while (true) {
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: 17255
diff changeset
   192
     *   break;
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: 17255
diff changeset
   193
     *   if (true) {
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: 17255
diff changeset
   194
     *     var s;
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: 17255
diff changeset
   195
     *   }
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: 17255
diff changeset
   196
     * }
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: 17255
diff changeset
   197
     *
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: 17255
diff changeset
   198
     * to an arbitrary nesting depth.
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: 17255
diff changeset
   199
     *
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: 17255
diff changeset
   200
     * see NASHORN-73
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: 17255
diff changeset
   201
     *
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: 17255
diff changeset
   202
     * @param functionNode the FunctionNode we are entering
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: 17255
diff changeset
   203
     * @param body the body of the FunctionNode we are entering
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: 17255
diff changeset
   204
     */
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: 17255
diff changeset
   205
    private void acceptDeclarations(final FunctionNode functionNode, final Block body) {
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
   206
        // This visitor will assign symbol to all declared variables, except function declarations (which are taken care
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
   207
        // in a separate step above) and "var" declarations in for loop initializers.
18319
0e1497116130 8015892: canBeUndefined too conservative for some use before declaration cases
lagergren
parents: 17970
diff changeset
   208
        //
0e1497116130 8015892: canBeUndefined too conservative for some use before declaration cases
lagergren
parents: 17970
diff changeset
   209
        // It also handles the case that a variable can be undefined, e.g
0e1497116130 8015892: canBeUndefined too conservative for some use before declaration cases
lagergren
parents: 17970
diff changeset
   210
        // if (cond) {
0e1497116130 8015892: canBeUndefined too conservative for some use before declaration cases
lagergren
parents: 17970
diff changeset
   211
        //    x = x.y;
0e1497116130 8015892: canBeUndefined too conservative for some use before declaration cases
lagergren
parents: 17970
diff changeset
   212
        // }
0e1497116130 8015892: canBeUndefined too conservative for some use before declaration cases
lagergren
parents: 17970
diff changeset
   213
        // var x = 17;
0e1497116130 8015892: canBeUndefined too conservative for some use before declaration cases
lagergren
parents: 17970
diff changeset
   214
        //
0e1497116130 8015892: canBeUndefined too conservative for some use before declaration cases
lagergren
parents: 17970
diff changeset
   215
        // by making sure that no identifier has been found earlier in the body than the
0e1497116130 8015892: canBeUndefined too conservative for some use before declaration cases
lagergren
parents: 17970
diff changeset
   216
        // declaration - if such is the case the identifier is flagged as caBeUndefined to
0e1497116130 8015892: canBeUndefined too conservative for some use before declaration cases
lagergren
parents: 17970
diff changeset
   217
        // be safe if it turns into a local var. Otherwise corrupt bytecode results
0e1497116130 8015892: canBeUndefined too conservative for some use before declaration cases
lagergren
parents: 17970
diff changeset
   218
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: 17527
diff changeset
   219
        body.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) {
18319
0e1497116130 8015892: canBeUndefined too conservative for some use before declaration cases
lagergren
parents: 17970
diff changeset
   220
            private final Set<String> uses = new HashSet<>();
0e1497116130 8015892: canBeUndefined too conservative for some use before declaration cases
lagergren
parents: 17970
diff changeset
   221
            private final Set<String> canBeUndefined = new HashSet<>();
0e1497116130 8015892: canBeUndefined too conservative for some use before declaration cases
lagergren
parents: 17970
diff changeset
   222
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
   223
            @Override
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   224
            public boolean enterFunctionNode(final FunctionNode nestedFn) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   225
                return false;
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   226
            }
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   227
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
   228
            @Override
18319
0e1497116130 8015892: canBeUndefined too conservative for some use before declaration cases
lagergren
parents: 17970
diff changeset
   229
            public Node leaveIdentNode(final IdentNode identNode) {
0e1497116130 8015892: canBeUndefined too conservative for some use before declaration cases
lagergren
parents: 17970
diff changeset
   230
                uses.add(identNode.getName());
0e1497116130 8015892: canBeUndefined too conservative for some use before declaration cases
lagergren
parents: 17970
diff changeset
   231
                return identNode;
0e1497116130 8015892: canBeUndefined too conservative for some use before declaration cases
lagergren
parents: 17970
diff changeset
   232
            }
0e1497116130 8015892: canBeUndefined too conservative for some use before declaration cases
lagergren
parents: 17970
diff changeset
   233
0e1497116130 8015892: canBeUndefined too conservative for some use before declaration cases
lagergren
parents: 17970
diff changeset
   234
            @Override
0e1497116130 8015892: canBeUndefined too conservative for some use before declaration cases
lagergren
parents: 17970
diff changeset
   235
            public boolean enterVarNode(final VarNode varNode) {
0e1497116130 8015892: canBeUndefined too conservative for some use before declaration cases
lagergren
parents: 17970
diff changeset
   236
                final String name = varNode.getName().getName();
18842
3c3be808b593 8019585: Sometimes a var declaration using itself in its init wasn't declared as canBeUndefined, causing erroneous bytecode
lagergren
parents: 18838
diff changeset
   237
                //if this is used before the var node, the var node symbol needs to be tagged as can be undefined
18319
0e1497116130 8015892: canBeUndefined too conservative for some use before declaration cases
lagergren
parents: 17970
diff changeset
   238
                if (uses.contains(name)) {
0e1497116130 8015892: canBeUndefined too conservative for some use before declaration cases
lagergren
parents: 17970
diff changeset
   239
                    canBeUndefined.add(name);
0e1497116130 8015892: canBeUndefined too conservative for some use before declaration cases
lagergren
parents: 17970
diff changeset
   240
                }
18842
3c3be808b593 8019585: Sometimes a var declaration using itself in its init wasn't declared as canBeUndefined, causing erroneous bytecode
lagergren
parents: 18838
diff changeset
   241
3c3be808b593 8019585: Sometimes a var declaration using itself in its init wasn't declared as canBeUndefined, causing erroneous bytecode
lagergren
parents: 18838
diff changeset
   242
                // all uses of the declared varnode inside the var node are potentially undefined
3c3be808b593 8019585: Sometimes a var declaration using itself in its init wasn't declared as canBeUndefined, causing erroneous bytecode
lagergren
parents: 18838
diff changeset
   243
                // however this is a bit conservative as e.g. var x = 17; var x = 1 + x; does work
3c3be808b593 8019585: Sometimes a var declaration using itself in its init wasn't declared as canBeUndefined, causing erroneous bytecode
lagergren
parents: 18838
diff changeset
   244
                if (!varNode.isFunctionDeclaration() && varNode.getInit() != null) {
3c3be808b593 8019585: Sometimes a var declaration using itself in its init wasn't declared as canBeUndefined, causing erroneous bytecode
lagergren
parents: 18838
diff changeset
   245
                    varNode.getInit().accept(new NodeVisitor<LexicalContext>(new LexicalContext()) {
3c3be808b593 8019585: Sometimes a var declaration using itself in its init wasn't declared as canBeUndefined, causing erroneous bytecode
lagergren
parents: 18838
diff changeset
   246
                       @Override
3c3be808b593 8019585: Sometimes a var declaration using itself in its init wasn't declared as canBeUndefined, causing erroneous bytecode
lagergren
parents: 18838
diff changeset
   247
                       public boolean enterIdentNode(final IdentNode identNode) {
3c3be808b593 8019585: Sometimes a var declaration using itself in its init wasn't declared as canBeUndefined, causing erroneous bytecode
lagergren
parents: 18838
diff changeset
   248
                           if (name.equals(identNode.getName())) {
3c3be808b593 8019585: Sometimes a var declaration using itself in its init wasn't declared as canBeUndefined, causing erroneous bytecode
lagergren
parents: 18838
diff changeset
   249
                              canBeUndefined.add(name);
3c3be808b593 8019585: Sometimes a var declaration using itself in its init wasn't declared as canBeUndefined, causing erroneous bytecode
lagergren
parents: 18838
diff changeset
   250
                           }
3c3be808b593 8019585: Sometimes a var declaration using itself in its init wasn't declared as canBeUndefined, causing erroneous bytecode
lagergren
parents: 18838
diff changeset
   251
                           return false;
3c3be808b593 8019585: Sometimes a var declaration using itself in its init wasn't declared as canBeUndefined, causing erroneous bytecode
lagergren
parents: 18838
diff changeset
   252
                       }
3c3be808b593 8019585: Sometimes a var declaration using itself in its init wasn't declared as canBeUndefined, causing erroneous bytecode
lagergren
parents: 18838
diff changeset
   253
                    });
3c3be808b593 8019585: Sometimes a var declaration using itself in its init wasn't declared as canBeUndefined, causing erroneous bytecode
lagergren
parents: 18838
diff changeset
   254
                }
3c3be808b593 8019585: Sometimes a var declaration using itself in its init wasn't declared as canBeUndefined, causing erroneous bytecode
lagergren
parents: 18838
diff changeset
   255
18319
0e1497116130 8015892: canBeUndefined too conservative for some use before declaration cases
lagergren
parents: 17970
diff changeset
   256
                return true;
0e1497116130 8015892: canBeUndefined too conservative for some use before declaration cases
lagergren
parents: 17970
diff changeset
   257
            }
0e1497116130 8015892: canBeUndefined too conservative for some use before declaration cases
lagergren
parents: 17970
diff changeset
   258
0e1497116130 8015892: canBeUndefined too conservative for some use before declaration cases
lagergren
parents: 17970
diff changeset
   259
            @Override
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: 17255
diff changeset
   260
            public Node leaveVarNode(final VarNode varNode) {
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   261
                // any declared symbols that aren't visited need to be typed as well, hence the list
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   262
                if (varNode.isStatement()) {
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: 17255
diff changeset
   263
                    final IdentNode ident  = varNode.getName();
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: 17255
diff changeset
   264
                    final Symbol    symbol = defineSymbol(body, ident.getName(), IS_VAR);
18319
0e1497116130 8015892: canBeUndefined too conservative for some use before declaration cases
lagergren
parents: 17970
diff changeset
   265
                    if (canBeUndefined.contains(ident.getName())) {
0e1497116130 8015892: canBeUndefined too conservative for some use before declaration cases
lagergren
parents: 17970
diff changeset
   266
                        symbol.setType(Type.OBJECT);
0e1497116130 8015892: canBeUndefined too conservative for some use before declaration cases
lagergren
parents: 17970
diff changeset
   267
                        symbol.setCanBeUndefined();
0e1497116130 8015892: canBeUndefined too conservative for some use before declaration cases
lagergren
parents: 17970
diff changeset
   268
                    }
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   269
                    functionNode.addDeclaredSymbol(symbol);
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   270
                    if (varNode.isFunctionDeclaration()) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   271
                        newType(symbol, FunctionNode.FUNCTION_TYPE);
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   272
                    }
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: 17527
diff changeset
   273
                    return varNode.setName((IdentNode)ident.setSymbol(lc, symbol));
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
   274
                }
18842
3c3be808b593 8019585: Sometimes a var declaration using itself in its init wasn't declared as canBeUndefined, causing erroneous bytecode
lagergren
parents: 18838
diff changeset
   275
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: 17255
diff changeset
   276
                return varNode;
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   277
            }
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
   278
        });
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   279
    }
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   280
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: 17255
diff changeset
   281
    private void enterFunctionBody() {
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: 17255
diff changeset
   282
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: 17527
diff changeset
   283
        final FunctionNode functionNode = lc.getCurrentFunction();
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: 17527
diff changeset
   284
        final Block body = lc.getCurrentBlock();
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: 17255
diff changeset
   285
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: 17255
diff changeset
   286
        initFunctionWideVariables(functionNode, body);
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: 17255
diff changeset
   287
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: 17255
diff changeset
   288
        if (functionNode.isProgram()) {
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: 17255
diff changeset
   289
            initFromPropertyMap(body);
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: 17255
diff changeset
   290
        } else if (!functionNode.isDeclared()) {
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: 17255
diff changeset
   291
            // It's neither declared nor program - it's a function expression then; assign it a self-symbol.
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: 17255
diff changeset
   292
            assert functionNode.getSymbol() == null;
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: 17255
diff changeset
   293
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: 17255
diff changeset
   294
            final boolean anonymous = functionNode.isAnonymous();
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: 17255
diff changeset
   295
            final String  name      = anonymous ? null : functionNode.getIdent().getName();
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: 17255
diff changeset
   296
            if (!(anonymous || body.getExistingSymbol(name) != null)) {
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: 17255
diff changeset
   297
                assert !anonymous && name != null;
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: 17255
diff changeset
   298
                newType(defineSymbol(body, name, IS_VAR | IS_FUNCTION_SELF), Type.OBJECT);
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: 17255
diff changeset
   299
            }
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: 17255
diff changeset
   300
        }
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: 17255
diff changeset
   301
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: 17255
diff changeset
   302
        acceptDeclarations(functionNode, body);
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: 17255
diff changeset
   303
    }
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: 17255
diff changeset
   304
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   305
    @Override
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   306
    public boolean enterBlock(final Block block) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   307
        start(block);
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: 17255
diff changeset
   308
        //ensure that we don't use information from a previous compile. This is very ugly TODO
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: 17255
diff changeset
   309
        //the symbols in the block should really be stateless
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: 17255
diff changeset
   310
        block.clearSymbols();
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   311
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: 17527
diff changeset
   312
        if (lc.isFunctionBody()) {
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   313
            enterFunctionBody();
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   314
        }
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   315
        pushLocalsBlock();
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   316
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   317
        return true;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   318
    }
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   319
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   320
    @Override
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   321
    public Node leaveBlock(final Block block) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   322
        popLocals();
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   323
        return end(block);
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   324
    }
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   325
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   326
    @Override
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: 17255
diff changeset
   327
    public boolean enterCallNode(final CallNode callNode) {
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: 17255
diff changeset
   328
        return start(callNode);
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   329
    }
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   330
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   331
    @Override
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: 17255
diff changeset
   332
    public Node leaveCallNode(final CallNode callNode) {
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: 17255
diff changeset
   333
        return end(ensureSymbol(callNode.getType(), callNode));
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   334
    }
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   335
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   336
    @Override
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   337
    public boolean enterCatchNode(final CatchNode catchNode) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   338
        final IdentNode exception = catchNode.getException();
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: 17527
diff changeset
   339
        final Block     block     = lc.getCurrentBlock();
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   340
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   341
        start(catchNode);
18333
2a89c3938a00 8016235: Use in catch block that may not have been executed in try block caused illegal byte code to be generated
lagergren
parents: 18319
diff changeset
   342
        catchNestingLevel++;
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   343
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   344
        // define block-local exception variable
18853
25ba8264b427 8019819: scope symbol didn't get a slot in certain cases
attila
parents: 18849
diff changeset
   345
        final String exname = exception.getName();
25ba8264b427 8019819: scope symbol didn't get a slot in certain cases
attila
parents: 18849
diff changeset
   346
        final Symbol def = defineSymbol(block, exname, IS_VAR | IS_LET | IS_ALWAYS_DEFINED);
18333
2a89c3938a00 8016235: Use in catch block that may not have been executed in try block caused illegal byte code to be generated
lagergren
parents: 18319
diff changeset
   347
        newType(def, Type.OBJECT); //we can catch anything, not just ecma exceptions
2a89c3938a00 8016235: Use in catch block that may not have been executed in try block caused illegal byte code to be generated
lagergren
parents: 18319
diff changeset
   348
18853
25ba8264b427 8019819: scope symbol didn't get a slot in certain cases
attila
parents: 18849
diff changeset
   349
        addLocalDef(exname);
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   350
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   351
        return true;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   352
    }
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   353
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: 17255
diff changeset
   354
    @Override
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: 17255
diff changeset
   355
    public Node leaveCatchNode(final CatchNode catchNode) {
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: 17255
diff changeset
   356
        final IdentNode exception = catchNode.getException();
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: 17527
diff changeset
   357
        final Block  block        = lc.getCurrentBlock();
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: 17255
diff changeset
   358
        final Symbol symbol       = findSymbol(block, exception.getName());
18333
2a89c3938a00 8016235: Use in catch block that may not have been executed in try block caused illegal byte code to be generated
lagergren
parents: 18319
diff changeset
   359
2a89c3938a00 8016235: Use in catch block that may not have been executed in try block caused illegal byte code to be generated
lagergren
parents: 18319
diff changeset
   360
        catchNestingLevel--;
2a89c3938a00 8016235: Use in catch block that may not have been executed in try block caused illegal byte code to be generated
lagergren
parents: 18319
diff changeset
   361
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: 17255
diff changeset
   362
        assert symbol != null;
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: 17527
diff changeset
   363
        return end(catchNode.setException((IdentNode)exception.setSymbol(lc, 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: 17255
diff changeset
   364
    }
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: 17255
diff changeset
   365
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   366
    /**
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   367
     * Declare the definition of a new symbol.
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   368
     *
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   369
     * @param name         Name of symbol.
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   370
     * @param symbolFlags  Symbol flags.
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   371
     *
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   372
     * @return Symbol for given name or null for redefinition.
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   373
     */
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: 17255
diff changeset
   374
    private Symbol defineSymbol(final Block block, final String name, final int symbolFlags) {
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   375
        int    flags  = symbolFlags;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   376
        Symbol symbol = findSymbol(block, name); // Locate symbol.
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   377
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   378
        if ((flags & KINDMASK) == IS_GLOBAL) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   379
            flags |= IS_SCOPE;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   380
        }
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   381
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: 17527
diff changeset
   382
        final FunctionNode function = lc.getFunction(block);
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   383
        if (symbol != null) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   384
            // Symbol was already defined. Check if it needs to be redefined.
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   385
            if ((flags & KINDMASK) == IS_PARAM) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   386
                if (!isLocal(function, symbol)) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   387
                    // Not defined in this function. Create a new definition.
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   388
                    symbol = null;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   389
                } else if (symbol.isParam()) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   390
                    // Duplicate parameter. Null return will force an error.
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   391
                    assert false : "duplicate parameter";
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   392
                    return null;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   393
                }
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   394
            } else if ((flags & KINDMASK) == IS_VAR) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   395
                if ((flags & IS_INTERNAL) == IS_INTERNAL || (flags & IS_LET) == IS_LET) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   396
                    // Always create a new definition.
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   397
                    symbol = null;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   398
                } else {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   399
                    // Not defined in this function. Create a new definition.
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   400
                    if (!isLocal(function, symbol) || symbol.less(IS_VAR)) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   401
                        symbol = null;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   402
                    }
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   403
                }
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   404
            }
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   405
        }
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   406
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   407
        if (symbol == null) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   408
            // If not found, then create a new one.
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   409
            Block symbolBlock;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   410
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   411
            // Determine where to create it.
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   412
            if ((flags & Symbol.KINDMASK) == IS_VAR && ((flags & IS_INTERNAL) == IS_INTERNAL || (flags & IS_LET) == IS_LET)) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   413
                symbolBlock = block; //internal vars are always defined in the block closest to them
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   414
            } else {
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: 17527
diff changeset
   415
                symbolBlock = lc.getFunctionBody(function);
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   416
            }
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   417
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   418
            // Create and add to appropriate block.
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   419
            symbol = new Symbol(name, flags);
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: 17527
diff changeset
   420
            symbolBlock.putSymbol(lc, symbol);
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   421
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   422
            if ((flags & Symbol.KINDMASK) != IS_GLOBAL) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   423
                symbol.setNeedsSlot(true);
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   424
            }
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   425
        } else if (symbol.less(flags)) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   426
            symbol.setFlags(flags);
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   427
        }
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   428
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   429
        return symbol;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   430
    }
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   431
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   432
    @Override
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   433
    public boolean enterFunctionNode(final FunctionNode functionNode) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   434
        start(functionNode, false);
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   435
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: 17255
diff changeset
   436
        if (functionNode.isLazy()) {
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: 17255
diff changeset
   437
            return false;
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: 17255
diff changeset
   438
        }
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: 17255
diff changeset
   439
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: 17255
diff changeset
   440
        //an outermost function in our lexical context that is not a program (runScript)
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: 17255
diff changeset
   441
        //is possible - it is a function being compiled lazily
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   442
        if (functionNode.isDeclared()) {
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: 17527
diff changeset
   443
            final Iterator<Block> blocks = lc.getBlocks();
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   444
            if (blocks.hasNext()) {
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: 17255
diff changeset
   445
                defineSymbol(blocks.next(), functionNode.getIdent().getName(), IS_VAR);
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   446
            }
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   447
        }
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   448
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   449
        returnTypes.push(functionNode.getReturnType());
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   450
        pushLocalsFunction();
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: 17255
diff changeset
   451
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   452
        return true;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   453
    }
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   454
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   455
    @Override
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   456
    public Node leaveFunctionNode(final FunctionNode functionNode) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   457
        FunctionNode newFunctionNode = functionNode;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   458
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: 17255
diff changeset
   459
        final Block body = newFunctionNode.getBody();
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: 17255
diff changeset
   460
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: 17255
diff changeset
   461
        //look for this function in the parent block
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: 17255
diff changeset
   462
        if (functionNode.isDeclared()) {
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: 17527
diff changeset
   463
            final Iterator<Block> blocks = lc.getBlocks();
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: 17255
diff changeset
   464
            if (blocks.hasNext()) {
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: 17255
diff changeset
   465
                newFunctionNode = (FunctionNode)newFunctionNode.setSymbol(lc, findSymbol(blocks.next(), functionNode.getIdent().getName()));
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: 17255
diff changeset
   466
            }
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: 17255
diff changeset
   467
        } else if (!functionNode.isProgram()) {
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: 17255
diff changeset
   468
            final boolean anonymous = functionNode.isAnonymous();
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: 17255
diff changeset
   469
            final String  name      = anonymous ? null : functionNode.getIdent().getName();
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: 17255
diff changeset
   470
            if (anonymous || body.getExistingSymbol(name) != null) {
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: 17527
diff changeset
   471
                newFunctionNode = (FunctionNode)ensureSymbol(FunctionNode.FUNCTION_TYPE, newFunctionNode);
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: 17255
diff changeset
   472
            } else {
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: 17255
diff changeset
   473
                assert name != null;
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: 17255
diff changeset
   474
                final Symbol self = body.getExistingSymbol(name);
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: 17255
diff changeset
   475
                assert self != null && self.isFunctionSelf();
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: 17255
diff changeset
   476
                newFunctionNode = (FunctionNode)newFunctionNode.setSymbol(lc, body.getExistingSymbol(name));
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: 17255
diff changeset
   477
            }
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: 17255
diff changeset
   478
        }
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: 17255
diff changeset
   479
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   480
        //unknown parameters are promoted to object type.
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: 17255
diff changeset
   481
        newFunctionNode = finalizeParameters(newFunctionNode);
17525
6582a7788183 8013912: Nashorn needs to reuse temporary symbols
attila
parents: 17524
diff changeset
   482
        newFunctionNode = finalizeTypes(newFunctionNode);
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   483
        for (final Symbol symbol : newFunctionNode.getDeclaredSymbols()) {
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   484
            if (symbol.getSymbolType().isUnknown()) {
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   485
                symbol.setType(Type.OBJECT);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   486
                symbol.setCanBeUndefined();
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   487
            }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   488
        }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   489
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   490
        if (newFunctionNode.hasLazyChildren()) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   491
            //the final body has already been assigned as we have left the function node block body by now
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   492
            objectifySymbols(body);
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   493
        }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   494
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   495
        if (body.getFlag(Block.NEEDS_SELF_SYMBOL)) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   496
            final IdentNode callee = compilerConstant(CALLEE);
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: 17255
diff changeset
   497
            VarNode selfInit =
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   498
                new VarNode(
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
   499
                    newFunctionNode.getLineNumber(),
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   500
                    newFunctionNode.getToken(),
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   501
                    newFunctionNode.getFinish(),
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   502
                    newFunctionNode.getIdent(),
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   503
                    callee);
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   504
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   505
            LOG.info("Accepting self symbol init ", selfInit, " for ", newFunctionNode.getName());
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   506
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
   507
            final List<Statement> newStatements = new ArrayList<>();
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   508
            assert callee.getSymbol() != null && callee.getSymbol().hasSlot();
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   509
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   510
            final IdentNode name       = selfInit.getName();
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   511
            final Symbol    nameSymbol = body.getExistingSymbol(name.getName());
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   512
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   513
            assert nameSymbol != null;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   514
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: 17255
diff changeset
   515
            selfInit = selfInit.setName((IdentNode)name.setSymbol(lc, nameSymbol));
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: 17255
diff changeset
   516
            selfInit = (VarNode)selfInit.setSymbol(lc, nameSymbol);
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   517
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: 17255
diff changeset
   518
            newStatements.add(selfInit);
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   519
            newStatements.addAll(body.getStatements());
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   520
            newFunctionNode = newFunctionNode.setBody(lc, body.setStatements(lc, newStatements));
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: 16262
diff changeset
   521
        }
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: 16262
diff changeset
   522
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   523
        if (returnTypes.peek().isUnknown()) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   524
            LOG.info("Unknown return type promoted to object");
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   525
            newFunctionNode = newFunctionNode.setReturnType(lc, Type.OBJECT);
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   526
        }
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   527
        final Type returnType = returnTypes.pop();
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   528
        newFunctionNode = newFunctionNode.setReturnType(lc, returnType.isUnknown() ? Type.OBJECT : returnType);
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   529
        newFunctionNode = newFunctionNode.setState(lc, CompilationState.ATTR);
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   530
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   531
        popLocals();
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   532
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   533
        end(newFunctionNode, false);
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   534
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: 17255
diff changeset
   535
        return newFunctionNode;
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
   536
    }
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
   537
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   538
    @Override
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   539
    public Node leaveCONVERT(final UnaryNode unaryNode) {
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   540
        assert false : "There should be no convert operators in IR during Attribution";
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: 17255
diff changeset
   541
        return end(unaryNode);
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   542
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   543
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   544
    @Override
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: 17255
diff changeset
   545
    public Node leaveIdentNode(final IdentNode identNode) {
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   546
        final String name = identNode.getName();
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   547
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   548
        start(identNode);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   549
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   550
        if (identNode.isPropertyName()) {
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   551
            // assign a pseudo symbol to property name
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   552
            final Symbol pseudoSymbol = pseudoSymbol(name);
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   553
            LOG.info("IdentNode is property name -> assigning pseudo symbol ", pseudoSymbol);
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   554
            LOG.unindent();
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
   555
            return end(identNode.setSymbol(lc, pseudoSymbol));
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   556
        }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   557
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: 17255
diff changeset
   558
        final Block block = lc.getCurrentBlock();
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   559
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
   560
        Symbol symbol = findSymbol(block, name);
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   561
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   562
        //If an existing symbol with the name is found, use that otherwise, declare a new one
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   563
        if (symbol != null) {
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   564
            LOG.info("Existing symbol = ", symbol);
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   565
            if (symbol.isFunctionSelf()) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   566
                final FunctionNode functionNode = lc.getDefiningFunction(symbol);
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   567
                assert functionNode != null;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   568
                assert lc.getFunctionBody(functionNode).getExistingSymbol(CALLEE.symbolName()) != null;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   569
                lc.setFlag(functionNode.getBody(), Block.NEEDS_SELF_SYMBOL);
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   570
                newType(symbol, FunctionNode.FUNCTION_TYPE);
18333
2a89c3938a00 8016235: Use in catch block that may not have been executed in try block caused illegal byte code to be generated
lagergren
parents: 18319
diff changeset
   571
            } else if (!identNode.isInitializedHere()) {
2a89c3938a00 8016235: Use in catch block that may not have been executed in try block caused illegal byte code to be generated
lagergren
parents: 18319
diff changeset
   572
                /*
2a89c3938a00 8016235: Use in catch block that may not have been executed in try block caused illegal byte code to be generated
lagergren
parents: 18319
diff changeset
   573
                 * See NASHORN-448, JDK-8016235
2a89c3938a00 8016235: Use in catch block that may not have been executed in try block caused illegal byte code to be generated
lagergren
parents: 18319
diff changeset
   574
                 *
2a89c3938a00 8016235: Use in catch block that may not have been executed in try block caused illegal byte code to be generated
lagergren
parents: 18319
diff changeset
   575
                 * Here is a use outside the local def scope
2a89c3938a00 8016235: Use in catch block that may not have been executed in try block caused illegal byte code to be generated
lagergren
parents: 18319
diff changeset
   576
                 * the inCatch check is a conservative approach to handle things that might have only been
2a89c3938a00 8016235: Use in catch block that may not have been executed in try block caused illegal byte code to be generated
lagergren
parents: 18319
diff changeset
   577
                 * defined in the try block, but with variable declarations, which due to JavaScript rules
2a89c3938a00 8016235: Use in catch block that may not have been executed in try block caused illegal byte code to be generated
lagergren
parents: 18319
diff changeset
   578
                 * have to be lifted up into the function scope outside the try block anyway, but as the
2a89c3938a00 8016235: Use in catch block that may not have been executed in try block caused illegal byte code to be generated
lagergren
parents: 18319
diff changeset
   579
                 * flow can fault at almost any place in the try block and get us to the catch block, all we
2a89c3938a00 8016235: Use in catch block that may not have been executed in try block caused illegal byte code to be generated
lagergren
parents: 18319
diff changeset
   580
                 * know is that we have a declaration, not a definition. This can be made better and less
2a89c3938a00 8016235: Use in catch block that may not have been executed in try block caused illegal byte code to be generated
lagergren
parents: 18319
diff changeset
   581
                 * conservative once we superimpose a CFG onto the AST.
2a89c3938a00 8016235: Use in catch block that may not have been executed in try block caused illegal byte code to be generated
lagergren
parents: 18319
diff changeset
   582
                 */
2a89c3938a00 8016235: Use in catch block that may not have been executed in try block caused illegal byte code to be generated
lagergren
parents: 18319
diff changeset
   583
                if (!isLocalDef(name) || inCatch()) {
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   584
                    newType(symbol, Type.OBJECT);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   585
                    symbol.setCanBeUndefined();
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   586
                }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   587
            }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   588
17255
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17249
diff changeset
   589
            // if symbol is non-local or we're in a with block, we need to put symbol in scope (if it isn't already)
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17249
diff changeset
   590
            maybeForceScope(symbol);
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   591
        } else {
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   592
            LOG.info("No symbol exists. Declare undefined: ", 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: 17255
diff changeset
   593
            symbol = defineSymbol(block, name, IS_GLOBAL);
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   594
            // we have never seen this before, it can be undefined
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   595
            newType(symbol, Type.OBJECT); // TODO unknown -we have explicit casts anyway?
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   596
            symbol.setCanBeUndefined();
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   597
            Symbol.setSymbolIsScope(lc, symbol);
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   598
        }
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   599
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   600
        setBlockScope(name, symbol);
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   601
17525
6582a7788183 8013912: Nashorn needs to reuse temporary symbols
attila
parents: 17524
diff changeset
   602
        if (!identNode.isInitializedHere()) {
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   603
            symbol.increaseUseCount();
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   604
        }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   605
        addLocalUse(identNode.getName());
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   606
17527
6e45d9c2328c 8014329: Slim down the label stack structure in CodeGenerator
lagergren
parents: 17525
diff changeset
   607
        return end(identNode.setSymbol(lc, symbol));
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   608
    }
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   609
18333
2a89c3938a00 8016235: Use in catch block that may not have been executed in try block caused illegal byte code to be generated
lagergren
parents: 18319
diff changeset
   610
    private boolean inCatch() {
2a89c3938a00 8016235: Use in catch block that may not have been executed in try block caused illegal byte code to be generated
lagergren
parents: 18319
diff changeset
   611
        return catchNestingLevel > 0;
2a89c3938a00 8016235: Use in catch block that may not have been executed in try block caused illegal byte code to be generated
lagergren
parents: 18319
diff changeset
   612
    }
2a89c3938a00 8016235: Use in catch block that may not have been executed in try block caused illegal byte code to be generated
lagergren
parents: 18319
diff changeset
   613
17255
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17249
diff changeset
   614
    /**
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17249
diff changeset
   615
     * If the symbol isn't already a scope symbol, and it is either not local to the current function, or it is being
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17249
diff changeset
   616
     * referenced from within a with block, we force it to be a scope symbol.
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17249
diff changeset
   617
     * @param symbol the symbol that might be scoped
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17249
diff changeset
   618
     */
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17249
diff changeset
   619
    private void maybeForceScope(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: 17255
diff changeset
   620
        if (!symbol.isScope() && symbolNeedsToBeScope(symbol)) {
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: 17527
diff changeset
   621
            Symbol.setSymbolIsScope(lc, symbol);
17255
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17249
diff changeset
   622
        }
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17249
diff changeset
   623
    }
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17249
diff changeset
   624
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17249
diff changeset
   625
    private boolean symbolNeedsToBeScope(Symbol symbol) {
18333
2a89c3938a00 8016235: Use in catch block that may not have been executed in try block caused illegal byte code to be generated
lagergren
parents: 18319
diff changeset
   626
        if (symbol.isThis() || symbol.isInternal()) {
17255
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17249
diff changeset
   627
            return false;
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17249
diff changeset
   628
        }
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17249
diff changeset
   629
        boolean previousWasBlock = false;
18333
2a89c3938a00 8016235: Use in catch block that may not have been executed in try block caused illegal byte code to be generated
lagergren
parents: 18319
diff changeset
   630
        for (final Iterator<LexicalContextNode> it = lc.getAllNodes(); it.hasNext();) {
17255
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17249
diff changeset
   631
            final LexicalContextNode node = it.next();
18333
2a89c3938a00 8016235: Use in catch block that may not have been executed in try block caused illegal byte code to be generated
lagergren
parents: 18319
diff changeset
   632
            if (node instanceof FunctionNode) {
17255
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17249
diff changeset
   633
                // We reached the function boundary without seeing a definition for the symbol - it needs to be in
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17249
diff changeset
   634
                // scope.
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17249
diff changeset
   635
                return true;
18333
2a89c3938a00 8016235: Use in catch block that may not have been executed in try block caused illegal byte code to be generated
lagergren
parents: 18319
diff changeset
   636
            } else if (node instanceof WithNode) {
2a89c3938a00 8016235: Use in catch block that may not have been executed in try block caused illegal byte code to be generated
lagergren
parents: 18319
diff changeset
   637
                if (previousWasBlock) {
17255
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17249
diff changeset
   638
                    // We reached a WithNode; the symbol must be scoped. Note that if the WithNode was not immediately
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17249
diff changeset
   639
                    // preceded by a block, this means we're currently processing its expression, not its body,
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17249
diff changeset
   640
                    // therefore it doesn't count.
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17249
diff changeset
   641
                    return true;
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17249
diff changeset
   642
                }
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17249
diff changeset
   643
                previousWasBlock = false;
18333
2a89c3938a00 8016235: Use in catch block that may not have been executed in try block caused illegal byte code to be generated
lagergren
parents: 18319
diff changeset
   644
            } else if (node instanceof Block) {
2a89c3938a00 8016235: Use in catch block that may not have been executed in try block caused illegal byte code to be generated
lagergren
parents: 18319
diff changeset
   645
                if (((Block)node).getExistingSymbol(symbol.getName()) == symbol) {
17255
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17249
diff changeset
   646
                    // We reached the block that defines the symbol without reaching either the function boundary, or a
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17249
diff changeset
   647
                    // WithNode. The symbol need not be scoped.
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17249
diff changeset
   648
                    return false;
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17249
diff changeset
   649
                }
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17249
diff changeset
   650
                previousWasBlock = true;
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17249
diff changeset
   651
            } else {
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17249
diff changeset
   652
                previousWasBlock = false;
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17249
diff changeset
   653
            }
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17249
diff changeset
   654
        }
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17249
diff changeset
   655
        throw new AssertionError();
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17249
diff changeset
   656
    }
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17249
diff changeset
   657
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   658
    private void setBlockScope(final String name, final Symbol symbol) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   659
        assert symbol != null;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   660
        if (symbol.isGlobal()) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   661
            setUsesGlobalSymbol();
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   662
            return;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   663
        }
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   664
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   665
        if (symbol.isScope()) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   666
            Block scopeBlock = null;
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: 17527
diff changeset
   667
            for (final Iterator<LexicalContextNode> contextNodeIter = lc.getAllNodes(); contextNodeIter.hasNext(); ) {
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   668
                final LexicalContextNode node = contextNodeIter.next();
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   669
                if (node instanceof Block) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   670
                    if (((Block)node).getExistingSymbol(name) != null) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   671
                        scopeBlock = (Block)node;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   672
                        break;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   673
                    }
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   674
                } else if (node instanceof FunctionNode) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   675
                    lc.setFlag(node, FunctionNode.USES_ANCESTOR_SCOPE);
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   676
                }
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   677
            }
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   678
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   679
            if (scopeBlock != null) {
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: 17527
diff changeset
   680
                assert lc.contains(scopeBlock);
18853
25ba8264b427 8019819: scope symbol didn't get a slot in certain cases
attila
parents: 18849
diff changeset
   681
                lc.setBlockNeedsScope(scopeBlock);
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   682
            }
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   683
        }
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   684
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   685
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
   686
    /**
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
   687
     * Marks the current function as one using any global symbol. The function and all its parent functions will all be
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
   688
     * marked as needing parent scope.
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
   689
     * @see #needsParentScope()
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
   690
     */
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
   691
    private void setUsesGlobalSymbol() {
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: 17527
diff changeset
   692
        for (final Iterator<FunctionNode> fns = lc.getFunctions(); fns.hasNext();) {
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: 17527
diff changeset
   693
            lc.setFlag(fns.next(), FunctionNode.USES_ANCESTOR_SCOPE);
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
   694
        }
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
   695
    }
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
   696
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
   697
    /**
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
   698
     * Search for symbol in the lexical context starting from the given block.
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
   699
     * @param name Symbol name.
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
   700
     * @return Found symbol or null if not found.
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
   701
     */
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
   702
    private Symbol findSymbol(final Block block, final String name) {
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
   703
        // Search up block chain to locate symbol.
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
   704
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: 17527
diff changeset
   705
        for (final Iterator<Block> blocks = lc.getBlocks(block); blocks.hasNext();) {
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
   706
            // Find name.
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
   707
            final Symbol symbol = blocks.next().getExistingSymbol(name);
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
   708
            // If found then we are good.
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: 17255
diff changeset
   709
            if (symbol != null) {
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
   710
                return symbol;
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
   711
            }
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
   712
        }
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
   713
        return null;
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
   714
    }
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
   715
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   716
    @Override
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
   717
    public Node leaveIndexNode(final IndexNode indexNode) {
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: 17255
diff changeset
   718
        return end(ensureSymbol(Type.OBJECT, indexNode));
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   719
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   720
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   721
    @SuppressWarnings("rawtypes")
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   722
    @Override
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: 17255
diff changeset
   723
    public Node leaveLiteralNode(final LiteralNode literalNode) {
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: 17255
diff changeset
   724
        assert !literalNode.isTokenType(TokenType.THIS) : "tokentype for " + literalNode + " is this"; //guard against old dead code case. literal nodes should never inherit tokens
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: 17255
diff changeset
   725
        assert literalNode instanceof ArrayLiteralNode || !(literalNode.getValue() instanceof Node) : "literals with Node values not supported";
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: 17527
diff changeset
   726
        final Symbol symbol = new Symbol(lc.getCurrentFunction().uniqueName(LITERAL_PREFIX.symbolName()), IS_CONSTANT, literalNode.getType());
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: 17255
diff changeset
   727
        if (literalNode instanceof ArrayLiteralNode) {
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: 17255
diff changeset
   728
            ((ArrayLiteralNode)literalNode).analyze();
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   729
        }
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: 17527
diff changeset
   730
        return end(literalNode.setSymbol(lc, symbol));
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   731
    }
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   732
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   733
    @Override
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   734
    public boolean enterObjectNode(final ObjectNode objectNode) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   735
        return start(objectNode);
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   736
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   737
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   738
    @Override
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
   739
    public Node leaveObjectNode(final ObjectNode objectNode) {
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: 17255
diff changeset
   740
        return end(ensureSymbol(Type.OBJECT, objectNode));
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   741
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   742
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   743
    @Override
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: 17255
diff changeset
   744
    public Node leavePropertyNode(final PropertyNode propertyNode) {
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   745
        // assign a pseudo symbol to property name, see NASHORN-710
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: 17527
diff changeset
   746
        return propertyNode.setSymbol(lc, new Symbol(propertyNode.getKeyName(), 0, Type.OBJECT));
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   747
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   748
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   749
    @Override
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
   750
    public Node leaveReturnNode(final ReturnNode returnNode) {
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   751
        final Node expr = returnNode.getExpression();
18854
8dd3bfd73623 8019983: Void returns combined with return with expression picked the wrong return type
lagergren
parents: 18853
diff changeset
   752
        final Type returnType;
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   753
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   754
        if (expr != null) {
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   755
            //we can't do parameter specialization if we return something that hasn't been typed yet
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   756
            final Symbol symbol = expr.getSymbol();
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   757
            if (expr.getType().isUnknown() && symbol.isParam()) {
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   758
                symbol.setType(Type.OBJECT);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   759
            }
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   760
18854
8dd3bfd73623 8019983: Void returns combined with return with expression picked the wrong return type
lagergren
parents: 18853
diff changeset
   761
            returnType = Type.widest(returnTypes.pop(), symbol.getSymbolType());
8dd3bfd73623 8019983: Void returns combined with return with expression picked the wrong return type
lagergren
parents: 18853
diff changeset
   762
        } else {
8dd3bfd73623 8019983: Void returns combined with return with expression picked the wrong return type
lagergren
parents: 18853
diff changeset
   763
            returnType = Type.OBJECT; //undefined
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   764
        }
18854
8dd3bfd73623 8019983: Void returns combined with return with expression picked the wrong return type
lagergren
parents: 18853
diff changeset
   765
        LOG.info("Returntype is now ", returnType);
8dd3bfd73623 8019983: Void returns combined with return with expression picked the wrong return type
lagergren
parents: 18853
diff changeset
   766
        returnTypes.push(returnType);
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   767
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   768
        end(returnNode);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   769
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   770
        return returnNode;
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   771
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   772
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   773
    @Override
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
   774
    public Node leaveSwitchNode(final SwitchNode switchNode) {
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   775
        Type type = Type.UNKNOWN;
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   776
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   777
        final List<CaseNode> newCases = new ArrayList<>();
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   778
        for (final CaseNode caseNode : switchNode.getCases()) {
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   779
            final Node test = caseNode.getTest();
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   780
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   781
            CaseNode newCaseNode = caseNode;
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   782
            if (test != null) {
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   783
                if (test instanceof LiteralNode) {
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   784
                    //go down to integers if we can
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   785
                    final LiteralNode<?> lit = (LiteralNode<?>)test;
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   786
                    if (lit.isNumeric() && !(lit.getValue() instanceof Integer)) {
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   787
                        if (JSType.isRepresentableAsInt(lit.getNumber())) {
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   788
                            newCaseNode = caseNode.setTest(LiteralNode.newInstance(lit, lit.getInt32()).accept(this));
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   789
                        }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   790
                    }
16235
cc200fdc3478 8008206: The allInteger case for SwitchNode generation in CodeGenerator assumes integer LITERALS only.
lagergren
parents: 16233
diff changeset
   791
                } else {
cc200fdc3478 8008206: The allInteger case for SwitchNode generation in CodeGenerator assumes integer LITERALS only.
lagergren
parents: 16233
diff changeset
   792
                    // the "all integer" case that CodeGenerator optimizes for currently assumes literals only
cc200fdc3478 8008206: The allInteger case for SwitchNode generation in CodeGenerator assumes integer LITERALS only.
lagergren
parents: 16233
diff changeset
   793
                    type = Type.OBJECT;
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   794
                }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   795
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   796
                type = Type.widest(type, newCaseNode.getTest().getType());
18849
858863c43d1d 8019821: allInteger switches were confused by boolean cases, as they are a narrower type than int
lagergren
parents: 18842
diff changeset
   797
                if (type.isBoolean()) {
858863c43d1d 8019821: allInteger switches were confused by boolean cases, as they are a narrower type than int
lagergren
parents: 18842
diff changeset
   798
                    type = Type.OBJECT; //booleans and integers aren't assignment compatible
858863c43d1d 8019821: allInteger switches were confused by boolean cases, as they are a narrower type than int
lagergren
parents: 18842
diff changeset
   799
                }
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   800
            }
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   801
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   802
            newCases.add(newCaseNode);
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   803
        }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   804
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   805
        //only optimize for all integers
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   806
        if (!type.isInteger()) {
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   807
            type = Type.OBJECT;
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   808
        }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   809
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: 17527
diff changeset
   810
        switchNode.setTag(newInternal(lc.getCurrentFunction().uniqueName(SWITCH_TAG_PREFIX.symbolName()), type));
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   811
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   812
        end(switchNode);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   813
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: 17527
diff changeset
   814
        return switchNode.setCases(lc, newCases);
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   815
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   816
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   817
    @Override
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
   818
    public Node leaveTryNode(final TryNode tryNode) {
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   819
        tryNode.setException(exceptionSymbol());
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   820
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   821
        if (tryNode.getFinallyBody() != null) {
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   822
            tryNode.setFinallyCatchAll(exceptionSymbol());
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   823
        }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   824
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   825
        end(tryNode);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   826
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   827
        return tryNode;
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   828
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   829
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   830
    @Override
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   831
    public boolean enterVarNode(final VarNode varNode) {
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   832
        start(varNode);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   833
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   834
        final IdentNode ident = varNode.getName();
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   835
        final String    name  = ident.getName();
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   836
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: 17527
diff changeset
   837
        final Symbol symbol = defineSymbol(lc.getCurrentBlock(), name, IS_VAR);
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   838
        assert symbol != null;
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   839
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   840
        // NASHORN-467 - use before definition of vars - conservative
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   841
        if (isLocalUse(ident.getName())) {
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   842
            newType(symbol, Type.OBJECT);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   843
            symbol.setCanBeUndefined();
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   844
        }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   845
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   846
        return true;
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   847
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   848
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   849
    @Override
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
   850
    public Node leaveVarNode(final VarNode varNode) {
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: 17255
diff changeset
   851
        VarNode newVarNode = varNode;
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: 17255
diff changeset
   852
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: 17255
diff changeset
   853
        final Node      init  = newVarNode.getInit();
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: 17255
diff changeset
   854
        final IdentNode ident = newVarNode.getName();
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   855
        final String    name  = ident.getName();
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   856
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
   857
        final Symbol  symbol = findSymbol(lc.getCurrentBlock(), ident.getName());
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
   858
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   859
        if (init == null) {
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   860
            // var x; with no init will be treated like a use of x by
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: 17255
diff changeset
   861
            // leaveIdentNode unless we remove the name from the localdef list.
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   862
            removeLocalDef(name);
17525
6582a7788183 8013912: Nashorn needs to reuse temporary symbols
attila
parents: 17524
diff changeset
   863
            return end(newVarNode.setSymbol(lc, symbol));
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   864
        }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   865
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
   866
        addLocalDef(name);
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
   867
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: 17255
diff changeset
   868
        assert symbol != null;
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: 17255
diff changeset
   869
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: 17255
diff changeset
   870
        final IdentNode newIdent = (IdentNode)ident.setSymbol(lc, symbol);
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: 17255
diff changeset
   871
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: 17255
diff changeset
   872
        newVarNode = newVarNode.setName(newIdent);
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: 17255
diff changeset
   873
        newVarNode = (VarNode)newVarNode.setSymbol(lc, symbol);
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: 17255
diff changeset
   874
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: 17255
diff changeset
   875
        final boolean isScript = lc.getDefiningFunction(symbol).isProgram(); //see NASHORN-56
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   876
        if ((init.getType().isNumeric() || init.getType().isBoolean()) && !isScript) {
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   877
            // Forbid integers as local vars for now as we have no way to treat them as undefined
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   878
            newType(symbol, init.getType());
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   879
        } else {
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   880
            newType(symbol, Type.OBJECT);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   881
        }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   882
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: 17255
diff changeset
   883
        assert newVarNode.hasType() : newVarNode + " has no type";
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   884
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: 17255
diff changeset
   885
        return end(newVarNode);
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   886
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   887
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   888
    @Override
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   889
    public Node leaveADD(final UnaryNode unaryNode) {
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: 17255
diff changeset
   890
        return end(ensureSymbol(arithType(), unaryNode));
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   891
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   892
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   893
    @Override
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   894
    public Node leaveBIT_NOT(final UnaryNode unaryNode) {
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: 17255
diff changeset
   895
        return end(ensureSymbol(Type.INT, unaryNode));
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   896
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   897
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   898
    @Override
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   899
    public Node leaveDECINC(final UnaryNode unaryNode) {
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   900
        // @see assignOffset
17525
6582a7788183 8013912: Nashorn needs to reuse temporary symbols
attila
parents: 17524
diff changeset
   901
        final UnaryNode newUnaryNode = unaryNode.setRHS(ensureAssignmentSlots(unaryNode.rhs()));
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   902
        final Type type = arithType();
17525
6582a7788183 8013912: Nashorn needs to reuse temporary symbols
attila
parents: 17524
diff changeset
   903
        newType(newUnaryNode.rhs().getSymbol(), type);
6582a7788183 8013912: Nashorn needs to reuse temporary symbols
attila
parents: 17524
diff changeset
   904
        return end(ensureSymbol(type, newUnaryNode));
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   905
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   906
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   907
    @Override
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   908
    public Node leaveDELETE(final UnaryNode unaryNode) {
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: 17527
diff changeset
   909
        final FunctionNode   currentFunctionNode = lc.getCurrentFunction();
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   910
        final boolean        strictMode          = currentFunctionNode.isStrict();
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   911
        final Node           rhs                 = unaryNode.rhs();
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   912
        final Node           strictFlagNode      = LiteralNode.newInstance(unaryNode, strictMode).accept(this);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   913
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   914
        Request request = Request.DELETE;
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   915
        final List<Node> args = new ArrayList<>();
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   916
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   917
        if (rhs instanceof IdentNode) {
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   918
            // If this is a declared variable or a function parameter, delete always fails (except for globals).
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   919
            final String name = ((IdentNode)rhs).getName();
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   920
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   921
            final boolean failDelete = strictMode || rhs.getSymbol().isParam() || (rhs.getSymbol().isVar() && !isProgramLevelSymbol(name));
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   922
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   923
            if (failDelete && rhs.getSymbol().isThis()) {
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   924
                return LiteralNode.newInstance(unaryNode, true).accept(this);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   925
            }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   926
            final Node literalNode = LiteralNode.newInstance(unaryNode, name).accept(this);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   927
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   928
            if (!failDelete) {
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   929
                args.add(compilerConstant(SCOPE));
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   930
            }
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   931
            args.add(literalNode);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   932
            args.add(strictFlagNode);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   933
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   934
            if (failDelete) {
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   935
                request = Request.FAIL_DELETE;
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   936
            }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   937
        } else if (rhs instanceof AccessNode) {
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   938
            final Node      base     = ((AccessNode)rhs).getBase();
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   939
            final IdentNode property = ((AccessNode)rhs).getProperty();
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   940
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   941
            args.add(base);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   942
            args.add(LiteralNode.newInstance(unaryNode, property.getName()).accept(this));
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   943
            args.add(strictFlagNode);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   944
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   945
        } else if (rhs instanceof IndexNode) {
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   946
            final Node base  = ((IndexNode)rhs).getBase();
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   947
            final Node index = ((IndexNode)rhs).getIndex();
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   948
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   949
            args.add(base);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   950
            args.add(index);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   951
            args.add(strictFlagNode);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   952
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   953
        } else {
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   954
            return LiteralNode.newInstance(unaryNode, true).accept(this);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   955
        }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   956
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   957
        final RuntimeNode runtimeNode = new RuntimeNode(unaryNode, request, args);
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   958
        assert runtimeNode.getSymbol() == unaryNode.getSymbol(); //unary parent constructor should do this
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   959
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
   960
        return leaveRuntimeNode(runtimeNode);
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   961
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   962
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   963
    /**
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   964
     * Is the symbol denoted by the specified name in the current lexical context defined in the program level
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   965
     * @param name the name of the symbol
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   966
     * @return true if the symbol denoted by the specified name in the current lexical context defined in the program level.
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   967
     */
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   968
    private boolean isProgramLevelSymbol(final String name) {
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: 17527
diff changeset
   969
        for(final Iterator<Block> it = lc.getBlocks(); it.hasNext();) {
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   970
            final Block next = it.next();
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   971
            if(next.getExistingSymbol(name) != null) {
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: 17527
diff changeset
   972
                return next == lc.getFunctionBody(lc.getOutermostFunction());
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   973
            }
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   974
        }
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   975
        throw new AssertionError("Couldn't find symbol " + name + " in the context");
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   976
    }
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   977
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   978
    @Override
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   979
    public Node leaveNEW(final UnaryNode unaryNode) {
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: 17255
diff changeset
   980
        return end(ensureSymbol(Type.OBJECT, unaryNode));
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   981
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   982
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   983
    @Override
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   984
    public Node leaveNOT(final UnaryNode unaryNode) {
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: 17255
diff changeset
   985
        return end(ensureSymbol(Type.BOOLEAN, unaryNode));
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   986
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
   987
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   988
    private IdentNode compilerConstant(CompilerConstants cc) {
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: 17527
diff changeset
   989
        final FunctionNode functionNode = lc.getCurrentFunction();
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: 17255
diff changeset
   990
        return (IdentNode)
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: 17255
diff changeset
   991
            new IdentNode(
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: 17255
diff changeset
   992
                functionNode.getToken(),
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: 17255
diff changeset
   993
                functionNode.getFinish(),
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: 17255
diff changeset
   994
                cc.symbolName()).
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: 17255
diff changeset
   995
                setSymbol(
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: 17527
diff changeset
   996
                    lc,
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: 17255
diff changeset
   997
                    functionNode.compilerConstant(cc));
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   998
    }
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
   999
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1000
    @Override
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1001
    public Node leaveTYPEOF(final UnaryNode unaryNode) {
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
  1002
        final Node rhs = unaryNode.rhs();
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1003
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1004
        List<Node> args = new ArrayList<>();
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1005
        if (rhs instanceof IdentNode && !rhs.getSymbol().isParam() && !rhs.getSymbol().isVar()) {
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
  1006
            args.add(compilerConstant(SCOPE));
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1007
            args.add(LiteralNode.newInstance(rhs, ((IdentNode)rhs).getName()).accept(this)); //null
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1008
        } else {
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1009
            args.add(rhs);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1010
            args.add(LiteralNode.newInstance(unaryNode).accept(this)); //null, do not reuse token of identifier rhs, it can be e.g. 'this'
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1011
        }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1012
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
  1013
        RuntimeNode runtimeNode = new RuntimeNode(unaryNode, Request.TYPEOF, args);
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1014
        assert runtimeNode.getSymbol() == unaryNode.getSymbol();
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1015
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
  1016
        runtimeNode = (RuntimeNode)leaveRuntimeNode(runtimeNode);
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1017
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1018
        end(unaryNode);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1019
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1020
        return runtimeNode;
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1021
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1022
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1023
    @Override
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
  1024
    public Node leaveRuntimeNode(final RuntimeNode runtimeNode) {
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: 17255
diff changeset
  1025
        return end(ensureSymbol(runtimeNode.getRequest().getReturnType(), runtimeNode));
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1026
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1027
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1028
    @Override
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1029
    public Node leaveSUB(final UnaryNode unaryNode) {
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: 17255
diff changeset
  1030
        return end(ensureSymbol(arithType(), unaryNode));
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1031
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1032
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1033
    @Override
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1034
    public Node leaveVOID(final UnaryNode unaryNode) {
18838
9b46630f50aa 8019629: void operator should always evaluate to undefined
sundar
parents: 18333
diff changeset
  1035
        return end(ensureSymbol(Type.OBJECT, unaryNode));
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1036
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1037
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1038
    /**
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1039
     * Add is a special binary, as it works not only on arithmetic, but for
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1040
     * strings etc as well.
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1041
     */
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1042
    @Override
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1043
    public Node leaveADD(final BinaryNode binaryNode) {
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1044
        final Node lhs = binaryNode.lhs();
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1045
        final Node rhs = binaryNode.rhs();
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1046
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1047
        ensureTypeNotUnknown(lhs);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1048
        ensureTypeNotUnknown(rhs);
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: 17255
diff changeset
  1049
        //even if we are adding two known types, this can overflow. i.e.
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: 17255
diff changeset
  1050
        //int and number -> number.
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: 17255
diff changeset
  1051
        //int and int are also number though.
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: 17255
diff changeset
  1052
        //something and object is object
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: 17255
diff changeset
  1053
        return end(ensureSymbol(Type.widest(arithType(), Type.widest(lhs.getType(), rhs.getType())), binaryNode));
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1054
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1055
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1056
    @Override
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1057
    public Node leaveAND(final BinaryNode binaryNode) {
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: 17255
diff changeset
  1058
        return end(ensureSymbol(Type.OBJECT, binaryNode));
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1059
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1060
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1061
    /**
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1062
     * This is a helper called before an assignment.
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1063
     * @param binaryNode assignment node
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1064
     */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
  1065
    private boolean enterAssignmentNode(final BinaryNode binaryNode) {
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1066
        start(binaryNode);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1067
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1068
        final Node lhs = binaryNode.lhs();
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1069
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1070
        if (lhs instanceof IdentNode) {
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: 17527
diff changeset
  1071
            final Block     block = lc.getCurrentBlock();
17255
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17249
diff changeset
  1072
            final IdentNode ident = (IdentNode)lhs;
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17249
diff changeset
  1073
            final String    name  = ident.getName();
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1074
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
  1075
            Symbol symbol = findSymbol(block, name);
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1076
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1077
            if (symbol == null) {
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: 17255
diff changeset
  1078
                symbol = defineSymbol(block, name, IS_GLOBAL);
17255
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17249
diff changeset
  1079
            } else {
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17249
diff changeset
  1080
                maybeForceScope(symbol);
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1081
            }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1082
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1083
            addLocalDef(name);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1084
        }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1085
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
  1086
        return true;
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1087
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1088
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: 17255
diff changeset
  1089
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: 17255
diff changeset
  1090
    /**
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: 17255
diff changeset
  1091
     * This assign helper is called after an assignment, when all children of
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: 17255
diff changeset
  1092
     * the assign has been processed. It fixes the types and recursively makes
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: 17255
diff changeset
  1093
     * sure that everyhing has slots that should have them in the chain.
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: 17255
diff changeset
  1094
     *
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: 17255
diff changeset
  1095
     * @param binaryNode assignment node
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: 17255
diff changeset
  1096
     */
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: 17255
diff changeset
  1097
    private Node leaveAssignmentNode(final BinaryNode binaryNode) {
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: 17255
diff changeset
  1098
        BinaryNode newBinaryNode = binaryNode;
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: 17255
diff changeset
  1099
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: 17255
diff changeset
  1100
        final Node lhs = binaryNode.lhs();
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: 17255
diff changeset
  1101
        final Node rhs = binaryNode.rhs();
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: 17255
diff changeset
  1102
        final Type type;
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: 17255
diff changeset
  1103
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: 17255
diff changeset
  1104
        if (rhs.getType().isNumeric()) {
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: 17255
diff changeset
  1105
            type = Type.widest(binaryNode.lhs().getType(), binaryNode.rhs().getType());
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: 17255
diff changeset
  1106
        } else {
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: 17255
diff changeset
  1107
            type = Type.OBJECT; //force lhs to be an object if not numeric assignment, e.g. strings too.
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: 17255
diff changeset
  1108
        }
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: 17255
diff changeset
  1109
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: 17255
diff changeset
  1110
        newType(lhs.getSymbol(), type);
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: 17255
diff changeset
  1111
        return end(ensureSymbol(type, newBinaryNode));
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: 17255
diff changeset
  1112
    }
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: 17255
diff changeset
  1113
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
  1114
    private boolean isLocal(FunctionNode function, Symbol symbol) {
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: 17527
diff changeset
  1115
        final FunctionNode definingFn = lc.getDefiningFunction(symbol);
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
  1116
        // Temp symbols are not assigned to a block, so their defining fn is null; those can be assumed local
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
  1117
        return definingFn == null || definingFn == function;
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
  1118
    }
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
  1119
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1120
    @Override
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
  1121
    public boolean enterASSIGN(final BinaryNode binaryNode) {
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1122
        return enterAssignmentNode(binaryNode);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1123
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1124
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1125
    @Override
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1126
    public Node leaveASSIGN(final BinaryNode binaryNode) {
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1127
        return leaveAssignmentNode(binaryNode);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1128
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1129
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1130
    @Override
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
  1131
    public boolean enterASSIGN_ADD(final BinaryNode binaryNode) {
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1132
        return enterAssignmentNode(binaryNode);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1133
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1134
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1135
    @Override
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1136
    public Node leaveASSIGN_ADD(final BinaryNode binaryNode) {
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1137
        final Node lhs = binaryNode.lhs();
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1138
        final Node rhs = binaryNode.rhs();
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1139
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1140
        final Type widest = Type.widest(lhs.getType(), rhs.getType());
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1141
        //Type.NUMBER if we can't prove that the add doesn't overflow. todo
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1142
        return leaveSelfModifyingAssignmentNode(binaryNode, widest.isNumeric() ? Type.NUMBER : Type.OBJECT);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1143
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1144
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1145
    @Override
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
  1146
    public boolean enterASSIGN_BIT_AND(final BinaryNode binaryNode) {
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1147
        return enterAssignmentNode(binaryNode);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1148
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1149
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1150
    @Override
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1151
    public Node leaveASSIGN_BIT_AND(final BinaryNode binaryNode) {
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1152
        return leaveSelfModifyingAssignmentNode(binaryNode);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1153
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1154
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1155
    @Override
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
  1156
    public boolean enterASSIGN_BIT_OR(final BinaryNode binaryNode) {
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1157
        return enterAssignmentNode(binaryNode);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1158
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1159
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1160
    @Override
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1161
    public Node leaveASSIGN_BIT_OR(final BinaryNode binaryNode) {
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1162
        return leaveSelfModifyingAssignmentNode(binaryNode);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1163
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1164
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1165
    @Override
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
  1166
    public boolean enterASSIGN_BIT_XOR(final BinaryNode binaryNode) {
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1167
        return enterAssignmentNode(binaryNode);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1168
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1169
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1170
    @Override
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1171
    public Node leaveASSIGN_BIT_XOR(final BinaryNode binaryNode) {
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1172
        return leaveSelfModifyingAssignmentNode(binaryNode);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1173
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1174
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1175
    @Override
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
  1176
    public boolean enterASSIGN_DIV(final BinaryNode binaryNode) {
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1177
        return enterAssignmentNode(binaryNode);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1178
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1179
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1180
    @Override
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1181
    public Node leaveASSIGN_DIV(final BinaryNode binaryNode) {
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1182
        return leaveSelfModifyingAssignmentNode(binaryNode);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1183
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1184
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1185
    @Override
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
  1186
    public boolean enterASSIGN_MOD(final BinaryNode binaryNode) {
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1187
        return enterAssignmentNode(binaryNode);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1188
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1189
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1190
    @Override
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1191
    public Node leaveASSIGN_MOD(final BinaryNode binaryNode) {
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1192
        return leaveSelfModifyingAssignmentNode(binaryNode);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1193
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1194
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1195
    @Override
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
  1196
    public boolean enterASSIGN_MUL(final BinaryNode binaryNode) {
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1197
        return enterAssignmentNode(binaryNode);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1198
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1199
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1200
    @Override
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1201
    public Node leaveASSIGN_MUL(final BinaryNode binaryNode) {
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1202
        return leaveSelfModifyingAssignmentNode(binaryNode);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1203
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1204
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1205
    @Override
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
  1206
    public boolean enterASSIGN_SAR(final BinaryNode binaryNode) {
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1207
        return enterAssignmentNode(binaryNode);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1208
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1209
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1210
    @Override
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1211
    public Node leaveASSIGN_SAR(final BinaryNode binaryNode) {
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1212
        return leaveSelfModifyingAssignmentNode(binaryNode);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1213
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1214
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1215
    @Override
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
  1216
    public boolean enterASSIGN_SHL(final BinaryNode binaryNode) {
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1217
        return enterAssignmentNode(binaryNode);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1218
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1219
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1220
    @Override
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1221
    public Node leaveASSIGN_SHL(final BinaryNode binaryNode) {
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1222
        return leaveSelfModifyingAssignmentNode(binaryNode);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1223
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1224
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1225
    @Override
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
  1226
    public boolean enterASSIGN_SHR(final BinaryNode binaryNode) {
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1227
        return enterAssignmentNode(binaryNode);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1228
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1229
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1230
    @Override
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1231
    public Node leaveASSIGN_SHR(final BinaryNode binaryNode) {
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1232
        return leaveSelfModifyingAssignmentNode(binaryNode);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1233
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1234
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1235
    @Override
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
  1236
    public boolean enterASSIGN_SUB(final BinaryNode binaryNode) {
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1237
        return enterAssignmentNode(binaryNode);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1238
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1239
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1240
    @Override
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1241
    public Node leaveASSIGN_SUB(final BinaryNode binaryNode) {
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1242
        return leaveSelfModifyingAssignmentNode(binaryNode);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1243
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1244
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1245
    @Override
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1246
    public Node leaveBIT_AND(final BinaryNode binaryNode) {
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: 16262
diff changeset
  1247
        return end(coerce(binaryNode, Type.INT));
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1248
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1249
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1250
    @Override
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1251
    public Node leaveBIT_OR(final BinaryNode binaryNode) {
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: 16262
diff changeset
  1252
        return end(coerce(binaryNode, Type.INT));
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1253
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1254
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1255
    @Override
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1256
    public Node leaveBIT_XOR(final BinaryNode binaryNode) {
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: 16262
diff changeset
  1257
        return end(coerce(binaryNode, Type.INT));
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1258
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1259
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1260
    @Override
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1261
    public Node leaveCOMMARIGHT(final BinaryNode binaryNode) {
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: 17255
diff changeset
  1262
        return end(ensureSymbol(binaryNode.rhs().getType(), binaryNode));
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1263
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1264
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1265
    @Override
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1266
    public Node leaveCOMMALEFT(final BinaryNode binaryNode) {
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: 17255
diff changeset
  1267
        return end(ensureSymbol(binaryNode.lhs().getType(), binaryNode));
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1268
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1269
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1270
    @Override
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1271
    public Node leaveDIV(final BinaryNode binaryNode) {
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1272
        return leaveBinaryArithmetic(binaryNode);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1273
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1274
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
  1275
    private Node leaveCmp(final BinaryNode binaryNode) {
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: 17255
diff changeset
  1276
        ensureTypeNotUnknown(binaryNode.lhs());
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: 17255
diff changeset
  1277
        ensureTypeNotUnknown(binaryNode.rhs());
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1278
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: 17255
diff changeset
  1279
        return end(ensureSymbol(Type.BOOLEAN, binaryNode));
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1280
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1281
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: 16262
diff changeset
  1282
    private Node coerce(final BinaryNode binaryNode, final Type operandType, final Type destType) {
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: 16262
diff changeset
  1283
        // TODO we currently don't support changing inferred type based on uses, only on
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: 16262
diff changeset
  1284
        // definitions. we would need some additional logic. We probably want to do that
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: 16262
diff changeset
  1285
        // in the future, if e.g. a specialized method gets parameter that is only used
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: 16262
diff changeset
  1286
        // as, say, an int : function(x) { return x & 4711 }, and x is not defined in
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: 16262
diff changeset
  1287
        // the function. to make this work, uncomment the following two type inferences
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: 16262
diff changeset
  1288
        // and debug.
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: 16262
diff changeset
  1289
        //newType(binaryNode.lhs().getSymbol(), operandType);
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: 16262
diff changeset
  1290
        //newType(binaryNode.rhs().getSymbol(), operandType);
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: 17255
diff changeset
  1291
        return ensureSymbol(destType, binaryNode);
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: 16262
diff changeset
  1292
    }
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: 16262
diff changeset
  1293
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: 16262
diff changeset
  1294
    private Node coerce(final BinaryNode binaryNode, final Type type) {
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: 16262
diff changeset
  1295
        return coerce(binaryNode, type, type);
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: 16262
diff changeset
  1296
    }
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: 16262
diff changeset
  1297
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1298
    //leave a binary node and inherit the widest type of lhs , rhs
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1299
    private Node leaveBinaryArithmetic(final BinaryNode binaryNode) {
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: 16262
diff changeset
  1300
        assert !Compiler.shouldUseIntegerArithmetic();
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: 16262
diff changeset
  1301
        return end(coerce(binaryNode, Type.NUMBER));
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1302
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1303
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1304
    @Override
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1305
    public Node leaveEQ(final BinaryNode binaryNode) {
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
  1306
        return leaveCmp(binaryNode);
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1307
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1308
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1309
    @Override
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1310
    public Node leaveEQ_STRICT(final BinaryNode binaryNode) {
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
  1311
        return leaveCmp(binaryNode);
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1312
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1313
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1314
    @Override
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1315
    public Node leaveGE(final BinaryNode binaryNode) {
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
  1316
        return leaveCmp(binaryNode);
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1317
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1318
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1319
    @Override
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1320
    public Node leaveGT(final BinaryNode binaryNode) {
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
  1321
        return leaveCmp(binaryNode);
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1322
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1323
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1324
    @Override
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1325
    public Node leaveIN(final BinaryNode binaryNode) {
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
  1326
        return leaveBinaryRuntimeOperator(binaryNode, Request.IN);
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1327
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1328
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1329
    @Override
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1330
    public Node leaveINSTANCEOF(final BinaryNode binaryNode) {
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
  1331
        return leaveBinaryRuntimeOperator(binaryNode, Request.INSTANCEOF);
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
  1332
    }
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
  1333
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
  1334
    private Node leaveBinaryRuntimeOperator(final BinaryNode binaryNode, final Request request) {
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1335
        try {
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
  1336
            // Don't do a full RuntimeNode.accept, as we don't want to double-visit the binary node operands
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
  1337
            return leaveRuntimeNode(new RuntimeNode(binaryNode, request));
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1338
        } finally {
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1339
            end(binaryNode);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1340
        }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1341
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1342
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1343
    @Override
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1344
    public Node leaveLE(final BinaryNode binaryNode) {
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
  1345
        return leaveCmp(binaryNode);
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1346
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1347
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1348
    @Override
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1349
    public Node leaveLT(final BinaryNode binaryNode) {
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
  1350
        return leaveCmp(binaryNode);
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1351
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1352
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1353
    @Override
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1354
    public Node leaveMOD(final BinaryNode binaryNode) {
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1355
        return leaveBinaryArithmetic(binaryNode);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1356
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1357
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1358
    @Override
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1359
    public Node leaveMUL(final BinaryNode binaryNode) {
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1360
        return leaveBinaryArithmetic(binaryNode);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1361
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1362
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1363
    @Override
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1364
    public Node leaveNE(final BinaryNode binaryNode) {
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
  1365
        return leaveCmp(binaryNode);
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1366
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1367
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1368
    @Override
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1369
    public Node leaveNE_STRICT(final BinaryNode binaryNode) {
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
  1370
        return leaveCmp(binaryNode);
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1371
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1372
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1373
    @Override
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1374
    public Node leaveOR(final BinaryNode binaryNode) {
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: 17255
diff changeset
  1375
        return end(ensureSymbol(Type.OBJECT, binaryNode));
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1376
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1377
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1378
    @Override
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1379
    public Node leaveSAR(final BinaryNode binaryNode) {
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: 16262
diff changeset
  1380
        return end(coerce(binaryNode, Type.INT));
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1381
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1382
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1383
    @Override
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1384
    public Node leaveSHL(final BinaryNode binaryNode) {
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: 16262
diff changeset
  1385
        return end(coerce(binaryNode, Type.INT));
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1386
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1387
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1388
    @Override
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1389
    public Node leaveSHR(final BinaryNode binaryNode) {
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: 16262
diff changeset
  1390
        return end(coerce(binaryNode, Type.LONG));
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1391
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1392
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1393
    @Override
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1394
    public Node leaveSUB(final BinaryNode binaryNode) {
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1395
        return leaveBinaryArithmetic(binaryNode);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1396
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1397
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1398
    @Override
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
  1399
    public Node leaveForNode(final ForNode forNode) {
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1400
        if (forNode.isForIn()) {
17970
a85557027014 8015673: Type for :e symbol is wrong
attila
parents: 17769
diff changeset
  1401
            forNode.setIterator(newInternal(lc.getCurrentFunction().uniqueName(ITERATOR_PREFIX.symbolName()), Type.typeFor(ITERATOR_PREFIX.type()))); //NASHORN-73
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1402
            /*
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1403
             * Iterators return objects, so we need to widen the scope of the
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1404
             * init variable if it, for example, has been assigned double type
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1405
             * see NASHORN-50
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1406
             */
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1407
            newType(forNode.getInit().getSymbol(), Type.OBJECT);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1408
        }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1409
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1410
        end(forNode);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1411
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1412
        return forNode;
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1413
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1414
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1415
    @Override
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
  1416
    public Node leaveTernaryNode(final TernaryNode ternaryNode) {
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1417
        final Node lhs  = ternaryNode.rhs();
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1418
        final Node rhs  = ternaryNode.third();
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1419
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1420
        ensureTypeNotUnknown(lhs);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1421
        ensureTypeNotUnknown(rhs);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1422
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1423
        final Type type = Type.widest(lhs.getType(), rhs.getType());
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: 17255
diff changeset
  1424
        return end(ensureSymbol(type, ternaryNode));
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1425
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1426
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: 17255
diff changeset
  1427
    private void initCompileConstant(final CompilerConstants cc, final Block block, final int flags, final Type type) {
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: 17255
diff changeset
  1428
        final Symbol symbol = defineSymbol(block, cc.symbolName(), flags);
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: 17255
diff changeset
  1429
        newType(symbol, type);
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: 17255
diff changeset
  1430
        symbol.setNeedsSlot(true);
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1431
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1432
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1433
    /**
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1434
     * Initialize parameters for function node. This may require specializing
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1435
     * types if a specialization profile is known
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1436
     *
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1437
     * @param functionNode the function node
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1438
     */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
  1439
    private void initParameters(final FunctionNode functionNode, final Block body) {
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: 17255
diff changeset
  1440
        int pos = 0;
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: 16262
diff changeset
  1441
        for (final IdentNode param : functionNode.getParameters()) {
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: 16262
diff changeset
  1442
            addLocalDef(param.getName());
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: 17255
diff changeset
  1443
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: 17255
diff changeset
  1444
            final Type callSiteParamType = functionNode.getHints().getParameterType(pos);
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: 17255
diff changeset
  1445
            int flags = IS_PARAM;
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: 17255
diff changeset
  1446
            if (callSiteParamType != null) {
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: 17255
diff changeset
  1447
                LOG.info("Param ", param, " has a callsite type ", callSiteParamType, ". Using that.");
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: 17255
diff changeset
  1448
                flags |= Symbol.IS_SPECIALIZED_PARAM;
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: 17255
diff changeset
  1449
            }
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: 17255
diff changeset
  1450
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: 17255
diff changeset
  1451
            final Symbol paramSymbol = defineSymbol(body, param.getName(), flags);
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: 17255
diff changeset
  1452
            assert paramSymbol != null;
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: 17255
diff changeset
  1453
17525
6582a7788183 8013912: Nashorn needs to reuse temporary symbols
attila
parents: 17524
diff changeset
  1454
            newType(paramSymbol, callSiteParamType == null ? Type.UNKNOWN : callSiteParamType);
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1455
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: 17255
diff changeset
  1456
            LOG.info("Initialized param ", pos, "=", paramSymbol);
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: 17255
diff changeset
  1457
            pos++;
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1458
        }
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: 17255
diff changeset
  1459
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1460
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1461
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1462
    /**
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1463
     * This has to run before fix assignment types, store any type specializations for
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1464
     * paramters, then turn then to objects for the generic version of this method
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1465
     *
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1466
     * @param functionNode functionNode
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1467
     */
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: 17255
diff changeset
  1468
    private FunctionNode finalizeParameters(final FunctionNode functionNode) {
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: 17255
diff changeset
  1469
        final List<IdentNode> newParams = new ArrayList<>();
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: 16262
diff changeset
  1470
        final boolean isVarArg = functionNode.isVarArg();
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
  1471
        final int nparams = functionNode.getParameters().size();
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1472
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
  1473
        int specialize = 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: 17255
diff changeset
  1474
        int pos = 0;
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: 17255
diff changeset
  1475
        for (final IdentNode param : functionNode.getParameters()) {
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: 17255
diff changeset
  1476
            final Symbol paramSymbol = functionNode.getBody().getExistingSymbol(param.getName());
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: 17255
diff changeset
  1477
            assert paramSymbol != null;
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: 17255
diff changeset
  1478
            assert paramSymbol.isParam();
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: 17527
diff changeset
  1479
            newParams.add((IdentNode)param.setSymbol(lc, paramSymbol));
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: 16262
diff changeset
  1480
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: 16262
diff changeset
  1481
            assert paramSymbol != null;
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: 17255
diff changeset
  1482
            Type type = functionNode.getHints().getParameterType(pos);
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: 16262
diff changeset
  1483
            if (type == null) {
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: 16262
diff changeset
  1484
                type = Type.OBJECT;
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1485
            }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1486
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: 16262
diff changeset
  1487
            // if we know that a parameter is only used as a certain type throughout
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: 16262
diff changeset
  1488
            // this function, we can tell the runtime system that no matter what the
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
  1489
            // call site is, use this information:
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
  1490
            // we also need more than half of the parameters to be specializable
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
  1491
            // for the heuristic to be worth it, and we need more than one use of
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
  1492
            // the parameter to consider it, i.e. function(x) { call(x); } doens't count
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
  1493
            if (paramSymbol.getUseCount() > 1 && !paramSymbol.getSymbolType().isObject()) {
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: 17255
diff changeset
  1494
                LOG.finest("Parameter ", param, " could profit from specialization to ", paramSymbol.getSymbolType());
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
  1495
                specialize++;
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: 16262
diff changeset
  1496
            }
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1497
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: 16262
diff changeset
  1498
            newType(paramSymbol, Type.widest(type, paramSymbol.getSymbolType()));
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: 16262
diff changeset
  1499
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: 16262
diff changeset
  1500
            // parameters should not be slots for a function that uses variable arity signature
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: 16262
diff changeset
  1501
            if (isVarArg) {
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: 16262
diff changeset
  1502
                paramSymbol.setNeedsSlot(false);
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1503
            }
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: 17255
diff changeset
  1504
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: 17255
diff changeset
  1505
            pos++;
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1506
        }
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: 17255
diff changeset
  1507
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
  1508
        FunctionNode newFunctionNode = functionNode;
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
  1509
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
  1510
        if (nparams == 0 || (specialize * 2) < nparams) {
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: 17527
diff changeset
  1511
            newFunctionNode = newFunctionNode.clearSnapshot(lc);
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
  1512
        }
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
  1513
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: 17527
diff changeset
  1514
        return newFunctionNode.setParameters(lc, newParams);
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1515
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1516
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1517
    /**
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1518
     * Move any properties from a global map into the scope of this method
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
  1519
     * @param block the function node body for which to init scope vars
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1520
     */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
  1521
    private void initFromPropertyMap(final Block block) {
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1522
        // For a script, add scope symbols as defined in the property map
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1523
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1524
        final PropertyMap map = Context.getGlobalMap();
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1525
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1526
        for (final Property property : map.getProperties()) {
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1527
            final String key    = property.getKey();
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: 17255
diff changeset
  1528
            final Symbol symbol = defineSymbol(block, key, IS_GLOBAL);
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1529
            newType(symbol, Type.OBJECT);
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
  1530
            LOG.info("Added global symbol from property map ", symbol);
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1531
        }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1532
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1533
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1534
    private static void ensureTypeNotUnknown(final Node node) {
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1535
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1536
        final Symbol symbol = node.getSymbol();
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1537
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
  1538
        LOG.info("Ensure type not unknown for: ", symbol);
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1539
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1540
        /*
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1541
         * Note that not just unknowns, but params need to be blown
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1542
         * up to objects, because we can have something like
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1543
         *
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1544
         * function f(a) {
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1545
         *    var b = ~a; //b and a are inferred to be int
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1546
         *    return b;
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1547
         * }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1548
         *
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1549
         * In this case, it would be correct to say that "if you have
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1550
         * an int at the callsite, just pass it".
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1551
         *
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1552
         * However
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1553
         *
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1554
         * function f(a) {
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1555
         *    var b = ~a;      //b and a are inferred to be int
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1556
         *    return b == 17;  //b is still inferred to be int.
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1557
         * }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1558
         *
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1559
         * can be called with f("17") and if we assume that b is an
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1560
         * int and don't blow it up to an object in the comparison, we
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1561
         * are screwed. I hate JavaScript.
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1562
         *
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1563
         * This check has to be done for any operation that might take
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1564
         * objects as parameters, for example +, but not *, which is known
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1565
         * to coerce types into doubles
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1566
         */
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: 17255
diff changeset
  1567
        if (node.getType().isUnknown() || (symbol.isParam() && !symbol.isSpecializedParam())) {
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1568
            newType(symbol, Type.OBJECT);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1569
            symbol.setCanBeUndefined();
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1570
         }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1571
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1572
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1573
    private static Symbol pseudoSymbol(final String name) {
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1574
        return new Symbol(name, 0, Type.OBJECT);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1575
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1576
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1577
    private Symbol exceptionSymbol() {
17970
a85557027014 8015673: Type for :e symbol is wrong
attila
parents: 17769
diff changeset
  1578
        return newInternal(lc.getCurrentFunction().uniqueName(EXCEPTION_PREFIX.symbolName()), Type.typeFor(EXCEPTION_PREFIX.type()));
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1579
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1580
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1581
    /**
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1582
     * In an assignment, recursively make sure that there are slots for
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1583
     * everything that has to be laid out as temporary storage, which is the
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1584
     * case if we are assign-op:ing a BaseNode subclass. This has to be
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1585
     * recursive to handle things like multi dimensional arrays as lhs
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1586
     *
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1587
     * see NASHORN-258
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1588
     *
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1589
     * @param assignmentDest the destination node of the assignment, e.g. lhs for binary nodes
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1590
     */
17525
6582a7788183 8013912: Nashorn needs to reuse temporary symbols
attila
parents: 17524
diff changeset
  1591
    private Node ensureAssignmentSlots(final Node assignmentDest) {
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: 17527
diff changeset
  1592
        final LexicalContext attrLexicalContext = lc;
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: 17527
diff changeset
  1593
        return assignmentDest.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) {
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1594
            @Override
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
  1595
            public Node leaveIndexNode(final IndexNode indexNode) {
16531
8f1b0de50d07 8017010: index evaluation to a temporary location for index operator much change temporaries to slots, but never scoped vars
lagergren
parents: 16530
diff changeset
  1596
                assert indexNode.getSymbol().isTemp();
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1597
                final Node index = indexNode.getIndex();
16531
8f1b0de50d07 8017010: index evaluation to a temporary location for index operator much change temporaries to slots, but never scoped vars
lagergren
parents: 16530
diff changeset
  1598
                //only temps can be set as needing slots. the others will self resolve
8f1b0de50d07 8017010: index evaluation to a temporary location for index operator much change temporaries to slots, but never scoped vars
lagergren
parents: 16530
diff changeset
  1599
                //it is illegal to take a scope var and force it to be a slot, that breaks
17525
6582a7788183 8013912: Nashorn needs to reuse temporary symbols
attila
parents: 17524
diff changeset
  1600
                Symbol indexSymbol = index.getSymbol();
6582a7788183 8013912: Nashorn needs to reuse temporary symbols
attila
parents: 17524
diff changeset
  1601
                if (indexSymbol.isTemp() && !indexSymbol.isConstant() && !indexSymbol.hasSlot()) {
6582a7788183 8013912: Nashorn needs to reuse temporary symbols
attila
parents: 17524
diff changeset
  1602
                    if(indexSymbol.isShared()) {
6582a7788183 8013912: Nashorn needs to reuse temporary symbols
attila
parents: 17524
diff changeset
  1603
                        indexSymbol = temporarySymbols.createUnshared(indexSymbol);
6582a7788183 8013912: Nashorn needs to reuse temporary symbols
attila
parents: 17524
diff changeset
  1604
                    }
6582a7788183 8013912: Nashorn needs to reuse temporary symbols
attila
parents: 17524
diff changeset
  1605
                    indexSymbol.setNeedsSlot(true);
6582a7788183 8013912: Nashorn needs to reuse temporary symbols
attila
parents: 17524
diff changeset
  1606
                    attrLexicalContext.getCurrentBlock().putSymbol(attrLexicalContext, indexSymbol);
6582a7788183 8013912: Nashorn needs to reuse temporary symbols
attila
parents: 17524
diff changeset
  1607
                    return indexNode.setIndex(index.setSymbol(attrLexicalContext, indexSymbol));
16531
8f1b0de50d07 8017010: index evaluation to a temporary location for index operator much change temporaries to slots, but never scoped vars
lagergren
parents: 16530
diff changeset
  1608
                }
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1609
                return indexNode;
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1610
            }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1611
        });
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1612
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1613
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1614
    /**
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1615
     * Return the type that arithmetic ops should use. Until we have implemented better type
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1616
     * analysis (range based) or overflow checks that are fast enough for int arithmetic,
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1617
     * this is the number type
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1618
     * @return the arithetic type
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1619
     */
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1620
    private static Type arithType() {
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1621
        return Compiler.shouldUseIntegerArithmetic() ? Type.INT : Type.NUMBER;
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1622
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1623
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1624
    /**
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1625
     * If types have changed, we can have failed to update vars. For example
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1626
     *
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1627
     * var x = 17; //x is int
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1628
     * x = "apa";  //x is object. This will be converted fine
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1629
     *
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1630
     * @param functionNode
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1631
     */
17525
6582a7788183 8013912: Nashorn needs to reuse temporary symbols
attila
parents: 17524
diff changeset
  1632
    private FunctionNode finalizeTypes(final FunctionNode functionNode) {
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1633
        final Set<Node> changed = new HashSet<>();
17525
6582a7788183 8013912: Nashorn needs to reuse temporary symbols
attila
parents: 17524
diff changeset
  1634
        FunctionNode currentFunctionNode = functionNode;
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1635
        do {
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1636
            changed.clear();
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: 17527
diff changeset
  1637
            final FunctionNode newFunctionNode = (FunctionNode)currentFunctionNode.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) {
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1638
17525
6582a7788183 8013912: Nashorn needs to reuse temporary symbols
attila
parents: 17524
diff changeset
  1639
                private Node widen(final Node node, final Type to) {
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1640
                    if (node instanceof LiteralNode) {
17525
6582a7788183 8013912: Nashorn needs to reuse temporary symbols
attila
parents: 17524
diff changeset
  1641
                        return node;
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1642
                    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1643
                    Type from = node.getType();
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1644
                    if (!Type.areEquivalent(from, to) && Type.widest(from, to) == to) {
17525
6582a7788183 8013912: Nashorn needs to reuse temporary symbols
attila
parents: 17524
diff changeset
  1645
                        LOG.fine("Had to post pass widen '", node, "' ", Debug.id(node), " from ", node.getType(), " to ", to);
6582a7788183 8013912: Nashorn needs to reuse temporary symbols
attila
parents: 17524
diff changeset
  1646
                        Symbol symbol = node.getSymbol();
6582a7788183 8013912: Nashorn needs to reuse temporary symbols
attila
parents: 17524
diff changeset
  1647
                        if(symbol.isShared() && symbol.wouldChangeType(to)) {
6582a7788183 8013912: Nashorn needs to reuse temporary symbols
attila
parents: 17524
diff changeset
  1648
                            symbol = temporarySymbols.getTypedTemporarySymbol(to);
6582a7788183 8013912: Nashorn needs to reuse temporary symbols
attila
parents: 17524
diff changeset
  1649
                        }
6582a7788183 8013912: Nashorn needs to reuse temporary symbols
attila
parents: 17524
diff changeset
  1650
                        newType(symbol, to);
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: 17527
diff changeset
  1651
                        final Node newNode = node.setSymbol(lc, symbol);
17525
6582a7788183 8013912: Nashorn needs to reuse temporary symbols
attila
parents: 17524
diff changeset
  1652
                        changed.add(newNode);
6582a7788183 8013912: Nashorn needs to reuse temporary symbols
attila
parents: 17524
diff changeset
  1653
                        return newNode;
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1654
                    }
17525
6582a7788183 8013912: Nashorn needs to reuse temporary symbols
attila
parents: 17524
diff changeset
  1655
                    return node;
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1656
                }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1657
16233
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
  1658
                @Override
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
  1659
                public boolean enterFunctionNode(final FunctionNode node) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
  1660
                    return !node.isLazy();
16233
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
  1661
                }
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
  1662
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1663
                /**
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1664
                 * Eg.
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1665
                 *
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1666
                 * var d = 17;
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1667
                 * var e;
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1668
                 * e = d; //initially typed as int for node type, should retype as double
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1669
                 * e = object;
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1670
                 *
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1671
                 * var d = 17;
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1672
                 * var e;
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1673
                 * e -= d; //initially type number, should number remain with a final conversion supplied by Store. ugly, but the computation result of the sub is numeric
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1674
                 * e = object;
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1675
                 *
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1676
                 */
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1677
                @SuppressWarnings("fallthrough")
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1678
                @Override
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
  1679
                public Node leaveBinaryNode(final BinaryNode binaryNode) {
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1680
                    final Type widest = Type.widest(binaryNode.lhs().getType(), binaryNode.rhs().getType());
17525
6582a7788183 8013912: Nashorn needs to reuse temporary symbols
attila
parents: 17524
diff changeset
  1681
                    BinaryNode newBinaryNode = binaryNode;
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1682
                    switch (binaryNode.tokenType()) {
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1683
                    default:
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1684
                        if (!binaryNode.isAssignment() || binaryNode.isSelfModifying()) {
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1685
                            break;
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1686
                        }
17525
6582a7788183 8013912: Nashorn needs to reuse temporary symbols
attila
parents: 17524
diff changeset
  1687
                        newBinaryNode = newBinaryNode.setLHS(widen(newBinaryNode.lhs(), widest));
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1688
                    case ADD:
17525
6582a7788183 8013912: Nashorn needs to reuse temporary symbols
attila
parents: 17524
diff changeset
  1689
                        newBinaryNode = (BinaryNode)widen(newBinaryNode, widest);
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1690
                    }
17525
6582a7788183 8013912: Nashorn needs to reuse temporary symbols
attila
parents: 17524
diff changeset
  1691
                    return newBinaryNode;
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1692
                }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1693
            });
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: 17527
diff changeset
  1694
            lc.replace(currentFunctionNode, newFunctionNode);
17525
6582a7788183 8013912: Nashorn needs to reuse temporary symbols
attila
parents: 17524
diff changeset
  1695
            currentFunctionNode = newFunctionNode;
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1696
        } while (!changed.isEmpty());
17525
6582a7788183 8013912: Nashorn needs to reuse temporary symbols
attila
parents: 17524
diff changeset
  1697
        return currentFunctionNode;
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1698
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1699
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1700
    private Node leaveSelfModifyingAssignmentNode(final BinaryNode binaryNode) {
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1701
        return leaveSelfModifyingAssignmentNode(binaryNode, binaryNode.getWidestOperationType());
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1702
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1703
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1704
    private Node leaveSelfModifyingAssignmentNode(final BinaryNode binaryNode, final Type destType) {
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1705
        //e.g. for -=, Number, no wider, destType (binaryNode.getWidestOperationType())  is the coerce type
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1706
        final Node lhs = binaryNode.lhs();
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1707
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1708
        newType(lhs.getSymbol(), destType); //may not narrow if dest is already wider than destType
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: 17255
diff changeset
  1709
//        ensureSymbol(destType, binaryNode); //for OP= nodes, the node can carry a narrower types than its lhs rhs. This is perfectly fine
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1710
17525
6582a7788183 8013912: Nashorn needs to reuse temporary symbols
attila
parents: 17524
diff changeset
  1711
        return end(ensureSymbol(destType, ensureAssignmentSlots(binaryNode)));
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1712
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1713
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: 17255
diff changeset
  1714
    private Node ensureSymbol(final Type type, final Node node) {
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: 17527
diff changeset
  1715
        LOG.info("New TEMPORARY added to ", lc.getCurrentFunction().getName(), " type=", type);
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: 17527
diff changeset
  1716
        return temporarySymbols.ensureSymbol(lc, type, node);
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1717
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1718
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16523
diff changeset
  1719
    private Symbol newInternal(final String name, final Type type) {
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: 17527
diff changeset
  1720
        final Symbol iter = defineSymbol(lc.getCurrentBlock(), name, IS_VAR | IS_INTERNAL);
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1721
        iter.setType(type); // NASHORN-73
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1722
        return iter;
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1723
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1724
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1725
    private static void newType(final Symbol symbol, final Type type) {
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1726
        final Type oldType = symbol.getSymbolType();
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1727
        symbol.setType(type);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1728
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1729
        if (symbol.getSymbolType() != oldType) {
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
  1730
            LOG.info("New TYPE ", type, " for ", symbol," (was ", oldType, ")");
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1731
        }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1732
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1733
        if (symbol.isParam()) {
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1734
            symbol.setType(type);
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
  1735
            LOG.info("Param type change ", symbol);
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1736
        }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1737
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1738
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
  1739
    private void pushLocalsFunction() {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
  1740
        localDefs.push(new HashSet<String>());
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
  1741
        localUses.push(new HashSet<String>());
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
  1742
    }
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
  1743
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
  1744
    private void pushLocalsBlock() {
18333
2a89c3938a00 8016235: Use in catch block that may not have been executed in try block caused illegal byte code to be generated
lagergren
parents: 18319
diff changeset
  1745
        localDefs.push(new HashSet<>(localDefs.peek()));
2a89c3938a00 8016235: Use in catch block that may not have been executed in try block caused illegal byte code to be generated
lagergren
parents: 18319
diff changeset
  1746
        localUses.push(new HashSet<>(localUses.peek()));
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
  1747
    }
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
  1748
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
  1749
    private void popLocals() {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
  1750
        localDefs.pop();
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
  1751
        localUses.pop();
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1752
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1753
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1754
    private boolean isLocalDef(final String name) {
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
  1755
        return localDefs.peek().contains(name);
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1756
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1757
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1758
    private void addLocalDef(final String name) {
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
  1759
        LOG.info("Adding local def of symbol: '", name, "'");
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
  1760
        localDefs.peek().add(name);
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1761
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1762
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1763
    private void removeLocalDef(final String name) {
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
  1764
        LOG.info("Removing local def of symbol: '", name, "'");
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
  1765
        localDefs.peek().remove(name);
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1766
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1767
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
  1768
    private boolean isLocalUse(final String name) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
  1769
        return localUses.peek().contains(name);
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1770
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1771
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1772
    private void addLocalUse(final String name) {
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
  1773
        LOG.info("Adding local use of symbol: '", name, "'");
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
  1774
        localUses.peek().add(name);
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1775
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1776
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: 16262
diff changeset
  1777
    /**
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: 16262
diff changeset
  1778
     * Pessimistically promote all symbols in current function node to Object types
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: 16262
diff changeset
  1779
     * This is done when the function contains unevaluated black boxes such as
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: 16262
diff changeset
  1780
     * lazy sub-function nodes that have not been compiled.
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: 16262
diff changeset
  1781
     *
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
  1782
     * @param body body for the function node we are leaving
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: 16262
diff changeset
  1783
     */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
  1784
    private static void objectifySymbols(final Block body) {
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: 17527
diff changeset
  1785
        body.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) {
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: 16262
diff changeset
  1786
            private void toObject(final Block block) {
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: 17255
diff changeset
  1787
                for (final Symbol symbol : block.getSymbols()) {
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
  1788
                    if (!symbol.isTemp()) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
  1789
                        newType(symbol, Type.OBJECT);
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
  1790
                    }
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: 16262
diff changeset
  1791
                }
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: 16262
diff changeset
  1792
            }
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: 16262
diff changeset
  1793
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: 16262
diff changeset
  1794
            @Override
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
  1795
            public boolean enterBlock(final Block 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: 16262
diff changeset
  1796
                toObject(block);
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
  1797
                return true;
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: 16262
diff changeset
  1798
            }
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: 16262
diff changeset
  1799
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: 16262
diff changeset
  1800
            @Override
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
  1801
            public boolean enterFunctionNode(final FunctionNode node) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
  1802
                return false;
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: 16262
diff changeset
  1803
            }
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: 16262
diff changeset
  1804
        });
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: 16262
diff changeset
  1805
    }
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: 16262
diff changeset
  1806
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1807
    private static String name(final Node node) {
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1808
        final String cn = node.getClass().getName();
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1809
        int lastDot = cn.lastIndexOf('.');
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1810
        if (lastDot == -1) {
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1811
            return cn;
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1812
        }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1813
        return cn.substring(lastDot + 1);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1814
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1815
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
  1816
    private boolean start(final Node node) {
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1817
        return start(node, true);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1818
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1819
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
  1820
    private boolean start(final Node node, final boolean printNode) {
16233
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
  1821
        if (DEBUG) {
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
  1822
            final StringBuilder sb = new StringBuilder();
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1823
16233
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
  1824
            sb.append("[ENTER ").
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
  1825
                append(name(node)).
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
  1826
                append("] ").
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
  1827
                append(printNode ? node.toString() : "").
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
  1828
                append(" in '").
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: 17527
diff changeset
  1829
                append(lc.getCurrentFunction().getName()).
16233
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
  1830
                append("'");
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
  1831
            LOG.info(sb);
16233
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
  1832
            LOG.indent();
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
  1833
        }
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1834
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
  1835
        return true;
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1836
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1837
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1838
    private Node end(final Node node) {
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1839
        return end(node, true);
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1840
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1841
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1842
    private Node end(final Node node, final boolean printNode) {
17525
6582a7788183 8013912: Nashorn needs to reuse temporary symbols
attila
parents: 17524
diff changeset
  1843
        if(node instanceof Statement) {
6582a7788183 8013912: Nashorn needs to reuse temporary symbols
attila
parents: 17524
diff changeset
  1844
            // If we're done with a statement, all temporaries can be reused.
6582a7788183 8013912: Nashorn needs to reuse temporary symbols
attila
parents: 17524
diff changeset
  1845
            temporarySymbols.reuse();
6582a7788183 8013912: Nashorn needs to reuse temporary symbols
attila
parents: 17524
diff changeset
  1846
        }
16233
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
  1847
        if (DEBUG) {
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
  1848
            final StringBuilder sb = new StringBuilder();
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1849
16233
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
  1850
            sb.append("[LEAVE ").
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
  1851
                append(name(node)).
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
  1852
                append("] ").
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
  1853
                append(printNode ? node.toString() : "").
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
  1854
                append(" in '").
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: 17527
diff changeset
  1855
                append(lc.getCurrentFunction().getName());
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1856
16233
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
  1857
            if (node.getSymbol() == null) {
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
  1858
                sb.append(" <NO SYMBOL>");
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
  1859
            } else {
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
  1860
                sb.append(" <symbol=").append(node.getSymbol()).append('>');
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
  1861
            }
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
  1862
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16226
diff changeset
  1863
            LOG.unindent();
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16531
diff changeset
  1864
            LOG.info(sb);
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1865
        }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1866
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1867
        return node;
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1868
    }
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents:
diff changeset
  1869
}