Chromium Code Reviews| 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 #include "vm/dart_api_message.h" | 5 #include "vm/dart_api_message.h" |
| 6 #include "vm/object.h" | 6 #include "vm/object.h" |
| 7 #include "vm/object_store.h" | 7 #include "vm/object_store.h" |
| 8 | 8 |
| 9 namespace dart { | 9 namespace dart { |
| 10 | 10 |
| 11 // TODO(sgjesse): When the external message format is done these | 11 // TODO(sgjesse): When the external message format is done these |
| 12 // duplicate constants from snapshot.cc should be removed. | 12 // duplicate constants from snapshot.cc should be removed. |
| 13 enum { | 13 enum { |
| 14 kInstanceId = ObjectStore::kMaxId, | 14 kInstanceId = ObjectStore::kMaxId, |
| 15 kMaxPredefinedObjectIds, | 15 kMaxPredefinedObjectIds, |
| 16 }; | 16 }; |
| 17 static const int kNumInitialReferences = 4; | 17 static const int kNumInitialReferences = 4; |
| 18 | 18 |
| 19 ApiMessageReader::ApiMessageReader(const uint8_t* buffer, | 19 ApiMessageReader::ApiMessageReader(const uint8_t* buffer, |
| 20 intptr_t length, | 20 intptr_t length, |
| 21 ReAlloc alloc) | 21 ReAlloc alloc) |
| 22 : BaseReader(buffer, length), | 22 : BaseReader(buffer, length), |
| 23 alloc_(alloc), | 23 alloc_(alloc), |
| 24 backward_references_(kNumInitialReferences) { | 24 backward_references_(kNumInitialReferences) { |
| 25 Init(); | 25 Init(); |
| 26 } | 26 } |
| 27 | 27 |
| 28 | 28 |
| 29 void ApiMessageReader::Init() { | 29 void ApiMessageReader::Init() { |
| 30 // Initialize marker objects used to handle Lists. | 30 // Initialize marker objects used to handle Lists. |
| 31 // TODO(sjesse): Remove this when message serialization format is | 31 // TODO(sjesse): Remove this when message serialization format is |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 187 Dart_CObject* length = ReadObject(); | 187 Dart_CObject* length = ReadObject(); |
| 188 ASSERT(length->type == Dart_CObject::kInt32); | 188 ASSERT(length->type == Dart_CObject::kInt32); |
| 189 for (int i = 0; i < length->value.as_int32; i++) { | 189 for (int i = 0; i < length->value.as_int32; i++) { |
| 190 Dart_CObject* type = ReadObject(); | 190 Dart_CObject* type = ReadObject(); |
| 191 if (type != &dynamic_type_marker) { | 191 if (type != &dynamic_type_marker) { |
| 192 return NULL; | 192 return NULL; |
| 193 } | 193 } |
| 194 } | 194 } |
| 195 return value; | 195 return value; |
| 196 } | 196 } |
| 197 case Object::kTypeParameterClass: { | |
| 198 // TODO(sjesse): Fix this workaround ignoring the type parameter. | |
|
srdjan
2012/03/30 21:46:52
sgjesse
regis
2012/03/30 22:01:43
Done. But many others are spelled "sjesse".
| |
| 199 Dart_CObject* value = &dynamic_type_marker; | |
| 200 AddBackwardReference(object_id, value); | |
| 201 intptr_t index = ReadIntptrValue(); | |
| 202 USE(index); | |
| 203 intptr_t token_index = ReadIntptrValue(); | |
| 204 USE(token_index); | |
| 205 int8_t type_state = Read<int8_t>(); | |
| 206 USE(type_state); | |
| 207 Dart_CObject* parameterized_class = ReadObject(); | |
| 208 // The type parameter is finalized, therefore parameterized_class is null. | |
| 209 ASSERT(parameterized_class->type == Dart_CObject::kNull); | |
| 210 Dart_CObject* name = ReadObject(); | |
| 211 ASSERT(name->type == Dart_CObject::kString); | |
| 212 return value; | |
| 213 } | |
| 197 case ObjectStore::kArrayClass: { | 214 case ObjectStore::kArrayClass: { |
| 198 intptr_t len = ReadSmiValue(); | 215 intptr_t len = ReadSmiValue(); |
| 199 Dart_CObject* value = AllocateDartCObjectArray(len); | 216 Dart_CObject* value = AllocateDartCObjectArray(len); |
| 200 AddBackwardReference(object_id, value); | 217 AddBackwardReference(object_id, value); |
| 201 // Skip type arguments. | 218 // Skip type arguments. |
| 202 // TODO(sjesse): Remove this when message serialization format is | 219 // TODO(sjesse): Remove this when message serialization format is |
| 203 // updated (currently type_arguments is leaked). | 220 // updated (currently type_arguments is leaked). |
| 204 Dart_CObject* type_arguments = ReadObject(); | 221 Dart_CObject* type_arguments = ReadObject(); |
| 205 if (type_arguments != &type_arguments_marker && | 222 if (type_arguments != &type_arguments_marker && |
| 206 type_arguments->type != Dart_CObject::kNull) { | 223 type_arguments->type != Dart_CObject::kNull) { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 288 } else if (object_id == ObjectStore::kDynamicType || | 305 } else if (object_id == ObjectStore::kDynamicType || |
| 289 object_id == ObjectStore::kDoubleInterface || | 306 object_id == ObjectStore::kDoubleInterface || |
| 290 object_id == ObjectStore::kIntInterface || | 307 object_id == ObjectStore::kIntInterface || |
| 291 object_id == ObjectStore::kBoolInterface || | 308 object_id == ObjectStore::kBoolInterface || |
| 292 object_id == ObjectStore::kStringInterface || | 309 object_id == ObjectStore::kStringInterface || |
| 293 object_id == ObjectStore::kByteArrayInterface) { | 310 object_id == ObjectStore::kByteArrayInterface) { |
| 294 // Always return dynamic type (this is only a marker). | 311 // Always return dynamic type (this is only a marker). |
| 295 return &dynamic_type_marker; | 312 return &dynamic_type_marker; |
| 296 } else { | 313 } else { |
| 297 intptr_t index = object_id - kMaxPredefinedObjectIds; | 314 intptr_t index = object_id - kMaxPredefinedObjectIds; |
| 298 ASSERT(index < backward_references_.length()); | 315 ASSERT((0 <= index) && (index < backward_references_.length())); |
| 299 ASSERT(backward_references_[index] != NULL); | 316 ASSERT(backward_references_[index] != NULL); |
| 300 return backward_references_[index]; | 317 return backward_references_[index]; |
| 301 } | 318 } |
| 302 return NULL; | 319 return NULL; |
| 303 } | 320 } |
| 304 | 321 |
| 305 | 322 |
| 306 Dart_CObject* ApiMessageReader::ReadObjectImpl(intptr_t header) { | 323 Dart_CObject* ApiMessageReader::ReadObjectImpl(intptr_t header) { |
| 307 SerializedHeaderType header_type = SerializedHeaderTag::decode(header); | 324 SerializedHeaderType header_type = SerializedHeaderTag::decode(header); |
| 308 intptr_t header_value = SerializedHeaderData::decode(header); | 325 intptr_t header_value = SerializedHeaderData::decode(header); |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 541 } | 558 } |
| 542 | 559 |
| 543 | 560 |
| 544 void ApiMessageWriter::WriteCMessage(Dart_CObject* object) { | 561 void ApiMessageWriter::WriteCMessage(Dart_CObject* object) { |
| 545 WriteCObject(object); | 562 WriteCObject(object); |
| 546 UnmarkAllCObjects(object); | 563 UnmarkAllCObjects(object); |
| 547 FinalizeBuffer(); | 564 FinalizeBuffer(); |
| 548 } | 565 } |
| 549 | 566 |
| 550 } // namespace dart | 567 } // namespace dart |
| OLD | NEW |