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-expression-rewriter.h" | 10 #include "src/ast/ast-expression-rewriter.h" |
(...skipping 1136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1147 parsing_module_)) { | 1147 parsing_module_)) { |
1148 *ok = false; | 1148 *ok = false; |
1149 ReportMessage(MessageTemplate::kUnexpectedReserved); | 1149 ReportMessage(MessageTemplate::kUnexpectedReserved); |
1150 return nullptr; | 1150 return nullptr; |
1151 } else if (IsEvalOrArguments(local_name)) { | 1151 } else if (IsEvalOrArguments(local_name)) { |
1152 *ok = false; | 1152 *ok = false; |
1153 ReportMessage(MessageTemplate::kStrictEvalArguments); | 1153 ReportMessage(MessageTemplate::kStrictEvalArguments); |
1154 return nullptr; | 1154 return nullptr; |
1155 } | 1155 } |
1156 | 1156 |
1157 DeclareVariable(local_name, CONST, kNeedsInitialization, position(), | 1157 DeclareModuleImport(local_name, position(), CHECK_OK); |
1158 CHECK_OK); | |
1159 | 1158 |
1160 NamedImport* import = new (zone()) NamedImport( | 1159 NamedImport* import = new (zone()) NamedImport( |
1161 import_name, local_name, scanner()->location()); | 1160 import_name, local_name, scanner()->location()); |
1162 result->Add(import, zone()); | 1161 result->Add(import, zone()); |
1163 | 1162 |
1164 if (peek() == Token::RBRACE) break; | 1163 if (peek() == Token::RBRACE) break; |
1165 Expect(Token::COMMA, CHECK_OK); | 1164 Expect(Token::COMMA, CHECK_OK); |
1166 } | 1165 } |
1167 | 1166 |
1168 Expect(Token::RBRACE, CHECK_OK); | 1167 Expect(Token::RBRACE, CHECK_OK); |
(...skipping 29 matching lines...) Expand all Loading... |
1198 return; | 1197 return; |
1199 } | 1198 } |
1200 | 1199 |
1201 // Parse ImportedDefaultBinding if present. | 1200 // Parse ImportedDefaultBinding if present. |
1202 const AstRawString* import_default_binding = nullptr; | 1201 const AstRawString* import_default_binding = nullptr; |
1203 Scanner::Location import_default_binding_loc; | 1202 Scanner::Location import_default_binding_loc; |
1204 if (tok != Token::MUL && tok != Token::LBRACE) { | 1203 if (tok != Token::MUL && tok != Token::LBRACE) { |
1205 import_default_binding = | 1204 import_default_binding = |
1206 ParseIdentifier(kDontAllowRestrictedIdentifiers, CHECK_OK_VOID); | 1205 ParseIdentifier(kDontAllowRestrictedIdentifiers, CHECK_OK_VOID); |
1207 import_default_binding_loc = scanner()->location(); | 1206 import_default_binding_loc = scanner()->location(); |
1208 DeclareVariable(import_default_binding, CONST, kNeedsInitialization, pos, | 1207 DeclareModuleImport(import_default_binding, pos, CHECK_OK_VOID); |
1209 CHECK_OK_VOID); | |
1210 } | 1208 } |
1211 | 1209 |
1212 // Parse NameSpaceImport or NamedImports if present. | 1210 // Parse NameSpaceImport or NamedImports if present. |
1213 const AstRawString* module_namespace_binding = nullptr; | 1211 const AstRawString* module_namespace_binding = nullptr; |
1214 Scanner::Location module_namespace_binding_loc; | 1212 Scanner::Location module_namespace_binding_loc; |
1215 const ZoneList<const NamedImport*>* named_imports = nullptr; | 1213 const ZoneList<const NamedImport*>* named_imports = nullptr; |
1216 if (import_default_binding == nullptr || Check(Token::COMMA)) { | 1214 if (import_default_binding == nullptr || Check(Token::COMMA)) { |
1217 switch (peek()) { | 1215 switch (peek()) { |
1218 case Token::MUL: { | 1216 case Token::MUL: { |
1219 Consume(Token::MUL); | 1217 Consume(Token::MUL); |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1474 DCHECK_NOT_NULL(name); | 1472 DCHECK_NOT_NULL(name); |
1475 VariableProxy* proxy = factory()->NewVariableProxy( | 1473 VariableProxy* proxy = factory()->NewVariableProxy( |
1476 name, NORMAL_VARIABLE, scanner()->location().beg_pos, | 1474 name, NORMAL_VARIABLE, scanner()->location().beg_pos, |
1477 scanner()->location().end_pos); | 1475 scanner()->location().end_pos); |
1478 Declaration* declaration = | 1476 Declaration* declaration = |
1479 factory()->NewVariableDeclaration(proxy, this->scope(), pos); | 1477 factory()->NewVariableDeclaration(proxy, this->scope(), pos); |
1480 Declare(declaration, DeclarationDescriptor::NORMAL, mode, init, CHECK_OK); | 1478 Declare(declaration, DeclarationDescriptor::NORMAL, mode, init, CHECK_OK); |
1481 return declaration; | 1479 return declaration; |
1482 } | 1480 } |
1483 | 1481 |
| 1482 Declaration* Parser::DeclareModuleImport(const AstRawString* name, int pos, |
| 1483 bool* ok) { |
| 1484 DCHECK_EQ(MODULE_SCOPE, scope()->scope_type()); |
| 1485 Declaration* decl = |
| 1486 DeclareVariable(name, CONST, kNeedsInitialization, pos, CHECK_OK); |
| 1487 // Allocate imports eagerly as hole check elimination logic in scope |
| 1488 // analisys depends on identifying imports. |
| 1489 // TODO(adamk): It's weird to allocate imports long before everything |
| 1490 // else. We should find a different way of filtering out imports |
| 1491 // during hole check elimination. |
| 1492 decl->proxy()->var()->AllocateTo(VariableLocation::MODULE, |
| 1493 Variable::kModuleImportIndex); |
| 1494 return decl; |
| 1495 } |
| 1496 |
1484 Variable* Parser::Declare(Declaration* declaration, | 1497 Variable* Parser::Declare(Declaration* declaration, |
1485 DeclarationDescriptor::Kind declaration_kind, | 1498 DeclarationDescriptor::Kind declaration_kind, |
1486 VariableMode mode, InitializationFlag init, bool* ok, | 1499 VariableMode mode, InitializationFlag init, bool* ok, |
1487 Scope* scope) { | 1500 Scope* scope) { |
1488 if (scope == nullptr) { | 1501 if (scope == nullptr) { |
1489 scope = this->scope(); | 1502 scope = this->scope(); |
1490 } | 1503 } |
1491 bool sloppy_mode_block_scope_function_redefinition = false; | 1504 bool sloppy_mode_block_scope_function_redefinition = false; |
1492 Variable* variable = scope->DeclareVariable( | 1505 Variable* variable = scope->DeclareVariable( |
1493 declaration, mode, init, allow_harmony_restrictive_generators(), | 1506 declaration, mode, init, allow_harmony_restrictive_generators(), |
(...skipping 3914 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5408 | 5421 |
5409 return final_loop; | 5422 return final_loop; |
5410 } | 5423 } |
5411 | 5424 |
5412 #undef CHECK_OK | 5425 #undef CHECK_OK |
5413 #undef CHECK_OK_VOID | 5426 #undef CHECK_OK_VOID |
5414 #undef CHECK_FAILED | 5427 #undef CHECK_FAILED |
5415 | 5428 |
5416 } // namespace internal | 5429 } // namespace internal |
5417 } // namespace v8 | 5430 } // namespace v8 |
OLD | NEW |