nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/ir/FunctionNode.java
author sundar
Tue, 12 Jul 2016 21:18:13 +0530
changeset 39662 e2b36a3779b9
parent 37732 3673fec68d16
child 47040 4ed4c4eba60c
permissions -rw-r--r--
8149929: Nashorn Parser API needs to be updated for ES6 Reviewed-by: mhaupt, hannesw
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     1
/*
16151
97c1e756ae1e 8005663: Update copyright year to 2013
jlaskey
parents: 16147
diff changeset
     2
 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     4
 *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    10
 *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    15
 * accompanied this code).
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    16
 *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    20
 *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    23
 * questions.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    24
 */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    25
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    26
package jdk.nashorn.internal.ir;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    27
26067
b32ccc3a76c9 8055199: Tidy up Nashorn codebase for code standards (August 2014)
attila
parents: 26065
diff changeset
    28
import static jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor.CALLSITE_PROFILE;
b32ccc3a76c9 8055199: Tidy up Nashorn codebase for code standards (August 2014)
attila
parents: 26065
diff changeset
    29
import static jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor.CALLSITE_STRICT;
b32ccc3a76c9 8055199: Tidy up Nashorn codebase for code standards (August 2014)
attila
parents: 26065
diff changeset
    30
import static jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor.CALLSITE_TRACE;
b32ccc3a76c9 8055199: Tidy up Nashorn codebase for code standards (August 2014)
attila
parents: 26065
diff changeset
    31
import static jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor.CALLSITE_TRACE_ENTEREXIT;
b32ccc3a76c9 8055199: Tidy up Nashorn codebase for code standards (August 2014)
attila
parents: 26065
diff changeset
    32
import static jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor.CALLSITE_TRACE_MISSES;
b32ccc3a76c9 8055199: Tidy up Nashorn codebase for code standards (August 2014)
attila
parents: 26065
diff changeset
    33
import static jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor.CALLSITE_TRACE_VALUES;
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
    34
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    35
import java.util.Collections;
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
    36
import java.util.Iterator;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    37
import java.util.List;
39662
e2b36a3779b9 8149929: Nashorn Parser API needs to be updated for ES6
sundar
parents: 37732
diff changeset
    38
import java.util.Map;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    39
import jdk.nashorn.internal.codegen.CompileUnit;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    40
import jdk.nashorn.internal.codegen.Compiler;
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
    41
import jdk.nashorn.internal.codegen.CompilerConstants;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    42
import jdk.nashorn.internal.codegen.Namespace;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    43
import jdk.nashorn.internal.codegen.types.Type;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    44
import jdk.nashorn.internal.ir.annotations.Ignore;
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
    45
import jdk.nashorn.internal.ir.annotations.Immutable;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    46
import jdk.nashorn.internal.ir.visitor.NodeVisitor;
27102
c64b3468d51d 8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents: 26768
diff changeset
    47
import jdk.nashorn.internal.parser.Token;
26503
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
    48
import jdk.nashorn.internal.runtime.RecompilableScriptFunctionData;
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16525
diff changeset
    49
import jdk.nashorn.internal.runtime.ScriptFunction;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    50
import jdk.nashorn.internal.runtime.Source;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    51
import jdk.nashorn.internal.runtime.UserAccessorProperty;
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
    52
import jdk.nashorn.internal.runtime.linker.LinkerCallSite;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    53
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    54
/**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    55
 * IR representation for function (or script.)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    56
 */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
    57
@Immutable
26500
85ea77a73bb8 8057588: Lots of trivial (empty) classes were generated by the Nashorn compiler as part of restOf-method generation
lagergren
parents: 26377
diff changeset
    58
public final class FunctionNode extends LexicalContextExpression implements Flags<FunctionNode>, CompileUnitHolder {
27204
06ec78f29a56 8059843: Make AST serializable
attila
parents: 27102
diff changeset
    59
    private static final long serialVersionUID = 1L;
06ec78f29a56 8059843: Make AST serializable
attila
parents: 27102
diff changeset
    60
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
    61
    /** Type used for all FunctionNodes */
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
    62
    public static final Type FUNCTION_TYPE = Type.typeFor(ScriptFunction.class);
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16525
diff changeset
    63
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    64
    /** Function kinds */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    65
    public enum Kind {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    66
        /** a normal function - nothing special */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    67
        NORMAL,
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    68
        /** a script function */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    69
        SCRIPT,
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    70
        /** a getter, @see {@link UserAccessorProperty} */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    71
        GETTER,
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    72
        /** a setter, @see {@link UserAccessorProperty} */
37732
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
    73
        SETTER,
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
    74
        /** an arrow function */
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
    75
        ARROW,
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
    76
        /** a generator function */
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
    77
        GENERATOR,
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
    78
        /** a module function */
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
    79
        MODULE
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    80
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    81
17523
cb4a7c901e0d 8013913: Removed Source field from all nodes except FunctionNode in order to save footprint
lagergren
parents: 17518
diff changeset
    82
    /** Source of entity. */
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
    83
    private transient final Source source;
16233
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16206
diff changeset
    84
26503
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
    85
    /**
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
    86
     * Opaque object representing parser state at the end of the function. Used when reparsing outer functions
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
    87
     * to skip parsing inner functions.
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
    88
     */
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
    89
    private final Object endParserState;
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
    90
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    91
    /** External function identifier. */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    92
    @Ignore
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
    93
    private final IdentNode ident;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
    94
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
    95
    /** The body of the function node */
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
    96
    private final Block body;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    97
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    98
    /** Internal function name. */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
    99
    private final String name;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   100
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   101
    /** Compilation unit. */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   102
    private final CompileUnit compileUnit;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   103
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   104
    /** Function kind. */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   105
    private final Kind kind;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   106
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   107
    /** List of parameters. */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   108
    private final List<IdentNode> parameters;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   109
39662
e2b36a3779b9 8149929: Nashorn Parser API needs to be updated for ES6
sundar
parents: 37732
diff changeset
   110
    /** Map of ES6 function parameter expressions. */
e2b36a3779b9 8149929: Nashorn Parser API needs to be updated for ES6
sundar
parents: 37732
diff changeset
   111
    private final Map<IdentNode, Expression> parameterExpressions;
e2b36a3779b9 8149929: Nashorn Parser API needs to be updated for ES6
sundar
parents: 37732
diff changeset
   112
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   113
    /** First token of function. **/
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   114
    private final long firstToken;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   115
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   116
    /** Last token of function. **/
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   117
    private final long lastToken;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   118
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   119
    /** Method's namespace. */
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   120
    private transient final Namespace namespace;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   121
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   122
    /** Number of properties of "this" object assigned in this function */
18852
604c1d681b6f 8017084: Use spill properties for large object literals
hannesw
parents: 17982
diff changeset
   123
    @Ignore
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   124
    private final int thisProperties;
18852
604c1d681b6f 8017084: Use spill properties for large object literals
hannesw
parents: 17982
diff changeset
   125
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   126
    /** Function flags. */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   127
    private final int flags;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   128
24725
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24720
diff changeset
   129
    /** Line number of function start */
18867
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 18853
diff changeset
   130
    private final int lineNumber;
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 18853
diff changeset
   131
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   132
    /** Root class for function */
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   133
    private final Class<?> rootClass;
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   134
37732
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   135
    /** The ES6 module */
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   136
    private final Module module;
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   137
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   138
    /** The debug flags */
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   139
    private final int debugFlags;
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   140
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   141
    /** Is anonymous function flag. */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   142
    public static final int IS_ANONYMOUS                = 1 << 0;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   143
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16525
diff changeset
   144
    /** Is the function created in a function declaration (as opposed to a function expression) */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   145
    public static final int IS_DECLARED                 = 1 << 1;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   146
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   147
    /** is this a strict mode function? */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   148
    public static final int IS_STRICT                   = 1 << 2;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   149
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   150
    /** Does the function use the "arguments" identifier ? */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   151
    public static final int USES_ARGUMENTS              = 1 << 3;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   152
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   153
    /** Has this function been split because it was too large? */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   154
    public static final int IS_SPLIT                    = 1 << 4;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   155
17255
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17233
diff changeset
   156
    /** Does the function call eval? If it does, then all variables in this function might be get/set by it and it can
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17233
diff changeset
   157
     * introduce new variables into this function's scope too.*/
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   158
    public static final int HAS_EVAL                    = 1 << 5;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   159
17255
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17233
diff changeset
   160
    /** Does a nested function contain eval? If it does, then all variables in this function might be get/set by it. */
23372
09707b3e5fb0 8021350: Share script classes between threads/globals within context
hannesw
parents: 22390
diff changeset
   161
    public static final int HAS_NESTED_EVAL             = 1 << 6;
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   162
18853
25ba8264b427 8019819: scope symbol didn't get a slot in certain cases
attila
parents: 18852
diff changeset
   163
    /** Does this function have any blocks that create a scope? This is used to determine if the function needs to
25ba8264b427 8019819: scope symbol didn't get a slot in certain cases
attila
parents: 18852
diff changeset
   164
     * have a local variable slot for the scope symbol. */
23372
09707b3e5fb0 8021350: Share script classes between threads/globals within context
hannesw
parents: 22390
diff changeset
   165
    public static final int HAS_SCOPE_BLOCK             = 1 << 7;
18853
25ba8264b427 8019819: scope symbol didn't get a slot in certain cases
attila
parents: 18852
diff changeset
   166
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   167
    /**
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   168
     * Flag this function as one that defines the identifier "arguments" as a function parameter or nested function
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   169
     * name. This precludes it from needing to have an Arguments object defined as "arguments" local variable. Note that
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   170
     * defining a local variable named "arguments" still requires construction of the Arguments object (see
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   171
     * ECMAScript 5.1 Chapter 10.5).
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   172
     * @see #needsArguments()
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   173
     */
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   174
    public static final int DEFINES_ARGUMENTS           = 1 << 8;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   175
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   176
    /** Does this function or any of its descendants use variables from an ancestor function's scope (incl. globals)? */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   177
    public static final int USES_ANCESTOR_SCOPE         = 1 << 9;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   178
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   179
    /** Does this function have nested declarations? */
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   180
    public static final int HAS_FUNCTION_DECLARATIONS   = 1 << 10;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   181
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   182
    /** Does this function have optimistic expressions? (If it does, it can undergo deoptimizing recompilation.) */
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   183
    public static final int IS_DEOPTIMIZABLE            = 1 << 11;
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   184
24738
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24727
diff changeset
   185
    /** Are we vararg, but do we just pass the arguments along to apply or call */
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   186
    public static final int HAS_APPLY_TO_CALL_SPECIALIZATION = 1 << 12;
24738
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24727
diff changeset
   187
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   188
    /**
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   189
     * Is this function the top-level program?
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   190
     */
37732
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   191
    public static final int IS_PROGRAM                  = 1 << 13;
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   192
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   193
    /**
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   194
     * Flag indicating whether this function uses the local variable symbol for itself. Only named function expressions
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   195
     * can have this flag set if they reference themselves (e.g. "(function f() { return f })". Declared functions will
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   196
     * use the symbol in their parent scope instead when they reference themselves by name.
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   197
     */
37732
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   198
    public static final int USES_SELF_SYMBOL            = 1 << 14;
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
   199
23372
09707b3e5fb0 8021350: Share script classes between threads/globals within context
hannesw
parents: 22390
diff changeset
   200
    /** Does this function use the "this" keyword? */
37732
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   201
    public static final int USES_THIS                   = 1 << 15;
24749
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   202
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   203
    /** Is this declared in a dynamic context */
37732
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   204
    public static final int IN_DYNAMIC_CONTEXT          = 1 << 16;
26065
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   205
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   206
26503
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   207
    /**
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   208
     * Whether this function needs the callee {@link ScriptFunction} instance passed to its code as a
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   209
     * parameter on invocation. Note that we aren't, in fact using this flag in function nodes.
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   210
     * Rather, it is always calculated (see {@link #needsCallee()}). {@link RecompilableScriptFunctionData}
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   211
     * will, however, cache the value of this flag.
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   212
     */
37732
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   213
    public static final int NEEDS_CALLEE                = 1 << 17;
26503
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   214
32435
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 32434
diff changeset
   215
    /**
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 32434
diff changeset
   216
     * Is the function node cached?
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 32434
diff changeset
   217
     */
37732
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   218
    public static final int IS_CACHED                   = 1 << 18;
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   219
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   220
    /**
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   221
     * Does this function contain a super call? (cf. ES6 14.3.5 Static Semantics: HasDirectSuper)
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   222
     */
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   223
    public static final int ES6_HAS_DIRECT_SUPER        = 1 << 19;
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   224
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   225
    /**
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   226
     * Does this function use the super binding?
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   227
     */
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   228
    public static final int ES6_USES_SUPER              = 1 << 20;
32435
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 32434
diff changeset
   229
37732
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   230
    /**
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   231
     * Is this function a (class or object) method?
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   232
     */
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   233
    public static final int ES6_IS_METHOD               = 1 << 21;
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   234
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   235
    /**
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   236
     * Is this the constructor method?
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   237
     */
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   238
    public static final int ES6_IS_CLASS_CONSTRUCTOR    = 1 << 22;
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   239
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   240
    /** Is this the constructor of a subclass (i.e., a class with an extends declaration)? */
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   241
    public static final int ES6_IS_SUBCLASS_CONSTRUCTOR = 1 << 23;
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   242
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   243
    /** is this a strong mode function? */
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   244
    public static final int ES6_IS_STRONG               = 1 << 24;
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   245
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   246
    /** Does this function use new.target? */
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   247
    public static final int ES6_USES_NEW_TARGET         = 1 << 25;
26065
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   248
39662
e2b36a3779b9 8149929: Nashorn Parser API needs to be updated for ES6
sundar
parents: 37732
diff changeset
   249
    /** Does this function have expression as its body? */
e2b36a3779b9 8149929: Nashorn Parser API needs to be updated for ES6
sundar
parents: 37732
diff changeset
   250
    public static final int HAS_EXPRESSION_BODY         = 1 << 26;
e2b36a3779b9 8149929: Nashorn Parser API needs to be updated for ES6
sundar
parents: 37732
diff changeset
   251
17255
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17233
diff changeset
   252
    /** Does this function or any nested functions contain an eval? */
aa61d23e36e5 8013419: Streamline handling of with and eval
attila
parents: 17233
diff changeset
   253
    private static final int HAS_DEEP_EVAL = HAS_EVAL | HAS_NESTED_EVAL;
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   254
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   255
    /** Does this function need to store all its variables in scope? */
33888
0c7b0ab328e0 8131929: Add option for debuggable scopes
hannesw
parents: 32692
diff changeset
   256
    public static final int HAS_ALL_VARS_IN_SCOPE = HAS_DEEP_EVAL;
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   257
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   258
    /** Does this function potentially need "arguments"? Note that this is not a full test, as further negative check of REDEFINES_ARGS is needed. */
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   259
    private static final int MAYBE_NEEDS_ARGUMENTS = USES_ARGUMENTS | HAS_EVAL;
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   260
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   261
    /** Does this function need the parent scope? It needs it if either it or its descendants use variables from it, or have a deep eval, or it's the program. */
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   262
    public static final int NEEDS_PARENT_SCOPE = USES_ANCESTOR_SCOPE | HAS_DEEP_EVAL | IS_PROGRAM;
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   263
37732
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   264
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   265
    /**
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   266
     * The following flags are derived from directive comments within this function.
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   267
     * Note that even IS_STRICT is one such flag but that requires special handling.
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   268
     */
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   269
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   270
    /** parser, print parse tree */
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   271
    public static final int DEBUG_PRINT_PARSE       = 1 << 0;
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   272
    /** parser, print lower parse tree */
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   273
    public static final int DEBUG_PRINT_LOWER_PARSE = 1 << 1;
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   274
    /** parser, print AST */
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   275
    public static final int DEBUG_PRINT_AST         = 1 << 2;
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   276
    /** parser, print lower AST */
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   277
    public static final int DEBUG_PRINT_LOWER_AST   = 1 << 3;
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   278
    /** parser, print symbols */
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   279
    public static final int DEBUG_PRINT_SYMBOLS     = 1 << 4;
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   280
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   281
    // callsite tracing, profiling within this function
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   282
    /** profile callsites in this function? */
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   283
    public static final int DEBUG_PROFILE           = 1 << 5;
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   284
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   285
    /** trace callsite enterexit in this function? */
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   286
    public static final int DEBUG_TRACE_ENTEREXIT   = 1 << 6;
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   287
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   288
    /** trace callsite misses in this function? */
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   289
    public static final int DEBUG_TRACE_MISSES      = 1 << 7;
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   290
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   291
    /** trace callsite values in this function? */
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   292
    public static final int DEBUG_TRACE_VALUES      = 1 << 8;
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   293
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   294
    /** extension callsite flags mask */
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   295
    public static final int DEBUG_CALLSITE_FLAGS = DEBUG_PRINT_PARSE |
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   296
            DEBUG_PRINT_LOWER_PARSE | DEBUG_PRINT_AST | DEBUG_PRINT_LOWER_AST |
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   297
            DEBUG_PRINT_SYMBOLS | DEBUG_PROFILE | DEBUG_TRACE_ENTEREXIT |
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   298
            DEBUG_TRACE_MISSES | DEBUG_TRACE_VALUES;
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   299
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   300
    /** What is the return type of this function? */
37732
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   301
    public Type returnType = Type.UNKNOWN;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   302
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   303
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   304
     * Constructor
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   305
     *
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   306
     * @param source     the source
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
   307
     * @param lineNumber line number
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   308
     * @param token      token
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   309
     * @param finish     finish
26503
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   310
     * @param firstToken first token of the function node (including the function declaration)
27102
c64b3468d51d 8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents: 26768
diff changeset
   311
     * @param lastToken  lastToken
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   312
     * @param namespace  the namespace
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   313
     * @param ident      the identifier
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   314
     * @param name       the name of the function
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   315
     * @param parameters parameter list
39662
e2b36a3779b9 8149929: Nashorn Parser API needs to be updated for ES6
sundar
parents: 37732
diff changeset
   316
     * @param paramExprs the ES6 function parameter expressions
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   317
     * @param kind       kind of function as in {@link FunctionNode.Kind}
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   318
     * @param flags      initial flags
27102
c64b3468d51d 8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents: 26768
diff changeset
   319
     * @param body       body of the function
c64b3468d51d 8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents: 26768
diff changeset
   320
     * @param endParserState The parser state at the end of the parsing.
37732
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   321
     * @param module     the module
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   322
     * @param debugFlags the debug flags
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   323
     */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   324
    public FunctionNode(
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   325
        final Source source,
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
   326
        final int lineNumber,
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   327
        final long token,
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   328
        final int finish,
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   329
        final long firstToken,
27102
c64b3468d51d 8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents: 26768
diff changeset
   330
        final long lastToken,
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   331
        final Namespace namespace,
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   332
        final IdentNode ident,
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   333
        final String name,
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   334
        final List<IdentNode> parameters,
39662
e2b36a3779b9 8149929: Nashorn Parser API needs to be updated for ES6
sundar
parents: 37732
diff changeset
   335
        final Map<IdentNode, Expression> paramExprs,
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   336
        final FunctionNode.Kind kind,
27102
c64b3468d51d 8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents: 26768
diff changeset
   337
        final int flags,
c64b3468d51d 8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents: 26768
diff changeset
   338
        final Block body,
37732
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   339
        final Object endParserState,
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   340
        final Module module,
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   341
        final int debugFlags) {
18867
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 18853
diff changeset
   342
        super(token, finish);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   343
17523
cb4a7c901e0d 8013913: Removed Source field from all nodes except FunctionNode in order to save footprint
lagergren
parents: 17518
diff changeset
   344
        this.source           = source;
18867
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 18853
diff changeset
   345
        this.lineNumber       = lineNumber;
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
   346
        this.ident            = ident;
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
   347
        this.name             = 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
   348
        this.kind             = kind;
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
   349
        this.parameters       = parameters;
39662
e2b36a3779b9 8149929: Nashorn Parser API needs to be updated for ES6
sundar
parents: 37732
diff changeset
   350
        this.parameterExpressions = paramExprs;
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
   351
        this.firstToken       = firstToken;
27102
c64b3468d51d 8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents: 26768
diff changeset
   352
        this.lastToken        = lastToken;
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
   353
        this.namespace        = namespace;
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
        this.flags            = 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
   355
        this.compileUnit      = null;
27102
c64b3468d51d 8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents: 26768
diff changeset
   356
        this.body             = body;
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   357
        this.thisProperties   = 0;
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   358
        this.rootClass        = null;
37732
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   359
        this.endParserState   = endParserState;
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   360
        this.module           = module;
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   361
        this.debugFlags       = debugFlags;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   362
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   363
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
    private 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
   365
        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
   366
        final long lastToken,
26768
751b0f427090 8025435: Optimistic builtins support, implemented initial optimistic versions of push, pop, and charCodeAt
lagergren
parents: 26503
diff changeset
   367
        final Object endParserState,
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
   368
        final int flags,
17752
9d2d0e74a833 8013919: Original exception no longer thrown away when a finally rethrows
lagergren
parents: 17524
diff changeset
   369
        final String name,
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
   370
        final Type returnType,
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
   371
        final CompileUnit compileUnit,
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
   372
        final Block body,
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   373
        final List<IdentNode> parameters,
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   374
        final int thisProperties,
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   375
        final Class<?> rootClass,
32435
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 32434
diff changeset
   376
        final Source source, final Namespace namespace) {
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   377
        super(functionNode);
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   378
26503
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   379
        this.endParserState    = endParserState;
18867
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 18853
diff changeset
   380
        this.lineNumber       = functionNode.lineNumber;
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
   381
        this.flags            = flags;
17752
9d2d0e74a833 8013919: Original exception no longer thrown away when a finally rethrows
lagergren
parents: 17524
diff changeset
   382
        this.name             = name;
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
   383
        this.returnType       = returnType;
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
   384
        this.compileUnit      = compileUnit;
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
   385
        this.lastToken        = lastToken;
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
   386
        this.body             = 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
   387
        this.parameters       = parameters;
39662
e2b36a3779b9 8149929: Nashorn Parser API needs to be updated for ES6
sundar
parents: 37732
diff changeset
   388
        this.parameterExpressions = functionNode.parameterExpressions;
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   389
        this.thisProperties   = thisProperties;
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   390
        this.rootClass        = rootClass;
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   391
        this.source           = source;
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   392
        this.namespace        = namespace;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   393
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   394
        // the fields below never change - they are final and assigned in constructor
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
   395
        this.ident           = functionNode.ident;
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
   396
        this.kind            = functionNode.kind;
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
   397
        this.firstToken      = functionNode.firstToken;
37732
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   398
        this.module          = functionNode.module;
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   399
        this.debugFlags      = functionNode.debugFlags;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   400
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   401
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   402
    @Override
17769
14ea7feaf658 8012522: Clean up lexical contexts - split out stack based functionality in CodeGenerator and generify NodeVisitors based on their LexicalContext type to avoid casts
lagergren
parents: 17756
diff changeset
   403
    public Node accept(final LexicalContext lc, final NodeVisitor<? extends LexicalContext> visitor) {
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   404
        if (visitor.enterFunctionNode(this)) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   405
            return visitor.leaveFunctionNode(setBody(lc, (Block)body.accept(visitor)));
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   406
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   407
        return this;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   408
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   409
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   410
    /**
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   411
     * Visits the parameter nodes of this function. Parameters are normally not visited automatically.
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   412
     * @param visitor the visitor to apply to the nodes.
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   413
     * @return a list of parameter nodes, potentially modified from original ones by the visitor.
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   414
     */
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   415
    public List<IdentNode> visitParameters(final NodeVisitor<? extends LexicalContext> visitor) {
25821
fbb51e67d2a7 8048869: Reduce compile time by about 5% by removing the Class.casts from the AST nodes
lagergren
parents: 24993
diff changeset
   416
        return Node.accept(visitor, parameters);
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   417
    }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   418
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   419
    /**
26065
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   420
     * Get additional callsite flags to be used specific to this function.
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   421
     *
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   422
     * @return callsite flags
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   423
     */
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   424
    public int getCallSiteFlags() {
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   425
        int callsiteFlags = 0;
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   426
        if (getFlag(IS_STRICT)) {
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   427
            callsiteFlags |= CALLSITE_STRICT;
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   428
        }
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   429
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   430
        // quick check for extension callsite flags turned on by directives.
37732
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   431
        if ((debugFlags & DEBUG_CALLSITE_FLAGS) == 0) {
26065
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   432
            return callsiteFlags;
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   433
        }
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   434
37732
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   435
        if (getDebugFlag(DEBUG_PROFILE)) {
26065
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   436
            callsiteFlags |= CALLSITE_PROFILE;
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   437
        }
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   438
37732
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   439
        if (getDebugFlag(DEBUG_TRACE_MISSES)) {
26065
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   440
            callsiteFlags |= CALLSITE_TRACE | CALLSITE_TRACE_MISSES;
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   441
        }
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   442
37732
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   443
        if (getDebugFlag(DEBUG_TRACE_VALUES)) {
26065
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   444
            callsiteFlags |= CALLSITE_TRACE | CALLSITE_TRACE_ENTEREXIT | CALLSITE_TRACE_VALUES;
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   445
        }
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   446
37732
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   447
        if (getDebugFlag(DEBUG_TRACE_ENTEREXIT)) {
26065
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   448
            callsiteFlags |= CALLSITE_TRACE | CALLSITE_TRACE_ENTEREXIT;
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   449
        }
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   450
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   451
        return callsiteFlags;
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   452
    }
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   453
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   454
    /**
17523
cb4a7c901e0d 8013913: Removed Source field from all nodes except FunctionNode in order to save footprint
lagergren
parents: 17518
diff changeset
   455
     * Get the source for this function
cb4a7c901e0d 8013913: Removed Source field from all nodes except FunctionNode in order to save footprint
lagergren
parents: 17518
diff changeset
   456
     * @return the source
cb4a7c901e0d 8013913: Removed Source field from all nodes except FunctionNode in order to save footprint
lagergren
parents: 17518
diff changeset
   457
     */
cb4a7c901e0d 8013913: Removed Source field from all nodes except FunctionNode in order to save footprint
lagergren
parents: 17518
diff changeset
   458
    public Source getSource() {
cb4a7c901e0d 8013913: Removed Source field from all nodes except FunctionNode in order to save footprint
lagergren
parents: 17518
diff changeset
   459
        return source;
cb4a7c901e0d 8013913: Removed Source field from all nodes except FunctionNode in order to save footprint
lagergren
parents: 17518
diff changeset
   460
    }
cb4a7c901e0d 8013913: Removed Source field from all nodes except FunctionNode in order to save footprint
lagergren
parents: 17518
diff changeset
   461
cb4a7c901e0d 8013913: Removed Source field from all nodes except FunctionNode in order to save footprint
lagergren
parents: 17518
diff changeset
   462
    /**
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   463
     * Sets the source and namespace for this function. It can only set a non-null source and namespace for a function
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   464
     * that currently has both a null source and a null namespace. This is used to re-set the source and namespace for
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   465
     * a deserialized function node.
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   466
     * @param source the source for the function.
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   467
     * @param namespace the namespace for the function
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   468
     * @return a new function node with the set source and namespace
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   469
     * @throws IllegalArgumentException if the specified source or namespace is null
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   470
     * @throws IllegalStateException if the function already has either a source or namespace set.
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   471
     */
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   472
    public FunctionNode initializeDeserialized(final Source source, final Namespace namespace) {
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   473
        if (source == null || namespace == null) {
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   474
            throw new IllegalArgumentException();
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   475
        } else if (this.source == source && this.namespace == namespace) {
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   476
            return this;
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   477
        } else if (this.source != null || this.namespace != null) {
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   478
            throw new IllegalStateException();
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   479
        }
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   480
        return new FunctionNode(
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   481
            this,
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   482
            lastToken,
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   483
            endParserState,
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   484
            flags,
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   485
            name,
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   486
            returnType,
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   487
            compileUnit,
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   488
            body,
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   489
            parameters,
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   490
            thisProperties,
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   491
            rootClass, source, namespace);
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   492
    }
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   493
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   494
    /**
26503
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   495
     * Get the unique ID for this function within the script file.
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   496
     * @return the id
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   497
     */
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   498
    public int getId() {
27102
c64b3468d51d 8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents: 26768
diff changeset
   499
        return isProgram() ? -1: Token.descPosition(firstToken);
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   500
    }
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   501
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   502
    /**
22390
1d2d88e478ea 8032068: implement @sourceURL and #sourceURL directives
sundar
parents: 19095
diff changeset
   503
     * get source name - sourceURL or name derived from Source.
1d2d88e478ea 8032068: implement @sourceURL and #sourceURL directives
sundar
parents: 19095
diff changeset
   504
     *
1d2d88e478ea 8032068: implement @sourceURL and #sourceURL directives
sundar
parents: 19095
diff changeset
   505
     * @return name for the script source
1d2d88e478ea 8032068: implement @sourceURL and #sourceURL directives
sundar
parents: 19095
diff changeset
   506
     */
1d2d88e478ea 8032068: implement @sourceURL and #sourceURL directives
sundar
parents: 19095
diff changeset
   507
    public String getSourceName() {
26055
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 25821
diff changeset
   508
        return getSourceName(source);
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   509
    }
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   510
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   511
    /**
24993
b707d46bae40 8046898: Make sure that lazy compilation is the default, remove redundant "enable lazy compilation" flags, added warning message if compile logging is enabled and lazy is switched off. Verified existing test suite code coverage equivalence between lazy and eager.
lagergren
parents: 24778
diff changeset
   512
     * Static source name getter
b707d46bae40 8046898: Make sure that lazy compilation is the default, remove redundant "enable lazy compilation" flags, added warning message if compile logging is enabled and lazy is switched off. Verified existing test suite code coverage equivalence between lazy and eager.
lagergren
parents: 24778
diff changeset
   513
     *
26055
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 25821
diff changeset
   514
     * @param source the source
24993
b707d46bae40 8046898: Make sure that lazy compilation is the default, remove redundant "enable lazy compilation" flags, added warning message if compile logging is enabled and lazy is switched off. Verified existing test suite code coverage equivalence between lazy and eager.
lagergren
parents: 24778
diff changeset
   515
     * @return source name
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   516
     */
26055
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 25821
diff changeset
   517
    public static String getSourceName(final Source source) {
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 25821
diff changeset
   518
        final String explicitURL = source.getExplicitURL();
fe8be844ba50 8043956: Make code caching work with optimistic typing and lazy compilation
hannesw
parents: 25821
diff changeset
   519
        return explicitURL != null ? explicitURL : source.getName();
22390
1d2d88e478ea 8032068: implement @sourceURL and #sourceURL directives
sundar
parents: 19095
diff changeset
   520
    }
1d2d88e478ea 8032068: implement @sourceURL and #sourceURL directives
sundar
parents: 19095
diff changeset
   521
1d2d88e478ea 8032068: implement @sourceURL and #sourceURL directives
sundar
parents: 19095
diff changeset
   522
    /**
26065
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   523
     * Function to parse nashorn per-function extension directive comments.
22390
1d2d88e478ea 8032068: implement @sourceURL and #sourceURL directives
sundar
parents: 19095
diff changeset
   524
     *
26065
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   525
     * @param directive nashorn extension directive string
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   526
     * @return integer flag for the given directive.
22390
1d2d88e478ea 8032068: implement @sourceURL and #sourceURL directives
sundar
parents: 19095
diff changeset
   527
     */
26065
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   528
    public static int getDirectiveFlag(final String directive) {
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   529
        switch (directive) {
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   530
            case "nashorn callsite trace enterexit":
37732
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   531
                return DEBUG_TRACE_ENTEREXIT;
26065
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   532
            case "nashorn callsite trace misses":
37732
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   533
                return DEBUG_TRACE_MISSES;
26065
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   534
            case "nashorn callsite trace objects":
37732
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   535
                return DEBUG_TRACE_VALUES;
26065
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   536
            case "nashorn callsite profile":
37732
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   537
                return DEBUG_PROFILE;
26065
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   538
            case "nashorn print parse":
37732
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   539
                return DEBUG_PRINT_PARSE;
26065
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   540
            case "nashorn print lower parse":
37732
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   541
                return DEBUG_PRINT_LOWER_PARSE;
26065
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   542
            case "nashorn print ast":
37732
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   543
                return DEBUG_PRINT_AST;
26065
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   544
            case "nashorn print lower ast":
37732
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   545
                return DEBUG_PRINT_LOWER_AST;
26065
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   546
            case "nashorn print symbols":
37732
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   547
                return DEBUG_PRINT_SYMBOLS;
26065
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   548
            default:
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   549
                // unknown/unsupported directive
d15adb218527 8055107: Extension directives to turn on callsite profiling, tracing, AST print and other debug features locally
sundar
parents: 26056
diff changeset
   550
                return 0;
22390
1d2d88e478ea 8032068: implement @sourceURL and #sourceURL directives
sundar
parents: 19095
diff changeset
   551
        }
1d2d88e478ea 8032068: implement @sourceURL and #sourceURL directives
sundar
parents: 19095
diff changeset
   552
    }
1d2d88e478ea 8032068: implement @sourceURL and #sourceURL directives
sundar
parents: 19095
diff changeset
   553
1d2d88e478ea 8032068: implement @sourceURL and #sourceURL directives
sundar
parents: 19095
diff changeset
   554
    /**
18867
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 18853
diff changeset
   555
     * Returns the line number.
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 18853
diff changeset
   556
     * @return the line number.
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 18853
diff changeset
   557
     */
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 18853
diff changeset
   558
    public int getLineNumber() {
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 18853
diff changeset
   559
        return lineNumber;
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 18853
diff changeset
   560
    }
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 18853
diff changeset
   561
bc91e3fcc5ba 8013925: Remove symbol fields from nodes that don't need them
attila
parents: 18853
diff changeset
   562
    /**
16233
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16206
diff changeset
   563
     * Create a unique name in the namespace of this FunctionNode
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16206
diff changeset
   564
     * @param base prefix for name
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16206
diff changeset
   565
     * @return base if no collision exists, otherwise a name prefix with base
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16206
diff changeset
   566
     */
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16206
diff changeset
   567
    public String uniqueName(final String base) {
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16206
diff changeset
   568
        return namespace.uniqueName(base);
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16206
diff changeset
   569
    }
95d3e01c04c3 8008199: Lazy compilation and trampoline implementation
lagergren
parents: 16206
diff changeset
   570
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   571
    @Override
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   572
    public void toString(final StringBuilder sb, final boolean printTypes) {
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   573
        sb.append('[').
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   574
            append(returnType).
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   575
            append(']').
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   576
            append(' ');
16201
889ddb179cdf 8007062: Split Lower up into Lower/Attr/FinalizeTypes. Integrate AccessSpecalizer into FinalizeTypes.
lagergren
parents: 16187
diff changeset
   577
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   578
        sb.append("function");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   579
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   580
        if (ident != null) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   581
            sb.append(' ');
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   582
            ident.toString(sb, printTypes);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   583
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   584
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   585
        sb.append('(');
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   586
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   587
        for (final Iterator<IdentNode> iter = parameters.iterator(); iter.hasNext(); ) {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   588
            final IdentNode parameter = iter.next();
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   589
            if (parameter.getSymbol() != null) {
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   590
                sb.append('[').append(parameter.getType()).append(']').append(' ');
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   591
            }
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   592
            parameter.toString(sb, printTypes);
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   593
            if (iter.hasNext()) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   594
                sb.append(", ");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   595
            }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   596
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   597
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   598
        sb.append(')');
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   599
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   600
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   601
    @Override
24738
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24727
diff changeset
   602
    public int getFlags() {
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24727
diff changeset
   603
        return flags;
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24727
diff changeset
   604
    }
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24727
diff changeset
   605
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24727
diff changeset
   606
    @Override
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   607
    public boolean getFlag(final int flag) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   608
        return (flags & flag) != 0;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   609
    }
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   610
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   611
    @Override
24725
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24720
diff changeset
   612
    public FunctionNode setFlags(final LexicalContext lc, final int flags) {
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   613
        if (this.flags == flags) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   614
            return this;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   615
        }
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   616
        return Node.replaceInLexicalContext(
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   617
                lc,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   618
                this,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   619
                new FunctionNode(
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   620
                        this,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   621
                        lastToken,
26503
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   622
                        endParserState,
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   623
                        flags,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   624
                        name,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   625
                        returnType,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   626
                        compileUnit,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   627
                        body,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   628
                        parameters,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   629
                        thisProperties,
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   630
                        rootClass, source, namespace));
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   631
    }
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   632
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   633
    @Override
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   634
    public FunctionNode clearFlag(final LexicalContext lc, final int flag) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   635
        return setFlags(lc, flags & ~flag);
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   636
    }
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   637
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   638
    @Override
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   639
    public FunctionNode setFlag(final LexicalContext lc, final int flag) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   640
        return setFlags(lc, flags | flag);
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   641
    }
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   642
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   643
    /**
37732
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   644
     * Returns the debug flags for this function.
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   645
     *
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   646
     * @return the debug flags
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   647
     */
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   648
    public int getDebugFlags() {
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   649
        return debugFlags;
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   650
    }
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   651
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   652
    /**
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   653
     * Checks whether a debug flag is set for this function.
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   654
     *
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   655
     * @param debugFlag the debug flag
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   656
     * @return true if the flag is set
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   657
     */
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   658
    public boolean getDebugFlag(final int debugFlag) {
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   659
        return (debugFlags & debugFlag) != 0;
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   660
    }
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   661
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
   662
    /**
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16525
diff changeset
   663
     * Returns true if the function is the top-level program.
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16525
diff changeset
   664
     * @return True if this function node represents the top-level program.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   665
     */
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16525
diff changeset
   666
    public boolean isProgram() {
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   667
        return getFlag(IS_PROGRAM);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   668
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   669
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   670
    /**
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   671
     * Returns true if the function contains at least one optimistic operation (and thus can be deoptimized).
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   672
     * @return true if the function contains at least one optimistic operation (and thus can be deoptimized).
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   673
     */
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   674
    public boolean canBeDeoptimized() {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   675
        return getFlag(IS_DEOPTIMIZABLE);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   676
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   677
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   678
    /**
26503
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   679
     * Check if this function has a call expression for the identifier "eval" (that is, {@code eval(...)}).
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   680
     *
26503
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   681
     * @return true if {@code eval} is called.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   682
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   683
    public boolean hasEval() {
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   684
        return getFlag(HAS_EVAL);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   685
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   686
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   687
    /**
26503
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   688
     * Returns true if a function nested (directly or transitively) within this function {@link #hasEval()}.
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   689
     *
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   690
     * @return true if a nested function calls {@code eval}.
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   691
     */
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   692
    public boolean hasNestedEval() {
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   693
        return getFlag(HAS_NESTED_EVAL);
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   694
    }
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   695
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   696
    /**
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   697
     * Get the first token for this function
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   698
     * @return the first token
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   699
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   700
    public long getFirstToken() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   701
        return firstToken;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   702
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   703
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   704
    /**
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   705
     * Check whether this function has nested function declarations
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   706
     * @return true if nested function declarations exist
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   707
     */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   708
    public boolean hasDeclaredFunctions() {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   709
        return getFlag(HAS_FUNCTION_DECLARATIONS);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   710
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   711
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   712
    /**
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   713
     * Check if this function's generated Java method needs a {@code callee} parameter. Functions that need access to
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   714
     * their parent scope, functions that reference themselves, and non-strict functions that need an Arguments object
19084
daddbeee0058 8020356: ClassCastException Undefined->Scope on spiltter class generated for a large switch statement
hannesw
parents: 18867
diff changeset
   715
     * (since it exposes {@code arguments.callee} property) will need to have a callee parameter. We also return true
daddbeee0058 8020356: ClassCastException Undefined->Scope on spiltter class generated for a large switch statement
hannesw
parents: 18867
diff changeset
   716
     * for split functions to make sure symbols slots are the same in the main and split methods.
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: 16252
diff changeset
   717
     *
24740
26791be09688 8040089: Apply to call transform was incomplete. Now passes all tests and performance is back
lagergren
parents: 24738
diff changeset
   718
     * A function that has had an apply(this,arguments) turned into a call doesn't need arguments anymore, but still
26791be09688 8040089: Apply to call transform was incomplete. Now passes all tests and performance is back
lagergren
parents: 24738
diff changeset
   719
     * has to fit the old callsite, thus, we require a dummy callee parameter for those functions as well
26791be09688 8040089: Apply to call transform was incomplete. Now passes all tests and performance is back
lagergren
parents: 24738
diff changeset
   720
     *
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   721
     * @return true if the function's generated Java method needs a {@code callee} parameter.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   722
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   723
    public boolean needsCallee() {
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   724
        // NOTE: we only need isSplit() here to ensure that :scope can never drop below slot 2 for splitting array units.
32435
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 32434
diff changeset
   725
        return needsParentScope() || usesSelfSymbol() || isSplit() || (needsArguments() && !isStrict()) || hasApplyToCallSpecialization();
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   726
    }
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   727
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
   728
    /**
23372
09707b3e5fb0 8021350: Share script classes between threads/globals within context
hannesw
parents: 22390
diff changeset
   729
     * Return {@code true} if this function makes use of the {@code this} object.
09707b3e5fb0 8021350: Share script classes between threads/globals within context
hannesw
parents: 22390
diff changeset
   730
     *
09707b3e5fb0 8021350: Share script classes between threads/globals within context
hannesw
parents: 22390
diff changeset
   731
     * @return true if function uses {@code this} object
09707b3e5fb0 8021350: Share script classes between threads/globals within context
hannesw
parents: 22390
diff changeset
   732
     */
09707b3e5fb0 8021350: Share script classes between threads/globals within context
hannesw
parents: 22390
diff changeset
   733
    public boolean usesThis() {
09707b3e5fb0 8021350: Share script classes between threads/globals within context
hannesw
parents: 22390
diff changeset
   734
        return getFlag(USES_THIS);
09707b3e5fb0 8021350: Share script classes between threads/globals within context
hannesw
parents: 22390
diff changeset
   735
    }
09707b3e5fb0 8021350: Share script classes between threads/globals within context
hannesw
parents: 22390
diff changeset
   736
24738
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24727
diff changeset
   737
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24727
diff changeset
   738
    /**
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24727
diff changeset
   739
     * Return true if function contains an apply to call transform
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24727
diff changeset
   740
     * @return true if this function has transformed apply to call
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24727
diff changeset
   741
     */
32435
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 32434
diff changeset
   742
    public boolean hasApplyToCallSpecialization() {
24738
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24727
diff changeset
   743
        return getFlag(HAS_APPLY_TO_CALL_SPECIALIZATION);
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24727
diff changeset
   744
    }
be2026c9717c 8039746: Transform applies to calls wherever possible, for ScriptFunctions and JSObjects.
lagergren
parents: 24727
diff changeset
   745
23372
09707b3e5fb0 8021350: Share script classes between threads/globals within context
hannesw
parents: 22390
diff changeset
   746
    /**
17752
9d2d0e74a833 8013919: Original exception no longer thrown away when a finally rethrows
lagergren
parents: 17524
diff changeset
   747
     * Get the identifier for this function, this is its symbol.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   748
     * @return the identifier as an IdentityNode
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   749
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   750
    public IdentNode getIdent() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   751
        return ident;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   752
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   753
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   754
    /**
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   755
     * Get the function body
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   756
     * @return the function body
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   757
     */
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   758
    public Block getBody() {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   759
        return body;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   760
    }
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   761
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   762
    /**
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   763
     * Reset the function body
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   764
     * @param lc lexical context
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   765
     * @param body new body
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   766
     * @return new function node if body changed, same if not
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   767
     */
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   768
    public FunctionNode setBody(final LexicalContext lc, final Block body) {
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   769
        if (this.body == body) {
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   770
            return this;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   771
        }
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   772
        return Node.replaceInLexicalContext(
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   773
                lc,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   774
                this,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   775
                new FunctionNode(
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   776
                        this,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   777
                        lastToken,
26503
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   778
                        endParserState,
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   779
                        flags |
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   780
                            (body.needsScope() ?
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   781
                                    FunctionNode.HAS_SCOPE_BLOCK :
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   782
                                    0),
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   783
                        name,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   784
                        returnType,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   785
                        compileUnit,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   786
                        body,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   787
                        parameters,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   788
                        thisProperties,
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   789
                        rootClass, source, namespace));
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   790
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   791
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   792
    /**
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   793
     * Does this function's method needs to be variable arity (gather all script-declared parameters in a final
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   794
     * {@code Object[]} parameter. Functions that need to have the "arguments" object as well as functions that simply
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   795
     * declare too many arguments for JVM to handle with fixed arity will need to be variable arity.
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   796
     * @return true if the Java method in the generated code that implements this function needs to be variable arity.
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   797
     * @see #needsArguments()
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   798
     * @see LinkerCallSite#ARGLIMIT
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   799
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   800
    public boolean isVarArg() {
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   801
        return needsArguments() || parameters.size() > LinkerCallSite.ARGLIMIT;
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   802
    }
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   803
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   804
    /**
24749
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   805
     * Was this function declared in a dynamic context, i.e. in a with or eval style
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   806
     * chain
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   807
     * @return true if in dynamic context
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   808
     */
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   809
    public boolean inDynamicContext() {
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   810
        return getFlag(IN_DYNAMIC_CONTEXT);
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   811
    }
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   812
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   813
    /**
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   814
     * Check whether a function would need dynamic scope, which is does if it has
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   815
     * evals and isn't strict.
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   816
     * @return true if dynamic scope is needed
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   817
     */
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   818
    public boolean needsDynamicScope() {
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   819
        // Function has a direct eval in it (so a top-level "var ..." in the eval code can introduce a new
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   820
        // variable into the function's scope), and it isn't strict (as evals in strict functions get an
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   821
        // isolated scope).
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   822
        return hasEval() && !isStrict();
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   823
    }
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   824
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   825
    /**
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   826
     * Flag this function as declared in a dynamic context
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   827
     * @param lc lexical context
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   828
     * @return new function node, or same if unmodified
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   829
     */
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   830
    public FunctionNode setInDynamicContext(final LexicalContext lc) {
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   831
        return setFlag(lc, IN_DYNAMIC_CONTEXT);
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   832
    }
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   833
1549c85f8200 8041625: AccessorProperty currentType must only by Object.class when non-primitive, and scoping followup problem for lazily generated with bodies
lagergren
parents: 24740
diff changeset
   834
    /**
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   835
     * Returns true if this function needs to have an Arguments object defined as a local variable named "arguments".
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   836
     * Functions that use "arguments" as identifier and don't define it as a name of a parameter or a nested function
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   837
     * (see ECMAScript 5.1 Chapter 10.5), as well as any function that uses eval or with, or has a nested function that
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   838
     * does the same, will have an "arguments" object. Also, if this function is a script, it will not have an
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   839
     * "arguments" object, because it does not have local variables; rather the Global object will have an explicit
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   840
     * "arguments" property that provides command-line arguments for the script.
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   841
     * @return true if this function needs an arguments object.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   842
     */
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   843
    public boolean needsArguments() {
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   844
        // uses "arguments" or calls eval, but it does not redefine "arguments", and finally, it's not a script, since
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   845
        // for top-level script, "arguments" is picked up from Context by Global.init() instead.
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   846
        return getFlag(MAYBE_NEEDS_ARGUMENTS) && !getFlag(DEFINES_ARGUMENTS) && !isProgram();
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   847
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   848
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   849
    /**
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   850
     * Returns true if this function needs access to its parent scope. Functions referencing variables outside their
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   851
     * scope (including global variables), as well as functions that call eval or have a with block, or have nested
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   852
     * functions that call eval or have a with block, will need a parent scope. Top-level script functions also need a
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   853
     * parent scope since they might be used from within eval, and eval will need an externally passed scope.
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   854
     * @return true if the function needs parent scope.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   855
     */
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   856
    public boolean needsParentScope() {
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   857
        return getFlag(NEEDS_PARENT_SCOPE);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   858
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   859
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   860
    /**
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   861
     * Set the number of properties assigned to the this object in this function.
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   862
     * @param lc the current lexical context.
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   863
     * @param thisProperties number of properties
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   864
     * @return a potentially modified function node
18852
604c1d681b6f 8017084: Use spill properties for large object literals
hannesw
parents: 17982
diff changeset
   865
     */
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   866
    public FunctionNode setThisProperties(final LexicalContext lc, final int thisProperties) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   867
        if (this.thisProperties == thisProperties) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   868
            return this;
18852
604c1d681b6f 8017084: Use spill properties for large object literals
hannesw
parents: 17982
diff changeset
   869
        }
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   870
        return Node.replaceInLexicalContext(
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   871
                lc,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   872
                this,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   873
                new FunctionNode(
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   874
                        this,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   875
                        lastToken,
26503
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   876
                        endParserState,
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   877
                        flags,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   878
                        name,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   879
                        returnType,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   880
                        compileUnit,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   881
                        body,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   882
                        parameters,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   883
                        thisProperties,
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   884
                        rootClass, source, namespace));
18852
604c1d681b6f 8017084: Use spill properties for large object literals
hannesw
parents: 17982
diff changeset
   885
    }
604c1d681b6f 8017084: Use spill properties for large object literals
hannesw
parents: 17982
diff changeset
   886
604c1d681b6f 8017084: Use spill properties for large object literals
hannesw
parents: 17982
diff changeset
   887
    /**
604c1d681b6f 8017084: Use spill properties for large object literals
hannesw
parents: 17982
diff changeset
   888
     * Get the number of properties assigned to the this object in this function.
604c1d681b6f 8017084: Use spill properties for large object literals
hannesw
parents: 17982
diff changeset
   889
     * @return number of properties
604c1d681b6f 8017084: Use spill properties for large object literals
hannesw
parents: 17982
diff changeset
   890
     */
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   891
    public int getThisProperties() {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
   892
        return thisProperties;
18852
604c1d681b6f 8017084: Use spill properties for large object literals
hannesw
parents: 17982
diff changeset
   893
    }
604c1d681b6f 8017084: Use spill properties for large object literals
hannesw
parents: 17982
diff changeset
   894
604c1d681b6f 8017084: Use spill properties for large object literals
hannesw
parents: 17982
diff changeset
   895
    /**
18853
25ba8264b427 8019819: scope symbol didn't get a slot in certain cases
attila
parents: 18852
diff changeset
   896
     * Returns true if any of the blocks in this function create their own scope.
25ba8264b427 8019819: scope symbol didn't get a slot in certain cases
attila
parents: 18852
diff changeset
   897
     * @return true if any of the blocks in this function create their own scope.
25ba8264b427 8019819: scope symbol didn't get a slot in certain cases
attila
parents: 18852
diff changeset
   898
     */
25ba8264b427 8019819: scope symbol didn't get a slot in certain cases
attila
parents: 18852
diff changeset
   899
    public boolean hasScopeBlock() {
25ba8264b427 8019819: scope symbol didn't get a slot in certain cases
attila
parents: 18852
diff changeset
   900
        return getFlag(HAS_SCOPE_BLOCK);
25ba8264b427 8019819: scope symbol didn't get a slot in certain cases
attila
parents: 18852
diff changeset
   901
    }
25ba8264b427 8019819: scope symbol didn't get a slot in certain cases
attila
parents: 18852
diff changeset
   902
25ba8264b427 8019819: scope symbol didn't get a slot in certain cases
attila
parents: 18852
diff changeset
   903
    /**
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   904
     * Return the kind of this function
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   905
     * @see FunctionNode.Kind
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   906
     * @return the kind
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   907
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   908
    public Kind getKind() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   909
        return kind;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   910
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   911
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   912
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   913
     * Return the last token for this function's code
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   914
     * @return last token
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   915
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   916
    public long getLastToken() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   917
        return lastToken;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   918
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   919
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   920
    /**
26503
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   921
     * Returns the end parser state for this function.
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   922
     * @return the end parser state for this function.
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   923
     */
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   924
    public Object getEndParserState() {
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   925
        return endParserState;
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   926
    }
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   927
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   928
    /**
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   929
     * Get the name of this function
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   930
     * @return the name
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   931
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   932
    public String getName() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   933
        return name;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   934
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   935
17752
9d2d0e74a833 8013919: Original exception no longer thrown away when a finally rethrows
lagergren
parents: 17524
diff changeset
   936
    /**
9d2d0e74a833 8013919: Original exception no longer thrown away when a finally rethrows
lagergren
parents: 17524
diff changeset
   937
     * Set the internal name for this function
9d2d0e74a833 8013919: Original exception no longer thrown away when a finally rethrows
lagergren
parents: 17524
diff changeset
   938
     * @param lc    lexical context
9d2d0e74a833 8013919: Original exception no longer thrown away when a finally rethrows
lagergren
parents: 17524
diff changeset
   939
     * @param name new name
9d2d0e74a833 8013919: Original exception no longer thrown away when a finally rethrows
lagergren
parents: 17524
diff changeset
   940
     * @return new function node if changed, otherwise the same
9d2d0e74a833 8013919: Original exception no longer thrown away when a finally rethrows
lagergren
parents: 17524
diff changeset
   941
     */
9d2d0e74a833 8013919: Original exception no longer thrown away when a finally rethrows
lagergren
parents: 17524
diff changeset
   942
    public FunctionNode setName(final LexicalContext lc, final String name) {
9d2d0e74a833 8013919: Original exception no longer thrown away when a finally rethrows
lagergren
parents: 17524
diff changeset
   943
        if (this.name.equals(name)) {
9d2d0e74a833 8013919: Original exception no longer thrown away when a finally rethrows
lagergren
parents: 17524
diff changeset
   944
            return this;
9d2d0e74a833 8013919: Original exception no longer thrown away when a finally rethrows
lagergren
parents: 17524
diff changeset
   945
        }
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   946
        return Node.replaceInLexicalContext(
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   947
                lc,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   948
                this,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   949
                new FunctionNode(
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   950
                        this,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   951
                        lastToken,
26503
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
   952
                        endParserState,
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   953
                        flags,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   954
                        name,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   955
                        returnType,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   956
                        compileUnit,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   957
                        body,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   958
                        parameters,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
   959
                        thisProperties,
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   960
                        rootClass, source, namespace));
17752
9d2d0e74a833 8013919: Original exception no longer thrown away when a finally rethrows
lagergren
parents: 17524
diff changeset
   961
    }
9d2d0e74a833 8013919: Original exception no longer thrown away when a finally rethrows
lagergren
parents: 17524
diff changeset
   962
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   963
    /**
26377
028dad61662f 8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents: 26250
diff changeset
   964
     * Check if this function should have all its variables in its own scope. Split sub-functions, and
16206
83069fa0935b 8006529: Methods always get callee - it should be conditional
attila
parents: 16201
diff changeset
   965
     * functions having with and/or eval blocks are such.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   966
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   967
     * @return true if all variables should be in scope
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   968
     */
16252
3bfe9b68a0fa 8008648: Lazy JIT scope and callee semantics bugfixes. Broke out wallclock timer.
lagergren
parents: 16245
diff changeset
   969
    public boolean allVarsInScope() {
26377
028dad61662f 8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents: 26250
diff changeset
   970
        return getFlag(HAS_ALL_VARS_IN_SCOPE);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   971
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   972
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   973
    /**
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   974
     * Checks if this function is split into several smaller fragments.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   975
     *
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
   976
     * @return true if this function is split into several smaller fragments.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   977
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   978
    public boolean isSplit() {
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
   979
        return getFlag(IS_SPLIT);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   980
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   981
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   982
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   983
     * Get the parameters to this function
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   984
     * @return a list of IdentNodes which represent the function parameters, in order
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   985
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   986
    public List<IdentNode> getParameters() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   987
        return Collections.unmodifiableList(parameters);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   988
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   989
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   990
    /**
39662
e2b36a3779b9 8149929: Nashorn Parser API needs to be updated for ES6
sundar
parents: 37732
diff changeset
   991
     * Get the ES6 style parameter expressions of this function. This may be null.
e2b36a3779b9 8149929: Nashorn Parser API needs to be updated for ES6
sundar
parents: 37732
diff changeset
   992
     *
e2b36a3779b9 8149929: Nashorn Parser API needs to be updated for ES6
sundar
parents: 37732
diff changeset
   993
     * @return a Map of parameter IdentNode to Expression node (for ES6 parameter expressions)
e2b36a3779b9 8149929: Nashorn Parser API needs to be updated for ES6
sundar
parents: 37732
diff changeset
   994
     */
e2b36a3779b9 8149929: Nashorn Parser API needs to be updated for ES6
sundar
parents: 37732
diff changeset
   995
    public Map<IdentNode, Expression> getParameterExpressions() {
e2b36a3779b9 8149929: Nashorn Parser API needs to be updated for ES6
sundar
parents: 37732
diff changeset
   996
        return parameterExpressions;
e2b36a3779b9 8149929: Nashorn Parser API needs to be updated for ES6
sundar
parents: 37732
diff changeset
   997
    }
e2b36a3779b9 8149929: Nashorn Parser API needs to be updated for ES6
sundar
parents: 37732
diff changeset
   998
e2b36a3779b9 8149929: Nashorn Parser API needs to be updated for ES6
sundar
parents: 37732
diff changeset
   999
    /**
32434
769b3d81ae69 8134731: Function.prototype.apply interacts incorrectly with arguments
sundar
parents: 28130
diff changeset
  1000
     * Return the number of parameters to this function
769b3d81ae69 8134731: Function.prototype.apply interacts incorrectly with arguments
sundar
parents: 28130
diff changeset
  1001
     * @return the number of parameters
769b3d81ae69 8134731: Function.prototype.apply interacts incorrectly with arguments
sundar
parents: 28130
diff changeset
  1002
     */
769b3d81ae69 8134731: Function.prototype.apply interacts incorrectly with arguments
sundar
parents: 28130
diff changeset
  1003
    public int getNumOfParams() {
769b3d81ae69 8134731: Function.prototype.apply interacts incorrectly with arguments
sundar
parents: 28130
diff changeset
  1004
        return parameters.size();
769b3d81ae69 8134731: Function.prototype.apply interacts incorrectly with arguments
sundar
parents: 28130
diff changeset
  1005
    }
769b3d81ae69 8134731: Function.prototype.apply interacts incorrectly with arguments
sundar
parents: 28130
diff changeset
  1006
769b3d81ae69 8134731: Function.prototype.apply interacts incorrectly with arguments
sundar
parents: 28130
diff changeset
  1007
    /**
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
  1008
     * Returns the identifier for a named parameter at the specified position in this function's parameter list.
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
  1009
     * @param index the parameter's position.
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
  1010
     * @return the identifier for the requested named parameter.
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
  1011
     * @throws IndexOutOfBoundsException if the index is invalid.
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
  1012
     */
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
  1013
    public IdentNode getParameter(final int index) {
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
  1014
        return parameters.get(index);
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
  1015
    }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
  1016
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
  1017
    /**
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
  1018
     * Reset the compile unit used to compile this function
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
  1019
     * @see Compiler
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
  1020
     * @param  lc lexical context
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
  1021
     * @param  parameters the compile unit
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
  1022
     * @return function node or a new one if state was changed
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: 16252
diff changeset
  1023
     */
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
  1024
    public FunctionNode setParameters(final LexicalContext lc, final List<IdentNode> parameters) {
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
        if (this.parameters == parameters) {
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
  1026
            return this;
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
  1027
        }
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1028
        return Node.replaceInLexicalContext(
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1029
                lc,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1030
                this,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1031
                new FunctionNode(
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1032
                        this,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1033
                        lastToken,
26503
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
  1034
                        endParserState,
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1035
                        flags,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1036
                        name,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1037
                        returnType,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1038
                        compileUnit,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1039
                        body,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1040
                        parameters,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1041
                        thisProperties,
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
  1042
                        rootClass, source, namespace));
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1043
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1044
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1045
    /**
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16525
diff changeset
  1046
     * Check if this function is created as a function declaration (as opposed to function expression)
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16525
diff changeset
  1047
     * @return true if function is declared.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1048
     */
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16525
diff changeset
  1049
    public boolean isDeclared() {
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1050
        return getFlag(IS_DECLARED);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1051
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1052
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1053
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1054
     * Check if this function is anonymous
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1055
     * @return true if function is anonymous
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1056
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1057
    public boolean isAnonymous() {
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1058
        return getFlag(IS_ANONYMOUS);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1059
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1060
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1061
    /**
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
  1062
     * Does this function use its self symbol - this is needed only for self-referencing named function expressions.
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
  1063
     * Self-referencing declared functions won't have this flag set, as they can access their own symbol through the
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
  1064
     * scope (since they're bound to the symbol with their name in their enclosing scope).
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
  1065
     * @return true if this function node is a named function expression that uses the symbol for itself.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1066
     */
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
  1067
    public boolean usesSelfSymbol() {
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
  1068
        return getFlag(USES_SELF_SYMBOL);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1069
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1070
27822
a3866b9fb44d 8066222: too strong assertion on function expression names
attila
parents: 27206
diff changeset
  1071
    /**
a3866b9fb44d 8066222: too strong assertion on function expression names
attila
parents: 27206
diff changeset
  1072
     * Returns true if this is a named function expression (that is, it isn't a declared function, it isn't an
a3866b9fb44d 8066222: too strong assertion on function expression names
attila
parents: 27206
diff changeset
  1073
     * anonymous function expression, and it isn't a program).
a3866b9fb44d 8066222: too strong assertion on function expression names
attila
parents: 27206
diff changeset
  1074
     * @return true if this is a named function expression
a3866b9fb44d 8066222: too strong assertion on function expression names
attila
parents: 27206
diff changeset
  1075
     */
a3866b9fb44d 8066222: too strong assertion on function expression names
attila
parents: 27206
diff changeset
  1076
    public boolean isNamedFunctionExpression() {
a3866b9fb44d 8066222: too strong assertion on function expression names
attila
parents: 27206
diff changeset
  1077
        return !getFlag(IS_PROGRAM | IS_ANONYMOUS | IS_DECLARED);
a3866b9fb44d 8066222: too strong assertion on function expression names
attila
parents: 27206
diff changeset
  1078
    }
a3866b9fb44d 8066222: too strong assertion on function expression names
attila
parents: 27206
diff changeset
  1079
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1080
    @Override
28130
433d6755c5f8 8067774: Use a stack of types when calculating local variable types
attila
parents: 27822
diff changeset
  1081
    public Type getType() {
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
  1082
        return FUNCTION_TYPE;
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
  1083
    }
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
  1084
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
  1085
    @Override
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
  1086
    public Type getWidestOperationType() {
16530
201d682e75f4 8010652: Eliminate non-child references in Block/FunctionNode, and make few node types immutable
attila
parents: 16525
diff changeset
  1087
        return FUNCTION_TYPE;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1088
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1089
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1090
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1091
     * Get the return type for this function. Return types can be specialized
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1092
     * if the compiler knows them, but parameters cannot, as they need to go through
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1093
     * appropriate object conversion
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1094
     *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1095
     * @return the return type
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1096
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1097
    public Type getReturnType() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1098
        return returnType;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1099
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1100
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1101
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1102
     * Set the function return type
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1103
     * @param lc lexical context
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1104
     * @param returnType new return type
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1105
     * @return function node or a new one if state was changed
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1106
     */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1107
    public FunctionNode setReturnType(final LexicalContext lc, final Type returnType) {
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1108
        //we never bother with object types narrower than objects, that will lead to byte code verification errors
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1109
        //as for instance even if we know we are returning a string from a method, the code generator will always
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1110
        //treat it as an object, at least for now
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
  1111
        final Type type = returnType.isObject() ? Type.OBJECT : returnType;
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
  1112
        if (this.returnType == type) {
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1113
            return this;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1114
        }
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1115
        return Node.replaceInLexicalContext(
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1116
            lc,
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1117
            this,
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1118
            new FunctionNode(
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1119
                this,
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1120
                lastToken,
26503
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
  1121
                endParserState,
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1122
                flags,
17752
9d2d0e74a833 8013919: Original exception no longer thrown away when a finally rethrows
lagergren
parents: 17524
diff changeset
  1123
                name,
19095
0b215bda525d 8020718: RETURN symbol has wrong type in split functions
hannesw
parents: 19084
diff changeset
  1124
                type,
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1125
                compileUnit,
24751
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
  1126
                body,
ccbd9cd3f720 8042118: Separate types from symbols
attila
parents: 24749
diff changeset
  1127
                parameters,
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1128
                thisProperties,
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
  1129
                rootClass, source, namespace
24725
7bb1f687a852 8033334: Make sure that scope depth information is maintained in the RecompilableScriptFunctionDatas, to avoid unnecessary slow proto linkage when doing on demand compilation
lagergren
parents: 24720
diff changeset
  1130
                ));
24719
f726e9d67629 8035820: Optimistic recompilation
attila
parents: 22390
diff changeset
  1131
   }
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1132
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1133
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1134
     * Check if the function is generated in strict mode
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1135
     * @return true if strict mode enabled for function
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1136
     */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1137
    public boolean isStrict() {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1138
        return getFlag(IS_STRICT);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1139
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1140
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1141
    /**
32435
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 32434
diff changeset
  1142
     * Returns true if this function node has been cached.
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 32434
diff changeset
  1143
     * @return true if this function node has been cached.
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 32434
diff changeset
  1144
     */
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 32434
diff changeset
  1145
    public boolean isCached() {
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 32434
diff changeset
  1146
        return getFlag(IS_CACHED);
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 32434
diff changeset
  1147
    }
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 32434
diff changeset
  1148
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 32434
diff changeset
  1149
    /**
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 32434
diff changeset
  1150
     * Mark this function node as having been cached.
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 32434
diff changeset
  1151
     * @param lc the current lexical context
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 32434
diff changeset
  1152
     * @return a function node equivalent to this one, with the flag set.
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 32434
diff changeset
  1153
     */
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 32434
diff changeset
  1154
    public FunctionNode setCached(final LexicalContext lc) {
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 32434
diff changeset
  1155
        return setFlag(lc, IS_CACHED);
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 32434
diff changeset
  1156
    }
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 32434
diff changeset
  1157
37732
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1158
    /**
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1159
     * Checks if the function is generated in strong mode.
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1160
     *
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1161
     * @return true if strong mode enabled for function
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1162
     */
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1163
    public boolean isStrong() {
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1164
        return getFlag(ES6_IS_STRONG);
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1165
    }
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1166
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1167
    /**
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1168
     * Checks if this is an ES6 method.
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1169
     *
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1170
     * @return true if the ES6 method flag is set
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1171
     */
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1172
    public boolean isMethod() {
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1173
        return getFlag(ES6_IS_METHOD);
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1174
    }
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1175
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1176
    /**
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1177
     * Checks if this function uses the ES6 super binding.
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1178
     *
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1179
     * @return true if the ES6 super flag is set
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1180
     */
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1181
    public boolean usesSuper() {
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1182
        return getFlag(ES6_USES_SUPER);
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1183
    }
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1184
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1185
    /**
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1186
     * Checks if this function directly uses the super binding.
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1187
     *
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1188
     * @return true if the ES6 has-direct-super flag is set
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1189
     */
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1190
    public boolean hasDirectSuper() {
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1191
        return getFlag(ES6_HAS_DIRECT_SUPER);
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1192
    }
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1193
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1194
    /**
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1195
     * Checks if this is an ES6 class constructor.
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1196
     *
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1197
     * @return true if the ES6 class constructor flag is set
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1198
     */
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1199
    public boolean isClassConstructor() {
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1200
        return getFlag(ES6_IS_CLASS_CONSTRUCTOR);
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1201
    }
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1202
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1203
    /**
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1204
     * Checks if this is an ES6 subclass constructor.
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1205
     *
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1206
     * @return true if the ES6 subclass constructor flag is set
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1207
     */
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1208
    public boolean isSubclassConstructor() {
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1209
        return getFlag(ES6_IS_SUBCLASS_CONSTRUCTOR);
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1210
    }
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1211
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1212
    /**
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1213
     * Checks if this function uses the ES6 new-targert.
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1214
     *
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1215
     * @return true if the ES6 new-target flag is set
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1216
     */
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1217
    public boolean usesNewTarget() {
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1218
        return getFlag(ES6_USES_NEW_TARGET);
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1219
    }
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1220
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1221
    /**
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1222
     * Checks if this is an ES6 module.
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1223
     *
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1224
     * @return true if this is an ES6 module
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1225
     */
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1226
    public boolean isModule() {
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1227
        return kind == Kind.MODULE;
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1228
    }
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1229
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1230
    /**
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1231
     * Returns the functions's ES6 module.
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1232
     *
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1233
     * @return the module, or null if this function is not part of one
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1234
     */
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1235
    public Module getModule() {
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1236
        return module;
3673fec68d16 8134503: support ES6 parsing in Nashorn
hannesw
parents: 33888
diff changeset
  1237
    }
32435
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 32434
diff changeset
  1238
cfd619ef23a6 8133300: Ensure symbol table immutability in Nashorn AST
attila
parents: 32434
diff changeset
  1239
    /**
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1240
     * Get the compile unit used to compile this function
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1241
     * @see Compiler
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1242
     * @return the compile unit
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1243
     */
26500
85ea77a73bb8 8057588: Lots of trivial (empty) classes were generated by the Nashorn compiler as part of restOf-method generation
lagergren
parents: 26377
diff changeset
  1244
    @Override
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1245
    public CompileUnit getCompileUnit() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1246
        return compileUnit;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1247
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1248
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1249
    /**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1250
     * Reset the compile unit used to compile this function
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1251
     * @see Compiler
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1252
     * @param lc lexical context
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1253
     * @param compileUnit the compile unit
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1254
     * @return function node or a new one if state was changed
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1255
     */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1256
    public FunctionNode setCompileUnit(final LexicalContext lc, final CompileUnit compileUnit) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1257
        if (this.compileUnit == compileUnit) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1258
            return this;
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1259
        }
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1260
        return Node.replaceInLexicalContext(
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1261
                lc,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1262
                this,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1263
                new FunctionNode(
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1264
                        this,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1265
                        lastToken,
26503
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
  1266
                        endParserState,
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1267
                        flags,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1268
                        name,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1269
                        returnType,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1270
                        compileUnit,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1271
                        body,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1272
                        parameters,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1273
                        thisProperties,
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
  1274
                        rootClass, source, namespace));
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1275
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1276
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1277
    /**
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1278
     * Create a temporary variable to the current frame.
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1279
     *
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1280
     * @param block that needs the temporary
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1281
     * @param type  Strong type of symbol.
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1282
     * @param node  Primary node to use symbol.
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1283
     *
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1284
     * @return Symbol used.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1285
     */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1286
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1287
    /**
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1288
     * Get the symbol for a compiler constant, or null if not available (yet)
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1289
     * @param cc compiler constant
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1290
     * @return symbol for compiler constant, or null if not defined yet (for example in Lower)
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1291
     */
17233
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1292
    public Symbol compilerConstant(final CompilerConstants cc) {
72ccf78a8216 8010701: Immutable nodes - final iteration
lagergren
parents: 16530
diff changeset
  1293
        return body.getExistingSymbol(cc.symbolName());
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1294
    }
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1295
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1296
    /**
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1297
     * Get the root class that this function node compiles to
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1298
     * @return root class
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1299
     */
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1300
    public Class<?> getRootClass() {
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1301
        return rootClass;
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1302
    }
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1303
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1304
    /**
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1305
     * Reset the root class that this function is compiled to
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1306
     * @see Compiler
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1307
     * @param lc lexical context
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1308
     * @param rootClass root class
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1309
     * @return function node or a new one if state was changed
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1310
     */
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1311
    public FunctionNode setRootClass(final LexicalContext lc, final Class<?> rootClass) {
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1312
        if (this.rootClass == rootClass) {
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1313
            return this;
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1314
        }
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1315
        return Node.replaceInLexicalContext(
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1316
                lc,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1317
                this,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1318
                new FunctionNode(
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1319
                        this,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1320
                        lastToken,
26503
3ed48a01100c 8057148: Skip nested functions on reparse
attila
parents: 26500
diff changeset
  1321
                        endParserState,
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1322
                        flags,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1323
                        name,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1324
                        returnType,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1325
                        compileUnit,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1326
                        body,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1327
                        parameters,
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1328
                        thisProperties,
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents: 27204
diff changeset
  1329
                        rootClass, source, namespace));
24759
31aed7d9c02a 8034206: Make parts of code pipeline reusable in order to facilitate faster warmup and faster lazy compilation.
lagergren
parents: 24751
diff changeset
  1330
    }
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
  1331
}