| 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 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 if (cls.is_finalized()) { | 312 if (cls.is_finalized()) { |
| 313 return; | 313 return; |
| 314 } | 314 } |
| 315 Type& super_type = Type::Handle(cls.super_type()); | 315 Type& super_type = Type::Handle(cls.super_type()); |
| 316 if (super_type.IsNull()) { | 316 if (super_type.IsNull()) { |
| 317 return; | 317 return; |
| 318 } | 318 } |
| 319 // Resolve failures lead to a longjmp. | 319 // Resolve failures lead to a longjmp. |
| 320 ResolveType(cls, super_type, kCanonicalizeWellFormed); | 320 ResolveType(cls, super_type, kCanonicalizeWellFormed); |
| 321 const Class& super_class = Class::Handle(super_type.type_class()); | 321 const Class& super_class = Class::Handle(super_type.type_class()); |
| 322 if (cls.is_interface() != super_class.is_interface()) { | |
| 323 String& class_name = String::Handle(cls.Name()); | |
| 324 String& super_class_name = String::Handle(super_class.Name()); | |
| 325 const Script& script = Script::Handle(cls.script()); | |
| 326 ReportError(script, cls.token_pos(), | |
| 327 "class '%s' and superclass '%s' are not " | |
| 328 "both classes or both interfaces", | |
| 329 class_name.ToCString(), | |
| 330 super_class_name.ToCString()); | |
| 331 } | |
| 332 // If cls belongs to core lib or to core lib's implementation, restrictions | 322 // If cls belongs to core lib or to core lib's implementation, restrictions |
| 333 // about allowed interfaces are lifted. | 323 // about allowed interfaces are lifted. |
| 334 if (cls.library() != Library::CoreLibrary()) { | 324 if (cls.library() != Library::CoreLibrary()) { |
| 335 // Prevent extending core implementation classes. | 325 // Prevent extending core implementation classes. |
| 336 bool is_error = false; | 326 bool is_error = false; |
| 337 switch (super_class.id()) { | 327 switch (super_class.id()) { |
| 338 case kNumberCid: | 328 case kNumberCid: |
| 339 case kIntegerCid: | 329 case kIntegerCid: |
| 340 case kSmiCid: | 330 case kSmiCid: |
| 341 case kMintCid: | 331 case kMintCid: |
| (...skipping 793 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1135 for (int i = 0; i < interfaces.Length(); i++) { | 1125 for (int i = 0; i < interfaces.Length(); i++) { |
| 1136 super_class ^= interfaces.At(i); | 1126 super_class ^= interfaces.At(i); |
| 1137 overridden_function = super_class.LookupDynamicFunction(function_name); | 1127 overridden_function = super_class.LookupDynamicFunction(function_name); |
| 1138 if (!overridden_function.IsNull() && | 1128 if (!overridden_function.IsNull() && |
| 1139 !function.HasCompatibleParametersWith(overridden_function)) { | 1129 !function.HasCompatibleParametersWith(overridden_function)) { |
| 1140 // Function types are purposely not checked for subtyping. | 1130 // Function types are purposely not checked for subtyping. |
| 1141 const String& class_name = String::Handle(cls.Name()); | 1131 const String& class_name = String::Handle(cls.Name()); |
| 1142 const String& super_class_name = String::Handle(super_class.Name()); | 1132 const String& super_class_name = String::Handle(super_class.Name()); |
| 1143 const Script& script = Script::Handle(cls.script()); | 1133 const Script& script = Script::Handle(cls.script()); |
| 1144 ReportError(script, function.token_pos(), | 1134 ReportError(script, function.token_pos(), |
| 1145 "class '%s' overrides function '%s' of %s '%s' " | 1135 "class '%s' overrides function '%s' of super class '%s' " |
| 1146 "with incompatible parameters", | 1136 "with incompatible parameters", |
| 1147 class_name.ToCString(), | 1137 class_name.ToCString(), |
| 1148 function_name.ToCString(), | 1138 function_name.ToCString(), |
| 1149 super_class.is_interface() ? "interface" : "super class", | |
| 1150 super_class_name.ToCString()); | 1139 super_class_name.ToCString()); |
| 1151 } | 1140 } |
| 1152 } | 1141 } |
| 1153 } | 1142 } |
| 1154 if (function.IsGetterFunction()) { | 1143 if (function.IsGetterFunction()) { |
| 1155 name = Field::NameFromGetter(function_name); | 1144 name = Field::NameFromGetter(function_name); |
| 1156 super_class = FindSuperOwnerOfFunction(cls, name); | 1145 super_class = FindSuperOwnerOfFunction(cls, name); |
| 1157 if (!super_class.IsNull()) { | 1146 if (!super_class.IsNull()) { |
| 1158 const String& class_name = String::Handle(cls.Name()); | 1147 const String& class_name = String::Handle(cls.Name()); |
| 1159 const String& super_class_name = String::Handle(super_class.Name()); | 1148 const String& super_class_name = String::Handle(super_class.Name()); |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1440 "const class '%s' has non-final field '%s'", | 1429 "const class '%s' has non-final field '%s'", |
| 1441 class_name.ToCString(), field_name.ToCString()); | 1430 class_name.ToCString(), field_name.ToCString()); |
| 1442 } | 1431 } |
| 1443 } | 1432 } |
| 1444 } | 1433 } |
| 1445 | 1434 |
| 1446 | 1435 |
| 1447 void ClassFinalizer::PrintClassInformation(const Class& cls) { | 1436 void ClassFinalizer::PrintClassInformation(const Class& cls) { |
| 1448 HANDLESCOPE(Isolate::Current()); | 1437 HANDLESCOPE(Isolate::Current()); |
| 1449 const String& class_name = String::Handle(cls.Name()); | 1438 const String& class_name = String::Handle(cls.Name()); |
| 1450 OS::Print("%s '%s'", | 1439 OS::Print("class '%s'", class_name.ToCString()); |
| 1451 cls.is_interface() ? "interface" : "class", | |
| 1452 class_name.ToCString()); | |
| 1453 const Library& library = Library::Handle(cls.library()); | 1440 const Library& library = Library::Handle(cls.library()); |
| 1454 if (!library.IsNull()) { | 1441 if (!library.IsNull()) { |
| 1455 OS::Print(" library '%s%s':\n", | 1442 OS::Print(" library '%s%s':\n", |
| 1456 String::Handle(library.url()).ToCString(), | 1443 String::Handle(library.url()).ToCString(), |
| 1457 String::Handle(library.private_key()).ToCString()); | 1444 String::Handle(library.private_key()).ToCString()); |
| 1458 } else { | 1445 } else { |
| 1459 OS::Print(" (null library):\n"); | 1446 OS::Print(" (null library):\n"); |
| 1460 } | 1447 } |
| 1461 const Type& super_type = Type::Handle(cls.super_type()); | 1448 const Type& super_type = Type::Handle(cls.super_type()); |
| 1462 if (super_type.IsNull()) { | 1449 if (super_type.IsNull()) { |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1592 void ClassFinalizer::ReportError(const char* format, ...) { | 1579 void ClassFinalizer::ReportError(const char* format, ...) { |
| 1593 va_list args; | 1580 va_list args; |
| 1594 va_start(args, format); | 1581 va_start(args, format); |
| 1595 const Error& error = Error::Handle( | 1582 const Error& error = Error::Handle( |
| 1596 Parser::FormatError(Script::Handle(), -1, "Error", format, args)); | 1583 Parser::FormatError(Script::Handle(), -1, "Error", format, args)); |
| 1597 va_end(args); | 1584 va_end(args); |
| 1598 ReportError(error); | 1585 ReportError(error); |
| 1599 } | 1586 } |
| 1600 | 1587 |
| 1601 } // namespace dart | 1588 } // namespace dart |
| OLD | NEW |