simplify extccomp.nim json logic via jsonutils; fix #18084 (#18100)

* simplify extccomp.nim json logic via jsonutils
* fix #18084
* simplify further
* workaround for bootstrap that can be removed after updating csources_v1 >= 1.2
This commit is contained in:
Timothee Cour 2021-06-03 13:29:45 -07:00 • committed by GitHub
commit 654a20166e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 99 additions and 190 deletions

View file

@ -34,6 +34,23 @@ import macros
from enumutils import symbolName
from typetraits import OrdinalEnum
when not defined(nimFixedForwardGeneric):
# xxx remove pending csources_v1 update >= 1.2.0
proc to[T](node: JsonNode, t: typedesc[T]): T =
when T is string: node.getStr
elif T is bool: node.getBool
else: static: doAssert false, $T # support as needed (only needed during bootstrap)
proc isNamedTuple(T: typedesc): bool = # old implementation
when T isnot tuple: result = false
else:
var t: T
for name, _ in t.fieldPairs:
when name == "Field0": return compiles(t.Field0)
else: return true
return false
else:
proc isNamedTuple(T: typedesc): bool {.magic: "TypeTrait".}
type
Joptions* = object # xxx rename FromJsonOptions
## Options controlling the behavior of `fromJson`.
@ -61,7 +78,6 @@ proc initToJsonOptions*(): ToJsonOptions =
## initializes `ToJsonOptions` with sane options.
ToJsonOptions(enumMode: joptEnumOrd, jsonNodeMode: joptJsonNodeAsRef)
proc isNamedTuple(T: typedesc): bool {.magic: "TypeTrait".}
proc distinctBase(T: typedesc): typedesc {.magic: "TypeTrait".}
template distinctBase[T](a: T): untyped = distinctBase(typeof(a))(a)