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

Side by Side Diff: runtime/bin/dartutils.h

Issue 14142008: Add support for more typed data types on native ports (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed review comments Created 7 years, 8 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 | « no previous file | runtime/bin/dartutils.cc » ('j') | runtime/include/dart_api.h » ('J')
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 BIN_DARTUTILS_H_ 5 #ifndef BIN_DARTUTILS_H_
6 #define BIN_DARTUTILS_H_ 6 #define BIN_DARTUTILS_H_
7 7
8 #include "bin/builtin.h" 8 #include "bin/builtin.h"
9 #include "bin/utils.h" 9 #include "bin/utils.h"
10 #include "include/dart_api.h" 10 #include "include/dart_api.h"
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 198
199 DISALLOW_ALLOCATION(); 199 DISALLOW_ALLOCATION();
200 DISALLOW_IMPLICIT_CONSTRUCTORS(DartUtils); 200 DISALLOW_IMPLICIT_CONSTRUCTORS(DartUtils);
201 }; 201 };
202 202
203 203
204 class CObject { 204 class CObject {
205 public: 205 public:
206 explicit CObject(Dart_CObject *cobject) : cobject_(cobject) {} 206 explicit CObject(Dart_CObject *cobject) : cobject_(cobject) {}
207 Dart_CObject::Type type() { return cobject_->type; } 207 Dart_CObject::Type type() { return cobject_->type; }
208 Dart_CObject::TypedDataType byte_array_type() {
siva 2013/04/15 23:28:45 for consistency should we name this typed_data_typ
209 ASSERT(type() == Dart_CObject::kTypedData);
210 return cobject_->value.as_typed_data.type;
211 }
208 212
209 bool IsNull() { return type() == Dart_CObject::kNull; } 213 bool IsNull() { return type() == Dart_CObject::kNull; }
210 bool IsBool() { return type() == Dart_CObject::kBool; } 214 bool IsBool() { return type() == Dart_CObject::kBool; }
211 bool IsInt32() { return type() == Dart_CObject::kInt32; } 215 bool IsInt32() { return type() == Dart_CObject::kInt32; }
212 bool IsInt64() { return type() == Dart_CObject::kInt64; } 216 bool IsInt64() { return type() == Dart_CObject::kInt64; }
213 bool IsInt32OrInt64() { return IsInt32() || IsInt64(); } 217 bool IsInt32OrInt64() { return IsInt32() || IsInt64(); }
214 bool IsIntptr() { return IsInt32OrInt64(); } 218 bool IsIntptr() { return IsInt32OrInt64(); }
215 bool IsBigint() { return type() == Dart_CObject::kBigint; } 219 bool IsBigint() { return type() == Dart_CObject::kBigint; }
216 bool IsDouble() { return type() == Dart_CObject::kDouble; } 220 bool IsDouble() { return type() == Dart_CObject::kDouble; }
217 bool IsString() { return type() == Dart_CObject::kString; } 221 bool IsString() { return type() == Dart_CObject::kString; }
218 bool IsArray() { return type() == Dart_CObject::kArray; } 222 bool IsArray() { return type() == Dart_CObject::kArray; }
219 bool IsUint8Array() { return type() == Dart_CObject::kUint8Array; } 223 bool IsTypedData() { return type() == Dart_CObject::kTypedData; }
224 bool IsUint8Array() {
225 return type() == Dart_CObject::kTypedData &&
226 byte_array_type() == Dart_CObject::kUint8Array;
227 }
220 228
221 bool IsTrue() { 229 bool IsTrue() {
222 return type() == Dart_CObject::kBool && cobject_->value.as_bool; 230 return type() == Dart_CObject::kBool && cobject_->value.as_bool;
223 } 231 }
224 232
225 bool IsFalse() { 233 bool IsFalse() {
226 return type() == Dart_CObject::kBool && !cobject_->value.as_bool; 234 return type() == Dart_CObject::kBool && !cobject_->value.as_bool;
227 } 235 }
228 236
229 void* operator new(size_t size) { 237 void* operator new(size_t size) {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 289
282 #define DECLARE_COBJECT_CONSTRUCTORS(t) \ 290 #define DECLARE_COBJECT_CONSTRUCTORS(t) \
283 explicit CObject##t(Dart_CObject *cobject) : CObject(cobject) { \ 291 explicit CObject##t(Dart_CObject *cobject) : CObject(cobject) { \
284 ASSERT(type() == Dart_CObject::k##t); \ 292 ASSERT(type() == Dart_CObject::k##t); \
285 cobject_ = cobject; \ 293 cobject_ = cobject; \
286 } \ 294 } \
287 explicit CObject##t(CObject* cobject) : CObject() { \ 295 explicit CObject##t(CObject* cobject) : CObject() { \
288 ASSERT(cobject != NULL); \ 296 ASSERT(cobject != NULL); \
289 ASSERT(cobject->type() == Dart_CObject::k##t); \ 297 ASSERT(cobject->type() == Dart_CObject::k##t); \
290 cobject_ = cobject->AsApiCObject(); \ 298 cobject_ = cobject->AsApiCObject(); \
291 } 299 } \
300
301
302 #define DECLARE_COBJECT_TYPED_DATA_CONSTRUCTORS(t) \
303 explicit CObject##t(Dart_CObject *cobject) : CObject(cobject) { \
304 ASSERT(type() == Dart_CObject::kTypedData); \
305 ASSERT(byte_array_type() == Dart_CObject::k##t); \
306 cobject_ = cobject; \
307 } \
308 explicit CObject##t(CObject* cobject) : CObject() { \
309 ASSERT(cobject != NULL); \
310 ASSERT(cobject->type() == Dart_CObject::kTypedData); \
311 ASSERT(cobject->byte_array_type() == Dart_CObject::k##t); \
312 cobject_ = cobject->AsApiCObject(); \
313 } \
314
315
316 #define DECLARE_COBJECT_EXTERNAL_TYPED_DATA_CONSTRUCTORS(t) \
317 explicit CObjectExternal##t(Dart_CObject *cobject) : CObject(cobject) { \
318 ASSERT(type() == Dart_CObject::kExternalTypedData); \
319 ASSERT(byte_array_type() == Dart_CObject::k##t); \
320 cobject_ = cobject; \
321 } \
322 explicit CObjectExternal##t(CObject* cobject) : CObject() { \
323 ASSERT(cobject != NULL); \
324 ASSERT(cobject->type() == Dart_CObject::kExternalTypedData); \
325 ASSERT(cobject->byte_array_type() == Dart_CObject::k##t); \
326 cobject_ = cobject->AsApiCObject(); \
327 } \
292 328
293 329
294 class CObjectBool : public CObject { 330 class CObjectBool : public CObject {
295 public: 331 public:
296 DECLARE_COBJECT_CONSTRUCTORS(Bool) 332 DECLARE_COBJECT_CONSTRUCTORS(Bool)
297 333
298 bool Value() const { return cobject_->value.as_bool; } 334 bool Value() const { return cobject_->value.as_bool; }
299 335
300 private: 336 private:
301 DISALLOW_COPY_AND_ASSIGN(CObjectBool); 337 DISALLOW_COPY_AND_ASSIGN(CObjectBool);
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 } 433 }
398 void SetAt(int index, CObject* value) { 434 void SetAt(int index, CObject* value) {
399 cobject_->value.as_array.values[index] = value->AsApiCObject(); 435 cobject_->value.as_array.values[index] = value->AsApiCObject();
400 } 436 }
401 437
402 private: 438 private:
403 DISALLOW_COPY_AND_ASSIGN(CObjectArray); 439 DISALLOW_COPY_AND_ASSIGN(CObjectArray);
404 }; 440 };
405 441
406 442
443 class CObjectTypedData : public CObject {
444 public:
445 explicit CObjectTypedData(Dart_CObject *cobject) : CObject(cobject) {
446 ASSERT(type() == Dart_CObject::kTypedData);
447 cobject_ = cobject;
448 }
449 explicit CObjectTypedData(CObject* cobject) : CObject() {
450 ASSERT(cobject != NULL);
451 ASSERT(cobject->type() == Dart_CObject::kTypedData);
452 cobject_ = cobject->AsApiCObject();
453 }
454
455 Dart_CObject::TypedDataType Type() const {
456 return cobject_->value.as_typed_data.type;
457 }
458 int Length() const { return cobject_->value.as_typed_data.length; }
459 uint8_t* Buffer() const { return cobject_->value.as_typed_data.values; }
siva 2013/04/15 23:28:45 probably need accessors: Peer Callback etc. for
460
461 private:
462 DISALLOW_COPY_AND_ASSIGN(CObjectTypedData);
463 };
464
465
407 class CObjectUint8Array : public CObject { 466 class CObjectUint8Array : public CObject {
408 public: 467 public:
409 DECLARE_COBJECT_CONSTRUCTORS(Uint8Array) 468 DECLARE_COBJECT_TYPED_DATA_CONSTRUCTORS(Uint8Array)
410 469
411 int Length() const { return cobject_->value.as_byte_array.length; } 470 int Length() const { return cobject_->value.as_typed_data.length; }
412 uint8_t* Buffer() const { return cobject_->value.as_byte_array.values; } 471 uint8_t* Buffer() const { return cobject_->value.as_typed_data.values; }
413 472
414 private: 473 private:
415 DISALLOW_COPY_AND_ASSIGN(CObjectUint8Array); 474 DISALLOW_COPY_AND_ASSIGN(CObjectUint8Array);
416 }; 475 };
siva 2013/04/15 23:28:45 Is this class CObjectUint8Array still needed I cou
417 476
418 477
419 class CObjectExternalUint8Array : public CObject { 478 class CObjectExternalUint8Array : public CObject {
420 public: 479 public:
421 DECLARE_COBJECT_CONSTRUCTORS(ExternalUint8Array) 480 DECLARE_COBJECT_EXTERNAL_TYPED_DATA_CONSTRUCTORS(Uint8Array)
422 481
423 int Length() const { return cobject_->value.as_external_byte_array.length; } 482 int Length() const { return cobject_->value.as_external_typed_data.length; }
424 void SetLength(uint64_t length) { 483 void SetLength(uint64_t length) {
425 cobject_->value.as_external_byte_array.length = length; 484 cobject_->value.as_external_typed_data.length = length;
426 } 485 }
427 uint8_t* Data() const { return cobject_->value.as_external_byte_array.data; } 486 uint8_t* Data() const { return cobject_->value.as_external_typed_data.data; }
428 void* Peer() const { return cobject_->value.as_external_byte_array.peer; } 487 void* Peer() const { return cobject_->value.as_external_typed_data.peer; }
429 Dart_WeakPersistentHandleFinalizer Callback() const { 488 Dart_WeakPersistentHandleFinalizer Callback() const {
430 return cobject_->value.as_external_byte_array.callback; 489 return cobject_->value.as_external_typed_data.callback;
431 } 490 }
432 491
433 private: 492 private:
434 DISALLOW_COPY_AND_ASSIGN(CObjectExternalUint8Array); 493 DISALLOW_COPY_AND_ASSIGN(CObjectExternalUint8Array);
435 }; 494 };
siva 2013/04/15 23:28:45 Can the code in file.cc that creates objects of th
436 495
437 #endif // BIN_DARTUTILS_H_ 496 #endif // BIN_DARTUTILS_H_
OLDNEW
« no previous file with comments | « no previous file | runtime/bin/dartutils.cc » ('j') | runtime/include/dart_api.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698