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

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

Issue 2966583002: Mark class as typedef class before parsing its function type when using the new (Closed)
Patch Set: Created 3 years, 5 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 | « 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 5453 matching lines...) Expand 10 before | Expand all | Expand 10 after
5464 5464
5465 // Create the function type alias scope class. It will be linked to its 5465 // Create the function type alias scope class. It will be linked to its
5466 // signature function after it has been parsed. The type parameters, in order 5466 // signature function after it has been parsed. The type parameters, in order
5467 // to be properly finalized, need to be associated to this scope class as 5467 // to be properly finalized, need to be associated to this scope class as
5468 // they are parsed. 5468 // they are parsed.
5469 const Class& function_type_alias = Class::Handle( 5469 const Class& function_type_alias = Class::Handle(
5470 Z, Class::New(library_, *alias_name, script_, declaration_pos)); 5470 Z, Class::New(library_, *alias_name, script_, declaration_pos));
5471 function_type_alias.set_is_synthesized_class(); 5471 function_type_alias.set_is_synthesized_class();
5472 function_type_alias.set_is_abstract(); 5472 function_type_alias.set_is_abstract();
5473 function_type_alias.set_is_prefinalized(); 5473 function_type_alias.set_is_prefinalized();
5474 // Make sure the function type alias can be recognized as a typedef class by
5475 // setting its signature function. When use_function_type_syntax is true, this
5476 // temporary signature function is replaced while parsing the function type.
5477 Function& signature_function = Function::Handle(
5478 Z, Function::NewSignatureFunction(function_type_alias,
5479 Function::Handle(Z), alias_name_pos));
5480 function_type_alias.set_signature_function(signature_function);
5474 library_.AddClass(function_type_alias); 5481 library_.AddClass(function_type_alias);
rmacnak 2017/06/29 21:11:09 ASSERT(function_type_alias.IsTypedefClass());
regis 2017/06/29 21:30:47 Done.
5475 ASSERT(current_class().IsTopLevel()); 5482 ASSERT(current_class().IsTopLevel());
5476 set_current_class(function_type_alias); 5483 set_current_class(function_type_alias);
5477 // Parse the type parameters of the typedef class. 5484 // Parse the type parameters of the typedef class.
5478 ParseTypeParameters(true); // Parameterizing current class. 5485 ParseTypeParameters(true); // Parameterizing current class.
5479 Function& signature_function = Function::Handle(Z);
5480 ASSERT(innermost_function().IsNull()); 5486 ASSERT(innermost_function().IsNull());
5481 if (use_function_type_syntax) { 5487 if (use_function_type_syntax) {
5482 ExpectToken(Token::kASSIGN); 5488 ExpectToken(Token::kASSIGN);
5483 ASSERT(result_type.IsNull()); // Not parsed yet. 5489 ASSERT(result_type.IsNull()); // Not parsed yet.
5484 // Do not resolve types before the function type alias can be recognized as
5485 // a typedef class, so that correct promotion of function types can occur.
5486 const Type& function_type = Type::Handle( 5490 const Type& function_type = Type::Handle(
5487 Z, ParseFunctionType(result_type, ClassFinalizer::kDoNotResolve)); 5491 Z, ParseFunctionType(result_type, ClassFinalizer::kDoNotResolve));
5488 signature_function = function_type.signature(); 5492 signature_function = function_type.signature();
5489 } else { 5493 } else {
5490 signature_function = Function::NewSignatureFunction(
5491 function_type_alias, Function::Handle(Z), alias_name_pos);
5492 innermost_function_ = signature_function.raw(); 5494 innermost_function_ = signature_function.raw();
5493 ParamList params; 5495 ParamList params;
5494 // Parse the formal parameters of the function type. 5496 // Parse the formal parameters of the function type.
5495 CheckToken(Token::kLPAREN, "formal parameter list expected"); 5497 CheckToken(Token::kLPAREN, "formal parameter list expected");
5496 // Add implicit closure object parameter. 5498 // Add implicit closure object parameter.
5497 params.AddFinalParameter(TokenPos(), &Symbols::ClosureParameter(), 5499 params.AddFinalParameter(TokenPos(), &Symbols::ClosureParameter(),
5498 &Object::dynamic_type()); 5500 &Object::dynamic_type());
5499 const bool allow_explicit_default_values = false; 5501 const bool allow_explicit_default_values = false;
5500 const bool evaluate_metadata = false; 5502 const bool evaluate_metadata = false;
5501 ParseFormalParameterList(use_function_type_syntax, 5503 ParseFormalParameterList(use_function_type_syntax,
5502 allow_explicit_default_values, evaluate_metadata, 5504 allow_explicit_default_values, evaluate_metadata,
5503 &params); 5505 &params);
5504 if (result_type.IsNull()) { 5506 if (result_type.IsNull()) {
5505 result_type = Type::DynamicType(); 5507 result_type = Type::DynamicType();
5506 } 5508 }
5507 signature_function.set_result_type(result_type); 5509 signature_function.set_result_type(result_type);
5508 AddFormalParamsToFunction(&params, signature_function); 5510 AddFormalParamsToFunction(&params, signature_function);
5509 ASSERT(innermost_function().raw() == signature_function.raw()); 5511 ASSERT(innermost_function().raw() == signature_function.raw());
5510 innermost_function_ = Function::null(); 5512 innermost_function_ = Function::null();
5511 } 5513 }
5512 ExpectSemicolon(); 5514 ExpectSemicolon();
5513 ASSERT(innermost_function().IsNull()); 5515 ASSERT(innermost_function().IsNull());
5514 5516 ASSERT(function_type_alias.signature_function() == signature_function.raw());
5515 // Set the signature function in the function type alias class.
5516 function_type_alias.set_signature_function(signature_function);
5517 5517
5518 // At this point, all function type parameters have been parsed and the class 5518 // At this point, all function type parameters have been parsed and the class
5519 // function_type_alias is recognized as a typedef, so we can resolve all type 5519 // function_type_alias is recognized as a typedef, so we can resolve all type
5520 // parameters in the signature type defined by the typedef. 5520 // parameters in the signature type defined by the typedef.
5521 AbstractType& function_type = 5521 AbstractType& function_type =
5522 Type::Handle(Z, signature_function.SignatureType()); 5522 Type::Handle(Z, signature_function.SignatureType());
5523 ASSERT(current_class().raw() == function_type_alias.raw()); 5523 ASSERT(current_class().raw() == function_type_alias.raw());
5524 ResolveType(&function_type); 5524 ResolveType(&function_type);
5525 // Resolving does not replace type or signature. 5525 // Resolving does not replace type or signature.
5526 ASSERT(function_type_alias.signature_function() == 5526 ASSERT(function_type_alias.signature_function() ==
(...skipping 7868 matching lines...) Expand 10 before | Expand all | Expand 10 after
13395 &Object::dynamic_type()); 13395 &Object::dynamic_type());
13396 13396
13397 const bool use_function_type_syntax = true; 13397 const bool use_function_type_syntax = true;
13398 const bool allow_explicit_default_values = false; 13398 const bool allow_explicit_default_values = false;
13399 const bool evaluate_metadata = false; 13399 const bool evaluate_metadata = false;
13400 ParseFormalParameterList(use_function_type_syntax, 13400 ParseFormalParameterList(use_function_type_syntax,
13401 allow_explicit_default_values, evaluate_metadata, 13401 allow_explicit_default_values, evaluate_metadata,
13402 &params); 13402 &params);
13403 AddFormalParamsToFunction(&params, signature_function); 13403 AddFormalParamsToFunction(&params, signature_function);
13404 innermost_function_ = innermost_function_.parent_function(); 13404 innermost_function_ = innermost_function_.parent_function();
13405 if (innermost_function().IsNull() && current_class().IsTypedefClass() &&
13406 !IsFunctionTypeSymbol()) {
13407 // The last parsed signature function is the typedef signature function.
13408 // Set it in the typedef class before building the signature type.
13409 current_class().set_signature_function(signature_function);
13410 }
13405 type = signature_function.SignatureType(); 13411 type = signature_function.SignatureType();
13406 } while (IsFunctionTypeSymbol()); 13412 } while (IsFunctionTypeSymbol());
13407 // At this point, all type parameters have been parsed, resolve the type. 13413 // At this point, all type parameters have been parsed, resolve the type.
13408 if (finalization == ClassFinalizer::kIgnore) { 13414 if (finalization == ClassFinalizer::kIgnore) {
13409 return Type::DynamicType(); 13415 return Type::DynamicType();
13410 } 13416 }
13411 if (finalization >= ClassFinalizer::kResolveTypeParameters) { 13417 if (finalization >= ClassFinalizer::kResolveTypeParameters) {
13412 ResolveType(&type); 13418 ResolveType(&type);
13413 if (finalization >= ClassFinalizer::kCanonicalize) { 13419 if (finalization >= ClassFinalizer::kCanonicalize) {
13414 type ^= CanonicalizeType(type); 13420 type ^= CanonicalizeType(type);
(...skipping 1999 matching lines...) Expand 10 before | Expand all | Expand 10 after
15414 TokenPosition* start, 15420 TokenPosition* start,
15415 TokenPosition* end) { 15421 TokenPosition* end) {
15416 UNREACHABLE(); 15422 UNREACHABLE();
15417 return false; 15423 return false;
15418 } 15424 }
15419 15425
15420 15426
15421 } // namespace dart 15427 } // namespace dart
15422 15428
15423 #endif // DART_PRECOMPILED_RUNTIME 15429 #endif // DART_PRECOMPILED_RUNTIME
OLDNEW
« no previous file with comments | « runtime/vm/object.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698