OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 <map> | 5 #include <map> |
6 #include <set> | 6 #include <set> |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "vm/kernel_to_il.h" | 9 #include "vm/kernel_to_il.h" |
10 | 10 |
(...skipping 1267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1278 ASSERT(!klass.IsNull()); | 1278 ASSERT(!klass.IsNull()); |
1279 // Note that if cls is _Closure, the returned type will be _Closure, | 1279 // Note that if cls is _Closure, the returned type will be _Closure, |
1280 // and not the signature type. | 1280 // and not the signature type. |
1281 Type& type = Type::ZoneHandle(Z, klass.CanonicalType()); | 1281 Type& type = Type::ZoneHandle(Z, klass.CanonicalType()); |
1282 if (!type.IsNull()) { | 1282 if (!type.IsNull()) { |
1283 return type; | 1283 return type; |
1284 } | 1284 } |
1285 type = Type::New(klass, TypeArguments::Handle(Z, klass.type_parameters()), | 1285 type = Type::New(klass, TypeArguments::Handle(Z, klass.type_parameters()), |
1286 klass.token_pos()); | 1286 klass.token_pos()); |
1287 if (klass.is_type_finalized()) { | 1287 if (klass.is_type_finalized()) { |
1288 type ^= ClassFinalizer::FinalizeType( | 1288 type ^= ClassFinalizer::FinalizeType(klass, type); |
1289 klass, type, ClassFinalizer::kCanonicalizeWellFormed); | |
1290 // Note that the receiver type may now be a malbounded type. | 1289 // Note that the receiver type may now be a malbounded type. |
1291 klass.SetCanonicalType(type); | 1290 klass.SetCanonicalType(type); |
1292 } | 1291 } |
1293 return type; | 1292 return type; |
1294 } | 1293 } |
1295 | 1294 |
1296 | 1295 |
1297 void TranslationHelper::ReportError(const char* format, ...) { | 1296 void TranslationHelper::ReportError(const char* format, ...) { |
1298 const Script& null_script = Script::Handle(Z); | 1297 const Script& null_script = Script::Handle(Z); |
1299 | 1298 |
(...skipping 3064 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4364 result_ = AbstractType::dynamic_type().raw(); | 4363 result_ = AbstractType::dynamic_type().raw(); |
4365 } | 4364 } |
4366 parameter_types.SetAt(pos, result_); | 4365 parameter_types.SetAt(pos, result_); |
4367 parameter_names.SetAt(pos, H.DartSymbol(tuple->first())); | 4366 parameter_names.SetAt(pos, H.DartSymbol(tuple->first())); |
4368 } | 4367 } |
4369 | 4368 |
4370 Type& signature_type = | 4369 Type& signature_type = |
4371 Type::ZoneHandle(Z, signature_function.SignatureType()); | 4370 Type::ZoneHandle(Z, signature_function.SignatureType()); |
4372 | 4371 |
4373 if (finalize_) { | 4372 if (finalize_) { |
4374 signature_type ^= ClassFinalizer::FinalizeType( | 4373 signature_type ^= |
4375 *active_class_->klass, signature_type, ClassFinalizer::kCanonicalize); | 4374 ClassFinalizer::FinalizeType(*active_class_->klass, signature_type); |
4376 // Do not refer to signature_function anymore, since it may have been | 4375 // Do not refer to signature_function anymore, since it may have been |
4377 // replaced during canonicalization. | 4376 // replaced during canonicalization. |
4378 signature_function = Function::null(); | 4377 signature_function = Function::null(); |
4379 } | 4378 } |
4380 | 4379 |
4381 result_ = signature_type.raw(); | 4380 result_ = signature_type.raw(); |
4382 } | 4381 } |
4383 | 4382 |
4384 | 4383 |
4385 static intptr_t FindTypeParameterIndex(List<TypeParameter>* parameters, | 4384 static intptr_t FindTypeParameterIndex(List<TypeParameter>* parameters, |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4466 // => We therefore ignore errors in `A` or `B`. | 4465 // => We therefore ignore errors in `A` or `B`. |
4467 const TypeArguments& type_arguments = TranslateTypeArguments( | 4466 const TypeArguments& type_arguments = TranslateTypeArguments( |
4468 node->type_arguments().raw_array(), node->type_arguments().length()); | 4467 node->type_arguments().raw_array(), node->type_arguments().length()); |
4469 | 4468 |
4470 | 4469 |
4471 dart::Object& klass = | 4470 dart::Object& klass = |
4472 dart::Object::Handle(Z, H.ToUnresolvedClass(node->klass())); | 4471 dart::Object::Handle(Z, H.ToUnresolvedClass(node->klass())); |
4473 result_ = Type::New(klass, type_arguments, TokenPosition::kNoSource); | 4472 result_ = Type::New(klass, type_arguments, TokenPosition::kNoSource); |
4474 if (finalize_) { | 4473 if (finalize_) { |
4475 ASSERT(active_class_->klass != NULL); | 4474 ASSERT(active_class_->klass != NULL); |
4476 result_ = ClassFinalizer::FinalizeType(*active_class_->klass, result_, | 4475 result_ = ClassFinalizer::FinalizeType(*active_class_->klass, result_); |
4477 ClassFinalizer::kCanonicalize); | |
4478 } | 4476 } |
4479 } | 4477 } |
4480 | 4478 |
4481 | 4479 |
4482 void DartTypeTranslator::VisitDynamicType(DynamicType* node) { | 4480 void DartTypeTranslator::VisitDynamicType(DynamicType* node) { |
4483 result_ = Object::dynamic_type().raw(); | 4481 result_ = Object::dynamic_type().raw(); |
4484 } | 4482 } |
4485 | 4483 |
4486 | 4484 |
4487 void DartTypeTranslator::VisitVoidType(VoidType* node) { | 4485 void DartTypeTranslator::VisitVoidType(VoidType* node) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4525 const TypeArguments& type_arguments = | 4523 const TypeArguments& type_arguments = |
4526 TranslateTypeArguments(receiver_type_arguments, length); | 4524 TranslateTypeArguments(receiver_type_arguments, length); |
4527 if (type_arguments.IsNull()) return type_arguments; | 4525 if (type_arguments.IsNull()) return type_arguments; |
4528 | 4526 |
4529 // We make a temporary [Type] object and use `ClassFinalizer::FinalizeType` to | 4527 // We make a temporary [Type] object and use `ClassFinalizer::FinalizeType` to |
4530 // finalize the argument types. | 4528 // finalize the argument types. |
4531 // (This can for example make the [type_arguments] vector larger) | 4529 // (This can for example make the [type_arguments] vector larger) |
4532 Type& type = Type::Handle( | 4530 Type& type = Type::Handle( |
4533 Z, Type::New(receiver_class, type_arguments, TokenPosition::kNoSource)); | 4531 Z, Type::New(receiver_class, type_arguments, TokenPosition::kNoSource)); |
4534 if (finalize_) { | 4532 if (finalize_) { |
4535 type ^= ClassFinalizer::FinalizeType( | 4533 type ^= ClassFinalizer::FinalizeType(*active_class_->klass, type); |
4536 *active_class_->klass, type, ClassFinalizer::kCanonicalizeWellFormed); | |
4537 } | 4534 } |
4538 | 4535 |
4539 const TypeArguments& instantiated_type_arguments = | 4536 const TypeArguments& instantiated_type_arguments = |
4540 TypeArguments::ZoneHandle(Z, type.arguments()); | 4537 TypeArguments::ZoneHandle(Z, type.arguments()); |
4541 return instantiated_type_arguments; | 4538 return instantiated_type_arguments; |
4542 } | 4539 } |
4543 | 4540 |
4544 | 4541 |
4545 const Type& DartTypeTranslator::ReceiverType(const dart::Class& klass) { | 4542 const Type& DartTypeTranslator::ReceiverType(const dart::Class& klass) { |
4546 ASSERT(!klass.IsNull()); | 4543 ASSERT(!klass.IsNull()); |
4547 ASSERT(!klass.IsTypedefClass()); | 4544 ASSERT(!klass.IsTypedefClass()); |
4548 // Note that if klass is _Closure, the returned type will be _Closure, | 4545 // Note that if klass is _Closure, the returned type will be _Closure, |
4549 // and not the signature type. | 4546 // and not the signature type. |
4550 Type& type = Type::ZoneHandle(Z, klass.CanonicalType()); | 4547 Type& type = Type::ZoneHandle(Z, klass.CanonicalType()); |
4551 if (!type.IsNull()) { | 4548 if (!type.IsNull()) { |
4552 return type; | 4549 return type; |
4553 } | 4550 } |
4554 type = Type::New(klass, TypeArguments::Handle(Z, klass.type_parameters()), | 4551 type = Type::New(klass, TypeArguments::Handle(Z, klass.type_parameters()), |
4555 klass.token_pos()); | 4552 klass.token_pos()); |
4556 if (klass.is_type_finalized()) { | 4553 if (klass.is_type_finalized()) { |
4557 type ^= ClassFinalizer::FinalizeType( | 4554 type ^= ClassFinalizer::FinalizeType(klass, type); |
4558 klass, type, ClassFinalizer::kCanonicalizeWellFormed); | |
4559 klass.SetCanonicalType(type); | 4555 klass.SetCanonicalType(type); |
4560 } | 4556 } |
4561 return type; | 4557 return type; |
4562 } | 4558 } |
4563 | 4559 |
4564 | 4560 |
4565 void FlowGraphBuilder::VisitTypeLiteral(TypeLiteral* node) { | 4561 void FlowGraphBuilder::VisitTypeLiteral(TypeLiteral* node) { |
4566 const AbstractType& type = T.TranslateType(node->type()); | 4562 const AbstractType& type = T.TranslateType(node->type()); |
4567 if (type.IsMalformed()) H.ReportError("Malformed type literal"); | 4563 if (type.IsMalformed()) H.ReportError("Malformed type literal"); |
4568 | 4564 |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4917 | 4913 |
4918 // Check for malbounded-ness of type. | 4914 // Check for malbounded-ness of type. |
4919 if (I->type_checks()) { | 4915 if (I->type_checks()) { |
4920 List<DartType>& kernel_type_arguments = node->arguments()->types(); | 4916 List<DartType>& kernel_type_arguments = node->arguments()->types(); |
4921 const TypeArguments& type_arguments = T.TranslateInstantiatedTypeArguments( | 4917 const TypeArguments& type_arguments = T.TranslateInstantiatedTypeArguments( |
4922 klass, kernel_type_arguments.raw_array(), | 4918 klass, kernel_type_arguments.raw_array(), |
4923 kernel_type_arguments.length()); | 4919 kernel_type_arguments.length()); |
4924 | 4920 |
4925 AbstractType& type = AbstractType::Handle( | 4921 AbstractType& type = AbstractType::Handle( |
4926 Z, Type::New(klass, type_arguments, TokenPosition::kNoSource)); | 4922 Z, Type::New(klass, type_arguments, TokenPosition::kNoSource)); |
4927 type = ClassFinalizer::FinalizeType(klass, type, | 4923 type = ClassFinalizer::FinalizeType(klass, type); |
4928 ClassFinalizer::kCanonicalize); | |
4929 | 4924 |
4930 if (type.IsMalbounded()) { | 4925 if (type.IsMalbounded()) { |
4931 // Evaluate expressions for correctness. | 4926 // Evaluate expressions for correctness. |
4932 List<Expression>& positional = node->arguments()->positional(); | 4927 List<Expression>& positional = node->arguments()->positional(); |
4933 List<NamedExpression>& named = node->arguments()->named(); | 4928 List<NamedExpression>& named = node->arguments()->named(); |
4934 for (intptr_t i = 0; i < positional.length(); ++i) { | 4929 for (intptr_t i = 0; i < positional.length(); ++i) { |
4935 instructions += TranslateExpression(positional[i]); | 4930 instructions += TranslateExpression(positional[i]); |
4936 instructions += Drop(); | 4931 instructions += Drop(); |
4937 } | 4932 } |
4938 for (intptr_t i = 0; i < named.length(); ++i) { | 4933 for (intptr_t i = 0; i < named.length(); ++i) { |
(...skipping 1354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6293 const ContextScope& context_scope = | 6288 const ContextScope& context_scope = |
6294 ContextScope::Handle(Z, scope->PreserveOuterScope(context_depth_)); | 6289 ContextScope::Handle(Z, scope->PreserveOuterScope(context_depth_)); |
6295 function.set_context_scope(context_scope); | 6290 function.set_context_scope(context_scope); |
6296 function.set_kernel_function(node); | 6291 function.set_kernel_function(node); |
6297 KernelReader::SetupFunctionParameters(H, T, dart::Class::Handle(Z), | 6292 KernelReader::SetupFunctionParameters(H, T, dart::Class::Handle(Z), |
6298 function, node, | 6293 function, node, |
6299 false, // is_method | 6294 false, // is_method |
6300 true); // is_closure | 6295 true); // is_closure |
6301 // Finalize function type. | 6296 // Finalize function type. |
6302 Type& signature_type = Type::Handle(Z, function.SignatureType()); | 6297 Type& signature_type = Type::Handle(Z, function.SignatureType()); |
6303 signature_type ^= ClassFinalizer::FinalizeType( | 6298 signature_type ^= |
6304 *active_class_.klass, signature_type, ClassFinalizer::kCanonicalize); | 6299 ClassFinalizer::FinalizeType(*active_class_.klass, signature_type); |
6305 function.SetSignatureType(signature_type); | 6300 function.SetSignatureType(signature_type); |
6306 | 6301 |
6307 I->AddClosureFunction(function); | 6302 I->AddClosureFunction(function); |
6308 } | 6303 } |
6309 break; | 6304 break; |
6310 } | 6305 } |
6311 | 6306 |
6312 const dart::Class& closure_class = | 6307 const dart::Class& closure_class = |
6313 dart::Class::ZoneHandle(Z, I->object_store()->closure_class()); | 6308 dart::Class::ZoneHandle(Z, I->object_store()->closure_class()); |
6314 ASSERT(!closure_class.IsNull()); | 6309 ASSERT(!closure_class.IsNull()); |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6438 thread->clear_sticky_error(); | 6433 thread->clear_sticky_error(); |
6439 return error.raw(); | 6434 return error.raw(); |
6440 } | 6435 } |
6441 } | 6436 } |
6442 | 6437 |
6443 | 6438 |
6444 } // namespace kernel | 6439 } // namespace kernel |
6445 } // namespace dart | 6440 } // namespace dart |
6446 | 6441 |
6447 #endif // !defined(DART_PRECOMPILED_RUNTIME) | 6442 #endif // !defined(DART_PRECOMPILED_RUNTIME) |
OLD | NEW |