Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1014)

Side by Side Diff: src/parsing/parser.cc

Issue 2165513004: [parser] More CHECK_OK cleanup. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/parsing/parser.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 301
302 302
303 // ---------------------------------------------------------------------------- 303 // ----------------------------------------------------------------------------
304 // The CHECK_OK macro is a convenient macro to enforce error 304 // The CHECK_OK macro is a convenient macro to enforce error
305 // handling for functions that may fail (by returning !*ok). 305 // handling for functions that may fail (by returning !*ok).
306 // 306 //
307 // CAUTION: This macro appends extra statements after a call, 307 // CAUTION: This macro appends extra statements after a call,
308 // thus it must never be used where only a single statement 308 // thus it must never be used where only a single statement
309 // is correct (e.g. an if statement branch w/o braces)! 309 // is correct (e.g. an if statement branch w/o braces)!
310 310
311 #define CHECK_OK ok); \ 311 #define CHECK_OK ok); \
312 if (!*ok) return NULL; \ 312 if (!*ok) return nullptr; \
313 ((void)0 313 ((void)0
314 #define DUMMY ) // to make indentation work 314 #define DUMMY ) // to make indentation work
315 #undef DUMMY 315 #undef DUMMY
316 316
317 // Used in functions where the return type is not ExpressionT. 317 #define CHECK_OK_VOID ok); \
318 #define CHECK_OK_CUSTOM(x) ok); \ 318 if (!*ok) return; \
319 if (!*ok) return this->x(); \
320 ((void)0 319 ((void)0
321 #define DUMMY ) // to make indentation work 320 #define DUMMY ) // to make indentation work
322 #undef DUMMY 321 #undef DUMMY
323 322
324 #define CHECK_FAILED /**/); \ 323 #define CHECK_FAILED /**/); \
325 if (failed_) return NULL; \ 324 if (failed_) return NULL; \
nickie 2016/07/19 10:56:07 Well, since you changed NULL to nullptr in line 31
neis 2016/07/19 15:21:21 Done.
326 ((void)0 325 ((void)0
327 #define DUMMY ) // to make indentation work 326 #define DUMMY ) // to make indentation work
328 #undef DUMMY 327 #undef DUMMY
329 328
330 // ---------------------------------------------------------------------------- 329 // ----------------------------------------------------------------------------
331 // Implementation of Parser 330 // Implementation of Parser
332 331
333 bool ParserTraits::IsEval(const AstRawString* identifier) const { 332 bool ParserTraits::IsEval(const AstRawString* identifier) const {
334 return identifier == parser_->ast_value_factory()->eval_string(); 333 return identifier == parser_->ast_value_factory()->eval_string();
335 } 334 }
(...skipping 858 matching lines...) Expand 10 before | Expand all | Expand 10 after
1194 DCHECK(target_stack_ == NULL); 1193 DCHECK(target_stack_ == NULL);
1195 1194
1196 if (result != NULL) { 1195 if (result != NULL) {
1197 Handle<String> inferred_name(shared_info->inferred_name()); 1196 Handle<String> inferred_name(shared_info->inferred_name());
1198 result->set_inferred_name(inferred_name); 1197 result->set_inferred_name(inferred_name);
1199 } 1198 }
1200 return result; 1199 return result;
1201 } 1200 }
1202 1201
1203 1202
1204 void* Parser::ParseStatementList(ZoneList<Statement*>* body, int end_token, 1203 void Parser::ParseStatementList(ZoneList<Statement*>* body, int end_token,
1205 bool* ok) { 1204 bool* ok) {
1206 // StatementList :: 1205 // StatementList ::
1207 // (StatementListItem)* <end_token> 1206 // (StatementListItem)* <end_token>
1208 1207
1209 // Allocate a target stack to use for this set of source 1208 // Allocate a target stack to use for this set of source
1210 // elements. This way, all scripts and functions get their own 1209 // elements. This way, all scripts and functions get their own
1211 // target stack thus avoiding illegal breaks and continues across 1210 // target stack thus avoiding illegal breaks and continues across
1212 // functions. 1211 // functions.
1213 TargetScope scope(&this->target_stack_); 1212 TargetScope scope(&this->target_stack_);
1214 1213
1215 DCHECK(body != NULL); 1214 DCHECK(body != NULL);
1216 bool directive_prologue = true; // Parsing directive prologue. 1215 bool directive_prologue = true; // Parsing directive prologue.
1217 1216
1218 while (peek() != end_token) { 1217 while (peek() != end_token) {
1219 if (directive_prologue && peek() != Token::STRING) { 1218 if (directive_prologue && peek() != Token::STRING) {
1220 directive_prologue = false; 1219 directive_prologue = false;
1221 } 1220 }
1222 1221
1223 Scanner::Location token_loc = scanner()->peek_location(); 1222 Scanner::Location token_loc = scanner()->peek_location();
1224 Statement* stat = ParseStatementListItem(CHECK_OK); 1223 Statement* stat = ParseStatementListItem(CHECK_OK_VOID);
1225 if (stat == NULL || stat->IsEmpty()) { 1224 if (stat == NULL || stat->IsEmpty()) {
1226 directive_prologue = false; // End of directive prologue. 1225 directive_prologue = false; // End of directive prologue.
1227 continue; 1226 continue;
1228 } 1227 }
1229 1228
1230 if (directive_prologue) { 1229 if (directive_prologue) {
1231 // A shot at a directive. 1230 // A shot at a directive.
1232 ExpressionStatement* e_stat; 1231 ExpressionStatement* e_stat;
1233 Literal* literal; 1232 Literal* literal;
1234 // Still processing directive prologue? 1233 // Still processing directive prologue?
(...skipping 13 matching lines...) Expand all
1248 1247
1249 if (!scope_->HasSimpleParameters()) { 1248 if (!scope_->HasSimpleParameters()) {
1250 // TC39 deemed "use strict" directives to be an error when occurring 1249 // TC39 deemed "use strict" directives to be an error when occurring
1251 // in the body of a function with non-simple parameter list, on 1250 // in the body of a function with non-simple parameter list, on
1252 // 29/7/2015. https://goo.gl/ueA7Ln 1251 // 29/7/2015. https://goo.gl/ueA7Ln
1253 const AstRawString* string = literal->raw_value()->AsString(); 1252 const AstRawString* string = literal->raw_value()->AsString();
1254 ParserTraits::ReportMessageAt( 1253 ParserTraits::ReportMessageAt(
1255 token_loc, MessageTemplate::kIllegalLanguageModeDirective, 1254 token_loc, MessageTemplate::kIllegalLanguageModeDirective,
1256 string); 1255 string);
1257 *ok = false; 1256 *ok = false;
1258 return nullptr; 1257 return;
1259 } 1258 }
1260 // Because declarations in strict eval code don't leak into the scope 1259 // Because declarations in strict eval code don't leak into the scope
1261 // of the eval call, it is likely that functions declared in strict 1260 // of the eval call, it is likely that functions declared in strict
1262 // eval code will be used within the eval code, so lazy parsing is 1261 // eval code will be used within the eval code, so lazy parsing is
1263 // probably not a win. 1262 // probably not a win.
1264 if (scope_->is_eval_scope()) mode_ = PARSE_EAGERLY; 1263 if (scope_->is_eval_scope()) mode_ = PARSE_EAGERLY;
1265 } else if (literal->raw_value()->AsString() == 1264 } else if (literal->raw_value()->AsString() ==
1266 ast_value_factory()->use_asm_string() && 1265 ast_value_factory()->use_asm_string() &&
1267 token_loc.end_pos - token_loc.beg_pos == 1266 token_loc.end_pos - token_loc.beg_pos ==
1268 ast_value_factory()->use_asm_string()->length() + 2) { 1267 ast_value_factory()->use_asm_string()->length() + 2) {
(...skipping 10 matching lines...) Expand all
1279 // End of the directive prologue. 1278 // End of the directive prologue.
1280 directive_prologue = false; 1279 directive_prologue = false;
1281 RaiseLanguageMode(SLOPPY); 1280 RaiseLanguageMode(SLOPPY);
1282 } 1281 }
1283 } else { 1282 } else {
1284 RaiseLanguageMode(SLOPPY); 1283 RaiseLanguageMode(SLOPPY);
1285 } 1284 }
1286 1285
1287 body->Add(stat, zone()); 1286 body->Add(stat, zone());
1288 } 1287 }
1289
1290 return 0;
1291 } 1288 }
1292 1289
1293 1290
1294 Statement* Parser::ParseStatementListItem(bool* ok) { 1291 Statement* Parser::ParseStatementListItem(bool* ok) {
1295 // (Ecma 262 6th Edition, 13.1): 1292 // (Ecma 262 6th Edition, 13.1):
1296 // StatementListItem: 1293 // StatementListItem:
1297 // Statement 1294 // Statement
1298 // Declaration 1295 // Declaration
1299 const Token::Value peeked = peek(); 1296 const Token::Value peeked = peek();
1300 switch (peeked) { 1297 switch (peeked) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1338 ParseImportDeclaration(CHECK_OK); 1335 ParseImportDeclaration(CHECK_OK);
1339 return factory()->NewEmptyStatement(kNoSourcePosition); 1336 return factory()->NewEmptyStatement(kNoSourcePosition);
1340 case Token::EXPORT: 1337 case Token::EXPORT:
1341 return ParseExportDeclaration(ok); 1338 return ParseExportDeclaration(ok);
1342 default: 1339 default:
1343 return ParseStatementListItem(ok); 1340 return ParseStatementListItem(ok);
1344 } 1341 }
1345 } 1342 }
1346 1343
1347 1344
1348 void* Parser::ParseModuleItemList(ZoneList<Statement*>* body, bool* ok) { 1345 void Parser::ParseModuleItemList(ZoneList<Statement*>* body, bool* ok) {
1349 // ecma262/#prod-Module 1346 // ecma262/#prod-Module
1350 // Module : 1347 // Module :
1351 // ModuleBody? 1348 // ModuleBody?
1352 // 1349 //
1353 // ecma262/#prod-ModuleItemList 1350 // ecma262/#prod-ModuleItemList
1354 // ModuleBody : 1351 // ModuleBody :
1355 // ModuleItem* 1352 // ModuleItem*
1356 1353
1357 DCHECK(scope_->is_module_scope()); 1354 DCHECK(scope_->is_module_scope());
1358 while (peek() != Token::EOS) { 1355 while (peek() != Token::EOS) {
1359 Statement* stat = ParseModuleItem(CHECK_OK); 1356 Statement* stat = ParseModuleItem(CHECK_OK_VOID);
1360 if (stat && !stat->IsEmpty()) { 1357 if (stat && !stat->IsEmpty()) {
1361 body->Add(stat, zone()); 1358 body->Add(stat, zone());
1362 } 1359 }
1363 } 1360 }
1364 return nullptr;
1365 } 1361 }
1366 1362
1367 1363
1368 const AstRawString* Parser::ParseModuleSpecifier(bool* ok) { 1364 const AstRawString* Parser::ParseModuleSpecifier(bool* ok) {
1369 // ModuleSpecifier : 1365 // ModuleSpecifier :
1370 // StringLiteral 1366 // StringLiteral
1371 1367
1372 Expect(Token::STRING, CHECK_OK); 1368 Expect(Token::STRING, CHECK_OK);
1373 return GetSymbol(scanner()); 1369 return GetSymbol(scanner());
1374 } 1370 }
1375 1371
1376 1372
1377 void* Parser::ParseExportClause(ZoneList<const AstRawString*>* export_names, 1373 void Parser::ParseExportClause(ZoneList<const AstRawString*>* export_names,
1378 ZoneList<Scanner::Location>* export_locations, 1374 ZoneList<Scanner::Location>* export_locations,
1379 ZoneList<const AstRawString*>* local_names, 1375 ZoneList<const AstRawString*>* local_names,
1380 Scanner::Location* reserved_loc, bool* ok) { 1376 Scanner::Location* reserved_loc, bool* ok) {
1381 // ExportClause : 1377 // ExportClause :
1382 // '{' '}' 1378 // '{' '}'
1383 // '{' ExportsList '}' 1379 // '{' ExportsList '}'
1384 // '{' ExportsList ',' '}' 1380 // '{' ExportsList ',' '}'
1385 // 1381 //
1386 // ExportsList : 1382 // ExportsList :
1387 // ExportSpecifier 1383 // ExportSpecifier
1388 // ExportsList ',' ExportSpecifier 1384 // ExportsList ',' ExportSpecifier
1389 // 1385 //
1390 // ExportSpecifier : 1386 // ExportSpecifier :
1391 // IdentifierName 1387 // IdentifierName
1392 // IdentifierName 'as' IdentifierName 1388 // IdentifierName 'as' IdentifierName
1393 1389
1394 Expect(Token::LBRACE, CHECK_OK); 1390 Expect(Token::LBRACE, CHECK_OK_VOID);
1395 1391
1396 Token::Value name_tok; 1392 Token::Value name_tok;
1397 while ((name_tok = peek()) != Token::RBRACE) { 1393 while ((name_tok = peek()) != Token::RBRACE) {
1398 // Keep track of the first reserved word encountered in case our 1394 // Keep track of the first reserved word encountered in case our
1399 // caller needs to report an error. 1395 // caller needs to report an error.
1400 if (!reserved_loc->IsValid() && 1396 if (!reserved_loc->IsValid() &&
1401 !Token::IsIdentifier(name_tok, STRICT, false, parsing_module_)) { 1397 !Token::IsIdentifier(name_tok, STRICT, false, parsing_module_)) {
1402 *reserved_loc = scanner()->location(); 1398 *reserved_loc = scanner()->location();
1403 } 1399 }
1404 const AstRawString* local_name = ParseIdentifierName(CHECK_OK); 1400 const AstRawString* local_name = ParseIdentifierName(CHECK_OK_VOID);
1405 const AstRawString* export_name = NULL; 1401 const AstRawString* export_name = NULL;
1406 if (CheckContextualKeyword(CStrVector("as"))) { 1402 if (CheckContextualKeyword(CStrVector("as"))) {
1407 export_name = ParseIdentifierName(CHECK_OK); 1403 export_name = ParseIdentifierName(CHECK_OK_VOID);
1408 } 1404 }
1409 if (export_name == NULL) { 1405 if (export_name == NULL) {
1410 export_name = local_name; 1406 export_name = local_name;
1411 } 1407 }
1412 export_names->Add(export_name, zone()); 1408 export_names->Add(export_name, zone());
1413 local_names->Add(local_name, zone()); 1409 local_names->Add(local_name, zone());
1414 export_locations->Add(scanner()->location(), zone()); 1410 export_locations->Add(scanner()->location(), zone());
1415 if (peek() == Token::RBRACE) break; 1411 if (peek() == Token::RBRACE) break;
1416 Expect(Token::COMMA, CHECK_OK); 1412 Expect(Token::COMMA, CHECK_OK_VOID);
1417 } 1413 }
1418 1414
1419 Expect(Token::RBRACE, CHECK_OK); 1415 Expect(Token::RBRACE, CHECK_OK_VOID);
1420
1421 return nullptr;
1422 } 1416 }
1423 1417
1424 1418
1425 ZoneList<const Parser::NamedImport*>* Parser::ParseNamedImports( 1419 ZoneList<const Parser::NamedImport*>* Parser::ParseNamedImports(
1426 int pos, bool* ok) { 1420 int pos, bool* ok) {
1427 // NamedImports : 1421 // NamedImports :
1428 // '{' '}' 1422 // '{' '}'
1429 // '{' ImportsList '}' 1423 // '{' ImportsList '}'
1430 // '{' ImportsList ',' '}' 1424 // '{' ImportsList ',' '}'
1431 // 1425 //
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1468 1462
1469 if (peek() == Token::RBRACE) break; 1463 if (peek() == Token::RBRACE) break;
1470 Expect(Token::COMMA, CHECK_OK); 1464 Expect(Token::COMMA, CHECK_OK);
1471 } 1465 }
1472 1466
1473 Expect(Token::RBRACE, CHECK_OK); 1467 Expect(Token::RBRACE, CHECK_OK);
1474 return result; 1468 return result;
1475 } 1469 }
1476 1470
1477 1471
1478 void* Parser::ParseImportDeclaration(bool* ok) { 1472 void Parser::ParseImportDeclaration(bool* ok) {
1479 // ImportDeclaration : 1473 // ImportDeclaration :
1480 // 'import' ImportClause 'from' ModuleSpecifier ';' 1474 // 'import' ImportClause 'from' ModuleSpecifier ';'
1481 // 'import' ModuleSpecifier ';' 1475 // 'import' ModuleSpecifier ';'
1482 // 1476 //
1483 // ImportClause : 1477 // ImportClause :
1484 // ImportedDefaultBinding 1478 // ImportedDefaultBinding
1485 // NameSpaceImport 1479 // NameSpaceImport
1486 // NamedImports 1480 // NamedImports
1487 // ImportedDefaultBinding ',' NameSpaceImport 1481 // ImportedDefaultBinding ',' NameSpaceImport
1488 // ImportedDefaultBinding ',' NamedImports 1482 // ImportedDefaultBinding ',' NamedImports
1489 // 1483 //
1490 // NameSpaceImport : 1484 // NameSpaceImport :
1491 // '*' 'as' ImportedBinding 1485 // '*' 'as' ImportedBinding
1492 1486
1493 int pos = peek_position(); 1487 int pos = peek_position();
1494 Expect(Token::IMPORT, CHECK_OK); 1488 Expect(Token::IMPORT, CHECK_OK_VOID);
1495 1489
1496 Token::Value tok = peek(); 1490 Token::Value tok = peek();
1497 1491
1498 // 'import' ModuleSpecifier ';' 1492 // 'import' ModuleSpecifier ';'
1499 if (tok == Token::STRING) { 1493 if (tok == Token::STRING) {
1500 const AstRawString* module_specifier = ParseModuleSpecifier(CHECK_OK); 1494 const AstRawString* module_specifier = ParseModuleSpecifier(CHECK_OK_VOID);
1501 ExpectSemicolon(CHECK_OK); 1495 ExpectSemicolon(CHECK_OK_VOID);
1502 scope_->module()->AddEmptyImport( 1496 scope_->module()->AddEmptyImport(
1503 module_specifier, scanner()->location(), zone()); 1497 module_specifier, scanner()->location(), zone());
1504 return nullptr; 1498 return;
1505 } 1499 }
1506 1500
1507 // Parse ImportedDefaultBinding if present. 1501 // Parse ImportedDefaultBinding if present.
1508 const AstRawString* import_default_binding = nullptr; 1502 const AstRawString* import_default_binding = nullptr;
1509 Scanner::Location import_default_binding_loc; 1503 Scanner::Location import_default_binding_loc;
1510 if (tok != Token::MUL && tok != Token::LBRACE) { 1504 if (tok != Token::MUL && tok != Token::LBRACE) {
1511 import_default_binding = 1505 import_default_binding =
1512 ParseIdentifier(kDontAllowRestrictedIdentifiers, CHECK_OK); 1506 ParseIdentifier(kDontAllowRestrictedIdentifiers, CHECK_OK_VOID);
1513 import_default_binding_loc = scanner()->location(); 1507 import_default_binding_loc = scanner()->location();
1514 DeclareImport(import_default_binding, pos, CHECK_OK); 1508 DeclareImport(import_default_binding, pos, CHECK_OK_VOID);
1515 } 1509 }
1516 1510
1517 // Parse NameSpaceImport or NamedImports if present. 1511 // Parse NameSpaceImport or NamedImports if present.
1518 const AstRawString* module_namespace_binding = nullptr; 1512 const AstRawString* module_namespace_binding = nullptr;
1519 Scanner::Location module_namespace_binding_loc; 1513 Scanner::Location module_namespace_binding_loc;
1520 const ZoneList<const NamedImport*>* named_imports = nullptr; 1514 const ZoneList<const NamedImport*>* named_imports = nullptr;
1521 if (import_default_binding == nullptr || Check(Token::COMMA)) { 1515 if (import_default_binding == nullptr || Check(Token::COMMA)) {
1522 switch (peek()) { 1516 switch (peek()) {
1523 case Token::MUL: { 1517 case Token::MUL: {
1524 Consume(Token::MUL); 1518 Consume(Token::MUL);
1525 ExpectContextualKeyword(CStrVector("as"), CHECK_OK); 1519 ExpectContextualKeyword(CStrVector("as"), CHECK_OK_VOID);
1526 module_namespace_binding = 1520 module_namespace_binding =
1527 ParseIdentifier(kDontAllowRestrictedIdentifiers, CHECK_OK); 1521 ParseIdentifier(kDontAllowRestrictedIdentifiers, CHECK_OK_VOID);
1528 module_namespace_binding_loc = scanner()->location(); 1522 module_namespace_binding_loc = scanner()->location();
1529 break; 1523 break;
1530 } 1524 }
1531 1525
1532 case Token::LBRACE: 1526 case Token::LBRACE:
1533 named_imports = ParseNamedImports(pos, CHECK_OK); 1527 named_imports = ParseNamedImports(pos, CHECK_OK_VOID);
1534 break; 1528 break;
1535 1529
1536 default: 1530 default:
1537 *ok = false; 1531 *ok = false;
1538 ReportUnexpectedToken(scanner()->current_token()); 1532 ReportUnexpectedToken(scanner()->current_token());
1539 return nullptr; 1533 return;
1540 } 1534 }
1541 } 1535 }
1542 1536
1543 ExpectContextualKeyword(CStrVector("from"), CHECK_OK); 1537 ExpectContextualKeyword(CStrVector("from"), CHECK_OK_VOID);
1544 const AstRawString* module_specifier = ParseModuleSpecifier(CHECK_OK); 1538 const AstRawString* module_specifier = ParseModuleSpecifier(CHECK_OK_VOID);
1545 ExpectSemicolon(CHECK_OK); 1539 ExpectSemicolon(CHECK_OK_VOID);
1546 1540
1547 // Now that we have all the information, we can make the appropriate 1541 // Now that we have all the information, we can make the appropriate
1548 // declarations. 1542 // declarations.
1549 1543
1550 if (module_namespace_binding != nullptr) { 1544 if (module_namespace_binding != nullptr) {
1551 scope_->module()->AddStarImport( 1545 scope_->module()->AddStarImport(
1552 module_namespace_binding, module_specifier, 1546 module_namespace_binding, module_specifier,
1553 module_namespace_binding_loc, zone()); 1547 module_namespace_binding_loc, zone());
1554 // TODO(neis): Create special immutable binding for the namespace object. 1548 // TODO(neis): Create special immutable binding for the namespace object.
1555 } 1549 }
1556 1550
1557 // TODO(neis): Would prefer to call DeclareImport below rather than above and 1551 // TODO(neis): Would prefer to call DeclareImport below rather than above and
1558 // in ParseNamedImports, but then a possible error message would point to the 1552 // in ParseNamedImports, but then a possible error message would point to the
1559 // wrong location. Maybe have a DeclareAt version of Declare that takes a 1553 // wrong location. Maybe have a DeclareAt version of Declare that takes a
1560 // location? 1554 // location?
1561 1555
1562 if (import_default_binding != nullptr) { 1556 if (import_default_binding != nullptr) {
1563 scope_->module()->AddImport( 1557 scope_->module()->AddImport(
1564 ast_value_factory()->default_string(), import_default_binding, 1558 ast_value_factory()->default_string(), import_default_binding,
1565 module_specifier, import_default_binding_loc, zone()); 1559 module_specifier, import_default_binding_loc, zone());
1566 // DeclareImport(import_default_binding, pos, CHECK_OK); 1560 // DeclareImport(import_default_binding, pos, CHECK_OK_VOID);
1567 } 1561 }
1568 1562
1569 if (named_imports != nullptr) { 1563 if (named_imports != nullptr) {
1570 if (named_imports->length() == 0) { 1564 if (named_imports->length() == 0) {
1571 scope_->module()->AddEmptyImport( 1565 scope_->module()->AddEmptyImport(
1572 module_specifier, scanner()->location(), zone()); 1566 module_specifier, scanner()->location(), zone());
1573 } else { 1567 } else {
1574 for (int i = 0; i < named_imports->length(); ++i) { 1568 for (int i = 0; i < named_imports->length(); ++i) {
1575 const NamedImport* import = named_imports->at(i); 1569 const NamedImport* import = named_imports->at(i);
1576 scope_->module()->AddImport( 1570 scope_->module()->AddImport(
1577 import->import_name, import->local_name, 1571 import->import_name, import->local_name,
1578 module_specifier, import->location, zone()); 1572 module_specifier, import->location, zone());
1579 // DeclareImport(import->local_name, pos, CHECK_OK); 1573 // DeclareImport(import->local_name, pos, CHECK_OK_VOID);
1580 } 1574 }
1581 } 1575 }
1582 } 1576 }
1583
1584 return nullptr;
1585 } 1577 }
1586 1578
1587 1579
1588 Statement* Parser::ParseExportDefault(bool* ok) { 1580 Statement* Parser::ParseExportDefault(bool* ok) {
1589 // Supports the following productions, starting after the 'default' token: 1581 // Supports the following productions, starting after the 'default' token:
1590 // 'export' 'default' HoistableDeclaration 1582 // 'export' 'default' HoistableDeclaration
1591 // 'export' 'default' ClassDeclaration 1583 // 'export' 'default' ClassDeclaration
1592 // 'export' 'default' AssignmentExpression[In] ';' 1584 // 'export' 'default' AssignmentExpression[In] ';'
1593 1585
1594 Expect(Token::DEFAULT, CHECK_OK); 1586 Expect(Token::DEFAULT, CHECK_OK);
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
1911 // scope. 1903 // scope.
1912 // Let/const variables are always added to the immediately enclosing scope. 1904 // Let/const variables are always added to the immediately enclosing scope.
1913 Scope* scope = 1905 Scope* scope =
1914 IsLexicalVariableMode(mode) ? scope_ : scope_->DeclarationScope(); 1906 IsLexicalVariableMode(mode) ? scope_ : scope_->DeclarationScope();
1915 return scope->NewUnresolved(factory(), name, Variable::NORMAL, 1907 return scope->NewUnresolved(factory(), name, Variable::NORMAL,
1916 scanner()->location().beg_pos, 1908 scanner()->location().beg_pos,
1917 scanner()->location().end_pos); 1909 scanner()->location().end_pos);
1918 } 1910 }
1919 1911
1920 1912
1921 void* Parser::DeclareImport(const AstRawString* local_name, int pos, bool* ok) { 1913 void Parser::DeclareImport(const AstRawString* local_name, int pos, bool* ok) {
1922 DCHECK_NOT_NULL(local_name); 1914 DCHECK_NOT_NULL(local_name);
1923 VariableProxy* proxy = NewUnresolved(local_name, IMPORT); 1915 VariableProxy* proxy = NewUnresolved(local_name, IMPORT);
1924 Declaration* declaration = 1916 Declaration* declaration =
1925 factory()->NewVariableDeclaration(proxy, IMPORT, scope_, pos); 1917 factory()->NewVariableDeclaration(proxy, IMPORT, scope_, pos);
1926 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK); 1918 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK_VOID);
1927 return nullptr;
1928 } 1919 }
1929 1920
1930 1921
1931 Variable* Parser::Declare(Declaration* declaration, 1922 Variable* Parser::Declare(Declaration* declaration,
1932 DeclarationDescriptor::Kind declaration_kind, 1923 DeclarationDescriptor::Kind declaration_kind,
1933 bool resolve, bool* ok, Scope* scope) { 1924 bool resolve, bool* ok, Scope* scope) {
1934 VariableProxy* proxy = declaration->proxy(); 1925 VariableProxy* proxy = declaration->proxy();
1935 DCHECK(proxy->raw_name() != NULL); 1926 DCHECK(proxy->raw_name() != NULL);
1936 const AstRawString* name = proxy->raw_name(); 1927 const AstRawString* name = proxy->raw_name();
1937 VariableMode mode = declaration->mode(); 1928 VariableMode mode = declaration->mode();
(...skipping 2151 matching lines...) Expand 10 before | Expand all | Expand 10 after
4089 // 4080 //
4090 if (expr->IsBinaryOperation()) { 4081 if (expr->IsBinaryOperation()) {
4091 BinaryOperation* binop = expr->AsBinaryOperation(); 4082 BinaryOperation* binop = expr->AsBinaryOperation();
4092 // The classifier has already run, so we know that the expression is a valid 4083 // The classifier has already run, so we know that the expression is a valid
4093 // arrow function formals production. 4084 // arrow function formals production.
4094 DCHECK_EQ(binop->op(), Token::COMMA); 4085 DCHECK_EQ(binop->op(), Token::COMMA);
4095 Expression* left = binop->left(); 4086 Expression* left = binop->left();
4096 Expression* right = binop->right(); 4087 Expression* right = binop->right();
4097 int comma_pos = binop->position(); 4088 int comma_pos = binop->position();
4098 ParseArrowFunctionFormalParameters(parameters, left, comma_pos, 4089 ParseArrowFunctionFormalParameters(parameters, left, comma_pos,
4099 CHECK_OK_CUSTOM(Void)); 4090 CHECK_OK_VOID);
4100 // LHS of comma expression should be unparenthesized. 4091 // LHS of comma expression should be unparenthesized.
4101 expr = right; 4092 expr = right;
4102 } 4093 }
4103 4094
4104 // Only the right-most expression may be a rest parameter. 4095 // Only the right-most expression may be a rest parameter.
4105 DCHECK(!parameters->has_rest); 4096 DCHECK(!parameters->has_rest);
4106 4097
4107 bool is_rest = expr->IsSpread(); 4098 bool is_rest = expr->IsSpread();
4108 if (is_rest) { 4099 if (is_rest) {
4109 expr = expr->AsSpread()->expression(); 4100 expr = expr->AsSpread()->expression();
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
4168 body->Add(factory()->NewExpressionStatement(init_generator_variable, 4159 body->Add(factory()->NewExpressionStatement(init_generator_variable,
4169 kNoSourcePosition), 4160 kNoSourcePosition),
4170 zone()); 4161 zone());
4171 4162
4172 Block* try_block = factory()->NewBlock(NULL, 8, true, kNoSourcePosition); 4163 Block* try_block = factory()->NewBlock(NULL, 8, true, kNoSourcePosition);
4173 4164
4174 ZoneList<Statement*>* inner_body = try_block->statements(); 4165 ZoneList<Statement*>* inner_body = try_block->statements();
4175 4166
4176 Expression* return_value = nullptr; 4167 Expression* return_value = nullptr;
4177 if (body_type == FunctionBody::Normal) { 4168 if (body_type == FunctionBody::Normal) {
4178 ParseStatementList(inner_body, Token::RBRACE, CHECK_OK_CUSTOM(Void)); 4169 ParseStatementList(inner_body, Token::RBRACE, CHECK_OK_VOID);
4179 return_value = factory()->NewUndefinedLiteral(kNoSourcePosition); 4170 return_value = factory()->NewUndefinedLiteral(kNoSourcePosition);
4180 } else { 4171 } else {
4181 return_value = 4172 return_value =
4182 ParseAssignmentExpression(accept_IN, classifier, CHECK_OK_CUSTOM(Void)); 4173 ParseAssignmentExpression(accept_IN, classifier, CHECK_OK_VOID);
4183 ParserTraits::RewriteNonPattern(classifier, CHECK_OK_CUSTOM(Void)); 4174 ParserTraits::RewriteNonPattern(classifier, CHECK_OK_VOID);
4184 } 4175 }
4185 4176
4186 return_value = BuildPromiseResolve(return_value, return_value->position()); 4177 return_value = BuildPromiseResolve(return_value, return_value->position());
4187 inner_body->Add( 4178 inner_body->Add(
4188 factory()->NewReturnStatement(return_value, return_value->position()), 4179 factory()->NewReturnStatement(return_value, return_value->position()),
4189 zone()); 4180 zone());
4190 body->Add(BuildRejectPromiseOnException(try_block), zone()); 4181 body->Add(BuildRejectPromiseOnException(try_block), zone());
4191 scope->set_end_position(scanner()->location().end_pos); 4182 scope->set_end_position(scanner()->location().end_pos);
4192 } 4183 }
4193 4184
(...skipping 16 matching lines...) Expand all
4210 } 4201 }
4211 4202
4212 4203
4213 void ParserTraits::ParseArrowFunctionFormalParameterList( 4204 void ParserTraits::ParseArrowFunctionFormalParameterList(
4214 ParserFormalParameters* parameters, Expression* expr, 4205 ParserFormalParameters* parameters, Expression* expr,
4215 const Scanner::Location& params_loc, 4206 const Scanner::Location& params_loc,
4216 Scanner::Location* duplicate_loc, bool* ok) { 4207 Scanner::Location* duplicate_loc, bool* ok) {
4217 if (expr->IsEmptyParentheses()) return; 4208 if (expr->IsEmptyParentheses()) return;
4218 4209
4219 ParseArrowFunctionFormalParameters(parameters, expr, params_loc.end_pos, 4210 ParseArrowFunctionFormalParameters(parameters, expr, params_loc.end_pos,
4220 CHECK_OK_CUSTOM(Void)); 4211 CHECK_OK_VOID);
4221 4212
4222 if (parameters->Arity() > Code::kMaxArguments) { 4213 if (parameters->Arity() > Code::kMaxArguments) {
4223 ReportMessageAt(params_loc, MessageTemplate::kMalformedArrowFunParamList); 4214 ReportMessageAt(params_loc, MessageTemplate::kMalformedArrowFunParamList);
4224 *ok = false; 4215 *ok = false;
4225 return; 4216 return;
4226 } 4217 }
4227 4218
4228 Type::ExpressionClassifier classifier(parser_); 4219 Type::ExpressionClassifier classifier(parser_);
4229 if (!parameters->is_simple) { 4220 if (!parameters->is_simple) {
4230 classifier.RecordNonSimpleParameter(); 4221 classifier.RecordNonSimpleParameter();
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
4534 // data contains the information we need to construct the lazy function. 4525 // data contains the information we need to construct the lazy function.
4535 FunctionEntry entry = 4526 FunctionEntry entry =
4536 cached_parse_data_->GetFunctionEntry(function_block_pos); 4527 cached_parse_data_->GetFunctionEntry(function_block_pos);
4537 // Check that cached data is valid. If not, mark it as invalid (the embedder 4528 // Check that cached data is valid. If not, mark it as invalid (the embedder
4538 // handles it). Note that end position greater than end of stream is safe, 4529 // handles it). Note that end position greater than end of stream is safe,
4539 // and hard to check. 4530 // and hard to check.
4540 if (entry.is_valid() && entry.end_pos() > function_block_pos) { 4531 if (entry.is_valid() && entry.end_pos() > function_block_pos) {
4541 scanner()->SeekForward(entry.end_pos() - 1); 4532 scanner()->SeekForward(entry.end_pos() - 1);
4542 4533
4543 scope_->set_end_position(entry.end_pos()); 4534 scope_->set_end_position(entry.end_pos());
4544 Expect(Token::RBRACE, CHECK_OK_CUSTOM(Void)); 4535 Expect(Token::RBRACE, CHECK_OK_VOID);
4545 total_preparse_skipped_ += scope_->end_position() - function_block_pos; 4536 total_preparse_skipped_ += scope_->end_position() - function_block_pos;
4546 *materialized_literal_count = entry.literal_count(); 4537 *materialized_literal_count = entry.literal_count();
4547 *expected_property_count = entry.property_count(); 4538 *expected_property_count = entry.property_count();
4548 SetLanguageMode(scope_, entry.language_mode()); 4539 SetLanguageMode(scope_, entry.language_mode());
4549 if (entry.uses_super_property()) scope_->RecordSuperPropertyUsage(); 4540 if (entry.uses_super_property()) scope_->RecordSuperPropertyUsage();
4550 if (entry.calls_eval()) scope_->RecordEvalCall(); 4541 if (entry.calls_eval()) scope_->RecordEvalCall();
4551 return; 4542 return;
4552 } 4543 }
4553 cached_parse_data_->Reject(); 4544 cached_parse_data_->Reject();
4554 } 4545 }
(...skipping 12 matching lines...) Expand all
4567 return; 4558 return;
4568 } 4559 }
4569 if (logger.has_error()) { 4560 if (logger.has_error()) {
4570 ParserTraits::ReportMessageAt( 4561 ParserTraits::ReportMessageAt(
4571 Scanner::Location(logger.start(), logger.end()), logger.message(), 4562 Scanner::Location(logger.start(), logger.end()), logger.message(),
4572 logger.argument_opt(), logger.error_type()); 4563 logger.argument_opt(), logger.error_type());
4573 *ok = false; 4564 *ok = false;
4574 return; 4565 return;
4575 } 4566 }
4576 scope_->set_end_position(logger.end()); 4567 scope_->set_end_position(logger.end());
4577 Expect(Token::RBRACE, CHECK_OK_CUSTOM(Void)); 4568 Expect(Token::RBRACE, CHECK_OK_VOID);
4578 total_preparse_skipped_ += scope_->end_position() - function_block_pos; 4569 total_preparse_skipped_ += scope_->end_position() - function_block_pos;
4579 *materialized_literal_count = logger.literals(); 4570 *materialized_literal_count = logger.literals();
4580 *expected_property_count = logger.properties(); 4571 *expected_property_count = logger.properties();
4581 SetLanguageMode(scope_, logger.language_mode()); 4572 SetLanguageMode(scope_, logger.language_mode());
4582 if (logger.uses_super_property()) { 4573 if (logger.uses_super_property()) {
4583 scope_->RecordSuperPropertyUsage(); 4574 scope_->RecordSuperPropertyUsage();
4584 } 4575 }
4585 if (logger.calls_eval()) { 4576 if (logger.calls_eval()) {
4586 scope_->RecordEvalCall(); 4577 scope_->RecordEvalCall();
4587 } 4578 }
(...skipping 1268 matching lines...) Expand 10 before | Expand all | Expand 10 after
5856 if (property == nullptr) return; 5847 if (property == nullptr) return;
5857 // Do not rewrite (computed) key expressions 5848 // Do not rewrite (computed) key expressions
5858 AST_REWRITE_PROPERTY(Expression, property, value); 5849 AST_REWRITE_PROPERTY(Expression, property, value);
5859 } 5850 }
5860 5851
5861 Parser* parser_; 5852 Parser* parser_;
5862 }; 5853 };
5863 5854
5864 5855
5865 void Parser::RewriteNonPattern(ExpressionClassifier* classifier, bool* ok) { 5856 void Parser::RewriteNonPattern(ExpressionClassifier* classifier, bool* ok) {
5866 ValidateExpression(classifier, CHECK_OK_CUSTOM(Void)); 5857 ValidateExpression(classifier, CHECK_OK_VOID);
5867 auto non_patterns_to_rewrite = function_state_->non_patterns_to_rewrite(); 5858 auto non_patterns_to_rewrite = function_state_->non_patterns_to_rewrite();
5868 int begin = classifier->GetNonPatternBegin(); 5859 int begin = classifier->GetNonPatternBegin();
5869 int end = non_patterns_to_rewrite->length(); 5860 int end = non_patterns_to_rewrite->length();
5870 if (begin < end) { 5861 if (begin < end) {
5871 NonPatternRewriter rewriter(stack_limit_, this); 5862 NonPatternRewriter rewriter(stack_limit_, this);
5872 for (int i = begin; i < end; i++) { 5863 for (int i = begin; i < end; i++) {
5873 DCHECK(non_patterns_to_rewrite->at(i)->IsRewritableExpression()); 5864 DCHECK(non_patterns_to_rewrite->at(i)->IsRewritableExpression());
5874 rewriter.Rewrite(non_patterns_to_rewrite->at(i)); 5865 rewriter.Rewrite(non_patterns_to_rewrite->at(i));
5875 } 5866 }
5876 non_patterns_to_rewrite->Rewind(begin); 5867 non_patterns_to_rewrite->Rewind(begin);
(...skipping 1181 matching lines...) Expand 10 before | Expand all | Expand 10 after
7058 } 7049 }
7059 7050
7060 #ifdef DEBUG 7051 #ifdef DEBUG
7061 void Parser::Print(AstNode* node) { 7052 void Parser::Print(AstNode* node) {
7062 ast_value_factory()->Internalize(Isolate::Current()); 7053 ast_value_factory()->Internalize(Isolate::Current());
7063 node->Print(Isolate::Current()); 7054 node->Print(Isolate::Current());
7064 } 7055 }
7065 #endif // DEBUG 7056 #endif // DEBUG
7066 7057
7067 #undef CHECK_OK 7058 #undef CHECK_OK
7068 #undef CHECK_OK_CUSTOM 7059 #undef CHECK_OK_VOID
7069 #undef CHECK_FAILED 7060 #undef CHECK_FAILED
7070 7061
7071 } // namespace internal 7062 } // namespace internal
7072 } // namespace v8 7063 } // namespace v8
OLDNEW
« no previous file with comments | « src/parsing/parser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698