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

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

Issue 2210533002: [modules] Mark namespace variables as kCreatedInitialized. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@modules-VariableLocation
Patch Set: Created 4 years, 4 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
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 <memory> 7 #include <memory>
8 8
9 #include "src/api.h" 9 #include "src/api.h"
10 #include "src/ast/ast.h" 10 #include "src/ast/ast.h"
(...skipping 1472 matching lines...) Expand 10 before | Expand all | Expand 10 after
1483 parsing_module_)) { 1483 parsing_module_)) {
1484 *ok = false; 1484 *ok = false;
1485 ReportMessage(MessageTemplate::kUnexpectedReserved); 1485 ReportMessage(MessageTemplate::kUnexpectedReserved);
1486 return nullptr; 1486 return nullptr;
1487 } else if (IsEvalOrArguments(local_name)) { 1487 } else if (IsEvalOrArguments(local_name)) {
1488 *ok = false; 1488 *ok = false;
1489 ReportMessage(MessageTemplate::kStrictEvalArguments); 1489 ReportMessage(MessageTemplate::kStrictEvalArguments);
1490 return nullptr; 1490 return nullptr;
1491 } 1491 }
1492 1492
1493 DeclareImport(local_name, position(), CHECK_OK); 1493 DeclareConstVariable(local_name, kNeedsInitialization, position(),
1494 CHECK_OK);
1494 1495
1495 NamedImport* import = new (zone()) NamedImport( 1496 NamedImport* import = new (zone()) NamedImport(
1496 import_name, local_name, scanner()->location()); 1497 import_name, local_name, scanner()->location());
1497 result->Add(import, zone()); 1498 result->Add(import, zone());
1498 1499
1499 if (peek() == Token::RBRACE) break; 1500 if (peek() == Token::RBRACE) break;
1500 Expect(Token::COMMA, CHECK_OK); 1501 Expect(Token::COMMA, CHECK_OK);
1501 } 1502 }
1502 1503
1503 Expect(Token::RBRACE, CHECK_OK); 1504 Expect(Token::RBRACE, CHECK_OK);
(...skipping 29 matching lines...) Expand all
1533 return; 1534 return;
1534 } 1535 }
1535 1536
1536 // Parse ImportedDefaultBinding if present. 1537 // Parse ImportedDefaultBinding if present.
1537 const AstRawString* import_default_binding = nullptr; 1538 const AstRawString* import_default_binding = nullptr;
1538 Scanner::Location import_default_binding_loc; 1539 Scanner::Location import_default_binding_loc;
1539 if (tok != Token::MUL && tok != Token::LBRACE) { 1540 if (tok != Token::MUL && tok != Token::LBRACE) {
1540 import_default_binding = 1541 import_default_binding =
1541 ParseIdentifier(kDontAllowRestrictedIdentifiers, CHECK_OK_VOID); 1542 ParseIdentifier(kDontAllowRestrictedIdentifiers, CHECK_OK_VOID);
1542 import_default_binding_loc = scanner()->location(); 1543 import_default_binding_loc = scanner()->location();
1543 DeclareImport(import_default_binding, pos, CHECK_OK_VOID); 1544 DeclareConstVariable(import_default_binding, kNeedsInitialization, pos,
1545 CHECK_OK_VOID);
1544 } 1546 }
1545 1547
1546 // Parse NameSpaceImport or NamedImports if present. 1548 // Parse NameSpaceImport or NamedImports if present.
1547 const AstRawString* module_namespace_binding = nullptr; 1549 const AstRawString* module_namespace_binding = nullptr;
1548 Scanner::Location module_namespace_binding_loc; 1550 Scanner::Location module_namespace_binding_loc;
1549 const ZoneList<const NamedImport*>* named_imports = nullptr; 1551 const ZoneList<const NamedImport*>* named_imports = nullptr;
1550 if (import_default_binding == nullptr || Check(Token::COMMA)) { 1552 if (import_default_binding == nullptr || Check(Token::COMMA)) {
1551 switch (peek()) { 1553 switch (peek()) {
1552 case Token::MUL: { 1554 case Token::MUL: {
1553 Consume(Token::MUL); 1555 Consume(Token::MUL);
1554 ExpectContextualKeyword(CStrVector("as"), CHECK_OK_VOID); 1556 ExpectContextualKeyword(CStrVector("as"), CHECK_OK_VOID);
1555 module_namespace_binding = 1557 module_namespace_binding =
1556 ParseIdentifier(kDontAllowRestrictedIdentifiers, CHECK_OK_VOID); 1558 ParseIdentifier(kDontAllowRestrictedIdentifiers, CHECK_OK_VOID);
1557 module_namespace_binding_loc = scanner()->location(); 1559 module_namespace_binding_loc = scanner()->location();
1558 DeclareImport(module_namespace_binding, pos, CHECK_OK_VOID); 1560 DeclareConstVariable(module_namespace_binding, kCreatedInitialized, pos,
1561 CHECK_OK_VOID);
1559 break; 1562 break;
1560 } 1563 }
1561 1564
1562 case Token::LBRACE: 1565 case Token::LBRACE:
1563 named_imports = ParseNamedImports(pos, CHECK_OK_VOID); 1566 named_imports = ParseNamedImports(pos, CHECK_OK_VOID);
1564 break; 1567 break;
1565 1568
1566 default: 1569 default:
1567 *ok = false; 1570 *ok = false;
1568 ReportUnexpectedToken(scanner()->current_token()); 1571 ReportUnexpectedToken(scanner()->current_token());
1569 return; 1572 return;
1570 } 1573 }
1571 } 1574 }
1572 1575
1573 ExpectContextualKeyword(CStrVector("from"), CHECK_OK_VOID); 1576 ExpectContextualKeyword(CStrVector("from"), CHECK_OK_VOID);
1574 const AstRawString* module_specifier = ParseModuleSpecifier(CHECK_OK_VOID); 1577 const AstRawString* module_specifier = ParseModuleSpecifier(CHECK_OK_VOID);
1575 ExpectSemicolon(CHECK_OK_VOID); 1578 ExpectSemicolon(CHECK_OK_VOID);
1576 1579
1577 // Now that we have all the information, we can make the appropriate 1580 // Now that we have all the information, we can make the appropriate
1578 // declarations. 1581 // declarations.
1579 1582
1580 // TODO(neis): Would prefer to call DeclareImport below rather than above and 1583 // TODO(neis): Would prefer to call DeclareConstVariable for each case below
1581 // in ParseNamedImports, but then a possible error message would point to the 1584 // rather than above and in ParseNamedImports, but then a possible error
1582 // wrong location. Maybe have a DeclareAt version of Declare that takes a 1585 // message would point to the wrong location. Maybe have a DeclareAt version
1583 // location? 1586 // of Declare that takes a location?
1584 1587
1585 if (module_namespace_binding != nullptr) { 1588 if (module_namespace_binding != nullptr) {
1586 module()->AddStarImport(module_namespace_binding, module_specifier, 1589 module()->AddStarImport(module_namespace_binding, module_specifier,
1587 module_namespace_binding_loc, zone()); 1590 module_namespace_binding_loc, zone());
1588 // DeclareImport(module_namespace_binding, pos, CHECK_OK_VOID);
1589 } 1591 }
1590 1592
1591 if (import_default_binding != nullptr) { 1593 if (import_default_binding != nullptr) {
1592 module()->AddImport(ast_value_factory()->default_string(), 1594 module()->AddImport(ast_value_factory()->default_string(),
1593 import_default_binding, module_specifier, 1595 import_default_binding, module_specifier,
1594 import_default_binding_loc, zone()); 1596 import_default_binding_loc, zone());
1595 // DeclareImport(import_default_binding, pos, CHECK_OK_VOID);
1596 } 1597 }
1597 1598
1598 if (named_imports != nullptr) { 1599 if (named_imports != nullptr) {
1599 if (named_imports->length() == 0) { 1600 if (named_imports->length() == 0) {
1600 module()->AddEmptyImport(module_specifier, scanner()->location(), zone()); 1601 module()->AddEmptyImport(module_specifier, scanner()->location(), zone());
1601 } else { 1602 } else {
1602 for (int i = 0; i < named_imports->length(); ++i) { 1603 for (int i = 0; i < named_imports->length(); ++i) {
1603 const NamedImport* import = named_imports->at(i); 1604 const NamedImport* import = named_imports->at(i);
1604 module()->AddImport(import->import_name, import->local_name, 1605 module()->AddImport(import->import_name, import->local_name,
1605 module_specifier, import->location, zone()); 1606 module_specifier, import->location, zone());
1606 // DeclareImport(import->local_name, pos, CHECK_OK_VOID);
1607 } 1607 }
1608 } 1608 }
1609 } 1609 }
1610 } 1610 }
1611 1611
1612 1612
1613 Statement* Parser::ParseExportDefault(bool* ok) { 1613 Statement* Parser::ParseExportDefault(bool* ok) {
1614 // Supports the following productions, starting after the 'default' token: 1614 // Supports the following productions, starting after the 'default' token:
1615 // 'export' 'default' HoistableDeclaration 1615 // 'export' 'default' HoistableDeclaration
1616 // 'export' 'default' ClassDeclaration 1616 // 'export' 'default' ClassDeclaration
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
1934 // scope. 1934 // scope.
1935 // Let/const variables are always added to the immediately enclosing scope. 1935 // Let/const variables are always added to the immediately enclosing scope.
1936 Scope* scope = IsLexicalVariableMode(mode) 1936 Scope* scope = IsLexicalVariableMode(mode)
1937 ? this->scope() 1937 ? this->scope()
1938 : this->scope()->DeclarationScope(); 1938 : this->scope()->DeclarationScope();
1939 return scope->NewUnresolved(factory(), name, Variable::NORMAL, 1939 return scope->NewUnresolved(factory(), name, Variable::NORMAL,
1940 scanner()->location().beg_pos, 1940 scanner()->location().beg_pos,
1941 scanner()->location().end_pos); 1941 scanner()->location().end_pos);
1942 } 1942 }
1943 1943
1944 1944 void Parser::DeclareConstVariable(const AstRawString* name,
1945 void Parser::DeclareImport(const AstRawString* local_name, int pos, bool* ok) { 1945 InitializationFlag init, int pos, bool* ok) {
1946 DCHECK_NOT_NULL(local_name); 1946 DCHECK_NOT_NULL(name);
1947 VariableProxy* proxy = NewUnresolved(local_name, CONST); 1947 VariableProxy* proxy = NewUnresolved(name, CONST);
1948 Declaration* declaration = 1948 Declaration* declaration =
1949 factory()->NewVariableDeclaration(proxy, CONST, scope(), pos); 1949 factory()->NewVariableDeclaration(proxy, CONST, scope(), init, pos);
1950 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK_VOID); 1950 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK_VOID);
1951 } 1951 }
neis 2016/08/03 14:48:14 I will try to reuse this function in other places,
1952 1952
1953 1953
1954 Variable* Parser::Declare(Declaration* declaration, 1954 Variable* Parser::Declare(Declaration* declaration,
1955 DeclarationDescriptor::Kind declaration_kind, 1955 DeclarationDescriptor::Kind declaration_kind,
1956 bool resolve, bool* ok, Scope* scope) { 1956 bool resolve, bool* ok, Scope* scope) {
1957 VariableProxy* proxy = declaration->proxy(); 1957 VariableProxy* proxy = declaration->proxy();
1958 DCHECK(proxy->raw_name() != NULL); 1958 DCHECK(proxy->raw_name() != NULL);
1959 const AstRawString* name = proxy->raw_name(); 1959 const AstRawString* name = proxy->raw_name();
1960 VariableMode mode = declaration->mode(); 1960 VariableMode mode = declaration->mode();
1961 DCHECK(IsDeclaredVariableMode(mode) && mode != CONST_LEGACY); 1961 DCHECK(IsDeclaredVariableMode(mode) && mode != CONST_LEGACY);
(...skipping 5161 matching lines...) Expand 10 before | Expand all | Expand 10 after
7123 node->Print(Isolate::Current()); 7123 node->Print(Isolate::Current());
7124 } 7124 }
7125 #endif // DEBUG 7125 #endif // DEBUG
7126 7126
7127 #undef CHECK_OK 7127 #undef CHECK_OK
7128 #undef CHECK_OK_VOID 7128 #undef CHECK_OK_VOID
7129 #undef CHECK_FAILED 7129 #undef CHECK_FAILED
7130 7130
7131 } // namespace internal 7131 } // namespace internal
7132 } // namespace v8 7132 } // namespace v8
OLDNEW
« src/ast/ast.h ('K') | « src/parsing/parser.h ('k') | test/cctest/test-parsing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698