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" |
11 #include "src/ast/ast-function-literal-id-reindexer.h" | 11 #include "src/ast/ast-function-literal-id-reindexer.h" |
12 #include "src/ast/ast-literal-reindexer.h" | |
13 #include "src/ast/ast-traversal-visitor.h" | 12 #include "src/ast/ast-traversal-visitor.h" |
14 #include "src/ast/ast.h" | 13 #include "src/ast/ast.h" |
15 #include "src/bailout-reason.h" | 14 #include "src/bailout-reason.h" |
16 #include "src/base/platform/platform.h" | 15 #include "src/base/platform/platform.h" |
17 #include "src/char-predicates-inl.h" | 16 #include "src/char-predicates-inl.h" |
18 #include "src/messages.h" | 17 #include "src/messages.h" |
19 #include "src/objects-inl.h" | 18 #include "src/objects-inl.h" |
20 #include "src/parsing/duplicate-finder.h" | 19 #include "src/parsing/duplicate-finder.h" |
21 #include "src/parsing/parameter-initializer-rewriter.h" | 20 #include "src/parsing/parameter-initializer-rewriter.h" |
22 #include "src/parsing/parse-info.h" | 21 #include "src/parsing/parse-info.h" |
(...skipping 2434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2457 } | 2456 } |
2458 DeclareFormalParameters(parameters->scope, parameters->params); | 2457 DeclareFormalParameters(parameters->scope, parameters->params); |
2459 if (!this->classifier() | 2458 if (!this->classifier() |
2460 ->is_valid_formal_parameter_list_without_duplicates()) { | 2459 ->is_valid_formal_parameter_list_without_duplicates()) { |
2461 *duplicate_loc = | 2460 *duplicate_loc = |
2462 this->classifier()->duplicate_formal_parameter_error().location; | 2461 this->classifier()->duplicate_formal_parameter_error().location; |
2463 } | 2462 } |
2464 DCHECK_EQ(parameters->is_simple, parameters->scope->has_simple_parameters()); | 2463 DCHECK_EQ(parameters->is_simple, parameters->scope->has_simple_parameters()); |
2465 } | 2464 } |
2466 | 2465 |
2467 void Parser::ReindexLiterals(const ParserFormalParameters& parameters) { | |
2468 if (function_state_->materialized_literal_count() > 0) { | |
2469 AstLiteralReindexer reindexer; | |
2470 | |
2471 for (auto p : parameters.params) { | |
2472 if (p->pattern != nullptr) reindexer.Reindex(p->pattern); | |
2473 if (p->initializer != nullptr) reindexer.Reindex(p->initializer); | |
2474 } | |
2475 | |
2476 DCHECK(reindexer.count() <= function_state_->materialized_literal_count()); | |
2477 } | |
2478 } | |
2479 | |
2480 void Parser::PrepareGeneratorVariables() { | 2466 void Parser::PrepareGeneratorVariables() { |
2481 // For generators, allocating variables in contexts is currently a win because | 2467 // For generators, allocating variables in contexts is currently a win because |
2482 // it minimizes the work needed to suspend and resume an activation. The | 2468 // it minimizes the work needed to suspend and resume an activation. The |
2483 // code produced for generators relies on this forced context allocation (it | 2469 // code produced for generators relies on this forced context allocation (it |
2484 // does not restore the frame's parameters upon resume). | 2470 // does not restore the frame's parameters upon resume). |
2485 function_state_->scope()->ForceContextAllocation(); | 2471 function_state_->scope()->ForceContextAllocation(); |
2486 | 2472 |
2487 // Calling a generator returns a generator object. That object is stored | 2473 // Calling a generator returns a generator object. That object is stored |
2488 // in a temporary variable, a definition that is used by "yield" | 2474 // in a temporary variable, a definition that is used by "yield" |
2489 // expressions. | 2475 // expressions. |
(...skipping 1036 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3526 | 3512 |
3527 expr = factory()->NewBinaryOperation( | 3513 expr = factory()->NewBinaryOperation( |
3528 Token::ADD, factory()->NewBinaryOperation( | 3514 Token::ADD, factory()->NewBinaryOperation( |
3529 Token::ADD, expr, middle, expr->position()), | 3515 Token::ADD, expr, middle, expr->position()), |
3530 cooked_str, sub->position()); | 3516 cooked_str, sub->position()); |
3531 } | 3517 } |
3532 return expr; | 3518 return expr; |
3533 } else { | 3519 } else { |
3534 uint32_t hash = ComputeTemplateLiteralHash(lit); | 3520 uint32_t hash = ComputeTemplateLiteralHash(lit); |
3535 | 3521 |
3536 int cooked_idx = function_state_->NextMaterializedLiteralIndex(); | 3522 // cooked and raw indexes. |
3537 int raw_idx = function_state_->NextMaterializedLiteralIndex(); | 3523 function_state_->NextMaterializedLiteralIndex(); |
| 3524 function_state_->NextMaterializedLiteralIndex(); |
3538 | 3525 |
3539 // $getTemplateCallSite | 3526 // $getTemplateCallSite |
3540 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(4, zone()); | 3527 ZoneList<Expression*>* args = new (zone()) ZoneList<Expression*>(4, zone()); |
3541 args->Add(factory()->NewArrayLiteral( | 3528 args->Add(factory()->NewArrayLiteral( |
3542 const_cast<ZoneList<Expression*>*>(cooked_strings), | 3529 const_cast<ZoneList<Expression*>*>(cooked_strings), pos), |
3543 cooked_idx, pos), | |
3544 zone()); | 3530 zone()); |
3545 args->Add( | 3531 args->Add(factory()->NewArrayLiteral( |
3546 factory()->NewArrayLiteral( | 3532 const_cast<ZoneList<Expression*>*>(raw_strings), pos), |
3547 const_cast<ZoneList<Expression*>*>(raw_strings), raw_idx, pos), | 3533 zone()); |
3548 zone()); | |
3549 | 3534 |
3550 // Truncate hash to Smi-range. | 3535 // Truncate hash to Smi-range. |
3551 Smi* hash_obj = Smi::cast(Internals::IntToSmi(static_cast<int>(hash))); | 3536 Smi* hash_obj = Smi::cast(Internals::IntToSmi(static_cast<int>(hash))); |
3552 args->Add(factory()->NewNumberLiteral(hash_obj->value(), pos), zone()); | 3537 args->Add(factory()->NewNumberLiteral(hash_obj->value(), pos), zone()); |
3553 | 3538 |
3554 Expression* call_site = factory()->NewCallRuntime( | 3539 Expression* call_site = factory()->NewCallRuntime( |
3555 Context::GET_TEMPLATE_CALL_SITE_INDEX, args, start); | 3540 Context::GET_TEMPLATE_CALL_SITE_INDEX, args, start); |
3556 | 3541 |
3557 // Call TagFn | 3542 // Call TagFn |
3558 ZoneList<Expression*>* call_args = | 3543 ZoneList<Expression*>* call_args = |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3635 int n = list->length(); | 3620 int n = list->length(); |
3636 while (i < n) { | 3621 while (i < n) { |
3637 if (!list->at(i)->IsSpread()) { | 3622 if (!list->at(i)->IsSpread()) { |
3638 ZoneList<Expression*>* unspread = | 3623 ZoneList<Expression*>* unspread = |
3639 new (zone()) ZoneList<Expression*>(1, zone()); | 3624 new (zone()) ZoneList<Expression*>(1, zone()); |
3640 | 3625 |
3641 // Push array of unspread parameters | 3626 // Push array of unspread parameters |
3642 while (i < n && !list->at(i)->IsSpread()) { | 3627 while (i < n && !list->at(i)->IsSpread()) { |
3643 unspread->Add(list->at(i++), zone()); | 3628 unspread->Add(list->at(i++), zone()); |
3644 } | 3629 } |
3645 int literal_index = function_state_->NextMaterializedLiteralIndex(); | 3630 function_state_->NextMaterializedLiteralIndex(); |
3646 args->Add(factory()->NewArrayLiteral(unspread, literal_index, | 3631 args->Add(factory()->NewArrayLiteral(unspread, kNoSourcePosition), |
3647 kNoSourcePosition), | |
3648 zone()); | 3632 zone()); |
3649 | 3633 |
3650 if (i == n) break; | 3634 if (i == n) break; |
3651 } | 3635 } |
3652 | 3636 |
3653 // Push eagerly spread argument | 3637 // Push eagerly spread argument |
3654 ZoneList<Expression*>* spread_list = | 3638 ZoneList<Expression*>* spread_list = |
3655 new (zone()) ZoneList<Expression*>(1, zone()); | 3639 new (zone()) ZoneList<Expression*>(1, zone()); |
3656 spread_list->Add(list->at(i++)->AsSpread()->expression(), zone()); | 3640 spread_list->Add(list->at(i++)->AsSpread()->expression(), zone()); |
3657 args->Add(factory()->NewCallRuntime(Context::SPREAD_ITERABLE_INDEX, | 3641 args->Add(factory()->NewCallRuntime(Context::SPREAD_ITERABLE_INDEX, |
(...skipping 1379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5037 | 5021 |
5038 return final_loop; | 5022 return final_loop; |
5039 } | 5023 } |
5040 | 5024 |
5041 #undef CHECK_OK | 5025 #undef CHECK_OK |
5042 #undef CHECK_OK_VOID | 5026 #undef CHECK_OK_VOID |
5043 #undef CHECK_FAILED | 5027 #undef CHECK_FAILED |
5044 | 5028 |
5045 } // namespace internal | 5029 } // namespace internal |
5046 } // namespace v8 | 5030 } // namespace v8 |
OLD | NEW |