More sophistication; Allow requiresInit to be specified per-field

This commit is contained in:
Zahary Karadjov 2020-03-27 18:43:23 +02:00 • committed by Andreas Rumpf
commit 7652aede41
4 changed files with 61 additions and 15 deletions

View file

@ -65,7 +65,7 @@ const
wInheritable, wGensym, wInject, wRequiresInit, wUnchecked, wUnion, wPacked,
wBorrow, wGcSafe, wPartial, wExplain, wPackage}
fieldPragmas* = declPragmas + {
wGuard, wBitsize, wCursor} - {wExportNims, wNodecl} # why exclude these?
wGuard, wBitsize, wCursor, wRequiresInit} - {wExportNims, wNodecl} # why exclude these?
varPragmas* = declPragmas + {wVolatile, wRegister, wThreadVar,
wMagic, wHeader, wCompilerProc, wCore, wDynlib,
wNoInit, wCompileTime, wGlobal,
@ -1087,8 +1087,12 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int,
else: incl(sym.typ.flags, tfUnion)
of wRequiresInit:
noVal(c, it)
if sym.typ == nil: invalidPragma(c, it)
else: incl(sym.typ.flags, tfRequiresInit)
if sym.kind == skField:
sym.flags.incl sfRequiresInit
elif sym.typ != nil:
incl(sym.typ.flags, tfRequiresInit)
else:
invalidPragma(c, it)
of wByRef:
noVal(c, it)
if sym == nil or sym.typ == nil: