Chromium Code Reviews| 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 3499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3510 FinalizeFormalParameterTypes(¶ms); | 3510 FinalizeFormalParameterTypes(¶ms); |
| 3511 } | 3511 } |
| 3512 | 3512 |
| 3513 // The number of parameters and their type are not yet set in local | 3513 // The number of parameters and their type are not yet set in local |
| 3514 // functions, since they are not 'top-level' parsed. | 3514 // functions, since they are not 'top-level' parsed. |
| 3515 // However, they are already set when the local function is compiled, since | 3515 // However, they are already set when the local function is compiled, since |
| 3516 // the local function was parsed when its parent was compiled. | 3516 // the local function was parsed when its parent was compiled. |
| 3517 if (func.parameter_types() == Object::empty_array().raw()) { | 3517 if (func.parameter_types() == Object::empty_array().raw()) { |
| 3518 AddFormalParamsToFunction(¶ms, func); | 3518 AddFormalParamsToFunction(¶ms, func); |
| 3519 } | 3519 } |
| 3520 ResolveSignature(ClassFinalizer::kResolveTypeParameters, func); | 3520 ResolveSignature(func); |
| 3521 if (!is_top_level_) { | 3521 if (!is_top_level_) { |
| 3522 ClassFinalizer::FinalizeSignature(current_class(), func); | 3522 ClassFinalizer::FinalizeSignature(Class::Handle(Z, func.origin()), func); |
| 3523 } | 3523 } |
| 3524 SetupDefaultsForOptionalParams(params); | 3524 SetupDefaultsForOptionalParams(params); |
| 3525 ASSERT(AbstractType::Handle(Z, func.result_type()).IsResolved()); | 3525 ASSERT(AbstractType::Handle(Z, func.result_type()).IsResolved()); |
| 3526 | 3526 |
| 3527 // Populate function scope with the formal parameters. | 3527 // Populate function scope with the formal parameters. |
| 3528 AddFormalParamsToScope(¶ms, current_block_->scope); | 3528 AddFormalParamsToScope(¶ms, current_block_->scope); |
| 3529 | 3529 |
| 3530 if (I->type_checks() && (FunctionLevel() > 0)) { | 3530 if (I->type_checks() && (FunctionLevel() > 0)) { |
| 3531 // We are parsing, but not compiling, a local function. | 3531 // We are parsing, but not compiling, a local function. |
| 3532 // The instantiator may be required at run time for generic type checks. | 3532 // The instantiator may be required at run time for generic type checks. |
| (...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4118 func.SetRedirectionType(redirection_type); | 4118 func.SetRedirectionType(redirection_type); |
| 4119 if (!redirection_identifier.IsNull()) { | 4119 if (!redirection_identifier.IsNull()) { |
| 4120 func.SetRedirectionIdentifier(redirection_identifier); | 4120 func.SetRedirectionIdentifier(redirection_identifier); |
| 4121 } | 4121 } |
| 4122 } | 4122 } |
| 4123 | 4123 |
| 4124 ASSERT(is_top_level_); | 4124 ASSERT(is_top_level_); |
| 4125 AddFormalParamsToFunction(&method->params, func); | 4125 AddFormalParamsToFunction(&method->params, func); |
| 4126 ASSERT(innermost_function().raw() == func.raw()); | 4126 ASSERT(innermost_function().raw() == func.raw()); |
| 4127 innermost_function_ = Function::null(); | 4127 innermost_function_ = Function::null(); |
| 4128 ResolveSignature(ClassFinalizer::kResolveTypeParameters, func); | 4128 ResolveSignature(func); |
| 4129 members->AddFunction(func); | 4129 members->AddFunction(func); |
| 4130 } | 4130 } |
| 4131 | 4131 |
| 4132 | 4132 |
| 4133 void Parser::ParseFieldDefinition(ClassDesc* members, MemberDesc* field) { | 4133 void Parser::ParseFieldDefinition(ClassDesc* members, MemberDesc* field) { |
| 4134 TRACE_PARSER("ParseFieldDefinition"); | 4134 TRACE_PARSER("ParseFieldDefinition"); |
| 4135 // The parser has read the first field name and is now at the token | 4135 // The parser has read the first field name and is now at the token |
| 4136 // after the field name. | 4136 // after the field name. |
| 4137 ASSERT(CurrentToken() == Token::kSEMICOLON || | 4137 ASSERT(CurrentToken() == Token::kSEMICOLON || |
| 4138 CurrentToken() == Token::kCOMMA || CurrentToken() == Token::kASSIGN); | 4138 CurrentToken() == Token::kCOMMA || CurrentToken() == Token::kASSIGN); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4258 /* is_abstract = */ false, | 4258 /* is_abstract = */ false, |
| 4259 /* is_external = */ false, | 4259 /* is_external = */ false, |
| 4260 /* is_native = */ false, current_class(), | 4260 /* is_native = */ false, current_class(), |
| 4261 field->name_pos); | 4261 field->name_pos); |
| 4262 ParamList params; | 4262 ParamList params; |
| 4263 ASSERT(current_class().raw() == getter.Owner()); | 4263 ASSERT(current_class().raw() == getter.Owner()); |
| 4264 params.AddReceiver(ReceiverType(current_class()), field->name_pos); | 4264 params.AddReceiver(ReceiverType(current_class()), field->name_pos); |
| 4265 getter.set_result_type(*field->type); | 4265 getter.set_result_type(*field->type); |
| 4266 getter.set_is_debuggable(false); | 4266 getter.set_is_debuggable(false); |
| 4267 AddFormalParamsToFunction(¶ms, getter); | 4267 AddFormalParamsToFunction(¶ms, getter); |
| 4268 ResolveSignature(ClassFinalizer::kResolveTypeParameters, getter); | 4268 ResolveSignature(getter); |
| 4269 members->AddFunction(getter); | 4269 members->AddFunction(getter); |
| 4270 if (!field->has_final) { | 4270 if (!field->has_final) { |
| 4271 // Build a setter accessor for non-const fields. | 4271 // Build a setter accessor for non-const fields. |
| 4272 String& setter_name = | 4272 String& setter_name = |
| 4273 String::Handle(Z, Field::SetterSymbol(*field->name)); | 4273 String::Handle(Z, Field::SetterSymbol(*field->name)); |
| 4274 setter = Function::New(setter_name, RawFunction::kImplicitSetter, | 4274 setter = Function::New(setter_name, RawFunction::kImplicitSetter, |
| 4275 field->has_static, field->has_final, | 4275 field->has_static, field->has_final, |
| 4276 /* is_abstract = */ false, | 4276 /* is_abstract = */ false, |
| 4277 /* is_external = */ false, | 4277 /* is_external = */ false, |
| 4278 /* is_native = */ false, current_class(), | 4278 /* is_native = */ false, current_class(), |
| 4279 field->name_pos); | 4279 field->name_pos); |
| 4280 ParamList params; | 4280 ParamList params; |
| 4281 ASSERT(current_class().raw() == setter.Owner()); | 4281 ASSERT(current_class().raw() == setter.Owner()); |
| 4282 params.AddReceiver(ReceiverType(current_class()), field->name_pos); | 4282 params.AddReceiver(ReceiverType(current_class()), field->name_pos); |
| 4283 params.AddFinalParameter(TokenPos(), &Symbols::Value(), field->type); | 4283 params.AddFinalParameter(TokenPos(), &Symbols::Value(), field->type); |
| 4284 setter.set_result_type(Object::void_type()); | 4284 setter.set_result_type(Object::void_type()); |
| 4285 setter.set_is_debuggable(false); | 4285 setter.set_is_debuggable(false); |
| 4286 if (library_.is_dart_scheme() && library_.IsPrivate(*field->name)) { | 4286 if (library_.is_dart_scheme() && library_.IsPrivate(*field->name)) { |
| 4287 setter.set_is_reflectable(false); | 4287 setter.set_is_reflectable(false); |
| 4288 } | 4288 } |
| 4289 AddFormalParamsToFunction(¶ms, setter); | 4289 AddFormalParamsToFunction(¶ms, setter); |
| 4290 ResolveSignature(ClassFinalizer::kResolveTypeParameters, setter); | 4290 ResolveSignature(setter); |
| 4291 members->AddFunction(setter); | 4291 members->AddFunction(setter); |
| 4292 } | 4292 } |
| 4293 } | 4293 } |
| 4294 | 4294 |
| 4295 if (CurrentToken() != Token::kCOMMA) { | 4295 if (CurrentToken() != Token::kCOMMA) { |
| 4296 break; | 4296 break; |
| 4297 } | 4297 } |
| 4298 ConsumeToken(); | 4298 ConsumeToken(); |
| 4299 field->name_pos = this->TokenPos(); | 4299 field->name_pos = this->TokenPos(); |
| 4300 field->name = ExpectIdentifier("field name expected"); | 4300 field->name = ExpectIdentifier("field name expected"); |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4550 } else { | 4550 } else { |
| 4551 ReportError( | 4551 ReportError( |
| 4552 "missing 'var', 'final', 'const' or type" | 4552 "missing 'var', 'final', 'const' or type" |
| 4553 " in field declaration"); | 4553 " in field declaration"); |
| 4554 } | 4554 } |
| 4555 } else if (member.type->IsVoidType()) { | 4555 } else if (member.type->IsVoidType()) { |
| 4556 ReportError(member.name_pos, "field may not be 'void'"); | 4556 ReportError(member.name_pos, "field may not be 'void'"); |
| 4557 } | 4557 } |
| 4558 if (!member.type->IsResolved()) { | 4558 if (!member.type->IsResolved()) { |
| 4559 AbstractType& type = AbstractType::ZoneHandle(Z, member.type->raw()); | 4559 AbstractType& type = AbstractType::ZoneHandle(Z, member.type->raw()); |
| 4560 ResolveType(ClassFinalizer::kResolveTypeParameters, &type); | 4560 ResolveType(&type); |
| 4561 member.type = &type; | 4561 member.type = &type; |
| 4562 } | 4562 } |
| 4563 ParseFieldDefinition(members, &member); | 4563 ParseFieldDefinition(members, &member); |
| 4564 } else { | 4564 } else { |
| 4565 UnexpectedToken(); | 4565 UnexpectedToken(); |
| 4566 } | 4566 } |
| 4567 current_member_ = NULL; | 4567 current_member_ = NULL; |
| 4568 CheckMemberNameConflict(members, &member); | 4568 CheckMemberNameConflict(members, &member); |
| 4569 members->AddMember(member); | 4569 members->AddMember(member); |
| 4570 } | 4570 } |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4869 if (!orig_class.ApplyPatch(cls, &error)) { | 4869 if (!orig_class.ApplyPatch(cls, &error)) { |
| 4870 Report::LongJumpF(error, script_, class_pos, "applying patch failed"); | 4870 Report::LongJumpF(error, script_, class_pos, "applying patch failed"); |
| 4871 } | 4871 } |
| 4872 } | 4872 } |
| 4873 } | 4873 } |
| 4874 | 4874 |
| 4875 | 4875 |
| 4876 void Parser::ParseEnumDefinition(const Class& cls) { | 4876 void Parser::ParseEnumDefinition(const Class& cls) { |
| 4877 TRACE_PARSER("ParseEnumDefinition"); | 4877 TRACE_PARSER("ParseEnumDefinition"); |
| 4878 INC_STAT(thread(), num_classes_parsed, 1); | 4878 INC_STAT(thread(), num_classes_parsed, 1); |
| 4879 | 4879 set_current_class(cls); |
| 4880 const Class& helper_class = | 4880 const Class& helper_class = |
| 4881 Class::Handle(Z, Library::LookupCoreClass(Symbols::_EnumHelper())); | 4881 Class::Handle(Z, Library::LookupCoreClass(Symbols::_EnumHelper())); |
| 4882 ASSERT(!helper_class.IsNull()); | 4882 ASSERT(!helper_class.IsNull()); |
| 4883 | 4883 |
| 4884 SkipMetadata(); | 4884 SkipMetadata(); |
| 4885 ExpectToken(Token::kENUM); | 4885 ExpectToken(Token::kENUM); |
| 4886 | 4886 |
| 4887 const String& enum_name = String::Handle(Z, cls.ScrubbedName()); | 4887 const String& enum_name = String::Handle(Z, cls.ScrubbedName()); |
| 4888 ClassDesc enum_members(Z, cls, enum_name, false, cls.token_pos()); | 4888 ClassDesc enum_members(Z, cls, enum_name, false, cls.token_pos()); |
| 4889 | 4889 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 4906 /* is_static = */ false, | 4906 /* is_static = */ false, |
| 4907 /* is_const = */ true, | 4907 /* is_const = */ true, |
| 4908 /* is_abstract = */ false, | 4908 /* is_abstract = */ false, |
| 4909 /* is_external = */ false, | 4909 /* is_external = */ false, |
| 4910 /* is_native = */ false, cls, cls.token_pos()); | 4910 /* is_native = */ false, cls, cls.token_pos()); |
| 4911 getter.set_result_type(int_type); | 4911 getter.set_result_type(int_type); |
| 4912 getter.set_is_debuggable(false); | 4912 getter.set_is_debuggable(false); |
| 4913 ParamList params; | 4913 ParamList params; |
| 4914 params.AddReceiver(&Object::dynamic_type(), cls.token_pos()); | 4914 params.AddReceiver(&Object::dynamic_type(), cls.token_pos()); |
| 4915 AddFormalParamsToFunction(¶ms, getter); | 4915 AddFormalParamsToFunction(¶ms, getter); |
| 4916 ResolveSignature(ClassFinalizer::kResolveTypeParameters, getter); | 4916 ResolveSignature(getter); |
| 4917 enum_members.AddFunction(getter); | 4917 enum_members.AddFunction(getter); |
| 4918 | 4918 |
| 4919 ASSERT(IsIdentifier()); | 4919 ASSERT(IsIdentifier()); |
| 4920 ASSERT(CurrentLiteral()->raw() == cls.Name()); | 4920 ASSERT(CurrentLiteral()->raw() == cls.Name()); |
| 4921 | 4921 |
| 4922 ConsumeToken(); // Enum type name. | 4922 ConsumeToken(); // Enum type name. |
| 4923 ExpectToken(Token::kLBRACE); | 4923 ExpectToken(Token::kLBRACE); |
| 4924 Field& enum_value = Field::Handle(Z); | 4924 Field& enum_value = Field::Handle(Z); |
| 4925 intptr_t i = 0; | 4925 intptr_t i = 0; |
| 4926 GrowableArray<String*> declared_names(8); | 4926 GrowableArray<String*> declared_names(8); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4979 } | 4979 } |
| 4980 ExpectToken(Token::kRBRACE); | 4980 ExpectToken(Token::kRBRACE); |
| 4981 | 4981 |
| 4982 const Class& array_class = Class::Handle(Z, I->object_store()->array_class()); | 4982 const Class& array_class = Class::Handle(Z, I->object_store()->array_class()); |
| 4983 TypeArguments& values_type_args = | 4983 TypeArguments& values_type_args = |
| 4984 TypeArguments::ZoneHandle(Z, TypeArguments::New(1)); | 4984 TypeArguments::ZoneHandle(Z, TypeArguments::New(1)); |
| 4985 const Type& enum_type = Type::Handle(Type::NewNonParameterizedType(cls)); | 4985 const Type& enum_type = Type::Handle(Type::NewNonParameterizedType(cls)); |
| 4986 values_type_args.SetTypeAt(0, enum_type); | 4986 values_type_args.SetTypeAt(0, enum_type); |
| 4987 Type& values_type = Type::ZoneHandle( | 4987 Type& values_type = Type::ZoneHandle( |
| 4988 Z, Type::New(array_class, values_type_args, cls.token_pos(), Heap::kOld)); | 4988 Z, Type::New(array_class, values_type_args, cls.token_pos(), Heap::kOld)); |
| 4989 values_type ^= ClassFinalizer::FinalizeType(cls, values_type, | 4989 values_type ^= CanonicalizeType(values_type); |
| 4990 ClassFinalizer::kCanonicalize); | |
| 4991 values_type_args = values_type.arguments(); // Get canonical type arguments. | 4990 values_type_args = values_type.arguments(); // Get canonical type arguments. |
| 4992 // Add static field 'const List<E> values'. | 4991 // Add static field 'const List<E> values'. |
| 4993 Field& values_field = Field::ZoneHandle(Z); | 4992 Field& values_field = Field::ZoneHandle(Z); |
| 4994 values_field = Field::New(Symbols::Values(), | 4993 values_field = Field::New(Symbols::Values(), |
| 4995 /* is_static = */ true, | 4994 /* is_static = */ true, |
| 4996 /* is_final = */ true, | 4995 /* is_final = */ true, |
| 4997 /* is_const = */ true, | 4996 /* is_const = */ true, |
| 4998 /* is_reflectable = */ true, cls, values_type, | 4997 /* is_reflectable = */ true, cls, values_type, |
| 4999 cls.token_pos()); | 4998 cls.token_pos()); |
| 5000 enum_members.AddField(values_field); | 4999 enum_members.AddField(values_field); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5035 /* is_static = */ false, | 5034 /* is_static = */ false, |
| 5036 /* is_const = */ true, | 5035 /* is_const = */ true, |
| 5037 /* is_abstract = */ false, | 5036 /* is_abstract = */ false, |
| 5038 /* is_external = */ false, | 5037 /* is_external = */ false, |
| 5039 /* is_native = */ false, cls, cls.token_pos()); | 5038 /* is_native = */ false, cls, cls.token_pos()); |
| 5040 name_getter.set_result_type(string_type); | 5039 name_getter.set_result_type(string_type); |
| 5041 name_getter.set_is_debuggable(false); | 5040 name_getter.set_is_debuggable(false); |
| 5042 ParamList name_params; | 5041 ParamList name_params; |
| 5043 name_params.AddReceiver(&Object::dynamic_type(), cls.token_pos()); | 5042 name_params.AddReceiver(&Object::dynamic_type(), cls.token_pos()); |
| 5044 AddFormalParamsToFunction(&name_params, name_getter); | 5043 AddFormalParamsToFunction(&name_params, name_getter); |
| 5045 ResolveSignature(ClassFinalizer::kResolveTypeParameters, name_getter); | 5044 ResolveSignature(name_getter); |
| 5046 enum_members.AddFunction(name_getter); | 5045 enum_members.AddFunction(name_getter); |
| 5047 | 5046 |
| 5048 // Clone the toString() function from the helper class. | 5047 // Clone the toString() function from the helper class. |
| 5049 Function& to_string_func = Function::Handle( | 5048 Function& to_string_func = Function::Handle( |
| 5050 Z, helper_class.LookupDynamicFunctionAllowPrivate(Symbols::toString())); | 5049 Z, helper_class.LookupDynamicFunctionAllowPrivate(Symbols::toString())); |
| 5051 ASSERT(!to_string_func.IsNull()); | 5050 ASSERT(!to_string_func.IsNull()); |
| 5052 to_string_func = to_string_func.Clone(cls); | 5051 to_string_func = to_string_func.Clone(cls); |
| 5053 enum_members.AddFunction(to_string_func); | 5052 enum_members.AddFunction(to_string_func); |
| 5054 | 5053 |
| 5055 // Clone the hashCode getter function from the helper class. | 5054 // Clone the hashCode getter function from the helper class. |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 5086 ctor.set_is_reflectable(false); | 5085 ctor.set_is_reflectable(false); |
| 5087 } | 5086 } |
| 5088 | 5087 |
| 5089 ParamList params; | 5088 ParamList params; |
| 5090 // Add implicit 'this' parameter. | 5089 // Add implicit 'this' parameter. |
| 5091 const AbstractType* receiver_type = ReceiverType(cls); | 5090 const AbstractType* receiver_type = ReceiverType(cls); |
| 5092 params.AddReceiver(receiver_type, cls.token_pos()); | 5091 params.AddReceiver(receiver_type, cls.token_pos()); |
| 5093 | 5092 |
| 5094 AddFormalParamsToFunction(¶ms, ctor); | 5093 AddFormalParamsToFunction(¶ms, ctor); |
| 5095 ctor.set_result_type(Object::dynamic_type()); | 5094 ctor.set_result_type(Object::dynamic_type()); |
| 5096 ResolveSignature(ClassFinalizer::kResolveTypeParameters, ctor); | 5095 ResolveSignature(ctor); |
| 5097 // The body of the constructor cannot modify the type of the constructed | 5096 // The body of the constructor cannot modify the type of the constructed |
| 5098 // instance, which is passed in as the receiver. | 5097 // instance, which is passed in as the receiver. |
| 5099 ctor.set_result_type(*receiver_type); | 5098 ctor.set_result_type(*receiver_type); |
| 5100 cls.AddFunction(ctor); | 5099 cls.AddFunction(ctor); |
| 5101 } | 5100 } |
| 5102 | 5101 |
| 5103 | 5102 |
| 5104 // Check for cycles in constructor redirection. | 5103 // Check for cycles in constructor redirection. |
| 5105 void Parser::CheckConstructors(ClassDesc* class_desc) { | 5104 void Parser::CheckConstructors(ClassDesc* class_desc) { |
| 5106 // Check for cycles in constructor redirection. | 5105 // Check for cycles in constructor redirection. |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5310 | 5309 |
| 5311 // Set the signature function in the function type alias class. | 5310 // Set the signature function in the function type alias class. |
| 5312 function_type_alias.set_signature_function(signature_function); | 5311 function_type_alias.set_signature_function(signature_function); |
| 5313 | 5312 |
| 5314 // At this point, all function type parameters have been parsed and the class | 5313 // At this point, all function type parameters have been parsed and the class |
| 5315 // function_type_alias is recognized as a typedef, so we can resolve all type | 5314 // function_type_alias is recognized as a typedef, so we can resolve all type |
| 5316 // parameters in the signature type defined by the typedef. | 5315 // parameters in the signature type defined by the typedef. |
| 5317 AbstractType& function_type = | 5316 AbstractType& function_type = |
| 5318 Type::Handle(Z, signature_function.SignatureType()); | 5317 Type::Handle(Z, signature_function.SignatureType()); |
| 5319 ASSERT(current_class().raw() == function_type_alias.raw()); | 5318 ASSERT(current_class().raw() == function_type_alias.raw()); |
| 5320 ResolveType(ClassFinalizer::kResolveTypeParameters, &function_type); | 5319 ResolveType(&function_type); |
| 5321 // Resolving does not replace type or signature. | 5320 // Resolving does not replace type or signature. |
| 5322 ASSERT(function_type_alias.signature_function() == | 5321 ASSERT(function_type_alias.signature_function() == |
| 5323 Type::Cast(function_type).signature()); | 5322 Type::Cast(function_type).signature()); |
| 5324 | 5323 |
| 5325 if (FLAG_trace_parser) { | 5324 if (FLAG_trace_parser) { |
| 5326 OS::Print("TopLevel parsing function type alias '%s'\n", | 5325 OS::Print("TopLevel parsing function type alias '%s'\n", |
| 5327 String::Handle(Z, signature_function.Signature()).ToCString()); | 5326 String::Handle(Z, signature_function.Signature()).ToCString()); |
| 5328 } | 5327 } |
| 5329 // The alias should not be marked as finalized yet, since it needs to be | 5328 // The alias should not be marked as finalized yet, since it needs to be |
| 5330 // checked in the class finalizer for illegal self references. | 5329 // checked in the class finalizer for illegal self references. |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5515 current_class().set_type_parameters(type_parameters); | 5514 current_class().set_type_parameters(type_parameters); |
| 5516 } else { | 5515 } else { |
| 5517 innermost_function().set_type_parameters(type_parameters); | 5516 innermost_function().set_type_parameters(type_parameters); |
| 5518 } | 5517 } |
| 5519 // Try to resolve the upper bounds, which will at least resolve the | 5518 // Try to resolve the upper bounds, which will at least resolve the |
| 5520 // referenced type parameters. | 5519 // referenced type parameters. |
| 5521 const intptr_t num_types = type_parameters.Length(); | 5520 const intptr_t num_types = type_parameters.Length(); |
| 5522 for (intptr_t i = 0; i < num_types; i++) { | 5521 for (intptr_t i = 0; i < num_types; i++) { |
| 5523 type_parameter ^= type_parameters.TypeAt(i); | 5522 type_parameter ^= type_parameters.TypeAt(i); |
| 5524 type_parameter_bound = type_parameter.bound(); | 5523 type_parameter_bound = type_parameter.bound(); |
| 5525 ResolveType(ClassFinalizer::kResolveTypeParameters, | 5524 ResolveType(&type_parameter_bound); |
| 5526 &type_parameter_bound); | |
| 5527 type_parameter.set_bound(type_parameter_bound); | 5525 type_parameter.set_bound(type_parameter_bound); |
| 5528 } | 5526 } |
| 5529 } | 5527 } |
| 5530 } | 5528 } |
| 5531 | 5529 |
| 5532 | 5530 |
| 5533 RawTypeArguments* Parser::ParseTypeArguments( | 5531 RawTypeArguments* Parser::ParseTypeArguments( |
| 5534 ClassFinalizer::FinalizationKind finalization) { | 5532 ClassFinalizer::FinalizationKind finalization) { |
| 5535 TRACE_PARSER("ParseTypeArguments"); | 5533 TRACE_PARSER("ParseTypeArguments"); |
| 5536 if (CurrentToken() == Token::kLT) { | 5534 if (CurrentToken() == Token::kLT) { |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5839 func.set_modifier(func_modifier); | 5837 func.set_modifier(func_modifier); |
| 5840 if (library_.is_dart_scheme() && library_.IsPrivate(func_name)) { | 5838 if (library_.is_dart_scheme() && library_.IsPrivate(func_name)) { |
| 5841 func.set_is_reflectable(false); | 5839 func.set_is_reflectable(false); |
| 5842 } | 5840 } |
| 5843 if (is_native) { | 5841 if (is_native) { |
| 5844 func.set_native_name(*native_name); | 5842 func.set_native_name(*native_name); |
| 5845 } | 5843 } |
| 5846 AddFormalParamsToFunction(¶ms, func); | 5844 AddFormalParamsToFunction(¶ms, func); |
| 5847 ASSERT(innermost_function().raw() == func.raw()); | 5845 ASSERT(innermost_function().raw() == func.raw()); |
| 5848 innermost_function_ = Function::null(); | 5846 innermost_function_ = Function::null(); |
| 5849 ResolveSignature(ClassFinalizer::kResolveTypeParameters, func); | 5847 ResolveSignature(func); |
| 5850 top_level->AddFunction(func); | 5848 top_level->AddFunction(func); |
| 5851 if (!is_patch) { | 5849 if (!is_patch) { |
| 5852 library_.AddObject(func, func_name); | 5850 library_.AddObject(func, func_name); |
| 5853 } else { | 5851 } else { |
| 5854 // Need to remove the previously added function that is being patched. | 5852 // Need to remove the previously added function that is being patched. |
| 5855 const Class& toplevel_cls = Class::Handle(Z, library_.toplevel_class()); | 5853 const Class& toplevel_cls = Class::Handle(Z, library_.toplevel_class()); |
| 5856 const Function& replaced_func = | 5854 const Function& replaced_func = |
| 5857 Function::Handle(Z, toplevel_cls.LookupStaticFunction(func_name)); | 5855 Function::Handle(Z, toplevel_cls.LookupStaticFunction(func_name)); |
| 5858 ASSERT(!replaced_func.IsNull()); | 5856 ASSERT(!replaced_func.IsNull()); |
| 5859 toplevel_cls.RemoveFunction(replaced_func); | 5857 toplevel_cls.RemoveFunction(replaced_func); |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5994 func.set_end_token_pos(accessor_end_pos); | 5992 func.set_end_token_pos(accessor_end_pos); |
| 5995 func.set_modifier(func_modifier); | 5993 func.set_modifier(func_modifier); |
| 5996 if (is_native) { | 5994 if (is_native) { |
| 5997 func.set_is_debuggable(false); | 5995 func.set_is_debuggable(false); |
| 5998 func.set_native_name(*native_name); | 5996 func.set_native_name(*native_name); |
| 5999 } | 5997 } |
| 6000 if (library_.is_dart_scheme() && library_.IsPrivate(accessor_name)) { | 5998 if (library_.is_dart_scheme() && library_.IsPrivate(accessor_name)) { |
| 6001 func.set_is_reflectable(false); | 5999 func.set_is_reflectable(false); |
| 6002 } | 6000 } |
| 6003 AddFormalParamsToFunction(¶ms, func); | 6001 AddFormalParamsToFunction(¶ms, func); |
| 6004 ResolveSignature(ClassFinalizer::kResolveTypeParameters, func); | 6002 ResolveSignature(func); |
| 6005 top_level->AddFunction(func); | 6003 top_level->AddFunction(func); |
| 6006 if (!is_patch) { | 6004 if (!is_patch) { |
| 6007 library_.AddObject(func, accessor_name); | 6005 library_.AddObject(func, accessor_name); |
| 6008 } else { | 6006 } else { |
| 6009 // Need to remove the previously added accessor that is being patched. | 6007 // Need to remove the previously added accessor that is being patched. |
| 6010 const Class& toplevel_cls = Class::Handle( | 6008 const Class& toplevel_cls = Class::Handle( |
| 6011 Z, owner.IsClass() ? Class::Cast(owner).raw() | 6009 Z, owner.IsClass() ? Class::Cast(owner).raw() |
| 6012 : PatchClass::Cast(owner).patched_class()); | 6010 : PatchClass::Cast(owner).patched_class()); |
| 6013 const Function& replaced_func = | 6011 const Function& replaced_func = |
| 6014 Function::Handle(Z, toplevel_cls.LookupFunction(accessor_name)); | 6012 Function::Handle(Z, toplevel_cls.LookupFunction(accessor_name)); |
| (...skipping 830 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6845 body.set_result_type(Object::dynamic_type()); | 6843 body.set_result_type(Object::dynamic_type()); |
| 6846 is_new_closure = true; | 6844 is_new_closure = true; |
| 6847 } | 6845 } |
| 6848 | 6846 |
| 6849 ParamList closure_params; | 6847 ParamList closure_params; |
| 6850 AddSyncGenClosureParameters(&closure_params); | 6848 AddSyncGenClosureParameters(&closure_params); |
| 6851 | 6849 |
| 6852 if (is_new_closure) { | 6850 if (is_new_closure) { |
| 6853 // Add the parameters to the newly created closure. | 6851 // Add the parameters to the newly created closure. |
| 6854 AddFormalParamsToFunction(&closure_params, body); | 6852 AddFormalParamsToFunction(&closure_params, body); |
| 6855 ResolveSignature(ClassFinalizer::kResolveTypeParameters, body); | 6853 ResolveSignature(body); |
| 6856 // Finalize function type. | 6854 // Finalize function type. |
| 6857 Type& signature_type = Type::Handle(Z, body.SignatureType()); | 6855 Type& signature_type = Type::Handle(Z, body.SignatureType()); |
| 6858 signature_type ^= ClassFinalizer::FinalizeType( | 6856 signature_type ^= CanonicalizeType(signature_type); |
| 6859 current_class(), signature_type, ClassFinalizer::kCanonicalize); | |
| 6860 body.SetSignatureType(signature_type); | 6857 body.SetSignatureType(signature_type); |
| 6861 ASSERT(AbstractType::Handle(Z, body.result_type()).IsResolved()); | 6858 ASSERT(AbstractType::Handle(Z, body.result_type()).IsResolved()); |
| 6862 ASSERT(body.NumParameters() == closure_params.parameters->length()); | 6859 ASSERT(body.NumParameters() == closure_params.parameters->length()); |
| 6863 } | 6860 } |
| 6864 | 6861 |
| 6865 OpenFunctionBlock(body); | 6862 OpenFunctionBlock(body); |
| 6866 AddFormalParamsToScope(&closure_params, current_block_->scope); | 6863 AddFormalParamsToScope(&closure_params, current_block_->scope); |
| 6867 async_temp_scope_ = current_block_->scope; | 6864 async_temp_scope_ = current_block_->scope; |
| 6868 return body.raw(); | 6865 return body.raw(); |
| 6869 } | 6866 } |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6973 closure.set_is_generated_body(true); | 6970 closure.set_is_generated_body(true); |
| 6974 closure.set_result_type(Object::dynamic_type()); | 6971 closure.set_result_type(Object::dynamic_type()); |
| 6975 is_new_closure = true; | 6972 is_new_closure = true; |
| 6976 } | 6973 } |
| 6977 // Create the parameter list for the async body closure. | 6974 // Create the parameter list for the async body closure. |
| 6978 ParamList closure_params; | 6975 ParamList closure_params; |
| 6979 AddAsyncClosureParameters(&closure_params); | 6976 AddAsyncClosureParameters(&closure_params); |
| 6980 if (is_new_closure) { | 6977 if (is_new_closure) { |
| 6981 // Add the parameters to the newly created closure. | 6978 // Add the parameters to the newly created closure. |
| 6982 AddFormalParamsToFunction(&closure_params, closure); | 6979 AddFormalParamsToFunction(&closure_params, closure); |
| 6983 ResolveSignature(ClassFinalizer::kResolveTypeParameters, closure); | 6980 ResolveSignature(closure); |
| 6984 | 6981 |
| 6985 // Finalize function type. | 6982 // Finalize function type. |
| 6986 Type& signature_type = Type::Handle(Z, closure.SignatureType()); | 6983 Type& signature_type = Type::Handle(Z, closure.SignatureType()); |
| 6987 signature_type ^= ClassFinalizer::FinalizeType( | 6984 signature_type ^= CanonicalizeType(signature_type); |
| 6988 current_class(), signature_type, ClassFinalizer::kCanonicalize); | |
| 6989 closure.SetSignatureType(signature_type); | 6985 closure.SetSignatureType(signature_type); |
| 6990 ASSERT(AbstractType::Handle(Z, closure.result_type()).IsResolved()); | 6986 ASSERT(AbstractType::Handle(Z, closure.result_type()).IsResolved()); |
| 6991 ASSERT(closure.NumParameters() == closure_params.parameters->length()); | 6987 ASSERT(closure.NumParameters() == closure_params.parameters->length()); |
| 6992 } | 6988 } |
| 6993 OpenFunctionBlock(closure); | 6989 OpenFunctionBlock(closure); |
| 6994 AddFormalParamsToScope(&closure_params, current_block_->scope); | 6990 AddFormalParamsToScope(&closure_params, current_block_->scope); |
| 6995 async_temp_scope_ = current_block_->scope; | 6991 async_temp_scope_ = current_block_->scope; |
| 6996 | 6992 |
| 6997 // Capture instantiator in case it may be needed to generate the type | 6993 // Capture instantiator in case it may be needed to generate the type |
| 6998 // check of the return value. (C.f. handling of Token::kRETURN.) | 6994 // check of the return value. (C.f. handling of Token::kRETURN.) |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7103 closure.set_result_type(Object::dynamic_type()); | 7099 closure.set_result_type(Object::dynamic_type()); |
| 7104 is_new_closure = true; | 7100 is_new_closure = true; |
| 7105 } | 7101 } |
| 7106 | 7102 |
| 7107 ParamList closure_params; | 7103 ParamList closure_params; |
| 7108 AddAsyncGenClosureParameters(&closure_params); | 7104 AddAsyncGenClosureParameters(&closure_params); |
| 7109 | 7105 |
| 7110 if (is_new_closure) { | 7106 if (is_new_closure) { |
| 7111 // Add the parameters to the newly created closure. | 7107 // Add the parameters to the newly created closure. |
| 7112 AddFormalParamsToFunction(&closure_params, closure); | 7108 AddFormalParamsToFunction(&closure_params, closure); |
| 7113 ResolveSignature(ClassFinalizer::kResolveTypeParameters, closure); | 7109 ResolveSignature(closure); |
| 7114 | 7110 |
| 7115 // Finalize function type. | 7111 // Finalize function type. |
| 7116 Type& signature_type = Type::Handle(Z, closure.SignatureType()); | 7112 Type& signature_type = Type::Handle(Z, closure.SignatureType()); |
| 7117 signature_type ^= ClassFinalizer::FinalizeType( | 7113 signature_type ^= CanonicalizeType(signature_type); |
| 7118 current_class(), signature_type, ClassFinalizer::kCanonicalize); | |
| 7119 closure.SetSignatureType(signature_type); | 7114 closure.SetSignatureType(signature_type); |
| 7120 ASSERT(AbstractType::Handle(Z, closure.result_type()).IsResolved()); | 7115 ASSERT(AbstractType::Handle(Z, closure.result_type()).IsResolved()); |
| 7121 ASSERT(closure.NumParameters() == closure_params.parameters->length()); | 7116 ASSERT(closure.NumParameters() == closure_params.parameters->length()); |
| 7122 } | 7117 } |
| 7123 | 7118 |
| 7124 OpenFunctionBlock(closure); | 7119 OpenFunctionBlock(closure); |
| 7125 AddFormalParamsToScope(&closure_params, current_block_->scope); | 7120 AddFormalParamsToScope(&closure_params, current_block_->scope); |
| 7126 async_temp_scope_ = current_block_->scope; | 7121 async_temp_scope_ = current_block_->scope; |
| 7127 return closure.raw(); | 7122 return closure.raw(); |
| 7128 } | 7123 } |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7473 } | 7468 } |
| 7474 | 7469 |
| 7475 | 7470 |
| 7476 void Parser::FinalizeFormalParameterTypes(const ParamList* params) { | 7471 void Parser::FinalizeFormalParameterTypes(const ParamList* params) { |
| 7477 ASSERT((params != NULL) && (params->parameters != NULL)); | 7472 ASSERT((params != NULL) && (params->parameters != NULL)); |
| 7478 const int num_parameters = params->parameters->length(); | 7473 const int num_parameters = params->parameters->length(); |
| 7479 AbstractType& type = AbstractType::Handle(Z); | 7474 AbstractType& type = AbstractType::Handle(Z); |
| 7480 for (int i = 0; i < num_parameters; i++) { | 7475 for (int i = 0; i < num_parameters; i++) { |
| 7481 ParamDesc& param_desc = (*params->parameters)[i]; | 7476 ParamDesc& param_desc = (*params->parameters)[i]; |
| 7482 type = param_desc.type->raw(); | 7477 type = param_desc.type->raw(); |
| 7483 ResolveType(ClassFinalizer::kCanonicalize, &type); | 7478 ResolveType(&type); |
| 7484 type = ClassFinalizer::FinalizeType(current_class(), type, | 7479 type = CanonicalizeType(type); |
| 7485 ClassFinalizer::kCanonicalize); | |
| 7486 if (type.raw() != param_desc.type->raw()) { | 7480 if (type.raw() != param_desc.type->raw()) { |
| 7487 param_desc.type = &AbstractType::ZoneHandle(Z, type.raw()); | 7481 param_desc.type = &AbstractType::ZoneHandle(Z, type.raw()); |
| 7488 } | 7482 } |
| 7489 } | 7483 } |
| 7490 } | 7484 } |
| 7491 | 7485 |
| 7492 | 7486 |
| 7493 // Populate the parameter type array and parameter name array of the function | 7487 // Populate the parameter type array and parameter name array of the function |
| 7494 // with the formal parameter types and names. | 7488 // with the formal parameter types and names. |
| 7495 void Parser::AddFormalParamsToFunction(const ParamList* params, | 7489 void Parser::AddFormalParamsToFunction(const ParamList* params, |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7864 if (!found_func) { | 7858 if (!found_func) { |
| 7865 ParseTypeParameters(false); // Not parameterizing class, but function. | 7859 ParseTypeParameters(false); // Not parameterizing class, but function. |
| 7866 } else { | 7860 } else { |
| 7867 TryParseTypeParameters(); | 7861 TryParseTypeParameters(); |
| 7868 } | 7862 } |
| 7869 } | 7863 } |
| 7870 | 7864 |
| 7871 if (!found_func && !result_type.IsFinalized()) { | 7865 if (!found_func && !result_type.IsFinalized()) { |
| 7872 // Now that type parameters are declared, the result type can be resolved | 7866 // Now that type parameters are declared, the result type can be resolved |
| 7873 // and finalized. | 7867 // and finalized. |
| 7874 ResolveType(ClassFinalizer::kCanonicalize, &result_type); | 7868 ResolveType(&result_type); |
| 7875 result_type = ClassFinalizer::FinalizeType(current_class(), result_type, | 7869 result_type = CanonicalizeType(result_type); |
| 7876 ClassFinalizer::kCanonicalize); | |
| 7877 function.set_result_type(result_type); | 7870 function.set_result_type(result_type); |
| 7878 } | 7871 } |
| 7879 | 7872 |
| 7880 CheckToken(Token::kLPAREN); | 7873 CheckToken(Token::kLPAREN); |
| 7881 | 7874 |
| 7882 // The function type needs to be finalized at compile time, since the closure | 7875 // The function type needs to be finalized at compile time, since the closure |
| 7883 // may be type checked at run time when assigned to a function variable, | 7876 // may be type checked at run time when assigned to a function variable, |
| 7884 // passed as a function argument, or returned as a function result. | 7877 // passed as a function argument, or returned as a function result. |
| 7885 | 7878 |
| 7886 LocalVariable* function_variable = NULL; | 7879 LocalVariable* function_variable = NULL; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7922 // Parse the local function. As a side effect of the parsing, the | 7915 // Parse the local function. As a side effect of the parsing, the |
| 7923 // variables of this function's scope that are referenced by the local | 7916 // variables of this function's scope that are referenced by the local |
| 7924 // function (and its inner nested functions) will be marked as captured. | 7917 // function (and its inner nested functions) will be marked as captured. |
| 7925 | 7918 |
| 7926 ASSERT(AbstractType::Handle(Z, function.result_type()).IsResolved()); | 7919 ASSERT(AbstractType::Handle(Z, function.result_type()).IsResolved()); |
| 7927 statements = Parser::ParseFunc(function, !is_literal); | 7920 statements = Parser::ParseFunc(function, !is_literal); |
| 7928 INC_STAT(thread(), num_functions_parsed, 1); | 7921 INC_STAT(thread(), num_functions_parsed, 1); |
| 7929 | 7922 |
| 7930 // Now that the local function has formal parameters, lookup the signature | 7923 // Now that the local function has formal parameters, lookup the signature |
| 7931 signature_type = function.SignatureType(); | 7924 signature_type = function.SignatureType(); |
| 7932 signature_type ^= ClassFinalizer::FinalizeType( | 7925 signature_type ^= CanonicalizeType(signature_type); |
| 7933 current_class(), signature_type, ClassFinalizer::kCanonicalize); | |
| 7934 function.SetSignatureType(signature_type); | 7926 function.SetSignatureType(signature_type); |
| 7935 } else { | 7927 } else { |
| 7936 // The local function was parsed before. The captured variables are | 7928 // The local function was parsed before. The captured variables are |
| 7937 // saved in the function's context scope. Iterate over the context scope | 7929 // saved in the function's context scope. Iterate over the context scope |
| 7938 // and mark its variables as captured. | 7930 // and mark its variables as captured. |
| 7939 const ContextScope& context_scope = | 7931 const ContextScope& context_scope = |
| 7940 ContextScope::Handle(Z, function.context_scope()); | 7932 ContextScope::Handle(Z, function.context_scope()); |
| 7941 ASSERT(!context_scope.IsNull()); | 7933 ASSERT(!context_scope.IsNull()); |
| 7942 String& var_name = String::Handle(Z); | 7934 String& var_name = String::Handle(Z); |
| 7943 for (int i = 0; i < context_scope.num_variables(); i++) { | 7935 for (int i = 0; i < context_scope.num_variables(); i++) { |
| (...skipping 2789 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 10733 } | 10725 } |
| 10734 // Object receiver. | 10726 // Object receiver. |
| 10735 // If the function is external and dynamic, pass the actual receiver, | 10727 // If the function is external and dynamic, pass the actual receiver, |
| 10736 // otherwise, pass a class literal of the unresolved method's owner. | 10728 // otherwise, pass a class literal of the unresolved method's owner. |
| 10737 if ((func != NULL) && !func->IsNull() && func->is_external() && | 10729 if ((func != NULL) && !func->IsNull() && func->is_external() && |
| 10738 !func->is_static()) { | 10730 !func->is_static()) { |
| 10739 arguments->Add(LoadReceiver(func->token_pos())); | 10731 arguments->Add(LoadReceiver(func->token_pos())); |
| 10740 } else { | 10732 } else { |
| 10741 AbstractType& type = AbstractType::ZoneHandle(Z); | 10733 AbstractType& type = AbstractType::ZoneHandle(Z); |
| 10742 type ^= Type::New(cls, TypeArguments::Handle(Z), call_pos, Heap::kOld); | 10734 type ^= Type::New(cls, TypeArguments::Handle(Z), call_pos, Heap::kOld); |
| 10743 type ^= ClassFinalizer::FinalizeType(current_class(), type, | 10735 type ^= CanonicalizeType(type); |
| 10744 ClassFinalizer::kCanonicalize); | |
| 10745 arguments->Add(new (Z) LiteralNode(call_pos, type)); | 10736 arguments->Add(new (Z) LiteralNode(call_pos, type)); |
| 10746 } | 10737 } |
| 10747 // String memberName. | 10738 // String memberName. |
| 10748 arguments->Add(new (Z) LiteralNode( | 10739 arguments->Add(new (Z) LiteralNode( |
| 10749 call_pos, String::ZoneHandle(Z, Symbols::New(T, function_name)))); | 10740 call_pos, String::ZoneHandle(Z, Symbols::New(T, function_name)))); |
| 10750 // Smi invocation_type. | 10741 // Smi invocation_type. |
| 10751 if (cls.IsTopLevel()) { | 10742 if (cls.IsTopLevel()) { |
| 10752 ASSERT(im_call == InvocationMirror::kStatic || | 10743 ASSERT(im_call == InvocationMirror::kStatic || |
| 10753 im_call == InvocationMirror::kTopLevel); | 10744 im_call == InvocationMirror::kTopLevel); |
| 10754 im_call = InvocationMirror::kTopLevel; | 10745 im_call = InvocationMirror::kTopLevel; |
| (...skipping 946 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 11701 "cannot access type parameter '%s' " | 11692 "cannot access type parameter '%s' " |
| 11702 "from static function", | 11693 "from static function", |
| 11703 name.ToCString()); | 11694 name.ToCString()); |
| 11704 } | 11695 } |
| 11705 // TODO(regis): Verify that CaptureInstantiator() was already called | 11696 // TODO(regis): Verify that CaptureInstantiator() was already called |
| 11706 // and remove call below. | 11697 // and remove call below. |
| 11707 if (FunctionLevel() > 0) { | 11698 if (FunctionLevel() > 0) { |
| 11708 // Make sure that the class instantiator is captured. | 11699 // Make sure that the class instantiator is captured. |
| 11709 CaptureInstantiator(); | 11700 CaptureInstantiator(); |
| 11710 } | 11701 } |
| 11711 type_parameter ^= ClassFinalizer::FinalizeType( | 11702 type_parameter ^= CanonicalizeType(type_parameter); |
| 11712 current_class(), type_parameter, ClassFinalizer::kCanonicalize); | |
| 11713 ASSERT(!type_parameter.IsMalformed()); | 11703 ASSERT(!type_parameter.IsMalformed()); |
| 11714 return new (Z) TypeNode(primary_pos, type_parameter); | 11704 return new (Z) TypeNode(primary_pos, type_parameter); |
| 11715 } else { | 11705 } else { |
| 11716 ASSERT(type_parameter.IsFunctionTypeParameter()); | 11706 ASSERT(type_parameter.IsFunctionTypeParameter()); |
| 11717 // TODO(regis): Verify that CaptureFunctionInstantiator() was already | 11707 // TODO(regis): Verify that CaptureFunctionInstantiator() was already |
| 11718 // called if necessary. | 11708 // called if necessary. |
| 11719 // TODO(regis): Finalize type parameter and return as type node. | 11709 // TODO(regis): Finalize type parameter and return as type node. |
| 11720 // For now, map to dynamic type. | 11710 // For now, map to dynamic type. |
| 11721 Type& type = Type::ZoneHandle(Z, Type::DynamicType()); | 11711 Type& type = Type::ZoneHandle(Z, Type::DynamicType()); |
| 11722 return new (Z) TypeNode(primary_pos, type); | 11712 return new (Z) TypeNode(primary_pos, type); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 11821 if (left->IsPrimaryNode()) { | 11811 if (left->IsPrimaryNode()) { |
| 11822 PrimaryNode* primary_node = left->AsPrimaryNode(); | 11812 PrimaryNode* primary_node = left->AsPrimaryNode(); |
| 11823 const TokenPosition primary_pos = primary_node->token_pos(); | 11813 const TokenPosition primary_pos = primary_node->token_pos(); |
| 11824 if (primary_node->primary().IsFunction()) { | 11814 if (primary_node->primary().IsFunction()) { |
| 11825 array = LoadClosure(primary_node); | 11815 array = LoadClosure(primary_node); |
| 11826 } else if (primary_node->primary().IsClass()) { | 11816 } else if (primary_node->primary().IsClass()) { |
| 11827 const Class& type_class = Class::Cast(primary_node->primary()); | 11817 const Class& type_class = Class::Cast(primary_node->primary()); |
| 11828 AbstractType& type = Type::ZoneHandle( | 11818 AbstractType& type = Type::ZoneHandle( |
| 11829 Z, Type::New(type_class, TypeArguments::Handle(Z), primary_pos, | 11819 Z, Type::New(type_class, TypeArguments::Handle(Z), primary_pos, |
| 11830 Heap::kOld)); | 11820 Heap::kOld)); |
| 11831 type ^= ClassFinalizer::FinalizeType(current_class(), type, | 11821 type ^= CanonicalizeType(type); |
| 11832 ClassFinalizer::kCanonicalize); | |
| 11833 // Type may be malbounded, but not malformed. | 11822 // Type may be malbounded, but not malformed. |
| 11834 ASSERT(!type.IsMalformed()); | 11823 ASSERT(!type.IsMalformed()); |
| 11835 array = new (Z) TypeNode(primary_pos, type); | 11824 array = new (Z) TypeNode(primary_pos, type); |
| 11836 } else if (primary_node->primary().IsTypeParameter()) { | 11825 } else if (primary_node->primary().IsTypeParameter()) { |
| 11837 array = LoadTypeParameter(primary_node); | 11826 array = LoadTypeParameter(primary_node); |
| 11838 } else { | 11827 } else { |
| 11839 UNREACHABLE(); // Internal parser error. | 11828 UNREACHABLE(); // Internal parser error. |
| 11840 } | 11829 } |
| 11841 } | 11830 } |
| 11842 selector = new (Z) | 11831 selector = new (Z) |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 11916 // TODO(regis): Should we throw a type error instead? | 11905 // TODO(regis): Should we throw a type error instead? |
| 11917 ReportError(primary_pos, | 11906 ReportError(primary_pos, |
| 11918 "illegal use of function type parameter '%s'", | 11907 "illegal use of function type parameter '%s'", |
| 11919 name.ToCString()); | 11908 name.ToCString()); |
| 11920 } | 11909 } |
| 11921 } else if (primary_node->primary().IsClass()) { | 11910 } else if (primary_node->primary().IsClass()) { |
| 11922 const Class& type_class = Class::Cast(primary_node->primary()); | 11911 const Class& type_class = Class::Cast(primary_node->primary()); |
| 11923 AbstractType& type = Type::ZoneHandle( | 11912 AbstractType& type = Type::ZoneHandle( |
| 11924 Z, Type::New(type_class, TypeArguments::Handle(Z), primary_pos, | 11913 Z, Type::New(type_class, TypeArguments::Handle(Z), primary_pos, |
| 11925 Heap::kOld)); | 11914 Heap::kOld)); |
| 11926 type ^= ClassFinalizer::FinalizeType(current_class(), type, | 11915 type ^= CanonicalizeType(type); |
| 11927 ClassFinalizer::kCanonicalize); | |
| 11928 // Type may be malbounded, but not malformed. | 11916 // Type may be malbounded, but not malformed. |
| 11929 ASSERT(!type.IsMalformed()); | 11917 ASSERT(!type.IsMalformed()); |
| 11930 selector = new (Z) TypeNode(primary_pos, type); | 11918 selector = new (Z) TypeNode(primary_pos, type); |
| 11931 } else { | 11919 } else { |
| 11932 UNREACHABLE(); // Internal parser error. | 11920 UNREACHABLE(); // Internal parser error. |
| 11933 } | 11921 } |
| 11934 } else { | 11922 } else { |
| 11935 // Left is not a primary node; this must be a closure call. | 11923 // Left is not a primary node; this must be a closure call. |
| 11936 AstNode* closure = left; | 11924 AstNode* closure = left; |
| 11937 selector = ParseClosureCall(closure); | 11925 selector = ParseClosureCall(closure); |
| 11938 } | 11926 } |
| 11939 } else { | 11927 } else { |
| 11940 // No (more) selectors to parse. | 11928 // No (more) selectors to parse. |
| 11941 left = LoadFieldIfUnresolved(left); | 11929 left = LoadFieldIfUnresolved(left); |
| 11942 if (left->IsPrimaryNode()) { | 11930 if (left->IsPrimaryNode()) { |
| 11943 PrimaryNode* primary_node = left->AsPrimaryNode(); | 11931 PrimaryNode* primary_node = left->AsPrimaryNode(); |
| 11944 const TokenPosition primary_pos = primary->token_pos(); | 11932 const TokenPosition primary_pos = primary->token_pos(); |
| 11945 if (primary_node->primary().IsFunction()) { | 11933 if (primary_node->primary().IsFunction()) { |
| 11946 // Treat as implicit closure. | 11934 // Treat as implicit closure. |
| 11947 left = LoadClosure(primary_node); | 11935 left = LoadClosure(primary_node); |
| 11948 } else if (primary_node->primary().IsClass()) { | 11936 } else if (primary_node->primary().IsClass()) { |
| 11949 const Class& type_class = Class::Cast(primary_node->primary()); | 11937 const Class& type_class = Class::Cast(primary_node->primary()); |
| 11950 AbstractType& type = Type::ZoneHandle( | 11938 AbstractType& type = Type::ZoneHandle( |
| 11951 Z, Type::New(type_class, TypeArguments::Handle(Z), primary_pos, | 11939 Z, Type::New(type_class, TypeArguments::Handle(Z), primary_pos, |
| 11952 Heap::kOld)); | 11940 Heap::kOld)); |
| 11953 type = ClassFinalizer::FinalizeType(current_class(), type, | 11941 type = CanonicalizeType(type); |
| 11954 ClassFinalizer::kCanonicalize); | |
| 11955 // Type may be malbounded, but not malformed. | 11942 // Type may be malbounded, but not malformed. |
| 11956 ASSERT(!type.IsMalformed()); | 11943 ASSERT(!type.IsMalformed()); |
| 11957 left = new (Z) TypeNode(primary_pos, type); | 11944 left = new (Z) TypeNode(primary_pos, type); |
| 11958 } else if (primary_node->primary().IsTypeParameter()) { | 11945 } else if (primary_node->primary().IsTypeParameter()) { |
| 11959 left = LoadTypeParameter(primary_node); | 11946 left = LoadTypeParameter(primary_node); |
| 11960 } else if (primary_node->IsSuper()) { | 11947 } else if (primary_node->IsSuper()) { |
| 11961 // Return "super" to handle unary super operator calls, | 11948 // Return "super" to handle unary super operator calls, |
| 11962 // or to report illegal use of "super" otherwise. | 11949 // or to report illegal use of "super" otherwise. |
| 11963 left = primary_node; | 11950 left = primary_node; |
| 11964 } else { | 11951 } else { |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 12164 // The result is a pair of the (side effects of the) store followed by | 12151 // The result is a pair of the (side effects of the) store followed by |
| 12165 // the (value of the) initial value temp variable load. | 12152 // the (value of the) initial value temp variable load. |
| 12166 let_expr->AddNode(store); | 12153 let_expr->AddNode(store); |
| 12167 let_expr->AddNode(new (Z) LoadLocalNode(op_pos, temp)); | 12154 let_expr->AddNode(new (Z) LoadLocalNode(op_pos, temp)); |
| 12168 return let_expr; | 12155 return let_expr; |
| 12169 } | 12156 } |
| 12170 return expr; | 12157 return expr; |
| 12171 } | 12158 } |
| 12172 | 12159 |
| 12173 | 12160 |
| 12174 // Resolve the types of the given signature from the current class according to | 12161 // Resolve the type parameters that may appear in the given signature from the |
| 12175 // the given type finalization mode. | 12162 // signature function and current class. |
| 12176 // Not all involved type classes may get resolved yet, but at least type | 12163 // Unresolved type classes get resolved later by the class finalizer. |
| 12177 // parameters will get resolved, thereby relieving the class | 12164 void Parser::ResolveSignature(const Function& signature) { |
| 12178 // finalizer from resolving type parameters out of context. | |
| 12179 // TODO(regis): Refactor this code which is partially duplicated in the class | |
| 12180 // finalizer, paying attention to type parameter resolution and mixin library. | |
| 12181 void Parser::ResolveSignature(ClassFinalizer::FinalizationKind finalization, | |
| 12182 const Function& signature) { | |
| 12183 const Function& saved_innermost_function = | 12165 const Function& saved_innermost_function = |
| 12184 Function::Handle(Z, innermost_function().raw()); | 12166 Function::Handle(Z, innermost_function().raw()); |
| 12185 innermost_function_ = signature.raw(); | 12167 innermost_function_ = signature.raw(); |
| 12186 // TODO(regis): Resolve upper bounds of function type parameters. | 12168 // TODO(regis): Resolve upper bounds of function type parameters. |
| 12187 AbstractType& type = AbstractType::Handle(signature.result_type()); | 12169 AbstractType& type = AbstractType::Handle(signature.result_type()); |
| 12188 ResolveType(finalization, &type); | 12170 ResolveType(&type); |
| 12189 signature.set_result_type(type); | 12171 signature.set_result_type(type); |
| 12190 const intptr_t num_parameters = signature.NumParameters(); | 12172 const intptr_t num_parameters = signature.NumParameters(); |
| 12191 for (intptr_t i = 0; i < num_parameters; i++) { | 12173 for (intptr_t i = 0; i < num_parameters; i++) { |
| 12192 type = signature.ParameterTypeAt(i); | 12174 type = signature.ParameterTypeAt(i); |
| 12193 ResolveType(finalization, &type); | 12175 ResolveType(&type); |
| 12194 signature.SetParameterTypeAt(i, type); | 12176 signature.SetParameterTypeAt(i, type); |
| 12195 } | 12177 } |
| 12196 innermost_function_ = saved_innermost_function.raw(); | 12178 innermost_function_ = saved_innermost_function.raw(); |
| 12197 } | 12179 } |
| 12198 | 12180 |
| 12199 | 12181 |
| 12200 // Resolve the given type and its type arguments from the current function and | 12182 // Resolve the type parameters that may appear in the given type and in its type |
| 12201 // current class according to the given type finalization mode. | 12183 // arguments from the current function and current class. |
| 12202 // Not all involved type classes may get resolved yet, but at least type | 12184 // Unresolved type classes get resolved later by the class finalizer. |
| 12203 // parameters will get resolved, thereby relieving the class | 12185 void Parser::ResolveType(AbstractType* type) { |
| 12204 // finalizer from resolving type parameters out of context. | |
| 12205 // TODO(regis): Refactor this code which is partially duplicated in the class | |
| 12206 // finalizer, paying attention to type parameter resolution and mixin library. | |
| 12207 void Parser::ResolveType(ClassFinalizer::FinalizationKind finalization, | |
| 12208 AbstractType* type) { | |
| 12209 ASSERT(finalization >= ClassFinalizer::kResolveTypeParameters); | |
| 12210 ASSERT(type != NULL); | 12186 ASSERT(type != NULL); |
| 12211 if (type->IsResolved()) { | 12187 if (type->IsResolved()) { |
| 12188 // Some types are resolved by definition, such as a TypeParameter. | |
| 12212 return; | 12189 return; |
| 12213 } | 12190 } |
| 12214 // Resolve class. | 12191 // Resolve type class. |
| 12215 if (!type->HasResolvedTypeClass()) { | 12192 if (!type->HasResolvedTypeClass()) { |
| 12216 const UnresolvedClass& unresolved_class = | 12193 const UnresolvedClass& unresolved_class = |
| 12217 UnresolvedClass::Handle(Z, type->unresolved_class()); | 12194 UnresolvedClass::Handle(Z, type->unresolved_class()); |
| 12218 const String& unresolved_class_name = | 12195 const String& unresolved_class_name = |
| 12219 String::Handle(Z, unresolved_class.ident()); | 12196 String::Handle(Z, unresolved_class.ident()); |
| 12220 Class& resolved_type_class = Class::Handle(Z); | |
| 12221 if (unresolved_class.library_or_library_prefix() == Object::null()) { | 12197 if (unresolved_class.library_or_library_prefix() == Object::null()) { |
| 12222 // First check if the type is a function type parameter. | 12198 // First check if the type is a function type parameter. |
| 12223 if (!innermost_function().IsNull()) { | 12199 if (!innermost_function().IsNull()) { |
| 12224 // TODO(regis): Shortcut this lookup if no generic functions in scope. | 12200 // TODO(regis): Shortcut this lookup if no generic functions in scope. |
| 12225 TypeParameter& type_parameter = TypeParameter::ZoneHandle( | 12201 TypeParameter& type_parameter = TypeParameter::ZoneHandle( |
| 12226 Z, innermost_function().LookupTypeParameter(unresolved_class_name, | 12202 Z, innermost_function().LookupTypeParameter(unresolved_class_name, |
| 12227 NULL)); | 12203 NULL)); |
| 12228 if (!type_parameter.IsNull()) { | 12204 if (!type_parameter.IsNull()) { |
| 12229 // TODO(regis): Check for absence of type arguments. | 12205 // TODO(regis): Check for absence of type arguments. |
| 12230 // For now, resolve the function type parameter to dynamic. | 12206 // For now, resolve the function type parameter to dynamic. |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 12253 *type = ClassFinalizer::NewFinalizedMalformedType( | 12229 *type = ClassFinalizer::NewFinalizedMalformedType( |
| 12254 Error::Handle(Z), // No previous error. | 12230 Error::Handle(Z), // No previous error. |
| 12255 script_, type_parameter.token_pos(), | 12231 script_, type_parameter.token_pos(), |
| 12256 "type parameter '%s' cannot be parameterized", | 12232 "type parameter '%s' cannot be parameterized", |
| 12257 String::Handle(Z, type_parameter.name()).ToCString()); | 12233 String::Handle(Z, type_parameter.name()).ToCString()); |
| 12258 return; | 12234 return; |
| 12259 } | 12235 } |
| 12260 *type = type_parameter.raw(); | 12236 *type = type_parameter.raw(); |
| 12261 return; | 12237 return; |
| 12262 } | 12238 } |
| 12263 // The referenced class may not have been parsed yet. It would be wrong | |
| 12264 // to resolve it too early to an imported class of the same name. Only | |
| 12265 // resolve the class when a finalized type is requested. | |
| 12266 // Note that when compiling a cloned mixin function, library_ may be | |
| 12267 // different than current_class's library. | |
| 12268 if (finalization > ClassFinalizer::kResolveTypeParameters) { | |
| 12269 resolved_type_class = library_.LookupClass(unresolved_class_name); | |
| 12270 } | |
| 12271 } else { | |
| 12272 // Resolve class name in the scope of the library prefix. | |
| 12273 const Object& prefix = | |
| 12274 Object::Handle(Z, unresolved_class.library_or_library_prefix()); | |
| 12275 ASSERT(prefix.IsLibraryPrefix()); | |
| 12276 resolved_type_class = | |
| 12277 LibraryPrefix::Cast(prefix).LookupClass(unresolved_class_name); | |
| 12278 } | 12239 } |
|
hausner
2017/02/03 20:27:01
Is it no longer necessary to look up classes from
regis
2017/02/03 20:36:43
We do it later in ClassFinalizer::ResolveClass().
| |
| 12279 // At this point, we can only have a parameterized_type. | |
| 12280 const Type& parameterized_type = Type::Cast(*type); | |
| 12281 if (!resolved_type_class.IsNull()) { | |
| 12282 // Replace unresolved class with resolved type class. | |
| 12283 parameterized_type.set_type_class(resolved_type_class); | |
| 12284 // Promote type to a function type in case its type class is a typedef. | |
| 12285 if (resolved_type_class.IsTypedefClass()) { | |
| 12286 ASSERT(!parameterized_type.IsFunctionType()); | |
| 12287 parameterized_type.set_signature( | |
| 12288 Function::Handle(Z, resolved_type_class.signature_function())); | |
| 12289 } | |
| 12290 // Replace FutureOr<T> type of async library with dynamic. | |
| 12291 if ((resolved_type_class.library() == Library::AsyncLibrary()) && | |
| 12292 (resolved_type_class.Name() == Symbols::FutureOr().raw())) { | |
| 12293 parameterized_type.set_type_class( | |
| 12294 Class::Handle(Object::dynamic_class())); | |
| 12295 parameterized_type.set_arguments(Object::null_type_arguments()); | |
| 12296 } | |
| 12297 } else if (finalization >= ClassFinalizer::kCanonicalize) { | |
| 12298 ClassFinalizer::FinalizeMalformedType( | |
| 12299 Error::Handle(Z), // No previous error. | |
| 12300 script_, parameterized_type, "type '%s' is not loaded", | |
| 12301 String::Handle(Z, parameterized_type.UserVisibleName()).ToCString()); | |
| 12302 return; | |
| 12303 } | |
| 12304 } | |
| 12305 if (finalization > ClassFinalizer::kResolveTypeParameters) { | |
| 12306 type->SetIsResolved(); | |
| 12307 } | 12240 } |
| 12308 // Resolve type arguments, if any. | 12241 // Resolve type arguments, if any. |
| 12309 if (type->arguments() != TypeArguments::null()) { | 12242 if (type->arguments() != TypeArguments::null()) { |
| 12310 const TypeArguments& arguments = | 12243 const TypeArguments& arguments = |
| 12311 TypeArguments::Handle(Z, type->arguments()); | 12244 TypeArguments::Handle(Z, type->arguments()); |
| 12312 const intptr_t num_arguments = arguments.Length(); | 12245 const intptr_t num_arguments = arguments.Length(); |
| 12313 AbstractType& type_argument = AbstractType::Handle(Z); | 12246 AbstractType& type_argument = AbstractType::Handle(Z); |
| 12314 for (intptr_t i = 0; i < num_arguments; i++) { | 12247 for (intptr_t i = 0; i < num_arguments; i++) { |
| 12315 type_argument ^= arguments.TypeAt(i); | 12248 type_argument ^= arguments.TypeAt(i); |
| 12316 ResolveType(finalization, &type_argument); | 12249 ResolveType(&type_argument); |
| 12317 arguments.SetTypeAt(i, type_argument); | 12250 arguments.SetTypeAt(i, type_argument); |
| 12318 } | 12251 } |
| 12319 } | 12252 } |
| 12320 if (type->IsFunctionType()) { | 12253 if (type->IsFunctionType()) { |
| 12321 const Function& signature = | 12254 const Function& signature = |
| 12322 Function::Handle(Z, Type::Cast(*type).signature()); | 12255 Function::Handle(Z, Type::Cast(*type).signature()); |
| 12323 Type& signature_type = Type::Handle(Z, signature.SignatureType()); | 12256 Type& signature_type = Type::Handle(Z, signature.SignatureType()); |
| 12324 if (signature_type.raw() != type->raw()) { | 12257 if (signature_type.raw() != type->raw()) { |
| 12325 ResolveType(finalization, &signature_type); | 12258 ResolveType(&signature_type); |
| 12326 } else { | 12259 } else { |
| 12327 ResolveSignature(finalization, signature); | 12260 ResolveSignature(signature); |
| 12328 if (signature.IsSignatureFunction()) { | |
| 12329 // Drop fields that are not necessary anymore after resolution. | |
| 12330 // The parent function, owner, and token position of a shared | |
| 12331 // canonical function type are meaningless, since the canonical | |
| 12332 // representent is picked arbitrarily. | |
| 12333 signature.set_parent_function(Function::Handle(Z)); | |
| 12334 // TODO(regis): As long as we support metadata in typedef signatures, | |
| 12335 // we cannot reset these fields used to reparse a typedef. | |
| 12336 // Note that the scope class of a typedef function type is always | |
| 12337 // preserved as the typedef class (not reset to _Closure class), thereby | |
| 12338 // preventing sharing of canonical function types between typedefs. | |
| 12339 // Not being shared, these fields are therefore always meaningful for | |
| 12340 // typedefs. | |
| 12341 } | |
| 12342 if (type->HasResolvedTypeClass()) { | |
| 12343 const Class& scope_class = Class::Handle(Z, type->type_class()); | |
| 12344 if (!scope_class.IsTypedefClass()) { | |
| 12345 if (signature.IsSignatureFunction()) { | |
| 12346 signature.set_owner(Object::Handle(Z)); | |
| 12347 signature.set_token_pos(TokenPosition::kNoSource); | |
| 12348 } | |
| 12349 if ((type->arguments() != TypeArguments::null()) && | |
| 12350 signature.HasInstantiatedSignature()) { | |
| 12351 ASSERT(scope_class.IsGeneric()); | |
| 12352 // Although the scope class of this function type is generic, | |
| 12353 // the signature of this function type does not refer to any | |
| 12354 // of its type parameters. Reset its scope class to _Closure. | |
| 12355 Type::Cast(*type).set_type_class(Class::Handle( | |
| 12356 Z, Isolate::Current()->object_store()->closure_class())); | |
| 12357 type->set_arguments(Object::null_type_arguments()); | |
| 12358 } | |
| 12359 } | |
| 12360 } | |
| 12361 } | 12261 } |
| 12362 } | 12262 } |
| 12363 } | 12263 } |
| 12364 | 12264 |
| 12365 | 12265 |
| 12266 RawAbstractType* Parser::CanonicalizeType(const AbstractType& type) { | |
| 12267 // If the current class is the result of a mixin application, we must | |
| 12268 // use the class scope of the class from which the function originates. | |
| 12269 if (current_class().IsMixinApplication()) { | |
| 12270 return ClassFinalizer::FinalizeType( | |
| 12271 Class::Handle(Z, parsed_function()->function().origin()), type, | |
| 12272 ClassFinalizer::kCanonicalize); | |
| 12273 } | |
| 12274 return ClassFinalizer::FinalizeType(current_class(), type, | |
| 12275 ClassFinalizer::kCanonicalize); | |
| 12276 } | |
| 12277 | |
| 12278 | |
| 12366 LocalVariable* Parser::LookupLocalScope(const String& ident) { | 12279 LocalVariable* Parser::LookupLocalScope(const String& ident) { |
| 12367 if (current_block_ == NULL) { | 12280 if (current_block_ == NULL) { |
| 12368 return NULL; | 12281 return NULL; |
| 12369 } | 12282 } |
| 12370 // A found name is treated as accessed and possibly marked as captured. | 12283 // A found name is treated as accessed and possibly marked as captured. |
| 12371 const bool kTestOnly = false; | 12284 const bool kTestOnly = false; |
| 12372 return current_block_->scope->LookupVariable(ident, kTestOnly); | 12285 return current_block_->scope->LookupVariable(ident, kTestOnly); |
| 12373 } | 12286 } |
| 12374 | 12287 |
| 12375 | 12288 |
| (...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 12898 if (resolved == NULL) { | 12811 if (resolved == NULL) { |
| 12899 // Check whether the identifier is a class type parameter. | 12812 // Check whether the identifier is a class type parameter. |
| 12900 if (!current_class().IsNull()) { | 12813 if (!current_class().IsNull()) { |
| 12901 TypeParameter& type_parameter = TypeParameter::ZoneHandle( | 12814 TypeParameter& type_parameter = TypeParameter::ZoneHandle( |
| 12902 Z, current_class().LookupTypeParameter(ident)); | 12815 Z, current_class().LookupTypeParameter(ident)); |
| 12903 if (!type_parameter.IsNull()) { | 12816 if (!type_parameter.IsNull()) { |
| 12904 if (FunctionLevel() > 0) { | 12817 if (FunctionLevel() > 0) { |
| 12905 // Make sure that the class instantiator is captured. | 12818 // Make sure that the class instantiator is captured. |
| 12906 CaptureInstantiator(); | 12819 CaptureInstantiator(); |
| 12907 } | 12820 } |
| 12908 type_parameter ^= ClassFinalizer::FinalizeType( | 12821 type_parameter ^= CanonicalizeType(type_parameter); |
| 12909 current_class(), type_parameter, ClassFinalizer::kCanonicalize); | |
| 12910 ASSERT(!type_parameter.IsMalformed()); | 12822 ASSERT(!type_parameter.IsMalformed()); |
| 12911 return new (Z) TypeNode(ident_pos, type_parameter); | 12823 return new (Z) TypeNode(ident_pos, type_parameter); |
| 12912 } | 12824 } |
| 12913 } | 12825 } |
| 12914 // Not found in the local scope, and the name is not a type parameter. | 12826 // Not found in the local scope, and the name is not a type parameter. |
| 12915 // Try finding the variable in the library scope (current library | 12827 // Try finding the variable in the library scope (current library |
| 12916 // and all libraries imported by it without a library prefix). | 12828 // and all libraries imported by it without a library prefix). |
| 12917 resolved = ResolveIdentInCurrentLibraryScope(ident_pos, ident); | 12829 resolved = ResolveIdentInCurrentLibraryScope(ident_pos, ident); |
| 12918 } | 12830 } |
| 12919 if (resolved->IsPrimaryNode()) { | 12831 if (resolved->IsPrimaryNode()) { |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 12940 resolved = LoadClosure(primary); | 12852 resolved = LoadClosure(primary); |
| 12941 } else { | 12853 } else { |
| 12942 ReportError(ident_pos, "illegal reference to method '%s'", | 12854 ReportError(ident_pos, "illegal reference to method '%s'", |
| 12943 ident.ToCString()); | 12855 ident.ToCString()); |
| 12944 } | 12856 } |
| 12945 } else if (primary->primary().IsClass()) { | 12857 } else if (primary->primary().IsClass()) { |
| 12946 const Class& type_class = Class::Cast(primary->primary()); | 12858 const Class& type_class = Class::Cast(primary->primary()); |
| 12947 AbstractType& type = | 12859 AbstractType& type = |
| 12948 Type::ZoneHandle(Z, Type::New(type_class, TypeArguments::Handle(Z), | 12860 Type::ZoneHandle(Z, Type::New(type_class, TypeArguments::Handle(Z), |
| 12949 primary_pos, Heap::kOld)); | 12861 primary_pos, Heap::kOld)); |
| 12950 type ^= ClassFinalizer::FinalizeType(current_class(), type, | 12862 type ^= CanonicalizeType(type); |
| 12951 ClassFinalizer::kCanonicalize); | |
| 12952 // Type may be malbounded, but not malformed. | 12863 // Type may be malbounded, but not malformed. |
| 12953 ASSERT(!type.IsMalformed()); | 12864 ASSERT(!type.IsMalformed()); |
| 12954 resolved = new (Z) TypeNode(primary_pos, type); | 12865 resolved = new (Z) TypeNode(primary_pos, type); |
| 12955 } | 12866 } |
| 12956 } | 12867 } |
| 12957 return resolved; | 12868 return resolved; |
| 12958 } | 12869 } |
| 12959 | 12870 |
| 12960 | 12871 |
| 12961 RawAbstractType* Parser::ParseType( | 12872 RawAbstractType* Parser::ParseType( |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 12993 type = Type::DynamicType(); | 12904 type = Type::DynamicType(); |
| 12994 } | 12905 } |
| 12995 // 'type' is the result type of the function type. | 12906 // 'type' is the result type of the function type. |
| 12996 type = ParseFunctionType(type, ClassFinalizer::kDoNotResolve); | 12907 type = ParseFunctionType(type, ClassFinalizer::kDoNotResolve); |
| 12997 } | 12908 } |
| 12998 // At this point, all type parameters have been parsed, resolve the type. | 12909 // At this point, all type parameters have been parsed, resolve the type. |
| 12999 if (finalization == ClassFinalizer::kIgnore) { | 12910 if (finalization == ClassFinalizer::kIgnore) { |
| 13000 return Type::DynamicType(); | 12911 return Type::DynamicType(); |
| 13001 } | 12912 } |
| 13002 if (finalization >= ClassFinalizer::kResolveTypeParameters) { | 12913 if (finalization >= ClassFinalizer::kResolveTypeParameters) { |
| 13003 ResolveType(finalization, &type); | 12914 ResolveType(&type); |
| 13004 if (finalization >= ClassFinalizer::kCanonicalize) { | 12915 if (finalization >= ClassFinalizer::kCanonicalize) { |
| 13005 type ^= ClassFinalizer::FinalizeType(current_class(), type, finalization); | 12916 type ^= CanonicalizeType(type); |
| 13006 } | 12917 } |
| 13007 } | 12918 } |
| 13008 return type.raw(); | 12919 return type.raw(); |
| 13009 } | 12920 } |
| 13010 | 12921 |
| 13011 | 12922 |
| 13012 // Parses and returns a function type. | 12923 // Parses and returns a function type. |
| 13013 // If 'result_type' is not null, parsing of the result type is skipped. | 12924 // If 'result_type' is not null, parsing of the result type is skipped. |
| 13014 RawType* Parser::ParseFunctionType( | 12925 RawType* Parser::ParseFunctionType( |
| 13015 const AbstractType& result_type, | 12926 const AbstractType& result_type, |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 13065 ¶ms); | 12976 ¶ms); |
| 13066 AddFormalParamsToFunction(¶ms, signature_function); | 12977 AddFormalParamsToFunction(¶ms, signature_function); |
| 13067 innermost_function_ = innermost_function_.parent_function(); | 12978 innermost_function_ = innermost_function_.parent_function(); |
| 13068 type = signature_function.SignatureType(); | 12979 type = signature_function.SignatureType(); |
| 13069 } while (IsFunctionTypeSymbol()); | 12980 } while (IsFunctionTypeSymbol()); |
| 13070 // At this point, all type parameters have been parsed, resolve the type. | 12981 // At this point, all type parameters have been parsed, resolve the type. |
| 13071 if (finalization == ClassFinalizer::kIgnore) { | 12982 if (finalization == ClassFinalizer::kIgnore) { |
| 13072 return Type::DynamicType(); | 12983 return Type::DynamicType(); |
| 13073 } | 12984 } |
| 13074 if (finalization >= ClassFinalizer::kResolveTypeParameters) { | 12985 if (finalization >= ClassFinalizer::kResolveTypeParameters) { |
| 13075 ResolveType(finalization, &type); | 12986 ResolveType(&type); |
| 13076 if (finalization >= ClassFinalizer::kCanonicalize) { | 12987 if (finalization >= ClassFinalizer::kCanonicalize) { |
| 13077 type ^= ClassFinalizer::FinalizeType(current_class(), type, finalization); | 12988 type ^= CanonicalizeType(type); |
| 13078 } | 12989 } |
| 13079 } | 12990 } |
| 13080 return Type::RawCast(type.raw()); | 12991 return Type::RawCast(type.raw()); |
| 13081 } | 12992 } |
| 13082 | 12993 |
| 13083 | 12994 |
| 13084 // Parses type = [ident "."] ident ["<" type { "," type } ">"], then resolve and | 12995 // Parses type = [ident "."] ident ["<" type { "," type } ">"], then resolve and |
| 13085 // finalize it according to the given type finalization mode. | 12996 // finalize it according to the given type finalization mode. |
| 13086 // Returns type and sets prefix. | 12997 // Returns type and sets prefix. |
| 13087 RawAbstractType* Parser::ParseType( | 12998 RawAbstractType* Parser::ParseType( |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 13179 type_class = UnresolvedClass::New(*prefix, type_name, ident_pos); | 13090 type_class = UnresolvedClass::New(*prefix, type_name, ident_pos); |
| 13180 } | 13091 } |
| 13181 TypeArguments& type_arguments = | 13092 TypeArguments& type_arguments = |
| 13182 TypeArguments::Handle(Z, ParseTypeArguments(finalization)); | 13093 TypeArguments::Handle(Z, ParseTypeArguments(finalization)); |
| 13183 if (finalization == ClassFinalizer::kIgnore) { | 13094 if (finalization == ClassFinalizer::kIgnore) { |
| 13184 return Type::DynamicType(); | 13095 return Type::DynamicType(); |
| 13185 } | 13096 } |
| 13186 AbstractType& type = AbstractType::Handle( | 13097 AbstractType& type = AbstractType::Handle( |
| 13187 Z, Type::New(type_class, type_arguments, ident_pos, Heap::kOld)); | 13098 Z, Type::New(type_class, type_arguments, ident_pos, Heap::kOld)); |
| 13188 if (finalization >= ClassFinalizer::kResolveTypeParameters) { | 13099 if (finalization >= ClassFinalizer::kResolveTypeParameters) { |
| 13189 ResolveType(finalization, &type); | 13100 ResolveType(&type); |
| 13190 if (finalization >= ClassFinalizer::kCanonicalize) { | 13101 if (finalization >= ClassFinalizer::kCanonicalize) { |
| 13191 type ^= ClassFinalizer::FinalizeType(current_class(), type, finalization); | 13102 type ^= CanonicalizeType(type); |
| 13192 } | 13103 } |
| 13193 } | 13104 } |
| 13194 return type.raw(); | 13105 return type.raw(); |
| 13195 } | 13106 } |
| 13196 | 13107 |
| 13197 | 13108 |
| 13198 void Parser::CheckConstructorCallTypeArguments( | 13109 void Parser::CheckConstructorCallTypeArguments( |
| 13199 TokenPosition pos, | 13110 TokenPosition pos, |
| 13200 const Function& constructor, | 13111 const Function& constructor, |
| 13201 const TypeArguments& type_arguments) { | 13112 const TypeArguments& type_arguments) { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 13262 "the element type"); | 13173 "the element type"); |
| 13263 } | 13174 } |
| 13264 // Ignore type arguments. | 13175 // Ignore type arguments. |
| 13265 list_type_arguments = TypeArguments::null(); | 13176 list_type_arguments = TypeArguments::null(); |
| 13266 } | 13177 } |
| 13267 } | 13178 } |
| 13268 ASSERT(list_type_arguments.IsNull() || (list_type_arguments.Length() == 1)); | 13179 ASSERT(list_type_arguments.IsNull() || (list_type_arguments.Length() == 1)); |
| 13269 const Class& array_class = Class::Handle(Z, I->object_store()->array_class()); | 13180 const Class& array_class = Class::Handle(Z, I->object_store()->array_class()); |
| 13270 Type& type = Type::ZoneHandle( | 13181 Type& type = Type::ZoneHandle( |
| 13271 Z, Type::New(array_class, list_type_arguments, type_pos, Heap::kOld)); | 13182 Z, Type::New(array_class, list_type_arguments, type_pos, Heap::kOld)); |
| 13272 type ^= ClassFinalizer::FinalizeType(current_class(), type, | 13183 type ^= CanonicalizeType(type); |
| 13273 ClassFinalizer::kCanonicalize); | |
| 13274 GrowableArray<AstNode*> element_list; | 13184 GrowableArray<AstNode*> element_list; |
| 13275 // Parse the list elements. Note: there may be an optional extra | 13185 // Parse the list elements. Note: there may be an optional extra |
| 13276 // comma after the last element. | 13186 // comma after the last element. |
| 13277 if (!is_empty_literal) { | 13187 if (!is_empty_literal) { |
| 13278 const bool saved_mode = SetAllowFunctionLiterals(true); | 13188 const bool saved_mode = SetAllowFunctionLiterals(true); |
| 13279 while (CurrentToken() != Token::kRBRACK) { | 13189 while (CurrentToken() != Token::kRBRACK) { |
| 13280 const TokenPosition element_pos = TokenPos(); | 13190 const TokenPosition element_pos = TokenPos(); |
| 13281 AstNode* element = ParseExpr(is_const, kConsumeCascades); | 13191 AstNode* element = ParseExpr(is_const, kConsumeCascades); |
| 13282 if (I->type_checks() && !is_const && !element_type.IsDynamicType()) { | 13192 if (I->type_checks() && !is_const && !element_type.IsDynamicType()) { |
| 13283 element = new (Z) AssignableNode(element_pos, element, element_type, | 13193 element = new (Z) AssignableNode(element_pos, element, element_type, |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 13345 CaptureInstantiator(); | 13255 CaptureInstantiator(); |
| 13346 } | 13256 } |
| 13347 TypeArguments& factory_type_args = | 13257 TypeArguments& factory_type_args = |
| 13348 TypeArguments::ZoneHandle(Z, list_type_arguments.raw()); | 13258 TypeArguments::ZoneHandle(Z, list_type_arguments.raw()); |
| 13349 // If the factory class extends other parameterized classes, adjust the | 13259 // If the factory class extends other parameterized classes, adjust the |
| 13350 // type argument vector. | 13260 // type argument vector. |
| 13351 if (!factory_type_args.IsNull() && (factory_class.NumTypeArguments() > 1)) { | 13261 if (!factory_type_args.IsNull() && (factory_class.NumTypeArguments() > 1)) { |
| 13352 ASSERT(factory_type_args.Length() == 1); | 13262 ASSERT(factory_type_args.Length() == 1); |
| 13353 Type& factory_type = Type::Handle( | 13263 Type& factory_type = Type::Handle( |
| 13354 Z, Type::New(factory_class, factory_type_args, type_pos, Heap::kOld)); | 13264 Z, Type::New(factory_class, factory_type_args, type_pos, Heap::kOld)); |
| 13355 factory_type ^= ClassFinalizer::FinalizeType( | 13265 // It is not strictly necessary to canonicalize factory_type, but only its |
| 13356 current_class(), factory_type, ClassFinalizer::kFinalize); | 13266 // type argument vector. |
| 13267 factory_type ^= CanonicalizeType(factory_type); | |
| 13357 factory_type_args = factory_type.arguments(); | 13268 factory_type_args = factory_type.arguments(); |
| 13358 ASSERT(factory_type_args.Length() == factory_class.NumTypeArguments()); | 13269 ASSERT(factory_type_args.Length() == factory_class.NumTypeArguments()); |
| 13270 ASSERT(factory_type_args.IsCanonical()); | |
| 13271 } else { | |
| 13272 factory_type_args = factory_type_args.Canonicalize(); | |
| 13359 } | 13273 } |
| 13360 factory_type_args = factory_type_args.Canonicalize(); | |
| 13361 ArgumentListNode* factory_param = new (Z) ArgumentListNode(literal_pos); | 13274 ArgumentListNode* factory_param = new (Z) ArgumentListNode(literal_pos); |
| 13362 if (element_list.length() == 0) { | 13275 if (element_list.length() == 0) { |
| 13363 LiteralNode* empty_array_literal = | 13276 LiteralNode* empty_array_literal = |
| 13364 new (Z) LiteralNode(TokenPos(), Object::empty_array()); | 13277 new (Z) LiteralNode(TokenPos(), Object::empty_array()); |
| 13365 factory_param->Add(empty_array_literal); | 13278 factory_param->Add(empty_array_literal); |
| 13366 } else { | 13279 } else { |
| 13367 ArrayNode* list = new (Z) ArrayNode(TokenPos(), type, element_list); | 13280 ArrayNode* list = new (Z) ArrayNode(TokenPos(), type, element_list); |
| 13368 factory_param->Add(list); | 13281 factory_param->Add(list); |
| 13369 } | 13282 } |
| 13370 return CreateConstructorCallNode(literal_pos, factory_type_args, | 13283 return CreateConstructorCallNode(literal_pos, factory_type_args, |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 13592 CaptureInstantiator(); | 13505 CaptureInstantiator(); |
| 13593 } | 13506 } |
| 13594 TypeArguments& factory_type_args = | 13507 TypeArguments& factory_type_args = |
| 13595 TypeArguments::ZoneHandle(Z, map_type_arguments.raw()); | 13508 TypeArguments::ZoneHandle(Z, map_type_arguments.raw()); |
| 13596 // If the factory class extends other parameterized classes, adjust the | 13509 // If the factory class extends other parameterized classes, adjust the |
| 13597 // type argument vector. | 13510 // type argument vector. |
| 13598 if (!factory_type_args.IsNull() && (factory_class.NumTypeArguments() > 2)) { | 13511 if (!factory_type_args.IsNull() && (factory_class.NumTypeArguments() > 2)) { |
| 13599 ASSERT(factory_type_args.Length() == 2); | 13512 ASSERT(factory_type_args.Length() == 2); |
| 13600 Type& factory_type = Type::Handle( | 13513 Type& factory_type = Type::Handle( |
| 13601 Z, Type::New(factory_class, factory_type_args, type_pos, Heap::kOld)); | 13514 Z, Type::New(factory_class, factory_type_args, type_pos, Heap::kOld)); |
| 13602 factory_type ^= ClassFinalizer::FinalizeType( | 13515 // It is not strictly necessary to canonicalize factory_type, but only its |
| 13603 current_class(), factory_type, ClassFinalizer::kFinalize); | 13516 // type argument vector. |
| 13517 factory_type ^= CanonicalizeType(factory_type); | |
| 13604 factory_type_args = factory_type.arguments(); | 13518 factory_type_args = factory_type.arguments(); |
| 13605 ASSERT(factory_type_args.Length() == factory_class.NumTypeArguments()); | 13519 ASSERT(factory_type_args.Length() == factory_class.NumTypeArguments()); |
| 13520 ASSERT(factory_type_args.IsCanonical()); | |
| 13521 } else { | |
| 13522 factory_type_args = factory_type_args.Canonicalize(); | |
| 13606 } | 13523 } |
| 13607 factory_type_args = factory_type_args.Canonicalize(); | |
| 13608 ArgumentListNode* factory_param = new (Z) ArgumentListNode(literal_pos); | 13524 ArgumentListNode* factory_param = new (Z) ArgumentListNode(literal_pos); |
| 13609 // The kv_pair array is temporary and of element type dynamic. It is passed | 13525 // The kv_pair array is temporary and of element type dynamic. It is passed |
| 13610 // to the factory to initialize a properly typed map. Pass a pre-allocated | 13526 // to the factory to initialize a properly typed map. Pass a pre-allocated |
| 13611 // array for the common empty map literal case. | 13527 // array for the common empty map literal case. |
| 13612 if (kv_pairs_list.length() == 0) { | 13528 if (kv_pairs_list.length() == 0) { |
| 13613 LiteralNode* empty_array_literal = | 13529 LiteralNode* empty_array_literal = |
| 13614 new (Z) LiteralNode(TokenPos(), Object::empty_array()); | 13530 new (Z) LiteralNode(TokenPos(), Object::empty_array()); |
| 13615 factory_param->Add(empty_array_literal); | 13531 factory_param->Add(empty_array_literal); |
| 13616 } else { | 13532 } else { |
| 13617 ArrayNode* kv_pairs = new (Z) ArrayNode( | 13533 ArrayNode* kv_pairs = new (Z) ArrayNode( |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 13726 // Replace the types parsed from the constructor. | 13642 // Replace the types parsed from the constructor. |
| 13727 params.EraseParameterTypes(); | 13643 params.EraseParameterTypes(); |
| 13728 | 13644 |
| 13729 closure = Function::NewClosureFunction(closure_name, innermost_function(), | 13645 closure = Function::NewClosureFunction(closure_name, innermost_function(), |
| 13730 token_pos); | 13646 token_pos); |
| 13731 closure.set_is_generated_body(true); | 13647 closure.set_is_generated_body(true); |
| 13732 closure.set_is_debuggable(false); | 13648 closure.set_is_debuggable(false); |
| 13733 closure.set_is_visible(false); | 13649 closure.set_is_visible(false); |
| 13734 closure.set_result_type(Object::dynamic_type()); | 13650 closure.set_result_type(Object::dynamic_type()); |
| 13735 AddFormalParamsToFunction(¶ms, closure); | 13651 AddFormalParamsToFunction(¶ms, closure); |
| 13736 ResolveSignature(ClassFinalizer::kResolveTypeParameters, closure); | 13652 ResolveSignature(closure); |
| 13737 | 13653 |
| 13738 // Finalize function type. | 13654 // Finalize function type. |
| 13739 Type& signature_type = Type::Handle(Z, closure.SignatureType()); | 13655 Type& signature_type = Type::Handle(Z, closure.SignatureType()); |
| 13740 signature_type ^= ClassFinalizer::FinalizeType( | 13656 signature_type ^= CanonicalizeType(signature_type); |
| 13741 current_class(), signature_type, ClassFinalizer::kCanonicalize); | |
| 13742 closure.SetSignatureType(signature_type); | 13657 closure.SetSignatureType(signature_type); |
| 13743 // Finalization would be premature when top-level parsing. | 13658 // Finalization would be premature when top-level parsing. |
| 13744 ASSERT(!is_top_level_); | 13659 ASSERT(!is_top_level_); |
| 13745 return closure.raw(); | 13660 return closure.raw(); |
| 13746 } | 13661 } |
| 13747 | 13662 |
| 13748 | 13663 |
| 13749 static String& BuildConstructorName(Thread* thread, | 13664 static String& BuildConstructorName(Thread* thread, |
| 13750 const String& type_class_name, | 13665 const String& type_class_name, |
| 13751 const String* named_constructor) { | 13666 const String* named_constructor) { |
| (...skipping 1284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 15036 const ArgumentListNode& function_args, | 14951 const ArgumentListNode& function_args, |
| 15037 const LocalVariable* temp_for_last_arg, | 14952 const LocalVariable* temp_for_last_arg, |
| 15038 bool is_super_invocation) { | 14953 bool is_super_invocation) { |
| 15039 UNREACHABLE(); | 14954 UNREACHABLE(); |
| 15040 return NULL; | 14955 return NULL; |
| 15041 } | 14956 } |
| 15042 | 14957 |
| 15043 } // namespace dart | 14958 } // namespace dart |
| 15044 | 14959 |
| 15045 #endif // DART_PRECOMPILED_RUNTIME | 14960 #endif // DART_PRECOMPILED_RUNTIME |
| OLD | NEW |