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

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

Issue 2979763002: [VM generic function types] Properly set the scope function after parsing a (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
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 2252 matching lines...) Expand 10 before | Expand all | Expand 10 after
2263 &Object::dynamic_type()); 2263 &Object::dynamic_type());
2264 2264
2265 const bool use_function_type_syntax = false; 2265 const bool use_function_type_syntax = false;
2266 const bool allow_explicit_default_values = false; 2266 const bool allow_explicit_default_values = false;
2267 const bool evaluate_metadata = false; 2267 const bool evaluate_metadata = false;
2268 ParseFormalParameterList(use_function_type_syntax, 2268 ParseFormalParameterList(use_function_type_syntax,
2269 allow_explicit_default_values, evaluate_metadata, 2269 allow_explicit_default_values, evaluate_metadata,
2270 &func_params); 2270 &func_params);
2271 2271
2272 signature_function.set_result_type(result_type); 2272 signature_function.set_result_type(result_type);
2273 // The result type may refer to the signature function's type parameters,
2274 // but was not parsed in the scope of the signature function. Adjust.
2275 result_type.SetScopeFunction(signature_function);
2273 AddFormalParamsToFunction(&func_params, signature_function); 2276 AddFormalParamsToFunction(&func_params, signature_function);
2274 2277
2275 ASSERT(innermost_function().raw() == signature_function.raw()); 2278 ASSERT(innermost_function().raw() == signature_function.raw());
2276 innermost_function_ = signature_function.parent_function(); 2279 innermost_function_ = signature_function.parent_function();
2277 2280
2278 Type& signature_type = 2281 Type& signature_type =
2279 Type::ZoneHandle(Z, signature_function.SignatureType()); 2282 Type::ZoneHandle(Z, signature_function.SignatureType());
2280 2283
2281 // A signature type itself cannot be malformed or malbounded, only its 2284 // A signature type itself cannot be malformed or malbounded, only its
2282 // signature function's result type or parameter types may be. 2285 // signature function's result type or parameter types may be.
(...skipping 1385 matching lines...) Expand 10 before | Expand all | Expand 10 after
3668 FinalizeFormalParameterTypes(&params); 3671 FinalizeFormalParameterTypes(&params);
3669 } 3672 }
3670 3673
3671 // The number of parameters and their type are not yet set in local 3674 // The number of parameters and their type are not yet set in local
3672 // functions, since they are not 'top-level' parsed. 3675 // functions, since they are not 'top-level' parsed.
3673 // However, they are already set when the local function is compiled, since 3676 // However, they are already set when the local function is compiled, since
3674 // the local function was parsed when its parent was compiled. 3677 // the local function was parsed when its parent was compiled.
3675 if (func.parameter_types() == Object::empty_array().raw()) { 3678 if (func.parameter_types() == Object::empty_array().raw()) {
3676 AddFormalParamsToFunction(&params, func); 3679 AddFormalParamsToFunction(&params, func);
3677 } 3680 }
3678 ResolveSignature(func); 3681 ResolveSignatureTypeParameters(func);
3679 if (!is_top_level_) { 3682 if (!is_top_level_) {
3680 ClassFinalizer::FinalizeSignature(Class::Handle(Z, func.origin()), func); 3683 ClassFinalizer::FinalizeSignature(Class::Handle(Z, func.origin()), func);
3681 } 3684 }
3682 SetupDefaultsForOptionalParams(params); 3685 SetupDefaultsForOptionalParams(params);
3683 ASSERT(AbstractType::Handle(Z, func.result_type()).IsResolved()); 3686 ASSERT(AbstractType::Handle(Z, func.result_type()).IsResolved());
3684 3687
3685 // Populate function scope with the formal parameters. 3688 // Populate function scope with the formal parameters.
3686 AddFormalParamsToScope(&params, current_block_->scope); 3689 AddFormalParamsToScope(&params, current_block_->scope);
3687 } 3690 }
3688 3691
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after
4265 if (method->has_abstract && (async_modifier != RawFunction::kNoModifier)) { 4268 if (method->has_abstract && (async_modifier != RawFunction::kNoModifier)) {
4266 ReportError(modifier_pos, 4269 ReportError(modifier_pos,
4267 "abstract function '%s' may not be async, async* or sync*", 4270 "abstract function '%s' may not be async, async* or sync*",
4268 method->name->ToCString()); 4271 method->name->ToCString());
4269 } 4272 }
4270 4273
4271 // Update function object. 4274 // Update function object.
4272 func.set_name(*method->name); 4275 func.set_name(*method->name);
4273 func.set_is_abstract(method->has_abstract); 4276 func.set_is_abstract(method->has_abstract);
4274 func.set_is_native(method->has_native); 4277 func.set_is_native(method->has_native);
4275 func.set_result_type(*method->type); // May set parent_function in type. 4278 func.set_result_type(*method->type);
4279 // The result type may refer to func's type parameters,
4280 // but was not parsed in the scope of func. Adjust.
4281 method->type->SetScopeFunction(func);
4282
4276 func.set_end_token_pos(method_end_pos); 4283 func.set_end_token_pos(method_end_pos);
4277 func.set_is_redirecting(is_redirecting); 4284 func.set_is_redirecting(is_redirecting);
4278 func.set_modifier(async_modifier); 4285 func.set_modifier(async_modifier);
4279 if (library_.is_dart_scheme() && library_.IsPrivate(*method->name)) { 4286 if (library_.is_dart_scheme() && library_.IsPrivate(*method->name)) {
4280 func.set_is_reflectable(false); 4287 func.set_is_reflectable(false);
4281 } 4288 }
4282 if (is_patch_source() && IsPatchAnnotation(method->metadata_pos)) { 4289 if (is_patch_source() && IsPatchAnnotation(method->metadata_pos)) {
4283 // Currently, we just ignore the patch annotation. If the function 4290 // Currently, we just ignore the patch annotation. If the function
4284 // name already exists in the patched class, this function will replace 4291 // name already exists in the patched class, this function will replace
4285 // the one in the patched class. 4292 // the one in the patched class.
(...skipping 12 matching lines...) Expand all
4298 func.SetRedirectionType(redirection_type); 4305 func.SetRedirectionType(redirection_type);
4299 if (!redirection_identifier.IsNull()) { 4306 if (!redirection_identifier.IsNull()) {
4300 func.SetRedirectionIdentifier(redirection_identifier); 4307 func.SetRedirectionIdentifier(redirection_identifier);
4301 } 4308 }
4302 } 4309 }
4303 4310
4304 ASSERT(is_top_level_); 4311 ASSERT(is_top_level_);
4305 AddFormalParamsToFunction(&method->params, func); 4312 AddFormalParamsToFunction(&method->params, func);
4306 ASSERT(innermost_function().raw() == func.raw()); 4313 ASSERT(innermost_function().raw() == func.raw());
4307 innermost_function_ = Function::null(); 4314 innermost_function_ = Function::null();
4308 ResolveSignature(func); 4315 ResolveSignatureTypeParameters(func);
4309 members->AddFunction(func); 4316 members->AddFunction(func);
4310 } 4317 }
4311 4318
4312 4319
4313 void Parser::ParseFieldDefinition(ClassDesc* members, MemberDesc* field) { 4320 void Parser::ParseFieldDefinition(ClassDesc* members, MemberDesc* field) {
4314 TRACE_PARSER("ParseFieldDefinition"); 4321 TRACE_PARSER("ParseFieldDefinition");
4315 // The parser has read the first field name and is now at the token 4322 // The parser has read the first field name and is now at the token
4316 // after the field name. 4323 // after the field name.
4317 ASSERT(CurrentToken() == Token::kSEMICOLON || 4324 ASSERT(CurrentToken() == Token::kSEMICOLON ||
4318 CurrentToken() == Token::kCOMMA || CurrentToken() == Token::kASSIGN); 4325 CurrentToken() == Token::kCOMMA || CurrentToken() == Token::kASSIGN);
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
4438 /* is_abstract = */ false, 4445 /* is_abstract = */ false,
4439 /* is_external = */ false, 4446 /* is_external = */ false,
4440 /* is_native = */ false, current_class(), 4447 /* is_native = */ false, current_class(),
4441 field->name_pos); 4448 field->name_pos);
4442 ParamList params; 4449 ParamList params;
4443 ASSERT(current_class().raw() == getter.Owner()); 4450 ASSERT(current_class().raw() == getter.Owner());
4444 params.AddReceiver(ReceiverType(current_class()), field->name_pos); 4451 params.AddReceiver(ReceiverType(current_class()), field->name_pos);
4445 getter.set_result_type(*field->type); 4452 getter.set_result_type(*field->type);
4446 getter.set_is_debuggable(false); 4453 getter.set_is_debuggable(false);
4447 AddFormalParamsToFunction(&params, getter); 4454 AddFormalParamsToFunction(&params, getter);
4448 ResolveSignature(getter); 4455 ResolveSignatureTypeParameters(getter);
4449 members->AddFunction(getter); 4456 members->AddFunction(getter);
4450 if (!field->has_final) { 4457 if (!field->has_final) {
4451 // Build a setter accessor for non-const fields. 4458 // Build a setter accessor for non-const fields.
4452 String& setter_name = 4459 String& setter_name =
4453 String::Handle(Z, Field::SetterSymbol(*field->name)); 4460 String::Handle(Z, Field::SetterSymbol(*field->name));
4454 setter = Function::New(setter_name, RawFunction::kImplicitSetter, 4461 setter = Function::New(setter_name, RawFunction::kImplicitSetter,
4455 field->has_static, field->has_final, 4462 field->has_static, field->has_final,
4456 /* is_abstract = */ false, 4463 /* is_abstract = */ false,
4457 /* is_external = */ false, 4464 /* is_external = */ false,
4458 /* is_native = */ false, current_class(), 4465 /* is_native = */ false, current_class(),
4459 field->name_pos); 4466 field->name_pos);
4460 ParamList params; 4467 ParamList params;
4461 ASSERT(current_class().raw() == setter.Owner()); 4468 ASSERT(current_class().raw() == setter.Owner());
4462 params.AddReceiver(ReceiverType(current_class()), field->name_pos); 4469 params.AddReceiver(ReceiverType(current_class()), field->name_pos);
4463 params.AddFinalParameter(TokenPos(), &Symbols::Value(), field->type); 4470 params.AddFinalParameter(TokenPos(), &Symbols::Value(), field->type);
4464 setter.set_result_type(Object::void_type()); 4471 setter.set_result_type(Object::void_type());
4465 setter.set_is_debuggable(false); 4472 setter.set_is_debuggable(false);
4466 if (library_.is_dart_scheme() && library_.IsPrivate(*field->name)) { 4473 if (library_.is_dart_scheme() && library_.IsPrivate(*field->name)) {
4467 setter.set_is_reflectable(false); 4474 setter.set_is_reflectable(false);
4468 } 4475 }
4469 AddFormalParamsToFunction(&params, setter); 4476 AddFormalParamsToFunction(&params, setter);
4470 ResolveSignature(setter); 4477 ResolveSignatureTypeParameters(setter);
4471 members->AddFunction(setter); 4478 members->AddFunction(setter);
4472 } 4479 }
4473 } 4480 }
4474 4481
4475 if (CurrentToken() != Token::kCOMMA) { 4482 if (CurrentToken() != Token::kCOMMA) {
4476 break; 4483 break;
4477 } 4484 }
4478 ConsumeToken(); 4485 ConsumeToken();
4479 field->name_pos = this->TokenPos(); 4486 field->name_pos = this->TokenPos();
4480 field->name = ExpectIdentifier("field name expected"); 4487 field->name = ExpectIdentifier("field name expected");
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
4721 } else { 4728 } else {
4722 ReportError( 4729 ReportError(
4723 "missing 'var', 'final', 'const' or type" 4730 "missing 'var', 'final', 'const' or type"
4724 " in field declaration"); 4731 " in field declaration");
4725 } 4732 }
4726 } else if (member.type->IsVoidType()) { 4733 } else if (member.type->IsVoidType()) {
4727 ReportError(member.name_pos, "field may not be 'void'"); 4734 ReportError(member.name_pos, "field may not be 'void'");
4728 } 4735 }
4729 if (!member.type->IsResolved()) { 4736 if (!member.type->IsResolved()) {
4730 AbstractType& type = AbstractType::ZoneHandle(Z, member.type->raw()); 4737 AbstractType& type = AbstractType::ZoneHandle(Z, member.type->raw());
4731 ResolveType(&type); 4738 ResolveTypeParameters(&type);
4732 member.type = &type; 4739 member.type = &type;
4733 } 4740 }
4734 ParseFieldDefinition(members, &member); 4741 ParseFieldDefinition(members, &member);
4735 } else { 4742 } else {
4736 UnexpectedToken(); 4743 UnexpectedToken();
4737 } 4744 }
4738 current_member_ = NULL; 4745 current_member_ = NULL;
4739 CheckMemberNameConflict(members, &member); 4746 CheckMemberNameConflict(members, &member);
4740 members->AddMember(member); 4747 members->AddMember(member);
4741 } 4748 }
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
5077 /* is_static = */ false, 5084 /* is_static = */ false,
5078 /* is_const = */ true, 5085 /* is_const = */ true,
5079 /* is_abstract = */ false, 5086 /* is_abstract = */ false,
5080 /* is_external = */ false, 5087 /* is_external = */ false,
5081 /* is_native = */ false, cls, cls.token_pos()); 5088 /* is_native = */ false, cls, cls.token_pos());
5082 getter.set_result_type(int_type); 5089 getter.set_result_type(int_type);
5083 getter.set_is_debuggable(false); 5090 getter.set_is_debuggable(false);
5084 ParamList params; 5091 ParamList params;
5085 params.AddReceiver(&Object::dynamic_type(), cls.token_pos()); 5092 params.AddReceiver(&Object::dynamic_type(), cls.token_pos());
5086 AddFormalParamsToFunction(&params, getter); 5093 AddFormalParamsToFunction(&params, getter);
5087 ResolveSignature(getter); 5094 ResolveSignatureTypeParameters(getter);
5088 enum_members.AddFunction(getter); 5095 enum_members.AddFunction(getter);
5089 5096
5090 ASSERT(IsIdentifier()); 5097 ASSERT(IsIdentifier());
5091 ASSERT(CurrentLiteral()->raw() == cls.Name()); 5098 ASSERT(CurrentLiteral()->raw() == cls.Name());
5092 5099
5093 ConsumeToken(); // Enum type name. 5100 ConsumeToken(); // Enum type name.
5094 ExpectToken(Token::kLBRACE); 5101 ExpectToken(Token::kLBRACE);
5095 Field& enum_value = Field::Handle(Z); 5102 Field& enum_value = Field::Handle(Z);
5096 intptr_t i = 0; 5103 intptr_t i = 0;
5097 GrowableArray<String*> declared_names(8); 5104 GrowableArray<String*> declared_names(8);
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
5205 /* is_static = */ false, 5212 /* is_static = */ false,
5206 /* is_const = */ true, 5213 /* is_const = */ true,
5207 /* is_abstract = */ false, 5214 /* is_abstract = */ false,
5208 /* is_external = */ false, 5215 /* is_external = */ false,
5209 /* is_native = */ false, cls, cls.token_pos()); 5216 /* is_native = */ false, cls, cls.token_pos());
5210 name_getter.set_result_type(string_type); 5217 name_getter.set_result_type(string_type);
5211 name_getter.set_is_debuggable(false); 5218 name_getter.set_is_debuggable(false);
5212 ParamList name_params; 5219 ParamList name_params;
5213 name_params.AddReceiver(&Object::dynamic_type(), cls.token_pos()); 5220 name_params.AddReceiver(&Object::dynamic_type(), cls.token_pos());
5214 AddFormalParamsToFunction(&name_params, name_getter); 5221 AddFormalParamsToFunction(&name_params, name_getter);
5215 ResolveSignature(name_getter); 5222 ResolveSignatureTypeParameters(name_getter);
5216 enum_members.AddFunction(name_getter); 5223 enum_members.AddFunction(name_getter);
5217 5224
5218 // Clone the toString() function from the helper class. 5225 // Clone the toString() function from the helper class.
5219 Function& to_string_func = Function::Handle( 5226 Function& to_string_func = Function::Handle(
5220 Z, helper_class.LookupDynamicFunctionAllowPrivate(Symbols::toString())); 5227 Z, helper_class.LookupDynamicFunctionAllowPrivate(Symbols::toString()));
5221 ASSERT(!to_string_func.IsNull()); 5228 ASSERT(!to_string_func.IsNull());
5222 to_string_func = to_string_func.Clone(cls); 5229 to_string_func = to_string_func.Clone(cls);
5223 enum_members.AddFunction(to_string_func); 5230 enum_members.AddFunction(to_string_func);
5224 5231
5225 // Clone the hashCode getter function from the helper class. 5232 // Clone the hashCode getter function from the helper class.
(...skipping 30 matching lines...) Expand all
5256 ctor.set_is_reflectable(false); 5263 ctor.set_is_reflectable(false);
5257 } 5264 }
5258 5265
5259 ParamList params; 5266 ParamList params;
5260 // Add implicit 'this' parameter. 5267 // Add implicit 'this' parameter.
5261 const AbstractType* receiver_type = ReceiverType(cls); 5268 const AbstractType* receiver_type = ReceiverType(cls);
5262 params.AddReceiver(receiver_type, cls.token_pos()); 5269 params.AddReceiver(receiver_type, cls.token_pos());
5263 5270
5264 AddFormalParamsToFunction(&params, ctor); 5271 AddFormalParamsToFunction(&params, ctor);
5265 ctor.set_result_type(Object::dynamic_type()); 5272 ctor.set_result_type(Object::dynamic_type());
5266 ResolveSignature(ctor); 5273 ResolveSignatureTypeParameters(ctor);
5267 // The body of the constructor cannot modify the type of the constructed 5274 // The body of the constructor cannot modify the type of the constructed
5268 // instance, which is passed in as the receiver. 5275 // instance, which is passed in as the receiver.
5269 ctor.set_result_type(*receiver_type); 5276 ctor.set_result_type(*receiver_type);
5270 cls.AddFunction(ctor); 5277 cls.AddFunction(ctor);
5271 } 5278 }
5272 5279
5273 5280
5274 void Parser::CheckFinalInitializationConflicts(const ClassDesc* class_desc, 5281 void Parser::CheckFinalInitializationConflicts(const ClassDesc* class_desc,
5275 const MemberDesc* member) { 5282 const MemberDesc* member) {
5276 const ParamList* params = &member->params; 5283 const ParamList* params = &member->params;
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
5507 &Object::dynamic_type()); 5514 &Object::dynamic_type());
5508 const bool allow_explicit_default_values = false; 5515 const bool allow_explicit_default_values = false;
5509 const bool evaluate_metadata = false; 5516 const bool evaluate_metadata = false;
5510 ParseFormalParameterList(use_function_type_syntax, 5517 ParseFormalParameterList(use_function_type_syntax,
5511 allow_explicit_default_values, evaluate_metadata, 5518 allow_explicit_default_values, evaluate_metadata,
5512 &params); 5519 &params);
5513 if (result_type.IsNull()) { 5520 if (result_type.IsNull()) {
5514 result_type = Type::DynamicType(); 5521 result_type = Type::DynamicType();
5515 } 5522 }
5516 signature_function.set_result_type(result_type); 5523 signature_function.set_result_type(result_type);
5524 // The result type may refer to the signature function's type parameters,
5525 // but was not parsed in the scope of the signature function. Adjust.
5526 result_type.SetScopeFunction(signature_function);
5517 AddFormalParamsToFunction(&params, signature_function); 5527 AddFormalParamsToFunction(&params, signature_function);
5518 ASSERT(innermost_function().raw() == signature_function.raw()); 5528 ASSERT(innermost_function().raw() == signature_function.raw());
5519 innermost_function_ = Function::null(); 5529 innermost_function_ = Function::null();
5520 } 5530 }
5521 ExpectSemicolon(); 5531 ExpectSemicolon();
5522 ASSERT(innermost_function().IsNull()); 5532 ASSERT(innermost_function().IsNull());
5523 ASSERT(function_type_alias.signature_function() == signature_function.raw()); 5533 ASSERT(function_type_alias.signature_function() == signature_function.raw());
5524 5534
5525 // At this point, all function type parameters have been parsed and the class 5535 // At this point, all function type parameters have been parsed and the class
5526 // function_type_alias is recognized as a typedef, so we can resolve all type 5536 // function_type_alias is recognized as a typedef, so we can resolve all type
5527 // parameters in the signature type defined by the typedef. 5537 // parameters in the signature type defined by the typedef.
5528 AbstractType& function_type = 5538 AbstractType& function_type =
5529 Type::Handle(Z, signature_function.SignatureType()); 5539 Type::Handle(Z, signature_function.SignatureType());
5530 ASSERT(current_class().raw() == function_type_alias.raw()); 5540 ASSERT(current_class().raw() == function_type_alias.raw());
5531 ResolveType(&function_type); 5541 ResolveTypeParameters(&function_type);
5532 // Resolving does not replace type or signature. 5542 // Resolving does not replace type or signature.
5533 ASSERT(function_type_alias.signature_function() == 5543 ASSERT(function_type_alias.signature_function() ==
5534 Type::Cast(function_type).signature()); 5544 Type::Cast(function_type).signature());
5535 5545
5536 if (FLAG_trace_parser) { 5546 if (FLAG_trace_parser) {
5537 OS::Print("TopLevel parsing function type alias '%s'\n", 5547 OS::Print("TopLevel parsing function type alias '%s'\n",
5538 String::Handle(Z, signature_function.Signature()).ToCString()); 5548 String::Handle(Z, signature_function.Signature()).ToCString());
5539 } 5549 }
5540 // The alias should not be marked as finalized yet, since it needs to be 5550 // The alias should not be marked as finalized yet, since it needs to be
5541 // checked in the class finalizer for illegal self references. 5551 // checked in the class finalizer for illegal self references.
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
5734 if (parameterizing_class) { 5744 if (parameterizing_class) {
5735 current_class().set_type_parameters(type_parameters); 5745 current_class().set_type_parameters(type_parameters);
5736 } else { 5746 } else {
5737 innermost_function().set_type_parameters(type_parameters); 5747 innermost_function().set_type_parameters(type_parameters);
5738 } 5748 }
5739 // Resolve type parameters referenced by upper bounds. 5749 // Resolve type parameters referenced by upper bounds.
5740 const intptr_t num_types = type_parameters.Length(); 5750 const intptr_t num_types = type_parameters.Length();
5741 for (intptr_t i = 0; i < num_types; i++) { 5751 for (intptr_t i = 0; i < num_types; i++) {
5742 type_parameter ^= type_parameters.TypeAt(i); 5752 type_parameter ^= type_parameters.TypeAt(i);
5743 type_parameter_bound = type_parameter.bound(); 5753 type_parameter_bound = type_parameter.bound();
5744 ResolveType(&type_parameter_bound); 5754 ResolveTypeParameters(&type_parameter_bound);
5745 type_parameter.set_bound(type_parameter_bound); 5755 type_parameter.set_bound(type_parameter_bound);
5746 } 5756 }
5747 } 5757 }
5748 } 5758 }
5749 5759
5750 5760
5751 RawTypeArguments* Parser::ParseTypeArguments( 5761 RawTypeArguments* Parser::ParseTypeArguments(
5752 ClassFinalizer::FinalizationKind finalization) { 5762 ClassFinalizer::FinalizationKind finalization) {
5753 TRACE_PARSER("ParseTypeArguments"); 5763 TRACE_PARSER("ParseTypeArguments");
5754 if (CurrentToken() == Token::kLT) { 5764 if (CurrentToken() == Token::kLT) {
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
6050 } else if (IsSymbol(Symbols::Native())) { 6060 } else if (IsSymbol(Symbols::Native())) {
6051 native_name = &ParseNativeDeclaration(); 6061 native_name = &ParseNativeDeclaration();
6052 function_end_pos = TokenPos(); 6062 function_end_pos = TokenPos();
6053 ExpectSemicolon(); 6063 ExpectSemicolon();
6054 is_native = true; 6064 is_native = true;
6055 func.set_is_native(true); 6065 func.set_is_native(true);
6056 } else { 6066 } else {
6057 ReportError("function block expected"); 6067 ReportError("function block expected");
6058 } 6068 }
6059 func.set_result_type(result_type); 6069 func.set_result_type(result_type);
6070 // The result type may refer to func's type parameters,
6071 // but was not parsed in the scope of func. Adjust.
6072 result_type.SetScopeFunction(func);
6060 func.set_end_token_pos(function_end_pos); 6073 func.set_end_token_pos(function_end_pos);
6061 func.set_modifier(func_modifier); 6074 func.set_modifier(func_modifier);
6062 if (library_.is_dart_scheme() && library_.IsPrivate(func_name)) { 6075 if (library_.is_dart_scheme() && library_.IsPrivate(func_name)) {
6063 func.set_is_reflectable(false); 6076 func.set_is_reflectable(false);
6064 } 6077 }
6065 if (is_native) { 6078 if (is_native) {
6066 func.set_native_name(*native_name); 6079 func.set_native_name(*native_name);
6067 } 6080 }
6068 AddFormalParamsToFunction(&params, func); 6081 AddFormalParamsToFunction(&params, func);
6069 ASSERT(innermost_function().raw() == func.raw()); 6082 ASSERT(innermost_function().raw() == func.raw());
6070 innermost_function_ = Function::null(); 6083 innermost_function_ = Function::null();
6071 ResolveSignature(func); 6084 ResolveSignatureTypeParameters(func);
6072 top_level->AddFunction(func); 6085 top_level->AddFunction(func);
6073 if (!is_patch) { 6086 if (!is_patch) {
6074 library_.AddObject(func, func_name); 6087 library_.AddObject(func, func_name);
6075 } else { 6088 } else {
6076 // Need to remove the previously added function that is being patched. 6089 // Need to remove the previously added function that is being patched.
6077 const Class& toplevel_cls = Class::Handle(Z, library_.toplevel_class()); 6090 const Class& toplevel_cls = Class::Handle(Z, library_.toplevel_class());
6078 const Function& replaced_func = 6091 const Function& replaced_func =
6079 Function::Handle(Z, toplevel_cls.LookupStaticFunction(func_name)); 6092 Function::Handle(Z, toplevel_cls.LookupStaticFunction(func_name));
6080 ASSERT(!replaced_func.IsNull()); 6093 ASSERT(!replaced_func.IsNull());
6081 toplevel_cls.RemoveFunction(replaced_func); 6094 toplevel_cls.RemoveFunction(replaced_func);
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
6206 ReportError("function block expected"); 6219 ReportError("function block expected");
6207 } 6220 }
6208 Function& func = Function::Handle( 6221 Function& func = Function::Handle(
6209 Z, Function::New(accessor_name, is_getter ? RawFunction::kGetterFunction 6222 Z, Function::New(accessor_name, is_getter ? RawFunction::kGetterFunction
6210 : RawFunction::kSetterFunction, 6223 : RawFunction::kSetterFunction,
6211 is_static, 6224 is_static,
6212 /* is_const = */ false, 6225 /* is_const = */ false,
6213 /* is_abstract = */ false, is_external, is_native, owner, 6226 /* is_abstract = */ false, is_external, is_native, owner,
6214 decl_begin_pos)); 6227 decl_begin_pos));
6215 func.set_result_type(result_type); 6228 func.set_result_type(result_type);
6229 // The result type may refer to func's type parameters,
6230 // but was not parsed in the scope of func. Adjust.
6231 result_type.SetScopeFunction(func);
6216 func.set_end_token_pos(accessor_end_pos); 6232 func.set_end_token_pos(accessor_end_pos);
6217 func.set_modifier(func_modifier); 6233 func.set_modifier(func_modifier);
6218 if (is_native) { 6234 if (is_native) {
6219 func.set_is_debuggable(false); 6235 func.set_is_debuggable(false);
6220 func.set_native_name(*native_name); 6236 func.set_native_name(*native_name);
6221 } 6237 }
6222 if (library_.is_dart_scheme() && library_.IsPrivate(accessor_name)) { 6238 if (library_.is_dart_scheme() && library_.IsPrivate(accessor_name)) {
6223 func.set_is_reflectable(false); 6239 func.set_is_reflectable(false);
6224 } 6240 }
6225 AddFormalParamsToFunction(&params, func); 6241 AddFormalParamsToFunction(&params, func);
6226 ResolveSignature(func); 6242 ResolveSignatureTypeParameters(func);
6227 top_level->AddFunction(func); 6243 top_level->AddFunction(func);
6228 if (!is_patch) { 6244 if (!is_patch) {
6229 library_.AddObject(func, accessor_name); 6245 library_.AddObject(func, accessor_name);
6230 } else { 6246 } else {
6231 // Need to remove the previously added accessor that is being patched. 6247 // Need to remove the previously added accessor that is being patched.
6232 const Class& toplevel_cls = Class::Handle( 6248 const Class& toplevel_cls = Class::Handle(
6233 Z, owner.IsClass() ? Class::Cast(owner).raw() 6249 Z, owner.IsClass() ? Class::Cast(owner).raw()
6234 : PatchClass::Cast(owner).patched_class()); 6250 : PatchClass::Cast(owner).patched_class());
6235 const Function& replaced_func = 6251 const Function& replaced_func =
6236 Function::Handle(Z, toplevel_cls.LookupFunction(accessor_name)); 6252 Function::Handle(Z, toplevel_cls.LookupFunction(accessor_name));
(...skipping 833 matching lines...) Expand 10 before | Expand all | Expand 10 after
7070 body.set_result_type(Object::dynamic_type()); 7086 body.set_result_type(Object::dynamic_type());
7071 is_new_closure = true; 7087 is_new_closure = true;
7072 } 7088 }
7073 7089
7074 ParamList closure_params; 7090 ParamList closure_params;
7075 AddSyncGenClosureParameters(&closure_params); 7091 AddSyncGenClosureParameters(&closure_params);
7076 7092
7077 if (is_new_closure) { 7093 if (is_new_closure) {
7078 // Add the parameters to the newly created closure. 7094 // Add the parameters to the newly created closure.
7079 AddFormalParamsToFunction(&closure_params, body); 7095 AddFormalParamsToFunction(&closure_params, body);
7080 ResolveSignature(body); 7096 ResolveSignatureTypeParameters(body);
7081 // Finalize function type. 7097 // Finalize function type.
7082 Type& signature_type = Type::Handle(Z, body.SignatureType()); 7098 Type& signature_type = Type::Handle(Z, body.SignatureType());
7083 signature_type ^= CanonicalizeType(signature_type); 7099 signature_type ^= CanonicalizeType(signature_type);
7084 body.SetSignatureType(signature_type); 7100 body.SetSignatureType(signature_type);
7085 ASSERT(AbstractType::Handle(Z, body.result_type()).IsResolved()); 7101 ASSERT(AbstractType::Handle(Z, body.result_type()).IsResolved());
7086 ASSERT(body.NumParameters() == closure_params.parameters->length()); 7102 ASSERT(body.NumParameters() == closure_params.parameters->length());
7087 } 7103 }
7088 7104
7089 OpenFunctionBlock(body); 7105 OpenFunctionBlock(body);
7090 AddFormalParamsToScope(&closure_params, current_block_->scope); 7106 AddFormalParamsToScope(&closure_params, current_block_->scope);
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
7198 // TODO(regis): Handle generic async function. 7214 // TODO(regis): Handle generic async function.
7199 closure.set_result_type(Object::dynamic_type()); 7215 closure.set_result_type(Object::dynamic_type());
7200 is_new_closure = true; 7216 is_new_closure = true;
7201 } 7217 }
7202 // Create the parameter list for the async body closure. 7218 // Create the parameter list for the async body closure.
7203 ParamList closure_params; 7219 ParamList closure_params;
7204 AddAsyncClosureParameters(&closure_params); 7220 AddAsyncClosureParameters(&closure_params);
7205 if (is_new_closure) { 7221 if (is_new_closure) {
7206 // Add the parameters to the newly created closure. 7222 // Add the parameters to the newly created closure.
7207 AddFormalParamsToFunction(&closure_params, closure); 7223 AddFormalParamsToFunction(&closure_params, closure);
7208 ResolveSignature(closure); 7224 ResolveSignatureTypeParameters(closure);
7209 7225
7210 // Finalize function type. 7226 // Finalize function type.
7211 Type& signature_type = Type::Handle(Z, closure.SignatureType()); 7227 Type& signature_type = Type::Handle(Z, closure.SignatureType());
7212 signature_type ^= CanonicalizeType(signature_type); 7228 signature_type ^= CanonicalizeType(signature_type);
7213 closure.SetSignatureType(signature_type); 7229 closure.SetSignatureType(signature_type);
7214 ASSERT(AbstractType::Handle(Z, closure.result_type()).IsResolved()); 7230 ASSERT(AbstractType::Handle(Z, closure.result_type()).IsResolved());
7215 ASSERT(closure.NumParameters() == closure_params.parameters->length()); 7231 ASSERT(closure.NumParameters() == closure_params.parameters->length());
7216 } 7232 }
7217 OpenFunctionBlock(closure); 7233 OpenFunctionBlock(closure);
7218 AddFormalParamsToScope(&closure_params, current_block_->scope); 7234 AddFormalParamsToScope(&closure_params, current_block_->scope);
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
7336 closure.set_result_type(Object::dynamic_type()); 7352 closure.set_result_type(Object::dynamic_type());
7337 is_new_closure = true; 7353 is_new_closure = true;
7338 } 7354 }
7339 7355
7340 ParamList closure_params; 7356 ParamList closure_params;
7341 AddAsyncGenClosureParameters(&closure_params); 7357 AddAsyncGenClosureParameters(&closure_params);
7342 7358
7343 if (is_new_closure) { 7359 if (is_new_closure) {
7344 // Add the parameters to the newly created closure. 7360 // Add the parameters to the newly created closure.
7345 AddFormalParamsToFunction(&closure_params, closure); 7361 AddFormalParamsToFunction(&closure_params, closure);
7346 ResolveSignature(closure); 7362 ResolveSignatureTypeParameters(closure);
7347 7363
7348 // Finalize function type. 7364 // Finalize function type.
7349 Type& signature_type = Type::Handle(Z, closure.SignatureType()); 7365 Type& signature_type = Type::Handle(Z, closure.SignatureType());
7350 signature_type ^= CanonicalizeType(signature_type); 7366 signature_type ^= CanonicalizeType(signature_type);
7351 closure.SetSignatureType(signature_type); 7367 closure.SetSignatureType(signature_type);
7352 ASSERT(AbstractType::Handle(Z, closure.result_type()).IsResolved()); 7368 ASSERT(AbstractType::Handle(Z, closure.result_type()).IsResolved());
7353 ASSERT(closure.NumParameters() == closure_params.parameters->length()); 7369 ASSERT(closure.NumParameters() == closure_params.parameters->length());
7354 } 7370 }
7355 7371
7356 OpenFunctionBlock(closure); 7372 OpenFunctionBlock(closure);
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
7777 } 7793 }
7778 7794
7779 7795
7780 void Parser::FinalizeFormalParameterTypes(const ParamList* params) { 7796 void Parser::FinalizeFormalParameterTypes(const ParamList* params) {
7781 ASSERT((params != NULL) && (params->parameters != NULL)); 7797 ASSERT((params != NULL) && (params->parameters != NULL));
7782 const int num_parameters = params->parameters->length(); 7798 const int num_parameters = params->parameters->length();
7783 AbstractType& type = AbstractType::Handle(Z); 7799 AbstractType& type = AbstractType::Handle(Z);
7784 for (int i = 0; i < num_parameters; i++) { 7800 for (int i = 0; i < num_parameters; i++) {
7785 ParamDesc& param_desc = (*params->parameters)[i]; 7801 ParamDesc& param_desc = (*params->parameters)[i];
7786 type = param_desc.type->raw(); 7802 type = param_desc.type->raw();
7787 ResolveType(&type); 7803 ResolveTypeParameters(&type);
7788 type = CanonicalizeType(type); 7804 type = CanonicalizeType(type);
7789 if (type.raw() != param_desc.type->raw()) { 7805 if (type.raw() != param_desc.type->raw()) {
7790 param_desc.type = &AbstractType::ZoneHandle(Z, type.raw()); 7806 param_desc.type = &AbstractType::ZoneHandle(Z, type.raw());
7791 } 7807 }
7792 } 7808 }
7793 } 7809 }
7794 7810
7795 7811
7796 // Populate the parameter type array and parameter name array of the function 7812 // Populate the parameter type array and parameter name array of the function
7797 // with the formal parameter types and names. 7813 // with the formal parameter types and names.
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
8159 // non-closurized version of this same function. 8175 // non-closurized version of this same function.
8160 function = I->LookupClosureFunction(innermost_function(), function_pos); 8176 function = I->LookupClosureFunction(innermost_function(), function_pos);
8161 if (function.IsNull()) { 8177 if (function.IsNull()) {
8162 // The function will be registered in the lookup table by the 8178 // The function will be registered in the lookup table by the
8163 // EffectGraphVisitor::VisitClosureNode when the newly allocated closure 8179 // EffectGraphVisitor::VisitClosureNode when the newly allocated closure
8164 // function has been properly setup. 8180 // function has been properly setup.
8165 found_func = false; 8181 found_func = false;
8166 function = Function::NewClosureFunction(*function_name, 8182 function = Function::NewClosureFunction(*function_name,
8167 innermost_function(), function_pos); 8183 innermost_function(), function_pos);
8168 function.set_result_type(result_type); 8184 function.set_result_type(result_type);
8185 // The result type may refer to the function's type parameters,
8186 // but was not parsed in the scope of the function. Adjust.
8187 result_type.SetScopeFunction(function);
8169 if (FLAG_enable_mirrors && metadata_pos.IsReal()) { 8188 if (FLAG_enable_mirrors && metadata_pos.IsReal()) {
8170 library_.AddFunctionMetadata(function, metadata_pos); 8189 library_.AddFunctionMetadata(function, metadata_pos);
8171 } 8190 }
8172 } 8191 }
8173 8192
8174 ASSERT(function.parent_function() == innermost_function_.raw()); 8193 ASSERT(function.parent_function() == innermost_function_.raw());
8175 innermost_function_ = function.raw(); 8194 innermost_function_ = function.raw();
8176 8195
8177 if (CurrentToken() == Token::kLT) { 8196 if (CurrentToken() == Token::kLT) {
8178 if (!FLAG_generic_method_syntax) { 8197 if (!FLAG_generic_method_syntax) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
8224 } 8243 }
8225 } 8244 }
8226 8245
8227 Type& signature_type = Type::ZoneHandle(Z); 8246 Type& signature_type = Type::ZoneHandle(Z);
8228 SequenceNode* statements = NULL; 8247 SequenceNode* statements = NULL;
8229 if (!found_func) { 8248 if (!found_func) {
8230 // Parse the local function. As a side effect of the parsing, the 8249 // Parse the local function. As a side effect of the parsing, the
8231 // variables of this function's scope that are referenced by the local 8250 // variables of this function's scope that are referenced by the local
8232 // function (and its inner nested functions) will be marked as captured. 8251 // function (and its inner nested functions) will be marked as captured.
8233 8252
8234 ResolveType(&result_type); // Parameter types are resolved in ParseFunc. 8253 ResolveTypeParameters(&result_type);
8235 function.set_result_type(result_type); 8254 function.set_result_type(result_type); // Update type without scope change.
8255 // Type parameters appearing in parameter types are resolved in ParseFunc.
8236 statements = Parser::ParseFunc(function, !is_literal); 8256 statements = Parser::ParseFunc(function, !is_literal);
8237 INC_STAT(thread(), num_functions_parsed, 1); 8257 INC_STAT(thread(), num_functions_parsed, 1);
8238 8258
8239 // Now that the local function has formal parameters, finalize its signature 8259 // Now that the local function has formal parameters, finalize its signature
8240 signature_type = function.SignatureType(); 8260 signature_type = function.SignatureType();
8241 signature_type ^= CanonicalizeType(signature_type); 8261 signature_type ^= CanonicalizeType(signature_type);
8242 function.SetSignatureType(signature_type); 8262 function.SetSignatureType(signature_type);
8243 } else { 8263 } else {
8244 // The local function was parsed before. The captured variables are 8264 // The local function was parsed before. The captured variables are
8245 // saved in the function's context scope. Iterate over the context scope 8265 // saved in the function's context scope. Iterate over the context scope
(...skipping 4303 matching lines...) Expand 10 before | Expand all | Expand 10 after
12549 let_expr->AddNode(new (Z) LoadLocalNode(op_pos, temp)); 12569 let_expr->AddNode(new (Z) LoadLocalNode(op_pos, temp));
12550 return let_expr; 12570 return let_expr;
12551 } 12571 }
12552 return expr; 12572 return expr;
12553 } 12573 }
12554 12574
12555 12575
12556 // Resolve the type parameters that may appear in the given signature from the 12576 // Resolve the type parameters that may appear in the given signature from the
12557 // signature function and current class. 12577 // signature function and current class.
12558 // Unresolved type classes get resolved later by the class finalizer. 12578 // Unresolved type classes get resolved later by the class finalizer.
12559 void Parser::ResolveSignature(const Function& signature) { 12579 void Parser::ResolveSignatureTypeParameters(const Function& signature) {
12560 const Function& saved_innermost_function = 12580 const Function& saved_innermost_function =
12561 Function::Handle(Z, innermost_function().raw()); 12581 Function::Handle(Z, innermost_function().raw());
12562 innermost_function_ = signature.raw(); 12582 innermost_function_ = signature.raw();
12563 AbstractType& type = AbstractType::Handle(); 12583 AbstractType& type = AbstractType::Handle();
12564 // Resolve upper bounds of function type parameters. 12584 // Resolve upper bounds of function type parameters.
12565 const intptr_t num_type_params = signature.NumTypeParameters(); 12585 const intptr_t num_type_params = signature.NumTypeParameters();
12566 if (num_type_params > 0) { 12586 if (num_type_params > 0) {
12567 TypeParameter& type_param = TypeParameter::Handle(); 12587 TypeParameter& type_param = TypeParameter::Handle();
12568 const TypeArguments& type_params = 12588 const TypeArguments& type_params =
12569 TypeArguments::Handle(signature.type_parameters()); 12589 TypeArguments::Handle(signature.type_parameters());
12570 for (intptr_t i = 0; i < num_type_params; i++) { 12590 for (intptr_t i = 0; i < num_type_params; i++) {
12571 type_param ^= type_params.TypeAt(i); 12591 type_param ^= type_params.TypeAt(i);
12572 type = type_param.bound(); 12592 type = type_param.bound();
12573 ResolveType(&type); 12593 ResolveTypeParameters(&type);
12574 type_param.set_bound(type); 12594 type_param.set_bound(type);
12575 } 12595 }
12576 } 12596 }
12577 // Resolve result type. 12597 // Resolve result type.
12578 type = signature.result_type(); 12598 type = signature.result_type();
12579 ResolveType(&type); 12599 ResolveTypeParameters(&type);
12580 signature.set_result_type(type); 12600 signature.set_result_type(type); // Update type without scope change.
12581 // Resolve formal parameter types. 12601 // Resolve formal parameter types.
12582 const intptr_t num_parameters = signature.NumParameters(); 12602 const intptr_t num_parameters = signature.NumParameters();
12583 for (intptr_t i = 0; i < num_parameters; i++) { 12603 for (intptr_t i = 0; i < num_parameters; i++) {
12584 type = signature.ParameterTypeAt(i); 12604 type = signature.ParameterTypeAt(i);
12585 ResolveType(&type); 12605 ResolveTypeParameters(&type);
12586 signature.SetParameterTypeAt(i, type); 12606 signature.SetParameterTypeAt(i, type);
12587 } 12607 }
12588 innermost_function_ = saved_innermost_function.raw(); 12608 innermost_function_ = saved_innermost_function.raw();
12589 } 12609 }
12590 12610
12591 12611
12592 // Resolve the type parameters that may appear in the given type and in its type 12612 // Resolve the type parameters that may appear in the given type and in its type
12593 // arguments from the current function and current class. 12613 // arguments from the current function and current class.
12594 // Unresolved type classes get resolved later by the class finalizer. 12614 // Unresolved type classes get resolved later by the class finalizer.
12595 void Parser::ResolveType(AbstractType* type) { 12615 void Parser::ResolveTypeParameters(AbstractType* type) {
12596 ASSERT(type != NULL); 12616 ASSERT(type != NULL);
12597 if (type->IsResolved()) { 12617 if (type->IsResolved()) {
12598 // Some types are resolved by definition, such as a TypeParameter. 12618 // Some types are resolved by definition, such as a TypeParameter.
12599 return; 12619 return;
12600 } 12620 }
12601 // Resolve type class. 12621 // Resolve type class.
12602 if (!type->HasResolvedTypeClass()) { 12622 if (!type->HasResolvedTypeClass()) {
12603 const UnresolvedClass& unresolved_class = 12623 const UnresolvedClass& unresolved_class =
12604 UnresolvedClass::Handle(Z, type->unresolved_class()); 12624 UnresolvedClass::Handle(Z, type->unresolved_class());
12605 const String& unresolved_class_name = 12625 const String& unresolved_class_name =
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
12664 // Resolve type arguments, if any. 12684 // Resolve type arguments, if any.
12665 if (type->arguments() != TypeArguments::null()) { 12685 if (type->arguments() != TypeArguments::null()) {
12666 const TypeArguments& arguments = 12686 const TypeArguments& arguments =
12667 TypeArguments::Handle(Z, type->arguments()); 12687 TypeArguments::Handle(Z, type->arguments());
12668 // Already resolved if canonical. 12688 // Already resolved if canonical.
12669 if (!arguments.IsCanonical()) { 12689 if (!arguments.IsCanonical()) {
12670 const intptr_t num_arguments = arguments.Length(); 12690 const intptr_t num_arguments = arguments.Length();
12671 AbstractType& type_argument = AbstractType::Handle(Z); 12691 AbstractType& type_argument = AbstractType::Handle(Z);
12672 for (intptr_t i = 0; i < num_arguments; i++) { 12692 for (intptr_t i = 0; i < num_arguments; i++) {
12673 type_argument = arguments.TypeAt(i); 12693 type_argument = arguments.TypeAt(i);
12674 ResolveType(&type_argument); 12694 ResolveTypeParameters(&type_argument);
12675 arguments.SetTypeAt(i, type_argument); 12695 arguments.SetTypeAt(i, type_argument);
12676 } 12696 }
12677 } 12697 }
12678 } 12698 }
12679 if (type->IsFunctionType()) { 12699 if (type->IsFunctionType()) {
12680 const Function& signature = 12700 const Function& signature =
12681 Function::Handle(Z, Type::Cast(*type).signature()); 12701 Function::Handle(Z, Type::Cast(*type).signature());
12682 Type& signature_type = Type::Handle(Z, signature.SignatureType()); 12702 Type& signature_type = Type::Handle(Z, signature.SignatureType());
12683 if (signature_type.raw() != type->raw()) { 12703 if (signature_type.raw() != type->raw()) {
12684 ResolveType(&signature_type); 12704 ResolveTypeParameters(&signature_type);
12685 } else { 12705 } else {
12686 ResolveSignature(signature); 12706 ResolveSignatureTypeParameters(signature);
12687 } 12707 }
12688 } 12708 }
12689 } 12709 }
12690 12710
12691 12711
12692 RawAbstractType* Parser::CanonicalizeType(const AbstractType& type) { 12712 RawAbstractType* Parser::CanonicalizeType(const AbstractType& type) {
12693 // If the current class is the result of a mixin application, we must 12713 // If the current class is the result of a mixin application, we must
12694 // use the class scope of the class from which the function originates. 12714 // use the class scope of the class from which the function originates.
12695 if (current_class().IsMixinApplication()) { 12715 if (current_class().IsMixinApplication()) {
12696 return ClassFinalizer::FinalizeType( 12716 return ClassFinalizer::FinalizeType(
(...skipping 641 matching lines...) Expand 10 before | Expand all | Expand 10 after
13338 type = Type::DynamicType(); 13358 type = Type::DynamicType();
13339 } 13359 }
13340 // 'type' is the result type of the function type. 13360 // 'type' is the result type of the function type.
13341 type = ParseFunctionType(type, ClassFinalizer::kDoNotResolve); 13361 type = ParseFunctionType(type, ClassFinalizer::kDoNotResolve);
13342 } 13362 }
13343 // At this point, all type parameters have been parsed, resolve the type. 13363 // At this point, all type parameters have been parsed, resolve the type.
13344 if (finalization == ClassFinalizer::kIgnore) { 13364 if (finalization == ClassFinalizer::kIgnore) {
13345 return Type::DynamicType(); 13365 return Type::DynamicType();
13346 } 13366 }
13347 if (finalization >= ClassFinalizer::kResolveTypeParameters) { 13367 if (finalization >= ClassFinalizer::kResolveTypeParameters) {
13348 ResolveType(&type); 13368 ResolveTypeParameters(&type);
13349 if (finalization >= ClassFinalizer::kCanonicalize) { 13369 if (finalization >= ClassFinalizer::kCanonicalize) {
13350 type ^= CanonicalizeType(type); 13370 type ^= CanonicalizeType(type);
13351 } 13371 }
13352 } 13372 }
13353 return type.raw(); 13373 return type.raw();
13354 } 13374 }
13355 13375
13356 13376
13357 // Parses and returns a function type. 13377 // Parses and returns a function type.
13358 // If 'result_type' is not null, parsing of the result type is skipped. 13378 // If 'result_type' is not null, parsing of the result type is skipped.
(...skipping 18 matching lines...) Expand all
13377 if (!IsSymbol(Symbols::Function())) { 13397 if (!IsSymbol(Symbols::Function())) {
13378 ReportError("'Function' expected"); 13398 ReportError("'Function' expected");
13379 } 13399 }
13380 do { 13400 do {
13381 ConsumeToken(); 13401 ConsumeToken();
13382 const Function& signature_function = Function::Handle( 13402 const Function& signature_function = Function::Handle(
13383 Z, Function::NewSignatureFunction(current_class(), innermost_function(), 13403 Z, Function::NewSignatureFunction(current_class(), innermost_function(),
13384 TokenPosition::kNoSource)); 13404 TokenPosition::kNoSource));
13385 innermost_function_ = signature_function.raw(); 13405 innermost_function_ = signature_function.raw();
13386 signature_function.set_result_type(type); 13406 signature_function.set_result_type(type);
13407 // The result type may refer to the signature function's type parameters,
13408 // but was not parsed in the scope of the signature function. Adjust.
13409 type.SetScopeFunction(signature_function);
13387 // Parse optional type parameters. 13410 // Parse optional type parameters.
13388 if (CurrentToken() == Token::kLT) { 13411 if (CurrentToken() == Token::kLT) {
13389 if (!FLAG_generic_method_syntax) { 13412 if (!FLAG_generic_method_syntax) {
13390 ReportError("generic type arguments not supported."); 13413 ReportError("generic type arguments not supported.");
13391 } 13414 }
13392 ParseTypeParameters(false); // Not parameterizing class, but function. 13415 ParseTypeParameters(false); // Not parameterizing class, but function.
13393 } 13416 }
13394 ParamList params; 13417 ParamList params;
13395 // We do not yet allow Function of any arity, so expect parameter list. 13418 // We do not yet allow Function of any arity, so expect parameter list.
13396 CheckToken(Token::kLPAREN, "formal parameter list expected"); 13419 CheckToken(Token::kLPAREN, "formal parameter list expected");
(...skipping 18 matching lines...) Expand all
13415 // Set it in the typedef class before building the signature type. 13438 // Set it in the typedef class before building the signature type.
13416 current_class().set_signature_function(signature_function); 13439 current_class().set_signature_function(signature_function);
13417 } 13440 }
13418 type = signature_function.SignatureType(); 13441 type = signature_function.SignatureType();
13419 } while (IsFunctionTypeSymbol()); 13442 } while (IsFunctionTypeSymbol());
13420 // At this point, all type parameters have been parsed, resolve the type. 13443 // At this point, all type parameters have been parsed, resolve the type.
13421 if (finalization == ClassFinalizer::kIgnore) { 13444 if (finalization == ClassFinalizer::kIgnore) {
13422 return Type::DynamicType(); 13445 return Type::DynamicType();
13423 } 13446 }
13424 if (finalization >= ClassFinalizer::kResolveTypeParameters) { 13447 if (finalization >= ClassFinalizer::kResolveTypeParameters) {
13425 ResolveType(&type); 13448 ResolveTypeParameters(&type);
13426 if (finalization >= ClassFinalizer::kCanonicalize) { 13449 if (finalization >= ClassFinalizer::kCanonicalize) {
13427 type ^= CanonicalizeType(type); 13450 type ^= CanonicalizeType(type);
13428 } 13451 }
13429 } 13452 }
13430 return Type::RawCast(type.raw()); 13453 return Type::RawCast(type.raw());
13431 } 13454 }
13432 13455
13433 13456
13434 // Parses type = [ident "."] ident ["<" type { "," type } ">"], then resolve and 13457 // Parses type = [ident "."] ident ["<" type { "," type } ">"], then resolve and
13435 // finalize it according to the given type finalization mode. 13458 // finalize it according to the given type finalization mode.
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
13531 type_class = UnresolvedClass::New(*prefix, type_name, ident_pos); 13554 type_class = UnresolvedClass::New(*prefix, type_name, ident_pos);
13532 } 13555 }
13533 TypeArguments& type_arguments = 13556 TypeArguments& type_arguments =
13534 TypeArguments::Handle(Z, ParseTypeArguments(finalization)); 13557 TypeArguments::Handle(Z, ParseTypeArguments(finalization));
13535 if (finalization == ClassFinalizer::kIgnore) { 13558 if (finalization == ClassFinalizer::kIgnore) {
13536 return Type::DynamicType(); 13559 return Type::DynamicType();
13537 } 13560 }
13538 AbstractType& type = AbstractType::Handle( 13561 AbstractType& type = AbstractType::Handle(
13539 Z, Type::New(type_class, type_arguments, ident_pos, Heap::kOld)); 13562 Z, Type::New(type_class, type_arguments, ident_pos, Heap::kOld));
13540 if (finalization >= ClassFinalizer::kResolveTypeParameters) { 13563 if (finalization >= ClassFinalizer::kResolveTypeParameters) {
13541 ResolveType(&type); 13564 ResolveTypeParameters(&type);
13542 if (finalization >= ClassFinalizer::kCanonicalize) { 13565 if (finalization >= ClassFinalizer::kCanonicalize) {
13543 type ^= CanonicalizeType(type); 13566 type ^= CanonicalizeType(type);
13544 } 13567 }
13545 } 13568 }
13546 return type.raw(); 13569 return type.raw();
13547 } 13570 }
13548 13571
13549 13572
13550 void Parser::CheckConstructorCallTypeArguments( 13573 void Parser::CheckConstructorCallTypeArguments(
13551 TokenPosition pos, 13574 TokenPosition pos,
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after
14086 params.EraseParameterTypes(); 14109 params.EraseParameterTypes();
14087 14110
14088 closure = Function::NewClosureFunction(closure_name, innermost_function(), 14111 closure = Function::NewClosureFunction(closure_name, innermost_function(),
14089 token_pos); 14112 token_pos);
14090 closure.set_is_generated_body(true); 14113 closure.set_is_generated_body(true);
14091 closure.set_is_debuggable(false); 14114 closure.set_is_debuggable(false);
14092 closure.set_is_visible(false); 14115 closure.set_is_visible(false);
14093 // TODO(regis): Verify that the closure cannot be generic. 14116 // TODO(regis): Verify that the closure cannot be generic.
14094 closure.set_result_type(Object::dynamic_type()); 14117 closure.set_result_type(Object::dynamic_type());
14095 AddFormalParamsToFunction(&params, closure); 14118 AddFormalParamsToFunction(&params, closure);
14096 ResolveSignature(closure); 14119 ResolveSignatureTypeParameters(closure);
14097 14120
14098 // Finalize function type. 14121 // Finalize function type.
14099 Type& signature_type = Type::Handle(Z, closure.SignatureType()); 14122 Type& signature_type = Type::Handle(Z, closure.SignatureType());
14100 signature_type ^= CanonicalizeType(signature_type); 14123 signature_type ^= CanonicalizeType(signature_type);
14101 closure.SetSignatureType(signature_type); 14124 closure.SetSignatureType(signature_type);
14102 // Finalization would be premature when top-level parsing. 14125 // Finalization would be premature when top-level parsing.
14103 ASSERT(!is_top_level_); 14126 ASSERT(!is_top_level_);
14104 return closure.raw(); 14127 return closure.raw();
14105 } 14128 }
14106 14129
(...skipping 1320 matching lines...) Expand 10 before | Expand all | Expand 10 after
15427 TokenPosition* start, 15450 TokenPosition* start,
15428 TokenPosition* end) { 15451 TokenPosition* end) {
15429 UNREACHABLE(); 15452 UNREACHABLE();
15430 return false; 15453 return false;
15431 } 15454 }
15432 15455
15433 15456
15434 } // namespace dart 15457 } // namespace dart
15435 15458
15436 #endif // DART_PRECOMPILED_RUNTIME 15459 #endif // DART_PRECOMPILED_RUNTIME
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698