Java Code Examples for jdk.nashorn.internal.ir.FunctionNode#Kind
The following examples show how to use
jdk.nashorn.internal.ir.FunctionNode#Kind .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RecompilableScriptFunctionData.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
private static String functionName(final FunctionNode fn) { if (fn.isAnonymous()) { return ""; } final FunctionNode.Kind kind = fn.getKind(); if (kind == FunctionNode.Kind.GETTER || kind == FunctionNode.Kind.SETTER) { final String name = NameCodec.decode(fn.getIdent().getName()); return name.substring(GET_SET_PREFIX_LENGTH); } return fn.getIdent().getName(); }
Example 2
Source File: ParserContextFunctionNode.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * @param token The token for the function * @param ident External function name * @param name Internal name of the function * @param namespace Function's namespace * @param line The source line of the function * @param kind Function kind * @param parameters The parameters of the function */ 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) { this.ident = ident; this.namespace = namespace; this.line = line; this.kind = kind; this.name = name; this.parameters = parameters; this.token = token; }
Example 3
Source File: RecompilableScriptFunctionData.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
private static String functionName(final FunctionNode fn) { if (fn.isAnonymous()) { return ""; } final FunctionNode.Kind kind = fn.getKind(); if (kind == FunctionNode.Kind.GETTER || kind == FunctionNode.Kind.SETTER) { final String name = NameCodec.decode(fn.getIdent().getName()); return name.substring(GET_SET_PREFIX_LENGTH); } return fn.getIdent().getName(); }
Example 4
Source File: RecompilableScriptFunctionData.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
private static String functionName(final FunctionNode fn) { if (fn.isAnonymous()) { return ""; } final FunctionNode.Kind kind = fn.getKind(); if (kind == FunctionNode.Kind.GETTER || kind == FunctionNode.Kind.SETTER) { final String name = NameCodec.decode(fn.getIdent().getName()); return name.substring(GET_SET_PREFIX_LENGTH); } return fn.getIdent().getName(); }
Example 5
Source File: Parser.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
/** * Set up a new function block. * * @param ident Name of function. * @return New block. */ private FunctionNode newFunctionNode(final long startToken, final IdentNode ident, final List<IdentNode> parameters, final FunctionNode.Kind kind, final int functionLine) { // Build function name. final StringBuilder sb = new StringBuilder(); final FunctionNode parentFunction = lc.getCurrentFunction(); if (parentFunction != null && !parentFunction.isProgram()) { sb.append(parentFunction.getName()).append('$'); } assert ident.getName() != null; sb.append(ident.getName()); final String name = namespace.uniqueName(sb.toString()); assert parentFunction != null || name.equals(PROGRAM.symbolName()) || name.startsWith(RecompilableScriptFunctionData.RECOMPILATION_PREFIX) : "name = " + name; int flags = 0; if (isStrictMode) { flags |= FunctionNode.IS_STRICT; } if (parentFunction == null) { flags |= FunctionNode.IS_PROGRAM; } // Start new block. final FunctionNode functionNode = new FunctionNode( source, functionLine, token, Token.descPosition(token), startToken, namespace, ident, name, parameters, kind, flags); lc.push(functionNode); // Create new block, and just put it on the context stack, restoreFunctionNode() will associate it with the // FunctionNode. newBlock(); return functionNode; }
Example 6
Source File: JSONWriter.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
@Override public boolean enterFunctionNode(final FunctionNode functionNode) { final boolean program = functionNode.isProgram(); if (program) { return emitProgram(functionNode); } enterDefault(functionNode); final String name; if (functionNode.isDeclared()) { name = "FunctionDeclaration"; } else { name = "FunctionExpression"; } type(name); comma(); property("id"); final FunctionNode.Kind kind = functionNode.getKind(); if (functionNode.isAnonymous() || kind == FunctionNode.Kind.GETTER || kind == FunctionNode.Kind.SETTER) { nullValue(); } else { functionNode.getIdent().accept(this); } comma(); array("params", functionNode.getParameters()); comma(); arrayStart("defaults"); arrayEnd(); comma(); property("rest"); nullValue(); comma(); property("body"); functionNode.getBody().accept(this); comma(); property("generator", false); comma(); property("expression", false); return leave(); }
Example 7
Source File: JSONWriter.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
@Override public boolean enterFunctionNode(final FunctionNode functionNode) { final boolean program = functionNode.isProgram(); if (program) { return emitProgram(functionNode); } enterDefault(functionNode); final String name; if (functionNode.isDeclared()) { name = "FunctionDeclaration"; } else { name = "FunctionExpression"; } type(name); comma(); property("id"); final FunctionNode.Kind kind = functionNode.getKind(); if (functionNode.isAnonymous() || kind == FunctionNode.Kind.GETTER || kind == FunctionNode.Kind.SETTER) { nullValue(); } else { functionNode.getIdent().accept(this); } comma(); array("params", functionNode.getParameters()); comma(); arrayStart("defaults"); arrayEnd(); comma(); property("rest"); nullValue(); comma(); property("body"); functionNode.getBody().accept(this); comma(); property("generator", false); comma(); property("expression", false); return leave(); }
Example 8
Source File: JSONWriter.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
@Override public boolean enterFunctionNode(final FunctionNode functionNode) { final boolean program = functionNode.isProgram(); if (program) { return emitProgram(functionNode); } enterDefault(functionNode); final String name; if (functionNode.isDeclared()) { name = "FunctionDeclaration"; } else { name = "FunctionExpression"; } type(name); comma(); property("id"); final FunctionNode.Kind kind = functionNode.getKind(); if (functionNode.isAnonymous() || kind == FunctionNode.Kind.GETTER || kind == FunctionNode.Kind.SETTER) { nullValue(); } else { functionNode.getIdent().accept(this); } comma(); array("params", functionNode.getParameters()); comma(); arrayStart("defaults"); arrayEnd(); comma(); property("rest"); nullValue(); comma(); property("body"); functionNode.getBody().accept(this); comma(); property("generator", false); comma(); property("expression", false); return leave(); }
Example 9
Source File: JSONWriter.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
@Override public boolean enterFunctionNode(final FunctionNode functionNode) { final boolean program = functionNode.isProgram(); if (program) { return emitProgram(functionNode); } enterDefault(functionNode); final String name; if (functionNode.isDeclared()) { name = "FunctionDeclaration"; } else { name = "FunctionExpression"; } type(name); comma(); property("id"); final FunctionNode.Kind kind = functionNode.getKind(); if (functionNode.isAnonymous() || kind == FunctionNode.Kind.GETTER || kind == FunctionNode.Kind.SETTER) { nullValue(); } else { functionNode.getIdent().accept(this); } comma(); array("params", functionNode.getParameters()); comma(); arrayStart("defaults"); arrayEnd(); comma(); property("rest"); nullValue(); comma(); property("body"); functionNode.getBody().accept(this); comma(); property("generator", false); comma(); property("expression", false); return leave(); }
Example 10
Source File: Parser.java From nashorn with GNU General Public License v2.0 | 4 votes |
/** * FunctionBody : * SourceElements? * * See 13 * * Parse function body. * @return function node (body.) */ private FunctionNode functionBody(final long firstToken, final IdentNode ident, final List<IdentNode> parameters, final FunctionNode.Kind kind) { FunctionNode functionNode = null; long lastToken = 0L; try { // Create a new function block. functionNode = newFunctionNode(firstToken, ident, parameters, kind); // Nashorn extension: expression closures if (!env._no_syntax_extensions && type != LBRACE) { /* * Example: * * function square(x) x * x; * print(square(3)); */ // just expression as function body final Expression expr = assignmentExpression(true); assert lc.getCurrentBlock() == lc.getFunctionBody(functionNode); final ReturnNode returnNode = new ReturnNode(functionNode.getLineNumber(), expr.getToken(), finish, expr); appendStatement(returnNode); lastToken = token; functionNode.setFinish(Token.descPosition(token) + Token.descLength(token)); } else { expect(LBRACE); // Gather the function elements. final List<Statement> prevFunctionDecls = functionDeclarations; functionDeclarations = new ArrayList<>(); try { sourceElements(); addFunctionDeclarations(functionNode); } finally { functionDeclarations = prevFunctionDecls; } lastToken = token; expect(RBRACE); functionNode.setFinish(finish); } } finally { functionNode = restoreFunctionNode(functionNode, lastToken); } return functionNode; }
Example 11
Source File: JSONWriter.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
@Override public boolean enterFunctionNode(final FunctionNode functionNode) { final boolean program = functionNode.isProgram(); if (program) { return emitProgram(functionNode); } enterDefault(functionNode); final String name; if (functionNode.isDeclared()) { name = "FunctionDeclaration"; } else { name = "FunctionExpression"; } type(name); comma(); property("id"); final FunctionNode.Kind kind = functionNode.getKind(); if (functionNode.isAnonymous() || kind == FunctionNode.Kind.GETTER || kind == FunctionNode.Kind.SETTER) { nullValue(); } else { functionNode.getIdent().accept(this); } comma(); array("params", functionNode.getParameters()); comma(); arrayStart("defaults"); arrayEnd(); comma(); property("rest"); nullValue(); comma(); property("body"); functionNode.getBody().accept(this); comma(); property("generator", false); comma(); property("expression", false); return leave(); }
Example 12
Source File: Parser.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
/** * FunctionBody : * SourceElements? * * See 13 * * Parse function body. * @return function node (body.) */ private FunctionNode functionBody(final long firstToken, final IdentNode ident, final List<IdentNode> parameters, final FunctionNode.Kind kind) { FunctionNode functionNode = null; long lastToken = 0L; try { // Create a new function block. functionNode = newFunctionNode(firstToken, ident, parameters, kind); // Nashorn extension: expression closures if (!env._no_syntax_extensions && type != LBRACE) { /* * Example: * * function square(x) x * x; * print(square(3)); */ // just expression as function body final Expression expr = assignmentExpression(true); assert lc.getCurrentBlock() == lc.getFunctionBody(functionNode); final ReturnNode returnNode = new ReturnNode(functionNode.getLineNumber(), expr.getToken(), finish, expr); appendStatement(returnNode); lastToken = token; functionNode.setFinish(Token.descPosition(token) + Token.descLength(token)); } else { expect(LBRACE); // Gather the function elements. final List<Statement> prevFunctionDecls = functionDeclarations; functionDeclarations = new ArrayList<>(); try { sourceElements(); addFunctionDeclarations(functionNode); } finally { functionDeclarations = prevFunctionDecls; } lastToken = token; expect(RBRACE); functionNode.setFinish(finish); } } finally { functionNode = restoreFunctionNode(functionNode, lastToken); } return functionNode; }
Example 13
Source File: Parser.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
/** * Set up a new function block. * * @param ident Name of function. * @return New block. */ private FunctionNode newFunctionNode(final long startToken, final IdentNode ident, final List<IdentNode> parameters, final FunctionNode.Kind kind) { // Build function name. final StringBuilder sb = new StringBuilder(); final FunctionNode parentFunction = lc.getCurrentFunction(); if (parentFunction != null && !parentFunction.isProgram()) { sb.append(parentFunction.getName()).append('$'); } sb.append(ident != null ? ident.getName() : FUNCTION_PREFIX.symbolName()); final String name = namespace.uniqueName(sb.toString()); assert parentFunction != null || name.equals(RUN_SCRIPT.symbolName()) : "name = " + name;// must not rename runScript(). int flags = 0; if (parentFunction == null) { flags |= FunctionNode.IS_PROGRAM; } if (isStrictMode) { flags |= FunctionNode.IS_STRICT; } if (env._specialize_calls != null) { if (env._specialize_calls.contains(name)) { flags |= FunctionNode.CAN_SPECIALIZE; } } // Start new block. FunctionNode functionNode = new FunctionNode( source, line, //TODO? token, Token.descPosition(token), startToken, namespace, ident, name, parameters, kind, flags); lc.push(functionNode); // Create new block, and just put it on the context stack, restoreFunctionNode() will associate it with the // FunctionNode. newBlock(); return functionNode; }
Example 14
Source File: ParserContextFunctionNode.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
/** * @return The kind if function */ public FunctionNode.Kind getKind() { return kind; }
Example 15
Source File: JSONWriter.java From jdk8u_nashorn with GNU General Public License v2.0 | 4 votes |
@Override public boolean enterFunctionNode(final FunctionNode functionNode) { final boolean program = functionNode.isProgram(); if (program) { return emitProgram(functionNode); } enterDefault(functionNode); final String name; if (functionNode.isDeclared()) { name = "FunctionDeclaration"; } else { name = "FunctionExpression"; } type(name); comma(); property("id"); final FunctionNode.Kind kind = functionNode.getKind(); if (functionNode.isAnonymous() || kind == FunctionNode.Kind.GETTER || kind == FunctionNode.Kind.SETTER) { nullValue(); } else { functionNode.getIdent().accept(this); } comma(); array("params", functionNode.getParameters()); comma(); arrayStart("defaults"); arrayEnd(); comma(); property("rest"); nullValue(); comma(); property("body"); functionNode.getBody().accept(this); comma(); property("generator", false); comma(); property("expression", false); return leave(); }
Example 16
Source File: JSONWriter.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
@Override public boolean enterFunctionNode(final FunctionNode functionNode) { final boolean program = functionNode.isProgram(); if (program) { return emitProgram(functionNode); } enterDefault(functionNode); final String name; if (functionNode.isDeclared()) { name = "FunctionDeclaration"; } else { name = "FunctionExpression"; } type(name); comma(); property("id"); final FunctionNode.Kind kind = functionNode.getKind(); if (functionNode.isAnonymous() || kind == FunctionNode.Kind.GETTER || kind == FunctionNode.Kind.SETTER) { nullValue(); } else { functionNode.getIdent().accept(this); } comma(); array("params", functionNode.getParameters()); comma(); arrayStart("defaults"); arrayEnd(); comma(); property("rest"); nullValue(); comma(); property("body"); functionNode.getBody().accept(this); comma(); property("generator", false); comma(); property("expression", false); return leave(); }
Example 17
Source File: Parser.java From hottub with GNU General Public License v2.0 | 4 votes |
/** * Set up a new function block. * * @param ident Name of function. * @return New block. */ private FunctionNode newFunctionNode(final long startToken, final IdentNode ident, final List<IdentNode> parameters, final FunctionNode.Kind kind, final int functionLine) { // Build function name. final StringBuilder sb = new StringBuilder(); final FunctionNode parentFunction = lc.getCurrentFunction(); if (parentFunction != null && !parentFunction.isProgram()) { sb.append(parentFunction.getName()).append('$'); } assert ident.getName() != null; sb.append(ident.getName()); final String name = namespace.uniqueName(sb.toString()); assert parentFunction != null || name.equals(PROGRAM.symbolName()) || name.startsWith(RecompilableScriptFunctionData.RECOMPILATION_PREFIX) : "name = " + name; int flags = 0; if (isStrictMode) { flags |= FunctionNode.IS_STRICT; } if (parentFunction == null) { flags |= FunctionNode.IS_PROGRAM; } // Start new block. final FunctionNode functionNode = new FunctionNode( source, functionLine, token, Token.descPosition(token), startToken, namespace, ident, name, parameters, kind, flags); lc.push(functionNode); // Create new block, and just put it on the context stack, restoreFunctionNode() will associate it with the // FunctionNode. newBlock(); return functionNode; }
Example 18
Source File: Parser.java From nashorn with GNU General Public License v2.0 | 4 votes |
/** * Set up a new function block. * * @param ident Name of function. * @return New block. */ private FunctionNode newFunctionNode(final long startToken, final IdentNode ident, final List<IdentNode> parameters, final FunctionNode.Kind kind) { // Build function name. final StringBuilder sb = new StringBuilder(); final FunctionNode parentFunction = lc.getCurrentFunction(); if (parentFunction != null && !parentFunction.isProgram()) { sb.append(parentFunction.getName()).append('$'); } sb.append(ident != null ? ident.getName() : FUNCTION_PREFIX.symbolName()); final String name = namespace.uniqueName(sb.toString()); assert parentFunction != null || name.equals(RUN_SCRIPT.symbolName()) : "name = " + name;// must not rename runScript(). int flags = 0; if (parentFunction == null) { flags |= FunctionNode.IS_PROGRAM; } if (isStrictMode) { flags |= FunctionNode.IS_STRICT; } if (env._specialize_calls != null) { if (env._specialize_calls.contains(name)) { flags |= FunctionNode.CAN_SPECIALIZE; } } // Start new block. FunctionNode functionNode = new FunctionNode( source, line, //TODO? token, Token.descPosition(token), startToken, namespace, ident, name, parameters, kind, flags); lc.push(functionNode); // Create new block, and just put it on the context stack, restoreFunctionNode() will associate it with the // FunctionNode. newBlock(); return functionNode; }
Example 19
Source File: JSONWriter.java From hottub with GNU General Public License v2.0 | 4 votes |
@Override public boolean enterFunctionNode(final FunctionNode functionNode) { final boolean program = functionNode.isProgram(); if (program) { return emitProgram(functionNode); } enterDefault(functionNode); final String name; if (functionNode.isDeclared()) { name = "FunctionDeclaration"; } else { name = "FunctionExpression"; } type(name); comma(); property("id"); final FunctionNode.Kind kind = functionNode.getKind(); if (functionNode.isAnonymous() || kind == FunctionNode.Kind.GETTER || kind == FunctionNode.Kind.SETTER) { nullValue(); } else { functionNode.getIdent().accept(this); } comma(); array("params", functionNode.getParameters()); comma(); arrayStart("defaults"); arrayEnd(); comma(); property("rest"); nullValue(); comma(); property("body"); functionNode.getBody().accept(this); comma(); property("generator", false); comma(); property("expression", false); return leave(); }
Example 20
Source File: Parser.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
/** * FunctionBody : * SourceElements? * * See 13 * * Parse function body. * @return function node (body.) */ private FunctionNode functionBody(final long firstToken, final IdentNode ident, final List<IdentNode> parameters, final FunctionNode.Kind kind) { FunctionNode functionNode = null; long lastToken = 0L; try { // Create a new function block. functionNode = newFunctionNode(firstToken, ident, parameters, kind); // Nashorn extension: expression closures if (!env._no_syntax_extensions && type != LBRACE) { /* * Example: * * function square(x) x * x; * print(square(3)); */ // just expression as function body final Expression expr = assignmentExpression(true); assert lc.getCurrentBlock() == lc.getFunctionBody(functionNode); final ReturnNode returnNode = new ReturnNode(functionNode.getLineNumber(), expr.getToken(), finish, expr); appendStatement(returnNode); lastToken = token; functionNode.setFinish(Token.descPosition(token) + Token.descLength(token)); } else { expect(LBRACE); // Gather the function elements. final List<Statement> prevFunctionDecls = functionDeclarations; functionDeclarations = new ArrayList<>(); try { sourceElements(); addFunctionDeclarations(functionNode); } finally { functionDeclarations = prevFunctionDecls; } lastToken = token; expect(RBRACE); functionNode.setFinish(finish); } } finally { functionNode = restoreFunctionNode(functionNode, lastToken); } return functionNode; }