[parser] Cleanup token ranges

Remove IdentifierOrEnum and AwaitOrYield and reduce Callable to exclude enum.

Change-Id: Id80c0c5e7a8d4869ab8d841f3b973ea7c0c844cc
Reviewed-on: https://chromium-review.googlesource.com/c/1357044
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57992}
This commit is contained in:
Toon Verwaest 2018-11-30 19:21:04 +01:00 committed by Commit Bot
parent 4679fdd221
commit dac7aa0f8c
4 changed files with 9 additions and 56 deletions

View File

@ -1551,7 +1551,7 @@ ParserBase<Impl>::ParseAndClassifyIdentifier() {
return name;
}
if (!Token::IsValidIdentifier(next, language_mode(), this->is_generator(),
if (!Token::IsValidIdentifier(next, language_mode(), is_generator(),
parsing_module_ || is_async_function())) {
ReportUnexpectedToken(next);
return impl()->EmptyIdentifierString();
@ -1590,7 +1590,7 @@ ParserBase<Impl>::ParseIdentifierOrStrictReservedWord(
template <typename Impl>
typename ParserBase<Impl>::IdentifierT ParserBase<Impl>::ParseIdentifierName() {
Token::Value next = Next();
if (!Token::IsAnyIdentifierOrEnum(next) && next != Token::ESCAPED_KEYWORD &&
if (!Token::IsAnyIdentifier(next) && next != Token::ESCAPED_KEYWORD &&
!Token::IsKeyword(next)) {
ReportUnexpectedToken(next);
return impl()->EmptyIdentifierString();
@ -2385,8 +2385,7 @@ ParserBase<Impl>::ParseObjectPropertyDefinition(ParsePropertyInfo* prop_info,
// IdentifierReference Initializer?
DCHECK_EQ(function_flags, ParseFunctionFlag::kIsNormal);
if (!Token::IsValidIdentifier(name_token, language_mode(),
this->is_generator(),
if (!Token::IsValidIdentifier(name_token, language_mode(), is_generator(),
parsing_module_ || is_async_function())) {
ReportUnexpectedToken(Next());
return impl()->NullLiteralProperty();

View File

@ -518,8 +518,7 @@ class Scanner {
token == Token::UNINITIALIZED || token == Token::REGEXP_LITERAL ||
token == Token::ESCAPED_KEYWORD ||
IsInRange(token, Token::NUMBER, Token::STRING) ||
(Token::IsAnyIdentifierOrEnum(token) &&
!Token::IsKeyword(token)) ||
(Token::IsAnyIdentifier(token) && !Token::IsKeyword(token)) ||
IsInRange(token, Token::TEMPLATE_SPAN, Token::TEMPLATE_TAIL);
}
bool CanAccessRawLiteral() const {

View File

@ -173,18 +173,16 @@ namespace internal {
T(IDENTIFIER, nullptr, 0) \
K(ASYNC, "async", 0) \
/* `await` is a reserved word in module code only */ \
/* BEGIN AwaitOrYield */ \
K(AWAIT, "await", 0) \
K(YIELD, "yield", 0) \
/* END AwaitOrYield */ \
K(LET, "let", 0) \
K(STATIC, "static", 0) \
/* Future reserved words (ECMA-262, section 7.6.1.2). */ \
T(FUTURE_STRICT_RESERVED_WORD, nullptr, 0) \
T(ESCAPED_STRICT_RESERVED_WORD, nullptr, 0) \
K(ENUM, "enum", 0) \
/* END Callable */ \
/* END AnyIdentifier */ \
/* END Callable */ \
K(ENUM, "enum", 0) \
K(CLASS, "class", 0) \
K(CONST, "const", 0) \
K(EXPORT, "export", 0) \
@ -230,7 +228,9 @@ class Token {
return IsStrictReservedWord(token) && is_sloppy(language_mode);
}
static bool IsCallable(Value token) { return IsInRange(token, SUPER, ENUM); }
static bool IsCallable(Value token) {
return IsInRange(token, SUPER, ESCAPED_STRICT_RESERVED_WORD);
}
static bool IsAutoSemicolon(Value token) {
return IsInRange(token, SEMICOLON, EOS);
@ -240,14 +240,6 @@ class Token {
return IsInRange(token, IDENTIFIER, ESCAPED_STRICT_RESERVED_WORD);
}
static bool IsAnyIdentifierOrEnum(Value token) {
return IsInRange(token, IDENTIFIER, ENUM);
}
static bool IsAwaitOrYield(Value token) {
return IsInRange(token, AWAIT, YIELD);
}
static bool IsStrictReservedWord(Value token) {
return IsInRange(token, YIELD, ESCAPED_STRICT_RESERVED_WORD);
}

View File

@ -111,31 +111,6 @@ TEST(AnyIdentifierToken) {
}
}
bool TokenIsAnyIdentifierOrEnum(Token::Value token) {
switch (token) {
case Token::IDENTIFIER:
case Token::ASYNC:
case Token::AWAIT:
case Token::YIELD:
case Token::LET:
case Token::STATIC:
case Token::FUTURE_STRICT_RESERVED_WORD:
case Token::ESCAPED_STRICT_RESERVED_WORD:
case Token::ENUM:
return true;
default:
return false;
}
}
TEST(AnyIdentifierOrEnumToken) {
for (int i = 0; i < Token::NUM_TOKENS; i++) {
Token::Value token = static_cast<Token::Value>(i);
CHECK_EQ(TokenIsAnyIdentifierOrEnum(token),
Token::IsAnyIdentifierOrEnum(token));
}
}
bool TokenIsCallable(Token::Value token) {
switch (token) {
case Token::SUPER:
@ -147,7 +122,6 @@ bool TokenIsCallable(Token::Value token) {
case Token::STATIC:
case Token::FUTURE_STRICT_RESERVED_WORD:
case Token::ESCAPED_STRICT_RESERVED_WORD:
case Token::ENUM:
return true;
default:
return false;
@ -200,17 +174,6 @@ TEST(IsValidIdentifierToken) {
}
}
bool TokenIsAwaitOrYield(Token::Value token) {
return token == Token::AWAIT || token == Token::YIELD;
}
TEST(IsAwaitOrYield) {
for (int i = 0; i < Token::NUM_TOKENS; i++) {
Token::Value token = static_cast<Token::Value>(i);
CHECK_EQ(TokenIsAwaitOrYield(token), Token::IsAwaitOrYield(token));
}
}
bool TokenIsStrictReservedWord(Token::Value token) {
switch (token) {
case Token::LET: