@@ -234,7 +234,7 @@ inline bool operator!=(const Array &L, const Array &R) { return !(L == R); }
234
234
// / Each Value is one of the JSON kinds:
235
235
// / null (nullptr_t)
236
236
// / boolean (bool)
237
- // / number (double or int64 )
237
+ // / number (double, int64 or uint64 )
238
238
// / string (StringRef)
239
239
// / array (json::Array)
240
240
// / object (json::Object)
@@ -342,9 +342,20 @@ class Value {
342
342
Value (T B) : Type(T_Boolean) {
343
343
create<bool >(B);
344
344
}
345
- // Integers (except boolean). Must be non-narrowing convertible to int64_t.
345
+
346
+ // Unsigned 64-bit long integers.
347
+ template <typename T,
348
+ typename = std::enable_if_t <std::is_same<T, uint64_t >::value>,
349
+ bool = false , bool = false >
350
+ Value (T V) : Type(T_UINT64) {
351
+ create<uint64_t >(uint64_t {V});
352
+ }
353
+
354
+ // Integers (except boolean and uint64_t).
355
+ // Must be non-narrowing convertible to int64_t.
346
356
template <typename T, typename = std::enable_if_t <std::is_integral<T>::value>,
347
- typename = std::enable_if_t <!std::is_same<T, bool >::value>>
357
+ typename = std::enable_if_t <!std::is_same<T, bool >::value>,
358
+ typename = std::enable_if_t <!std::is_same<T, uint64_t >::value>>
348
359
Value (T I) : Type(T_Integer) {
349
360
create<int64_t >(int64_t {I});
350
361
}
@@ -382,6 +393,7 @@ class Value {
382
393
return Boolean;
383
394
case T_Double:
384
395
case T_Integer:
396
+ case T_UINT64:
385
397
return Number;
386
398
case T_String:
387
399
case T_StringRef:
@@ -410,6 +422,8 @@ class Value {
410
422
return as<double >();
411
423
if (LLVM_LIKELY (Type == T_Integer))
412
424
return as<int64_t >();
425
+ if (LLVM_LIKELY (Type == T_UINT64))
426
+ return as<uint64_t >();
413
427
return llvm::None;
414
428
}
415
429
// Succeeds if the Value is a Number, and exactly representable as int64_t.
@@ -425,6 +439,16 @@ class Value {
425
439
}
426
440
return llvm::None;
427
441
}
442
+ llvm::Optional<uint64_t > getAsUINT64 () const {
443
+ if (Type == T_UINT64)
444
+ return as<uint64_t >();
445
+ else if (Type == T_Integer) {
446
+ int64_t N = as<int64_t >();
447
+ if (N >= 0 )
448
+ return as<uint64_t >();
449
+ }
450
+ return llvm::None;
451
+ }
428
452
llvm::Optional<llvm::StringRef> getAsString () const {
429
453
if (Type == T_String)
430
454
return llvm::StringRef (as<std::string>());
@@ -467,20 +491,22 @@ class Value {
467
491
468
492
friend class OStream ;
469
493
470
- enum ValueType : char {
494
+ enum ValueType : char16_t {
471
495
T_Null,
472
496
T_Boolean,
473
497
T_Double,
474
498
T_Integer,
499
+ T_UINT64,
475
500
T_StringRef,
476
501
T_String,
477
502
T_Object,
478
503
T_Array,
479
504
};
480
505
// All members mutable, see moveFrom().
481
506
mutable ValueType Type;
482
- mutable llvm::AlignedCharArrayUnion<bool , double , int64_t , llvm::StringRef,
483
- std::string, json::Array, json::Object>
507
+ mutable llvm::AlignedCharArrayUnion<bool , double , int64_t , uint64_t ,
508
+ llvm::StringRef, std::string, json::Array,
509
+ json::Object>
484
510
Union;
485
511
friend bool operator ==(const Value &, const Value &);
486
512
};
@@ -683,6 +709,14 @@ inline bool fromJSON(const Value &E, bool &Out, Path P) {
683
709
P.report (" expected boolean" );
684
710
return false ;
685
711
}
712
+ inline bool fromJSON (const Value &E, uint64_t &Out, Path P) {
713
+ if (auto S = E.getAsUINT64 ()) {
714
+ Out = *S;
715
+ return true ;
716
+ }
717
+ P.report (" expected uint64_t" );
718
+ return false ;
719
+ }
686
720
inline bool fromJSON (const Value &E, std::nullptr_t &Out, Path P) {
687
721
if (auto S = E.getAsNull ()) {
688
722
Out = *S;
0 commit comments