OLD | NEW |
---|---|
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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/heap.h" | 8 #include "vm/heap.h" |
9 #include "vm/isolate.h" | 9 #include "vm/isolate.h" |
10 #include "vm/longjump.h" | 10 #include "vm/longjump.h" |
(...skipping 859 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
870 interface_name.ToCString()); | 870 interface_name.ToCString()); |
871 } | 871 } |
872 } | 872 } |
873 | 873 |
874 // If the class/interface has no explicit interfaces, we are done. | 874 // If the class/interface has no explicit interfaces, we are done. |
875 Array& super_interfaces = Array::Handle(cls.interfaces()); | 875 Array& super_interfaces = Array::Handle(cls.interfaces()); |
876 if (super_interfaces.Length() == 0) { | 876 if (super_interfaces.Length() == 0) { |
877 return; | 877 return; |
878 } | 878 } |
879 | 879 |
880 // If cls belongs to core lib or to core lib's implementation, restrictions | |
881 // about allowed interfaces are lifted. | |
882 const bool cls_belongs_to_core_lib = | |
883 (cls.library() == Library::CoreLibrary()) || | |
884 (cls.library() == Library::CoreImplLibrary()); | |
885 | |
886 // Resolve and check the interfaces of cls. | |
880 visited->Add(&cls); | 887 visited->Add(&cls); |
881 Type& interface = Type::Handle(); | 888 Type& interface = Type::Handle(); |
882 for (intptr_t i = 0; i < super_interfaces.Length(); i++) { | 889 for (intptr_t i = 0; i < super_interfaces.Length(); i++) { |
883 interface ^= super_interfaces.At(i); | 890 interface ^= super_interfaces.At(i); |
884 interface = ResolveType(cls, interface); | 891 interface = ResolveType(cls, interface); |
885 super_interfaces.SetAt(i, interface); | 892 super_interfaces.SetAt(i, interface); |
886 if (interface.IsTypeParameter()) { | 893 if (interface.IsTypeParameter()) { |
887 ReportError("Type parameter '%s' cannot be used as interface\n", | 894 ReportError("Type parameter '%s' cannot be used as interface\n", |
888 String::Handle(interface.Name()).ToCString()); | 895 String::Handle(interface.Name()).ToCString()); |
889 } | 896 } |
890 const Class& interface_class = Class::Handle(interface.type_class()); | 897 const Class& interface_class = Class::Handle(interface.type_class()); |
891 if (!interface_class.is_interface()) { | 898 if (!interface_class.is_interface()) { |
892 ReportError("Class name '%s' used where interface expected\n", | 899 ReportError("Class '%s' is used where an interface is expected\n", |
893 String::Handle(interface_class.Name()).ToCString()); | 900 String::Handle(interface_class.Name()).ToCString()); |
894 } | 901 } |
895 // TODO(regis): Verify that unless cls is in core lib, it cannot implement | 902 // Verify that unless cls belongs to core lib, it cannot extend or implement |
896 // an instance of Number or String. Any other? bool? | 903 // any of bool, num, int, double, String, Function, Dynamic. |
897 | 904 // The exception is signature classes, which are compiler generated and |
905 // represent a function type, therefore implementing the Function interface. | |
906 if (!cls_belongs_to_core_lib) { | |
907 if (interface.IsBoolInterface() || | |
908 interface.IsNumberInterface() || | |
909 interface.IsIntInterface() || | |
910 interface.IsDoubleInterface() || | |
911 interface.IsStringInterface() || | |
912 (interface.IsFunctionInterface() && !cls.IsSignatureClass())|| | |
srdjan
2011/10/28 21:42:42
Add space before ||
regis
2011/10/28 22:23:58
Done.
| |
913 interface.IsDynamicType()) { | |
914 ReportError("'%s' is not allowed to extend or implement '%s'\n", | |
915 String::Handle(cls.Name()).ToCString(), | |
916 String::Handle(interface_class.Name()).ToCString()); | |
917 } | |
918 } | |
srdjan
2011/10/28 21:42:42
We need also to check for Smi, Double, etc classes
regis
2011/10/28 22:23:58
Good point! Since these are classes rather than in
| |
898 // Now resolve the super interfaces. | 919 // Now resolve the super interfaces. |
899 ResolveInterfaces(interface_class, visited); | 920 ResolveInterfaces(interface_class, visited); |
900 } | 921 } |
901 visited->RemoveLast(); | 922 visited->RemoveLast(); |
902 } | 923 } |
903 | 924 |
904 | 925 |
905 // A class is marked as constant if it has one constant constructor. | 926 // A class is marked as constant if it has one constant constructor. |
906 // A constant class: | 927 // A constant class: |
907 // - may extend only const classes. | 928 // - may extend only const classes. |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1012 ASSERT(msg_buffer != NULL); | 1033 ASSERT(msg_buffer != NULL); |
1013 va_list args; | 1034 va_list args; |
1014 va_start(args, format); | 1035 va_start(args, format); |
1015 OS::VSNPrint(msg_buffer, kBufferLength, format, args); | 1036 OS::VSNPrint(msg_buffer, kBufferLength, format, args); |
1016 va_end(args); | 1037 va_end(args); |
1017 isolate->long_jump_base()->Jump(1, msg_buffer); | 1038 isolate->long_jump_base()->Jump(1, msg_buffer); |
1018 UNREACHABLE(); | 1039 UNREACHABLE(); |
1019 } | 1040 } |
1020 | 1041 |
1021 } // namespace dart | 1042 } // namespace dart |
OLD | NEW |