Commit a1aa3b24 authored by Adam Klein's avatar Adam Klein Committed by Commit Bot

[parser] Give all Blocks kNoSourcePosition

There was only one case where this wasn't the case, having to do with
variable declarations, and for that case the information need not
actually be stored on the block, but should rather be propagated
to the VariableProxy.

Bug: v8:6092
Change-Id: I0d0025ec73d3dd4f9402606105d3e883a9417283
Reviewed-on: https://chromium-review.googlesource.com/639911
Commit-Queue: Adam Klein <adamk@chromium.org>
Reviewed-by: 's avatarYang Guo <yangguo@chromium.org>
Reviewed-by: 's avatarMarja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47692}
parent 232b1af3
......@@ -376,8 +376,8 @@ class Block : public BreakableStatement {
protected:
Block(Zone* zone, ZoneList<const AstRawString*>* labels, int capacity,
bool ignore_completion_value, int pos)
: BreakableStatement(TARGET_FOR_NAMED_ONLY, pos, kBlock),
bool ignore_completion_value)
: BreakableStatement(TARGET_FOR_NAMED_ONLY, kNoSourcePosition, kBlock),
statements_(capacity, zone),
scope_(NULL) {
bit_field_ |= IgnoreCompletionField::encode(ignore_completion_value) |
......@@ -391,8 +391,8 @@ class LabeledBlock final : public Block {
friend class Block;
LabeledBlock(Zone* zone, ZoneList<const AstRawString*>* labels, int capacity,
bool ignore_completion_value, int pos)
: Block(zone, labels, capacity, ignore_completion_value, pos),
bool ignore_completion_value)
: Block(zone, labels, capacity, ignore_completion_value),
labels_(labels) {
DCHECK_NOT_NULL(labels);
DCHECK_GT(labels->length(), 0);
......@@ -3170,13 +3170,12 @@ class AstNodeFactory final BASE_EMBEDDED {
}
Block* NewBlock(int capacity, bool ignore_completion_value,
int pos = kNoSourcePosition,
ZoneList<const AstRawString*>* labels = nullptr) {
return labels != nullptr ? new (zone_)
LabeledBlock(zone_, labels, capacity,
ignore_completion_value, pos)
: new (zone_) Block(zone_, labels, capacity,
ignore_completion_value, pos);
return labels != nullptr
? new (zone_) LabeledBlock(zone_, labels, capacity,
ignore_completion_value)
: new (zone_)
Block(zone_, labels, capacity, ignore_completion_value);
}
#define STATEMENT_WITH_LABELS(NodeType) \
......
......@@ -3728,8 +3728,7 @@ typename ParserBase<Impl>::BlockT ParserBase<Impl>::ParseVariableDeclarations(
BlockT init_block = impl()->NullStatement();
if (var_context != kForStatement) {
init_block = factory()->NewBlock(
1, true, parsing_result->descriptor.declaration_pos);
init_block = factory()->NewBlock(1, true);
}
switch (peek()) {
......@@ -4878,8 +4877,7 @@ typename ParserBase<Impl>::StatementT ParserBase<Impl>::ParseStatement(
if (labels == nullptr) {
return ParseStatementAsUnlabelled(labels, ok);
} else {
BlockT result =
factory()->NewBlock(1, false, kNoSourcePosition, labels);
BlockT result = factory()->NewBlock(1, false, labels);
typename Types::Target target(this, result);
StatementT statement = ParseStatementAsUnlabelled(labels, CHECK_OK);
result->statements()->Add(statement, zone());
......@@ -4951,7 +4949,7 @@ typename ParserBase<Impl>::BlockT ParserBase<Impl>::ParseBlock(
// '{' StatementList '}'
// Construct block expecting 16 statements.
BlockT body = factory()->NewBlock(16, false, kNoSourcePosition, labels);
BlockT body = factory()->NewBlock(16, false, labels);
// Parse the statements and collect escaping labels.
Expect(Token::LBRACE, CHECK_OK_CUSTOM(NullStatement));
......
......@@ -1438,8 +1438,7 @@ Variable* Parser::Declare(Declaration* declaration,
Block* Parser::BuildInitializationBlock(
DeclarationParsingResult* parsing_result,
ZoneList<const AstRawString*>* names, bool* ok) {
Block* result =
factory()->NewBlock(1, true, parsing_result->descriptor.declaration_pos);
Block* result = factory()->NewBlock(1, true);
for (auto declaration : parsing_result->declarations) {
DeclareAndInitializeVariables(result, &(parsing_result->descriptor),
&declaration, names, CHECK_OK);
......@@ -1927,8 +1926,7 @@ Block* Parser::RewriteForVarInLegacy(const ForInfo& for_info) {
++use_counts_[v8::Isolate::kForInInitializer];
const AstRawString* name = decl.pattern->AsVariableProxy()->raw_name();
VariableProxy* single_var = NewUnresolved(name);
Block* init_block = factory()->NewBlock(
2, true, for_info.parsing_result.descriptor.declaration_pos);
Block* init_block = factory()->NewBlock(2, true);
init_block->statements()->Add(
factory()->NewExpressionStatement(
factory()->NewAssignment(Token::ASSIGN, single_var,
......@@ -2256,8 +2254,9 @@ Statement* Parser::DesugarLexicalBindingsInForStatement(
Token::INIT, decl->proxy(), temp_proxy, kNoSourcePosition);
Statement* assignment_statement =
factory()->NewExpressionStatement(assignment, kNoSourcePosition);
DCHECK(init->position() != kNoSourcePosition);
decl->proxy()->var()->set_initializer_position(init->position());
int declaration_pos = for_info.parsing_result.descriptor.declaration_pos;
DCHECK(declaration_pos != kNoSourcePosition);
decl->proxy()->var()->set_initializer_position(declaration_pos);
ignore_completion_block->statements()->Add(assignment_statement, zone());
}
......
......@@ -314,7 +314,7 @@ void PatternRewriter::VisitRewritableExpression(RewritableExpression* node) {
int pos = assign->position();
Block* old_block = block_;
block_ = factory()->NewBlock(8, true, pos);
block_ = factory()->NewBlock(8, true);
Variable* temp = nullptr;
Expression* pattern = assign->target();
Expression* old_value = current_value_;
......
......@@ -662,7 +662,6 @@ class PreParserFactory {
}
PreParserStatement NewBlock(int capacity, bool ignore_completion_value,
int pos = kNoSourcePosition,
ZoneList<const AstRawString*>* labels = nullptr) {
return PreParserStatement::Default();
}
......
......@@ -114,7 +114,7 @@ class Processor final : public AstVisitor<Processor> {
Statement* Processor::AssignUndefinedBefore(Statement* s) {
Expression* undef = factory()->NewUndefinedLiteral(kNoSourcePosition);
Expression* assignment = SetResult(undef);
Block* b = factory()->NewBlock(2, false, kNoSourcePosition);
Block* b = factory()->NewBlock(2, false);
b->statements()->Add(
factory()->NewExpressionStatement(assignment, kNoSourcePosition), zone());
b->statements()->Add(s, zone());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment