mirror of
https://github.com/status-im/nim-stew.git
synced 2025-01-24 02:50:18 +00:00
Add shims/macros.getCustomPragmaFixed
This commit is contained in:
parent
10e39dcfe5
commit
a695d9e7bd
@ -119,19 +119,26 @@ proc skipPragma*(n: NimNode): NimNode =
|
|||||||
if n.kind == nnkPragmaExpr: n[0]
|
if n.kind == nnkPragmaExpr: n[0]
|
||||||
else: n
|
else: n
|
||||||
|
|
||||||
macro hasCustomPragmaFixed*(T: type, field: static string, pragma: typed{nkSym}): untyped =
|
proc getPragma(T: NimNode, lookedUpField: string, pragma: NimNode): NimNode =
|
||||||
let Tresolved = getType(T)[1]
|
let Tresolved = getType(T)[1]
|
||||||
if isTuple(Tresolved):
|
if isTuple(Tresolved):
|
||||||
return newLit(false)
|
return nil
|
||||||
|
|
||||||
for f in recordFields(Tresolved.getImpl):
|
for f in recordFields(Tresolved.getImpl):
|
||||||
var fieldName = f.name
|
var fieldName = f.name
|
||||||
# TODO: Fix this in eqIdent
|
# TODO: Fix this in eqIdent
|
||||||
if fieldName.kind == nnkAccQuoted: fieldName = fieldName[0]
|
if fieldName.kind == nnkAccQuoted: fieldName = fieldName[0]
|
||||||
if eqIdent(fieldName, field):
|
if eqIdent(fieldName, lookedUpField):
|
||||||
return newLit(f.pragmas.findPragma(pragma) != nil)
|
return f.pragmas.findPragma(pragma)
|
||||||
|
|
||||||
error "The type " & $Tresolved & " doesn't have a field named " & field
|
error "The type " & $Tresolved & " doesn't have a field named " & lookedUpField
|
||||||
|
|
||||||
|
macro getCustomPragmaFixed*(T: type, field: static string, pragma: typed{nkSym}): untyped =
|
||||||
|
let p = getPragma(T, field, pragma)
|
||||||
|
if p != nil and p.len == 2: p[1] else: p
|
||||||
|
|
||||||
|
macro hasCustomPragmaFixed*(T: type, field: static string, pragma: typed{nkSym}): untyped =
|
||||||
|
newLit(getPragma(T, field, pragma) != nil)
|
||||||
|
|
||||||
proc humaneTypeName*(typedescNode: NimNode): string =
|
proc humaneTypeName*(typedescNode: NimNode): string =
|
||||||
var t = getType(typedescNode)[1]
|
var t = getType(typedescNode)[1]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user