[parser] Remove as, from, meta, of, target as contextual keywords

Change-Id: Ib73eca9233252a4b5b89f91cae1762528552c1b5
Reviewed-on: https://chromium-review.googlesource.com/c/1333407
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: Igor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57473}
This commit is contained in:
Toon Verwaest 2018-11-13 14:50:45 +01:00 committed by Commit Bot
parent 42217a2f0a
commit 019494b364
8 changed files with 77 additions and 84 deletions

View File

@ -198,6 +198,7 @@ class AstBigInt {
F(anonymous, "anonymous") \
F(anonymous_function, "(anonymous function)") \
F(arguments, "arguments") \
F(as, "as") \
F(async, "async") \
F(await, "await") \
F(bigint, "bigint") \
@ -215,16 +216,19 @@ class AstBigInt {
F(dot_catch, ".catch") \
F(empty, "") \
F(eval, "eval") \
F(from, "from") \
F(function, "function") \
F(get_space, "get ") \
F(length, "length") \
F(let, "let") \
F(meta, "meta") \
F(name, "name") \
F(native, "native") \
F(new_target, ".new.target") \
F(next, "next") \
F(number, "number") \
F(object, "object") \
F(of, "of") \
F(private_constructor, "#constructor") \
F(proto, "__proto__") \
F(prototype, "prototype") \
@ -233,6 +237,7 @@ class AstBigInt {
F(star_default_star, "*default*") \
F(string, "string") \
F(symbol, "symbol") \
F(target, "target") \
F(this, "this") \
F(this_function, ".this_function") \
F(throw, "throw") \

View File

@ -97,6 +97,7 @@
V(_, array_to_string, "[object Array]") \
V(_, ArrayBuffer_string, "ArrayBuffer") \
V(_, ArrayIterator_string, "Array Iterator") \
V(_, as_string, "as") \
V(_, assign_string, "assign") \
V(_, async_string, "async") \
V(_, auto_string, "auto") \
@ -155,6 +156,7 @@
V(_, flags_string, "flags") \
V(_, Float32Array_string, "Float32Array") \
V(_, Float64Array_string, "Float64Array") \
V(_, from_string, "from") \
V(_, Function_string, "Function") \
V(_, function_native_code_string, "function () { [native code] }") \
V(_, function_string, "function") \
@ -191,6 +193,7 @@
V(_, Map_string, "Map") \
V(_, MapIterator_string, "Map Iterator") \
V(_, message_string, "message") \
V(_, meta_string, "meta") \
V(_, minus_Infinity_string, "-Infinity") \
V(_, Module_string, "Module") \
V(_, multiline_string, "multiline") \
@ -213,6 +216,7 @@
V(_, Object_string, "Object") \
V(_, object_string, "object") \
V(_, object_to_string, "[object Object]") \
V(_, of_string, "of") \
V(_, ok, "ok") \
V(_, one_string, "1") \
V(_, ownKeys_string, "ownKeys") \
@ -261,6 +265,7 @@
V(_, Symbol_string, "Symbol") \
V(_, symbol_string, "symbol") \
V(_, SyntaxError_string, "SyntaxError") \
V(_, target_string, "target") \
V(_, then_string, "then") \
V(_, this_function_string, ".this_function") \
V(_, this_string, "this") \

View File

@ -709,27 +709,25 @@ class ParserBase {
bool peek_any_identifier() { return Token::IsAnyIdentifier(peek()); }
bool CheckContextualKeyword(Token::Value token) {
if (PeekContextualKeyword(token)) {
bool PeekContextualKeyword(const AstRawString* name) {
return peek() == Token::IDENTIFIER &&
scanner()->NextSymbol(ast_value_factory()) == name;
}
bool CheckContextualKeyword(const AstRawString* name) {
if (PeekContextualKeyword(name)) {
Consume(Token::IDENTIFIER);
return true;
}
return false;
}
bool PeekContextualKeyword(Token::Value token) {
DCHECK(Token::IsContextualKeyword(token));
return peek() == Token::IDENTIFIER &&
scanner()->next_contextual_token() == token;
}
void ExpectMetaProperty(const AstRawString* property_name,
const char* full_name, int pos);
void ExpectMetaProperty(Token::Value property_name, const char* full_name,
int pos);
void ExpectContextualKeyword(Token::Value token) {
DCHECK(Token::IsContextualKeyword(token));
void ExpectContextualKeyword(const AstRawString* name) {
Expect(Token::IDENTIFIER);
if (V8_UNLIKELY(scanner()->current_contextual_token() != token)) {
if (V8_UNLIKELY(scanner()->CurrentSymbol(ast_value_factory()) != name)) {
ReportUnexpectedToken(scanner()->current_token());
}
}
@ -738,7 +736,7 @@ class ParserBase {
if (Check(Token::IN)) {
*visit_mode = ForEachStatement::ENUMERATE;
return true;
} else if (CheckContextualKeyword(Token::OF)) {
} else if (CheckContextualKeyword(ast_value_factory()->of_string())) {
*visit_mode = ForEachStatement::ITERATE;
return true;
}
@ -746,7 +744,8 @@ class ParserBase {
}
bool PeekInOrOf() {
return peek() == Token::IN || PeekContextualKeyword(Token::OF);
return peek() == Token::IN ||
PeekContextualKeyword(ast_value_factory()->of_string());
}
// Checks whether an octal literal was last seen between beg_pos and end_pos.
@ -3339,7 +3338,7 @@ ParserBase<Impl>::ParseImportExpressions() {
Consume(Token::IMPORT);
int pos = position();
if (allow_harmony_import_meta() && peek() == Token::PERIOD) {
ExpectMetaProperty(Token::META, "import.meta", pos);
ExpectMetaProperty(ast_value_factory()->meta_string(), "import.meta", pos);
if (!parsing_module_) {
impl()->ReportMessageAt(scanner()->location(),
MessageTemplate::kImportMetaOutsideModule);
@ -3389,7 +3388,7 @@ typename ParserBase<Impl>::ExpressionT ParserBase<Impl>::ParseSuperExpression(
}
template <typename Impl>
void ParserBase<Impl>::ExpectMetaProperty(Token::Value property_name,
void ParserBase<Impl>::ExpectMetaProperty(const AstRawString* property_name,
const char* full_name, int pos) {
Consume(Token::PERIOD);
ExpectContextualKeyword(property_name);
@ -3404,7 +3403,7 @@ template <typename Impl>
typename ParserBase<Impl>::ExpressionT
ParserBase<Impl>::ParseNewTargetExpression() {
int pos = position();
ExpectMetaProperty(Token::TARGET, "new.target", pos);
ExpectMetaProperty(ast_value_factory()->target_string(), "new.target", pos);
classifier()->RecordAssignmentPatternError(
Scanner::Location(pos, end_position()),
@ -5747,7 +5746,7 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseForAwaitStatement(
}
}
ExpectContextualKeyword(Token::OF);
ExpectContextualKeyword(ast_value_factory()->of_string());
int each_keyword_pos = scanner()->location().beg_pos;
const bool kAllowIn = true;

View File

@ -928,7 +928,7 @@ ZoneChunkList<Parser::ExportClauseData>* Parser::ParseExportClause(
const AstRawString* local_name = ParseIdentifierName();
const AstRawString* export_name = nullptr;
Scanner::Location location = scanner()->location();
if (CheckContextualKeyword(Token::AS)) {
if (CheckContextualKeyword(ast_value_factory()->as_string())) {
export_name = ParseIdentifierName();
// Set the location to the whole "a as b" string, so that it makes sense
// both for errors due to "a" and for errors due to "b".
@ -973,7 +973,7 @@ ZonePtrList<const Parser::NamedImport>* Parser::ParseNamedImports(int pos) {
// In the presence of 'as', the left-side of the 'as' can
// be any IdentifierName. But without 'as', it must be a valid
// BindingIdentifier.
if (CheckContextualKeyword(Token::AS)) {
if (CheckContextualKeyword(ast_value_factory()->as_string())) {
local_name = ParseIdentifierName();
}
if (!Token::IsIdentifier(scanner()->current_token(), LanguageMode::kStrict,
@ -1047,7 +1047,7 @@ void Parser::ParseImportDeclaration() {
switch (peek()) {
case Token::MUL: {
Consume(Token::MUL);
ExpectContextualKeyword(Token::AS);
ExpectContextualKeyword(ast_value_factory()->as_string());
module_namespace_binding =
ParseIdentifier(kDontAllowRestrictedIdentifiers);
module_namespace_binding_loc = scanner()->location();
@ -1066,7 +1066,7 @@ void Parser::ParseImportDeclaration() {
}
}
ExpectContextualKeyword(Token::FROM);
ExpectContextualKeyword(ast_value_factory()->from_string());
Scanner::Location specifier_loc = scanner()->peek_location();
const AstRawString* module_specifier = ParseModuleSpecifier();
ExpectSemicolon();
@ -1184,10 +1184,11 @@ void Parser::ParseExportStar() {
int pos = position();
Consume(Token::MUL);
if (!FLAG_harmony_namespace_exports || !PeekContextualKeyword(Token::AS)) {
if (!FLAG_harmony_namespace_exports ||
!PeekContextualKeyword(ast_value_factory()->as_string())) {
// 'export' '*' 'from' ModuleSpecifier ';'
Scanner::Location loc = scanner()->location();
ExpectContextualKeyword(Token::FROM);
ExpectContextualKeyword(ast_value_factory()->from_string());
Scanner::Location specifier_loc = scanner()->peek_location();
const AstRawString* module_specifier = ParseModuleSpecifier();
ExpectSemicolon();
@ -1203,14 +1204,14 @@ void Parser::ParseExportStar() {
// ~>
// import * as .x from "..."; export {.x as x};
ExpectContextualKeyword(Token::AS);
ExpectContextualKeyword(ast_value_factory()->as_string());
const AstRawString* export_name = ParseIdentifierName();
Scanner::Location export_name_loc = scanner()->location();
const AstRawString* local_name = NextInternalNamespaceExportName();
Scanner::Location local_name_loc = Scanner::Location::invalid();
DeclareVariable(local_name, VariableMode::kConst, kCreatedInitialized, pos);
ExpectContextualKeyword(Token::FROM);
ExpectContextualKeyword(ast_value_factory()->from_string());
Scanner::Location specifier_loc = scanner()->peek_location();
const AstRawString* module_specifier = ParseModuleSpecifier();
ExpectSemicolon();
@ -1258,7 +1259,7 @@ Statement* Parser::ParseExportDeclaration() {
ParseExportClause(&reserved_loc);
const AstRawString* module_specifier = nullptr;
Scanner::Location specifier_loc;
if (CheckContextualKeyword(Token::FROM)) {
if (CheckContextualKeyword(ast_value_factory()->from_string())) {
specifier_loc = scanner()->peek_location();
module_specifier = ParseModuleSpecifier();
} else if (reserved_loc.IsValid()) {

View File

@ -154,7 +154,6 @@ static const Token::Value one_char_tokens[] = {
#define KEYWORDS(KEYWORD_GROUP, KEYWORD) \
KEYWORD_GROUP('a') \
KEYWORD("as", Token::AS) \
KEYWORD("async", Token::ASYNC) \
KEYWORD("await", Token::AWAIT) \
KEYWORD_GROUP('b') \
@ -179,7 +178,6 @@ static const Token::Value one_char_tokens[] = {
KEYWORD("false", Token::FALSE_LITERAL) \
KEYWORD("finally", Token::FINALLY) \
KEYWORD("for", Token::FOR) \
KEYWORD("from", Token::FROM) \
KEYWORD("function", Token::FUNCTION) \
KEYWORD_GROUP('g') \
KEYWORD("get", Token::GET) \
@ -192,13 +190,9 @@ static const Token::Value one_char_tokens[] = {
KEYWORD("interface", Token::FUTURE_STRICT_RESERVED_WORD) \
KEYWORD_GROUP('l') \
KEYWORD("let", Token::LET) \
KEYWORD_GROUP('m') \
KEYWORD("meta", Token::META) \
KEYWORD_GROUP('n') \
KEYWORD("new", Token::NEW) \
KEYWORD("null", Token::NULL_LITERAL) \
KEYWORD_GROUP('o') \
KEYWORD("of", Token::OF) \
KEYWORD_GROUP('p') \
KEYWORD("package", Token::FUTURE_STRICT_RESERVED_WORD) \
KEYWORD("private", Token::FUTURE_STRICT_RESERVED_WORD) \
@ -212,7 +206,6 @@ static const Token::Value one_char_tokens[] = {
KEYWORD("super", Token::SUPER) \
KEYWORD("switch", Token::SWITCH) \
KEYWORD_GROUP('t') \
KEYWORD("target", Token::TARGET) \
KEYWORD("this", Token::THIS) \
KEYWORD("throw", Token::THROW) \
KEYWORD("true", Token::TRUE_LITERAL) \

View File

@ -197,12 +197,7 @@ namespace internal {
\
/* Contextual keyword tokens */ \
C(GET, "get", 0) \
C(SET, "set", 0) \
C(OF, "of", 0) \
C(TARGET, "target", 0) \
C(META, "meta", 0) \
C(AS, "as", 0) \
C(FROM, "from", 0)
C(SET, "set", 0)
class Token {
public:
@ -223,7 +218,7 @@ class Token {
// Predicates
static bool IsKeyword(Value token) { return token_type[token] == 'K'; }
static bool IsContextualKeyword(Value token) {
return IsInRange(token, GET, FROM);
return IsInRange(token, GET, SET);
}
static bool IsIdentifier(Value token, LanguageMode language_mode,

View File

@ -108,18 +108,13 @@ TEST(AllThePushbacks) {
}
TEST(ContextualKeywordTokens) {
auto scanner = make_scanner("function of get bla");
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());
// of (contextual keyword)
scanner->Next();
CHECK_TOK(Token::IDENTIFIER, scanner->current_token());
CHECK_TOK(Token::OF, scanner->current_contextual_token());
// get (contextual keyword)
scanner->Next();
CHECK_TOK(Token::IDENTIFIER, scanner->current_token());

View File

@ -302,42 +302,42 @@ KNOWN_MAPS = {
("RO_SPACE", 0x02739): (171, "Tuple2Map"),
("RO_SPACE", 0x027d9): (173, "ArrayBoilerplateDescriptionMap"),
("RO_SPACE", 0x02b19): (161, "InterceptorInfoMap"),
("RO_SPACE", 0x04fc1): (153, "AccessCheckInfoMap"),
("RO_SPACE", 0x05011): (154, "AccessorInfoMap"),
("RO_SPACE", 0x05061): (155, "AccessorPairMap"),
("RO_SPACE", 0x050b1): (156, "AliasedArgumentsEntryMap"),
("RO_SPACE", 0x05101): (157, "AllocationMementoMap"),
("RO_SPACE", 0x05151): (158, "AsyncGeneratorRequestMap"),
("RO_SPACE", 0x051a1): (159, "DebugInfoMap"),
("RO_SPACE", 0x051f1): (160, "FunctionTemplateInfoMap"),
("RO_SPACE", 0x05241): (162, "InterpreterDataMap"),
("RO_SPACE", 0x05291): (163, "ModuleInfoEntryMap"),
("RO_SPACE", 0x052e1): (164, "ModuleMap"),
("RO_SPACE", 0x05331): (165, "ObjectTemplateInfoMap"),
("RO_SPACE", 0x05381): (166, "PromiseCapabilityMap"),
("RO_SPACE", 0x053d1): (167, "PromiseReactionMap"),
("RO_SPACE", 0x05421): (168, "PrototypeInfoMap"),
("RO_SPACE", 0x05471): (169, "ScriptMap"),
("RO_SPACE", 0x054c1): (170, "StackFrameInfoMap"),
("RO_SPACE", 0x05511): (172, "Tuple3Map"),
("RO_SPACE", 0x05561): (174, "WasmDebugInfoMap"),
("RO_SPACE", 0x055b1): (175, "WasmExportedFunctionDataMap"),
("RO_SPACE", 0x05601): (176, "CallableTaskMap"),
("RO_SPACE", 0x05651): (177, "CallbackTaskMap"),
("RO_SPACE", 0x056a1): (178, "PromiseFulfillReactionJobTaskMap"),
("RO_SPACE", 0x056f1): (179, "PromiseRejectReactionJobTaskMap"),
("RO_SPACE", 0x05741): (180, "PromiseResolveThenableJobTaskMap"),
("RO_SPACE", 0x05791): (181, "WeakFactoryCleanupJobTaskMap"),
("RO_SPACE", 0x057e1): (182, "MicrotaskQueueMap"),
("RO_SPACE", 0x05831): (183, "AllocationSiteWithWeakNextMap"),
("RO_SPACE", 0x05881): (183, "AllocationSiteWithoutWeakNextMap"),
("RO_SPACE", 0x058d1): (216, "LoadHandler1Map"),
("RO_SPACE", 0x05921): (216, "LoadHandler2Map"),
("RO_SPACE", 0x05971): (216, "LoadHandler3Map"),
("RO_SPACE", 0x059c1): (224, "StoreHandler0Map"),
("RO_SPACE", 0x05a11): (224, "StoreHandler1Map"),
("RO_SPACE", 0x05a61): (224, "StoreHandler2Map"),
("RO_SPACE", 0x05ab1): (224, "StoreHandler3Map"),
("RO_SPACE", 0x05039): (153, "AccessCheckInfoMap"),
("RO_SPACE", 0x05089): (154, "AccessorInfoMap"),
("RO_SPACE", 0x050d9): (155, "AccessorPairMap"),
("RO_SPACE", 0x05129): (156, "AliasedArgumentsEntryMap"),
("RO_SPACE", 0x05179): (157, "AllocationMementoMap"),
("RO_SPACE", 0x051c9): (158, "AsyncGeneratorRequestMap"),
("RO_SPACE", 0x05219): (159, "DebugInfoMap"),
("RO_SPACE", 0x05269): (160, "FunctionTemplateInfoMap"),
("RO_SPACE", 0x052b9): (162, "InterpreterDataMap"),
("RO_SPACE", 0x05309): (163, "ModuleInfoEntryMap"),
("RO_SPACE", 0x05359): (164, "ModuleMap"),
("RO_SPACE", 0x053a9): (165, "ObjectTemplateInfoMap"),
("RO_SPACE", 0x053f9): (166, "PromiseCapabilityMap"),
("RO_SPACE", 0x05449): (167, "PromiseReactionMap"),
("RO_SPACE", 0x05499): (168, "PrototypeInfoMap"),
("RO_SPACE", 0x054e9): (169, "ScriptMap"),
("RO_SPACE", 0x05539): (170, "StackFrameInfoMap"),
("RO_SPACE", 0x05589): (172, "Tuple3Map"),
("RO_SPACE", 0x055d9): (174, "WasmDebugInfoMap"),
("RO_SPACE", 0x05629): (175, "WasmExportedFunctionDataMap"),
("RO_SPACE", 0x05679): (176, "CallableTaskMap"),
("RO_SPACE", 0x056c9): (177, "CallbackTaskMap"),
("RO_SPACE", 0x05719): (178, "PromiseFulfillReactionJobTaskMap"),
("RO_SPACE", 0x05769): (179, "PromiseRejectReactionJobTaskMap"),
("RO_SPACE", 0x057b9): (180, "PromiseResolveThenableJobTaskMap"),
("RO_SPACE", 0x05809): (181, "WeakFactoryCleanupJobTaskMap"),
("RO_SPACE", 0x05859): (182, "MicrotaskQueueMap"),
("RO_SPACE", 0x058a9): (183, "AllocationSiteWithWeakNextMap"),
("RO_SPACE", 0x058f9): (183, "AllocationSiteWithoutWeakNextMap"),
("RO_SPACE", 0x05949): (216, "LoadHandler1Map"),
("RO_SPACE", 0x05999): (216, "LoadHandler2Map"),
("RO_SPACE", 0x059e9): (216, "LoadHandler3Map"),
("RO_SPACE", 0x05a39): (224, "StoreHandler0Map"),
("RO_SPACE", 0x05a89): (224, "StoreHandler1Map"),
("RO_SPACE", 0x05ad9): (224, "StoreHandler2Map"),
("RO_SPACE", 0x05b29): (224, "StoreHandler3Map"),
("MAP_SPACE", 0x00139): (1057, "ExternalMap"),
("MAP_SPACE", 0x00189): (1073, "JSMessageObjectMap"),
}