| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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/interpreter/bytecode-generator.h" | 5 #include "src/interpreter/bytecode-generator.h" |
| 6 | 6 |
| 7 #include "src/ast/scopes.h" | 7 #include "src/ast/scopes.h" |
| 8 #include "src/compiler.h" | 8 #include "src/compiler.h" |
| 9 #include "src/interpreter/bytecode-register-allocator.h" | 9 #include "src/interpreter/bytecode-register-allocator.h" |
| 10 #include "src/interpreter/control-flow-builders.h" | 10 #include "src/interpreter/control-flow-builders.h" |
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 | 415 |
| 416 // Visit declarations within the function scope. | 416 // Visit declarations within the function scope. |
| 417 VisitDeclarations(scope()->declarations()); | 417 VisitDeclarations(scope()->declarations()); |
| 418 | 418 |
| 419 // Visit statements in the function body. | 419 // Visit statements in the function body. |
| 420 VisitStatements(info()->literal()->body()); | 420 VisitStatements(info()->literal()->body()); |
| 421 } | 421 } |
| 422 | 422 |
| 423 | 423 |
| 424 void BytecodeGenerator::VisitBlock(Block* stmt) { | 424 void BytecodeGenerator::VisitBlock(Block* stmt) { |
| 425 BlockBuilder block_builder(this->builder()); | 425 // Visit declarations and statements. |
| 426 if (stmt->scope() != nullptr && stmt->scope()->NeedsContext()) { |
| 427 VisitNewLocalBlockContext(stmt->scope()); |
| 428 ContextScope scope(this, stmt->scope()); |
| 429 VisitBlockDeclarationsAndStatements(stmt); |
| 430 } else { |
| 431 VisitBlockDeclarationsAndStatements(stmt); |
| 432 } |
| 433 } |
| 434 |
| 435 |
| 436 void BytecodeGenerator::VisitBlockDeclarationsAndStatements(Block* stmt) { |
| 437 BlockBuilder block_builder(builder()); |
| 426 ControlScopeForBreakable execution_control(this, stmt, &block_builder); | 438 ControlScopeForBreakable execution_control(this, stmt, &block_builder); |
| 427 | 439 if (stmt->scope() != nullptr) { |
| 428 if (stmt->scope() == NULL) { | 440 VisitDeclarations(stmt->scope()->declarations()); |
| 429 // Visit statements in the same scope, no declarations. | |
| 430 VisitStatements(stmt->statements()); | |
| 431 } else { | |
| 432 // Visit declarations and statements in a block scope. | |
| 433 if (stmt->scope()->NeedsContext()) { | |
| 434 VisitNewLocalBlockContext(stmt->scope()); | |
| 435 ContextScope scope(this, stmt->scope()); | |
| 436 VisitDeclarations(stmt->scope()->declarations()); | |
| 437 VisitStatements(stmt->statements()); | |
| 438 } else { | |
| 439 VisitDeclarations(stmt->scope()->declarations()); | |
| 440 VisitStatements(stmt->statements()); | |
| 441 } | |
| 442 } | 441 } |
| 442 VisitStatements(stmt->statements()); |
| 443 if (stmt->labels() != nullptr) block_builder.EndBlock(); | 443 if (stmt->labels() != nullptr) block_builder.EndBlock(); |
| 444 } | 444 } |
| 445 | 445 |
| 446 | 446 |
| 447 void BytecodeGenerator::VisitVariableDeclaration(VariableDeclaration* decl) { | 447 void BytecodeGenerator::VisitVariableDeclaration(VariableDeclaration* decl) { |
| 448 Variable* variable = decl->proxy()->var(); | 448 Variable* variable = decl->proxy()->var(); |
| 449 VariableMode mode = decl->mode(); | 449 VariableMode mode = decl->mode(); |
| 450 // Const and let variables are initialized with the hole so that we can | 450 // Const and let variables are initialized with the hole so that we can |
| 451 // check that they are only assigned once. | 451 // check that they are only assigned once. |
| 452 bool hole_init = mode == CONST || mode == CONST_LEGACY || mode == LET; | 452 bool hole_init = mode == CONST || mode == CONST_LEGACY || mode == LET; |
| (...skipping 1763 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2216 } | 2216 } |
| 2217 | 2217 |
| 2218 | 2218 |
| 2219 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { | 2219 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { |
| 2220 return info()->feedback_vector()->GetIndex(slot); | 2220 return info()->feedback_vector()->GetIndex(slot); |
| 2221 } | 2221 } |
| 2222 | 2222 |
| 2223 } // namespace interpreter | 2223 } // namespace interpreter |
| 2224 } // namespace internal | 2224 } // namespace internal |
| 2225 } // namespace v8 | 2225 } // namespace v8 |
| OLD | NEW |