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 <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 1537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1548 Scanner::Location module_namespace_binding_loc; | 1548 Scanner::Location module_namespace_binding_loc; |
1549 const ZoneList<const NamedImport*>* named_imports = nullptr; | 1549 const ZoneList<const NamedImport*>* named_imports = nullptr; |
1550 if (import_default_binding == nullptr || Check(Token::COMMA)) { | 1550 if (import_default_binding == nullptr || Check(Token::COMMA)) { |
1551 switch (peek()) { | 1551 switch (peek()) { |
1552 case Token::MUL: { | 1552 case Token::MUL: { |
1553 Consume(Token::MUL); | 1553 Consume(Token::MUL); |
1554 ExpectContextualKeyword(CStrVector("as"), CHECK_OK_VOID); | 1554 ExpectContextualKeyword(CStrVector("as"), CHECK_OK_VOID); |
1555 module_namespace_binding = | 1555 module_namespace_binding = |
1556 ParseIdentifier(kDontAllowRestrictedIdentifiers, CHECK_OK_VOID); | 1556 ParseIdentifier(kDontAllowRestrictedIdentifiers, CHECK_OK_VOID); |
1557 module_namespace_binding_loc = scanner()->location(); | 1557 module_namespace_binding_loc = scanner()->location(); |
1558 DeclareImport(module_namespace_binding, pos, CHECK_OK_VOID); | |
1558 break; | 1559 break; |
1559 } | 1560 } |
1560 | 1561 |
1561 case Token::LBRACE: | 1562 case Token::LBRACE: |
1562 named_imports = ParseNamedImports(pos, CHECK_OK_VOID); | 1563 named_imports = ParseNamedImports(pos, CHECK_OK_VOID); |
1563 break; | 1564 break; |
1564 | 1565 |
1565 default: | 1566 default: |
1566 *ok = false; | 1567 *ok = false; |
1567 ReportUnexpectedToken(scanner()->current_token()); | 1568 ReportUnexpectedToken(scanner()->current_token()); |
1568 return; | 1569 return; |
1569 } | 1570 } |
1570 } | 1571 } |
1571 | 1572 |
1572 ExpectContextualKeyword(CStrVector("from"), CHECK_OK_VOID); | 1573 ExpectContextualKeyword(CStrVector("from"), CHECK_OK_VOID); |
1573 const AstRawString* module_specifier = ParseModuleSpecifier(CHECK_OK_VOID); | 1574 const AstRawString* module_specifier = ParseModuleSpecifier(CHECK_OK_VOID); |
1574 ExpectSemicolon(CHECK_OK_VOID); | 1575 ExpectSemicolon(CHECK_OK_VOID); |
1575 | 1576 |
1576 // Now that we have all the information, we can make the appropriate | 1577 // Now that we have all the information, we can make the appropriate |
1577 // declarations. | 1578 // declarations. |
1578 | 1579 |
1579 if (module_namespace_binding != nullptr) { | |
1580 module()->AddStarImport(module_namespace_binding, module_specifier, | |
1581 module_namespace_binding_loc, zone()); | |
1582 // TODO(neis): Create special immutable binding for the namespace object. | |
1583 } | |
1584 | |
1585 // TODO(neis): Would prefer to call DeclareImport below rather than above and | 1580 // TODO(neis): Would prefer to call DeclareImport below rather than above and |
1586 // in ParseNamedImports, but then a possible error message would point to the | 1581 // in ParseNamedImports, but then a possible error message would point to the |
1587 // wrong location. Maybe have a DeclareAt version of Declare that takes a | 1582 // wrong location. Maybe have a DeclareAt version of Declare that takes a |
1588 // location? | 1583 // location? |
1589 | 1584 |
1585 if (module_namespace_binding != nullptr) { | |
1586 module()->AddStarImport(module_namespace_binding, module_specifier, | |
1587 module_namespace_binding_loc, zone()); | |
1588 // DeclareImport(module_namespace_binding, pos, CHECK_OK_VOID); | |
adamk
2016/08/02 16:34:31
Leave a TODO here?
neis
2016/08/03 09:16:30
Hmm? This is the same as all the other DeclareImpo
adamk
2016/08/03 17:51:26
Oops, didn't look in the right place, I get it.
| |
1589 } | |
1590 | |
1590 if (import_default_binding != nullptr) { | 1591 if (import_default_binding != nullptr) { |
1591 module()->AddImport(ast_value_factory()->default_string(), | 1592 module()->AddImport(ast_value_factory()->default_string(), |
1592 import_default_binding, module_specifier, | 1593 import_default_binding, module_specifier, |
1593 import_default_binding_loc, zone()); | 1594 import_default_binding_loc, zone()); |
1594 // DeclareImport(import_default_binding, pos, CHECK_OK_VOID); | 1595 // DeclareImport(import_default_binding, pos, CHECK_OK_VOID); |
1595 } | 1596 } |
1596 | 1597 |
1597 if (named_imports != nullptr) { | 1598 if (named_imports != nullptr) { |
1598 if (named_imports->length() == 0) { | 1599 if (named_imports->length() == 0) { |
1599 module()->AddEmptyImport(module_specifier, scanner()->location(), zone()); | 1600 module()->AddEmptyImport(module_specifier, scanner()->location(), zone()); |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1936 ? this->scope() | 1937 ? this->scope() |
1937 : this->scope()->DeclarationScope(); | 1938 : this->scope()->DeclarationScope(); |
1938 return scope->NewUnresolved(factory(), name, Variable::NORMAL, | 1939 return scope->NewUnresolved(factory(), name, Variable::NORMAL, |
1939 scanner()->location().beg_pos, | 1940 scanner()->location().beg_pos, |
1940 scanner()->location().end_pos); | 1941 scanner()->location().end_pos); |
1941 } | 1942 } |
1942 | 1943 |
1943 | 1944 |
1944 void Parser::DeclareImport(const AstRawString* local_name, int pos, bool* ok) { | 1945 void Parser::DeclareImport(const AstRawString* local_name, int pos, bool* ok) { |
1945 DCHECK_NOT_NULL(local_name); | 1946 DCHECK_NOT_NULL(local_name); |
1946 VariableProxy* proxy = NewUnresolved(local_name, IMPORT); | 1947 VariableProxy* proxy = NewUnresolved(local_name, CONST); |
1947 Declaration* declaration = | 1948 Declaration* declaration = |
1948 factory()->NewVariableDeclaration(proxy, IMPORT, scope(), pos); | 1949 factory()->NewVariableDeclaration(proxy, CONST, scope(), pos); |
1949 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK_VOID); | 1950 Declare(declaration, DeclarationDescriptor::NORMAL, true, CHECK_OK_VOID); |
1950 } | 1951 } |
1951 | 1952 |
1952 | 1953 |
1953 Variable* Parser::Declare(Declaration* declaration, | 1954 Variable* Parser::Declare(Declaration* declaration, |
1954 DeclarationDescriptor::Kind declaration_kind, | 1955 DeclarationDescriptor::Kind declaration_kind, |
1955 bool resolve, bool* ok, Scope* scope) { | 1956 bool resolve, bool* ok, Scope* scope) { |
1956 VariableProxy* proxy = declaration->proxy(); | 1957 VariableProxy* proxy = declaration->proxy(); |
1957 DCHECK(proxy->raw_name() != NULL); | 1958 DCHECK(proxy->raw_name() != NULL); |
1958 const AstRawString* name = proxy->raw_name(); | 1959 const AstRawString* name = proxy->raw_name(); |
(...skipping 5163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
7122 node->Print(Isolate::Current()); | 7123 node->Print(Isolate::Current()); |
7123 } | 7124 } |
7124 #endif // DEBUG | 7125 #endif // DEBUG |
7125 | 7126 |
7126 #undef CHECK_OK | 7127 #undef CHECK_OK |
7127 #undef CHECK_OK_VOID | 7128 #undef CHECK_OK_VOID |
7128 #undef CHECK_FAILED | 7129 #undef CHECK_FAILED |
7129 | 7130 |
7130 } // namespace internal | 7131 } // namespace internal |
7131 } // namespace v8 | 7132 } // namespace v8 |
OLD | NEW |