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

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

Issue 2447143005: [parsing] When failing due to variable redeclaration, point at the variable. (Closed)
Patch Set: Created 4 years, 1 month 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-expression-rewriter.h" 10 #include "src/ast/ast-expression-rewriter.h"
(...skipping 1457 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(
1515 declaration->proxy()->position(),
1516 var_end_pos >= 0 ? var_end_pos : declaration->proxy()->position() + 1);
adamk 2016/10/27 10:32:49 var_end_pos != kNoSourcePosition
1509 if (declaration_kind == DeclarationDescriptor::NORMAL) { 1517 if (declaration_kind == DeclarationDescriptor::NORMAL) {
1510 ReportMessage(MessageTemplate::kVarRedeclaration, 1518 ReportMessageAt(loc, MessageTemplate::kVarRedeclaration,
1511 declaration->proxy()->raw_name()); 1519 declaration->proxy()->raw_name());
1512 } else { 1520 } else {
1513 ReportMessage(MessageTemplate::kParamDupe); 1521 ReportMessageAt(loc, MessageTemplate::kParamDupe);
1514 } 1522 }
1515 return nullptr; 1523 return nullptr;
1516 } 1524 }
1517 if (sloppy_mode_block_scope_function_redefinition) { 1525 if (sloppy_mode_block_scope_function_redefinition) {
1518 ++use_counts_[v8::Isolate::kSloppyModeBlockScopedFunctionRedefinition]; 1526 ++use_counts_[v8::Isolate::kSloppyModeBlockScopedFunctionRedefinition];
1519 } 1527 }
1520 return variable; 1528 return variable;
1521 } 1529 }
1522 1530
1523 Block* Parser::BuildInitializationBlock( 1531 Block* Parser::BuildInitializationBlock(
(...skipping 3886 matching lines...) Expand 10 before | Expand all | Expand 10 after
5410 5418
5411 return final_loop; 5419 return final_loop;
5412 } 5420 }
5413 5421
5414 #undef CHECK_OK 5422 #undef CHECK_OK
5415 #undef CHECK_OK_VOID 5423 #undef CHECK_OK_VOID
5416 #undef CHECK_FAILED 5424 #undef CHECK_FAILED
5417 5425
5418 } // namespace internal 5426 } // namespace internal
5419 } // namespace v8 5427 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698