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 #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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 55 return Handle(isolate, object::null()); \ | 55 return Handle(isolate, object::null()); \ |
| 56 } \ | 56 } \ |
| 57 static object& Handle(Raw##object* raw_ptr) { \ | 57 static object& Handle(Raw##object* raw_ptr) { \ |
| 58 return Handle(Isolate::Current(), raw_ptr); \ | 58 return Handle(Isolate::Current(), raw_ptr); \ |
| 59 } \ | 59 } \ |
| 60 static object& CheckedHandle(Isolate* isolate, RawObject* raw_ptr) { \ | 60 static object& CheckedHandle(Isolate* isolate, RawObject* raw_ptr) { \ |
| 61 object* obj = \ | 61 object* obj = \ |
| 62 reinterpret_cast<object*>(VMHandles::AllocateHandle(isolate)); \ | 62 reinterpret_cast<object*>(VMHandles::AllocateHandle(isolate)); \ |
| 63 initializeHandle(obj, raw_ptr); \ | 63 initializeHandle(obj, raw_ptr); \ |
| 64 if (!obj->Is##object()) { \ | 64 if (!obj->Is##object()) { \ |
| 65 FATAL("Handle check failed."); \ | 65 FATAL2("Handle check failed: saw %s expected %s", \ |
| 66 obj->GetClassName(), #object); \ | |
|
Ivan Posva
2012/08/03 20:13:10
What would happen if you used ToCString() here, in
| |
| 66 } \ | 67 } \ |
| 67 return *obj; \ | 68 return *obj; \ |
| 68 } \ | 69 } \ |
| 69 static object& CheckedHandle(RawObject* raw_ptr) { \ | 70 static object& CheckedHandle(RawObject* raw_ptr) { \ |
| 70 return CheckedHandle(Isolate::Current(), raw_ptr); \ | 71 return CheckedHandle(Isolate::Current(), raw_ptr); \ |
| 71 } \ | 72 } \ |
| 72 static object& ZoneHandle(Isolate* isolate, Raw##object* raw_ptr) { \ | 73 static object& ZoneHandle(Isolate* isolate, Raw##object* raw_ptr) { \ |
| 73 object* obj = reinterpret_cast<object*>( \ | 74 object* obj = reinterpret_cast<object*>( \ |
| 74 VMHandles::AllocateZoneHandle(isolate)); \ | 75 VMHandles::AllocateZoneHandle(isolate)); \ |
| 75 initializeHandle(obj, raw_ptr); \ | 76 initializeHandle(obj, raw_ptr); \ |
| 76 return *obj; \ | 77 return *obj; \ |
| 77 } \ | 78 } \ |
| 78 static object& ZoneHandle() { \ | 79 static object& ZoneHandle() { \ |
| 79 return ZoneHandle(Isolate::Current(), object::null()); \ | 80 return ZoneHandle(Isolate::Current(), object::null()); \ |
| 80 } \ | 81 } \ |
| 81 static object& ZoneHandle(Raw##object* raw_ptr) { \ | 82 static object& ZoneHandle(Raw##object* raw_ptr) { \ |
| 82 return ZoneHandle(Isolate::Current(), raw_ptr); \ | 83 return ZoneHandle(Isolate::Current(), raw_ptr); \ |
| 83 } \ | 84 } \ |
| 84 static object& CheckedZoneHandle(Isolate* isolate, RawObject* raw_ptr) { \ | 85 static object& CheckedZoneHandle(Isolate* isolate, RawObject* raw_ptr) { \ |
| 85 object* obj = reinterpret_cast<object*>( \ | 86 object* obj = reinterpret_cast<object*>( \ |
| 86 VMHandles::AllocateZoneHandle(isolate)); \ | 87 VMHandles::AllocateZoneHandle(isolate)); \ |
| 87 initializeHandle(obj, raw_ptr); \ | 88 initializeHandle(obj, raw_ptr); \ |
| 88 if (!obj->Is##object()) { \ | 89 if (!obj->Is##object()) { \ |
| 89 FATAL("Handle check failed."); \ | 90 FATAL2("Handle check failed: saw %s expected %s", \ |
| 91 obj->GetClassName(), #object); \ | |
| 90 } \ | 92 } \ |
| 91 return *obj; \ | 93 return *obj; \ |
| 92 } \ | 94 } \ |
| 93 static object& CheckedZoneHandle(RawObject* raw_ptr) { \ | 95 static object& CheckedZoneHandle(RawObject* raw_ptr) { \ |
| 94 return CheckedZoneHandle(Isolate::Current(), raw_ptr); \ | 96 return CheckedZoneHandle(Isolate::Current(), raw_ptr); \ |
| 95 } \ | 97 } \ |
| 96 /* T::Cast cannot be applied to a null Object, because the object vtable */ \ | 98 /* T::Cast cannot be applied to a null Object, because the object vtable */ \ |
| 97 /* is not setup for type T, although some methods are supposed to work */ \ | 99 /* is not setup for type T, although some methods are supposed to work */ \ |
| 98 /* with null, for example Instance::Equals(). */ \ | 100 /* with null, for example Instance::Equals(). */ \ |
| 99 static const object& Cast(const Object& obj) { \ | 101 static const object& Cast(const Object& obj) { \ |
| 100 ASSERT(obj.Is##object()); \ | 102 ASSERT(obj.Is##object()); \ |
| 101 return reinterpret_cast<const object&>(obj); \ | 103 return reinterpret_cast<const object&>(obj); \ |
| 102 } \ | 104 } \ |
| 103 static Raw##object* null() { \ | 105 static Raw##object* null() { \ |
| 104 return reinterpret_cast<Raw##object*>(Object::null()); \ | 106 return reinterpret_cast<Raw##object*>(Object::null()); \ |
| 105 } \ | 107 } \ |
| 106 virtual const char* ToCString() const; \ | 108 virtual const char* ToCString() const; \ |
| 109 virtual const char* GetClassName() const { return #object; } \ | |
| 107 static const ObjectKind kInstanceKind = k##object; \ | 110 static const ObjectKind kInstanceKind = k##object; \ |
| 108 protected: /* NOLINT */ \ | 111 protected: /* NOLINT */ \ |
| 109 object() : super() {} \ | 112 object() : super() {} \ |
| 110 private: /* NOLINT */ \ | 113 private: /* NOLINT */ \ |
| 111 /* Initialize the handle based on the raw_ptr in the presence of null. */ \ | 114 /* Initialize the handle based on the raw_ptr in the presence of null. */ \ |
| 112 static void initializeHandle(object* obj, RawObject* raw_ptr) { \ | 115 static void initializeHandle(object* obj, RawObject* raw_ptr) { \ |
| 113 if (raw_ptr != Object::null()) { \ | 116 if (raw_ptr != Object::null()) { \ |
| 114 obj->SetRaw(raw_ptr); \ | 117 obj->SetRaw(raw_ptr); \ |
| 115 } else { \ | 118 } else { \ |
| 116 obj->raw_ = Object::null(); \ | 119 obj->raw_ = Object::null(); \ |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 218 | 221 |
| 219 bool IsNull() const { return raw_ == null_; } | 222 bool IsNull() const { return raw_ == null_; } |
| 220 | 223 |
| 221 virtual const char* ToCString() const { | 224 virtual const char* ToCString() const { |
| 222 if (IsNull()) { | 225 if (IsNull()) { |
| 223 return "null"; | 226 return "null"; |
| 224 } else { | 227 } else { |
| 225 return "Object"; | 228 return "Object"; |
| 226 } | 229 } |
| 227 } | 230 } |
| 231 virtual const char* GetClassName() const { | |
| 232 return "Object"; | |
| 233 } | |
| 228 | 234 |
| 229 bool IsNew() const { return raw()->IsNewObject(); } | 235 bool IsNew() const { return raw()->IsNewObject(); } |
| 230 bool IsOld() const { return raw()->IsOldObject(); } | 236 bool IsOld() const { return raw()->IsOldObject(); } |
| 231 | 237 |
| 232 // Print the object on stdout for debugging. | 238 // Print the object on stdout for debugging. |
| 233 void Print() const; | 239 void Print() const; |
| 234 | 240 |
| 235 bool IsZoneHandle() const { | 241 bool IsZoneHandle() const { |
| 236 return VMHandles::IsZoneHandle(reinterpret_cast<uword>(this)); | 242 return VMHandles::IsZoneHandle(reinterpret_cast<uword>(this)); |
| 237 } | 243 } |
| (...skipping 5131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5369 if (this->CharAt(i) != str.CharAt(begin_index + i)) { | 5375 if (this->CharAt(i) != str.CharAt(begin_index + i)) { |
| 5370 return false; | 5376 return false; |
| 5371 } | 5377 } |
| 5372 } | 5378 } |
| 5373 return true; | 5379 return true; |
| 5374 } | 5380 } |
| 5375 | 5381 |
| 5376 } // namespace dart | 5382 } // namespace dart |
| 5377 | 5383 |
| 5378 #endif // VM_OBJECT_H_ | 5384 #endif // VM_OBJECT_H_ |
| OLD | NEW |