Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: runtime/vm/object.h

Issue 9664029: Fix type check to perform a subtype test at top level instead of an (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/exceptions.cc ('k') | runtime/vm/object.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #ifndef VM_OBJECT_H_ 5 #ifndef VM_OBJECT_H_
6 #define VM_OBJECT_H_ 6 #define VM_OBJECT_H_
7 7
8 #include "include/dart_api.h" 8 #include "include/dart_api.h"
9 #include "platform/assert.h" 9 #include "platform/assert.h"
10 #include "platform/utils.h" 10 #include "platform/utils.h"
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 static RawError* Init(Isolate* isolate); 317 static RawError* Init(Isolate* isolate);
318 static void InitFromSnapshot(Isolate* isolate); 318 static void InitFromSnapshot(Isolate* isolate);
319 static void InitOnce(); 319 static void InitOnce();
320 320
321 static intptr_t InstanceSize() { 321 static intptr_t InstanceSize() {
322 return RoundedAllocationSize(sizeof(RawObject)); 322 return RoundedAllocationSize(sizeof(RawObject));
323 } 323 }
324 324
325 static const ObjectKind kInstanceKind = kObject; 325 static const ObjectKind kInstanceKind = kObject;
326 326
327 enum TypeTestKind {
328 kIsSubtypeOf,
329 kIsAssignableTo
330 };
331
332 protected: 327 protected:
333 // Used for extracting the C++ vtable during bringup. 328 // Used for extracting the C++ vtable during bringup.
334 Object() : raw_(null_) {} 329 Object() : raw_(null_) {}
335 330
336 uword raw_value() const { 331 uword raw_value() const {
337 return reinterpret_cast<uword>(raw()); 332 return reinterpret_cast<uword>(raw());
338 } 333 }
339 334
340 inline void SetRaw(RawObject* value); 335 inline void SetRaw(RawObject* value);
341 336
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 559
565 // Check if this class represents a signature class. 560 // Check if this class represents a signature class.
566 bool IsSignatureClass() const { 561 bool IsSignatureClass() const {
567 return signature_function() != Object::null(); 562 return signature_function() != Object::null();
568 } 563 }
569 564
570 // Check if this class represents a canonical signature class, i.e. not an 565 // Check if this class represents a canonical signature class, i.e. not an
571 // alias as defined in a typedef. 566 // alias as defined in a typedef.
572 bool IsCanonicalSignatureClass() const; 567 bool IsCanonicalSignatureClass() const;
573 568
574 // Check the "more specific than" relationship.
575 bool IsMoreSpecificThan(
576 const AbstractTypeArguments& type_arguments,
577 const Class& other,
578 const AbstractTypeArguments& other_type_arguments,
579 Error* malformed_error) const;
580
581 // Check the subtype relationship. 569 // Check the subtype relationship.
582 bool IsSubtypeOf(const AbstractTypeArguments& type_arguments, 570 bool IsSubtypeOf(const AbstractTypeArguments& type_arguments,
583 const Class& other, 571 const Class& other,
584 const AbstractTypeArguments& other_type_arguments, 572 const AbstractTypeArguments& other_type_arguments,
585 Error* malformed_error) const { 573 Error* malformed_error) const;
586 return TestType(kIsSubtypeOf,
587 type_arguments,
588 other,
589 other_type_arguments,
590 malformed_error);
591 }
592
593 // Check the assignability relationship.
594 bool IsAssignableTo(const AbstractTypeArguments& type_arguments,
595 const Class& dst,
596 const AbstractTypeArguments& dst_type_arguments,
597 Error* malformed_error) const {
598 return TestType(kIsAssignableTo,
599 type_arguments,
600 dst,
601 dst_type_arguments,
602 malformed_error);
603 }
604 574
605 // Check if this is the top level class. 575 // Check if this is the top level class.
606 bool IsTopLevel() const; 576 bool IsTopLevel() const;
607 577
608 RawArray* fields() const { return raw_ptr()->fields_; } 578 RawArray* fields() const { return raw_ptr()->fields_; }
609 void SetFields(const Array& value) const; 579 void SetFields(const Array& value) const;
610 580
611 RawArray* functions() const { return raw_ptr()->functions_; } 581 RawArray* functions() const { return raw_ptr()->functions_; }
612 void SetFunctions(const Array& value) const; 582 void SetFunctions(const Array& value) const;
613 583
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 void set_signature_type(const AbstractType& value) const; 681 void set_signature_type(const AbstractType& value) const;
712 void set_class_state(int8_t state) const; 682 void set_class_state(int8_t state) const;
713 683
714 void set_constants(const Array& value) const; 684 void set_constants(const Array& value) const;
715 685
716 void set_canonical_types(const Array& value) const; 686 void set_canonical_types(const Array& value) const;
717 RawArray* canonical_types() const; 687 RawArray* canonical_types() const;
718 688
719 void CalculateFieldOffsets() const; 689 void CalculateFieldOffsets() const;
720 690
721 // Check the subtype or assignability relationship.
722 bool TestType(TypeTestKind test,
723 const AbstractTypeArguments& type_arguments,
724 const Class& other,
725 const AbstractTypeArguments& other_type_arguments,
726 Error* malformed_error) const;
727
728 // Assigns empty array to all raw class array fields. 691 // Assigns empty array to all raw class array fields.
729 void InitEmptyFields(); 692 void InitEmptyFields();
730 693
731 RawFunction* LookupAccessorFunction(const char* prefix, 694 RawFunction* LookupAccessorFunction(const char* prefix,
732 intptr_t prefix_length, 695 intptr_t prefix_length,
733 const String& name) const; 696 const String& name) const;
734 697
735 HEAP_OBJECT_IMPLEMENTATION(Class, Object); 698 HEAP_OBJECT_IMPLEMENTATION(Class, Object);
736 friend class Object; 699 friend class Object;
737 friend class Instance; 700 friend class Instance;
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
855 818
856 // Check if this type is an interface type. 819 // Check if this type is an interface type.
857 bool IsInterfaceType() const { 820 bool IsInterfaceType() const {
858 if (!HasResolvedTypeClass()) { 821 if (!HasResolvedTypeClass()) {
859 return false; 822 return false;
860 } 823 }
861 const Class& cls = Class::Handle(type_class()); 824 const Class& cls = Class::Handle(type_class());
862 return !cls.IsNull() && cls.is_interface(); 825 return !cls.IsNull() && cls.is_interface();
863 } 826 }
864 827
865 // Check the "more specific than" relationship.
866 bool IsMoreSpecificThan(const AbstractType& other,
867 Error* malformed_error) const;
868
869 // Check the subtype relationship. 828 // Check the subtype relationship.
870 bool IsSubtypeOf(const AbstractType& other, Error* malformed_error) const { 829 bool IsSubtypeOf(const AbstractType& other, Error* malformed_error) const;
871 return Test(kIsSubtypeOf, other, malformed_error);
872 }
873
874 // Check the assignability relationship.
875 bool IsAssignableTo(const AbstractType& dst,
876 Error* malformed_error) const {
877 return Test(kIsAssignableTo, dst, malformed_error);
878 }
879 830
880 static RawAbstractType* NewTypeParameter(intptr_t index, 831 static RawAbstractType* NewTypeParameter(intptr_t index,
881 const String& name, 832 const String& name,
882 intptr_t token_index); 833 intptr_t token_index);
883 834
884 static RawAbstractType* NewInstantiatedType( 835 static RawAbstractType* NewInstantiatedType(
885 const AbstractType& uninstantiated_type, 836 const AbstractType& uninstantiated_type,
886 const AbstractTypeArguments& instantiator_type_arguments); 837 const AbstractTypeArguments& instantiator_type_arguments);
887 838
888 protected: 839 protected:
889 // Check the subtype or assignability relationship.
890 bool Test(TypeTestKind test,
891 const AbstractType& other,
892 Error* malformed_error) const;
893
894 HEAP_OBJECT_IMPLEMENTATION(AbstractType, Object); 840 HEAP_OBJECT_IMPLEMENTATION(AbstractType, Object);
895 friend class Class; 841 friend class Class;
896 }; 842 };
897 843
898 844
899 // A Type consists of a class, possibly parameterized with type 845 // A Type consists of a class, possibly parameterized with type
900 // arguments. Example: C<T1, T2>. 846 // arguments. Example: C<T1, T2>.
901 // An unresolved class is a String specifying the class name. 847 // An unresolved class is a String specifying the class name.
902 class Type : public AbstractType { 848 class Type : public AbstractType {
903 public: 849 public:
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
1094 // Check if this type argument vector consists solely of DynamicType, 1040 // Check if this type argument vector consists solely of DynamicType,
1095 // considering only a prefix of length 'len'. 1041 // considering only a prefix of length 'len'.
1096 bool IsDynamicTypes(intptr_t len) const; 1042 bool IsDynamicTypes(intptr_t len) const;
1097 1043
1098 // Check that this type argument vector is within the declared bounds of the 1044 // Check that this type argument vector is within the declared bounds of the
1099 // given class or interface. If not, set malformed_error (if not yet set). 1045 // given class or interface. If not, set malformed_error (if not yet set).
1100 bool IsWithinBoundsOf(const Class& cls, 1046 bool IsWithinBoundsOf(const Class& cls,
1101 const AbstractTypeArguments& bounds_instantiator, 1047 const AbstractTypeArguments& bounds_instantiator,
1102 Error* malformed_error) const; 1048 Error* malformed_error) const;
1103 1049
1104 // Check the "more specific than" relationship, considering only a prefix of 1050 // Check the subtype relationship, considering only a prefix of length 'len'.
1105 // length 'len'. 1051 bool IsSubtypeOf(const AbstractTypeArguments& other,
1106 bool IsMoreSpecificThan(const AbstractTypeArguments& other, 1052 intptr_t len,
1107 intptr_t len, 1053 Error* malformed_error) const;
1108 Error* malformed_error) const;
1109 1054
1110 bool Equals(const AbstractTypeArguments& other) const; 1055 bool Equals(const AbstractTypeArguments& other) const;
1111 1056
1112 // UNREACHABLEs as AbstractTypeArguments is an abstract class. 1057 // UNREACHABLEs as AbstractTypeArguments is an abstract class.
1113 virtual intptr_t Length() const; 1058 virtual intptr_t Length() const;
1114 virtual RawAbstractType* TypeAt(intptr_t index) const; 1059 virtual RawAbstractType* TypeAt(intptr_t index) const;
1115 virtual void SetTypeAt(intptr_t index, const AbstractType& value) const; 1060 virtual void SetTypeAt(intptr_t index, const AbstractType& value) const;
1116 virtual bool IsResolved() const; 1061 virtual bool IsResolved() const;
1117 virtual bool IsInstantiated() const; 1062 virtual bool IsInstantiated() const;
1118 virtual bool IsUninstantiatedIdentity() const; 1063 virtual bool IsUninstantiatedIdentity() const;
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
1404 // Returns true if this function has parameters that are compatible with the 1349 // Returns true if this function has parameters that are compatible with the
1405 // parameters of the other function in order for this function to override the 1350 // parameters of the other function in order for this function to override the
1406 // other function. Parameter types are ignored. 1351 // other function. Parameter types are ignored.
1407 bool HasCompatibleParametersWith(const Function& other) const; 1352 bool HasCompatibleParametersWith(const Function& other) const;
1408 1353
1409 // Returns true if the type of this function is a subtype of the type of 1354 // Returns true if the type of this function is a subtype of the type of
1410 // the other function. 1355 // the other function.
1411 bool IsSubtypeOf(const AbstractTypeArguments& type_arguments, 1356 bool IsSubtypeOf(const AbstractTypeArguments& type_arguments,
1412 const Function& other, 1357 const Function& other,
1413 const AbstractTypeArguments& other_type_arguments, 1358 const AbstractTypeArguments& other_type_arguments,
1414 Error* malformed_error) const { 1359 Error* malformed_error) const;
1415 return TestType(kIsSubtypeOf,
1416 type_arguments,
1417 other,
1418 other_type_arguments,
1419 malformed_error);
1420 }
1421
1422 // Returns true if the type of this function can be assigned to the type of
1423 // the destination function.
1424 bool IsAssignableTo(const AbstractTypeArguments& type_arguments,
1425 const Function& dst,
1426 const AbstractTypeArguments& dst_type_arguments,
1427 Error* malformed_error) const {
1428 return TestType(kIsAssignableTo,
1429 type_arguments,
1430 dst,
1431 dst_type_arguments,
1432 malformed_error);
1433 }
1434 1360
1435 // Returns true if this function represents a (possibly implicit) closure 1361 // Returns true if this function represents a (possibly implicit) closure
1436 // function. 1362 // function.
1437 bool IsClosureFunction() const { 1363 bool IsClosureFunction() const {
1438 return kind() == RawFunction::kClosureFunction; 1364 return kind() == RawFunction::kClosureFunction;
1439 } 1365 }
1440 1366
1441 // Returns true if this function represents an implicit closure function. 1367 // Returns true if this function represents an implicit closure function.
1442 bool IsImplicitClosureFunction() const; 1368 bool IsImplicitClosureFunction() const;
1443 1369
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1497 void set_is_static(bool is_static) const; 1423 void set_is_static(bool is_static) const;
1498 void set_is_const(bool is_const) const; 1424 void set_is_const(bool is_const) const;
1499 void set_parent_function(const Function& value) const; 1425 void set_parent_function(const Function& value) const;
1500 void set_token_index(intptr_t value) const; 1426 void set_token_index(intptr_t value) const;
1501 void set_implicit_closure_function(const Function& value) const; 1427 void set_implicit_closure_function(const Function& value) const;
1502 static RawFunction* New(); 1428 static RawFunction* New();
1503 1429
1504 RawString* BuildSignature(bool instantiate, 1430 RawString* BuildSignature(bool instantiate,
1505 const AbstractTypeArguments& instantiator) const; 1431 const AbstractTypeArguments& instantiator) const;
1506 1432
1507 // Checks the subtype or assignability relationship between the type of this
1508 // function and the type of the other function.
1509 bool TestType(TypeTestKind test,
1510 const AbstractTypeArguments& type_arguments,
1511 const Function& other,
1512 const AbstractTypeArguments& other_type_arguments,
1513 Error* malformed_error) const;
1514
1515 // Checks the type of the formal parameter at the given position for 1433 // Checks the type of the formal parameter at the given position for
1516 // assignability relationship between the type of this function and the type 1434 // assignability relationship between the type of this function and the type
1517 // of the other function. 1435 // of the other function.
1518 bool TestParameterType( 1436 bool TestParameterType(
1519 intptr_t parameter_position, 1437 intptr_t parameter_position,
1520 const AbstractTypeArguments& type_arguments, 1438 const AbstractTypeArguments& type_arguments,
1521 const Function& other, 1439 const Function& other,
1522 const AbstractTypeArguments& other_type_arguments, 1440 const AbstractTypeArguments& other_type_arguments,
1523 Error* malformed_error) const; 1441 Error* malformed_error) const;
1524 1442
(...skipping 1025 matching lines...) Expand 10 before | Expand all | Expand 10 after
2550 2468
2551 void SetField(const Field& field, const Object& value) const { 2469 void SetField(const Field& field, const Object& value) const {
2552 StorePointer(FieldAddr(field), value.raw()); 2470 StorePointer(FieldAddr(field), value.raw());
2553 } 2471 }
2554 2472
2555 RawType* GetType() const; 2473 RawType* GetType() const;
2556 2474
2557 virtual RawAbstractTypeArguments* GetTypeArguments() const; 2475 virtual RawAbstractTypeArguments* GetTypeArguments() const;
2558 virtual void SetTypeArguments(const AbstractTypeArguments& value) const; 2476 virtual void SetTypeArguments(const AbstractTypeArguments& value) const;
2559 2477
2560 // Check if this instance is an instance of the given type. 2478 // Check if the type of this instance is a subtype of the given type.
2561 bool IsInstanceOf(const AbstractType& type, 2479 bool IsInstanceOf(const AbstractType& type,
2562 const AbstractTypeArguments& type_instantiator, 2480 const AbstractTypeArguments& type_instantiator,
2563 Error* malformed_error) const { 2481 Error* malformed_error) const;
2564 return TestType(kIsSubtypeOf, type, type_instantiator, malformed_error);
2565 }
2566
2567 // Check if this instance is assignable to the given type.
2568 bool IsAssignableTo(const AbstractType& type,
2569 const AbstractTypeArguments& type_instantiator,
2570 Error* malformed_error) const {
2571 return TestType(kIsAssignableTo, type, type_instantiator, malformed_error);
2572 }
2573 2482
2574 bool IsValidNativeIndex(int index) const; 2483 bool IsValidNativeIndex(int index) const;
2575 2484
2576 intptr_t GetNativeField(int index) const { 2485 intptr_t GetNativeField(int index) const {
2577 return *NativeFieldAddr(index); 2486 return *NativeFieldAddr(index);
2578 } 2487 }
2579 2488
2580 void SetNativeField(int index, intptr_t value) const { 2489 void SetNativeField(int index, intptr_t value) const {
2581 *NativeFieldAddr(index) = value; 2490 *NativeFieldAddr(index) = value;
2582 } 2491 }
(...skipping 16 matching lines...) Expand all
2599 ASSERT(IsValidNativeIndex(index)); 2508 ASSERT(IsValidNativeIndex(index));
2600 return reinterpret_cast<intptr_t*>((raw_value() - kHeapObjectTag) 2509 return reinterpret_cast<intptr_t*>((raw_value() - kHeapObjectTag)
2601 + (index * kWordSize) 2510 + (index * kWordSize)
2602 + sizeof(RawObject)); 2511 + sizeof(RawObject));
2603 } 2512 }
2604 void SetFieldAtOffset(intptr_t offset, const Object& value) const { 2513 void SetFieldAtOffset(intptr_t offset, const Object& value) const {
2605 StorePointer(FieldAddrAtOffset(offset), value.raw()); 2514 StorePointer(FieldAddrAtOffset(offset), value.raw());
2606 } 2515 }
2607 bool IsValidFieldOffset(int offset) const; 2516 bool IsValidFieldOffset(int offset) const;
2608 2517
2609 // Check the subtype or assignability relationship between the type of this
2610 // instance and the given type.
2611 bool TestType(TypeTestKind test,
2612 const AbstractType& type,
2613 const AbstractTypeArguments& type_instantiator,
2614 Error* malformed_error) const;
2615
2616 // TODO(iposva): Determine if this gets in the way of Smi. 2518 // TODO(iposva): Determine if this gets in the way of Smi.
2617 HEAP_OBJECT_IMPLEMENTATION(Instance, Object); 2519 HEAP_OBJECT_IMPLEMENTATION(Instance, Object);
2618 friend class Class; 2520 friend class Class;
2619 }; 2521 };
2620 2522
2621 2523
2622 class Number : public Instance { 2524 class Number : public Instance {
2623 public: 2525 public:
2624 // TODO(iposva): Fill in a useful Number interface. 2526 // TODO(iposva): Fill in a useful Number interface.
2625 virtual bool IsZero() const { 2527 virtual bool IsZero() const {
(...skipping 1300 matching lines...) Expand 10 before | Expand all | Expand 10 after
3926 } 3828 }
3927 3829
3928 3830
3929 void Context::SetAt(intptr_t index, const Instance& value) const { 3831 void Context::SetAt(intptr_t index, const Instance& value) const {
3930 StorePointer(InstanceAddr(index), value.raw()); 3832 StorePointer(InstanceAddr(index), value.raw());
3931 } 3833 }
3932 3834
3933 } // namespace dart 3835 } // namespace dart
3934 3836
3935 #endif // VM_OBJECT_H_ 3837 #endif // VM_OBJECT_H_
OLDNEW
« no previous file with comments | « runtime/vm/exceptions.cc ('k') | runtime/vm/object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698