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/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 1104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1115 // Check for illegal self references. | 1115 // Check for illegal self references. |
1116 GrowableArray<intptr_t> visited_aliases; | 1116 GrowableArray<intptr_t> visited_aliases; |
1117 if (!IsAliasCycleFree(cls, &visited_aliases)) { | 1117 if (!IsAliasCycleFree(cls, &visited_aliases)) { |
1118 const String& name = String::Handle(cls.Name()); | 1118 const String& name = String::Handle(cls.Name()); |
1119 const Script& script = Script::Handle(cls.script()); | 1119 const Script& script = Script::Handle(cls.script()); |
1120 ReportError(script, cls.token_pos(), | 1120 ReportError(script, cls.token_pos(), |
1121 "typedef '%s' illegally refers to itself", | 1121 "typedef '%s' illegally refers to itself", |
1122 name.ToCString()); | 1122 name.ToCString()); |
1123 } | 1123 } |
1124 cls.Finalize(); | 1124 cls.Finalize(); |
| 1125 // Signature classes extend Object. No need to add this class to the direct |
| 1126 // subclasses of Object. |
| 1127 ASSERT(super_type.IsNull() || super_type.IsObjectType()); |
1125 return; | 1128 return; |
1126 } | 1129 } |
1127 // Finalize factory class, if any. | 1130 // Finalize factory class, if any. |
1128 if (cls.is_interface()) { | 1131 if (cls.is_interface()) { |
1129 if (cls.HasFactoryClass()) { | 1132 if (cls.HasFactoryClass()) { |
1130 const Class& factory_class = Class::Handle(cls.FactoryClass()); | 1133 const Class& factory_class = Class::Handle(cls.FactoryClass()); |
1131 if (!factory_class.is_finalized()) { | 1134 if (!factory_class.is_finalized()) { |
1132 FinalizeClass(factory_class, generating_snapshot); | 1135 FinalizeClass(factory_class, generating_snapshot); |
1133 // Finalizing the factory class may indirectly finalize this interface. | 1136 // Finalizing the factory class may indirectly finalize this interface. |
1134 if (cls.is_finalized()) { | 1137 if (cls.is_finalized()) { |
(...skipping 26 matching lines...) Expand all Loading... |
1161 if (lib.native_entry_resolver() == NULL) { | 1164 if (lib.native_entry_resolver() == NULL) { |
1162 const String& cls_name = String::Handle(cls.Name()); | 1165 const String& cls_name = String::Handle(cls.Name()); |
1163 const String& lib_name = String::Handle(lib.url()); | 1166 const String& lib_name = String::Handle(lib.url()); |
1164 const Script& script = Script::Handle(cls.script()); | 1167 const Script& script = Script::Handle(cls.script()); |
1165 ReportError(script, cls.token_pos(), | 1168 ReportError(script, cls.token_pos(), |
1166 "class '%s' is trying to extend a native fields class, " | 1169 "class '%s' is trying to extend a native fields class, " |
1167 "but library '%s' has no native resolvers", | 1170 "but library '%s' has no native resolvers", |
1168 cls_name.ToCString(), lib_name.ToCString()); | 1171 cls_name.ToCString(), lib_name.ToCString()); |
1169 } | 1172 } |
1170 } | 1173 } |
| 1174 // Add this class to the direct subclasses of the superclass, unless the |
| 1175 // superclass is Object. |
| 1176 if (!super_type.IsNull() && !super_type.IsObjectType()) { |
| 1177 ASSERT(!super_class.IsNull()); |
| 1178 super_class.AddDirectSubclass(cls); |
| 1179 } |
1171 } | 1180 } |
1172 | 1181 |
1173 | 1182 |
1174 bool ClassFinalizer::IsSuperCycleFree(const Class& cls) { | 1183 bool ClassFinalizer::IsSuperCycleFree(const Class& cls) { |
1175 Class& test1 = Class::Handle(cls.raw()); | 1184 Class& test1 = Class::Handle(cls.raw()); |
1176 Class& test2 = Class::Handle(cls.SuperClass()); | 1185 Class& test2 = Class::Handle(cls.SuperClass()); |
1177 // A finalized class has been checked for cycles. | 1186 // A finalized class has been checked for cycles. |
1178 // Using the hare and tortoise algorithm for locating cycles. | 1187 // Using the hare and tortoise algorithm for locating cycles. |
1179 while (!test1.is_finalized() && | 1188 while (!test1.is_finalized() && |
1180 !test2.IsNull() && !test2.is_finalized()) { | 1189 !test2.IsNull() && !test2.is_finalized()) { |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1500 void ClassFinalizer::ReportError(const char* format, ...) { | 1509 void ClassFinalizer::ReportError(const char* format, ...) { |
1501 va_list args; | 1510 va_list args; |
1502 va_start(args, format); | 1511 va_start(args, format); |
1503 const Error& error = Error::Handle( | 1512 const Error& error = Error::Handle( |
1504 Parser::FormatError(Script::Handle(), -1, "Error", format, args)); | 1513 Parser::FormatError(Script::Handle(), -1, "Error", format, args)); |
1505 va_end(args); | 1514 va_end(args); |
1506 ReportError(error); | 1515 ReportError(error); |
1507 } | 1516 } |
1508 | 1517 |
1509 } // namespace dart | 1518 } // namespace dart |
OLD | NEW |