< prev index next >

src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/parser/ParserContextFunctionNode.java

Print this page




   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package jdk.nashorn.internal.parser;
  26 

  27 import java.util.List;
  28 import jdk.nashorn.internal.codegen.Namespace;
  29 import jdk.nashorn.internal.ir.FunctionNode;
  30 import jdk.nashorn.internal.ir.IdentNode;

  31 
  32 /**
  33  * ParserContextNode that represents a function that is currently being parsed
  34  */
  35 class ParserContextFunctionNode extends ParserContextBaseNode {
  36 
  37     /** Function name */
  38     private final String name;
  39 
  40     /** Function identifier node */
  41     private final IdentNode ident;
  42 
  43     /** Name space for function */
  44     private final Namespace namespace;
  45 
  46     /** Line number for function declaration */
  47     private final int line;
  48 
  49     /** Function node kind, see {@link FunctionNode#Kind} */
  50     private final FunctionNode.Kind kind;
  51 
  52     /** List of parameter identifiers for function */
  53     private final List<IdentNode> parameters;
  54 
  55     /** Token for function start */
  56     private final long token;
  57 
  58     /** Last function token */
  59     private long lastToken;
  60 
  61     /** Opaque node for parser end state, see {@link Parser} */
  62     private Object endParserState;
  63 








  64     /**
  65      * @param token The token for the function
  66      * @param ident External function name
  67      * @param name  Internal name of the function
  68      * @param namespace Function's namespace
  69      * @param line  The source line of the function
  70      * @param kind  Function kind
  71      * @param parameters The parameters of the function
  72      */
  73     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) {
  74         this.ident      = ident;
  75         this.namespace  = namespace;
  76         this.line       = line;
  77         this.kind       = kind;
  78         this.name       = name;
  79         this.parameters = parameters;
  80         this.token      = token;
  81     }
  82 
  83     /**


 138      */
 139     public int getLineNumber() {
 140         return line;
 141     }
 142 
 143     /**
 144      * @return The kind if function
 145      */
 146     public FunctionNode.Kind getKind() {
 147         return kind;
 148     }
 149 
 150     /**
 151      * Get parameters
 152      * @return The parameters of the function
 153      */
 154     public List<IdentNode> getParameters() {
 155         return parameters;
 156     }
 157 




 158     /**
 159      * Set last token
 160      * @param token New last token
 161      */
 162     public void setLastToken(final long token) {
 163         this.lastToken = token;
 164 
 165     }
 166 
 167     /**
 168      * @return lastToken Function's last token
 169      */
 170     public long getLastToken() {
 171         return lastToken;
 172     }
 173 
 174     /**
 175      * Returns the ParserState of when the parsing of this function was ended
 176      * @return endParserState The end parser state
 177      */
 178     public Object getEndParserState() {
 179         return endParserState;
 180     }
 181 
 182     /**
 183      * Sets the ParserState of when the parsing of this function was ended
 184      * @param endParserState The end parser state
 185      */
 186     public void setEndParserState(final Object endParserState) {
 187         this.endParserState = endParserState;
 188     }
 189 
 190     /**
 191      * Returns the if of this function
 192      * @return The function id
 193      */
 194     public int getId() {
 195         return isProgram() ? -1 : Token.descPosition(token);


































































 196     }
 197 }


   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package jdk.nashorn.internal.parser;
  26 
  27 import java.util.HashSet;
  28 import java.util.List;
  29 import jdk.nashorn.internal.codegen.Namespace;
  30 import jdk.nashorn.internal.ir.FunctionNode;
  31 import jdk.nashorn.internal.ir.IdentNode;
  32 import jdk.nashorn.internal.ir.Module;
  33 
  34 /**
  35  * ParserContextNode that represents a function that is currently being parsed
  36  */
  37 class ParserContextFunctionNode extends ParserContextBaseNode {
  38 
  39     /** Function name */
  40     private final String name;
  41 
  42     /** Function identifier node */
  43     private final IdentNode ident;
  44 
  45     /** Name space for function */
  46     private final Namespace namespace;
  47 
  48     /** Line number for function declaration */
  49     private final int line;
  50 
  51     /** Function node kind, see {@link FunctionNode.Kind} */
  52     private final FunctionNode.Kind kind;
  53 
  54     /** List of parameter identifiers for function */
  55     private List<IdentNode> parameters;
  56 
  57     /** Token for function start */
  58     private final long token;
  59 
  60     /** Last function token */
  61     private long lastToken;
  62 
  63     /** Opaque node for parser end state, see {@link Parser} */
  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;
  73 
  74     /**
  75      * @param token The token for the function
  76      * @param ident External function name
  77      * @param name  Internal name of the function
  78      * @param namespace Function's namespace
  79      * @param line  The source line of the function
  80      * @param kind  Function kind
  81      * @param parameters The parameters of the function
  82      */
  83     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) {
  84         this.ident      = ident;
  85         this.namespace  = namespace;
  86         this.line       = line;
  87         this.kind       = kind;
  88         this.name       = name;
  89         this.parameters = parameters;
  90         this.token      = token;
  91     }
  92 
  93     /**


 148      */
 149     public int getLineNumber() {
 150         return line;
 151     }
 152 
 153     /**
 154      * @return The kind if function
 155      */
 156     public FunctionNode.Kind getKind() {
 157         return kind;
 158     }
 159 
 160     /**
 161      * Get parameters
 162      * @return The parameters of the function
 163      */
 164     public List<IdentNode> getParameters() {
 165         return parameters;
 166     }
 167 
 168     void setParameters(List<IdentNode> parameters) {
 169         this.parameters = parameters;
 170     }
 171 
 172     /**
 173      * Set last token
 174      * @param token New last token
 175      */
 176     public void setLastToken(final long token) {
 177         this.lastToken = token;
 178 
 179     }
 180 
 181     /**
 182      * @return lastToken Function's last token
 183      */
 184     public long getLastToken() {
 185         return lastToken;
 186     }
 187 
 188     /**
 189      * Returns the ParserState of when the parsing of this function was ended
 190      * @return endParserState The end parser state
 191      */
 192     public Object getEndParserState() {
 193         return endParserState;
 194     }
 195 
 196     /**
 197      * Sets the ParserState of when the parsing of this function was ended
 198      * @param endParserState The end parser state
 199      */
 200     public void setEndParserState(final Object endParserState) {
 201         this.endParserState = endParserState;
 202     }
 203 
 204     /**
 205      * Returns the if of this function
 206      * @return The function id
 207      */
 208     public int getId() {
 209         return isProgram() ? -1 : Token.descPosition(token);
 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     }
 277 }
< prev index next >