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