| 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 "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 28 matching lines...) Expand all Loading... |
| 39 count_ += 1; | 39 count_ += 1; |
| 40 } else { | 40 } else { |
| 41 abort(); // We should never get into this situation. | 41 abort(); // We should never get into this situation. |
| 42 } | 42 } |
| 43 } | 43 } |
| 44 | 44 |
| 45 void operator delete(void* pointer) { abort(); } | 45 void operator delete(void* pointer) { abort(); } |
| 46 | 46 |
| 47 private: | 47 private: |
| 48 void* operator new(size_t size); | 48 void* operator new(size_t size); |
| 49 CommandLineOptions(const CommandLineOptions&); | |
| 50 void operator=(const CommandLineOptions&); | |
| 51 | 49 |
| 52 int count_; | 50 int count_; |
| 53 int max_count_; | 51 int max_count_; |
| 54 const char** arguments_; | 52 const char** arguments_; |
| 53 |
| 54 DISALLOW_COPY_AND_ASSIGN(CommandLineOptions); |
| 55 }; | 55 }; |
| 56 | 56 |
| 57 | 57 |
| 58 class DartUtils { | 58 class DartUtils { |
| 59 public: | 59 public: |
| 60 // TODO(turnidge): Clean up the implementations of these so that | 60 // TODO(turnidge): Clean up the implementations of these so that |
| 61 // they allow for proper error propagation. | 61 // they allow for proper error propagation. |
| 62 | 62 |
| 63 // Assumes that the value object is known to be an integer object | 63 // Assumes that the value object is known to be an integer object |
| 64 // that fits in a signed 64-bit integer. | 64 // that fits in a signed 64-bit integer. |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 static CObject* Bool(bool value); | 162 static CObject* Bool(bool value); |
| 163 static Dart_CObject* NewInt32(int32_t value); | 163 static Dart_CObject* NewInt32(int32_t value); |
| 164 static Dart_CObject* NewInt64(int64_t value); | 164 static Dart_CObject* NewInt64(int64_t value); |
| 165 static Dart_CObject* NewIntptr(intptr_t value); | 165 static Dart_CObject* NewIntptr(intptr_t value); |
| 166 // TODO(sgjesse): Add support for kBigint. | 166 // TODO(sgjesse): Add support for kBigint. |
| 167 static Dart_CObject* NewDouble(double value); | 167 static Dart_CObject* NewDouble(double value); |
| 168 static Dart_CObject* NewString(int length); | 168 static Dart_CObject* NewString(int length); |
| 169 static Dart_CObject* NewString(const char* str); | 169 static Dart_CObject* NewString(const char* str); |
| 170 static Dart_CObject* NewArray(int length); | 170 static Dart_CObject* NewArray(int length); |
| 171 static Dart_CObject* NewUint8Array(int length); | 171 static Dart_CObject* NewUint8Array(int length); |
| 172 static Dart_CObject* NewExternalUint8Array(int length, |
| 173 uint8_t* data, |
| 174 void* peer, |
| 175 Dart_PeerFinalizer callback); |
| 172 | 176 |
| 173 Dart_CObject* AsApiCObject() { return cobject_; } | 177 Dart_CObject* AsApiCObject() { return cobject_; } |
| 174 | 178 |
| 175 // Create a new CObject array with an illegal arguments error. | 179 // Create a new CObject array with an illegal arguments error. |
| 176 static CObject* IllegalArgumentError(); | 180 static CObject* IllegalArgumentError(); |
| 177 // Create a new CObject array with a file closed error. | 181 // Create a new CObject array with a file closed error. |
| 178 static CObject* FileClosedError(); | 182 static CObject* FileClosedError(); |
| 179 // Create a new CObject array with the current OS error. | 183 // Create a new CObject array with the current OS error. |
| 180 static CObject* NewOSError(); | 184 static CObject* NewOSError(); |
| 181 // Create a new CObject array with the specified OS error. | 185 // Create a new CObject array with the specified OS error. |
| 182 static CObject* NewOSError(OSError* os_error); | 186 static CObject* NewOSError(OSError* os_error); |
| 183 | 187 |
| 184 protected: | 188 protected: |
| 185 CObject() : cobject_(NULL) {} | 189 CObject() : cobject_(NULL) {} |
| 186 Dart_CObject* cobject_; | 190 Dart_CObject* cobject_; |
| 187 | 191 |
| 188 private: | 192 private: |
| 189 static Dart_CObject* New(Dart_CObject::Type type, int additional_bytes = 0); | 193 static Dart_CObject* New(Dart_CObject::Type type, int additional_bytes = 0); |
| 190 | 194 |
| 191 static Dart_CObject api_null_; | 195 static Dart_CObject api_null_; |
| 192 static Dart_CObject api_true_; | 196 static Dart_CObject api_true_; |
| 193 static Dart_CObject api_false_; | 197 static Dart_CObject api_false_; |
| 194 static CObject null_; | 198 static CObject null_; |
| 195 static CObject true_; | 199 static CObject true_; |
| 196 static CObject false_; | 200 static CObject false_; |
| 201 |
| 202 private: |
| 203 DISALLOW_COPY_AND_ASSIGN(CObject); |
| 197 }; | 204 }; |
| 198 | 205 |
| 199 | 206 |
| 200 #define DECLARE_COBJECT_CONSTRUCTORS(t) \ | 207 #define DECLARE_COBJECT_CONSTRUCTORS(t) \ |
| 201 explicit CObject##t(Dart_CObject *cobject) : CObject(cobject) { \ | 208 explicit CObject##t(Dart_CObject *cobject) : CObject(cobject) { \ |
| 202 ASSERT(type() == Dart_CObject::k##t); \ | 209 ASSERT(type() == Dart_CObject::k##t); \ |
| 203 cobject_ = cobject; \ | 210 cobject_ = cobject; \ |
| 204 } \ | 211 } \ |
| 205 explicit CObject##t(CObject* cobject) : CObject() { \ | 212 explicit CObject##t(CObject* cobject) : CObject() { \ |
| 206 ASSERT(cobject != NULL); \ | 213 ASSERT(cobject != NULL); \ |
| 207 ASSERT(cobject->type() == Dart_CObject::k##t); \ | 214 ASSERT(cobject->type() == Dart_CObject::k##t); \ |
| 208 cobject_ = cobject->AsApiCObject(); \ | 215 cobject_ = cobject->AsApiCObject(); \ |
| 209 } | 216 } |
| 210 | 217 |
| 211 | 218 |
| 212 class CObjectBool : public CObject { | 219 class CObjectBool : public CObject { |
| 213 public: | 220 public: |
| 214 DECLARE_COBJECT_CONSTRUCTORS(Bool) | 221 DECLARE_COBJECT_CONSTRUCTORS(Bool) |
| 215 | 222 |
| 216 bool Value() const { return cobject_->value.as_bool; } | 223 bool Value() const { return cobject_->value.as_bool; } |
| 224 |
| 225 private: |
| 226 DISALLOW_COPY_AND_ASSIGN(CObjectBool); |
| 217 }; | 227 }; |
| 218 | 228 |
| 219 | 229 |
| 220 class CObjectInt32 : public CObject { | 230 class CObjectInt32 : public CObject { |
| 221 public: | 231 public: |
| 222 DECLARE_COBJECT_CONSTRUCTORS(Int32) | 232 DECLARE_COBJECT_CONSTRUCTORS(Int32) |
| 223 | 233 |
| 224 int32_t Value() const { return cobject_->value.as_int32; } | 234 int32_t Value() const { return cobject_->value.as_int32; } |
| 235 |
| 236 private: |
| 237 DISALLOW_COPY_AND_ASSIGN(CObjectInt32); |
| 225 }; | 238 }; |
| 226 | 239 |
| 227 | 240 |
| 228 class CObjectInt64 : public CObject { | 241 class CObjectInt64 : public CObject { |
| 229 public: | 242 public: |
| 230 DECLARE_COBJECT_CONSTRUCTORS(Int64) | 243 DECLARE_COBJECT_CONSTRUCTORS(Int64) |
| 231 | 244 |
| 232 int64_t Value() const { return cobject_->value.as_int64; } | 245 int64_t Value() const { return cobject_->value.as_int64; } |
| 246 |
| 247 private: |
| 248 DISALLOW_COPY_AND_ASSIGN(CObjectInt64); |
| 233 }; | 249 }; |
| 234 | 250 |
| 235 | 251 |
| 236 class CObjectIntptr : public CObject { | 252 class CObjectIntptr : public CObject { |
| 237 public: | 253 public: |
| 238 explicit CObjectIntptr(Dart_CObject *cobject) : CObject(cobject) { | 254 explicit CObjectIntptr(Dart_CObject *cobject) : CObject(cobject) { |
| 239 ASSERT(type() == Dart_CObject::kInt32 || type() == Dart_CObject::kInt64); | 255 ASSERT(type() == Dart_CObject::kInt32 || type() == Dart_CObject::kInt64); |
| 240 cobject_ = cobject; | 256 cobject_ = cobject; |
| 241 } | 257 } |
| 242 explicit CObjectIntptr(CObject* cobject) : CObject() { | 258 explicit CObjectIntptr(CObject* cobject) : CObject() { |
| 243 ASSERT(cobject != NULL); | 259 ASSERT(cobject != NULL); |
| 244 ASSERT(cobject->type() == Dart_CObject::kInt64 || | 260 ASSERT(cobject->type() == Dart_CObject::kInt64 || |
| 245 cobject->type() == Dart_CObject::kInt32); | 261 cobject->type() == Dart_CObject::kInt32); |
| 246 cobject_ = cobject->AsApiCObject(); | 262 cobject_ = cobject->AsApiCObject(); |
| 247 } | 263 } |
| 248 | 264 |
| 249 intptr_t Value() { | 265 intptr_t Value() { |
| 250 intptr_t result; | 266 intptr_t result; |
| 251 if (type() == Dart_CObject::kInt32) { | 267 if (type() == Dart_CObject::kInt32) { |
| 252 result = cobject_->value.as_int32; | 268 result = cobject_->value.as_int32; |
| 253 } else { | 269 } else { |
| 254 result = cobject_->value.as_int64; | 270 result = cobject_->value.as_int64; |
| 255 } | 271 } |
| 256 return result; | 272 return result; |
| 257 } | 273 } |
| 274 |
| 275 private: |
| 276 DISALLOW_COPY_AND_ASSIGN(CObjectIntptr); |
| 258 }; | 277 }; |
| 259 | 278 |
| 260 | 279 |
| 261 class CObjectBigint : public CObject { | 280 class CObjectBigint : public CObject { |
| 262 public: | 281 public: |
| 263 DECLARE_COBJECT_CONSTRUCTORS(Bigint) | 282 DECLARE_COBJECT_CONSTRUCTORS(Bigint) |
| 264 | 283 |
| 265 char* Value() const { return cobject_->value.as_bigint; } | 284 char* Value() const { return cobject_->value.as_bigint; } |
| 285 |
| 286 private: |
| 287 DISALLOW_COPY_AND_ASSIGN(CObjectBigint); |
| 266 }; | 288 }; |
| 267 | 289 |
| 268 | 290 |
| 269 class CObjectDouble : public CObject { | 291 class CObjectDouble : public CObject { |
| 270 public: | 292 public: |
| 271 DECLARE_COBJECT_CONSTRUCTORS(Double) | 293 DECLARE_COBJECT_CONSTRUCTORS(Double) |
| 272 | 294 |
| 273 double Value() const { return cobject_->value.as_double; } | 295 double Value() const { return cobject_->value.as_double; } |
| 296 |
| 297 private: |
| 298 DISALLOW_COPY_AND_ASSIGN(CObjectDouble); |
| 274 }; | 299 }; |
| 275 | 300 |
| 276 | 301 |
| 277 class CObjectString : public CObject { | 302 class CObjectString : public CObject { |
| 278 public: | 303 public: |
| 279 DECLARE_COBJECT_CONSTRUCTORS(String) | 304 DECLARE_COBJECT_CONSTRUCTORS(String) |
| 280 | 305 |
| 281 int Length() const { return strlen(cobject_->value.as_string); } | 306 int Length() const { return strlen(cobject_->value.as_string); } |
| 282 char* CString() const { return cobject_->value.as_string; } | 307 char* CString() const { return cobject_->value.as_string; } |
| 308 |
| 309 private: |
| 310 DISALLOW_COPY_AND_ASSIGN(CObjectString); |
| 283 }; | 311 }; |
| 284 | 312 |
| 285 | 313 |
| 286 class CObjectArray : public CObject { | 314 class CObjectArray : public CObject { |
| 287 public: | 315 public: |
| 288 DECLARE_COBJECT_CONSTRUCTORS(Array) | 316 DECLARE_COBJECT_CONSTRUCTORS(Array) |
| 289 | 317 |
| 290 int Length() const { return cobject_->value.as_array.length; } | 318 int Length() const { return cobject_->value.as_array.length; } |
| 291 CObject* operator[](int index) const { | 319 CObject* operator[](int index) const { |
| 292 return new CObject(cobject_->value.as_array.values[index]); | 320 return new CObject(cobject_->value.as_array.values[index]); |
| 293 } | 321 } |
| 294 void SetAt(int index, CObject* value) { | 322 void SetAt(int index, CObject* value) { |
| 295 cobject_->value.as_array.values[index] = value->AsApiCObject(); | 323 cobject_->value.as_array.values[index] = value->AsApiCObject(); |
| 296 } | 324 } |
| 325 |
| 326 private: |
| 327 DISALLOW_COPY_AND_ASSIGN(CObjectArray); |
| 297 }; | 328 }; |
| 298 | 329 |
| 299 | 330 |
| 300 class CObjectUint8Array : public CObject { | 331 class CObjectUint8Array : public CObject { |
| 301 public: | 332 public: |
| 302 DECLARE_COBJECT_CONSTRUCTORS(Uint8Array) | 333 DECLARE_COBJECT_CONSTRUCTORS(Uint8Array) |
| 303 | 334 |
| 304 int Length() const { return cobject_->value.as_byte_array.length; } | 335 int Length() const { return cobject_->value.as_byte_array.length; } |
| 305 uint8_t* Buffer() const { return cobject_->value.as_byte_array.values; } | 336 uint8_t* Buffer() const { return cobject_->value.as_byte_array.values; } |
| 337 |
| 338 private: |
| 339 DISALLOW_COPY_AND_ASSIGN(CObjectUint8Array); |
| 340 }; |
| 341 |
| 342 |
| 343 class CObjectExternalUint8Array : public CObject { |
| 344 public: |
| 345 DECLARE_COBJECT_CONSTRUCTORS(ExternalUint8Array) |
| 346 |
| 347 int Length() const { return cobject_->value.as_external_byte_array.length; } |
| 348 uint8_t* Data() const { return cobject_->value.as_external_byte_array.data; } |
| 349 void* Peer() const { return cobject_->value.as_external_byte_array.peer; } |
| 350 Dart_PeerFinalizer Callback() const { |
| 351 return cobject_->value.as_external_byte_array.callback; |
| 352 } |
| 353 |
| 354 private: |
| 355 DISALLOW_COPY_AND_ASSIGN(CObjectExternalUint8Array); |
| 306 }; | 356 }; |
| 307 | 357 |
| 308 #endif // BIN_DARTUTILS_H_ | 358 #endif // BIN_DARTUTILS_H_ |
| OLD | NEW |