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

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

Issue 15689013: - Modify dart_api.h to be a proper C API. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 6 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/dart_api_impl_test.cc ('k') | 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 "vm/dart_api_state.h" 8 #include "vm/dart_api_state.h"
9 #include "vm/snapshot.h" 9 #include "vm/snapshot.h"
10 10
11 namespace dart { 11 namespace dart {
12 12
13 // Use this C structure for reading internal objects in the serialized 13 // Use this C structure for reading internal objects in the serialized
14 // data. These are objects that we need to process in order to 14 // data. These are objects that we need to process in order to
15 // generate the Dart_CObject graph but that we don't want to expose in 15 // generate the Dart_CObject graph but that we don't want to expose in
16 // that graph. 16 // that graph.
17 struct Dart_CObject_Internal : public Dart_CObject { 17 struct Dart_CObject_Internal : public Dart_CObject {
18 enum Type { 18 enum Type {
19 kTypeArguments = Dart_CObject::kNumberOfTypes, 19 kTypeArguments = Dart_CObject_kNumberOfTypes,
20 kDynamicType, 20 kDynamicType,
21 kClass, 21 kClass,
22 kView, 22 kView,
23 kUninitialized, 23 kUninitialized,
24 }; 24 };
25 struct Dart_CObject_Internal* cls; 25 struct Dart_CObject_Internal* cls;
26 union { 26 union {
27 struct { 27 struct {
28 struct _Dart_CObject* library_url; 28 struct _Dart_CObject* library_url;
29 struct _Dart_CObject* class_name; 29 struct _Dart_CObject* class_name;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 private: 63 private:
64 Dart_CObject* reference_; 64 Dart_CObject* reference_;
65 DeserializeState state_; 65 DeserializeState state_;
66 66
67 DISALLOW_COPY_AND_ASSIGN(BackRefNode); 67 DISALLOW_COPY_AND_ASSIGN(BackRefNode);
68 }; 68 };
69 69
70 // Allocates a Dart_CObject object. 70 // Allocates a Dart_CObject object.
71 Dart_CObject* AllocateDartCObject(); 71 Dart_CObject* AllocateDartCObject();
72 // Allocates a Dart_CObject object with the specified type. 72 // Allocates a Dart_CObject object with the specified type.
73 Dart_CObject* AllocateDartCObject(Dart_CObject::Type type); 73 Dart_CObject* AllocateDartCObject(Dart_CObject_Type type);
74 // Allocates a Dart_CObject object representing an unsupported 74 // Allocates a Dart_CObject object representing an unsupported
75 // object in the API message. 75 // object in the API message.
76 Dart_CObject* AllocateDartCObjectUnsupported(); 76 Dart_CObject* AllocateDartCObjectUnsupported();
77 // Allocates a Dart_CObject object for the null object. 77 // Allocates a Dart_CObject object for the null object.
78 Dart_CObject* AllocateDartCObjectNull(); 78 Dart_CObject* AllocateDartCObjectNull();
79 // Allocates a Dart_CObject object for a boolean object. 79 // Allocates a Dart_CObject object for a boolean object.
80 Dart_CObject* AllocateDartCObjectBool(bool value); 80 Dart_CObject* AllocateDartCObjectBool(bool value);
81 // Allocates a Dart_CObject object for for a 32-bit integer. 81 // Allocates a Dart_CObject object for for a 32-bit integer.
82 Dart_CObject* AllocateDartCObjectInt32(int32_t value); 82 Dart_CObject* AllocateDartCObjectInt32(int32_t value);
83 // Allocates a Dart_CObject object for for a 64-bit integer. 83 // Allocates a Dart_CObject object for for a 64-bit integer.
84 Dart_CObject* AllocateDartCObjectInt64(int64_t value); 84 Dart_CObject* AllocateDartCObjectInt64(int64_t value);
85 // Allocates a Dart_CObject object for bigint data. 85 // Allocates a Dart_CObject object for bigint data.
86 Dart_CObject* AllocateDartCObjectBigint(intptr_t length); 86 Dart_CObject* AllocateDartCObjectBigint(intptr_t length);
87 // Allocates a Dart_CObject object for a double. 87 // Allocates a Dart_CObject object for a double.
88 Dart_CObject* AllocateDartCObjectDouble(double value); 88 Dart_CObject* AllocateDartCObjectDouble(double value);
89 // Allocates a Dart_CObject object for string data. 89 // Allocates a Dart_CObject object for string data.
90 Dart_CObject* AllocateDartCObjectString(intptr_t length); 90 Dart_CObject* AllocateDartCObjectString(intptr_t length);
91 // Allocates a C Dart_CObject object for a typed data. 91 // Allocates a C Dart_CObject object for a typed data.
92 Dart_CObject* AllocateDartCObjectTypedData( 92 Dart_CObject* AllocateDartCObjectTypedData(
93 Dart_CObject::TypedDataType type, intptr_t length); 93 Dart_TypedData_Type type, intptr_t length);
94 // Allocates a C array of Dart_CObject objects. 94 // Allocates a C array of Dart_CObject objects.
95 Dart_CObject* AllocateDartCObjectArray(intptr_t length); 95 Dart_CObject* AllocateDartCObjectArray(intptr_t length);
96 // Allocates a Dart_CObject_Internal object with the specified type. 96 // Allocates a Dart_CObject_Internal object with the specified type.
97 Dart_CObject_Internal* AllocateDartCObjectInternal( 97 Dart_CObject_Internal* AllocateDartCObjectInternal(
98 Dart_CObject_Internal::Type type); 98 Dart_CObject_Internal::Type type);
99 // Allocates a Dart_CObject_Internal object for a class object. 99 // Allocates a Dart_CObject_Internal object for a class object.
100 Dart_CObject_Internal* AllocateDartCObjectClass(); 100 Dart_CObject_Internal* AllocateDartCObjectClass();
101 // Allocates a backwards reference node. 101 // Allocates a backwards reference node.
102 BackRefNode* AllocateBackRefNode(Dart_CObject* ref, DeserializeState state); 102 BackRefNode* AllocateBackRefNode(Dart_CObject* ref, DeserializeState state);
103 103
104 void Init(); 104 void Init();
105 105
106 intptr_t LookupInternalClass(intptr_t class_header); 106 intptr_t LookupInternalClass(intptr_t class_header);
107 Dart_CObject* ReadVMIsolateObject(intptr_t value); 107 Dart_CObject* ReadVMIsolateObject(intptr_t value);
108 Dart_CObject* ReadInternalVMObject(intptr_t class_id, intptr_t object_id); 108 Dart_CObject* ReadInternalVMObject(intptr_t class_id, intptr_t object_id);
109 Dart_CObject* ReadInlinedObject(intptr_t object_id); 109 Dart_CObject* ReadInlinedObject(intptr_t object_id);
110 Dart_CObject* ReadObjectImpl(); 110 Dart_CObject* ReadObjectImpl();
111 Dart_CObject* ReadIndexedObject(intptr_t object_id); 111 Dart_CObject* ReadIndexedObject(intptr_t object_id);
112 Dart_CObject* ReadVMSymbol(intptr_t object_id); 112 Dart_CObject* ReadVMSymbol(intptr_t object_id);
113 Dart_CObject* ReadObjectRef(); 113 Dart_CObject* ReadObjectRef();
114 Dart_CObject* ReadObject(); 114 Dart_CObject* ReadObject();
115 115
116 // Add object to backward references. 116 // Add object to backward references.
117 void AddBackRef(intptr_t id, Dart_CObject* obj, DeserializeState state); 117 void AddBackRef(intptr_t id, Dart_CObject* obj, DeserializeState state);
118 118
119 // Get an object from the backward references list. 119 // Get an object from the backward references list.
120 Dart_CObject* GetBackRef(intptr_t id); 120 Dart_CObject* GetBackRef(intptr_t id);
121 121
122 Dart_CObject_Internal* AsInternal(Dart_CObject* object) { 122 Dart_CObject_Internal* AsInternal(Dart_CObject* object) {
123 ASSERT(object->type >= Dart_CObject::kNumberOfTypes); 123 ASSERT(object->type >= Dart_CObject_kNumberOfTypes);
124 return reinterpret_cast<Dart_CObject_Internal*>(object); 124 return reinterpret_cast<Dart_CObject_Internal*>(object);
125 } 125 }
126 126
127 // Allocation of the structures for the decoded message happens 127 // Allocation of the structures for the decoded message happens
128 // either in the supplied zone or using the supplied allocation 128 // either in the supplied zone or using the supplied allocation
129 // function. 129 // function.
130 ReAlloc alloc_; 130 ReAlloc alloc_;
131 ApiGrowableArray<BackRefNode*> backward_references_; 131 ApiGrowableArray<BackRefNode*> backward_references_;
132 Dart_CObject** vm_symbol_references_; 132 Dart_CObject** vm_symbol_references_;
133 133
134 Dart_CObject type_arguments_marker; 134 Dart_CObject type_arguments_marker;
135 Dart_CObject dynamic_type_marker; 135 Dart_CObject dynamic_type_marker;
136 }; 136 };
137 137
138 138
139 class ApiMessageWriter : public BaseWriter { 139 class ApiMessageWriter : public BaseWriter {
140 public: 140 public:
141 static const intptr_t kInitialSize = 512; 141 static const intptr_t kInitialSize = 512;
142 ApiMessageWriter(uint8_t** buffer, ReAlloc alloc) 142 ApiMessageWriter(uint8_t** buffer, ReAlloc alloc)
143 : BaseWriter(buffer, alloc, kInitialSize), 143 : BaseWriter(buffer, alloc, kInitialSize),
144 object_id_(0), forward_list_(NULL), 144 object_id_(0), forward_list_(NULL),
145 forward_list_length_(0), forward_id_(0) { 145 forward_list_length_(0), forward_id_(0) {
146 ASSERT(kDartCObjectTypeMask >= Dart_CObject::kNumberOfTypes - 1); 146 ASSERT(kDartCObjectTypeMask >= Dart_CObject_kNumberOfTypes - 1);
147 } 147 }
148 ~ApiMessageWriter() { 148 ~ApiMessageWriter() {
149 ::free(forward_list_); 149 ::free(forward_list_);
150 } 150 }
151 151
152 // Writes a message of integers. 152 // Writes a message of integers.
153 void WriteMessage(intptr_t field_count, intptr_t *data); 153 void WriteMessage(intptr_t field_count, intptr_t *data);
154 154
155 // Writes a message with a single object. 155 // Writes a message with a single object.
156 bool WriteCMessage(Dart_CObject* object); 156 bool WriteCMessage(Dart_CObject* object);
(...skipping 13 matching lines...) Expand all
170 170
171 void WriteSmi(int64_t value); 171 void WriteSmi(int64_t value);
172 void WriteNullObject(); 172 void WriteNullObject();
173 void WriteMint(Dart_CObject* object, int64_t value); 173 void WriteMint(Dart_CObject* object, int64_t value);
174 void WriteInt32(Dart_CObject* object); 174 void WriteInt32(Dart_CObject* object);
175 void WriteInt64(Dart_CObject* object); 175 void WriteInt64(Dart_CObject* object);
176 void WriteInlinedHeader(Dart_CObject* object); 176 void WriteInlinedHeader(Dart_CObject* object);
177 bool WriteCObject(Dart_CObject* object); 177 bool WriteCObject(Dart_CObject* object);
178 bool WriteCObjectRef(Dart_CObject* object); 178 bool WriteCObjectRef(Dart_CObject* object);
179 bool WriteForwardedCObject(Dart_CObject* object); 179 bool WriteForwardedCObject(Dart_CObject* object);
180 bool WriteCObjectInlined(Dart_CObject* object, Dart_CObject::Type type); 180 bool WriteCObjectInlined(Dart_CObject* object, Dart_CObject_Type type);
181 181
182 intptr_t object_id_; 182 intptr_t object_id_;
183 Dart_CObject** forward_list_; 183 Dart_CObject** forward_list_;
184 intptr_t forward_list_length_; 184 intptr_t forward_list_length_;
185 intptr_t forward_id_; 185 intptr_t forward_id_;
186 186
187 DISALLOW_COPY_AND_ASSIGN(ApiMessageWriter); 187 DISALLOW_COPY_AND_ASSIGN(ApiMessageWriter);
188 }; 188 };
189 189
190 } // namespace dart 190 } // namespace dart
191 191
192 #endif // VM_DART_API_MESSAGE_H_ 192 #endif // VM_DART_API_MESSAGE_H_
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_impl_test.cc ('k') | runtime/vm/dart_api_message.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698