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

Side by Side Diff: runtime/vm/parser.cc

Issue 2835363002: Properly handle implicit closure function when a generic function. (Closed)
Patch Set: Created 3 years, 8 months 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
« runtime/vm/object.cc ('K') | « runtime/vm/object.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/parser.h" 5 #include "vm/parser.h"
6 #include "vm/flags.h" 6 #include "vm/flags.h"
7 7
8 #ifndef DART_PRECOMPILED_RUNTIME 8 #ifndef DART_PRECOMPILED_RUNTIME
9 9
10 #include "lib/invocation_mirror.h" 10 #include "lib/invocation_mirror.h"
(...skipping 1539 matching lines...) Expand 10 before | Expand all | Expand 10 after
1550 return CloseBlock(); 1550 return CloseBlock();
1551 } 1551 }
1552 1552
1553 1553
1554 SequenceNode* Parser::ParseImplicitClosure(const Function& func) { 1554 SequenceNode* Parser::ParseImplicitClosure(const Function& func) {
1555 TRACE_PARSER("ParseImplicitClosure"); 1555 TRACE_PARSER("ParseImplicitClosure");
1556 TokenPosition token_pos = func.token_pos(); 1556 TokenPosition token_pos = func.token_pos();
1557 1557
1558 OpenFunctionBlock(func); 1558 OpenFunctionBlock(func);
1559 1559
1560 if (FLAG_reify_generic_functions) {
1561 // The parent function of an implicit closure is the original function, i.e.
1562 // non-closurized. It is not an enclosing function in the usual sense of a
1563 // parent function. Do not set parent_type_arguments() in parsed_function_.
1564 ASSERT(func.IsGeneric() == func.HasGenericParent());
1565
1566 if (func.IsGeneric()) {
1567 // Insert function type arguments variable to scope.
1568 LocalVariable* function_type_arguments = new (Z) LocalVariable(
1569 TokenPosition::kNoSource, TokenPosition::kNoSource,
1570 Symbols::FunctionTypeArgumentsVar(), Object::dynamic_type());
1571 current_block_->scope->AddVariable(function_type_arguments);
1572 ASSERT(FunctionLevel() == 0);
1573 parsed_function_->set_function_type_arguments(function_type_arguments);
1574 }
1575 }
1576
1577 // TODO(regis): Pass the function type arguments if func is generic.
1560 ParamList params; 1578 ParamList params;
1561 params.AddFinalParameter(token_pos, &Symbols::ClosureParameter(), 1579 params.AddFinalParameter(token_pos, &Symbols::ClosureParameter(),
1562 &Object::dynamic_type()); 1580 &Object::dynamic_type());
1563 1581
1564 const Function& parent = Function::Handle(func.parent_function()); 1582 const Function& parent = Function::Handle(func.parent_function());
1565 if (parent.IsImplicitSetterFunction()) { 1583 if (parent.IsImplicitSetterFunction()) {
1566 const TokenPosition ident_pos = func.token_pos(); 1584 const TokenPosition ident_pos = func.token_pos();
1567 ASSERT(IsIdentifier()); 1585 ASSERT(IsIdentifier());
1568 params.AddFinalParameter(ident_pos, &Symbols::Value(), 1586 params.AddFinalParameter(ident_pos, &Symbols::Value(),
1569 &Object::dynamic_type()); 1587 &Object::dynamic_type());
(...skipping 1883 matching lines...) Expand 10 before | Expand all | Expand 10 after
3453 3471
3454 if (func.IsGenerativeConstructor()) { 3472 if (func.IsGenerativeConstructor()) {
3455 SequenceNode* statements = ParseConstructor(func); 3473 SequenceNode* statements = ParseConstructor(func);
3456 last_used_try_index_ = saved_try_index; 3474 last_used_try_index_ = saved_try_index;
3457 return statements; 3475 return statements;
3458 } 3476 }
3459 3477
3460 ASSERT(!func.IsGenerativeConstructor()); 3478 ASSERT(!func.IsGenerativeConstructor());
3461 OpenFunctionBlock(func); // Build local scope for function. 3479 OpenFunctionBlock(func); // Build local scope for function.
3462 3480
3463 if (FLAG_reify_generic_functions && func.IsGeneric()) { 3481 if (FLAG_reify_generic_functions) {
3464 // Lookup function type arguments variable in parent function scope, if any. 3482 // Lookup function type arguments variable in parent function scope, if any.
3465 if (func.HasGenericParent()) { 3483 if (func.HasGenericParent()) {
3466 const String* variable_name = &Symbols::FunctionTypeArgumentsVar(); 3484 const String* variable_name = &Symbols::FunctionTypeArgumentsVar();
3467 LocalVariable* parent_type_arguments = 3485 LocalVariable* parent_type_arguments =
3468 current_block_->scope->LookupVariable(*variable_name, true); 3486 current_block_->scope->LookupVariable(*variable_name, true);
3469 ASSERT(parent_type_arguments != NULL); 3487 ASSERT(parent_type_arguments != NULL);
3470 // TODO(regis): It may be too early to capture parent_type_arguments here. 3488 // TODO(regis): It may be too early to capture parent_type_arguments here.
3471 // In case it is never used, we could save capturing and concatenating. 3489 // In case it is never used, we could save capturing and concatenating.
3472 current_block_->scope->CaptureVariable(parent_type_arguments); 3490 current_block_->scope->CaptureVariable(parent_type_arguments);
3473 parsed_function_->set_parent_type_arguments(parent_type_arguments); 3491 if (FunctionLevel() == 0) {
3492 parsed_function_->set_parent_type_arguments(parent_type_arguments);
3493 if (!func.IsGeneric() && parent_type_arguments->is_captured()) {
3494 parsed_function_->set_function_type_arguments(parent_type_arguments);
3495 }
3496 }
3474 } 3497 }
3475 // Insert function type arguments variable to scope. 3498 if (func.IsGeneric()) {
3476 LocalVariable* function_type_arguments = new (Z) LocalVariable( 3499 // Insert function type arguments variable to scope.
3477 TokenPosition::kNoSource, TokenPosition::kNoSource, 3500 LocalVariable* function_type_arguments = new (Z) LocalVariable(
3478 Symbols::FunctionTypeArgumentsVar(), Object::dynamic_type()); 3501 TokenPosition::kNoSource, TokenPosition::kNoSource,
3479 current_block_->scope->AddVariable(function_type_arguments); 3502 Symbols::FunctionTypeArgumentsVar(), Object::dynamic_type());
3480 parsed_function_->set_function_type_arguments(function_type_arguments); 3503 current_block_->scope->AddVariable(function_type_arguments);
3504 if (FunctionLevel() == 0) {
3505 parsed_function_->set_function_type_arguments(function_type_arguments);
3506 }
3507 }
3481 } 3508 }
3482 3509
3483 ParamList params; 3510 ParamList params;
3484 // An instance closure function may capture and access the receiver, but via 3511 // An instance closure function may capture and access the receiver, but via
3485 // the context and not via the first formal parameter. 3512 // the context and not via the first formal parameter.
3486 if (func.IsClosureFunction()) { 3513 if (func.IsClosureFunction()) {
3487 // The first parameter of a closure function is the closure object. 3514 // The first parameter of a closure function is the closure object.
3488 ASSERT(!func.is_const()); // Closure functions cannot be const. 3515 ASSERT(!func.is_const()); // Closure functions cannot be const.
3489 params.AddFinalParameter(TokenPos(), &Symbols::ClosureParameter(), 3516 params.AddFinalParameter(TokenPos(), &Symbols::ClosureParameter(),
3490 &Object::dynamic_type()); 3517 &Object::dynamic_type());
(...skipping 11679 matching lines...) Expand 10 before | Expand all | Expand 10 after
15170 const ArgumentListNode& function_args, 15197 const ArgumentListNode& function_args,
15171 const LocalVariable* temp_for_last_arg, 15198 const LocalVariable* temp_for_last_arg,
15172 bool is_super_invocation) { 15199 bool is_super_invocation) {
15173 UNREACHABLE(); 15200 UNREACHABLE();
15174 return NULL; 15201 return NULL;
15175 } 15202 }
15176 15203
15177 } // namespace dart 15204 } // namespace dart
15178 15205
15179 #endif // DART_PRECOMPILED_RUNTIME 15206 #endif // DART_PRECOMPILED_RUNTIME
OLDNEW
« runtime/vm/object.cc ('K') | « runtime/vm/object.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698