OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/parsing/parser.h" | 5 #include "src/parsing/parser.h" |
6 | 6 |
7 #include "src/api.h" | 7 #include "src/api.h" |
8 #include "src/ast/ast.h" | 8 #include "src/ast/ast.h" |
9 #include "src/ast/ast-expression-rewriter.h" | 9 #include "src/ast/ast-expression-rewriter.h" |
10 #include "src/ast/ast-expression-visitor.h" | 10 #include "src/ast/ast-expression-visitor.h" |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 | 322 |
323 | 323 |
324 // ---------------------------------------------------------------------------- | 324 // ---------------------------------------------------------------------------- |
325 // The CHECK_OK macro is a convenient macro to enforce error | 325 // The CHECK_OK macro is a convenient macro to enforce error |
326 // handling for functions that may fail (by returning !*ok). | 326 // handling for functions that may fail (by returning !*ok). |
327 // | 327 // |
328 // CAUTION: This macro appends extra statements after a call, | 328 // CAUTION: This macro appends extra statements after a call, |
329 // thus it must never be used where only a single statement | 329 // thus it must never be used where only a single statement |
330 // is correct (e.g. an if statement branch w/o braces)! | 330 // is correct (e.g. an if statement branch w/o braces)! |
331 | 331 |
332 #define CHECK_OK ok); \ | 332 #define CHECK_OK ok); \ |
333 if (!*ok) return NULL; \ | 333 if (!*ok) return nullptr; \ |
334 ((void)0 | 334 ((void)0 |
335 #define DUMMY ) // to make indentation work | 335 #define DUMMY ) // to make indentation work |
336 #undef DUMMY | 336 #undef DUMMY |
337 | 337 |
338 // Used in functions where the return type is not ExpressionT. | 338 #define CHECK_OK_VOID ok); \ |
339 #define CHECK_OK_CUSTOM(x) ok); \ | 339 if (!*ok) return; \ |
340 if (!*ok) return this->x(); \ | |
341 ((void)0 | 340 ((void)0 |
342 #define DUMMY ) // to make indentation work | 341 #define DUMMY ) // to make indentation work |
343 #undef DUMMY | 342 #undef DUMMY |
344 | 343 |
345 #define CHECK_FAILED /**/); \ | 344 #define CHECK_FAILED /**/); \ |
346 if (failed_) return NULL; \ | 345 if (failed_) return nullptr; \ |
347 ((void)0 | 346 ((void)0 |
348 #define DUMMY ) // to make indentation work | 347 #define DUMMY ) // to make indentation work |
349 #undef DUMMY | 348 #undef DUMMY |
350 | 349 |
351 // ---------------------------------------------------------------------------- | 350 // ---------------------------------------------------------------------------- |
352 // Implementation of Parser | 351 // Implementation of Parser |
353 | 352 |
354 bool ParserTraits::IsEval(const AstRawString* identifier) const { | 353 bool ParserTraits::IsEval(const AstRawString* identifier) const { |
355 return identifier == parser_->ast_value_factory()->eval_string(); | 354 return identifier == parser_->ast_value_factory()->eval_string(); |
356 } | 355 } |
(...skipping 858 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1215 DCHECK_NULL(target_stack_); | 1214 DCHECK_NULL(target_stack_); |
1216 | 1215 |
1217 if (result != nullptr) { | 1216 if (result != nullptr) { |
1218 Handle<String> inferred_name(shared_info->inferred_name()); | 1217 Handle<String> inferred_name(shared_info->inferred_name()); |
1219 result->set_inferred_name(inferred_name); | 1218 result->set_inferred_name(inferred_name); |
1220 } | 1219 } |
1221 return result; | 1220 return result; |
1222 } | 1221 } |
1223 | 1222 |
1224 | 1223 |
1225 void* Parser::ParseStatementList(ZoneList<Statement*>* body, int end_token, | 1224 void Parser::ParseStatementList(ZoneList<Statement*>* body, int end_token, |
1226 bool* ok) { | 1225 bool* ok) { |
1227 // StatementList :: | 1226 // StatementList :: |
1228 // (StatementListItem)* <end_token> | 1227 // (StatementListItem)* <end_token> |
1229 | 1228 |
1230 // Allocate a target stack to use for this set of source | 1229 // Allocate a target stack to use for this set of source |
1231 // elements. This way, all scripts and functions get their own | 1230 // elements. This way, all scripts and functions get their own |
1232 // target stack thus avoiding illegal breaks and continues across | 1231 // target stack thus avoiding illegal breaks and continues across |
1233 // functions. | 1232 // functions. |
1234 TargetScope scope(&this->target_stack_); | 1233 TargetScope scope(&this->target_stack_); |
1235 | 1234 |
1236 DCHECK(body != NULL); | 1235 DCHECK(body != NULL); |
1237 bool directive_prologue = true; // Parsing directive prologue. | 1236 bool directive_prologue = true; // Parsing directive prologue. |
1238 | 1237 |
1239 while (peek() != end_token) { | 1238 while (peek() != end_token) { |
1240 if (directive_prologue && peek() != Token::STRING) { | 1239 if (directive_prologue && peek() != Token::STRING) { |
1241 directive_prologue = false; | 1240 directive_prologue = false; |
1242 } | 1241 } |
1243 | 1242 |
1244 Scanner::Location token_loc = scanner()->peek_location(); | 1243 Scanner::Location token_loc = scanner()->peek_location(); |
1245 Statement* stat = ParseStatementListItem(CHECK_OK); | 1244 Statement* stat = ParseStatementListItem(CHECK_OK_VOID); |
1246 if (stat == NULL || stat->IsEmpty()) { | 1245 if (stat == NULL || stat->IsEmpty()) { |
1247 directive_prologue = false; // End of directive prologue. | 1246 directive_prologue = false; // End of directive prologue. |
1248 continue; | 1247 continue; |
1249 } | 1248 } |
1250 | 1249 |
1251 if (directive_prologue) { | 1250 if (directive_prologue) { |
1252 // A shot at a directive. | 1251 // A shot at a directive. |
1253 ExpressionStatement* e_stat; | 1252 ExpressionStatement* e_stat; |
1254 Literal* literal; | 1253 Literal* literal; |
1255 // Still processing directive prologue? | 1254 // Still processing directive prologue? |
(...skipping 13 matching lines...) Expand all Loading... |
1269 | 1268 |
1270 if (!this->scope()->HasSimpleParameters()) { | 1269 if (!this->scope()->HasSimpleParameters()) { |
1271 // TC39 deemed "use strict" directives to be an error when occurring | 1270 // TC39 deemed "use strict" directives to be an error when occurring |
1272 // in the body of a function with non-simple parameter list, on | 1271 // in the body of a function with non-simple parameter list, on |
1273 // 29/7/2015. https://goo.gl/ueA7Ln | 1272 // 29/7/2015. https://goo.gl/ueA7Ln |
1274 const AstRawString* string = literal->raw_value()->AsString(); | 1273 const AstRawString* string = literal->raw_value()->AsString(); |
1275 ParserTraits::ReportMessageAt( | 1274 ParserTraits::ReportMessageAt( |
1276 token_loc, MessageTemplate::kIllegalLanguageModeDirective, | 1275 token_loc, MessageTemplate::kIllegalLanguageModeDirective, |
1277 string); | 1276 string); |
1278 *ok = false; | 1277 *ok = false; |
1279 return nullptr; | 1278 return; |
1280 } | 1279 } |
1281 // Because declarations in strict eval code don't leak into the scope | 1280 // Because declarations in strict eval code don't leak into the scope |
1282 // of the eval call, it is likely that functions declared in strict | 1281 // of the eval call, it is likely that functions declared in strict |
1283 // eval code will be used within the eval code, so lazy parsing is | 1282 // eval code will be used within the eval code, so lazy parsing is |
1284 // probably not a win. | 1283 // probably not a win. |
1285 if (this->scope()->is_eval_scope()) mode_ = PARSE_EAGERLY; | 1284 if (this->scope()->is_eval_scope()) mode_ = PARSE_EAGERLY; |
1286 } else if (literal->raw_value()->AsString() == | 1285 } else if (literal->raw_value()->AsString() == |
1287 ast_value_factory()->use_asm_string() && | 1286 ast_value_factory()->use_asm_string() && |
1288 token_loc.end_pos - token_loc.beg_pos == | 1287 token_loc.end_pos - token_loc.beg_pos == |
1289 ast_value_factory()->use_asm_string()->length() + 2) { | 1288 ast_value_factory()->use_asm_string()->length() + 2) { |
(...skipping 10 matching lines...) Expand all Loading... |
1300 // End of the directive prologue. | 1299 // End of the directive prologue. |
1301 directive_prologue = false; | 1300 directive_prologue = false; |
1302 RaiseLanguageMode(SLOPPY); | 1301 RaiseLanguageMode(SLOPPY); |
1303 } | 1302 } |
1304 } else { | 1303 } else { |
1305 RaiseLanguageMode(SLOPPY); | 1304 RaiseLanguageMode(SLOPPY); |
1306 } | 1305 } |
1307 | 1306 |
1308 body->Add(stat, zone()); | 1307 body->Add(stat, zone()); |
1309 } | 1308 } |
1310 | |
1311 return 0; | |
1312 } | 1309 } |
1313 | 1310 |
1314 | 1311 |
1315 Statement* Parser::ParseStatementListItem(bool* ok) { | 1312 Statement* Parser::ParseStatementListItem(bool* ok) { |
1316 // (Ecma 262 6th Edition, 13.1): | 1313 // (Ecma 262 6th Edition, 13.1): |
1317 // StatementListItem: | 1314 // StatementListItem: |
1318 // Statement | 1315 // Statement |
1319 // Declaration | 1316 // Declaration |
1320 const Token::Value peeked = peek(); | 1317 const Token::Value peeked = peek(); |
1321 switch (peeked) { | 1318 switch (peeked) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1359 ParseImportDeclaration(CHECK_OK); | 1356 ParseImportDeclaration(CHECK_OK); |
1360 return factory()->NewEmptyStatement(kNoSourcePosition); | 1357 return factory()->NewEmptyStatement(kNoSourcePosition); |
1361 case Token::EXPORT: | 1358 case Token::EXPORT: |
1362 return ParseExportDeclaration(ok); | 1359 return ParseExportDeclaration(ok); |
1363 default: | 1360 default: |
1364 return ParseStatementListItem(ok); | 1361 return ParseStatementListItem(ok); |
1365 } | 1362 } |
1366 } | 1363 } |
1367 | 1364 |
1368 | 1365 |
1369 void* Parser::ParseModuleItemList(ZoneList<Statement*>* body, bool* ok) { | 1366 void Parser::ParseModuleItemList(ZoneList<Statement*>* body, bool* ok) { |
1370 // ecma262/#prod-Module | 1367 // ecma262/#prod-Module |
1371 // Module : | 1368 // Module : |
1372 // ModuleBody? | 1369 // ModuleBody? |
1373 // | 1370 // |
1374 // ecma262/#prod-ModuleItemList | 1371 // ecma262/#prod-ModuleItemList |
1375 // ModuleBody : | 1372 // ModuleBody : |
1376 // ModuleItem* | 1373 // ModuleItem* |
1377 | 1374 |
1378 DCHECK(scope()->is_module_scope()); | 1375 DCHECK(scope()->is_module_scope()); |
1379 while (peek() != Token::EOS) { | 1376 while (peek() != Token::EOS) { |
1380 Statement* stat = ParseModuleItem(CHECK_OK); | 1377 Statement* stat = ParseModuleItem(CHECK_OK_VOID); |
1381 if (stat && !stat->IsEmpty()) { | 1378 if (stat && !stat->IsEmpty()) { |
1382 body->Add(stat, zone()); | 1379 body->Add(stat, zone()); |
1383 } | 1380 } |
1384 } | 1381 } |
1385 return nullptr; | |
1386 } | 1382 } |
1387 | 1383 |
1388 | 1384 |
1389 const AstRawString* Parser::ParseModuleSpecifier(bool* ok) { | 1385 const AstRawString* Parser::ParseModuleSpecifier(bool* ok) { |
1390 // ModuleSpecifier : | 1386 // ModuleSpecifier : |
1391 // StringLiteral | 1387 // StringLiteral |
1392 | 1388 |
1393 Expect(Token::STRING, CHECK_OK); | 1389 Expect(Token::STRING, CHECK_OK); |
1394 return GetSymbol(scanner()); | 1390 return GetSymbol(scanner()); |
1395 } | 1391 } |
1396 | 1392 |
1397 | 1393 |
1398 void* Parser::ParseExportClause(ZoneList<const AstRawString*>* export_names, | 1394 void Parser::ParseExportClause(ZoneList<const AstRawString*>* export_names, |
1399 ZoneList<Scanner::Location>* export_locations, | 1395 ZoneList<Scanner::Location>* export_locations, |
1400 ZoneList<const AstRawString*>* local_names, | 1396 ZoneList<const AstRawString*>* local_names, |
1401 Scanner::Location* reserved_loc, bool* ok) { | 1397 Scanner::Location* reserved_loc, bool* ok) { |
1402 // ExportClause : | 1398 // ExportClause : |
1403 // '{' '}' | 1399 // '{' '}' |
1404 // '{' ExportsList '}' | 1400 // '{' ExportsList '}' |
1405 // '{' ExportsList ',' '}' | 1401 // '{' ExportsList ',' '}' |
1406 // | 1402 // |
1407 // ExportsList : | 1403 // ExportsList : |
1408 // ExportSpecifier | 1404 // ExportSpecifier |
1409 // ExportsList ',' ExportSpecifier | 1405 // ExportsList ',' ExportSpecifier |
1410 // | 1406 // |
1411 // ExportSpecifier : | 1407 // ExportSpecifier : |
1412 // IdentifierName | 1408 // IdentifierName |
1413 // IdentifierName 'as' IdentifierName | 1409 // IdentifierName 'as' IdentifierName |
1414 | 1410 |
1415 Expect(Token::LBRACE, CHECK_OK); | 1411 Expect(Token::LBRACE, CHECK_OK_VOID); |
1416 | 1412 |
1417 Token::Value name_tok; | 1413 Token::Value name_tok; |
1418 while ((name_tok = peek()) != Token::RBRACE) { | 1414 while ((name_tok = peek()) != Token::RBRACE) { |
1419 // Keep track of the first reserved word encountered in case our | 1415 // Keep track of the first reserved word encountered in case our |
1420 // caller needs to report an error. | 1416 // caller needs to report an error. |
1421 if (!reserved_loc->IsValid() && | 1417 if (!reserved_loc->IsValid() && |
1422 !Token::IsIdentifier(name_tok, STRICT, false, parsing_module_)) { | 1418 !Token::IsIdentifier(name_tok, STRICT, false, parsing_module_)) { |
1423 *reserved_loc = scanner()->location(); | 1419 *reserved_loc = scanner()->location(); |
1424 } | 1420 } |
1425 const AstRawString* local_name = ParseIdentifierName(CHECK_OK); | 1421 const AstRawString* local_name = ParseIdentifierName(CHECK_OK_VOID); |
1426 const AstRawString* export_name = NULL; | 1422 const AstRawString* export_name = NULL; |
1427 if (CheckContextualKeyword(CStrVector("as"))) { | 1423 if (CheckContextualKeyword(CStrVector("as"))) { |
1428 export_name = ParseIdentifierName(CHECK_OK); | 1424 export_name = ParseIdentifierName(CHECK_OK_VOID); |
1429 } | 1425 } |
1430 if (export_name == NULL) { | 1426 if (export_name == NULL) { |
1431 export_name = local_name; | 1427 export_name = local_name; |
1432 } | 1428 } |
1433 export_names->Add(export_name, zone()); | 1429 export_names->Add(export_name, zone()); |
1434 local_names->Add(local_name, zone()); | 1430 local_names->Add(local_name, zone()); |
1435 export_locations->Add(scanner()->location(), zone()); | 1431 export_locations->Add(scanner()->location(), zone()); |
1436 if (peek() == Token::RBRACE) break; | 1432 if (peek() == Token::RBRACE) break; |
1437 Expect(Token::COMMA, CHECK_OK); | 1433 Expect(Token::COMMA, CHECK_OK_VOID); |
1438 } | 1434 } |
1439 | 1435 |
1440 Expect(Token::RBRACE, CHECK_OK); | 1436 Expect(Token::RBRACE, CHECK_OK_VOID); |
1441 | |
1442 return nullptr; | |
1443 } | 1437 } |
1444 | 1438 |
1445 | 1439 |
1446 ZoneList<const Parser::NamedImport*>* Parser::ParseNamedImports( | 1440 ZoneList<const Parser::NamedImport*>* Parser::ParseNamedImports( |
1447 int pos, bool* ok) { | 1441 int pos, bool* ok) { |
1448 // NamedImports : | 1442 // NamedImports : |
1449 // '{' '}' | 1443 // '{' '}' |
1450 // '{' ImportsList '}' | 1444 // '{' ImportsList '}' |
1451 // '{' ImportsList ',' '}' | 1445 // '{' ImportsList ',' '}' |
1452 // | 1446 // |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1489 | 1483 |
1490 if (peek() == Token::RBRACE) break; | 1484 if (peek() == Token::RBRACE) break; |
1491 Expect(Token::COMMA, CHECK_OK); | 1485 Expect(Token::COMMA, CHECK_OK); |
1492 } | 1486 } |
1493 | 1487 |
1494 Expect(Token::RBRACE, CHECK_OK); | 1488 Expect(Token::RBRACE, CHECK_OK); |
1495 return result; | 1489 return result; |
1496 } | 1490 } |
1497 | 1491 |
1498 | 1492 |
1499 void* Parser::ParseImportDeclaration(bool* ok) { | 1493 void Parser::ParseImportDeclaration(bool* ok) { |
1500 // ImportDeclaration : | 1494 // ImportDeclaration : |
1501 // 'import' ImportClause 'from' ModuleSpecifier ';' | 1495 // 'import' ImportClause 'from' ModuleSpecifier ';' |
1502 // 'import' ModuleSpecifier ';' | 1496 // 'import' ModuleSpecifier ';' |
1503 // | 1497 // |
1504 // ImportClause : | 1498 // ImportClause : |
1505 // ImportedDefaultBinding | 1499 // ImportedDefaultBinding |
1506 // NameSpaceImport | 1500 // NameSpaceImport |
1507 // NamedImports | 1501 // NamedImports |
1508 // ImportedDefaultBinding ',' NameSpaceImport | 1502 // ImportedDefaultBinding ',' NameSpaceImport |
1509 // ImportedDefaultBinding ',' NamedImports | 1503 // ImportedDefaultBinding ',' NamedImports |
1510 // | 1504 // |
1511 // NameSpaceImport : | 1505 // NameSpaceImport : |
1512 // '*' 'as' ImportedBinding | 1506 // '*' 'as' ImportedBinding |
1513 | 1507 |
1514 int pos = peek_position(); | 1508 int pos = peek_position(); |
1515 Expect(Token::IMPORT, CHECK_OK); | 1509 Expect(Token::IMPORT, CHECK_OK_VOID); |
1516 | 1510 |
1517 Token::Value tok = peek(); | 1511 Token::Value tok = peek(); |
1518 | 1512 |
1519 // 'import' ModuleSpecifier ';' | 1513 // 'import' ModuleSpecifier ';' |
1520 if (tok == Token::STRING) { | 1514 if (tok == Token::STRING) { |
1521 const AstRawString* module_specifier = ParseModuleSpecifier(CHECK_OK); | 1515 const AstRawString* module_specifier = ParseModuleSpecifier(CHECK_OK_VOID); |
1522 ExpectSemicolon(CHECK_OK); | 1516 ExpectSemicolon(CHECK_OK_VOID); |
1523 module()->AddEmptyImport(module_specifier, scanner()->location(), zone()); | 1517 module()->AddEmptyImport(module_specifier, scanner()->location(), zone()); |
1524 return nullptr; | 1518 return; |
1525 } | 1519 } |
1526 | 1520 |
1527 // Parse ImportedDefaultBinding if present. | 1521 // Parse ImportedDefaultBinding if present. |
1528 const AstRawString* import_default_binding = nullptr; | 1522 const AstRawString* import_default_binding = nullptr; |
1529 Scanner::Location import_default_binding_loc; | 1523 Scanner::Location import_default_binding_loc; |
1530 if (tok != Token::MUL && tok != Token::LBRACE) { | 1524 if (tok != Token::MUL && tok != Token::LBRACE) { |
1531 import_default_binding = | 1525 import_default_binding = |
1532 ParseIdentifier(kDontAllowRestrictedIdentifiers, CHECK_OK); | 1526 ParseIdentifier(kDontAllowRestrictedIdentifiers, CHECK_OK_VOID); |
1533 import_default_binding_loc = scanner()->location(); | 1527 import_default_binding_loc = scanner()->location(); |
1534 DeclareImport(import_default_binding, pos, CHECK_OK); | 1528 DeclareImport(import_default_binding, pos, CHECK_OK_VOID); |
1535 } | 1529 } |
1536 | 1530 |
1537 // Parse NameSpaceImport or NamedImports if present. | 1531 // Parse NameSpaceImport or NamedImports if present. |
1538 const AstRawString* module_namespace_binding = nullptr; | 1532 const AstRawString* module_namespace_binding = nullptr; |
1539 Scanner::Location module_namespace_binding_loc; | 1533 Scanner::Location module_namespace_binding_loc; |
1540 const ZoneList<const NamedImport*>* named_imports = nullptr; | 1534 const ZoneList<const NamedImport*>* named_imports = nullptr; |
1541 if (import_default_binding == nullptr || Check(Token::COMMA)) { | 1535 if (import_default_binding == nullptr || Check(Token::COMMA)) { |
1542 switch (peek()) { | 1536 switch (peek()) { |
1543 case Token::MUL: { | 1537 case Token::MUL: { |
1544 Consume(Token::MUL); | 1538 Consume(Token::MUL); |
1545 ExpectContextualKeyword(CStrVector("as"), CHECK_OK); | 1539 ExpectContextualKeyword(CStrVector("as"), CHECK_OK_VOID); |
1546 module_namespace_binding = | 1540 module_namespace_binding = |
1547 ParseIdentifier(kDontAllowRestrictedIdentifiers, CHECK_OK); | 1541 ParseIdentifier(kDontAllowRestrictedIdentifiers, CHECK_OK_VOID); |
1548 module_namespace_binding_loc = scanner()->location(); | 1542 module_namespace_binding_loc = scanner()->location(); |
1549 break; | 1543 break; |
1550 } | 1544 } |
1551 | 1545 |
1552 case Token::LBRACE: | 1546 case Token::LBRACE: |
1553 named_imports = ParseNamedImports(pos, CHECK_OK); | 1547 named_imports = ParseNamedImports(pos, CHECK_OK_VOID); |
1554 break; | 1548 break; |
1555 | 1549 |
1556 default: | 1550 default: |
1557 *ok = false; | 1551 *ok = false; |
1558 ReportUnexpectedToken(scanner()->current_token()); | 1552 ReportUnexpectedToken(scanner()->current_token()); |
1559 return nullptr; | 1553 return; |
1560 } | 1554 } |
1561 } | 1555 } |
1562 | 1556 |
1563 ExpectContextualKeyword(CStrVector("from"), CHECK_OK); | 1557 ExpectContextualKeyword(CStrVector("from"), CHECK_OK_VOID); |
1564 const AstRawString* module_specifier = ParseModuleSpecifier(CHECK_OK); | 1558 const AstRawString* module_specifier = ParseModuleSpecifier(CHECK_OK_VOID); |
1565 ExpectSemicolon(CHECK_OK); | 1559 ExpectSemicolon(CHECK_OK_VOID); |
1566 | 1560 |
1567 // Now that we have all the information, we can make the appropriate | 1561 // Now that we have all the information, we can make the appropriate |
1568 // declarations. | 1562 // declarations. |
1569 | 1563 |
1570 if (module_namespace_binding != nullptr) { | 1564 if (module_namespace_binding != nullptr) { |
1571 module()->AddStarImport(module_namespace_binding, module_specifier, | 1565 module()->AddStarImport(module_namespace_binding, module_specifier, |
1572 module_namespace_binding_loc, zone()); | 1566 module_namespace_binding_loc, zone()); |
1573 // TODO(neis): Create special immutable binding for the namespace object. | 1567 // TODO(neis): Create special immutable binding for the namespace object. |
1574 } | 1568 } |
1575 | 1569 |
1576 // TODO(neis): Would prefer to call DeclareImport below rather than above and | 1570 // TODO(neis): Would prefer to call DeclareImport below rather than above and |
1577 // in ParseNamedImports, but then a possible error message would point to the | 1571 // in ParseNamedImports, but then a possible error message would point to the |
1578 // wrong location. Maybe have a DeclareAt version of Declare that takes a | 1572 // wrong location. Maybe have a DeclareAt version of Declare that takes a |
1579 // location? | 1573 // location? |
1580 | 1574 |
1581 if (import_default_binding != nullptr) { | 1575 if (import_default_binding != nullptr) { |
1582 module()->AddImport(ast_value_factory()->default_string(), | 1576 module()->AddImport(ast_value_factory()->default_string(), |
1583 import_default_binding, module_specifier, | 1577 import_default_binding, module_specifier, |
1584 import_default_binding_loc, zone()); | 1578 import_default_binding_loc, zone()); |
1585 // DeclareImport(import_default_binding, pos, CHECK_OK); | 1579 // DeclareImport(import_default_binding, pos, CHECK_OK_VOID); |
1586 } | 1580 } |
1587 | 1581 |
1588 if (named_imports != nullptr) { | 1582 if (named_imports != nullptr) { |
1589 if (named_imports->length() == 0) { | 1583 if (named_imports->length() == 0) { |
1590 module()->AddEmptyImport(module_specifier, scanner()->location(), zone()); | 1584 module()->AddEmptyImport(module_specifier, scanner()->location(), zone()); |
1591 } else { | 1585 } else { |
1592 for (int i = 0; i < named_imports->length(); ++i) { | 1586 for (int i = 0; i < named_imports->length(); ++i) { |
1593 const NamedImport* import = named_imports->at(i); | 1587 const NamedImport* import = named_imports->at(i); |
1594 module()->AddImport(import->import_name, import->local_name, | 1588 module()->AddImport(import->import_name, import->local_name, |
1595 module_specifier, import->location, zone()); | 1589 module_specifier, import->location, zone()); |
1596 // DeclareImport(import->local_name, pos, CHECK_OK); | 1590 // DeclareImport(import->local_name, pos, CHECK_OK_VOID); |
1597 } | 1591 } |
1598 } | 1592 } |
1599 } | 1593 } |
1600 | |
1601 return nullptr; | |
1602 } | 1594 } |
1603 | 1595 |
1604 | 1596 |
1605 Statement* Parser::ParseExportDefault(bool* ok) { | 1597 Statement* Parser::ParseExportDefault(bool* ok) { |
1606 // Supports the following productions, starting after the 'default' token: | 1598 // Supports the following productions, starting after the 'default' token: |
1607 // 'export' 'default' HoistableDeclaration | 1599 // 'export' 'default' HoistableDeclaration |
1608 // 'export' 'default' ClassDeclaration | 1600 // 'export' 'default' ClassDeclaration |
1609 // 'export' 'default' AssignmentExpression[In] ';' | 1601 // 'export' 'default' AssignmentExpression[In] ';' |
1610 | 1602 |
1611 Expect(Token::DEFAULT, CHECK_OK); | 1603 Expect(Token::DEFAULT, CHECK_OK); |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1927 // Let/const variables are always added to the immediately enclosing scope. | 1919 // Let/const variables are always added to the immediately enclosing scope. |
1928 Scope* scope = IsLexicalVariableMode(mode) | 1920 Scope* scope = IsLexicalVariableMode(mode) |
1929 ? this->scope() | 1921 ? this->scope() |
1930 : this->scope()->DeclarationScope(); | 1922 : this->scope()->DeclarationScope(); |
1931 return scope->NewUnresolved(factory(), name, Variable::NORMAL, | 1923 return scope->NewUnresolved(factory(), name, Variable::NORMAL, |
1932 scanner()->location().beg_pos, | 1924 scanner()->location().beg_pos, |
1933 scanner()->location().end_pos); | 1925 scanner()->location().end_pos); |
1934 } | 1926 } |
1935 | 1927 |
1936 | 1928 |
1937 void* Parser::DeclareImport(const AstRawString* local_name, int pos, bool* ok) { | 1929 void Parser::DeclareImport(const AstRawString* local_name, int pos, bool* ok) { |
1938 DCHECK_NOT_NULL(local_name); | 1930 DCHECK_NOT_NULL(local_name); |
1939 VariableProxy* proxy = NewUnresolved(local_name, IMPORT); | 1931 VariableProxy* proxy = NewUnresolved(local_name, IMPORT); |
1940 Declaration* declaration = | 1932 Declaration* declaration = |
1941 factory()->NewVariableDeclaration(proxy, IMPORT, scope(), pos); | 1933 factory()->NewVariableDeclaration(proxy, IMPORT, scope(), pos); |
1942 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK); | 1934 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK_VOID); |
1943 return nullptr; | |
1944 } | 1935 } |
1945 | 1936 |
1946 | 1937 |
1947 Variable* Parser::Declare(Declaration* declaration, | 1938 Variable* Parser::Declare(Declaration* declaration, |
1948 DeclarationDescriptor::Kind declaration_kind, | 1939 DeclarationDescriptor::Kind declaration_kind, |
1949 bool resolve, bool* ok, Scope* scope) { | 1940 bool resolve, bool* ok, Scope* scope) { |
1950 VariableProxy* proxy = declaration->proxy(); | 1941 VariableProxy* proxy = declaration->proxy(); |
1951 DCHECK(proxy->raw_name() != NULL); | 1942 DCHECK(proxy->raw_name() != NULL); |
1952 const AstRawString* name = proxy->raw_name(); | 1943 const AstRawString* name = proxy->raw_name(); |
1953 VariableMode mode = declaration->mode(); | 1944 VariableMode mode = declaration->mode(); |
(...skipping 2153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4107 // | 4098 // |
4108 if (expr->IsBinaryOperation()) { | 4099 if (expr->IsBinaryOperation()) { |
4109 BinaryOperation* binop = expr->AsBinaryOperation(); | 4100 BinaryOperation* binop = expr->AsBinaryOperation(); |
4110 // The classifier has already run, so we know that the expression is a valid | 4101 // The classifier has already run, so we know that the expression is a valid |
4111 // arrow function formals production. | 4102 // arrow function formals production. |
4112 DCHECK_EQ(binop->op(), Token::COMMA); | 4103 DCHECK_EQ(binop->op(), Token::COMMA); |
4113 Expression* left = binop->left(); | 4104 Expression* left = binop->left(); |
4114 Expression* right = binop->right(); | 4105 Expression* right = binop->right(); |
4115 int comma_pos = binop->position(); | 4106 int comma_pos = binop->position(); |
4116 ParseArrowFunctionFormalParameters(parameters, left, comma_pos, | 4107 ParseArrowFunctionFormalParameters(parameters, left, comma_pos, |
4117 CHECK_OK_CUSTOM(Void)); | 4108 CHECK_OK_VOID); |
4118 // LHS of comma expression should be unparenthesized. | 4109 // LHS of comma expression should be unparenthesized. |
4119 expr = right; | 4110 expr = right; |
4120 } | 4111 } |
4121 | 4112 |
4122 // Only the right-most expression may be a rest parameter. | 4113 // Only the right-most expression may be a rest parameter. |
4123 DCHECK(!parameters->has_rest); | 4114 DCHECK(!parameters->has_rest); |
4124 | 4115 |
4125 bool is_rest = expr->IsSpread(); | 4116 bool is_rest = expr->IsSpread(); |
4126 if (is_rest) { | 4117 if (is_rest) { |
4127 expr = expr->AsSpread()->expression(); | 4118 expr = expr->AsSpread()->expression(); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4186 body->Add(factory()->NewExpressionStatement(init_generator_variable, | 4177 body->Add(factory()->NewExpressionStatement(init_generator_variable, |
4187 kNoSourcePosition), | 4178 kNoSourcePosition), |
4188 zone()); | 4179 zone()); |
4189 | 4180 |
4190 Block* try_block = factory()->NewBlock(NULL, 8, true, kNoSourcePosition); | 4181 Block* try_block = factory()->NewBlock(NULL, 8, true, kNoSourcePosition); |
4191 | 4182 |
4192 ZoneList<Statement*>* inner_body = try_block->statements(); | 4183 ZoneList<Statement*>* inner_body = try_block->statements(); |
4193 | 4184 |
4194 Expression* return_value = nullptr; | 4185 Expression* return_value = nullptr; |
4195 if (body_type == FunctionBody::Normal) { | 4186 if (body_type == FunctionBody::Normal) { |
4196 ParseStatementList(inner_body, Token::RBRACE, CHECK_OK_CUSTOM(Void)); | 4187 ParseStatementList(inner_body, Token::RBRACE, CHECK_OK_VOID); |
4197 return_value = factory()->NewUndefinedLiteral(kNoSourcePosition); | 4188 return_value = factory()->NewUndefinedLiteral(kNoSourcePosition); |
4198 } else { | 4189 } else { |
4199 return_value = | 4190 return_value = |
4200 ParseAssignmentExpression(accept_IN, classifier, CHECK_OK_CUSTOM(Void)); | 4191 ParseAssignmentExpression(accept_IN, classifier, CHECK_OK_VOID); |
4201 ParserTraits::RewriteNonPattern(classifier, CHECK_OK_CUSTOM(Void)); | 4192 ParserTraits::RewriteNonPattern(classifier, CHECK_OK_VOID); |
4202 } | 4193 } |
4203 | 4194 |
4204 return_value = BuildPromiseResolve(return_value, return_value->position()); | 4195 return_value = BuildPromiseResolve(return_value, return_value->position()); |
4205 inner_body->Add( | 4196 inner_body->Add( |
4206 factory()->NewReturnStatement(return_value, return_value->position()), | 4197 factory()->NewReturnStatement(return_value, return_value->position()), |
4207 zone()); | 4198 zone()); |
4208 body->Add(BuildRejectPromiseOnException(try_block), zone()); | 4199 body->Add(BuildRejectPromiseOnException(try_block), zone()); |
4209 scope->set_end_position(scanner()->location().end_pos); | 4200 scope->set_end_position(scanner()->location().end_pos); |
4210 } | 4201 } |
4211 | 4202 |
(...skipping 16 matching lines...) Expand all Loading... |
4228 } | 4219 } |
4229 | 4220 |
4230 | 4221 |
4231 void ParserTraits::ParseArrowFunctionFormalParameterList( | 4222 void ParserTraits::ParseArrowFunctionFormalParameterList( |
4232 ParserFormalParameters* parameters, Expression* expr, | 4223 ParserFormalParameters* parameters, Expression* expr, |
4233 const Scanner::Location& params_loc, | 4224 const Scanner::Location& params_loc, |
4234 Scanner::Location* duplicate_loc, bool* ok) { | 4225 Scanner::Location* duplicate_loc, bool* ok) { |
4235 if (expr->IsEmptyParentheses()) return; | 4226 if (expr->IsEmptyParentheses()) return; |
4236 | 4227 |
4237 ParseArrowFunctionFormalParameters(parameters, expr, params_loc.end_pos, | 4228 ParseArrowFunctionFormalParameters(parameters, expr, params_loc.end_pos, |
4238 CHECK_OK_CUSTOM(Void)); | 4229 CHECK_OK_VOID); |
4239 | 4230 |
4240 if (parameters->Arity() > Code::kMaxArguments) { | 4231 if (parameters->Arity() > Code::kMaxArguments) { |
4241 ReportMessageAt(params_loc, MessageTemplate::kMalformedArrowFunParamList); | 4232 ReportMessageAt(params_loc, MessageTemplate::kMalformedArrowFunParamList); |
4242 *ok = false; | 4233 *ok = false; |
4243 return; | 4234 return; |
4244 } | 4235 } |
4245 | 4236 |
4246 Type::ExpressionClassifier classifier(parser_); | 4237 Type::ExpressionClassifier classifier(parser_); |
4247 if (!parameters->is_simple) { | 4238 if (!parameters->is_simple) { |
4248 classifier.RecordNonSimpleParameter(); | 4239 classifier.RecordNonSimpleParameter(); |
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4551 // data contains the information we need to construct the lazy function. | 4542 // data contains the information we need to construct the lazy function. |
4552 FunctionEntry entry = | 4543 FunctionEntry entry = |
4553 cached_parse_data_->GetFunctionEntry(function_block_pos); | 4544 cached_parse_data_->GetFunctionEntry(function_block_pos); |
4554 // Check that cached data is valid. If not, mark it as invalid (the embedder | 4545 // Check that cached data is valid. If not, mark it as invalid (the embedder |
4555 // handles it). Note that end position greater than end of stream is safe, | 4546 // handles it). Note that end position greater than end of stream is safe, |
4556 // and hard to check. | 4547 // and hard to check. |
4557 if (entry.is_valid() && entry.end_pos() > function_block_pos) { | 4548 if (entry.is_valid() && entry.end_pos() > function_block_pos) { |
4558 scanner()->SeekForward(entry.end_pos() - 1); | 4549 scanner()->SeekForward(entry.end_pos() - 1); |
4559 | 4550 |
4560 scope()->set_end_position(entry.end_pos()); | 4551 scope()->set_end_position(entry.end_pos()); |
4561 Expect(Token::RBRACE, CHECK_OK_CUSTOM(Void)); | 4552 Expect(Token::RBRACE, CHECK_OK_VOID); |
4562 total_preparse_skipped_ += scope()->end_position() - function_block_pos; | 4553 total_preparse_skipped_ += scope()->end_position() - function_block_pos; |
4563 *materialized_literal_count = entry.literal_count(); | 4554 *materialized_literal_count = entry.literal_count(); |
4564 *expected_property_count = entry.property_count(); | 4555 *expected_property_count = entry.property_count(); |
4565 SetLanguageMode(scope(), entry.language_mode()); | 4556 SetLanguageMode(scope(), entry.language_mode()); |
4566 if (entry.uses_super_property()) scope()->RecordSuperPropertyUsage(); | 4557 if (entry.uses_super_property()) scope()->RecordSuperPropertyUsage(); |
4567 if (entry.calls_eval()) scope()->RecordEvalCall(); | 4558 if (entry.calls_eval()) scope()->RecordEvalCall(); |
4568 return; | 4559 return; |
4569 } | 4560 } |
4570 cached_parse_data_->Reject(); | 4561 cached_parse_data_->Reject(); |
4571 } | 4562 } |
(...skipping 12 matching lines...) Expand all Loading... |
4584 return; | 4575 return; |
4585 } | 4576 } |
4586 if (logger.has_error()) { | 4577 if (logger.has_error()) { |
4587 ParserTraits::ReportMessageAt( | 4578 ParserTraits::ReportMessageAt( |
4588 Scanner::Location(logger.start(), logger.end()), logger.message(), | 4579 Scanner::Location(logger.start(), logger.end()), logger.message(), |
4589 logger.argument_opt(), logger.error_type()); | 4580 logger.argument_opt(), logger.error_type()); |
4590 *ok = false; | 4581 *ok = false; |
4591 return; | 4582 return; |
4592 } | 4583 } |
4593 scope()->set_end_position(logger.end()); | 4584 scope()->set_end_position(logger.end()); |
4594 Expect(Token::RBRACE, CHECK_OK_CUSTOM(Void)); | 4585 Expect(Token::RBRACE, CHECK_OK_VOID); |
4595 total_preparse_skipped_ += scope()->end_position() - function_block_pos; | 4586 total_preparse_skipped_ += scope()->end_position() - function_block_pos; |
4596 *materialized_literal_count = logger.literals(); | 4587 *materialized_literal_count = logger.literals(); |
4597 *expected_property_count = logger.properties(); | 4588 *expected_property_count = logger.properties(); |
4598 SetLanguageMode(scope(), logger.language_mode()); | 4589 SetLanguageMode(scope(), logger.language_mode()); |
4599 if (logger.uses_super_property()) { | 4590 if (logger.uses_super_property()) { |
4600 scope()->RecordSuperPropertyUsage(); | 4591 scope()->RecordSuperPropertyUsage(); |
4601 } | 4592 } |
4602 if (logger.calls_eval()) { | 4593 if (logger.calls_eval()) { |
4603 scope()->RecordEvalCall(); | 4594 scope()->RecordEvalCall(); |
4604 } | 4595 } |
(...skipping 1270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5875 if (property == nullptr) return; | 5866 if (property == nullptr) return; |
5876 // Do not rewrite (computed) key expressions | 5867 // Do not rewrite (computed) key expressions |
5877 AST_REWRITE_PROPERTY(Expression, property, value); | 5868 AST_REWRITE_PROPERTY(Expression, property, value); |
5878 } | 5869 } |
5879 | 5870 |
5880 Parser* parser_; | 5871 Parser* parser_; |
5881 }; | 5872 }; |
5882 | 5873 |
5883 | 5874 |
5884 void Parser::RewriteNonPattern(ExpressionClassifier* classifier, bool* ok) { | 5875 void Parser::RewriteNonPattern(ExpressionClassifier* classifier, bool* ok) { |
5885 ValidateExpression(classifier, CHECK_OK_CUSTOM(Void)); | 5876 ValidateExpression(classifier, CHECK_OK_VOID); |
5886 auto non_patterns_to_rewrite = function_state_->non_patterns_to_rewrite(); | 5877 auto non_patterns_to_rewrite = function_state_->non_patterns_to_rewrite(); |
5887 int begin = classifier->GetNonPatternBegin(); | 5878 int begin = classifier->GetNonPatternBegin(); |
5888 int end = non_patterns_to_rewrite->length(); | 5879 int end = non_patterns_to_rewrite->length(); |
5889 if (begin < end) { | 5880 if (begin < end) { |
5890 NonPatternRewriter rewriter(stack_limit_, this); | 5881 NonPatternRewriter rewriter(stack_limit_, this); |
5891 for (int i = begin; i < end; i++) { | 5882 for (int i = begin; i < end; i++) { |
5892 DCHECK(non_patterns_to_rewrite->at(i)->IsRewritableExpression()); | 5883 DCHECK(non_patterns_to_rewrite->at(i)->IsRewritableExpression()); |
5893 rewriter.Rewrite(non_patterns_to_rewrite->at(i)); | 5884 rewriter.Rewrite(non_patterns_to_rewrite->at(i)); |
5894 } | 5885 } |
5895 non_patterns_to_rewrite->Rewind(begin); | 5886 non_patterns_to_rewrite->Rewind(begin); |
(...skipping 1181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7077 } | 7068 } |
7078 | 7069 |
7079 #ifdef DEBUG | 7070 #ifdef DEBUG |
7080 void Parser::Print(AstNode* node) { | 7071 void Parser::Print(AstNode* node) { |
7081 ast_value_factory()->Internalize(Isolate::Current()); | 7072 ast_value_factory()->Internalize(Isolate::Current()); |
7082 node->Print(Isolate::Current()); | 7073 node->Print(Isolate::Current()); |
7083 } | 7074 } |
7084 #endif // DEBUG | 7075 #endif // DEBUG |
7085 | 7076 |
7086 #undef CHECK_OK | 7077 #undef CHECK_OK |
7087 #undef CHECK_OK_CUSTOM | 7078 #undef CHECK_OK_VOID |
7088 #undef CHECK_FAILED | 7079 #undef CHECK_FAILED |
7089 | 7080 |
7090 } // namespace internal | 7081 } // namespace internal |
7091 } // namespace v8 | 7082 } // namespace v8 |
OLD | NEW |