Commit 1f66512f authored by Toon Verwaest's avatar Toon Verwaest Committed by Commit Bot

[parser] Remove final remaining contextual keywords

Change-Id: I9c022d8d1aa363168546303516b5b3ee6196fdb5
Reviewed-on: https://chromium-review.googlesource.com/c/1333412
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57475}
parent 2234c4d5
......@@ -218,6 +218,7 @@ class AstBigInt {
F(eval, "eval") \
F(from, "from") \
F(function, "function") \
F(get, "get") \
F(get_space, "get ") \
F(length, "length") \
F(let, "let") \
......@@ -233,6 +234,7 @@ class AstBigInt {
F(proto, "__proto__") \
F(prototype, "prototype") \
F(return, "return") \
F(set, "set") \
F(set_space, "set ") \
F(star_default_star, "*default*") \
F(string, "string") \
......
......@@ -1509,13 +1509,14 @@ ParserBase<Impl>::ParseAndClassifyIdentifier() {
} else if (is_sloppy(language_mode()) &&
(Token::IsStrictReservedWord(next) ||
(next == Token::YIELD && !is_generator()))) {
IdentifierT name = impl()->GetSymbol();
classifier()->RecordStrictModeFormalParameterError(
scanner()->location(), MessageTemplate::kUnexpectedStrictReserved);
if (scanner()->IsLet()) {
if (impl()->IdentifierEquals(name, ast_value_factory()->let_string())) {
classifier()->RecordLetPatternError(
scanner()->location(), MessageTemplate::kLetInLexicalBinding);
}
return impl()->GetSymbol();
return name;
} else {
ReportUnexpectedToken(next);
return impl()->EmptyIdentifierString();
......@@ -1946,21 +1947,6 @@ inline bool ParsePropertyKindFromToken(Token::Value token,
return false;
}
inline bool ParseAsAccessor(Token::Value token, Token::Value contextual_token,
ParsePropertyKind* kind) {
if (ParsePropertyKindFromToken(token, kind)) return false;
if (contextual_token == Token::GET) {
*kind = ParsePropertyKind::kAccessorGetter;
} else if (contextual_token == Token::SET) {
*kind = ParsePropertyKind::kAccessorSetter;
} else {
return false;
}
return true;
}
template <class Impl>
typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParsePropertyName(
IdentifierT* name, ParsePropertyKind* kind, ParseFunctionFlags* flags,
......@@ -1986,11 +1972,21 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParsePropertyName(
*kind = ParsePropertyKind::kMethod;
}
if (*kind == ParsePropertyKind::kNotSet && Check(Token::IDENTIFIER) &&
!ParseAsAccessor(peek(), scanner()->current_contextual_token(), kind)) {
*name = impl()->GetSymbol();
impl()->PushLiteralName(*name);
return factory()->NewStringLiteral(*name, position());
if (*kind == ParsePropertyKind::kNotSet && Check(Token::IDENTIFIER)) {
IdentifierT symbol = impl()->GetSymbol();
if (!ParsePropertyKindFromToken(peek(), kind)) {
if (impl()->IdentifierEquals(symbol, ast_value_factory()->get_string())) {
*kind = ParsePropertyKind::kAccessorGetter;
} else if (impl()->IdentifierEquals(symbol,
ast_value_factory()->set_string())) {
*kind = ParsePropertyKind::kAccessorSetter;
}
}
if (!IsAccessor(*kind)) {
*name = symbol;
impl()->PushLiteralName(*name);
return factory()->NewStringLiteral(*name, position());
}
}
int pos = peek_position();
......
......@@ -179,8 +179,6 @@ static const Token::Value one_char_tokens[] = {
KEYWORD("finally", Token::FINALLY) \
KEYWORD("for", Token::FOR) \
KEYWORD("function", Token::FUNCTION) \
KEYWORD_GROUP('g') \
KEYWORD("get", Token::GET) \
KEYWORD_GROUP('i') \
KEYWORD("if", Token::IF) \
KEYWORD("implements", Token::FUTURE_STRICT_RESERVED_WORD) \
......@@ -201,7 +199,6 @@ static const Token::Value one_char_tokens[] = {
KEYWORD_GROUP('r') \
KEYWORD("return", Token::RETURN) \
KEYWORD_GROUP('s') \
KEYWORD("set", Token::SET) \
KEYWORD("static", Token::STATIC) \
KEYWORD("super", Token::SUPER) \
KEYWORD("switch", Token::SWITCH) \
......@@ -358,9 +355,9 @@ V8_INLINE Token::Value Scanner::ScanIdentifierOrKeywordInner(
Token::Value token =
KeywordOrIdentifierToken(chars.start(), chars.length());
if (token == Token::IDENTIFIER ||
token == Token::FUTURE_STRICT_RESERVED_WORD ||
Token::IsContextualKeyword(token))
token == Token::FUTURE_STRICT_RESERVED_WORD) {
literal->Complete();
}
return token;
} else {
literal->Complete();
......@@ -557,11 +554,7 @@ V8_INLINE Token::Value Scanner::ScanSingleToken() {
if (unicode_cache_->IsIdentifierStart(c0_) ||
(CombineSurrogatePair() &&
unicode_cache_->IsIdentifierStart(c0_))) {
Token::Value token = ScanIdentifierOrKeyword();
if (!Token::IsContextualKeyword(token)) return token;
next().contextual_token = token;
return Token::IDENTIFIER;
return ScanIdentifierOrKeyword();
}
if (IsDecimalDigit(c0_)) return ScanNumber(false);
if (c0_ == kEndOfInput) {
......@@ -581,7 +574,6 @@ void Scanner::Scan(TokenDesc* next_desc) {
next_desc->literal_chars.Drop();
next_desc->raw_literal_chars.Drop();
next_desc->contextual_token = Token::UNINITIALIZED;
next_desc->invalid_template_escape_message = MessageTemplate::kNone;
next_desc->token = ScanSingleToken();
......
......@@ -253,7 +253,6 @@ Token::Value Scanner::Next() {
next_ = next_next_;
next_next_ = previous;
previous->token = Token::UNINITIALIZED;
previous->contextual_token = Token::UNINITIALIZED;
DCHECK_NE(Token::UNINITIALIZED, current().token);
}
return current().token;
......@@ -438,13 +437,6 @@ void Scanner::SanityCheckTokenDesc(const TokenDesc& token) const {
DCHECK_EQ(token.invalid_template_escape_message, MessageTemplate::kNone);
break;
}
DCHECK_IMPLIES(token.token != Token::IDENTIFIER,
token.contextual_token == Token::UNINITIALIZED);
DCHECK_IMPLIES(token.contextual_token != Token::UNINITIALIZED,
token.token == Token::IDENTIFIER &&
Token::IsContextualKeyword(token.contextual_token));
DCHECK(!Token::IsContextualKeyword(token.token));
}
#endif // DEBUG
......@@ -690,7 +682,6 @@ Token::Value Scanner::ScanTemplateSpan() {
literal.Complete();
next().location.end_pos = source_pos();
next().token = result;
next().contextual_token = Token::UNINITIALIZED;
return result;
}
......@@ -1066,7 +1057,7 @@ Token::Value Scanner::ScanIdentifierOrKeywordInnerSlow(LiteralScope* literal,
if (escaped) return Token::ESCAPED_STRICT_RESERVED_WORD;
return token;
}
if (token == Token::IDENTIFIER || Token::IsContextualKeyword(token)) {
if (token == Token::IDENTIFIER) {
literal->Complete();
return token;
}
......@@ -1129,7 +1120,6 @@ bool Scanner::ScanRegExpPattern() {
literal.Complete();
next().token = Token::REGEXP_LITERAL;
next().contextual_token = Token::UNINITIALIZED;
return true;
}
......@@ -1225,10 +1215,7 @@ void Scanner::SeekNext(size_t position) {
// 1, Reset the current_, next_ and next_next_ tokens
// (next_ + next_next_ will be overwrittem by Next(),
// current_ will remain unchanged, so overwrite it fully.)
for (TokenDesc& token : token_storage_) {
token.token = Token::UNINITIALIZED;
token.contextual_token = Token::UNINITIALIZED;
}
for (TokenDesc& token : token_storage_) token.token = Token::UNINITIALIZED;
// 2, reset the source to the desired position,
source_->Seek(position);
// 3, re-scan, by scanning the look-ahead char + 1 token (next_).
......
......@@ -242,10 +242,7 @@ class Scanner {
if (!has_parser_error()) {
c0_ = kEndOfInput;
source_->set_parser_error();
for (TokenDesc& desc : token_storage_) {
desc.token = Token::ILLEGAL;
desc.contextual_token = Token::UNINITIALIZED;
}
for (TokenDesc& desc : token_storage_) desc.token = Token::ILLEGAL;
}
}
V8_INLINE void reset_parser_error_flag() {
......@@ -285,11 +282,6 @@ class Scanner {
// Returns the current token again.
Token::Value current_token() const { return current().token; }
Token::Value current_contextual_token() const {
return current().contextual_token;
}
Token::Value next_contextual_token() const { return next().contextual_token; }
// Returns the location information for the current token
// (the token last returned by Next()).
const Location& location() const { return current().location; }
......@@ -337,34 +329,6 @@ class Scanner {
return current().token == token;
}
inline bool CurrentMatchesContextual(Token::Value token) const {
DCHECK(Token::IsContextualKeyword(token));
return current_contextual_token() == token;
}
// Match the token against the contextual keyword or literal buffer.
inline bool CurrentMatchesContextualEscaped(Token::Value token) const {
DCHECK(Token::IsContextualKeyword(token) || token == Token::LET);
// Escaped keywords are not matched as tokens. So if we require escape
// and/or string processing we need to look at the literal content
// (which was escape-processed already).
// Conveniently, !current().literal_chars.is_used() for all proper
// keywords, so this second condition should exit early in common cases.
return (current_contextual_token() == token) ||
(current().literal_chars.is_used() &&
current().literal_chars.Equals(Vector<const char>(
Token::String(token), Token::StringLength(token))));
}
bool IsGet() { return CurrentMatchesContextual(Token::GET); }
bool IsSet() { return CurrentMatchesContextual(Token::SET); }
bool IsLet() const {
return CurrentMatches(Token::LET) ||
CurrentMatchesContextualEscaped(Token::LET);
}
template <size_t N>
bool NextLiteralEquals(const char (&s)[N]) {
DCHECK_EQ(Token::STRING, peek());
......@@ -580,7 +544,6 @@ class Scanner {
LiteralBuffer literal_chars;
LiteralBuffer raw_literal_chars;
Token::Value token = Token::UNINITIALIZED;
Token::Value contextual_token = Token::UNINITIALIZED;
MessageTemplate invalid_template_escape_message = MessageTemplate::kNone;
Location invalid_template_escape_location;
uint32_t smi_value_ = 0;
......
......@@ -20,12 +20,6 @@ namespace internal {
//
// T: Non-keyword tokens
// K: Keyword tokens
// C: Contextual keyword token
//
// Contextual keyword tokens are tokens that are scanned as Token::IDENTIFIER,
// but that in some contexts are treated as keywords. This mostly happens
// when ECMAScript introduces new keywords, but for backwards compatibility
// allows them to still be used as indentifiers in most contexts.
// IGNORE_TOKEN is a convenience macro that can be supplied as
// an argument (at any position) for a TOKEN_LIST call. It does
......@@ -193,11 +187,7 @@ namespace internal {
/* Scanner-internal use only. */ \
T(WHITESPACE, nullptr, 0) \
T(UNINITIALIZED, nullptr, 0) \
T(REGEXP_LITERAL, nullptr, 0) \
\
/* Contextual keyword tokens */ \
C(GET, "get", 0) \
C(SET, "set", 0)
T(REGEXP_LITERAL, nullptr, 0)
class Token {
public:
......@@ -217,9 +207,6 @@ class Token {
// Predicates
static bool IsKeyword(Value token) { return token_type[token] == 'K'; }
static bool IsContextualKeyword(Value token) {
return IsInRange(token, GET, SET);
}
static bool IsIdentifier(Value token, LanguageMode language_mode,
bool is_generator, bool disallow_await) {
......@@ -266,8 +253,6 @@ class Token {
return IsInRange(token, INIT, ASSIGN_EXP);
}
static bool IsGetOrSet(Value op) { return IsInRange(op, GET, SET); }
static bool IsBinaryOp(Value op) { return IsInRange(op, COMMA, EXP); }
static bool IsCompareOp(Value op) { return IsInRange(op, EQ, IN); }
......
......@@ -107,24 +107,5 @@ TEST(AllThePushbacks) {
}
}
TEST(ContextualKeywordTokens) {
auto scanner = make_scanner("function get bla");
// function (regular keyword)
scanner->Next();
CHECK_TOK(Token::FUNCTION, scanner->current_token());
CHECK_TOK(Token::UNINITIALIZED, scanner->current_contextual_token());
// get (contextual keyword)
scanner->Next();
CHECK_TOK(Token::IDENTIFIER, scanner->current_token());
CHECK_TOK(Token::GET, scanner->current_contextual_token());
// bla (identfier, not any sort of keyword)
scanner->Next();
CHECK_TOK(Token::IDENTIFIER, scanner->current_token());
CHECK_TOK(Token::UNINITIALIZED, scanner->current_contextual_token());
}
} // namespace internal
} // namespace v8
......@@ -71,14 +71,6 @@ void MockUseCounterCallback(v8::Isolate* isolate,
} // namespace
TEST(IsContextualKeyword) {
for (int i = 0; i < Token::NUM_TOKENS; i++) {
Token::Value token = static_cast<Token::Value>(i);
CHECK_EQ(Token::TypeForTesting(token) == 'C',
Token::IsContextualKeyword(token));
}
}
bool TokenIsAutoSemicolon(Token::Value token) {
switch (token) {
case Token::SEMICOLON:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment