| OLD | NEW |
| 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 2184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2195 &Object::dynamic_type()); | 2195 &Object::dynamic_type()); |
| 2196 | 2196 |
| 2197 const bool use_function_type_syntax = false; | 2197 const bool use_function_type_syntax = false; |
| 2198 const bool allow_explicit_default_values = false; | 2198 const bool allow_explicit_default_values = false; |
| 2199 const bool evaluate_metadata = false; | 2199 const bool evaluate_metadata = false; |
| 2200 ParseFormalParameterList(use_function_type_syntax, | 2200 ParseFormalParameterList(use_function_type_syntax, |
| 2201 allow_explicit_default_values, evaluate_metadata, | 2201 allow_explicit_default_values, evaluate_metadata, |
| 2202 &func_params); | 2202 &func_params); |
| 2203 | 2203 |
| 2204 signature_function.set_result_type(result_type); | 2204 signature_function.set_result_type(result_type); |
| 2205 // The result type may refer to the signature function's type parameters, |
| 2206 // but was not parsed in the scope of the signature function. Adjust. |
| 2207 result_type.SetScopeFunction(signature_function); |
| 2205 AddFormalParamsToFunction(&func_params, signature_function); | 2208 AddFormalParamsToFunction(&func_params, signature_function); |
| 2206 | 2209 |
| 2207 ASSERT(innermost_function().raw() == signature_function.raw()); | 2210 ASSERT(innermost_function().raw() == signature_function.raw()); |
| 2208 innermost_function_ = signature_function.parent_function(); | 2211 innermost_function_ = signature_function.parent_function(); |
| 2209 | 2212 |
| 2210 Type& signature_type = | 2213 Type& signature_type = |
| 2211 Type::ZoneHandle(Z, signature_function.SignatureType()); | 2214 Type::ZoneHandle(Z, signature_function.SignatureType()); |
| 2212 | 2215 |
| 2213 // A signature type itself cannot be malformed or malbounded, only its | 2216 // A signature type itself cannot be malformed or malbounded, only its |
| 2214 // signature function's result type or parameter types may be. | 2217 // signature function's result type or parameter types may be. |
| (...skipping 1359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3574 FinalizeFormalParameterTypes(¶ms); | 3577 FinalizeFormalParameterTypes(¶ms); |
| 3575 } | 3578 } |
| 3576 | 3579 |
| 3577 // The number of parameters and their type are not yet set in local | 3580 // The number of parameters and their type are not yet set in local |
| 3578 // functions, since they are not 'top-level' parsed. | 3581 // functions, since they are not 'top-level' parsed. |
| 3579 // However, they are already set when the local function is compiled, since | 3582 // However, they are already set when the local function is compiled, since |
| 3580 // the local function was parsed when its parent was compiled. | 3583 // the local function was parsed when its parent was compiled. |
| 3581 if (func.parameter_types() == Object::empty_array().raw()) { | 3584 if (func.parameter_types() == Object::empty_array().raw()) { |
| 3582 AddFormalParamsToFunction(¶ms, func); | 3585 AddFormalParamsToFunction(¶ms, func); |
| 3583 } | 3586 } |
| 3584 ResolveSignature(func); | 3587 ResolveSignatureTypeParameters(func); |
| 3585 if (!is_top_level_) { | 3588 if (!is_top_level_) { |
| 3586 ClassFinalizer::FinalizeSignature(Class::Handle(Z, func.origin()), func); | 3589 ClassFinalizer::FinalizeSignature(Class::Handle(Z, func.origin()), func); |
| 3587 } | 3590 } |
| 3588 SetupDefaultsForOptionalParams(params); | 3591 SetupDefaultsForOptionalParams(params); |
| 3589 ASSERT(AbstractType::Handle(Z, func.result_type()).IsResolved()); | 3592 ASSERT(AbstractType::Handle(Z, func.result_type()).IsResolved()); |
| 3590 | 3593 |
| 3591 // Populate function scope with the formal parameters. | 3594 // Populate function scope with the formal parameters. |
| 3592 AddFormalParamsToScope(¶ms, current_block_->scope); | 3595 AddFormalParamsToScope(¶ms, current_block_->scope); |
| 3593 } | 3596 } |
| 3594 | 3597 |
| (...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4166 if (method->has_abstract && (async_modifier != RawFunction::kNoModifier)) { | 4169 if (method->has_abstract && (async_modifier != RawFunction::kNoModifier)) { |
| 4167 ReportError(modifier_pos, | 4170 ReportError(modifier_pos, |
| 4168 "abstract function '%s' may not be async, async* or sync*", | 4171 "abstract function '%s' may not be async, async* or sync*", |
| 4169 method->name->ToCString()); | 4172 method->name->ToCString()); |
| 4170 } | 4173 } |
| 4171 | 4174 |
| 4172 // Update function object. | 4175 // Update function object. |
| 4173 func.set_name(*method->name); | 4176 func.set_name(*method->name); |
| 4174 func.set_is_abstract(method->has_abstract); | 4177 func.set_is_abstract(method->has_abstract); |
| 4175 func.set_is_native(method->has_native); | 4178 func.set_is_native(method->has_native); |
| 4176 func.set_result_type(*method->type); // May set parent_function in type. | 4179 func.set_result_type(*method->type); |
| 4180 // The result type may refer to func's type parameters, |
| 4181 // but was not parsed in the scope of func. Adjust. |
| 4182 method->type->SetScopeFunction(func); |
| 4183 |
| 4177 func.set_end_token_pos(method_end_pos); | 4184 func.set_end_token_pos(method_end_pos); |
| 4178 func.set_is_redirecting(is_redirecting); | 4185 func.set_is_redirecting(is_redirecting); |
| 4179 func.set_modifier(async_modifier); | 4186 func.set_modifier(async_modifier); |
| 4180 if (library_.is_dart_scheme() && library_.IsPrivate(*method->name)) { | 4187 if (library_.is_dart_scheme() && library_.IsPrivate(*method->name)) { |
| 4181 func.set_is_reflectable(false); | 4188 func.set_is_reflectable(false); |
| 4182 } | 4189 } |
| 4183 if (is_patch_source() && IsPatchAnnotation(method->metadata_pos)) { | 4190 if (is_patch_source() && IsPatchAnnotation(method->metadata_pos)) { |
| 4184 // Currently, we just ignore the patch annotation. If the function | 4191 // Currently, we just ignore the patch annotation. If the function |
| 4185 // name already exists in the patched class, this function will replace | 4192 // name already exists in the patched class, this function will replace |
| 4186 // the one in the patched class. | 4193 // the one in the patched class. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 4199 func.SetRedirectionType(redirection_type); | 4206 func.SetRedirectionType(redirection_type); |
| 4200 if (!redirection_identifier.IsNull()) { | 4207 if (!redirection_identifier.IsNull()) { |
| 4201 func.SetRedirectionIdentifier(redirection_identifier); | 4208 func.SetRedirectionIdentifier(redirection_identifier); |
| 4202 } | 4209 } |
| 4203 } | 4210 } |
| 4204 | 4211 |
| 4205 ASSERT(is_top_level_); | 4212 ASSERT(is_top_level_); |
| 4206 AddFormalParamsToFunction(&method->params, func); | 4213 AddFormalParamsToFunction(&method->params, func); |
| 4207 ASSERT(innermost_function().raw() == func.raw()); | 4214 ASSERT(innermost_function().raw() == func.raw()); |
| 4208 innermost_function_ = Function::null(); | 4215 innermost_function_ = Function::null(); |
| 4209 ResolveSignature(func); | 4216 ResolveSignatureTypeParameters(func); |
| 4210 members->AddFunction(func); | 4217 members->AddFunction(func); |
| 4211 } | 4218 } |
| 4212 | 4219 |
| 4213 void Parser::ParseFieldDefinition(ClassDesc* members, MemberDesc* field) { | 4220 void Parser::ParseFieldDefinition(ClassDesc* members, MemberDesc* field) { |
| 4214 TRACE_PARSER("ParseFieldDefinition"); | 4221 TRACE_PARSER("ParseFieldDefinition"); |
| 4215 // The parser has read the first field name and is now at the token | 4222 // The parser has read the first field name and is now at the token |
| 4216 // after the field name. | 4223 // after the field name. |
| 4217 ASSERT(CurrentToken() == Token::kSEMICOLON || | 4224 ASSERT(CurrentToken() == Token::kSEMICOLON || |
| 4218 CurrentToken() == Token::kCOMMA || CurrentToken() == Token::kASSIGN); | 4225 CurrentToken() == Token::kCOMMA || CurrentToken() == Token::kASSIGN); |
| 4219 ASSERT(field->type != NULL); | 4226 ASSERT(field->type != NULL); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4338 /* is_abstract = */ false, | 4345 /* is_abstract = */ false, |
| 4339 /* is_external = */ false, | 4346 /* is_external = */ false, |
| 4340 /* is_native = */ false, current_class(), | 4347 /* is_native = */ false, current_class(), |
| 4341 field->name_pos); | 4348 field->name_pos); |
| 4342 ParamList params; | 4349 ParamList params; |
| 4343 ASSERT(current_class().raw() == getter.Owner()); | 4350 ASSERT(current_class().raw() == getter.Owner()); |
| 4344 params.AddReceiver(ReceiverType(current_class()), field->name_pos); | 4351 params.AddReceiver(ReceiverType(current_class()), field->name_pos); |
| 4345 getter.set_result_type(*field->type); | 4352 getter.set_result_type(*field->type); |
| 4346 getter.set_is_debuggable(false); | 4353 getter.set_is_debuggable(false); |
| 4347 AddFormalParamsToFunction(¶ms, getter); | 4354 AddFormalParamsToFunction(¶ms, getter); |
| 4348 ResolveSignature(getter); | 4355 ResolveSignatureTypeParameters(getter); |
| 4349 members->AddFunction(getter); | 4356 members->AddFunction(getter); |
| 4350 if (!field->has_final) { | 4357 if (!field->has_final) { |
| 4351 // Build a setter accessor for non-const fields. | 4358 // Build a setter accessor for non-const fields. |
| 4352 String& setter_name = | 4359 String& setter_name = |
| 4353 String::Handle(Z, Field::SetterSymbol(*field->name)); | 4360 String::Handle(Z, Field::SetterSymbol(*field->name)); |
| 4354 setter = Function::New(setter_name, RawFunction::kImplicitSetter, | 4361 setter = Function::New(setter_name, RawFunction::kImplicitSetter, |
| 4355 field->has_static, field->has_final, | 4362 field->has_static, field->has_final, |
| 4356 /* is_abstract = */ false, | 4363 /* is_abstract = */ false, |
| 4357 /* is_external = */ false, | 4364 /* is_external = */ false, |
| 4358 /* is_native = */ false, current_class(), | 4365 /* is_native = */ false, current_class(), |
| 4359 field->name_pos); | 4366 field->name_pos); |
| 4360 ParamList params; | 4367 ParamList params; |
| 4361 ASSERT(current_class().raw() == setter.Owner()); | 4368 ASSERT(current_class().raw() == setter.Owner()); |
| 4362 params.AddReceiver(ReceiverType(current_class()), field->name_pos); | 4369 params.AddReceiver(ReceiverType(current_class()), field->name_pos); |
| 4363 params.AddFinalParameter(TokenPos(), &Symbols::Value(), field->type); | 4370 params.AddFinalParameter(TokenPos(), &Symbols::Value(), field->type); |
| 4364 setter.set_result_type(Object::void_type()); | 4371 setter.set_result_type(Object::void_type()); |
| 4365 setter.set_is_debuggable(false); | 4372 setter.set_is_debuggable(false); |
| 4366 if (library_.is_dart_scheme() && library_.IsPrivate(*field->name)) { | 4373 if (library_.is_dart_scheme() && library_.IsPrivate(*field->name)) { |
| 4367 setter.set_is_reflectable(false); | 4374 setter.set_is_reflectable(false); |
| 4368 } | 4375 } |
| 4369 AddFormalParamsToFunction(¶ms, setter); | 4376 AddFormalParamsToFunction(¶ms, setter); |
| 4370 ResolveSignature(setter); | 4377 ResolveSignatureTypeParameters(setter); |
| 4371 members->AddFunction(setter); | 4378 members->AddFunction(setter); |
| 4372 } | 4379 } |
| 4373 } | 4380 } |
| 4374 | 4381 |
| 4375 if (CurrentToken() != Token::kCOMMA) { | 4382 if (CurrentToken() != Token::kCOMMA) { |
| 4376 break; | 4383 break; |
| 4377 } | 4384 } |
| 4378 ConsumeToken(); | 4385 ConsumeToken(); |
| 4379 field->name_pos = this->TokenPos(); | 4386 field->name_pos = this->TokenPos(); |
| 4380 field->name = ExpectIdentifier("field name expected"); | 4387 field->name = ExpectIdentifier("field name expected"); |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4618 } else { | 4625 } else { |
| 4619 ReportError( | 4626 ReportError( |
| 4620 "missing 'var', 'final', 'const' or type" | 4627 "missing 'var', 'final', 'const' or type" |
| 4621 " in field declaration"); | 4628 " in field declaration"); |
| 4622 } | 4629 } |
| 4623 } else if (member.type->IsVoidType()) { | 4630 } else if (member.type->IsVoidType()) { |
| 4624 ReportError(member.name_pos, "field may not be 'void'"); | 4631 ReportError(member.name_pos, "field may not be 'void'"); |
| 4625 } | 4632 } |
| 4626 if (!member.type->IsResolved()) { | 4633 if (!member.type->IsResolved()) { |
| 4627 AbstractType& type = AbstractType::ZoneHandle(Z, member.type->raw()); | 4634 AbstractType& type = AbstractType::ZoneHandle(Z, member.type->raw()); |
| 4628 ResolveType(&type); | 4635 ResolveTypeParameters(&type); |
| 4629 member.type = &type; | 4636 member.type = &type; |
| 4630 } | 4637 } |
| 4631 ParseFieldDefinition(members, &member); | 4638 ParseFieldDefinition(members, &member); |
| 4632 } else { | 4639 } else { |
| 4633 UnexpectedToken(); | 4640 UnexpectedToken(); |
| 4634 } | 4641 } |
| 4635 current_member_ = NULL; | 4642 current_member_ = NULL; |
| 4636 CheckMemberNameConflict(members, &member); | 4643 CheckMemberNameConflict(members, &member); |
| 4637 members->AddMember(member); | 4644 members->AddMember(member); |
| 4638 } | 4645 } |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4970 /* is_static = */ false, | 4977 /* is_static = */ false, |
| 4971 /* is_const = */ true, | 4978 /* is_const = */ true, |
| 4972 /* is_abstract = */ false, | 4979 /* is_abstract = */ false, |
| 4973 /* is_external = */ false, | 4980 /* is_external = */ false, |
| 4974 /* is_native = */ false, cls, cls.token_pos()); | 4981 /* is_native = */ false, cls, cls.token_pos()); |
| 4975 getter.set_result_type(int_type); | 4982 getter.set_result_type(int_type); |
| 4976 getter.set_is_debuggable(false); | 4983 getter.set_is_debuggable(false); |
| 4977 ParamList params; | 4984 ParamList params; |
| 4978 params.AddReceiver(&Object::dynamic_type(), cls.token_pos()); | 4985 params.AddReceiver(&Object::dynamic_type(), cls.token_pos()); |
| 4979 AddFormalParamsToFunction(¶ms, getter); | 4986 AddFormalParamsToFunction(¶ms, getter); |
| 4980 ResolveSignature(getter); | 4987 ResolveSignatureTypeParameters(getter); |
| 4981 enum_members.AddFunction(getter); | 4988 enum_members.AddFunction(getter); |
| 4982 | 4989 |
| 4983 ASSERT(IsIdentifier()); | 4990 ASSERT(IsIdentifier()); |
| 4984 ASSERT(CurrentLiteral()->raw() == cls.Name()); | 4991 ASSERT(CurrentLiteral()->raw() == cls.Name()); |
| 4985 | 4992 |
| 4986 ConsumeToken(); // Enum type name. | 4993 ConsumeToken(); // Enum type name. |
| 4987 ExpectToken(Token::kLBRACE); | 4994 ExpectToken(Token::kLBRACE); |
| 4988 Field& enum_value = Field::Handle(Z); | 4995 Field& enum_value = Field::Handle(Z); |
| 4989 intptr_t i = 0; | 4996 intptr_t i = 0; |
| 4990 GrowableArray<String*> declared_names(8); | 4997 GrowableArray<String*> declared_names(8); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5098 /* is_static = */ false, | 5105 /* is_static = */ false, |
| 5099 /* is_const = */ true, | 5106 /* is_const = */ true, |
| 5100 /* is_abstract = */ false, | 5107 /* is_abstract = */ false, |
| 5101 /* is_external = */ false, | 5108 /* is_external = */ false, |
| 5102 /* is_native = */ false, cls, cls.token_pos()); | 5109 /* is_native = */ false, cls, cls.token_pos()); |
| 5103 name_getter.set_result_type(string_type); | 5110 name_getter.set_result_type(string_type); |
| 5104 name_getter.set_is_debuggable(false); | 5111 name_getter.set_is_debuggable(false); |
| 5105 ParamList name_params; | 5112 ParamList name_params; |
| 5106 name_params.AddReceiver(&Object::dynamic_type(), cls.token_pos()); | 5113 name_params.AddReceiver(&Object::dynamic_type(), cls.token_pos()); |
| 5107 AddFormalParamsToFunction(&name_params, name_getter); | 5114 AddFormalParamsToFunction(&name_params, name_getter); |
| 5108 ResolveSignature(name_getter); | 5115 ResolveSignatureTypeParameters(name_getter); |
| 5109 enum_members.AddFunction(name_getter); | 5116 enum_members.AddFunction(name_getter); |
| 5110 | 5117 |
| 5111 // Clone the toString() function from the helper class. | 5118 // Clone the toString() function from the helper class. |
| 5112 Function& to_string_func = Function::Handle( | 5119 Function& to_string_func = Function::Handle( |
| 5113 Z, helper_class.LookupDynamicFunctionAllowPrivate(Symbols::toString())); | 5120 Z, helper_class.LookupDynamicFunctionAllowPrivate(Symbols::toString())); |
| 5114 ASSERT(!to_string_func.IsNull()); | 5121 ASSERT(!to_string_func.IsNull()); |
| 5115 to_string_func = to_string_func.Clone(cls); | 5122 to_string_func = to_string_func.Clone(cls); |
| 5116 enum_members.AddFunction(to_string_func); | 5123 enum_members.AddFunction(to_string_func); |
| 5117 | 5124 |
| 5118 // Clone the hashCode getter function from the helper class. | 5125 // Clone the hashCode getter function from the helper class. |
| (...skipping 29 matching lines...) Expand all Loading... |
| 5148 ctor.set_is_reflectable(false); | 5155 ctor.set_is_reflectable(false); |
| 5149 } | 5156 } |
| 5150 | 5157 |
| 5151 ParamList params; | 5158 ParamList params; |
| 5152 // Add implicit 'this' parameter. | 5159 // Add implicit 'this' parameter. |
| 5153 const AbstractType* receiver_type = ReceiverType(cls); | 5160 const AbstractType* receiver_type = ReceiverType(cls); |
| 5154 params.AddReceiver(receiver_type, cls.token_pos()); | 5161 params.AddReceiver(receiver_type, cls.token_pos()); |
| 5155 | 5162 |
| 5156 AddFormalParamsToFunction(¶ms, ctor); | 5163 AddFormalParamsToFunction(¶ms, ctor); |
| 5157 ctor.set_result_type(Object::dynamic_type()); | 5164 ctor.set_result_type(Object::dynamic_type()); |
| 5158 ResolveSignature(ctor); | 5165 ResolveSignatureTypeParameters(ctor); |
| 5159 // The body of the constructor cannot modify the type of the constructed | 5166 // The body of the constructor cannot modify the type of the constructed |
| 5160 // instance, which is passed in as the receiver. | 5167 // instance, which is passed in as the receiver. |
| 5161 ctor.set_result_type(*receiver_type); | 5168 ctor.set_result_type(*receiver_type); |
| 5162 cls.AddFunction(ctor); | 5169 cls.AddFunction(ctor); |
| 5163 } | 5170 } |
| 5164 | 5171 |
| 5165 void Parser::CheckFinalInitializationConflicts(const ClassDesc* class_desc, | 5172 void Parser::CheckFinalInitializationConflicts(const ClassDesc* class_desc, |
| 5166 const MemberDesc* member) { | 5173 const MemberDesc* member) { |
| 5167 const ParamList* params = &member->params; | 5174 const ParamList* params = &member->params; |
| 5168 if (!params->has_field_initializer) { | 5175 if (!params->has_field_initializer) { |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5394 &Object::dynamic_type()); | 5401 &Object::dynamic_type()); |
| 5395 const bool allow_explicit_default_values = false; | 5402 const bool allow_explicit_default_values = false; |
| 5396 const bool evaluate_metadata = false; | 5403 const bool evaluate_metadata = false; |
| 5397 ParseFormalParameterList(use_function_type_syntax, | 5404 ParseFormalParameterList(use_function_type_syntax, |
| 5398 allow_explicit_default_values, evaluate_metadata, | 5405 allow_explicit_default_values, evaluate_metadata, |
| 5399 ¶ms); | 5406 ¶ms); |
| 5400 if (result_type.IsNull()) { | 5407 if (result_type.IsNull()) { |
| 5401 result_type = Type::DynamicType(); | 5408 result_type = Type::DynamicType(); |
| 5402 } | 5409 } |
| 5403 signature_function.set_result_type(result_type); | 5410 signature_function.set_result_type(result_type); |
| 5411 // The result type may refer to the signature function's type parameters, |
| 5412 // but was not parsed in the scope of the signature function. Adjust. |
| 5413 result_type.SetScopeFunction(signature_function); |
| 5404 AddFormalParamsToFunction(¶ms, signature_function); | 5414 AddFormalParamsToFunction(¶ms, signature_function); |
| 5405 ASSERT(innermost_function().raw() == signature_function.raw()); | 5415 ASSERT(innermost_function().raw() == signature_function.raw()); |
| 5406 innermost_function_ = Function::null(); | 5416 innermost_function_ = Function::null(); |
| 5407 } | 5417 } |
| 5408 ExpectSemicolon(); | 5418 ExpectSemicolon(); |
| 5409 ASSERT(innermost_function().IsNull()); | 5419 ASSERT(innermost_function().IsNull()); |
| 5410 ASSERT(function_type_alias.signature_function() == signature_function.raw()); | 5420 ASSERT(function_type_alias.signature_function() == signature_function.raw()); |
| 5411 | 5421 |
| 5412 // At this point, all function type parameters have been parsed and the class | 5422 // At this point, all function type parameters have been parsed and the class |
| 5413 // function_type_alias is recognized as a typedef, so we can resolve all type | 5423 // function_type_alias is recognized as a typedef, so we can resolve all type |
| 5414 // parameters in the signature type defined by the typedef. | 5424 // parameters in the signature type defined by the typedef. |
| 5415 AbstractType& function_type = | 5425 AbstractType& function_type = |
| 5416 Type::Handle(Z, signature_function.SignatureType()); | 5426 Type::Handle(Z, signature_function.SignatureType()); |
| 5417 ASSERT(current_class().raw() == function_type_alias.raw()); | 5427 ASSERT(current_class().raw() == function_type_alias.raw()); |
| 5418 ResolveType(&function_type); | 5428 ResolveTypeParameters(&function_type); |
| 5419 // Resolving does not replace type or signature. | 5429 // Resolving does not replace type or signature. |
| 5420 ASSERT(function_type_alias.signature_function() == | 5430 ASSERT(function_type_alias.signature_function() == |
| 5421 Type::Cast(function_type).signature()); | 5431 Type::Cast(function_type).signature()); |
| 5422 | 5432 |
| 5423 if (FLAG_trace_parser) { | 5433 if (FLAG_trace_parser) { |
| 5424 OS::Print("TopLevel parsing function type alias '%s'\n", | 5434 OS::Print("TopLevel parsing function type alias '%s'\n", |
| 5425 String::Handle(Z, signature_function.Signature()).ToCString()); | 5435 String::Handle(Z, signature_function.Signature()).ToCString()); |
| 5426 } | 5436 } |
| 5427 // The alias should not be marked as finalized yet, since it needs to be | 5437 // The alias should not be marked as finalized yet, since it needs to be |
| 5428 // checked in the class finalizer for illegal self references. | 5438 // checked in the class finalizer for illegal self references. |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5613 if (parameterizing_class) { | 5623 if (parameterizing_class) { |
| 5614 current_class().set_type_parameters(type_parameters); | 5624 current_class().set_type_parameters(type_parameters); |
| 5615 } else { | 5625 } else { |
| 5616 innermost_function().set_type_parameters(type_parameters); | 5626 innermost_function().set_type_parameters(type_parameters); |
| 5617 } | 5627 } |
| 5618 // Resolve type parameters referenced by upper bounds. | 5628 // Resolve type parameters referenced by upper bounds. |
| 5619 const intptr_t num_types = type_parameters.Length(); | 5629 const intptr_t num_types = type_parameters.Length(); |
| 5620 for (intptr_t i = 0; i < num_types; i++) { | 5630 for (intptr_t i = 0; i < num_types; i++) { |
| 5621 type_parameter ^= type_parameters.TypeAt(i); | 5631 type_parameter ^= type_parameters.TypeAt(i); |
| 5622 type_parameter_bound = type_parameter.bound(); | 5632 type_parameter_bound = type_parameter.bound(); |
| 5623 ResolveType(&type_parameter_bound); | 5633 ResolveTypeParameters(&type_parameter_bound); |
| 5624 type_parameter.set_bound(type_parameter_bound); | 5634 type_parameter.set_bound(type_parameter_bound); |
| 5625 } | 5635 } |
| 5626 } | 5636 } |
| 5627 } | 5637 } |
| 5628 | 5638 |
| 5629 RawTypeArguments* Parser::ParseTypeArguments( | 5639 RawTypeArguments* Parser::ParseTypeArguments( |
| 5630 ClassFinalizer::FinalizationKind finalization) { | 5640 ClassFinalizer::FinalizationKind finalization) { |
| 5631 TRACE_PARSER("ParseTypeArguments"); | 5641 TRACE_PARSER("ParseTypeArguments"); |
| 5632 if (CurrentToken() == Token::kLT) { | 5642 if (CurrentToken() == Token::kLT) { |
| 5633 GrowableArray<AbstractType*> types; | 5643 GrowableArray<AbstractType*> types; |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5923 } else if (IsSymbol(Symbols::Native())) { | 5933 } else if (IsSymbol(Symbols::Native())) { |
| 5924 native_name = &ParseNativeDeclaration(); | 5934 native_name = &ParseNativeDeclaration(); |
| 5925 function_end_pos = TokenPos(); | 5935 function_end_pos = TokenPos(); |
| 5926 ExpectSemicolon(); | 5936 ExpectSemicolon(); |
| 5927 is_native = true; | 5937 is_native = true; |
| 5928 func.set_is_native(true); | 5938 func.set_is_native(true); |
| 5929 } else { | 5939 } else { |
| 5930 ReportError("function block expected"); | 5940 ReportError("function block expected"); |
| 5931 } | 5941 } |
| 5932 func.set_result_type(result_type); | 5942 func.set_result_type(result_type); |
| 5943 // The result type may refer to func's type parameters, |
| 5944 // but was not parsed in the scope of func. Adjust. |
| 5945 result_type.SetScopeFunction(func); |
| 5933 func.set_end_token_pos(function_end_pos); | 5946 func.set_end_token_pos(function_end_pos); |
| 5934 func.set_modifier(func_modifier); | 5947 func.set_modifier(func_modifier); |
| 5935 if (library_.is_dart_scheme() && library_.IsPrivate(func_name)) { | 5948 if (library_.is_dart_scheme() && library_.IsPrivate(func_name)) { |
| 5936 func.set_is_reflectable(false); | 5949 func.set_is_reflectable(false); |
| 5937 } | 5950 } |
| 5938 if (is_native) { | 5951 if (is_native) { |
| 5939 func.set_native_name(*native_name); | 5952 func.set_native_name(*native_name); |
| 5940 } | 5953 } |
| 5941 AddFormalParamsToFunction(¶ms, func); | 5954 AddFormalParamsToFunction(¶ms, func); |
| 5942 ASSERT(innermost_function().raw() == func.raw()); | 5955 ASSERT(innermost_function().raw() == func.raw()); |
| 5943 innermost_function_ = Function::null(); | 5956 innermost_function_ = Function::null(); |
| 5944 ResolveSignature(func); | 5957 ResolveSignatureTypeParameters(func); |
| 5945 top_level->AddFunction(func); | 5958 top_level->AddFunction(func); |
| 5946 if (!is_patch) { | 5959 if (!is_patch) { |
| 5947 library_.AddObject(func, func_name); | 5960 library_.AddObject(func, func_name); |
| 5948 } else { | 5961 } else { |
| 5949 // Need to remove the previously added function that is being patched. | 5962 // Need to remove the previously added function that is being patched. |
| 5950 const Class& toplevel_cls = Class::Handle(Z, library_.toplevel_class()); | 5963 const Class& toplevel_cls = Class::Handle(Z, library_.toplevel_class()); |
| 5951 const Function& replaced_func = | 5964 const Function& replaced_func = |
| 5952 Function::Handle(Z, toplevel_cls.LookupStaticFunction(func_name)); | 5965 Function::Handle(Z, toplevel_cls.LookupStaticFunction(func_name)); |
| 5953 ASSERT(!replaced_func.IsNull()); | 5966 ASSERT(!replaced_func.IsNull()); |
| 5954 toplevel_cls.RemoveFunction(replaced_func); | 5967 toplevel_cls.RemoveFunction(replaced_func); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6079 } | 6092 } |
| 6080 Function& func = Function::Handle( | 6093 Function& func = Function::Handle( |
| 6081 Z, Function::New(accessor_name, | 6094 Z, Function::New(accessor_name, |
| 6082 is_getter ? RawFunction::kGetterFunction | 6095 is_getter ? RawFunction::kGetterFunction |
| 6083 : RawFunction::kSetterFunction, | 6096 : RawFunction::kSetterFunction, |
| 6084 is_static, | 6097 is_static, |
| 6085 /* is_const = */ false, | 6098 /* is_const = */ false, |
| 6086 /* is_abstract = */ false, is_external, is_native, owner, | 6099 /* is_abstract = */ false, is_external, is_native, owner, |
| 6087 decl_begin_pos)); | 6100 decl_begin_pos)); |
| 6088 func.set_result_type(result_type); | 6101 func.set_result_type(result_type); |
| 6102 // The result type may refer to func's type parameters, |
| 6103 // but was not parsed in the scope of func. Adjust. |
| 6104 result_type.SetScopeFunction(func); |
| 6089 func.set_end_token_pos(accessor_end_pos); | 6105 func.set_end_token_pos(accessor_end_pos); |
| 6090 func.set_modifier(func_modifier); | 6106 func.set_modifier(func_modifier); |
| 6091 if (is_native) { | 6107 if (is_native) { |
| 6092 func.set_is_debuggable(false); | 6108 func.set_is_debuggable(false); |
| 6093 func.set_native_name(*native_name); | 6109 func.set_native_name(*native_name); |
| 6094 } | 6110 } |
| 6095 if (library_.is_dart_scheme() && library_.IsPrivate(accessor_name)) { | 6111 if (library_.is_dart_scheme() && library_.IsPrivate(accessor_name)) { |
| 6096 func.set_is_reflectable(false); | 6112 func.set_is_reflectable(false); |
| 6097 } | 6113 } |
| 6098 AddFormalParamsToFunction(¶ms, func); | 6114 AddFormalParamsToFunction(¶ms, func); |
| 6099 ResolveSignature(func); | 6115 ResolveSignatureTypeParameters(func); |
| 6100 top_level->AddFunction(func); | 6116 top_level->AddFunction(func); |
| 6101 if (!is_patch) { | 6117 if (!is_patch) { |
| 6102 library_.AddObject(func, accessor_name); | 6118 library_.AddObject(func, accessor_name); |
| 6103 } else { | 6119 } else { |
| 6104 // Need to remove the previously added accessor that is being patched. | 6120 // Need to remove the previously added accessor that is being patched. |
| 6105 const Class& toplevel_cls = Class::Handle( | 6121 const Class& toplevel_cls = Class::Handle( |
| 6106 Z, owner.IsClass() ? Class::Cast(owner).raw() | 6122 Z, owner.IsClass() ? Class::Cast(owner).raw() |
| 6107 : PatchClass::Cast(owner).patched_class()); | 6123 : PatchClass::Cast(owner).patched_class()); |
| 6108 const Function& replaced_func = | 6124 const Function& replaced_func = |
| 6109 Function::Handle(Z, toplevel_cls.LookupFunction(accessor_name)); | 6125 Function::Handle(Z, toplevel_cls.LookupFunction(accessor_name)); |
| (...skipping 813 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6923 body.set_result_type(Object::dynamic_type()); | 6939 body.set_result_type(Object::dynamic_type()); |
| 6924 is_new_closure = true; | 6940 is_new_closure = true; |
| 6925 } | 6941 } |
| 6926 | 6942 |
| 6927 ParamList closure_params; | 6943 ParamList closure_params; |
| 6928 AddSyncGenClosureParameters(&closure_params); | 6944 AddSyncGenClosureParameters(&closure_params); |
| 6929 | 6945 |
| 6930 if (is_new_closure) { | 6946 if (is_new_closure) { |
| 6931 // Add the parameters to the newly created closure. | 6947 // Add the parameters to the newly created closure. |
| 6932 AddFormalParamsToFunction(&closure_params, body); | 6948 AddFormalParamsToFunction(&closure_params, body); |
| 6933 ResolveSignature(body); | 6949 ResolveSignatureTypeParameters(body); |
| 6934 // Finalize function type. | 6950 // Finalize function type. |
| 6935 Type& signature_type = Type::Handle(Z, body.SignatureType()); | 6951 Type& signature_type = Type::Handle(Z, body.SignatureType()); |
| 6936 signature_type ^= CanonicalizeType(signature_type); | 6952 signature_type ^= CanonicalizeType(signature_type); |
| 6937 body.SetSignatureType(signature_type); | 6953 body.SetSignatureType(signature_type); |
| 6938 ASSERT(AbstractType::Handle(Z, body.result_type()).IsResolved()); | 6954 ASSERT(AbstractType::Handle(Z, body.result_type()).IsResolved()); |
| 6939 ASSERT(body.NumParameters() == closure_params.parameters->length()); | 6955 ASSERT(body.NumParameters() == closure_params.parameters->length()); |
| 6940 } | 6956 } |
| 6941 | 6957 |
| 6942 OpenFunctionBlock(body); | 6958 OpenFunctionBlock(body); |
| 6943 AddFormalParamsToScope(&closure_params, current_block_->scope); | 6959 AddFormalParamsToScope(&closure_params, current_block_->scope); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7049 // TODO(regis): Handle generic async function. | 7065 // TODO(regis): Handle generic async function. |
| 7050 closure.set_result_type(Object::dynamic_type()); | 7066 closure.set_result_type(Object::dynamic_type()); |
| 7051 is_new_closure = true; | 7067 is_new_closure = true; |
| 7052 } | 7068 } |
| 7053 // Create the parameter list for the async body closure. | 7069 // Create the parameter list for the async body closure. |
| 7054 ParamList closure_params; | 7070 ParamList closure_params; |
| 7055 AddAsyncClosureParameters(&closure_params); | 7071 AddAsyncClosureParameters(&closure_params); |
| 7056 if (is_new_closure) { | 7072 if (is_new_closure) { |
| 7057 // Add the parameters to the newly created closure. | 7073 // Add the parameters to the newly created closure. |
| 7058 AddFormalParamsToFunction(&closure_params, closure); | 7074 AddFormalParamsToFunction(&closure_params, closure); |
| 7059 ResolveSignature(closure); | 7075 ResolveSignatureTypeParameters(closure); |
| 7060 | 7076 |
| 7061 // Finalize function type. | 7077 // Finalize function type. |
| 7062 Type& signature_type = Type::Handle(Z, closure.SignatureType()); | 7078 Type& signature_type = Type::Handle(Z, closure.SignatureType()); |
| 7063 signature_type ^= CanonicalizeType(signature_type); | 7079 signature_type ^= CanonicalizeType(signature_type); |
| 7064 closure.SetSignatureType(signature_type); | 7080 closure.SetSignatureType(signature_type); |
| 7065 ASSERT(AbstractType::Handle(Z, closure.result_type()).IsResolved()); | 7081 ASSERT(AbstractType::Handle(Z, closure.result_type()).IsResolved()); |
| 7066 ASSERT(closure.NumParameters() == closure_params.parameters->length()); | 7082 ASSERT(closure.NumParameters() == closure_params.parameters->length()); |
| 7067 } | 7083 } |
| 7068 OpenFunctionBlock(closure); | 7084 OpenFunctionBlock(closure); |
| 7069 AddFormalParamsToScope(&closure_params, current_block_->scope); | 7085 AddFormalParamsToScope(&closure_params, current_block_->scope); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7183 closure.set_result_type(Object::dynamic_type()); | 7199 closure.set_result_type(Object::dynamic_type()); |
| 7184 is_new_closure = true; | 7200 is_new_closure = true; |
| 7185 } | 7201 } |
| 7186 | 7202 |
| 7187 ParamList closure_params; | 7203 ParamList closure_params; |
| 7188 AddAsyncGenClosureParameters(&closure_params); | 7204 AddAsyncGenClosureParameters(&closure_params); |
| 7189 | 7205 |
| 7190 if (is_new_closure) { | 7206 if (is_new_closure) { |
| 7191 // Add the parameters to the newly created closure. | 7207 // Add the parameters to the newly created closure. |
| 7192 AddFormalParamsToFunction(&closure_params, closure); | 7208 AddFormalParamsToFunction(&closure_params, closure); |
| 7193 ResolveSignature(closure); | 7209 ResolveSignatureTypeParameters(closure); |
| 7194 | 7210 |
| 7195 // Finalize function type. | 7211 // Finalize function type. |
| 7196 Type& signature_type = Type::Handle(Z, closure.SignatureType()); | 7212 Type& signature_type = Type::Handle(Z, closure.SignatureType()); |
| 7197 signature_type ^= CanonicalizeType(signature_type); | 7213 signature_type ^= CanonicalizeType(signature_type); |
| 7198 closure.SetSignatureType(signature_type); | 7214 closure.SetSignatureType(signature_type); |
| 7199 ASSERT(AbstractType::Handle(Z, closure.result_type()).IsResolved()); | 7215 ASSERT(AbstractType::Handle(Z, closure.result_type()).IsResolved()); |
| 7200 ASSERT(closure.NumParameters() == closure_params.parameters->length()); | 7216 ASSERT(closure.NumParameters() == closure_params.parameters->length()); |
| 7201 } | 7217 } |
| 7202 | 7218 |
| 7203 OpenFunctionBlock(closure); | 7219 OpenFunctionBlock(closure); |
| (...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7614 } | 7630 } |
| 7615 } | 7631 } |
| 7616 | 7632 |
| 7617 void Parser::FinalizeFormalParameterTypes(const ParamList* params) { | 7633 void Parser::FinalizeFormalParameterTypes(const ParamList* params) { |
| 7618 ASSERT((params != NULL) && (params->parameters != NULL)); | 7634 ASSERT((params != NULL) && (params->parameters != NULL)); |
| 7619 const int num_parameters = params->parameters->length(); | 7635 const int num_parameters = params->parameters->length(); |
| 7620 AbstractType& type = AbstractType::Handle(Z); | 7636 AbstractType& type = AbstractType::Handle(Z); |
| 7621 for (int i = 0; i < num_parameters; i++) { | 7637 for (int i = 0; i < num_parameters; i++) { |
| 7622 ParamDesc& param_desc = (*params->parameters)[i]; | 7638 ParamDesc& param_desc = (*params->parameters)[i]; |
| 7623 type = param_desc.type->raw(); | 7639 type = param_desc.type->raw(); |
| 7624 ResolveType(&type); | 7640 ResolveTypeParameters(&type); |
| 7625 type = CanonicalizeType(type); | 7641 type = CanonicalizeType(type); |
| 7626 if (type.raw() != param_desc.type->raw()) { | 7642 if (type.raw() != param_desc.type->raw()) { |
| 7627 param_desc.type = &AbstractType::ZoneHandle(Z, type.raw()); | 7643 param_desc.type = &AbstractType::ZoneHandle(Z, type.raw()); |
| 7628 } | 7644 } |
| 7629 } | 7645 } |
| 7630 } | 7646 } |
| 7631 | 7647 |
| 7632 // Populate the parameter type array and parameter name array of the function | 7648 // Populate the parameter type array and parameter name array of the function |
| 7633 // with the formal parameter types and names. | 7649 // with the formal parameter types and names. |
| 7634 void Parser::AddFormalParamsToFunction(const ParamList* params, | 7650 void Parser::AddFormalParamsToFunction(const ParamList* params, |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7982 // non-closurized version of this same function. | 7998 // non-closurized version of this same function. |
| 7983 function = I->LookupClosureFunction(innermost_function(), function_pos); | 7999 function = I->LookupClosureFunction(innermost_function(), function_pos); |
| 7984 if (function.IsNull()) { | 8000 if (function.IsNull()) { |
| 7985 // The function will be registered in the lookup table by the | 8001 // The function will be registered in the lookup table by the |
| 7986 // EffectGraphVisitor::VisitClosureNode when the newly allocated closure | 8002 // EffectGraphVisitor::VisitClosureNode when the newly allocated closure |
| 7987 // function has been properly setup. | 8003 // function has been properly setup. |
| 7988 found_func = false; | 8004 found_func = false; |
| 7989 function = Function::NewClosureFunction(*function_name, | 8005 function = Function::NewClosureFunction(*function_name, |
| 7990 innermost_function(), function_pos); | 8006 innermost_function(), function_pos); |
| 7991 function.set_result_type(result_type); | 8007 function.set_result_type(result_type); |
| 8008 // The result type may refer to the function's type parameters, |
| 8009 // but was not parsed in the scope of the function. Adjust. |
| 8010 result_type.SetScopeFunction(function); |
| 7992 if (FLAG_enable_mirrors && metadata_pos.IsReal()) { | 8011 if (FLAG_enable_mirrors && metadata_pos.IsReal()) { |
| 7993 library_.AddFunctionMetadata(function, metadata_pos); | 8012 library_.AddFunctionMetadata(function, metadata_pos); |
| 7994 } | 8013 } |
| 7995 } | 8014 } |
| 7996 | 8015 |
| 7997 ASSERT(function.parent_function() == innermost_function_.raw()); | 8016 ASSERT(function.parent_function() == innermost_function_.raw()); |
| 7998 innermost_function_ = function.raw(); | 8017 innermost_function_ = function.raw(); |
| 7999 | 8018 |
| 8000 if (CurrentToken() == Token::kLT) { | 8019 if (CurrentToken() == Token::kLT) { |
| 8001 if (!FLAG_generic_method_syntax) { | 8020 if (!FLAG_generic_method_syntax) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8047 } | 8066 } |
| 8048 } | 8067 } |
| 8049 | 8068 |
| 8050 Type& signature_type = Type::ZoneHandle(Z); | 8069 Type& signature_type = Type::ZoneHandle(Z); |
| 8051 SequenceNode* statements = NULL; | 8070 SequenceNode* statements = NULL; |
| 8052 if (!found_func) { | 8071 if (!found_func) { |
| 8053 // Parse the local function. As a side effect of the parsing, the | 8072 // Parse the local function. As a side effect of the parsing, the |
| 8054 // variables of this function's scope that are referenced by the local | 8073 // variables of this function's scope that are referenced by the local |
| 8055 // function (and its inner nested functions) will be marked as captured. | 8074 // function (and its inner nested functions) will be marked as captured. |
| 8056 | 8075 |
| 8057 ResolveType(&result_type); // Parameter types are resolved in ParseFunc. | 8076 ResolveTypeParameters(&result_type); |
| 8058 function.set_result_type(result_type); | 8077 function.set_result_type(result_type); // Update type without scope change. |
| 8078 // Type parameters appearing in parameter types are resolved in ParseFunc. |
| 8059 statements = Parser::ParseFunc(function, !is_literal); | 8079 statements = Parser::ParseFunc(function, !is_literal); |
| 8060 INC_STAT(thread(), num_functions_parsed, 1); | 8080 INC_STAT(thread(), num_functions_parsed, 1); |
| 8061 | 8081 |
| 8062 // Now that the local function has formal parameters, finalize its signature | 8082 // Now that the local function has formal parameters, finalize its signature |
| 8063 signature_type = function.SignatureType(); | 8083 signature_type = function.SignatureType(); |
| 8064 signature_type ^= CanonicalizeType(signature_type); | 8084 signature_type ^= CanonicalizeType(signature_type); |
| 8065 function.SetSignatureType(signature_type); | 8085 function.SetSignatureType(signature_type); |
| 8066 } else { | 8086 } else { |
| 8067 // The local function was parsed before. The captured variables are | 8087 // The local function was parsed before. The captured variables are |
| 8068 // saved in the function's context scope. Iterate over the context scope | 8088 // saved in the function's context scope. Iterate over the context scope |
| (...skipping 4202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12271 let_expr->AddNode(store); | 12291 let_expr->AddNode(store); |
| 12272 let_expr->AddNode(new (Z) LoadLocalNode(op_pos, temp)); | 12292 let_expr->AddNode(new (Z) LoadLocalNode(op_pos, temp)); |
| 12273 return let_expr; | 12293 return let_expr; |
| 12274 } | 12294 } |
| 12275 return expr; | 12295 return expr; |
| 12276 } | 12296 } |
| 12277 | 12297 |
| 12278 // Resolve the type parameters that may appear in the given signature from the | 12298 // Resolve the type parameters that may appear in the given signature from the |
| 12279 // signature function and current class. | 12299 // signature function and current class. |
| 12280 // Unresolved type classes get resolved later by the class finalizer. | 12300 // Unresolved type classes get resolved later by the class finalizer. |
| 12281 void Parser::ResolveSignature(const Function& signature) { | 12301 void Parser::ResolveSignatureTypeParameters(const Function& signature) { |
| 12282 const Function& saved_innermost_function = | 12302 const Function& saved_innermost_function = |
| 12283 Function::Handle(Z, innermost_function().raw()); | 12303 Function::Handle(Z, innermost_function().raw()); |
| 12284 innermost_function_ = signature.raw(); | 12304 innermost_function_ = signature.raw(); |
| 12285 AbstractType& type = AbstractType::Handle(); | 12305 AbstractType& type = AbstractType::Handle(); |
| 12286 // Resolve upper bounds of function type parameters. | 12306 // Resolve upper bounds of function type parameters. |
| 12287 const intptr_t num_type_params = signature.NumTypeParameters(); | 12307 const intptr_t num_type_params = signature.NumTypeParameters(); |
| 12288 if (num_type_params > 0) { | 12308 if (num_type_params > 0) { |
| 12289 TypeParameter& type_param = TypeParameter::Handle(); | 12309 TypeParameter& type_param = TypeParameter::Handle(); |
| 12290 const TypeArguments& type_params = | 12310 const TypeArguments& type_params = |
| 12291 TypeArguments::Handle(signature.type_parameters()); | 12311 TypeArguments::Handle(signature.type_parameters()); |
| 12292 for (intptr_t i = 0; i < num_type_params; i++) { | 12312 for (intptr_t i = 0; i < num_type_params; i++) { |
| 12293 type_param ^= type_params.TypeAt(i); | 12313 type_param ^= type_params.TypeAt(i); |
| 12294 type = type_param.bound(); | 12314 type = type_param.bound(); |
| 12295 ResolveType(&type); | 12315 ResolveTypeParameters(&type); |
| 12296 type_param.set_bound(type); | 12316 type_param.set_bound(type); |
| 12297 } | 12317 } |
| 12298 } | 12318 } |
| 12299 // Resolve result type. | 12319 // Resolve result type. |
| 12300 type = signature.result_type(); | 12320 type = signature.result_type(); |
| 12301 ResolveType(&type); | 12321 ResolveTypeParameters(&type); |
| 12302 signature.set_result_type(type); | 12322 signature.set_result_type(type); // Update type without scope change. |
| 12303 // Resolve formal parameter types. | 12323 // Resolve formal parameter types. |
| 12304 const intptr_t num_parameters = signature.NumParameters(); | 12324 const intptr_t num_parameters = signature.NumParameters(); |
| 12305 for (intptr_t i = 0; i < num_parameters; i++) { | 12325 for (intptr_t i = 0; i < num_parameters; i++) { |
| 12306 type = signature.ParameterTypeAt(i); | 12326 type = signature.ParameterTypeAt(i); |
| 12307 ResolveType(&type); | 12327 ResolveTypeParameters(&type); |
| 12308 signature.SetParameterTypeAt(i, type); | 12328 signature.SetParameterTypeAt(i, type); |
| 12309 } | 12329 } |
| 12310 innermost_function_ = saved_innermost_function.raw(); | 12330 innermost_function_ = saved_innermost_function.raw(); |
| 12311 } | 12331 } |
| 12312 | 12332 |
| 12313 // Resolve the type parameters that may appear in the given type and in its type | 12333 // Resolve the type parameters that may appear in the given type and in its type |
| 12314 // arguments from the current function and current class. | 12334 // arguments from the current function and current class. |
| 12315 // Unresolved type classes get resolved later by the class finalizer. | 12335 // Unresolved type classes get resolved later by the class finalizer. |
| 12316 void Parser::ResolveType(AbstractType* type) { | 12336 void Parser::ResolveTypeParameters(AbstractType* type) { |
| 12317 ASSERT(type != NULL); | 12337 ASSERT(type != NULL); |
| 12318 if (type->IsResolved()) { | 12338 if (type->IsResolved()) { |
| 12319 // Some types are resolved by definition, such as a TypeParameter. | 12339 // Some types are resolved by definition, such as a TypeParameter. |
| 12320 return; | 12340 return; |
| 12321 } | 12341 } |
| 12322 // Resolve type class. | 12342 // Resolve type class. |
| 12323 if (!type->HasResolvedTypeClass()) { | 12343 if (!type->HasResolvedTypeClass()) { |
| 12324 const UnresolvedClass& unresolved_class = | 12344 const UnresolvedClass& unresolved_class = |
| 12325 UnresolvedClass::Handle(Z, type->unresolved_class()); | 12345 UnresolvedClass::Handle(Z, type->unresolved_class()); |
| 12326 const String& unresolved_class_name = | 12346 const String& unresolved_class_name = |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12385 // Resolve type arguments, if any. | 12405 // Resolve type arguments, if any. |
| 12386 if (type->arguments() != TypeArguments::null()) { | 12406 if (type->arguments() != TypeArguments::null()) { |
| 12387 const TypeArguments& arguments = | 12407 const TypeArguments& arguments = |
| 12388 TypeArguments::Handle(Z, type->arguments()); | 12408 TypeArguments::Handle(Z, type->arguments()); |
| 12389 // Already resolved if canonical. | 12409 // Already resolved if canonical. |
| 12390 if (!arguments.IsCanonical()) { | 12410 if (!arguments.IsCanonical()) { |
| 12391 const intptr_t num_arguments = arguments.Length(); | 12411 const intptr_t num_arguments = arguments.Length(); |
| 12392 AbstractType& type_argument = AbstractType::Handle(Z); | 12412 AbstractType& type_argument = AbstractType::Handle(Z); |
| 12393 for (intptr_t i = 0; i < num_arguments; i++) { | 12413 for (intptr_t i = 0; i < num_arguments; i++) { |
| 12394 type_argument = arguments.TypeAt(i); | 12414 type_argument = arguments.TypeAt(i); |
| 12395 ResolveType(&type_argument); | 12415 ResolveTypeParameters(&type_argument); |
| 12396 arguments.SetTypeAt(i, type_argument); | 12416 arguments.SetTypeAt(i, type_argument); |
| 12397 } | 12417 } |
| 12398 } | 12418 } |
| 12399 } | 12419 } |
| 12400 if (type->IsFunctionType()) { | 12420 if (type->IsFunctionType()) { |
| 12401 const Function& signature = | 12421 const Function& signature = |
| 12402 Function::Handle(Z, Type::Cast(*type).signature()); | 12422 Function::Handle(Z, Type::Cast(*type).signature()); |
| 12403 Type& signature_type = Type::Handle(Z, signature.SignatureType()); | 12423 Type& signature_type = Type::Handle(Z, signature.SignatureType()); |
| 12404 if (signature_type.raw() != type->raw()) { | 12424 if (signature_type.raw() != type->raw()) { |
| 12405 ResolveType(&signature_type); | 12425 ResolveTypeParameters(&signature_type); |
| 12406 } else { | 12426 } else { |
| 12407 ResolveSignature(signature); | 12427 ResolveSignatureTypeParameters(signature); |
| 12408 } | 12428 } |
| 12409 } | 12429 } |
| 12410 } | 12430 } |
| 12411 | 12431 |
| 12412 RawAbstractType* Parser::CanonicalizeType(const AbstractType& type) { | 12432 RawAbstractType* Parser::CanonicalizeType(const AbstractType& type) { |
| 12413 // If the current class is the result of a mixin application, we must | 12433 // If the current class is the result of a mixin application, we must |
| 12414 // use the class scope of the class from which the function originates. | 12434 // use the class scope of the class from which the function originates. |
| 12415 if (current_class().IsMixinApplication()) { | 12435 if (current_class().IsMixinApplication()) { |
| 12416 return ClassFinalizer::FinalizeType( | 12436 return ClassFinalizer::FinalizeType( |
| 12417 Class::Handle(Z, parsed_function()->function().origin()), type); | 12437 Class::Handle(Z, parsed_function()->function().origin()), type); |
| (...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13040 type = Type::DynamicType(); | 13060 type = Type::DynamicType(); |
| 13041 } | 13061 } |
| 13042 // 'type' is the result type of the function type. | 13062 // 'type' is the result type of the function type. |
| 13043 type = ParseFunctionType(type, ClassFinalizer::kDoNotResolve); | 13063 type = ParseFunctionType(type, ClassFinalizer::kDoNotResolve); |
| 13044 } | 13064 } |
| 13045 // At this point, all type parameters have been parsed, resolve the type. | 13065 // At this point, all type parameters have been parsed, resolve the type. |
| 13046 if (finalization == ClassFinalizer::kIgnore) { | 13066 if (finalization == ClassFinalizer::kIgnore) { |
| 13047 return Type::DynamicType(); | 13067 return Type::DynamicType(); |
| 13048 } | 13068 } |
| 13049 if (finalization >= ClassFinalizer::kResolveTypeParameters) { | 13069 if (finalization >= ClassFinalizer::kResolveTypeParameters) { |
| 13050 ResolveType(&type); | 13070 ResolveTypeParameters(&type); |
| 13051 if (finalization >= ClassFinalizer::kCanonicalize) { | 13071 if (finalization >= ClassFinalizer::kCanonicalize) { |
| 13052 type ^= CanonicalizeType(type); | 13072 type ^= CanonicalizeType(type); |
| 13053 } | 13073 } |
| 13054 } | 13074 } |
| 13055 return type.raw(); | 13075 return type.raw(); |
| 13056 } | 13076 } |
| 13057 | 13077 |
| 13058 // Parses and returns a function type. | 13078 // Parses and returns a function type. |
| 13059 // If 'result_type' is not null, parsing of the result type is skipped. | 13079 // If 'result_type' is not null, parsing of the result type is skipped. |
| 13060 RawType* Parser::ParseFunctionType( | 13080 RawType* Parser::ParseFunctionType( |
| (...skipping 17 matching lines...) Expand all Loading... |
| 13078 if (!IsSymbol(Symbols::Function())) { | 13098 if (!IsSymbol(Symbols::Function())) { |
| 13079 ReportError("'Function' expected"); | 13099 ReportError("'Function' expected"); |
| 13080 } | 13100 } |
| 13081 do { | 13101 do { |
| 13082 ConsumeToken(); | 13102 ConsumeToken(); |
| 13083 const Function& signature_function = Function::Handle( | 13103 const Function& signature_function = Function::Handle( |
| 13084 Z, Function::NewSignatureFunction(current_class(), innermost_function(), | 13104 Z, Function::NewSignatureFunction(current_class(), innermost_function(), |
| 13085 TokenPosition::kNoSource)); | 13105 TokenPosition::kNoSource)); |
| 13086 innermost_function_ = signature_function.raw(); | 13106 innermost_function_ = signature_function.raw(); |
| 13087 signature_function.set_result_type(type); | 13107 signature_function.set_result_type(type); |
| 13108 // The result type may refer to the signature function's type parameters, |
| 13109 // but was not parsed in the scope of the signature function. Adjust. |
| 13110 type.SetScopeFunction(signature_function); |
| 13088 // Parse optional type parameters. | 13111 // Parse optional type parameters. |
| 13089 if (CurrentToken() == Token::kLT) { | 13112 if (CurrentToken() == Token::kLT) { |
| 13090 if (!FLAG_generic_method_syntax) { | 13113 if (!FLAG_generic_method_syntax) { |
| 13091 ReportError("generic type arguments not supported."); | 13114 ReportError("generic type arguments not supported."); |
| 13092 } | 13115 } |
| 13093 ParseTypeParameters(false); // Not parameterizing class, but function. | 13116 ParseTypeParameters(false); // Not parameterizing class, but function. |
| 13094 } | 13117 } |
| 13095 ParamList params; | 13118 ParamList params; |
| 13096 // We do not yet allow Function of any arity, so expect parameter list. | 13119 // We do not yet allow Function of any arity, so expect parameter list. |
| 13097 CheckToken(Token::kLPAREN, "formal parameter list expected"); | 13120 CheckToken(Token::kLPAREN, "formal parameter list expected"); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 13116 // Set it in the typedef class before building the signature type. | 13139 // Set it in the typedef class before building the signature type. |
| 13117 current_class().set_signature_function(signature_function); | 13140 current_class().set_signature_function(signature_function); |
| 13118 } | 13141 } |
| 13119 type = signature_function.SignatureType(); | 13142 type = signature_function.SignatureType(); |
| 13120 } while (IsFunctionTypeSymbol()); | 13143 } while (IsFunctionTypeSymbol()); |
| 13121 // At this point, all type parameters have been parsed, resolve the type. | 13144 // At this point, all type parameters have been parsed, resolve the type. |
| 13122 if (finalization == ClassFinalizer::kIgnore) { | 13145 if (finalization == ClassFinalizer::kIgnore) { |
| 13123 return Type::DynamicType(); | 13146 return Type::DynamicType(); |
| 13124 } | 13147 } |
| 13125 if (finalization >= ClassFinalizer::kResolveTypeParameters) { | 13148 if (finalization >= ClassFinalizer::kResolveTypeParameters) { |
| 13126 ResolveType(&type); | 13149 ResolveTypeParameters(&type); |
| 13127 if (finalization >= ClassFinalizer::kCanonicalize) { | 13150 if (finalization >= ClassFinalizer::kCanonicalize) { |
| 13128 type ^= CanonicalizeType(type); | 13151 type ^= CanonicalizeType(type); |
| 13129 } | 13152 } |
| 13130 } | 13153 } |
| 13131 return Type::RawCast(type.raw()); | 13154 return Type::RawCast(type.raw()); |
| 13132 } | 13155 } |
| 13133 | 13156 |
| 13134 // Parses type = [ident "."] ident ["<" type { "," type } ">"], then resolve and | 13157 // Parses type = [ident "."] ident ["<" type { "," type } ">"], then resolve and |
| 13135 // finalize it according to the given type finalization mode. | 13158 // finalize it according to the given type finalization mode. |
| 13136 // Returns type and sets prefix. | 13159 // Returns type and sets prefix. |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13232 type_class = UnresolvedClass::New(*prefix, type_name, ident_pos); | 13255 type_class = UnresolvedClass::New(*prefix, type_name, ident_pos); |
| 13233 } | 13256 } |
| 13234 TypeArguments& type_arguments = | 13257 TypeArguments& type_arguments = |
| 13235 TypeArguments::Handle(Z, ParseTypeArguments(finalization)); | 13258 TypeArguments::Handle(Z, ParseTypeArguments(finalization)); |
| 13236 if (finalization == ClassFinalizer::kIgnore) { | 13259 if (finalization == ClassFinalizer::kIgnore) { |
| 13237 return Type::DynamicType(); | 13260 return Type::DynamicType(); |
| 13238 } | 13261 } |
| 13239 AbstractType& type = AbstractType::Handle( | 13262 AbstractType& type = AbstractType::Handle( |
| 13240 Z, Type::New(type_class, type_arguments, ident_pos, Heap::kOld)); | 13263 Z, Type::New(type_class, type_arguments, ident_pos, Heap::kOld)); |
| 13241 if (finalization >= ClassFinalizer::kResolveTypeParameters) { | 13264 if (finalization >= ClassFinalizer::kResolveTypeParameters) { |
| 13242 ResolveType(&type); | 13265 ResolveTypeParameters(&type); |
| 13243 if (finalization >= ClassFinalizer::kCanonicalize) { | 13266 if (finalization >= ClassFinalizer::kCanonicalize) { |
| 13244 type ^= CanonicalizeType(type); | 13267 type ^= CanonicalizeType(type); |
| 13245 } | 13268 } |
| 13246 } | 13269 } |
| 13247 return type.raw(); | 13270 return type.raw(); |
| 13248 } | 13271 } |
| 13249 | 13272 |
| 13250 void Parser::CheckConstructorCallTypeArguments( | 13273 void Parser::CheckConstructorCallTypeArguments( |
| 13251 TokenPosition pos, | 13274 TokenPosition pos, |
| 13252 const Function& constructor, | 13275 const Function& constructor, |
| (...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13779 params.EraseParameterTypes(); | 13802 params.EraseParameterTypes(); |
| 13780 | 13803 |
| 13781 closure = Function::NewClosureFunction(closure_name, innermost_function(), | 13804 closure = Function::NewClosureFunction(closure_name, innermost_function(), |
| 13782 token_pos); | 13805 token_pos); |
| 13783 closure.set_is_generated_body(true); | 13806 closure.set_is_generated_body(true); |
| 13784 closure.set_is_debuggable(false); | 13807 closure.set_is_debuggable(false); |
| 13785 closure.set_is_visible(false); | 13808 closure.set_is_visible(false); |
| 13786 // TODO(regis): Verify that the closure cannot be generic. | 13809 // TODO(regis): Verify that the closure cannot be generic. |
| 13787 closure.set_result_type(Object::dynamic_type()); | 13810 closure.set_result_type(Object::dynamic_type()); |
| 13788 AddFormalParamsToFunction(¶ms, closure); | 13811 AddFormalParamsToFunction(¶ms, closure); |
| 13789 ResolveSignature(closure); | 13812 ResolveSignatureTypeParameters(closure); |
| 13790 | 13813 |
| 13791 // Finalize function type. | 13814 // Finalize function type. |
| 13792 Type& signature_type = Type::Handle(Z, closure.SignatureType()); | 13815 Type& signature_type = Type::Handle(Z, closure.SignatureType()); |
| 13793 signature_type ^= CanonicalizeType(signature_type); | 13816 signature_type ^= CanonicalizeType(signature_type); |
| 13794 closure.SetSignatureType(signature_type); | 13817 closure.SetSignatureType(signature_type); |
| 13795 // Finalization would be premature when top-level parsing. | 13818 // Finalization would be premature when top-level parsing. |
| 13796 ASSERT(!is_top_level_); | 13819 ASSERT(!is_top_level_); |
| 13797 return closure.raw(); | 13820 return closure.raw(); |
| 13798 } | 13821 } |
| 13799 | 13822 |
| (...skipping 1278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15078 bool Parser::FieldHasFunctionLiteralInitializer(const Field& field, | 15101 bool Parser::FieldHasFunctionLiteralInitializer(const Field& field, |
| 15079 TokenPosition* start, | 15102 TokenPosition* start, |
| 15080 TokenPosition* end) { | 15103 TokenPosition* end) { |
| 15081 UNREACHABLE(); | 15104 UNREACHABLE(); |
| 15082 return false; | 15105 return false; |
| 15083 } | 15106 } |
| 15084 | 15107 |
| 15085 } // namespace dart | 15108 } // namespace dart |
| 15086 | 15109 |
| 15087 #endif // DART_PRECOMPILED_RUNTIME | 15110 #endif // DART_PRECOMPILED_RUNTIME |
| OLD | NEW |