Custom pragmas in procs bug fix (#7086)
This commit is contained in:
parent
d9c922fc70
commit
27aab0be16
4 changed files with 17 additions and 5 deletions
|
|
@ -979,6 +979,7 @@ const
|
||||||
nkIdentKinds* = {nkIdent, nkSym, nkAccQuoted, nkOpenSymChoice,
|
nkIdentKinds* = {nkIdent, nkSym, nkAccQuoted, nkOpenSymChoice,
|
||||||
nkClosedSymChoice}
|
nkClosedSymChoice}
|
||||||
|
|
||||||
|
nkPragmaCallKinds* = {nkExprColonExpr, nkCall, nkCallStrLit}
|
||||||
nkLiterals* = {nkCharLit..nkTripleStrLit}
|
nkLiterals* = {nkCharLit..nkTripleStrLit}
|
||||||
nkLambdaKinds* = {nkLambda, nkDo}
|
nkLambdaKinds* = {nkLambda, nkDo}
|
||||||
declarativeDefs* = {nkProcDef, nkFuncDef, nkMethodDef, nkIteratorDef, nkConverterDef}
|
declarativeDefs* = {nkProcDef, nkFuncDef, nkMethodDef, nkIteratorDef, nkConverterDef}
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@ import
|
||||||
const
|
const
|
||||||
FirstCallConv* = wNimcall
|
FirstCallConv* = wNimcall
|
||||||
LastCallConv* = wNoconv
|
LastCallConv* = wNoconv
|
||||||
nkPragmaCallKinds = {nkExprColonExpr, nkCall, nkCallStrLit}
|
|
||||||
|
|
||||||
const
|
const
|
||||||
procPragmas* = {FirstCallConv..LastCallConv, wImportc, wExportc, wNodecl,
|
procPragmas* = {FirstCallConv..LastCallConv, wImportc, wExportc, wNodecl,
|
||||||
|
|
|
||||||
|
|
@ -1143,7 +1143,7 @@ proc semProcAnnotation(c: PContext, prc: PNode;
|
||||||
if n == nil or n.kind == nkEmpty: return
|
if n == nil or n.kind == nkEmpty: return
|
||||||
for i in countup(0, n.len-1):
|
for i in countup(0, n.len-1):
|
||||||
var it = n.sons[i]
|
var it = n.sons[i]
|
||||||
var key = if it.kind == nkExprColonExpr: it.sons[0] else: it
|
var key = if it.kind in nkPragmaCallKinds and it.len >= 1: it.sons[0] else: it
|
||||||
let m = lookupMacro(c, key)
|
let m = lookupMacro(c, key)
|
||||||
if m == nil:
|
if m == nil:
|
||||||
if key.kind == nkIdent and key.ident.id == ord(wDelegator):
|
if key.kind == nkIdent and key.ident.id == ord(wDelegator):
|
||||||
|
|
@ -1164,10 +1164,12 @@ proc semProcAnnotation(c: PContext, prc: PNode;
|
||||||
if prc[pragmasPos].kind != nkEmpty and prc[pragmasPos].len == 0:
|
if prc[pragmasPos].kind != nkEmpty and prc[pragmasPos].len == 0:
|
||||||
prc.sons[pragmasPos] = emptyNode
|
prc.sons[pragmasPos] = emptyNode
|
||||||
|
|
||||||
if it.kind == nkExprColonExpr:
|
if it.kind in nkPragmaCallKinds and it.len > 1:
|
||||||
# pass pragma argument to the macro too:
|
# pass pragma arguments to the macro too:
|
||||||
x.add(it.sons[1])
|
for i in 1..<it.len:
|
||||||
|
x.add(it.sons[i])
|
||||||
x.add(prc)
|
x.add(prc)
|
||||||
|
|
||||||
# recursion assures that this works for multiple macro annotations too:
|
# recursion assures that this works for multiple macro annotations too:
|
||||||
result = semExpr(c, x)
|
result = semExpr(c, x)
|
||||||
# since a proc annotation can set pragmas, we process these here again.
|
# since a proc annotation can set pragmas, we process these here again.
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,11 @@ block: # A bit more advanced case
|
||||||
d {.alternativeKey("df", 5).}: float
|
d {.alternativeKey("df", 5).}: float
|
||||||
e {.alternativeKey(V = 5).}: seq[bool]
|
e {.alternativeKey(V = 5).}: seq[bool]
|
||||||
|
|
||||||
|
|
||||||
|
proc myproc(x: int, s: string) {.alternativeKey(V = 5), serializationKey"myprocSS".} =
|
||||||
|
echo x, s
|
||||||
|
|
||||||
|
|
||||||
var s: MySerializable
|
var s: MySerializable
|
||||||
|
|
||||||
const aDefVal = s.a.getCustomPragmaVal(defaultValue)
|
const aDefVal = s.a.getCustomPragmaVal(defaultValue)
|
||||||
|
|
@ -41,3 +46,8 @@ block: # A bit more advanced case
|
||||||
|
|
||||||
const cSerKey = getCustomPragmaVal(s.field.c, serializationKey)
|
const cSerKey = getCustomPragmaVal(s.field.c, serializationKey)
|
||||||
static: assert(cSerKey == "cc")
|
static: assert(cSerKey == "cc")
|
||||||
|
|
||||||
|
const procSerKey = getCustomPragmaVal(myproc, serializationKey)
|
||||||
|
static: assert(procSerKey == "myprocSS")
|
||||||
|
|
||||||
|
static: assert(hasCustomPragma(myproc, alternativeKey))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue