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_DART_API_MESSAGE_H_ | 5 #ifndef VM_DART_API_MESSAGE_H_ |
6 #define VM_DART_API_MESSAGE_H_ | 6 #define VM_DART_API_MESSAGE_H_ |
7 | 7 |
8 #include "include/dart_native_api.h" | 8 #include "include/dart_native_api.h" |
| 9 #include "platform/utils.h" |
| 10 #include "vm/allocation.h" |
9 #include "vm/dart_api_state.h" | 11 #include "vm/dart_api_state.h" |
| 12 #include "vm/raw_object.h" |
10 #include "vm/snapshot.h" | 13 #include "vm/snapshot.h" |
11 | 14 |
12 namespace dart { | 15 namespace dart { |
13 | 16 |
14 // Use this C structure for reading internal objects in the serialized | 17 // Use this C structure for reading internal objects in the serialized |
15 // data. These are objects that we need to process in order to | 18 // data. These are objects that we need to process in order to |
16 // generate the Dart_CObject graph but that we don't want to expose in | 19 // generate the Dart_CObject graph but that we don't want to expose in |
17 // that graph. | 20 // that graph. |
18 struct Dart_CObject_Internal : public Dart_CObject { | 21 struct Dart_CObject_Internal : public Dart_CObject { |
19 enum Type { | 22 enum Type { |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 bool WriteCObjectInlined(Dart_CObject* object, Dart_CObject_Type type); | 197 bool WriteCObjectInlined(Dart_CObject* object, Dart_CObject_Type type); |
195 | 198 |
196 intptr_t object_id_; | 199 intptr_t object_id_; |
197 Dart_CObject** forward_list_; | 200 Dart_CObject** forward_list_; |
198 intptr_t forward_list_length_; | 201 intptr_t forward_list_length_; |
199 intptr_t forward_id_; | 202 intptr_t forward_id_; |
200 | 203 |
201 DISALLOW_COPY_AND_ASSIGN(ApiMessageWriter); | 204 DISALLOW_COPY_AND_ASSIGN(ApiMessageWriter); |
202 }; | 205 }; |
203 | 206 |
| 207 |
| 208 // This class handles translation of certain RawObjects to CObjects for |
| 209 // NativeMessageHandlers. |
| 210 // |
| 211 // TODO(zra): Expand to support not only null, but also other VM heap objects |
| 212 // as well. |
| 213 class ApiObjectConverter : public AllStatic { |
| 214 public: |
| 215 static bool CanConvert(RawObject* raw_obj) { |
| 216 return !raw_obj->IsHeapObject() || (raw_obj == Object::null()); |
| 217 } |
| 218 |
| 219 static bool Convert(RawObject* raw_obj, Dart_CObject* c_obj) { |
| 220 if (!raw_obj->IsHeapObject()) { |
| 221 ConvertSmi(reinterpret_cast<RawSmi*>(raw_obj), c_obj); |
| 222 } else if (raw_obj == Object::null()) { |
| 223 ConvertNull(c_obj); |
| 224 } else { |
| 225 return false; |
| 226 } |
| 227 return true; |
| 228 } |
| 229 |
| 230 private: |
| 231 static void ConvertSmi(RawSmi* raw_smi, Dart_CObject* c_obj) { |
| 232 ASSERT(!raw_smi->IsHeapObject()); |
| 233 intptr_t value = Smi::Value(raw_smi); |
| 234 if (Utils::IsInt(31, value)) { |
| 235 c_obj->type = Dart_CObject_kInt32; |
| 236 c_obj->value.as_int32 = static_cast<int32_t>(value); |
| 237 } else { |
| 238 c_obj->type = Dart_CObject_kInt64; |
| 239 c_obj->value.as_int64 = static_cast<int64_t>(value); |
| 240 } |
| 241 } |
| 242 |
| 243 static void ConvertNull(Dart_CObject* c_obj) { |
| 244 c_obj->type = Dart_CObject_kNull; |
| 245 c_obj->value.as_int64 = 0; |
| 246 } |
| 247 }; |
| 248 |
204 } // namespace dart | 249 } // namespace dart |
205 | 250 |
206 #endif // VM_DART_API_MESSAGE_H_ | 251 #endif // VM_DART_API_MESSAGE_H_ |
OLD | NEW |