Chromium Code Reviews| 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 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 250 "class '%s' and superclass '%s' are not " | 250 "class '%s' and superclass '%s' are not " |
| 251 "both classes or both interfaces", | 251 "both classes or both interfaces", |
| 252 class_name.ToCString(), | 252 class_name.ToCString(), |
| 253 super_class_name.ToCString()); | 253 super_class_name.ToCString()); |
| 254 } | 254 } |
| 255 // If cls belongs to core lib or to core lib's implementation, restrictions | 255 // If cls belongs to core lib or to core lib's implementation, restrictions |
| 256 // about allowed interfaces are lifted. | 256 // about allowed interfaces are lifted. |
| 257 if ((cls.library() != Library::CoreLibrary()) && | 257 if ((cls.library() != Library::CoreLibrary()) && |
| 258 (cls.library() != Library::CoreImplLibrary())) { | 258 (cls.library() != Library::CoreImplLibrary())) { |
| 259 // Prevent extending core implementation classes. | 259 // Prevent extending core implementation classes. |
| 260 bool is_error = false; | |
| 260 switch (super_class.id()) { | 261 switch (super_class.id()) { |
| 261 case kNumberCid: | 262 case kNumberCid: |
| 262 case kIntegerCid: | 263 case kIntegerCid: |
| 263 case kSmiCid: | 264 case kSmiCid: |
| 264 case kMintCid: | 265 case kMintCid: |
| 265 case kBigintCid: | 266 case kBigintCid: |
| 266 case kDoubleCid: | 267 case kDoubleCid: |
| 267 case kOneByteStringCid: | 268 case kOneByteStringCid: |
| 268 case kTwoByteStringCid: | 269 case kTwoByteStringCid: |
| 269 case kFourByteStringCid: | 270 case kFourByteStringCid: |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 288 case kExternalUint32ArrayCid: | 289 case kExternalUint32ArrayCid: |
| 289 case kInt64ArrayCid: | 290 case kInt64ArrayCid: |
| 290 case kExternalInt64ArrayCid: | 291 case kExternalInt64ArrayCid: |
| 291 case kUint64ArrayCid: | 292 case kUint64ArrayCid: |
| 292 case kExternalUint64ArrayCid: | 293 case kExternalUint64ArrayCid: |
| 293 case kFloat32ArrayCid: | 294 case kFloat32ArrayCid: |
| 294 case kExternalFloat32ArrayCid: | 295 case kExternalFloat32ArrayCid: |
| 295 case kFloat64ArrayCid: | 296 case kFloat64ArrayCid: |
| 296 case kExternalFloat64ArrayCid: | 297 case kExternalFloat64ArrayCid: |
| 297 case kDartFunctionCid: | 298 case kDartFunctionCid: |
| 298 case kWeakPropertyCid: { | 299 case kWeakPropertyCid: |
| 299 const Script& script = Script::Handle(cls.script()); | 300 is_error = true; |
| 300 ReportError(script, cls.token_pos(), | |
| 301 "'%s' is not allowed to extend '%s'", | |
| 302 String::Handle(cls.Name()).ToCString(), | |
| 303 String::Handle(super_class.Name()).ToCString()); | |
| 304 break; | 301 break; |
| 305 } | 302 default: |
| 306 default: break; | 303 // Special case: classes for which we don't have a known class id. |
| 304 if (Type::Handle(Type::Double()).type_class() == super_class.raw()) { | |
| 305 is_error = true; | |
| 306 } | |
|
siva
2012/08/29 23:49:36
I presume this is tied to the TODO you have in dou
| |
| 307 break; | |
| 308 } | |
| 309 if (is_error) { | |
| 310 const Script& script = Script::Handle(cls.script()); | |
| 311 ReportError(script, cls.token_pos(), | |
| 312 "'%s' is not allowed to extend '%s'", | |
| 313 String::Handle(cls.Name()).ToCString(), | |
| 314 String::Handle(super_class.Name()).ToCString()); | |
| 307 } | 315 } |
| 308 } | 316 } |
| 309 return; | 317 return; |
| 310 } | 318 } |
| 311 | 319 |
| 312 | 320 |
| 313 void ClassFinalizer::ResolveFactoryClass(const Class& interface) { | 321 void ClassFinalizer::ResolveFactoryClass(const Class& interface) { |
| 314 ASSERT(interface.is_interface()); | 322 ASSERT(interface.is_interface()); |
| 315 if (interface.is_finalized() || | 323 if (interface.is_finalized() || |
| 316 !interface.HasFactoryClass() || | 324 !interface.HasFactoryClass() || |
| (...skipping 903 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1220 String::Handle(interface_class.Name()).ToCString()); | 1228 String::Handle(interface_class.Name()).ToCString()); |
| 1221 } | 1229 } |
| 1222 // Verify that unless cls belongs to core lib, it cannot extend or implement | 1230 // Verify that unless cls belongs to core lib, it cannot extend or implement |
| 1223 // any of bool, num, int, double, String, Function, Dynamic. | 1231 // any of bool, num, int, double, String, Function, Dynamic. |
| 1224 // The exception is signature classes, which are compiler generated and | 1232 // The exception is signature classes, which are compiler generated and |
| 1225 // represent a function type, therefore implementing the Function interface. | 1233 // represent a function type, therefore implementing the Function interface. |
| 1226 if (!cls_belongs_to_core_lib) { | 1234 if (!cls_belongs_to_core_lib) { |
| 1227 if (interface.IsBoolInterface() || | 1235 if (interface.IsBoolInterface() || |
| 1228 interface.IsNumberType() || | 1236 interface.IsNumberType() || |
| 1229 interface.IsIntInterface() || | 1237 interface.IsIntInterface() || |
| 1230 interface.IsDoubleInterface() || | 1238 interface.IsDoubleType() || |
| 1231 interface.IsStringInterface() || | 1239 interface.IsStringInterface() || |
| 1232 (interface.IsFunctionType() && !cls.IsSignatureClass()) || | 1240 (interface.IsFunctionType() && !cls.IsSignatureClass()) || |
| 1233 interface.IsDynamicType()) { | 1241 interface.IsDynamicType()) { |
| 1234 const Script& script = Script::Handle(cls.script()); | 1242 const Script& script = Script::Handle(cls.script()); |
| 1235 ReportError(script, cls.token_pos(), | 1243 ReportError(script, cls.token_pos(), |
| 1236 "'%s' is not allowed to extend or implement '%s'", | 1244 "'%s' is not allowed to extend or implement '%s'", |
| 1237 String::Handle(cls.Name()).ToCString(), | 1245 String::Handle(cls.Name()).ToCString(), |
| 1238 String::Handle(interface_class.Name()).ToCString()); | 1246 String::Handle(interface_class.Name()).ToCString()); |
| 1239 } | 1247 } |
| 1240 } | 1248 } |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1392 void ClassFinalizer::ReportError(const char* format, ...) { | 1400 void ClassFinalizer::ReportError(const char* format, ...) { |
| 1393 va_list args; | 1401 va_list args; |
| 1394 va_start(args, format); | 1402 va_start(args, format); |
| 1395 const Error& error = Error::Handle( | 1403 const Error& error = Error::Handle( |
| 1396 Parser::FormatError(Script::Handle(), -1, "Error", format, args)); | 1404 Parser::FormatError(Script::Handle(), -1, "Error", format, args)); |
| 1397 va_end(args); | 1405 va_end(args); |
| 1398 ReportError(error); | 1406 ReportError(error); |
| 1399 } | 1407 } |
| 1400 | 1408 |
| 1401 } // namespace dart | 1409 } // namespace dart |
| OLD | NEW |