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

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

Issue 1269783004: Fix constructor closures in checked mode (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 4 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
« no previous file with comments | « no previous file | 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 6
7 #include "lib/invocation_mirror.h" 7 #include "lib/invocation_mirror.h"
8 #include "platform/utils.h" 8 #include "platform/utils.h"
9 #include "vm/ast_transformer.h" 9 #include "vm/ast_transformer.h"
10 #include "vm/bootstrap.h" 10 #include "vm/bootstrap.h"
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 param.is_final = true; 550 param.is_final = true;
551 param.type = type; 551 param.type = type;
552 this->parameters->Add(param); 552 this->parameters->Add(param);
553 } 553 }
554 554
555 void AddReceiver(const AbstractType* receiver_type, intptr_t token_pos) { 555 void AddReceiver(const AbstractType* receiver_type, intptr_t token_pos) {
556 ASSERT(this->parameters->is_empty()); 556 ASSERT(this->parameters->is_empty());
557 AddFinalParameter(token_pos, &Symbols::This(), receiver_type); 557 AddFinalParameter(token_pos, &Symbols::This(), receiver_type);
558 } 558 }
559 559
560 void EraseParameterTypes() {
561 const Type& dynamic_type = Type::ZoneHandle(Type::DynamicType());
562 const int num_parameters = parameters->length();
563 for (int i = 0; i < num_parameters; i++) {
564 (*parameters)[i].type = &dynamic_type;
565 }
566 }
560 567
561 // Make the parameter variables visible/invisible. 568 // Make the parameter variables visible/invisible.
562 // Field initializer parameters are always invisible. 569 // Field initializer parameters are always invisible.
563 void SetInvisible(bool invisible) { 570 void SetInvisible(bool invisible) {
564 const intptr_t num_params = parameters->length(); 571 const intptr_t num_params = parameters->length();
565 for (int i = 0; i < num_params; i++) { 572 for (int i = 0; i < num_params; i++) {
566 ParamDesc& param = (*parameters)[i]; 573 ParamDesc& param = (*parameters)[i];
567 ASSERT(param.var != NULL); 574 ASSERT(param.var != NULL);
568 if (!param.is_field_initializer) { 575 if (!param.is_field_initializer) {
569 param.var->set_invisible(invisible); 576 param.var->set_invisible(invisible);
(...skipping 765 matching lines...) Expand 10 before | Expand all | Expand 10 after
1335 1342
1336 ParamList params; 1343 ParamList params;
1337 // The first parameter of the closure function is the implicit closure 1344 // The first parameter of the closure function is the implicit closure
1338 // argument. 1345 // argument.
1339 params.AddFinalParameter(token_pos, 1346 params.AddFinalParameter(token_pos,
1340 &Symbols::ClosureParameter(), 1347 &Symbols::ClosureParameter(),
1341 &Type::ZoneHandle(Z, Type::DynamicType())); 1348 &Type::ZoneHandle(Z, Type::DynamicType()));
1342 bool params_ok = ParseFormalParameters(constructor, &params); 1349 bool params_ok = ParseFormalParameters(constructor, &params);
1343 USE(params_ok); 1350 USE(params_ok);
1344 ASSERT(params_ok); 1351 ASSERT(params_ok);
1352 // Per language spec, the type of the closure parameters is dynamic.
1353 // Replace the types parsed from the constructor.
1354 params.EraseParameterTypes();
1345 1355
1346 SetupDefaultsForOptionalParams(&params, default_values); 1356 SetupDefaultsForOptionalParams(&params, default_values);
1347 ASSERT(func.num_fixed_parameters() == params.num_fixed_parameters); 1357 ASSERT(func.num_fixed_parameters() == params.num_fixed_parameters);
1348 ASSERT(func.NumOptionalParameters() == params.num_optional_parameters); 1358 ASSERT(func.NumOptionalParameters() == params.num_optional_parameters);
1349 1359
1350 OpenFunctionBlock(func); 1360 OpenFunctionBlock(func);
1351 LocalScope* scope = current_block_->scope; 1361 LocalScope* scope = current_block_->scope;
1352 AddFormalParamsToScope(&params, scope); 1362 AddFormalParamsToScope(&params, scope);
1353 1363
1354 ArgumentListNode* ctor_args = new ArgumentListNode(token_pos); 1364 ArgumentListNode* ctor_args = new ArgumentListNode(token_pos);
(...skipping 11502 matching lines...) Expand 10 before | Expand all | Expand 10 after
12857 ASSERT(ctr.kind() == RawFunction::kConstructor); 12867 ASSERT(ctr.kind() == RawFunction::kConstructor);
12858 String& closure_name = String::Handle(Z, ctr.name()); 12868 String& closure_name = String::Handle(Z, ctr.name());
12859 closure_name = Symbols::FromConcat(Symbols::ConstructorClosurePrefix(), 12869 closure_name = Symbols::FromConcat(Symbols::ConstructorClosurePrefix(),
12860 closure_name); 12870 closure_name);
12861 ParamList params; 12871 ParamList params;
12862 params.AddFinalParameter(token_pos, 12872 params.AddFinalParameter(token_pos,
12863 &Symbols::ClosureParameter(), 12873 &Symbols::ClosureParameter(),
12864 &Type::ZoneHandle(Z, Type::DynamicType())); 12874 &Type::ZoneHandle(Z, Type::DynamicType()));
12865 12875
12866 ParseFormalParameters(ctr, &params); 12876 ParseFormalParameters(ctr, &params);
12877 // Per language spec, the type of the closure parameters is dynamic.
12878 // Replace the types parsed from the constructor.
12879 params.EraseParameterTypes();
12880
12867 Function& closure = Function::Handle(Z); 12881 Function& closure = Function::Handle(Z);
12868 closure = Function::NewClosureFunction(closure_name, 12882 closure = Function::NewClosureFunction(closure_name,
12869 innermost_function(), 12883 innermost_function(),
12870 token_pos); 12884 token_pos);
12871 closure.set_is_generated_body(true); 12885 closure.set_is_generated_body(true);
12872 closure.set_result_type(AbstractType::Handle(Type::DynamicType())); 12886 closure.set_result_type(AbstractType::Handle(Type::DynamicType()));
12873 AddFormalParamsToFunction(&params, closure); 12887 AddFormalParamsToFunction(&params, closure);
12874 12888
12875 // Create and set the signature class of the closure. 12889 // Create and set the signature class of the closure.
12876 const String& sig = String::Handle(Z, closure.Signature()); 12890 const String& sig = String::Handle(Z, closure.Signature());
(...skipping 1169 matching lines...) Expand 10 before | Expand all | Expand 10 after
14046 void Parser::SkipQualIdent() { 14060 void Parser::SkipQualIdent() {
14047 ASSERT(IsIdentifier()); 14061 ASSERT(IsIdentifier());
14048 ConsumeToken(); 14062 ConsumeToken();
14049 if (CurrentToken() == Token::kPERIOD) { 14063 if (CurrentToken() == Token::kPERIOD) {
14050 ConsumeToken(); // Consume the kPERIOD token. 14064 ConsumeToken(); // Consume the kPERIOD token.
14051 ExpectIdentifier("identifier expected after '.'"); 14065 ExpectIdentifier("identifier expected after '.'");
14052 } 14066 }
14053 } 14067 }
14054 14068
14055 } // namespace dart 14069 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698