Use the new fixed hasCustomPragma definition

This commit is contained in:
Zahary Karadjov 2019-07-10 20:18:12 +03:00
parent 60613bac5d
commit e126d48e6c
No known key found for this signature in database
GPG Key ID: C8936F8A3073D609
1 changed files with 9 additions and 4 deletions

View File

@ -24,8 +24,10 @@ template enumInstanceSerializedFields*(obj: auto,
## will be read first and the iteration will continue depending on the
## value being deserialized.
##
type ObjType = type(obj)
for fieldNameVar, fieldVar in fieldPairs(obj):
when not hasCustomPragma(fieldVar, dontSerialize):
when not hasCustomPragmaFixed(ObjType, fieldNameVar, dontSerialize):
body
macro enumAllSerializedFields*(T: type,
@ -46,21 +48,24 @@ macro enumAllSerializedFields*(T: type,
## a different order. Fields marked with the `dontSerialize` pragma
## are skipped.
##
var T = getImpl(getType(T)[1])
var Timpl = getImpl(getType(T)[1])
result = newStmtList()
for field in recordFields(T):
for field in recordFields(Timpl):
if field.readPragma("dontSerialize") != nil:
continue
let
fident = field.name
fieldName = newLit($field.name)
fieldType = field.typ
result.add quote do:
block:
template `fieldNameVar`: auto = `fieldName`
type `fieldTypeVar` = `fieldType`
# type `fieldTypeVar` = `fieldType`
# TODO: This is a work-around for a classic Nim issue:
type `fieldTypeVar` = type(default(`T`).`fident`)
`body`
type