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

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: work in progress 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);
5482 ASSERT(function_type_alias.IsTypedefClass());
5475 ASSERT(current_class().IsTopLevel()); 5483 ASSERT(current_class().IsTopLevel());
5476 set_current_class(function_type_alias); 5484 set_current_class(function_type_alias);
5477 // Parse the type parameters of the typedef class. 5485 // Parse the type parameters of the typedef class.
5478 ParseTypeParameters(true); // Parameterizing current class. 5486 ParseTypeParameters(true); // Parameterizing current class.
5479 Function& signature_function = Function::Handle(Z);
5480 ASSERT(innermost_function().IsNull()); 5487 ASSERT(innermost_function().IsNull());
5481 if (use_function_type_syntax) { 5488 if (use_function_type_syntax) {
5482 ExpectToken(Token::kASSIGN); 5489 ExpectToken(Token::kASSIGN);
5483 ASSERT(result_type.IsNull()); // Not parsed yet. 5490 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( 5491 const Type& function_type = Type::Handle(
5487 Z, ParseFunctionType(result_type, ClassFinalizer::kDoNotResolve)); 5492 Z, ParseFunctionType(result_type, ClassFinalizer::kDoNotResolve));
5488 signature_function = function_type.signature(); 5493 signature_function = function_type.signature();
5489 } else { 5494 } else {
5490 signature_function = Function::NewSignatureFunction(
5491 function_type_alias, Function::Handle(Z), alias_name_pos);
5492 innermost_function_ = signature_function.raw(); 5495 innermost_function_ = signature_function.raw();
5493 ParamList params; 5496 ParamList params;
5494 // Parse the formal parameters of the function type. 5497 // Parse the formal parameters of the function type.
5495 CheckToken(Token::kLPAREN, "formal parameter list expected"); 5498 CheckToken(Token::kLPAREN, "formal parameter list expected");
5496 // Add implicit closure object parameter. 5499 // Add implicit closure object parameter.
5497 params.AddFinalParameter(TokenPos(), &Symbols::ClosureParameter(), 5500 params.AddFinalParameter(TokenPos(), &Symbols::ClosureParameter(),
5498 &Object::dynamic_type()); 5501 &Object::dynamic_type());
5499 const bool allow_explicit_default_values = false; 5502 const bool allow_explicit_default_values = false;
5500 const bool evaluate_metadata = false; 5503 const bool evaluate_metadata = false;
5501 ParseFormalParameterList(use_function_type_syntax, 5504 ParseFormalParameterList(use_function_type_syntax,
5502 allow_explicit_default_values, evaluate_metadata, 5505 allow_explicit_default_values, evaluate_metadata,
5503 &params); 5506 &params);
5504 if (result_type.IsNull()) { 5507 if (result_type.IsNull()) {
5505 result_type = Type::DynamicType(); 5508 result_type = Type::DynamicType();
5506 } 5509 }
5507 signature_function.set_result_type(result_type); 5510 signature_function.set_result_type(result_type);
5508 AddFormalParamsToFunction(&params, signature_function); 5511 AddFormalParamsToFunction(&params, signature_function);
5509 ASSERT(innermost_function().raw() == signature_function.raw()); 5512 ASSERT(innermost_function().raw() == signature_function.raw());
5510 innermost_function_ = Function::null(); 5513 innermost_function_ = Function::null();
5511 } 5514 }
5512 ExpectSemicolon(); 5515 ExpectSemicolon();
5513 ASSERT(innermost_function().IsNull()); 5516 ASSERT(innermost_function().IsNull());
5514 5517 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 5518
5518 // At this point, all function type parameters have been parsed and the class 5519 // 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 5520 // function_type_alias is recognized as a typedef, so we can resolve all type
5520 // parameters in the signature type defined by the typedef. 5521 // parameters in the signature type defined by the typedef.
5521 AbstractType& function_type = 5522 AbstractType& function_type =
5522 Type::Handle(Z, signature_function.SignatureType()); 5523 Type::Handle(Z, signature_function.SignatureType());
5523 ASSERT(current_class().raw() == function_type_alias.raw()); 5524 ASSERT(current_class().raw() == function_type_alias.raw());
5524 ResolveType(&function_type); 5525 ResolveType(&function_type);
5525 // Resolving does not replace type or signature. 5526 // Resolving does not replace type or signature.
5526 ASSERT(function_type_alias.signature_function() == 5527 ASSERT(function_type_alias.signature_function() ==
(...skipping 7868 matching lines...) Expand 10 before | Expand all | Expand 10 after
13395 &Object::dynamic_type()); 13396 &Object::dynamic_type());
13396 13397
13397 const bool use_function_type_syntax = true; 13398 const bool use_function_type_syntax = true;
13398 const bool allow_explicit_default_values = false; 13399 const bool allow_explicit_default_values = false;
13399 const bool evaluate_metadata = false; 13400 const bool evaluate_metadata = false;
13400 ParseFormalParameterList(use_function_type_syntax, 13401 ParseFormalParameterList(use_function_type_syntax,
13401 allow_explicit_default_values, evaluate_metadata, 13402 allow_explicit_default_values, evaluate_metadata,
13402 &params); 13403 &params);
13403 AddFormalParamsToFunction(&params, signature_function); 13404 AddFormalParamsToFunction(&params, signature_function);
13404 innermost_function_ = innermost_function_.parent_function(); 13405 innermost_function_ = innermost_function_.parent_function();
13406 if (innermost_function().IsNull() && current_class().IsTypedefClass() &&
13407 !IsFunctionTypeSymbol()) {
13408 // The last parsed signature function is the typedef signature function.
13409 // Set it in the typedef class before building the signature type.
13410 current_class().set_signature_function(signature_function);
13411 }
13405 type = signature_function.SignatureType(); 13412 type = signature_function.SignatureType();
13406 } while (IsFunctionTypeSymbol()); 13413 } while (IsFunctionTypeSymbol());
13407 // At this point, all type parameters have been parsed, resolve the type. 13414 // At this point, all type parameters have been parsed, resolve the type.
13408 if (finalization == ClassFinalizer::kIgnore) { 13415 if (finalization == ClassFinalizer::kIgnore) {
13409 return Type::DynamicType(); 13416 return Type::DynamicType();
13410 } 13417 }
13411 if (finalization >= ClassFinalizer::kResolveTypeParameters) { 13418 if (finalization >= ClassFinalizer::kResolveTypeParameters) {
13412 ResolveType(&type); 13419 ResolveType(&type);
13413 if (finalization >= ClassFinalizer::kCanonicalize) { 13420 if (finalization >= ClassFinalizer::kCanonicalize) {
13414 type ^= CanonicalizeType(type); 13421 type ^= CanonicalizeType(type);
(...skipping 1999 matching lines...) Expand 10 before | Expand all | Expand 10 after
15414 TokenPosition* start, 15421 TokenPosition* start,
15415 TokenPosition* end) { 15422 TokenPosition* end) {
15416 UNREACHABLE(); 15423 UNREACHABLE();
15417 return false; 15424 return false;
15418 } 15425 }
15419 15426
15420 15427
15421 } // namespace dart 15428 } // namespace dart
15422 15429
15423 #endif // DART_PRECOMPILED_RUNTIME 15430 #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