jdk.nashorn.internal.parser.Token Java Examples
The following examples show how to use
jdk.nashorn.internal.parser.Token.
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: Debug.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * Dump a token stream to stdout * * TODO: most other bugging goes to stderr, change? * * @param source the source * @param lexer the lexer * @param stream the stream to dump */ public static void dumpTokens(final Source source, final Lexer lexer, final TokenStream stream) { TokenType type; int k = 0; do { while (k > stream.last()) { // Get more tokens. lexer.lexify(); } final long token = stream.get(k); type = Token.descType(token); System.out.println("" + k + ": " + Token.toString(source, token, true)); k++; } while(type != EOF); }
Example #2
Source File: Lower.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
@Override public Node leaveExpressionStatement(final ExpressionStatement expressionStatement) { final Expression expr = expressionStatement.getExpression(); ExpressionStatement node = expressionStatement; final FunctionNode currentFunction = lc.getCurrentFunction(); if (currentFunction.isProgram()) { if (!isInternalExpression(expr) && !isEvalResultAssignment(expr)) { node = expressionStatement.setExpression( new BinaryNode( Token.recast( expressionStatement.getToken(), TokenType.ASSIGN), compilerConstant(RETURN), expr)); } } return addStatement(node); }
Example #3
Source File: Lower.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
@Override public Node leaveExpressionStatement(final ExpressionStatement expressionStatement) { final Expression expr = expressionStatement.getExpression(); ExpressionStatement node = expressionStatement; final FunctionNode currentFunction = lc.getCurrentFunction(); if (currentFunction.isProgram()) { if (!isInternalExpression(expr) && !isEvalResultAssignment(expr)) { node = expressionStatement.setExpression( new BinaryNode( Token.recast( expressionStatement.getToken(), TokenType.ASSIGN), compilerConstant(RETURN), expr)); } } return addStatement(node); }
Example #4
Source File: Lower.java From nashorn with GNU General Public License v2.0 | 6 votes |
@Override public Node leaveExpressionStatement(final ExpressionStatement expressionStatement) { final Expression expr = expressionStatement.getExpression(); ExpressionStatement node = expressionStatement; final FunctionNode currentFunction = lc.getCurrentFunction(); if (currentFunction.isProgram()) { if (!isInternalExpression(expr) && !isEvalResultAssignment(expr)) { node = expressionStatement.setExpression( new BinaryNode( Token.recast( expressionStatement.getToken(), TokenType.ASSIGN), compilerConstant(RETURN), expr)); } } return addStatement(node); }
Example #5
Source File: Debug.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
/** * Dump a token stream to stdout * * TODO: most other bugging goes to stderr, change? * * @param source the source * @param lexer the lexer * @param stream the stream to dump */ public static void dumpTokens(final Source source, final Lexer lexer, final TokenStream stream) { TokenType type; int k = 0; do { while (k > stream.last()) { // Get more tokens. lexer.lexify(); } final long token = stream.get(k); type = Token.descType(token); System.out.println("" + k + ": " + Token.toString(source, token, true)); k++; } while(type != EOF); }
Example #6
Source File: SplitIntoFunctions.java From jdk8u_nashorn with GNU General Public License v2.0 | 6 votes |
@Override public Node leaveBlock(final Block block) { if (!artificialBlock) { if (lc.isFunctionBody()) { // Prepend declaration-only var statements to the top of the statement list. lc.prependStatements(getCurrentFunctionState().varStatements); } else if (lc.isSplitBody()) { appendSplitReturn(FALLTHROUGH_STATE, NO_LINE_NUMBER); if (getCurrentFunctionState().fn.isProgram()) { // If we're splitting the program, make sure every shard ends with "return :return" and // begins with ":return = :return-in;". lc.prependStatement(new ExpressionStatement(NO_LINE_NUMBER, NO_TOKEN, NO_FINISH, new BinaryNode(Token.toDesc(TokenType.ASSIGN, 0, 0), createReturnIdent(), createReturnParamIdent()))); } } } return block; }
Example #7
Source File: SplitIntoFunctions.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
@Override public Node leaveBlock(final Block block) { if (!artificialBlock) { if (lc.isFunctionBody()) { // Prepend declaration-only var statements to the top of the statement list. lc.prependStatements(getCurrentFunctionState().varStatements); } else if (lc.isSplitBody()) { appendSplitReturn(FALLTHROUGH_STATE, NO_LINE_NUMBER); if (getCurrentFunctionState().fn.isProgram()) { // If we're splitting the program, make sure every shard ends with "return :return" and // begins with ":return = :return-in;". lc.prependStatement(new ExpressionStatement(NO_LINE_NUMBER, NO_TOKEN, NO_FINISH, new BinaryNode(Token.toDesc(TokenType.ASSIGN, 0, 0), createReturnIdent(), createReturnParamIdent()))); } } } return block; }
Example #8
Source File: Lower.java From jdk8u_nashorn with GNU General Public License v2.0 | 6 votes |
@Override public Node leaveExpressionStatement(final ExpressionStatement expressionStatement) { final Expression expr = expressionStatement.getExpression(); ExpressionStatement node = expressionStatement; final FunctionNode currentFunction = lc.getCurrentFunction(); if (currentFunction.isProgram()) { if (!isInternalExpression(expr) && !isEvalResultAssignment(expr)) { node = expressionStatement.setExpression( new BinaryNode( Token.recast( expressionStatement.getToken(), TokenType.ASSIGN), compilerConstant(RETURN), expr)); } } return addStatement(node); }
Example #9
Source File: SplitIntoFunctions.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
@Override public Node leaveBlock(final Block block) { if (!artificialBlock) { if (lc.isFunctionBody()) { // Prepend declaration-only var statements to the top of the statement list. lc.prependStatements(getCurrentFunctionState().varStatements); } else if (lc.isSplitBody()) { appendSplitReturn(FALLTHROUGH_STATE, NO_LINE_NUMBER); if (getCurrentFunctionState().fn.isProgram()) { // If we're splitting the program, make sure every shard ends with "return :return" and // begins with ":return = :return-in;". lc.prependStatement(new ExpressionStatement(NO_LINE_NUMBER, NO_TOKEN, NO_FINISH, new BinaryNode(Token.toDesc(TokenType.ASSIGN, 0, 0), createReturnIdent(), createReturnParamIdent()))); } } } return block; }
Example #10
Source File: Debug.java From jdk8u_nashorn with GNU General Public License v2.0 | 6 votes |
/** * Dump a token stream to stdout * * TODO: most other bugging goes to stderr, change? * * @param source the source * @param lexer the lexer * @param stream the stream to dump */ public static void dumpTokens(final Source source, final Lexer lexer, final TokenStream stream) { TokenType type; int k = 0; do { while (k > stream.last()) { // Get more tokens. lexer.lexify(); } final long token = stream.get(k); type = Token.descType(token); System.out.println("" + k + ": " + Token.toString(source, token, true)); k++; } while(type != EOF); }
Example #11
Source File: SplitIntoFunctions.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
@Override public Node leaveBlock(final Block block) { if (!artificialBlock) { if (lc.isFunctionBody()) { // Prepend declaration-only var statements to the top of the statement list. lc.prependStatements(getCurrentFunctionState().varStatements); } else if (lc.isSplitBody()) { appendSplitReturn(FALLTHROUGH_STATE, NO_LINE_NUMBER); if (getCurrentFunctionState().fn.isProgram()) { // If we're splitting the program, make sure every shard ends with "return :return" and // begins with ":return = :return-in;". lc.prependStatement(new ExpressionStatement(NO_LINE_NUMBER, NO_TOKEN, NO_FINISH, new BinaryNode(Token.toDesc(TokenType.ASSIGN, 0, 0), createReturnIdent(), createReturnParamIdent()))); } } } return block; }
Example #12
Source File: SplitIntoFunctions.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private static IfNode makeIfStateEquals(final int lineNumber, final long token, final int finish, final int value, final Block pass, final Statement fail) { return new IfNode(lineNumber, token, finish, new BinaryNode(Token.recast(token, TokenType.EQ_STRICT), GetSplitState.INSTANCE, intLiteral(value)), pass, fail == null ? null : new Block(NO_TOKEN, NO_FINISH, fail)); }
Example #13
Source File: LiteralNode.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * Constructor * * @param token token * @param finish finish * @param value array literal value, a Node array */ protected ArrayLiteralNode(final long token, final int finish, final Expression[] value) { super(Token.recast(token, TokenType.ARRAY), finish, value); this.elementType = Type.UNKNOWN; this.presets = null; this.postsets = null; this.splitRanges = null; }
Example #14
Source File: RecompilableScriptFunctionData.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private static long tokenFor(final FunctionNode fn) { final int position = Token.descPosition(fn.getFirstToken()); final long lastToken = Token.withDelimiter(fn.getLastToken()); // EOL uses length field to store the line number final int length = Token.descPosition(lastToken) - position + (Token.descType(lastToken) == TokenType.EOL ? 0 : Token.descLength(lastToken)); return Token.toDesc(TokenType.FUNCTION, position, length); }
Example #15
Source File: RecompilableScriptFunctionData.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
@Override String toSource() { if (source != null && token != 0) { return source.getString(Token.descPosition(token), Token.descLength(token)); } return "function " + (name == null ? "" : name) + "() { [native code] }"; }
Example #16
Source File: RecompilableScriptFunctionData.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
@Override String toSource() { if (source != null && token != 0) { return source.getString(Token.descPosition(token), Token.descLength(token)); } return "function " + (name == null ? "" : name) + "() { [native code] }"; }
Example #17
Source File: RecompilableScriptFunctionData.java From jdk8u_nashorn with GNU General Public License v2.0 | 5 votes |
@Override String toSource() { if (source != null && token != 0) { return source.getString(Token.descPosition(token), Token.descLength(token)); } return "function " + (name == null ? "" : name) + "() { [native code] }"; }
Example #18
Source File: ErrorManager.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Format an error message to include source and line information. * @param message Error message string. * @param source Source file information. * @param line Source line number. * @param column Source column number. * @param token Offending token descriptor. * @return formatted string */ public static String format(final String message, final Source source, final int line, final int column, final long token) { final String eoln = System.lineSeparator(); final int position = Token.descPosition(token); final StringBuilder sb = new StringBuilder(); // Source description and message. sb.append(source.getName()). append(':'). append(line). append(':'). append(column). append(' '). append(message). append(eoln); // Source content. final String sourceLine = source.getSourceLine(position); sb.append(sourceLine).append(eoln); // Pointer to column. for (int i = 0; i < column; i++) { if (i < sourceLine.length() && sourceLine.charAt(i) == '\t') { sb.append('\t'); } else { sb.append(' '); } } sb.append('^'); // Use will append eoln. // buffer.append(eoln); return sb.toString(); }
Example #19
Source File: ErrorManager.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
/** * Format an error message to include source and line information. * @param message Error message string. * @param source Source file information. * @param line Source line number. * @param column Source column number. * @param token Offending token descriptor. * @return formatted string */ public static String format(final String message, final Source source, final int line, final int column, final long token) { final String eoln = System.lineSeparator(); final int position = Token.descPosition(token); final StringBuilder sb = new StringBuilder(); // Source description and message. sb.append(source.getName()). append(':'). append(line). append(':'). append(column). append(' '). append(message). append(eoln); // Source content. final String sourceLine = source.getSourceLine(position); sb.append(sourceLine).append(eoln); // Pointer to column. for (int i = 0; i < column; i++) { if (sourceLine.charAt(i) == '\t') { sb.append('\t'); } else { sb.append(' '); } } sb.append('^'); // Use will append eoln. // buffer.append(eoln); return sb.toString(); }
Example #20
Source File: SplitIntoFunctions.java From jdk8u_nashorn with GNU General Public License v2.0 | 5 votes |
private static IfNode makeIfStateEquals(final int lineNumber, final long token, final int finish, final int value, final Block pass, final Statement fail) { return new IfNode(lineNumber, token, finish, new BinaryNode(Token.recast(token, TokenType.EQ_STRICT), GetSplitState.INSTANCE, intLiteral(value)), pass, fail == null ? null : new Block(NO_TOKEN, NO_FINISH, fail)); }
Example #21
Source File: RecompilableScriptFunctionData.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
@Override String toSource() { if (source != null && token != 0) { return source.getString(Token.descPosition(token), Token.descLength(token)); } return "function " + (name == null ? "" : name) + "() { [native code] }"; }
Example #22
Source File: RecompilableScriptFunctionData.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
private static long tokenFor(final FunctionNode fn) { final int position = Token.descPosition(fn.getFirstToken()); final long lastToken = Token.withDelimiter(fn.getLastToken()); // EOL uses length field to store the line number final int length = Token.descPosition(lastToken) - position + (Token.descType(lastToken) == TokenType.EOL ? 0 : Token.descLength(lastToken)); return Token.toDesc(TokenType.FUNCTION, position, length); }
Example #23
Source File: RecompilableScriptFunctionData.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
@Override String toSource() { if (source != null && token != 0) { return source.getString(Token.descPosition(token), Token.descLength(token)); } return "function " + (name == null ? "" : name) + "() { [native code] }"; }
Example #24
Source File: RecompilableScriptFunctionData.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
private static long tokenFor(final FunctionNode fn) { final int position = Token.descPosition(fn.getFirstToken()); final long lastToken = Token.withDelimiter(fn.getLastToken()); // EOL uses length field to store the line number final int length = Token.descPosition(lastToken) - position + (Token.descType(lastToken) == TokenType.EOL ? 0 : Token.descLength(lastToken)); return Token.toDesc(TokenType.FUNCTION, position, length); }
Example #25
Source File: ErrorManager.java From hottub with GNU General Public License v2.0 | 5 votes |
/** * Format an error message to include source and line information. * @param message Error message string. * @param source Source file information. * @param line Source line number. * @param column Source column number. * @param token Offending token descriptor. * @return formatted string */ public static String format(final String message, final Source source, final int line, final int column, final long token) { final String eoln = System.lineSeparator(); final int position = Token.descPosition(token); final StringBuilder sb = new StringBuilder(); // Source description and message. sb.append(source.getName()). append(':'). append(line). append(':'). append(column). append(' '). append(message). append(eoln); // Source content. final String sourceLine = source.getSourceLine(position); sb.append(sourceLine).append(eoln); // Pointer to column. for (int i = 0; i < column; i++) { if (i < sourceLine.length() && sourceLine.charAt(i) == '\t') { sb.append('\t'); } else { sb.append(' '); } } sb.append('^'); // Use will append eoln. // buffer.append(eoln); return sb.toString(); }
Example #26
Source File: LiteralNode.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
private LexerTokenLiteralNode(final long token, final int finish, final LexerToken value) { super(Token.recast(token, TokenType.STRING), finish, value); //TODO is string the correct token type here? }
Example #27
Source File: RecompilableScriptFunctionData.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
private static long tokenFor(final FunctionNode fn) { final int position = Token.descPosition(fn.getFirstToken()); final int length = Token.descPosition(fn.getLastToken()) - position + Token.descLength(fn.getLastToken()); return Token.toDesc(TokenType.FUNCTION, position, length); }
Example #28
Source File: Source.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
/** * Fetch a portion of source content associated with a token. * @param token Token descriptor. * @return Source content portion. */ public String getString(final long token) { final int start = Token.descPosition(token); final int len = Token.descLength(token); return new String(data(), start, len); }
Example #29
Source File: LiteralNode.java From hottub with GNU General Public License v2.0 | 4 votes |
private StringLiteralNode(final long token, final int finish, final String value) { super(Token.recast(token, TokenType.STRING), finish, value); }
Example #30
Source File: LiteralNode.java From hottub with GNU General Public License v2.0 | 4 votes |
private NullLiteralNode(final long token, final int finish) { super(Token.recast(token, TokenType.OBJECT), finish, null); }