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

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

Issue 18472009: JSONStream Print Dart Objects (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 5 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/json_test.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"
11 #include "vm/json_stream.h"
11 #include "vm/bitmap.h" 12 #include "vm/bitmap.h"
12 #include "vm/dart.h" 13 #include "vm/dart.h"
13 #include "vm/globals.h" 14 #include "vm/globals.h"
14 #include "vm/handles.h" 15 #include "vm/handles.h"
15 #include "vm/heap.h" 16 #include "vm/heap.h"
16 #include "vm/isolate.h" 17 #include "vm/isolate.h"
17 #include "vm/os.h" 18 #include "vm/os.h"
18 #include "vm/raw_object.h" 19 #include "vm/raw_object.h"
19 #include "vm/scanner.h" 20 #include "vm/scanner.h"
20 21
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 return reinterpret_cast<const object&>(obj); \ 113 return reinterpret_cast<const object&>(obj); \
113 } \ 114 } \
114 static Raw##object* RawCast(RawObject* raw) { \ 115 static Raw##object* RawCast(RawObject* raw) { \
115 ASSERT(Object::Handle(raw).Is##object()); \ 116 ASSERT(Object::Handle(raw).Is##object()); \
116 return reinterpret_cast<Raw##object*>(raw); \ 117 return reinterpret_cast<Raw##object*>(raw); \
117 } \ 118 } \
118 static Raw##object* null() { \ 119 static Raw##object* null() { \
119 return reinterpret_cast<Raw##object*>(Object::null()); \ 120 return reinterpret_cast<Raw##object*>(Object::null()); \
120 } \ 121 } \
121 virtual const char* ToCString() const; \ 122 virtual const char* ToCString() const; \
123 /* Object is printed as JSON into stream. If ref is true only a header */ \
124 /* with an object id is printed. If ref is false the object is fully */ \
125 /* printed. */ \
126 virtual void PrintToJSONStream(JSONStream* stream, bool ref = true) const; \
122 static const ClassId kClassId = k##object##Cid; \ 127 static const ClassId kClassId = k##object##Cid; \
123 private: /* NOLINT */ \ 128 private: /* NOLINT */ \
124 /* Initialize the handle based on the raw_ptr in the presence of null. */ \ 129 /* Initialize the handle based on the raw_ptr in the presence of null. */ \
125 static void initializeHandle(object* obj, RawObject* raw_ptr) { \ 130 static void initializeHandle(object* obj, RawObject* raw_ptr) { \
126 if (raw_ptr != Object::null()) { \ 131 if (raw_ptr != Object::null()) { \
127 obj->SetRaw(raw_ptr); \ 132 obj->SetRaw(raw_ptr); \
128 } else { \ 133 } else { \
129 obj->raw_ = Object::null(); \ 134 obj->raw_ = Object::null(); \
130 object fake_object; \ 135 object fake_object; \
131 obj->set_vtable(fake_object.vtable()); \ 136 obj->set_vtable(fake_object.vtable()); \
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 bool IsNull() const { return raw_ == null_; } 244 bool IsNull() const { return raw_ == null_; }
240 245
241 virtual const char* ToCString() const { 246 virtual const char* ToCString() const {
242 if (IsNull()) { 247 if (IsNull()) {
243 return "null"; 248 return "null";
244 } else { 249 } else {
245 return "Object"; 250 return "Object";
246 } 251 }
247 } 252 }
248 253
254 virtual void PrintToJSONStream(JSONStream* stream, bool ref = true) const {
255 if (IsNull()) {
256 stream->OpenObject();
257 stream->PrintProperty("type", "null");
258 stream->CloseObject();
259 return;
260 }
261 ASSERT(!IsNull());
262 stream->OpenObject();
263 stream->PrintProperty("type", "Object");
264 stream->CloseObject();
265 }
266
249 // Returns the name that is used to identify an object in the 267 // Returns the name that is used to identify an object in the
250 // namespace dictionary. 268 // namespace dictionary.
251 // Object::DictionaryName() returns String::null(). Only subclasses 269 // Object::DictionaryName() returns String::null(). Only subclasses
252 // of Object that need to be entered in the library and library prefix 270 // of Object that need to be entered in the library and library prefix
253 // namespaces need to provide an implementation. 271 // namespaces need to provide an implementation.
254 virtual RawString* DictionaryName() const; 272 virtual RawString* DictionaryName() const;
255 273
256 bool IsNew() const { return raw()->IsNewObject(); } 274 bool IsNew() const { return raw()->IsNewObject(); }
257 bool IsOld() const { return raw()->IsOldObject(); } 275 bool IsOld() const { return raw()->IsOldObject(); }
258 bool InVMHeap() const { 276 bool InVMHeap() const {
(...skipping 5712 matching lines...) Expand 10 before | Expand all | Expand 10 after
5971 5989
5972 5990
5973 RawObject* MegamorphicCache::GetTargetFunction(const Array& array, 5991 RawObject* MegamorphicCache::GetTargetFunction(const Array& array,
5974 intptr_t index) { 5992 intptr_t index) {
5975 return array.At((index * kEntryLength) + kTargetFunctionIndex); 5993 return array.At((index * kEntryLength) + kTargetFunctionIndex);
5976 } 5994 }
5977 5995
5978 } // namespace dart 5996 } // namespace dart
5979 5997
5980 #endif // VM_OBJECT_H_ 5998 #endif // VM_OBJECT_H_
OLDNEW
« no previous file with comments | « runtime/vm/json_test.cc ('k') | runtime/vm/object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698