| 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 BIN_DARTUTILS_H_ | 5 #ifndef BIN_DARTUTILS_H_ |
| 6 #define BIN_DARTUTILS_H_ | 6 #define BIN_DARTUTILS_H_ |
| 7 | 7 |
| 8 #include "include/dart_api.h" | 8 #include "include/dart_api.h" |
| 9 | 9 |
| 10 #include "platform/assert.h" | 10 #include "platform/assert.h" |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 | 221 |
| 222 class CObject { | 222 class CObject { |
| 223 public: | 223 public: |
| 224 // These match the constants in sdk/lib/io/common.dart. | 224 // These match the constants in sdk/lib/io/common.dart. |
| 225 static const int kSuccess = 0; | 225 static const int kSuccess = 0; |
| 226 static const int kArgumentError = 1; | 226 static const int kArgumentError = 1; |
| 227 static const int kOSError = 2; | 227 static const int kOSError = 2; |
| 228 static const int kFileClosedError = 3; | 228 static const int kFileClosedError = 3; |
| 229 | 229 |
| 230 explicit CObject(Dart_CObject *cobject) : cobject_(cobject) {} | 230 explicit CObject(Dart_CObject *cobject) : cobject_(cobject) {} |
| 231 Dart_CObject::Type type() { return cobject_->type; } | 231 Dart_CObject_Type type() { return cobject_->type; } |
| 232 Dart_CObject::TypedDataType byte_array_type() { | 232 Dart_TypedData_Type byte_array_type() { |
| 233 ASSERT(type() == Dart_CObject::kTypedData || | 233 ASSERT(type() == Dart_CObject_kTypedData || |
| 234 type() == Dart_CObject::kExternalTypedData); | 234 type() == Dart_CObject_kExternalTypedData); |
| 235 return cobject_->value.as_typed_data.type; | 235 return cobject_->value.as_typed_data.type; |
| 236 } | 236 } |
| 237 | 237 |
| 238 bool IsNull() { return type() == Dart_CObject::kNull; } | 238 bool IsNull() { return type() == Dart_CObject_kNull; } |
| 239 bool IsBool() { return type() == Dart_CObject::kBool; } | 239 bool IsBool() { return type() == Dart_CObject_kBool; } |
| 240 bool IsInt32() { return type() == Dart_CObject::kInt32; } | 240 bool IsInt32() { return type() == Dart_CObject_kInt32; } |
| 241 bool IsInt64() { return type() == Dart_CObject::kInt64; } | 241 bool IsInt64() { return type() == Dart_CObject_kInt64; } |
| 242 bool IsInt32OrInt64() { return IsInt32() || IsInt64(); } | 242 bool IsInt32OrInt64() { return IsInt32() || IsInt64(); } |
| 243 bool IsIntptr() { return IsInt32OrInt64(); } | 243 bool IsIntptr() { return IsInt32OrInt64(); } |
| 244 bool IsBigint() { return type() == Dart_CObject::kBigint; } | 244 bool IsBigint() { return type() == Dart_CObject_kBigint; } |
| 245 bool IsDouble() { return type() == Dart_CObject::kDouble; } | 245 bool IsDouble() { return type() == Dart_CObject_kDouble; } |
| 246 bool IsString() { return type() == Dart_CObject::kString; } | 246 bool IsString() { return type() == Dart_CObject_kString; } |
| 247 bool IsArray() { return type() == Dart_CObject::kArray; } | 247 bool IsArray() { return type() == Dart_CObject_kArray; } |
| 248 bool IsTypedData() { return type() == Dart_CObject::kTypedData; } | 248 bool IsTypedData() { return type() == Dart_CObject_kTypedData; } |
| 249 bool IsUint8Array() { | 249 bool IsUint8Array() { |
| 250 return type() == Dart_CObject::kTypedData && | 250 return type() == Dart_CObject_kTypedData && |
| 251 byte_array_type() == Dart_CObject::kUint8Array; | 251 byte_array_type() == Dart_TypedData_kUint8; |
| 252 } | 252 } |
| 253 | 253 |
| 254 bool IsTrue() { | 254 bool IsTrue() { |
| 255 return type() == Dart_CObject::kBool && cobject_->value.as_bool; | 255 return type() == Dart_CObject_kBool && cobject_->value.as_bool; |
| 256 } | 256 } |
| 257 | 257 |
| 258 bool IsFalse() { | 258 bool IsFalse() { |
| 259 return type() == Dart_CObject::kBool && !cobject_->value.as_bool; | 259 return type() == Dart_CObject_kBool && !cobject_->value.as_bool; |
| 260 } | 260 } |
| 261 | 261 |
| 262 void* operator new(size_t size) { | 262 void* operator new(size_t size) { |
| 263 return Dart_ScopeAllocate(size); | 263 return Dart_ScopeAllocate(size); |
| 264 } | 264 } |
| 265 | 265 |
| 266 static CObject* Null(); | 266 static CObject* Null(); |
| 267 static CObject* True(); | 267 static CObject* True(); |
| 268 static CObject* False(); | 268 static CObject* False(); |
| 269 static CObject* Bool(bool value); | 269 static CObject* Bool(bool value); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 291 // Create a new CObject array with the current OS error. | 291 // Create a new CObject array with the current OS error. |
| 292 static CObject* NewOSError(); | 292 static CObject* NewOSError(); |
| 293 // Create a new CObject array with the specified OS error. | 293 // Create a new CObject array with the specified OS error. |
| 294 static CObject* NewOSError(OSError* os_error); | 294 static CObject* NewOSError(OSError* os_error); |
| 295 | 295 |
| 296 protected: | 296 protected: |
| 297 CObject() : cobject_(NULL) {} | 297 CObject() : cobject_(NULL) {} |
| 298 Dart_CObject* cobject_; | 298 Dart_CObject* cobject_; |
| 299 | 299 |
| 300 private: | 300 private: |
| 301 static Dart_CObject* New(Dart_CObject::Type type, int additional_bytes = 0); | 301 static Dart_CObject* New(Dart_CObject_Type type, int additional_bytes = 0); |
| 302 | 302 |
| 303 static Dart_CObject api_null_; | 303 static Dart_CObject api_null_; |
| 304 static Dart_CObject api_true_; | 304 static Dart_CObject api_true_; |
| 305 static Dart_CObject api_false_; | 305 static Dart_CObject api_false_; |
| 306 static CObject null_; | 306 static CObject null_; |
| 307 static CObject true_; | 307 static CObject true_; |
| 308 static CObject false_; | 308 static CObject false_; |
| 309 | 309 |
| 310 private: | 310 private: |
| 311 DISALLOW_COPY_AND_ASSIGN(CObject); | 311 DISALLOW_COPY_AND_ASSIGN(CObject); |
| 312 }; | 312 }; |
| 313 | 313 |
| 314 | 314 |
| 315 #define DECLARE_COBJECT_CONSTRUCTORS(t) \ | 315 #define DECLARE_COBJECT_CONSTRUCTORS(t) \ |
| 316 explicit CObject##t(Dart_CObject *cobject) : CObject(cobject) { \ | 316 explicit CObject##t(Dart_CObject *cobject) : CObject(cobject) { \ |
| 317 ASSERT(type() == Dart_CObject::k##t); \ | 317 ASSERT(type() == Dart_CObject_k##t); \ |
| 318 cobject_ = cobject; \ | 318 cobject_ = cobject; \ |
| 319 } \ | 319 } \ |
| 320 explicit CObject##t(CObject* cobject) : CObject() { \ | 320 explicit CObject##t(CObject* cobject) : CObject() { \ |
| 321 ASSERT(cobject != NULL); \ | 321 ASSERT(cobject != NULL); \ |
| 322 ASSERT(cobject->type() == Dart_CObject::k##t); \ | 322 ASSERT(cobject->type() == Dart_CObject_k##t); \ |
| 323 cobject_ = cobject->AsApiCObject(); \ | 323 cobject_ = cobject->AsApiCObject(); \ |
| 324 } \ | 324 } \ |
| 325 | 325 |
| 326 | 326 |
| 327 #define DECLARE_COBJECT_TYPED_DATA_CONSTRUCTORS(t) \ | 327 #define DECLARE_COBJECT_TYPED_DATA_CONSTRUCTORS(t) \ |
| 328 explicit CObject##t(Dart_CObject *cobject) : CObject(cobject) { \ | 328 explicit CObject##t##Array(Dart_CObject *cobject) : CObject(cobject) { \ |
| 329 ASSERT(type() == Dart_CObject::kTypedData); \ | 329 ASSERT(type() == Dart_CObject_kTypedData); \ |
| 330 ASSERT(byte_array_type() == Dart_CObject::k##t); \ | 330 ASSERT(byte_array_type() == Dart_TypedData_k##t); \ |
| 331 cobject_ = cobject; \ | 331 cobject_ = cobject; \ |
| 332 } \ | 332 } \ |
| 333 explicit CObject##t(CObject* cobject) : CObject() { \ | 333 explicit CObject##t##Array(CObject* cobject) : CObject() { \ |
| 334 ASSERT(cobject != NULL); \ | 334 ASSERT(cobject != NULL); \ |
| 335 ASSERT(cobject->type() == Dart_CObject::kTypedData); \ | 335 ASSERT(cobject->type() == Dart_CObject_kTypedData); \ |
| 336 ASSERT(cobject->byte_array_type() == Dart_CObject::k##t); \ | 336 ASSERT(cobject->byte_array_type() == Dart_TypedData_k##t); \ |
| 337 cobject_ = cobject->AsApiCObject(); \ | 337 cobject_ = cobject->AsApiCObject(); \ |
| 338 } \ | 338 } \ |
| 339 | 339 |
| 340 | 340 |
| 341 #define DECLARE_COBJECT_EXTERNAL_TYPED_DATA_CONSTRUCTORS(t) \ | 341 #define DECLARE_COBJECT_EXTERNAL_TYPED_DATA_CONSTRUCTORS(t) \ |
| 342 explicit CObjectExternal##t(Dart_CObject *cobject) : CObject(cobject) { \ | 342 explicit CObjectExternal##t##Array(Dart_CObject *cobject) \ |
| 343 ASSERT(type() == Dart_CObject::kExternalTypedData); \ | 343 : CObject(cobject) { \ |
| 344 ASSERT(byte_array_type() == Dart_CObject::k##t); \ | 344 ASSERT(type() == Dart_CObject_kExternalTypedData); \ |
| 345 ASSERT(byte_array_type() == Dart_TypedData_k##t); \ |
| 345 cobject_ = cobject; \ | 346 cobject_ = cobject; \ |
| 346 } \ | 347 } \ |
| 347 explicit CObjectExternal##t(CObject* cobject) : CObject() { \ | 348 explicit CObjectExternal##t##Array(CObject* cobject) : CObject() { \ |
| 348 ASSERT(cobject != NULL); \ | 349 ASSERT(cobject != NULL); \ |
| 349 ASSERT(cobject->type() == Dart_CObject::kExternalTypedData); \ | 350 ASSERT(cobject->type() == Dart_CObject_kExternalTypedData); \ |
| 350 ASSERT(cobject->byte_array_type() == Dart_CObject::k##t); \ | 351 ASSERT(cobject->byte_array_type() == Dart_TypedData_k##t); \ |
| 351 cobject_ = cobject->AsApiCObject(); \ | 352 cobject_ = cobject->AsApiCObject(); \ |
| 352 } \ | 353 } \ |
| 353 | 354 |
| 354 | 355 |
| 355 class CObjectBool : public CObject { | 356 class CObjectBool : public CObject { |
| 356 public: | 357 public: |
| 357 DECLARE_COBJECT_CONSTRUCTORS(Bool) | 358 DECLARE_COBJECT_CONSTRUCTORS(Bool) |
| 358 | 359 |
| 359 bool Value() const { return cobject_->value.as_bool; } | 360 bool Value() const { return cobject_->value.as_bool; } |
| 360 | 361 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 381 int64_t Value() const { return cobject_->value.as_int64; } | 382 int64_t Value() const { return cobject_->value.as_int64; } |
| 382 | 383 |
| 383 private: | 384 private: |
| 384 DISALLOW_COPY_AND_ASSIGN(CObjectInt64); | 385 DISALLOW_COPY_AND_ASSIGN(CObjectInt64); |
| 385 }; | 386 }; |
| 386 | 387 |
| 387 | 388 |
| 388 class CObjectIntptr : public CObject { | 389 class CObjectIntptr : public CObject { |
| 389 public: | 390 public: |
| 390 explicit CObjectIntptr(Dart_CObject *cobject) : CObject(cobject) { | 391 explicit CObjectIntptr(Dart_CObject *cobject) : CObject(cobject) { |
| 391 ASSERT(type() == Dart_CObject::kInt32 || type() == Dart_CObject::kInt64); | 392 ASSERT(type() == Dart_CObject_kInt32 || type() == Dart_CObject_kInt64); |
| 392 cobject_ = cobject; | 393 cobject_ = cobject; |
| 393 } | 394 } |
| 394 explicit CObjectIntptr(CObject* cobject) : CObject() { | 395 explicit CObjectIntptr(CObject* cobject) : CObject() { |
| 395 ASSERT(cobject != NULL); | 396 ASSERT(cobject != NULL); |
| 396 ASSERT(cobject->type() == Dart_CObject::kInt64 || | 397 ASSERT(cobject->type() == Dart_CObject_kInt64 || |
| 397 cobject->type() == Dart_CObject::kInt32); | 398 cobject->type() == Dart_CObject_kInt32); |
| 398 cobject_ = cobject->AsApiCObject(); | 399 cobject_ = cobject->AsApiCObject(); |
| 399 } | 400 } |
| 400 | 401 |
| 401 intptr_t Value() { | 402 intptr_t Value() { |
| 402 intptr_t result; | 403 intptr_t result; |
| 403 if (type() == Dart_CObject::kInt32) { | 404 if (type() == Dart_CObject_kInt32) { |
| 404 result = cobject_->value.as_int32; | 405 result = cobject_->value.as_int32; |
| 405 } else { | 406 } else { |
| 406 ASSERT(sizeof(result) == 8); | 407 ASSERT(sizeof(result) == 8); |
| 407 result = static_cast<intptr_t>(cobject_->value.as_int64); | 408 result = static_cast<intptr_t>(cobject_->value.as_int64); |
| 408 } | 409 } |
| 409 return result; | 410 return result; |
| 410 } | 411 } |
| 411 | 412 |
| 412 private: | 413 private: |
| 413 DISALLOW_COPY_AND_ASSIGN(CObjectIntptr); | 414 DISALLOW_COPY_AND_ASSIGN(CObjectIntptr); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 } | 462 } |
| 462 | 463 |
| 463 private: | 464 private: |
| 464 DISALLOW_COPY_AND_ASSIGN(CObjectArray); | 465 DISALLOW_COPY_AND_ASSIGN(CObjectArray); |
| 465 }; | 466 }; |
| 466 | 467 |
| 467 | 468 |
| 468 class CObjectTypedData : public CObject { | 469 class CObjectTypedData : public CObject { |
| 469 public: | 470 public: |
| 470 explicit CObjectTypedData(Dart_CObject *cobject) : CObject(cobject) { | 471 explicit CObjectTypedData(Dart_CObject *cobject) : CObject(cobject) { |
| 471 ASSERT(type() == Dart_CObject::kTypedData); | 472 ASSERT(type() == Dart_CObject_kTypedData); |
| 472 cobject_ = cobject; | 473 cobject_ = cobject; |
| 473 } | 474 } |
| 474 explicit CObjectTypedData(CObject* cobject) : CObject() { | 475 explicit CObjectTypedData(CObject* cobject) : CObject() { |
| 475 ASSERT(cobject != NULL); | 476 ASSERT(cobject != NULL); |
| 476 ASSERT(cobject->type() == Dart_CObject::kTypedData); | 477 ASSERT(cobject->type() == Dart_CObject_kTypedData); |
| 477 cobject_ = cobject->AsApiCObject(); | 478 cobject_ = cobject->AsApiCObject(); |
| 478 } | 479 } |
| 479 | 480 |
| 480 Dart_CObject::TypedDataType Type() const { | 481 Dart_TypedData_Type Type() const { |
| 481 return cobject_->value.as_typed_data.type; | 482 return cobject_->value.as_typed_data.type; |
| 482 } | 483 } |
| 483 int Length() const { return cobject_->value.as_typed_data.length; } | 484 int Length() const { return cobject_->value.as_typed_data.length; } |
| 484 uint8_t* Buffer() const { return cobject_->value.as_typed_data.values; } | 485 uint8_t* Buffer() const { return cobject_->value.as_typed_data.values; } |
| 485 | 486 |
| 486 private: | 487 private: |
| 487 DISALLOW_COPY_AND_ASSIGN(CObjectTypedData); | 488 DISALLOW_COPY_AND_ASSIGN(CObjectTypedData); |
| 488 }; | 489 }; |
| 489 | 490 |
| 490 | 491 |
| 491 class CObjectUint8Array : public CObject { | 492 class CObjectUint8Array : public CObject { |
| 492 public: | 493 public: |
| 493 DECLARE_COBJECT_TYPED_DATA_CONSTRUCTORS(Uint8Array) | 494 DECLARE_COBJECT_TYPED_DATA_CONSTRUCTORS(Uint8) |
| 494 | 495 |
| 495 int Length() const { return cobject_->value.as_typed_data.length; } | 496 int Length() const { return cobject_->value.as_typed_data.length; } |
| 496 uint8_t* Buffer() const { return cobject_->value.as_typed_data.values; } | 497 uint8_t* Buffer() const { return cobject_->value.as_typed_data.values; } |
| 497 | 498 |
| 498 private: | 499 private: |
| 499 DISALLOW_COPY_AND_ASSIGN(CObjectUint8Array); | 500 DISALLOW_COPY_AND_ASSIGN(CObjectUint8Array); |
| 500 }; | 501 }; |
| 501 | 502 |
| 502 | 503 |
| 503 class CObjectExternalUint8Array : public CObject { | 504 class CObjectExternalUint8Array : public CObject { |
| 504 public: | 505 public: |
| 505 DECLARE_COBJECT_EXTERNAL_TYPED_DATA_CONSTRUCTORS(Uint8Array) | 506 DECLARE_COBJECT_EXTERNAL_TYPED_DATA_CONSTRUCTORS(Uint8) |
| 506 | 507 |
| 507 int Length() const { return cobject_->value.as_external_typed_data.length; } | 508 int Length() const { return cobject_->value.as_external_typed_data.length; } |
| 508 void SetLength(uint64_t length) { | 509 void SetLength(uint64_t length) { |
| 509 cobject_->value.as_external_typed_data.length = length; | 510 cobject_->value.as_external_typed_data.length = length; |
| 510 } | 511 } |
| 511 uint8_t* Data() const { return cobject_->value.as_external_typed_data.data; } | 512 uint8_t* Data() const { return cobject_->value.as_external_typed_data.data; } |
| 512 void* Peer() const { return cobject_->value.as_external_typed_data.peer; } | 513 void* Peer() const { return cobject_->value.as_external_typed_data.peer; } |
| 513 Dart_WeakPersistentHandleFinalizer Callback() const { | 514 Dart_WeakPersistentHandleFinalizer Callback() const { |
| 514 return cobject_->value.as_external_typed_data.callback; | 515 return cobject_->value.as_external_typed_data.callback; |
| 515 } | 516 } |
| 516 | 517 |
| 517 private: | 518 private: |
| 518 DISALLOW_COPY_AND_ASSIGN(CObjectExternalUint8Array); | 519 DISALLOW_COPY_AND_ASSIGN(CObjectExternalUint8Array); |
| 519 }; | 520 }; |
| 520 | 521 |
| 521 } // namespace bin | 522 } // namespace bin |
| 522 } // namespace dart | 523 } // namespace dart |
| 523 | 524 |
| 524 #endif // BIN_DARTUTILS_H_ | 525 #endif // BIN_DARTUTILS_H_ |
| OLD | NEW |