Mercurial > hg > openjdk > aarch64-port > nashorn
changeset 1380:55c1eef5c4fc
8079362: Enforce best practices for Node token API usage
Reviewed-by: hannesw, sundar
author | attila |
---|---|
date | Wed, 06 May 2015 15:46:54 +0200 |
parents | bf44ade6c2c2 |
children | 7320ba416df1 cd840e74bc74 |
files | src/jdk/nashorn/internal/codegen/AssignSymbols.java src/jdk/nashorn/internal/codegen/LocalVariableTypesCalculator.java src/jdk/nashorn/internal/codegen/Lower.java src/jdk/nashorn/internal/ir/AccessNode.java src/jdk/nashorn/internal/ir/BaseNode.java src/jdk/nashorn/internal/ir/BinaryNode.java src/jdk/nashorn/internal/ir/Node.java src/jdk/nashorn/internal/ir/VarNode.java src/jdk/nashorn/internal/parser/Parser.java |
diffstat | 9 files changed, 26 insertions(+), 27 deletions(-) [+] |
line wrap: on
line diff
--- a/src/jdk/nashorn/internal/codegen/AssignSymbols.java Thu May 14 20:13:03 2015 -0700 +++ b/src/jdk/nashorn/internal/codegen/AssignSymbols.java Wed May 06 15:46:54 2015 +0200 @@ -84,6 +84,7 @@ import jdk.nashorn.internal.ir.VarNode; import jdk.nashorn.internal.ir.WithNode; import jdk.nashorn.internal.ir.visitor.NodeVisitor; +import jdk.nashorn.internal.parser.TokenType; import jdk.nashorn.internal.runtime.Context; import jdk.nashorn.internal.runtime.ECMAErrors; import jdk.nashorn.internal.runtime.ErrorManager; @@ -714,12 +715,10 @@ @Override public Node leaveBinaryNode(final BinaryNode binaryNode) { - switch (binaryNode.tokenType()) { - case ASSIGN: + if (binaryNode.isTokenType(TokenType.ASSIGN)) { return leaveASSIGN(binaryNode); - default: - return super.leaveBinaryNode(binaryNode); } + return super.leaveBinaryNode(binaryNode); } private Node leaveASSIGN(final BinaryNode binaryNode) {
--- a/src/jdk/nashorn/internal/codegen/LocalVariableTypesCalculator.java Thu May 14 20:13:03 2015 -0700 +++ b/src/jdk/nashorn/internal/codegen/LocalVariableTypesCalculator.java Wed May 06 15:46:54 2015 +0200 @@ -459,7 +459,7 @@ // NOTE: regardless of operator's lexical associativity, lhs is always evaluated first. final Expression lhs = binaryNode.lhs(); final LvarType lhsType; - if (!(lhs instanceof IdentNode && binaryNode.tokenType() == TokenType.ASSIGN)) { + if (!(lhs instanceof IdentNode && binaryNode.isTokenType(TokenType.ASSIGN))) { lhsType = visitExpression(lhs); } else { // Can't visit IdentNode on LHS of a simple assignment, as visits imply use, and this is def.
--- a/src/jdk/nashorn/internal/codegen/Lower.java Thu May 14 20:13:03 2015 -0700 +++ b/src/jdk/nashorn/internal/codegen/Lower.java Wed May 06 15:46:54 2015 +0200 @@ -200,7 +200,7 @@ final String name = getConstantPropertyName(indexNode.getIndex()); if (name != null) { // If index node is a constant property name convert index node to access node. - assert Token.descType(indexNode.getToken()) == TokenType.LBRACKET; + assert indexNode.isIndex(); return new AccessNode(indexNode.getToken(), indexNode.getFinish(), indexNode.getBase(), name); } return super.leaveIndexNode(indexNode);
--- a/src/jdk/nashorn/internal/ir/AccessNode.java Thu May 14 20:13:03 2015 -0700 +++ b/src/jdk/nashorn/internal/ir/AccessNode.java Wed May 06 15:46:54 2015 +0200 @@ -28,8 +28,6 @@ import jdk.nashorn.internal.codegen.types.Type; import jdk.nashorn.internal.ir.annotations.Immutable; import jdk.nashorn.internal.ir.visitor.NodeVisitor; -import jdk.nashorn.internal.parser.Token; -import jdk.nashorn.internal.parser.TokenType; /** * IR representation of a property access (period operator.) @@ -103,14 +101,6 @@ return property; } - /** - * Return true if this node represents an index operation normally represented as {@link IndexNode}. - * @return true if an index access. - */ - public boolean isIndex() { - return Token.descType(getToken()) == TokenType.LBRACKET; - } - private AccessNode setBase(final Expression base) { if (this.base == base) { return this;
--- a/src/jdk/nashorn/internal/ir/BaseNode.java Thu May 14 20:13:03 2015 -0700 +++ b/src/jdk/nashorn/internal/ir/BaseNode.java Wed May 06 15:46:54 2015 +0200 @@ -29,6 +29,7 @@ import jdk.nashorn.internal.codegen.types.Type; import jdk.nashorn.internal.ir.annotations.Immutable; +import jdk.nashorn.internal.parser.TokenType; /** * IR base for accessing/indexing nodes. @@ -122,6 +123,14 @@ } /** + * Return true if this node represents an index operation normally represented as {@link IndexNode}. + * @return true if an index access. + */ + public boolean isIndex() { + return isTokenType(TokenType.LBRACKET); + } + + /** * Mark this node as being the callee operand of a {@link CallNode}. * @return a base node identical to this one in all aspects except with its function flag set. */
--- a/src/jdk/nashorn/internal/ir/BinaryNode.java Thu May 14 20:13:03 2015 -0700 +++ b/src/jdk/nashorn/internal/ir/BinaryNode.java Wed May 06 15:46:54 2015 +0200 @@ -312,7 +312,7 @@ @Override public boolean isSelfModifying() { - return isAssignment() && tokenType() != TokenType.ASSIGN; + return isAssignment() && !isTokenType(TokenType.ASSIGN); } @Override @@ -529,7 +529,7 @@ final TokenType tokenType = tokenType(); if(tokenType == TokenType.ADD || tokenType == TokenType.ASSIGN_ADD) { return OPTIMISTIC_UNDECIDED_TYPE; - } else if (CAN_OVERFLOW.contains(tokenType())) { + } else if (CAN_OVERFLOW.contains(tokenType)) { return Type.INT; } return getMostPessimisticType();
--- a/src/jdk/nashorn/internal/ir/Node.java Thu May 14 20:13:03 2015 -0700 +++ b/src/jdk/nashorn/internal/ir/Node.java Wed May 06 15:46:54 2015 +0200 @@ -220,26 +220,28 @@ } /** - * Return token tokenType from a token descriptor. + * Returns this node's token's type. If you want to check for the node having a specific token type, + * consider using {@link #isTokenType(TokenType)} instead. * - * @return Type of token. + * @return type of token. */ public TokenType tokenType() { return Token.descType(token); } /** - * Test token tokenType. + * Tests if this node has the specific token type. * - * @param type a type to check this token against + * @param type a token type to check this node's token type against * @return true if token types match. */ public boolean isTokenType(final TokenType type) { - return Token.descType(token) == type; + return tokenType() == type; } /** - * Get the token for this location + * Get the token for this node. If you want to retrieve the token's type, consider using + * {@link #tokenType()} or {@link #isTokenType(TokenType)} instead. * @return the token */ public long getToken() {
--- a/src/jdk/nashorn/internal/ir/VarNode.java Thu May 14 20:13:03 2015 -0700 +++ b/src/jdk/nashorn/internal/ir/VarNode.java Wed May 06 15:46:54 2015 +0200 @@ -27,7 +27,6 @@ import jdk.nashorn.internal.ir.annotations.Immutable; import jdk.nashorn.internal.ir.visitor.NodeVisitor; -import jdk.nashorn.internal.parser.Token; /** * Node represents a var/let declaration. @@ -182,7 +181,7 @@ @Override public void toString(final StringBuilder sb, final boolean printType) { - sb.append(Token.descType(getToken()).getName()).append(' '); + sb.append(tokenType().getName()).append(' '); name.toString(sb, printType); if (init != null) {
--- a/src/jdk/nashorn/internal/parser/Parser.java Thu May 14 20:13:03 2015 -0700 +++ b/src/jdk/nashorn/internal/parser/Parser.java Wed May 06 15:46:54 2015 +0200 @@ -607,7 +607,7 @@ * @return whether the ident can be used as L-value */ private static boolean checkIdentLValue(final IdentNode ident) { - return Token.descType(ident.getToken()).getKind() != TokenKind.KEYWORD; + return ident.tokenType().getKind() != TokenKind.KEYWORD; } /**