| 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 1457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1468 } | 1468 } |
| 1469 | 1469 |
| 1470 Declaration* Parser::DeclareVariable(const AstRawString* name, | 1470 Declaration* Parser::DeclareVariable(const AstRawString* name, |
| 1471 VariableMode mode, InitializationFlag init, | 1471 VariableMode mode, InitializationFlag init, |
| 1472 int pos, bool* ok) { | 1472 int pos, bool* ok) { |
| 1473 DCHECK_NOT_NULL(name); | 1473 DCHECK_NOT_NULL(name); |
| 1474 VariableProxy* proxy = factory()->NewVariableProxy( | 1474 VariableProxy* proxy = factory()->NewVariableProxy( |
| 1475 name, NORMAL_VARIABLE, scanner()->location().beg_pos); | 1475 name, NORMAL_VARIABLE, scanner()->location().beg_pos); |
| 1476 Declaration* declaration = | 1476 Declaration* declaration = |
| 1477 factory()->NewVariableDeclaration(proxy, this->scope(), pos); | 1477 factory()->NewVariableDeclaration(proxy, this->scope(), pos); |
| 1478 Declare(declaration, DeclarationDescriptor::NORMAL, mode, init, CHECK_OK); | 1478 Declare(declaration, DeclarationDescriptor::NORMAL, mode, init, ok, nullptr, |
| 1479 scanner()->location().end_pos); |
| 1480 if (!*ok) return nullptr; |
| 1479 return declaration; | 1481 return declaration; |
| 1480 } | 1482 } |
| 1481 | 1483 |
| 1482 Declaration* Parser::DeclareModuleImport(const AstRawString* name, int pos, | 1484 Declaration* Parser::DeclareModuleImport(const AstRawString* name, int pos, |
| 1483 bool* ok) { | 1485 bool* ok) { |
| 1484 DCHECK_EQ(MODULE_SCOPE, scope()->scope_type()); | 1486 DCHECK_EQ(MODULE_SCOPE, scope()->scope_type()); |
| 1485 Declaration* decl = | 1487 Declaration* decl = |
| 1486 DeclareVariable(name, CONST, kNeedsInitialization, pos, CHECK_OK); | 1488 DeclareVariable(name, CONST, kNeedsInitialization, pos, CHECK_OK); |
| 1487 // Allocate imports eagerly as hole check elimination logic in scope | 1489 // Allocate imports eagerly as hole check elimination logic in scope |
| 1488 // analisys depends on identifying imports. | 1490 // analisys depends on identifying imports. |
| 1489 // TODO(adamk): It's weird to allocate imports long before everything | 1491 // TODO(adamk): It's weird to allocate imports long before everything |
| 1490 // else. We should find a different way of filtering out imports | 1492 // else. We should find a different way of filtering out imports |
| 1491 // during hole check elimination. | 1493 // during hole check elimination. |
| 1492 decl->proxy()->var()->AllocateTo(VariableLocation::MODULE, | 1494 decl->proxy()->var()->AllocateTo(VariableLocation::MODULE, |
| 1493 Variable::kModuleImportIndex); | 1495 Variable::kModuleImportIndex); |
| 1494 return decl; | 1496 return decl; |
| 1495 } | 1497 } |
| 1496 | 1498 |
| 1497 Variable* Parser::Declare(Declaration* declaration, | 1499 Variable* Parser::Declare(Declaration* declaration, |
| 1498 DeclarationDescriptor::Kind declaration_kind, | 1500 DeclarationDescriptor::Kind declaration_kind, |
| 1499 VariableMode mode, InitializationFlag init, bool* ok, | 1501 VariableMode mode, InitializationFlag init, bool* ok, |
| 1500 Scope* scope) { | 1502 Scope* scope, int var_end_pos) { |
| 1501 if (scope == nullptr) { | 1503 if (scope == nullptr) { |
| 1502 scope = this->scope(); | 1504 scope = this->scope(); |
| 1503 } | 1505 } |
| 1504 bool sloppy_mode_block_scope_function_redefinition = false; | 1506 bool sloppy_mode_block_scope_function_redefinition = false; |
| 1505 Variable* variable = scope->DeclareVariable( | 1507 Variable* variable = scope->DeclareVariable( |
| 1506 declaration, mode, init, allow_harmony_restrictive_generators(), | 1508 declaration, mode, init, allow_harmony_restrictive_generators(), |
| 1507 &sloppy_mode_block_scope_function_redefinition, ok); | 1509 &sloppy_mode_block_scope_function_redefinition, ok); |
| 1508 if (!*ok) { | 1510 if (!*ok) { |
| 1511 // If we only have the start position of a proxy, we can't highlight the |
| 1512 // whole variable name. Pretend its length is 1 so that we highlight at |
| 1513 // least the first character. |
| 1514 Scanner::Location loc(declaration->proxy()->position(), |
| 1515 var_end_pos != kNoSourcePosition |
| 1516 ? var_end_pos |
| 1517 : declaration->proxy()->position() + 1); |
| 1509 if (declaration_kind == DeclarationDescriptor::NORMAL) { | 1518 if (declaration_kind == DeclarationDescriptor::NORMAL) { |
| 1510 ReportMessage(MessageTemplate::kVarRedeclaration, | 1519 ReportMessageAt(loc, MessageTemplate::kVarRedeclaration, |
| 1511 declaration->proxy()->raw_name()); | 1520 declaration->proxy()->raw_name()); |
| 1512 } else { | 1521 } else { |
| 1513 ReportMessage(MessageTemplate::kParamDupe); | 1522 ReportMessageAt(loc, MessageTemplate::kParamDupe); |
| 1514 } | 1523 } |
| 1515 return nullptr; | 1524 return nullptr; |
| 1516 } | 1525 } |
| 1517 if (sloppy_mode_block_scope_function_redefinition) { | 1526 if (sloppy_mode_block_scope_function_redefinition) { |
| 1518 ++use_counts_[v8::Isolate::kSloppyModeBlockScopedFunctionRedefinition]; | 1527 ++use_counts_[v8::Isolate::kSloppyModeBlockScopedFunctionRedefinition]; |
| 1519 } | 1528 } |
| 1520 return variable; | 1529 return variable; |
| 1521 } | 1530 } |
| 1522 | 1531 |
| 1523 Block* Parser::BuildInitializationBlock( | 1532 Block* Parser::BuildInitializationBlock( |
| (...skipping 3886 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5410 | 5419 |
| 5411 return final_loop; | 5420 return final_loop; |
| 5412 } | 5421 } |
| 5413 | 5422 |
| 5414 #undef CHECK_OK | 5423 #undef CHECK_OK |
| 5415 #undef CHECK_OK_VOID | 5424 #undef CHECK_OK_VOID |
| 5416 #undef CHECK_FAILED | 5425 #undef CHECK_FAILED |
| 5417 | 5426 |
| 5418 } // namespace internal | 5427 } // namespace internal |
| 5419 } // namespace v8 | 5428 } // namespace v8 |
| OLD | NEW |