author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 41422 | nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/parser/ParserContextFunctionNode.java@97eda72f53b6 |
permissions | -rw-r--r-- |
27102
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
1 |
/* |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
2 |
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
4 |
* |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
10 |
* |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
15 |
* accompanied this code). |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
16 |
* |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
20 |
* |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
23 |
* questions. |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
24 |
*/ |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
25 |
package jdk.nashorn.internal.parser; |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
26 |
|
39662
e2b36a3779b9
8149929: Nashorn Parser API needs to be updated for ES6
sundar
parents:
37732
diff
changeset
|
27 |
import java.util.HashMap; |
37732 | 28 |
import java.util.HashSet; |
27102
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
29 |
import java.util.List; |
39662
e2b36a3779b9
8149929: Nashorn Parser API needs to be updated for ES6
sundar
parents:
37732
diff
changeset
|
30 |
import java.util.Map; |
27102
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
31 |
import jdk.nashorn.internal.codegen.Namespace; |
39662
e2b36a3779b9
8149929: Nashorn Parser API needs to be updated for ES6
sundar
parents:
37732
diff
changeset
|
32 |
import jdk.nashorn.internal.ir.Expression; |
27102
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
33 |
import jdk.nashorn.internal.ir.FunctionNode; |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
34 |
import jdk.nashorn.internal.ir.IdentNode; |
37732 | 35 |
import jdk.nashorn.internal.ir.Module; |
27102
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
36 |
|
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
37 |
/** |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
38 |
* ParserContextNode that represents a function that is currently being parsed |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
39 |
*/ |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
40 |
class ParserContextFunctionNode extends ParserContextBaseNode { |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
41 |
|
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
42 |
/** Function name */ |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
43 |
private final String name; |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
44 |
|
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
45 |
/** Function identifier node */ |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
46 |
private final IdentNode ident; |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
47 |
|
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
48 |
/** Name space for function */ |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
49 |
private final Namespace namespace; |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
50 |
|
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
51 |
/** Line number for function declaration */ |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
52 |
private final int line; |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
53 |
|
37732 | 54 |
/** Function node kind, see {@link FunctionNode.Kind} */ |
27102
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
55 |
private final FunctionNode.Kind kind; |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
56 |
|
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
57 |
/** List of parameter identifiers for function */ |
37732 | 58 |
private List<IdentNode> parameters; |
27102
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
59 |
|
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
60 |
/** Token for function start */ |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
61 |
private final long token; |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
62 |
|
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
63 |
/** Last function token */ |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
64 |
private long lastToken; |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
65 |
|
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
66 |
/** Opaque node for parser end state, see {@link Parser} */ |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
67 |
private Object endParserState; |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
68 |
|
37732 | 69 |
private HashSet<String> parameterBoundNames; |
70 |
private IdentNode duplicateParameterBinding; |
|
71 |
private boolean simpleParameterList = true; |
|
72 |
||
73 |
private Module module; |
|
74 |
||
75 |
private int debugFlags; |
|
39662
e2b36a3779b9
8149929: Nashorn Parser API needs to be updated for ES6
sundar
parents:
37732
diff
changeset
|
76 |
private Map<IdentNode, Expression> parameterExpressions; |
37732 | 77 |
|
27102
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
78 |
/** |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
79 |
* @param token The token for the function |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
80 |
* @param ident External function name |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
81 |
* @param name Internal name of the function |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
82 |
* @param namespace Function's namespace |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
83 |
* @param line The source line of the function |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
84 |
* @param kind Function kind |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
85 |
* @param parameters The parameters of the function |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
86 |
*/ |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
87 |
public ParserContextFunctionNode(final long token, final IdentNode ident, final String name, final Namespace namespace, final int line, final FunctionNode.Kind kind, final List<IdentNode> parameters) { |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
88 |
this.ident = ident; |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
89 |
this.namespace = namespace; |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
90 |
this.line = line; |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
91 |
this.kind = kind; |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
92 |
this.name = name; |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
93 |
this.parameters = parameters; |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
94 |
this.token = token; |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
95 |
} |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
96 |
|
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
97 |
/** |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
98 |
* @return Internal name of the function |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
99 |
*/ |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
100 |
public String getName() { |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
101 |
return name; |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
102 |
} |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
103 |
|
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
104 |
/** |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
105 |
* @return The external identifier for the function |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
106 |
*/ |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
107 |
public IdentNode getIdent() { |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
108 |
return ident; |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
109 |
} |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
110 |
|
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
111 |
/** |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
112 |
* |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
113 |
* @return true if function is the program function |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
114 |
*/ |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
115 |
public boolean isProgram() { |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
116 |
return getFlag(FunctionNode.IS_PROGRAM) != 0; |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
117 |
} |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
118 |
|
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
119 |
/** |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
120 |
* @return if function in strict mode |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
121 |
*/ |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
122 |
public boolean isStrict() { |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
123 |
return getFlag(FunctionNode.IS_STRICT) != 0; |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
124 |
} |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
125 |
|
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
126 |
/** |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
127 |
* @return true if the function has nested evals |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
128 |
*/ |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
129 |
public boolean hasNestedEval() { |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
130 |
return getFlag(FunctionNode.HAS_NESTED_EVAL) != 0; |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
131 |
} |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
132 |
|
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
133 |
/** |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
134 |
* Returns true if any of the blocks in this function create their own scope. |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
135 |
* @return true if any of the blocks in this function create their own scope. |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
136 |
*/ |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
137 |
public boolean hasScopeBlock() { |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
138 |
return getFlag(FunctionNode.HAS_SCOPE_BLOCK) != 0; |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
139 |
} |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
140 |
|
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
141 |
/** |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
142 |
* Create a unique name in the namespace of this FunctionNode |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
143 |
* @param base prefix for name |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
144 |
* @return base if no collision exists, otherwise a name prefix with base |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
145 |
*/ |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
146 |
public String uniqueName(final String base) { |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
147 |
return namespace.uniqueName(base); |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
148 |
} |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
149 |
|
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
150 |
/** |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
151 |
* @return line number of the function |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
152 |
*/ |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
153 |
public int getLineNumber() { |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
154 |
return line; |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
155 |
} |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
156 |
|
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
157 |
/** |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
158 |
* @return The kind if function |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
159 |
*/ |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
160 |
public FunctionNode.Kind getKind() { |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
161 |
return kind; |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
162 |
} |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
163 |
|
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
164 |
/** |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
165 |
* Get parameters |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
166 |
* @return The parameters of the function |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
167 |
*/ |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
168 |
public List<IdentNode> getParameters() { |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
169 |
return parameters; |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
170 |
} |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
171 |
|
41422 | 172 |
void setParameters(final List<IdentNode> parameters) { |
37732 | 173 |
this.parameters = parameters; |
174 |
} |
|
175 |
||
27102
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
176 |
/** |
39662
e2b36a3779b9
8149929: Nashorn Parser API needs to be updated for ES6
sundar
parents:
37732
diff
changeset
|
177 |
* Return ES6 function parameter expressions |
e2b36a3779b9
8149929: Nashorn Parser API needs to be updated for ES6
sundar
parents:
37732
diff
changeset
|
178 |
* |
e2b36a3779b9
8149929: Nashorn Parser API needs to be updated for ES6
sundar
parents:
37732
diff
changeset
|
179 |
* @return ES6 function parameter expressions |
e2b36a3779b9
8149929: Nashorn Parser API needs to be updated for ES6
sundar
parents:
37732
diff
changeset
|
180 |
*/ |
e2b36a3779b9
8149929: Nashorn Parser API needs to be updated for ES6
sundar
parents:
37732
diff
changeset
|
181 |
public Map<IdentNode, Expression> getParameterExpressions() { |
e2b36a3779b9
8149929: Nashorn Parser API needs to be updated for ES6
sundar
parents:
37732
diff
changeset
|
182 |
return parameterExpressions; |
e2b36a3779b9
8149929: Nashorn Parser API needs to be updated for ES6
sundar
parents:
37732
diff
changeset
|
183 |
} |
e2b36a3779b9
8149929: Nashorn Parser API needs to be updated for ES6
sundar
parents:
37732
diff
changeset
|
184 |
|
41422 | 185 |
void addParameterExpression(final IdentNode ident, final Expression node) { |
39662
e2b36a3779b9
8149929: Nashorn Parser API needs to be updated for ES6
sundar
parents:
37732
diff
changeset
|
186 |
if (parameterExpressions == null) { |
e2b36a3779b9
8149929: Nashorn Parser API needs to be updated for ES6
sundar
parents:
37732
diff
changeset
|
187 |
parameterExpressions = new HashMap<>(); |
e2b36a3779b9
8149929: Nashorn Parser API needs to be updated for ES6
sundar
parents:
37732
diff
changeset
|
188 |
} |
e2b36a3779b9
8149929: Nashorn Parser API needs to be updated for ES6
sundar
parents:
37732
diff
changeset
|
189 |
parameterExpressions.put(ident, node); |
e2b36a3779b9
8149929: Nashorn Parser API needs to be updated for ES6
sundar
parents:
37732
diff
changeset
|
190 |
} |
e2b36a3779b9
8149929: Nashorn Parser API needs to be updated for ES6
sundar
parents:
37732
diff
changeset
|
191 |
|
e2b36a3779b9
8149929: Nashorn Parser API needs to be updated for ES6
sundar
parents:
37732
diff
changeset
|
192 |
/** |
27102
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
193 |
* Set last token |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
194 |
* @param token New last token |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
195 |
*/ |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
196 |
public void setLastToken(final long token) { |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
197 |
this.lastToken = token; |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
198 |
|
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
199 |
} |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
200 |
|
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
201 |
/** |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
202 |
* @return lastToken Function's last token |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
203 |
*/ |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
204 |
public long getLastToken() { |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
205 |
return lastToken; |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
206 |
} |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
207 |
|
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
208 |
/** |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
209 |
* Returns the ParserState of when the parsing of this function was ended |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
210 |
* @return endParserState The end parser state |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
211 |
*/ |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
212 |
public Object getEndParserState() { |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
213 |
return endParserState; |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
214 |
} |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
215 |
|
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
216 |
/** |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
217 |
* Sets the ParserState of when the parsing of this function was ended |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
218 |
* @param endParserState The end parser state |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
219 |
*/ |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
220 |
public void setEndParserState(final Object endParserState) { |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
221 |
this.endParserState = endParserState; |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
222 |
} |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
223 |
|
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
224 |
/** |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
225 |
* Returns the if of this function |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
226 |
* @return The function id |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
227 |
*/ |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
228 |
public int getId() { |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
229 |
return isProgram() ? -1 : Token.descPosition(token); |
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
230 |
} |
37732 | 231 |
|
232 |
/** |
|
233 |
* Returns the debug flags for this function. |
|
234 |
* |
|
235 |
* @return the debug flags |
|
236 |
*/ |
|
237 |
int getDebugFlags() { |
|
238 |
return debugFlags; |
|
239 |
} |
|
240 |
||
241 |
/** |
|
242 |
* Sets a debug flag for this function. |
|
243 |
* |
|
244 |
* @param debugFlag the debug flag |
|
245 |
*/ |
|
246 |
void setDebugFlag(final int debugFlag) { |
|
247 |
debugFlags |= debugFlag; |
|
248 |
} |
|
249 |
||
250 |
public boolean isMethod() { |
|
251 |
return getFlag(FunctionNode.ES6_IS_METHOD) != 0; |
|
252 |
} |
|
253 |
||
254 |
public boolean isClassConstructor() { |
|
255 |
return getFlag(FunctionNode.ES6_IS_CLASS_CONSTRUCTOR) != 0; |
|
256 |
} |
|
257 |
||
258 |
public boolean isSubclassConstructor() { |
|
259 |
return getFlag(FunctionNode.ES6_IS_SUBCLASS_CONSTRUCTOR) != 0; |
|
260 |
} |
|
261 |
||
262 |
boolean addParameterBinding(final IdentNode bindingIdentifier) { |
|
263 |
if (Parser.isArguments(bindingIdentifier)) { |
|
264 |
setFlag(FunctionNode.DEFINES_ARGUMENTS); |
|
265 |
} |
|
266 |
||
267 |
if (parameterBoundNames == null) { |
|
268 |
parameterBoundNames = new HashSet<>(); |
|
269 |
} |
|
270 |
if (parameterBoundNames.add(bindingIdentifier.getName())) { |
|
271 |
return true; |
|
272 |
} else { |
|
273 |
duplicateParameterBinding = bindingIdentifier; |
|
274 |
return false; |
|
275 |
} |
|
276 |
} |
|
277 |
||
278 |
public IdentNode getDuplicateParameterBinding() { |
|
279 |
return duplicateParameterBinding; |
|
280 |
} |
|
281 |
||
282 |
public boolean isSimpleParameterList() { |
|
283 |
return simpleParameterList; |
|
284 |
} |
|
285 |
||
286 |
public void setSimpleParameterList(final boolean simpleParameterList) { |
|
287 |
this.simpleParameterList = simpleParameterList; |
|
288 |
} |
|
289 |
||
290 |
public Module getModule() { |
|
291 |
return module; |
|
292 |
} |
|
293 |
||
294 |
public void setModule(final Module module) { |
|
295 |
this.module = module; |
|
296 |
} |
|
27102
c64b3468d51d
8012518: Reengineer Parser.java to make it play well with the copy-on-write IR.
lagergren
parents:
diff
changeset
|
297 |
} |