| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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/class_finalizer.h" | 5 #include "vm/class_finalizer.h" |
| 6 | 6 |
| 7 #include "vm/flags.h" | 7 #include "vm/flags.h" |
| 8 #include "vm/hash_table.h" | 8 #include "vm/hash_table.h" |
| 9 #include "vm/heap.h" | 9 #include "vm/heap.h" |
| 10 #include "vm/isolate.h" | 10 #include "vm/isolate.h" |
| (...skipping 778 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 789 // Finalize the current type arguments of the type, which are still the | 789 // Finalize the current type arguments of the type, which are still the |
| 790 // parsed type arguments. | 790 // parsed type arguments. |
| 791 if (!arguments.IsNull()) { | 791 if (!arguments.IsNull()) { |
| 792 for (intptr_t i = 0; i < num_type_parameters; i++) { | 792 for (intptr_t i = 0; i < num_type_parameters; i++) { |
| 793 type_arg = full_arguments.TypeAt(offset + i); | 793 type_arg = full_arguments.TypeAt(offset + i); |
| 794 ASSERT(!type_arg.IsBeingFinalized()); | 794 ASSERT(!type_arg.IsBeingFinalized()); |
| 795 type_arg = FinalizeType(cls, type_arg, kFinalize, pending_types); | 795 type_arg = FinalizeType(cls, type_arg, kFinalize, pending_types); |
| 796 if (type_arg.IsMalformed()) { | 796 if (type_arg.IsMalformed()) { |
| 797 // Malformed type arguments are mapped to dynamic. | 797 // Malformed type arguments are mapped to dynamic. |
| 798 type_arg = Type::DynamicType(); | 798 type_arg = Type::DynamicType(); |
| 799 } else if (type_arg.IsFunctionType()) { |
| 800 const Function& signature_function = |
| 801 Function::Handle(zone, Type::Cast(type_arg).signature()); |
| 802 if (signature_function.IsGeneric()) { |
| 803 const String& type_arg_name = |
| 804 String::Handle(zone, type_arg.UserVisibleName()); |
| 805 const String& type_name = |
| 806 String::Handle(zone, type.UserVisibleName()); |
| 807 ReportError(cls, type_arg.token_pos(), |
| 808 "generic function type '%s' not allowed as type " |
| 809 "argument of type '%s'", |
| 810 type_arg_name.ToCString(), type_name.ToCString()); |
| 811 } |
| 799 } | 812 } |
| 800 full_arguments.SetTypeAt(offset + i, type_arg); | 813 full_arguments.SetTypeAt(offset + i, type_arg); |
| 801 } | 814 } |
| 802 } | 815 } |
| 803 if (offset > 0) { | 816 if (offset > 0) { |
| 804 TrailPtr instantiation_trail = new Trail(zone, 4); | 817 TrailPtr instantiation_trail = new Trail(zone, 4); |
| 805 Error& bound_error = Error::Handle(zone); | 818 Error& bound_error = Error::Handle(zone); |
| 806 FinalizeTypeArguments(type_class, full_arguments, offset, &bound_error, | 819 FinalizeTypeArguments(type_class, full_arguments, offset, &bound_error, |
| 807 pending_types, instantiation_trail); | 820 pending_types, instantiation_trail); |
| 808 } | 821 } |
| (...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1334 // Resolve upper bounds of function type parameters. | 1347 // Resolve upper bounds of function type parameters. |
| 1335 const intptr_t num_type_params = function.NumTypeParameters(); | 1348 const intptr_t num_type_params = function.NumTypeParameters(); |
| 1336 if (num_type_params > 0) { | 1349 if (num_type_params > 0) { |
| 1337 TypeParameter& type_param = TypeParameter::Handle(); | 1350 TypeParameter& type_param = TypeParameter::Handle(); |
| 1338 const TypeArguments& type_params = | 1351 const TypeArguments& type_params = |
| 1339 TypeArguments::Handle(function.type_parameters()); | 1352 TypeArguments::Handle(function.type_parameters()); |
| 1340 for (intptr_t i = 0; i < num_type_params; i++) { | 1353 for (intptr_t i = 0; i < num_type_params; i++) { |
| 1341 type_param ^= type_params.TypeAt(i); | 1354 type_param ^= type_params.TypeAt(i); |
| 1342 type = type_param.bound(); | 1355 type = type_param.bound(); |
| 1343 ResolveType(cls, type); | 1356 ResolveType(cls, type); |
| 1357 if (type.IsFunctionType()) { |
| 1358 const Function& signature_function = |
| 1359 Function::Handle(Type::Cast(type).signature()); |
| 1360 if (signature_function.IsGeneric()) { |
| 1361 const String& type_name = String::Handle(type.UserVisibleName()); |
| 1362 const String& type_param_name = String::Handle(type_param.name()); |
| 1363 ReportError(cls, type.token_pos(), |
| 1364 "generic function type '%s' not allowed as bound of " |
| 1365 "function type parameter '%s'", |
| 1366 type_name.ToCString(), type_param_name.ToCString()); |
| 1367 } |
| 1368 } |
| 1344 } | 1369 } |
| 1345 } | 1370 } |
| 1346 // Resolve result type. | 1371 // Resolve result type. |
| 1347 type = function.result_type(); | 1372 type = function.result_type(); |
| 1348 // It is not a compile time error if this name does not resolve to a class or | 1373 // It is not a compile time error if this name does not resolve to a class or |
| 1349 // interface. | 1374 // interface. |
| 1350 ResolveType(cls, type); | 1375 ResolveType(cls, type); |
| 1351 // Resolve formal parameter types. | 1376 // Resolve formal parameter types. |
| 1352 const intptr_t num_parameters = function.NumParameters(); | 1377 const intptr_t num_parameters = function.NumParameters(); |
| 1353 for (intptr_t i = 0; i < num_parameters; i++) { | 1378 for (intptr_t i = 0; i < num_parameters; i++) { |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1452 const TypeArguments& type_params = | 1477 const TypeArguments& type_params = |
| 1453 TypeArguments::Handle(cls.type_parameters()); | 1478 TypeArguments::Handle(cls.type_parameters()); |
| 1454 ASSERT((type_params.IsNull() && (num_type_params == 0)) || | 1479 ASSERT((type_params.IsNull() && (num_type_params == 0)) || |
| 1455 (type_params.Length() == num_type_params)); | 1480 (type_params.Length() == num_type_params)); |
| 1456 // In a first pass, resolve all bounds. This guarantees that finalization | 1481 // In a first pass, resolve all bounds. This guarantees that finalization |
| 1457 // of mutually referencing bounds will not encounter an unresolved bound. | 1482 // of mutually referencing bounds will not encounter an unresolved bound. |
| 1458 for (intptr_t i = 0; i < num_type_params; i++) { | 1483 for (intptr_t i = 0; i < num_type_params; i++) { |
| 1459 type_param ^= type_params.TypeAt(i); | 1484 type_param ^= type_params.TypeAt(i); |
| 1460 bound = type_param.bound(); | 1485 bound = type_param.bound(); |
| 1461 ResolveType(cls, bound); | 1486 ResolveType(cls, bound); |
| 1487 if (bound.IsFunctionType()) { |
| 1488 const Function& signature_function = |
| 1489 Function::Handle(Type::Cast(bound).signature()); |
| 1490 if (signature_function.IsGeneric()) { |
| 1491 const String& bound_name = String::Handle(bound.UserVisibleName()); |
| 1492 const String& type_param_name = String::Handle(type_param.name()); |
| 1493 ReportError(cls, bound.token_pos(), |
| 1494 "generic function type '%s' not allowed as bound of " |
| 1495 "class type parameter '%s'", |
| 1496 bound_name.ToCString(), type_param_name.ToCString()); |
| 1497 } |
| 1498 } |
| 1462 } | 1499 } |
| 1463 } | 1500 } |
| 1464 | 1501 |
| 1465 // Finalize the upper bounds of the type parameters of class cls. | 1502 // Finalize the upper bounds of the type parameters of class cls. |
| 1466 void ClassFinalizer::FinalizeUpperBounds(const Class& cls, | 1503 void ClassFinalizer::FinalizeUpperBounds(const Class& cls, |
| 1467 FinalizationKind finalization) { | 1504 FinalizationKind finalization) { |
| 1468 const intptr_t num_type_params = cls.NumTypeParameters(); | 1505 const intptr_t num_type_params = cls.NumTypeParameters(); |
| 1469 TypeParameter& type_param = TypeParameter::Handle(); | 1506 TypeParameter& type_param = TypeParameter::Handle(); |
| 1470 AbstractType& bound = AbstractType::Handle(); | 1507 AbstractType& bound = AbstractType::Handle(); |
| 1471 const TypeArguments& type_params = | 1508 const TypeArguments& type_params = |
| (...skipping 2281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3753 ProgramVisitor::VisitFunctions(&function_visitor); | 3790 ProgramVisitor::VisitFunctions(&function_visitor); |
| 3754 | 3791 |
| 3755 class ClearCodeClassVisitor : public ClassVisitor { | 3792 class ClearCodeClassVisitor : public ClassVisitor { |
| 3756 void Visit(const Class& cls) { cls.DisableAllocationStub(); } | 3793 void Visit(const Class& cls) { cls.DisableAllocationStub(); } |
| 3757 }; | 3794 }; |
| 3758 ClearCodeClassVisitor class_visitor; | 3795 ClearCodeClassVisitor class_visitor; |
| 3759 ProgramVisitor::VisitClasses(&class_visitor); | 3796 ProgramVisitor::VisitClasses(&class_visitor); |
| 3760 } | 3797 } |
| 3761 | 3798 |
| 3762 } // namespace dart | 3799 } // namespace dart |
| OLD | NEW |