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

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

Issue 1523013002: Fold ApiObjectConverter use into ApiMessageReader (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years 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
« no previous file with comments | « no previous file | runtime/vm/dart_api_message.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_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" 9 #include "platform/utils.h"
10 #include "vm/allocation.h" 10 #include "vm/allocation.h"
11 #include "vm/dart_api_state.h" 11 #include "vm/dart_api_state.h"
12 #include "vm/message.h"
12 #include "vm/raw_object.h" 13 #include "vm/raw_object.h"
13 #include "vm/snapshot.h" 14 #include "vm/snapshot.h"
14 15
15 namespace dart { 16 namespace dart {
16 17
17 // Use this C structure for reading internal objects in the serialized 18 // Use this C structure for reading internal objects in the serialized
18 // data. These are objects that we need to process in order to 19 // data. These are objects that we need to process in order to
19 // generate the Dart_CObject graph but that we don't want to expose in 20 // generate the Dart_CObject graph but that we don't want to expose in
20 // that graph. 21 // that graph.
21 struct Dart_CObject_Internal : public Dart_CObject { 22 struct Dart_CObject_Internal : public Dart_CObject {
(...skipping 19 matching lines...) Expand all
41 }; 42 };
42 43
43 44
44 // Reads a message snapshot into a C structure. 45 // Reads a message snapshot into a C structure.
45 class ApiMessageReader : public BaseReader { 46 class ApiMessageReader : public BaseReader {
46 public: 47 public:
47 // The ApiMessageReader object must be enclosed by an ApiNativeScope. 48 // The ApiMessageReader object must be enclosed by an ApiNativeScope.
48 // Allocation of all C Heap objects is done in the zone associated with 49 // Allocation of all C Heap objects is done in the zone associated with
49 // the enclosing ApiNativeScope. 50 // the enclosing ApiNativeScope.
50 ApiMessageReader(const uint8_t* buffer, intptr_t length); 51 ApiMessageReader(const uint8_t* buffer, intptr_t length);
52 explicit ApiMessageReader(Message* message);
51 ~ApiMessageReader() { } 53 ~ApiMessageReader() { }
52 54
53 Dart_CObject* ReadMessage(); 55 Dart_CObject* ReadMessage();
54 56
55 private: 57 private:
56 class BackRefNode { 58 class BackRefNode {
57 public: 59 public:
58 BackRefNode(Dart_CObject* reference, DeserializeState state) 60 BackRefNode(Dart_CObject* reference, DeserializeState state)
59 : reference_(reference), state_(state) {} 61 : reference_(reference), state_(state) {}
60 Dart_CObject* reference() const { return reference_; } 62 Dart_CObject* reference() const { return reference_; }
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 }; 207 };
206 208
207 209
208 // This class handles translation of certain RawObjects to CObjects for 210 // This class handles translation of certain RawObjects to CObjects for
209 // NativeMessageHandlers. 211 // NativeMessageHandlers.
210 // 212 //
211 // TODO(zra): Expand to support not only null, but also other VM heap objects 213 // TODO(zra): Expand to support not only null, but also other VM heap objects
212 // as well. 214 // as well.
213 class ApiObjectConverter : public AllStatic { 215 class ApiObjectConverter : public AllStatic {
214 public: 216 public:
215 static bool CanConvert(RawObject* raw_obj) { 217 static bool CanConvert(const RawObject* raw_obj) {
216 return !raw_obj->IsHeapObject() || (raw_obj == Object::null()); 218 return !raw_obj->IsHeapObject() || (raw_obj == Object::null());
217 } 219 }
218 220
219 static bool Convert(RawObject* raw_obj, Dart_CObject* c_obj) { 221 static bool Convert(const RawObject* raw_obj, Dart_CObject* c_obj) {
220 if (!raw_obj->IsHeapObject()) { 222 if (!raw_obj->IsHeapObject()) {
221 ConvertSmi(reinterpret_cast<RawSmi*>(raw_obj), c_obj); 223 ConvertSmi(reinterpret_cast<const RawSmi*>(raw_obj), c_obj);
222 } else if (raw_obj == Object::null()) { 224 } else if (raw_obj == Object::null()) {
223 ConvertNull(c_obj); 225 ConvertNull(c_obj);
224 } else { 226 } else {
225 return false; 227 return false;
226 } 228 }
227 return true; 229 return true;
228 } 230 }
229 231
230 private: 232 private:
231 static void ConvertSmi(RawSmi* raw_smi, Dart_CObject* c_obj) { 233 static void ConvertSmi(const RawSmi* raw_smi, Dart_CObject* c_obj) {
232 ASSERT(!raw_smi->IsHeapObject()); 234 ASSERT(!raw_smi->IsHeapObject());
233 intptr_t value = Smi::Value(raw_smi); 235 intptr_t value = Smi::Value(raw_smi);
234 if (Utils::IsInt(31, value)) { 236 if (Utils::IsInt(31, value)) {
235 c_obj->type = Dart_CObject_kInt32; 237 c_obj->type = Dart_CObject_kInt32;
236 c_obj->value.as_int32 = static_cast<int32_t>(value); 238 c_obj->value.as_int32 = static_cast<int32_t>(value);
237 } else { 239 } else {
238 c_obj->type = Dart_CObject_kInt64; 240 c_obj->type = Dart_CObject_kInt64;
239 c_obj->value.as_int64 = static_cast<int64_t>(value); 241 c_obj->value.as_int64 = static_cast<int64_t>(value);
240 } 242 }
241 } 243 }
242 244
243 static void ConvertNull(Dart_CObject* c_obj) { 245 static void ConvertNull(Dart_CObject* c_obj) {
244 c_obj->type = Dart_CObject_kNull; 246 c_obj->type = Dart_CObject_kNull;
245 c_obj->value.as_int64 = 0; 247 c_obj->value.as_int64 = 0;
246 } 248 }
247 }; 249 };
248 250
249 } // namespace dart 251 } // namespace dart
250 252
251 #endif // VM_DART_API_MESSAGE_H_ 253 #endif // VM_DART_API_MESSAGE_H_
OLDNEW
« no previous file with comments | « no previous file | runtime/vm/dart_api_message.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698