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

Side by Side Diff: runtime/bin/dartutils.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/bin/crypto.cc ('k') | runtime/bin/dartutils.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 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
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
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) : CObject(cobject) { \
343 ASSERT(type() == Dart_CObject::kExternalTypedData); \ 343 ASSERT(type() == Dart_CObject_kExternalTypedData); \
344 ASSERT(byte_array_type() == Dart_CObject::k##t); \ 344 ASSERT(byte_array_type() == Dart_TypedData_k##t); \
345 cobject_ = cobject; \ 345 cobject_ = cobject; \
346 } \ 346 } \
347 explicit CObjectExternal##t(CObject* cobject) : CObject() { \ 347 explicit CObjectExternal##t##Array(CObject* cobject) : CObject() { \
348 ASSERT(cobject != NULL); \ 348 ASSERT(cobject != NULL); \
349 ASSERT(cobject->type() == Dart_CObject::kExternalTypedData); \ 349 ASSERT(cobject->type() == Dart_CObject_kExternalTypedData); \
350 ASSERT(cobject->byte_array_type() == Dart_CObject::k##t); \ 350 ASSERT(cobject->byte_array_type() == Dart_TypedData_k##t); \
351 cobject_ = cobject->AsApiCObject(); \ 351 cobject_ = cobject->AsApiCObject(); \
352 } \ 352 } \
353 353
siva 2013/05/31 01:12:41 I think there are some indentation issues with the
Ivan Posva 2013/05/31 04:35:46 I addressed all of the lint warning in the latest
354 354
355 class CObjectBool : public CObject { 355 class CObjectBool : public CObject {
356 public: 356 public:
357 DECLARE_COBJECT_CONSTRUCTORS(Bool) 357 DECLARE_COBJECT_CONSTRUCTORS(Bool)
358 358
359 bool Value() const { return cobject_->value.as_bool; } 359 bool Value() const { return cobject_->value.as_bool; }
360 360
361 private: 361 private:
362 DISALLOW_COPY_AND_ASSIGN(CObjectBool); 362 DISALLOW_COPY_AND_ASSIGN(CObjectBool);
363 }; 363 };
(...skipping 17 matching lines...) Expand all
381 int64_t Value() const { return cobject_->value.as_int64; } 381 int64_t Value() const { return cobject_->value.as_int64; }
382 382
383 private: 383 private:
384 DISALLOW_COPY_AND_ASSIGN(CObjectInt64); 384 DISALLOW_COPY_AND_ASSIGN(CObjectInt64);
385 }; 385 };
386 386
387 387
388 class CObjectIntptr : public CObject { 388 class CObjectIntptr : public CObject {
389 public: 389 public:
390 explicit CObjectIntptr(Dart_CObject *cobject) : CObject(cobject) { 390 explicit CObjectIntptr(Dart_CObject *cobject) : CObject(cobject) {
391 ASSERT(type() == Dart_CObject::kInt32 || type() == Dart_CObject::kInt64); 391 ASSERT(type() == Dart_CObject_kInt32 || type() == Dart_CObject_kInt64);
392 cobject_ = cobject; 392 cobject_ = cobject;
393 } 393 }
394 explicit CObjectIntptr(CObject* cobject) : CObject() { 394 explicit CObjectIntptr(CObject* cobject) : CObject() {
395 ASSERT(cobject != NULL); 395 ASSERT(cobject != NULL);
396 ASSERT(cobject->type() == Dart_CObject::kInt64 || 396 ASSERT(cobject->type() == Dart_CObject_kInt64 ||
397 cobject->type() == Dart_CObject::kInt32); 397 cobject->type() == Dart_CObject_kInt32);
398 cobject_ = cobject->AsApiCObject(); 398 cobject_ = cobject->AsApiCObject();
399 } 399 }
400 400
401 intptr_t Value() { 401 intptr_t Value() {
402 intptr_t result; 402 intptr_t result;
403 if (type() == Dart_CObject::kInt32) { 403 if (type() == Dart_CObject_kInt32) {
404 result = cobject_->value.as_int32; 404 result = cobject_->value.as_int32;
405 } else { 405 } else {
406 ASSERT(sizeof(result) == 8); 406 ASSERT(sizeof(result) == 8);
407 result = static_cast<intptr_t>(cobject_->value.as_int64); 407 result = static_cast<intptr_t>(cobject_->value.as_int64);
408 } 408 }
409 return result; 409 return result;
410 } 410 }
411 411
412 private: 412 private:
413 DISALLOW_COPY_AND_ASSIGN(CObjectIntptr); 413 DISALLOW_COPY_AND_ASSIGN(CObjectIntptr);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 } 461 }
462 462
463 private: 463 private:
464 DISALLOW_COPY_AND_ASSIGN(CObjectArray); 464 DISALLOW_COPY_AND_ASSIGN(CObjectArray);
465 }; 465 };
466 466
467 467
468 class CObjectTypedData : public CObject { 468 class CObjectTypedData : public CObject {
469 public: 469 public:
470 explicit CObjectTypedData(Dart_CObject *cobject) : CObject(cobject) { 470 explicit CObjectTypedData(Dart_CObject *cobject) : CObject(cobject) {
471 ASSERT(type() == Dart_CObject::kTypedData); 471 ASSERT(type() == Dart_CObject_kTypedData);
472 cobject_ = cobject; 472 cobject_ = cobject;
473 } 473 }
474 explicit CObjectTypedData(CObject* cobject) : CObject() { 474 explicit CObjectTypedData(CObject* cobject) : CObject() {
475 ASSERT(cobject != NULL); 475 ASSERT(cobject != NULL);
476 ASSERT(cobject->type() == Dart_CObject::kTypedData); 476 ASSERT(cobject->type() == Dart_CObject_kTypedData);
477 cobject_ = cobject->AsApiCObject(); 477 cobject_ = cobject->AsApiCObject();
478 } 478 }
479 479
480 Dart_CObject::TypedDataType Type() const { 480 Dart_TypedData_Type Type() const {
481 return cobject_->value.as_typed_data.type; 481 return cobject_->value.as_typed_data.type;
482 } 482 }
483 int Length() const { return cobject_->value.as_typed_data.length; } 483 int Length() const { return cobject_->value.as_typed_data.length; }
484 uint8_t* Buffer() const { return cobject_->value.as_typed_data.values; } 484 uint8_t* Buffer() const { return cobject_->value.as_typed_data.values; }
485 485
486 private: 486 private:
487 DISALLOW_COPY_AND_ASSIGN(CObjectTypedData); 487 DISALLOW_COPY_AND_ASSIGN(CObjectTypedData);
488 }; 488 };
489 489
490 490
491 class CObjectUint8Array : public CObject { 491 class CObjectUint8Array : public CObject {
492 public: 492 public:
493 DECLARE_COBJECT_TYPED_DATA_CONSTRUCTORS(Uint8Array) 493 DECLARE_COBJECT_TYPED_DATA_CONSTRUCTORS(Uint8)
494 494
495 int Length() const { return cobject_->value.as_typed_data.length; } 495 int Length() const { return cobject_->value.as_typed_data.length; }
496 uint8_t* Buffer() const { return cobject_->value.as_typed_data.values; } 496 uint8_t* Buffer() const { return cobject_->value.as_typed_data.values; }
497 497
498 private: 498 private:
499 DISALLOW_COPY_AND_ASSIGN(CObjectUint8Array); 499 DISALLOW_COPY_AND_ASSIGN(CObjectUint8Array);
500 }; 500 };
501 501
502 502
503 class CObjectExternalUint8Array : public CObject { 503 class CObjectExternalUint8Array : public CObject {
504 public: 504 public:
505 DECLARE_COBJECT_EXTERNAL_TYPED_DATA_CONSTRUCTORS(Uint8Array) 505 DECLARE_COBJECT_EXTERNAL_TYPED_DATA_CONSTRUCTORS(Uint8)
506 506
507 int Length() const { return cobject_->value.as_external_typed_data.length; } 507 int Length() const { return cobject_->value.as_external_typed_data.length; }
508 void SetLength(uint64_t length) { 508 void SetLength(uint64_t length) {
509 cobject_->value.as_external_typed_data.length = length; 509 cobject_->value.as_external_typed_data.length = length;
510 } 510 }
511 uint8_t* Data() const { return cobject_->value.as_external_typed_data.data; } 511 uint8_t* Data() const { return cobject_->value.as_external_typed_data.data; }
512 void* Peer() const { return cobject_->value.as_external_typed_data.peer; } 512 void* Peer() const { return cobject_->value.as_external_typed_data.peer; }
513 Dart_WeakPersistentHandleFinalizer Callback() const { 513 Dart_WeakPersistentHandleFinalizer Callback() const {
514 return cobject_->value.as_external_typed_data.callback; 514 return cobject_->value.as_external_typed_data.callback;
515 } 515 }
516 516
517 private: 517 private:
518 DISALLOW_COPY_AND_ASSIGN(CObjectExternalUint8Array); 518 DISALLOW_COPY_AND_ASSIGN(CObjectExternalUint8Array);
519 }; 519 };
520 520
521 } // namespace bin 521 } // namespace bin
522 } // namespace dart 522 } // namespace dart
523 523
524 #endif // BIN_DARTUTILS_H_ 524 #endif // BIN_DARTUTILS_H_
OLDNEW
« no previous file with comments | « runtime/bin/crypto.cc ('k') | runtime/bin/dartutils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698