< prev index next >
src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/parser/ParserContextFunctionNode.java
Print this page
@@ -22,14 +22,16 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package jdk.nashorn.internal.parser;
+import java.util.HashSet;
import java.util.List;
import jdk.nashorn.internal.codegen.Namespace;
import jdk.nashorn.internal.ir.FunctionNode;
import jdk.nashorn.internal.ir.IdentNode;
+import jdk.nashorn.internal.ir.Module;
/**
* ParserContextNode that represents a function that is currently being parsed
*/
class ParserContextFunctionNode extends ParserContextBaseNode {
@@ -44,25 +46,33 @@
private final Namespace namespace;
/** Line number for function declaration */
private final int line;
- /** Function node kind, see {@link FunctionNode#Kind} */
+ /** Function node kind, see {@link FunctionNode.Kind} */
private final FunctionNode.Kind kind;
/** List of parameter identifiers for function */
- private final List<IdentNode> parameters;
+ private List<IdentNode> parameters;
/** Token for function start */
private final long token;
/** Last function token */
private long lastToken;
/** Opaque node for parser end state, see {@link Parser} */
private Object endParserState;
+ private HashSet<String> parameterBoundNames;
+ private IdentNode duplicateParameterBinding;
+ private boolean simpleParameterList = true;
+
+ private Module module;
+
+ private int debugFlags;
+
/**
* @param token The token for the function
* @param ident External function name
* @param name Internal name of the function
* @param namespace Function's namespace
@@ -153,10 +163,14 @@
*/
public List<IdentNode> getParameters() {
return parameters;
}
+ void setParameters(List<IdentNode> parameters) {
+ this.parameters = parameters;
+ }
+
/**
* Set last token
* @param token New last token
*/
public void setLastToken(final long token) {
@@ -192,6 +206,72 @@
* @return The function id
*/
public int getId() {
return isProgram() ? -1 : Token.descPosition(token);
}
+
+ /**
+ * Returns the debug flags for this function.
+ *
+ * @return the debug flags
+ */
+ int getDebugFlags() {
+ return debugFlags;
+ }
+
+ /**
+ * Sets a debug flag for this function.
+ *
+ * @param debugFlag the debug flag
+ */
+ void setDebugFlag(final int debugFlag) {
+ debugFlags |= debugFlag;
+ }
+
+ public boolean isMethod() {
+ return getFlag(FunctionNode.ES6_IS_METHOD) != 0;
+ }
+
+ public boolean isClassConstructor() {
+ return getFlag(FunctionNode.ES6_IS_CLASS_CONSTRUCTOR) != 0;
+ }
+
+ public boolean isSubclassConstructor() {
+ return getFlag(FunctionNode.ES6_IS_SUBCLASS_CONSTRUCTOR) != 0;
+ }
+
+ boolean addParameterBinding(final IdentNode bindingIdentifier) {
+ if (Parser.isArguments(bindingIdentifier)) {
+ setFlag(FunctionNode.DEFINES_ARGUMENTS);
+ }
+
+ if (parameterBoundNames == null) {
+ parameterBoundNames = new HashSet<>();
+ }
+ if (parameterBoundNames.add(bindingIdentifier.getName())) {
+ return true;
+ } else {
+ duplicateParameterBinding = bindingIdentifier;
+ return false;
+ }
+ }
+
+ public IdentNode getDuplicateParameterBinding() {
+ return duplicateParameterBinding;
+ }
+
+ public boolean isSimpleParameterList() {
+ return simpleParameterList;
+ }
+
+ public void setSimpleParameterList(final boolean simpleParameterList) {
+ this.simpleParameterList = simpleParameterList;
+ }
+
+ public Module getModule() {
+ return module;
+ }
+
+ public void setModule(final Module module) {
+ this.module = module;
+ }
}
< prev index next >