| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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_JSON_STREAM_H_ | 5 #ifndef VM_JSON_STREAM_H_ |
| 6 #define VM_JSON_STREAM_H_ | 6 #define VM_JSON_STREAM_H_ |
| 7 | 7 |
| 8 #include "platform/json.h" | 8 #include "platform/json.h" |
| 9 #include "vm/allocation.h" | 9 #include "vm/allocation.h" |
| 10 | 10 |
| 11 namespace dart { | 11 namespace dart { |
| 12 | 12 |
| 13 class Field; | 13 class Field; |
| 14 class Instance; | 14 class Instance; |
| 15 class JSONArray; | 15 class JSONArray; |
| 16 class JSONObject; | 16 class JSONObject; |
| 17 class Object; | 17 class Object; |
| 18 class SourceBreakpoint; |
| 18 | 19 |
| 19 class JSONStream : ValueObject { | 20 class JSONStream : ValueObject { |
| 20 public: | 21 public: |
| 21 explicit JSONStream(intptr_t buf_size = 256); | 22 explicit JSONStream(intptr_t buf_size = 256); |
| 22 ~JSONStream(); | 23 ~JSONStream(); |
| 23 | 24 |
| 24 TextBuffer* buffer() { return &buffer_; } | 25 TextBuffer* buffer() { return &buffer_; } |
| 25 const char* ToCString() { return buffer_.buf(); } | 26 const char* ToCString() { return buffer_.buf(); } |
| 26 | 27 |
| 27 void SetArguments(const char** arguments, intptr_t num_arguments); | 28 void SetArguments(const char** arguments, intptr_t num_arguments); |
| 28 void SetOptions(const char** option_keys, const char** option_values, | 29 void SetOptions(const char** option_keys, const char** option_values, |
| 29 intptr_t num_options); | 30 intptr_t num_options); |
| 30 | 31 |
| 31 intptr_t num_arguments() const { return num_arguments_; } | 32 intptr_t num_arguments() const { return num_arguments_; } |
| 32 const char* GetArgument(intptr_t i) const { | 33 const char* GetArgument(intptr_t i) const { |
| 33 return arguments_[i]; | 34 return arguments_[i]; |
| 34 } | 35 } |
| 35 intptr_t num_options() const { return num_options_; } | 36 intptr_t num_options() const { return num_options_; } |
| 36 const char* GetOptionKey(intptr_t i) const { | 37 const char* GetOptionKey(intptr_t i) const { |
| 37 return option_keys_[i]; | 38 return option_keys_[i]; |
| 38 } | 39 } |
| 39 const char* GetOptionValue(intptr_t i) const { | 40 const char* GetOptionValue(intptr_t i) const { |
| 40 return option_values_[i]; | 41 return option_values_[i]; |
| 41 } | 42 } |
| 42 | 43 |
| 44 const char* LookupOption(const char* key) const; |
| 45 |
| 43 private: | 46 private: |
| 44 void Clear(); | 47 void Clear(); |
| 45 | 48 |
| 46 void OpenObject(const char* property_name = NULL); | 49 void OpenObject(const char* property_name = NULL); |
| 47 void CloseObject(); | 50 void CloseObject(); |
| 48 | 51 |
| 49 void OpenArray(const char* property_name = NULL); | 52 void OpenArray(const char* property_name = NULL); |
| 50 void CloseArray(); | 53 void CloseArray(); |
| 51 | 54 |
| 52 void PrintValueBool(bool b); | 55 void PrintValueBool(bool b); |
| 53 void PrintValue(intptr_t i); | 56 void PrintValue(intptr_t i); |
| 54 void PrintValue(double d); | 57 void PrintValue(double d); |
| 55 void PrintValue(const char* s); | 58 void PrintValue(const char* s); |
| 56 void PrintfValue(const char* format, ...) PRINTF_ATTRIBUTE(2, 3); | 59 void PrintfValue(const char* format, ...) PRINTF_ATTRIBUTE(2, 3); |
| 57 void PrintValue(const Object& o, bool ref = true); | 60 void PrintValue(const Object& o, bool ref = true); |
| 58 void PrintValue(const Field& f, const Instance& instance, bool ref = true); | 61 void PrintValue(const Field& f, const Instance& instance, bool ref = true); |
| 62 void PrintValue(const SourceBreakpoint* bpt); |
| 59 | 63 |
| 60 void PrintPropertyBool(const char* name, bool b); | 64 void PrintPropertyBool(const char* name, bool b); |
| 61 void PrintProperty(const char* name, intptr_t i); | 65 void PrintProperty(const char* name, intptr_t i); |
| 62 void PrintProperty(const char* name, double d); | 66 void PrintProperty(const char* name, double d); |
| 63 void PrintProperty(const char* name, const char* s); | 67 void PrintProperty(const char* name, const char* s); |
| 64 void PrintfProperty(const char* name, const char* format, ...) | 68 void PrintfProperty(const char* name, const char* format, ...) |
| 65 PRINTF_ATTRIBUTE(3, 4); | 69 PRINTF_ATTRIBUTE(3, 4); |
| 66 void PrintProperty(const char* name, const Object& o, bool ref = true); | 70 void PrintProperty(const char* name, const Object& o, bool ref = true); |
| 67 | 71 |
| 68 void PrintPropertyName(const char* name); | 72 void PrintPropertyName(const char* name); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 void AddValue(const char* s) const { stream_->PrintValue(s); } | 151 void AddValue(const char* s) const { stream_->PrintValue(s); } |
| 148 void AddValue(const Object& obj, bool ref = true) const { | 152 void AddValue(const Object& obj, bool ref = true) const { |
| 149 stream_->PrintValue(obj, ref); | 153 stream_->PrintValue(obj, ref); |
| 150 } | 154 } |
| 151 // Print a field bound to a value. Value is looked up from 'instance'. | 155 // Print a field bound to a value. Value is looked up from 'instance'. |
| 152 void AddValue(const Field& field, | 156 void AddValue(const Field& field, |
| 153 const Instance& instance, | 157 const Instance& instance, |
| 154 bool ref = true) const { | 158 bool ref = true) const { |
| 155 stream_->PrintValue(field, instance, ref); | 159 stream_->PrintValue(field, instance, ref); |
| 156 } | 160 } |
| 161 void AddValue(const SourceBreakpoint* bpt) const { |
| 162 stream_->PrintValue(bpt); |
| 163 } |
| 157 void AddValueF(const char* format, ...) const PRINTF_ATTRIBUTE(2, 3); | 164 void AddValueF(const char* format, ...) const PRINTF_ATTRIBUTE(2, 3); |
| 158 | 165 |
| 159 private: | 166 private: |
| 160 JSONStream* stream_; | 167 JSONStream* stream_; |
| 161 | 168 |
| 162 friend class JSONObject; | 169 friend class JSONObject; |
| 163 | 170 |
| 164 DISALLOW_ALLOCATION(); | 171 DISALLOW_ALLOCATION(); |
| 165 DISALLOW_COPY_AND_ASSIGN(JSONArray); | 172 DISALLOW_COPY_AND_ASSIGN(JSONArray); |
| 166 }; | 173 }; |
| 167 | 174 |
| 168 } // namespace dart | 175 } // namespace dart |
| 169 | 176 |
| 170 #endif // VM_JSON_STREAM_H_ | 177 #endif // VM_JSON_STREAM_H_ |
| OLD | NEW |