nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/parser/ParserContextFunctionNode.java
changeset 37732 3673fec68d16
parent 27102 c64b3468d51d
child 39662 e2b36a3779b9
equal deleted inserted replaced
37646:84aba7335005 37732:3673fec68d16
    22  * or visit www.oracle.com if you need additional information or have any
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    23  * questions.
    24  */
    24  */
    25 package jdk.nashorn.internal.parser;
    25 package jdk.nashorn.internal.parser;
    26 
    26 
       
    27 import java.util.HashSet;
    27 import java.util.List;
    28 import java.util.List;
    28 import jdk.nashorn.internal.codegen.Namespace;
    29 import jdk.nashorn.internal.codegen.Namespace;
    29 import jdk.nashorn.internal.ir.FunctionNode;
    30 import jdk.nashorn.internal.ir.FunctionNode;
    30 import jdk.nashorn.internal.ir.IdentNode;
    31 import jdk.nashorn.internal.ir.IdentNode;
       
    32 import jdk.nashorn.internal.ir.Module;
    31 
    33 
    32 /**
    34 /**
    33  * ParserContextNode that represents a function that is currently being parsed
    35  * ParserContextNode that represents a function that is currently being parsed
    34  */
    36  */
    35 class ParserContextFunctionNode extends ParserContextBaseNode {
    37 class ParserContextFunctionNode extends ParserContextBaseNode {
    44     private final Namespace namespace;
    46     private final Namespace namespace;
    45 
    47 
    46     /** Line number for function declaration */
    48     /** Line number for function declaration */
    47     private final int line;
    49     private final int line;
    48 
    50 
    49     /** Function node kind, see {@link FunctionNode#Kind} */
    51     /** Function node kind, see {@link FunctionNode.Kind} */
    50     private final FunctionNode.Kind kind;
    52     private final FunctionNode.Kind kind;
    51 
    53 
    52     /** List of parameter identifiers for function */
    54     /** List of parameter identifiers for function */
    53     private final List<IdentNode> parameters;
    55     private List<IdentNode> parameters;
    54 
    56 
    55     /** Token for function start */
    57     /** Token for function start */
    56     private final long token;
    58     private final long token;
    57 
    59 
    58     /** Last function token */
    60     /** Last function token */
    59     private long lastToken;
    61     private long lastToken;
    60 
    62 
    61     /** Opaque node for parser end state, see {@link Parser} */
    63     /** Opaque node for parser end state, see {@link Parser} */
    62     private Object endParserState;
    64     private Object endParserState;
       
    65 
       
    66     private HashSet<String> parameterBoundNames;
       
    67     private IdentNode duplicateParameterBinding;
       
    68     private boolean simpleParameterList = true;
       
    69 
       
    70     private Module module;
       
    71 
       
    72     private int debugFlags;
    63 
    73 
    64     /**
    74     /**
    65      * @param token The token for the function
    75      * @param token The token for the function
    66      * @param ident External function name
    76      * @param ident External function name
    67      * @param name  Internal name of the function
    77      * @param name  Internal name of the function
   153      */
   163      */
   154     public List<IdentNode> getParameters() {
   164     public List<IdentNode> getParameters() {
   155         return parameters;
   165         return parameters;
   156     }
   166     }
   157 
   167 
       
   168     void setParameters(List<IdentNode> parameters) {
       
   169         this.parameters = parameters;
       
   170     }
       
   171 
   158     /**
   172     /**
   159      * Set last token
   173      * Set last token
   160      * @param token New last token
   174      * @param token New last token
   161      */
   175      */
   162     public void setLastToken(final long token) {
   176     public void setLastToken(final long token) {
   192      * @return The function id
   206      * @return The function id
   193      */
   207      */
   194     public int getId() {
   208     public int getId() {
   195         return isProgram() ? -1 : Token.descPosition(token);
   209         return isProgram() ? -1 : Token.descPosition(token);
   196     }
   210     }
       
   211 
       
   212     /**
       
   213      * Returns the debug flags for this function.
       
   214      *
       
   215      * @return the debug flags
       
   216      */
       
   217     int getDebugFlags() {
       
   218         return debugFlags;
       
   219     }
       
   220 
       
   221     /**
       
   222      * Sets a debug flag for this function.
       
   223      *
       
   224      * @param debugFlag the debug flag
       
   225      */
       
   226     void setDebugFlag(final int debugFlag) {
       
   227         debugFlags |= debugFlag;
       
   228     }
       
   229 
       
   230     public boolean isMethod() {
       
   231         return getFlag(FunctionNode.ES6_IS_METHOD) != 0;
       
   232     }
       
   233 
       
   234     public boolean isClassConstructor() {
       
   235         return getFlag(FunctionNode.ES6_IS_CLASS_CONSTRUCTOR) != 0;
       
   236     }
       
   237 
       
   238     public boolean isSubclassConstructor() {
       
   239         return getFlag(FunctionNode.ES6_IS_SUBCLASS_CONSTRUCTOR) != 0;
       
   240     }
       
   241 
       
   242     boolean addParameterBinding(final IdentNode bindingIdentifier) {
       
   243         if (Parser.isArguments(bindingIdentifier)) {
       
   244             setFlag(FunctionNode.DEFINES_ARGUMENTS);
       
   245         }
       
   246 
       
   247         if (parameterBoundNames == null) {
       
   248             parameterBoundNames = new HashSet<>();
       
   249         }
       
   250         if (parameterBoundNames.add(bindingIdentifier.getName())) {
       
   251             return true;
       
   252         } else {
       
   253             duplicateParameterBinding = bindingIdentifier;
       
   254             return false;
       
   255         }
       
   256     }
       
   257 
       
   258     public IdentNode getDuplicateParameterBinding() {
       
   259         return duplicateParameterBinding;
       
   260     }
       
   261 
       
   262     public boolean isSimpleParameterList() {
       
   263         return simpleParameterList;
       
   264     }
       
   265 
       
   266     public void setSimpleParameterList(final boolean simpleParameterList) {
       
   267         this.simpleParameterList = simpleParameterList;
       
   268     }
       
   269 
       
   270     public Module getModule() {
       
   271         return module;
       
   272     }
       
   273 
       
   274     public void setModule(final Module module) {
       
   275         this.module = module;
       
   276     }
   197 }
   277 }