Co-authored-by: cooldome <ariabushenko@bk.ru>
This commit is contained in:
parent
95fd8ae93c
commit
f86fc5316a
3 changed files with 46 additions and 24 deletions
|
|
@ -1472,9 +1472,14 @@ proc semProcAnnotation(c: PContext, prc: PNode;
|
||||||
if whichPragma(it) != wInvalid:
|
if whichPragma(it) != wInvalid:
|
||||||
# Not a custom pragma
|
# Not a custom pragma
|
||||||
continue
|
continue
|
||||||
elif strTableGet(c.userPragmas, considerQuotedIdent(c, key)) != nil:
|
else:
|
||||||
# User-defined pragma
|
let ident = considerQuotedIdent(c, key)
|
||||||
continue
|
if strTableGet(c.userPragmas, ident) != nil:
|
||||||
|
continue # User defined pragma
|
||||||
|
else:
|
||||||
|
let sym = searchInScopes(c, ident)
|
||||||
|
if sym != nil and sfCustomPragma in sym.flags:
|
||||||
|
continue # User custom pragma
|
||||||
|
|
||||||
# we transform ``proc p {.m, rest.}`` into ``m(do: proc p {.rest.})`` and
|
# we transform ``proc p {.m, rest.}`` into ``m(do: proc p {.rest.})`` and
|
||||||
# let the semantic checker deal with it:
|
# let the semantic checker deal with it:
|
||||||
|
|
|
||||||
|
|
@ -1576,28 +1576,34 @@ proc applyTypeSectionPragmas(c: PContext; pragmas, operand: PNode): PNode =
|
||||||
|
|
||||||
if p.kind == nkEmpty or whichPragma(p) != wInvalid:
|
if p.kind == nkEmpty or whichPragma(p) != wInvalid:
|
||||||
discard "builtin pragma"
|
discard "builtin pragma"
|
||||||
elif strTableGet(c.userPragmas, considerQuotedIdent(c, key)) != nil:
|
|
||||||
discard "User-defined pragma"
|
|
||||||
else:
|
else:
|
||||||
# we transform ``(arg1, arg2: T) {.m, rest.}`` into ``m((arg1, arg2: T) {.rest.})`` and
|
let ident = considerQuotedIdent(c, key)
|
||||||
# let the semantic checker deal with it:
|
if strTableGet(c.userPragmas, ident) != nil:
|
||||||
var x = newNodeI(nkCall, key.info)
|
discard "User-defined pragma"
|
||||||
x.add(key)
|
else:
|
||||||
if p.kind in nkPragmaCallKinds and p.len > 1:
|
let sym = searchInScopes(c, ident)
|
||||||
# pass pragma arguments to the macro too:
|
if sym != nil and sfCustomPragma in sym.flags:
|
||||||
for i in 1 ..< p.len:
|
discard "Custom user pragma"
|
||||||
x.add(p[i])
|
else:
|
||||||
# Also pass the node the pragma has been applied to
|
# we transform ``(arg1, arg2: T) {.m, rest.}`` into ``m((arg1, arg2: T) {.rest.})`` and
|
||||||
x.add(operand.copyTreeWithoutNode(p))
|
# let the semantic checker deal with it:
|
||||||
# recursion assures that this works for multiple macro annotations too:
|
var x = newNodeI(nkCall, key.info)
|
||||||
var r = semOverloadedCall(c, x, x, {skMacro, skTemplate}, {efNoUndeclared})
|
x.add(key)
|
||||||
if r != nil:
|
if p.kind in nkPragmaCallKinds and p.len > 1:
|
||||||
doAssert r[0].kind == nkSym
|
# pass pragma arguments to the macro too:
|
||||||
let m = r[0].sym
|
for i in 1 ..< p.len:
|
||||||
case m.kind
|
x.add(p[i])
|
||||||
of skMacro: return semMacroExpr(c, r, r, m, {efNoSemCheck})
|
# Also pass the node the pragma has been applied to
|
||||||
of skTemplate: return semTemplateExpr(c, r, m, {efNoSemCheck})
|
x.add(operand.copyTreeWithoutNode(p))
|
||||||
else: doAssert(false, "cannot happen")
|
# recursion assures that this works for multiple macro annotations too:
|
||||||
|
var r = semOverloadedCall(c, x, x, {skMacro, skTemplate}, {efNoUndeclared})
|
||||||
|
if r != nil:
|
||||||
|
doAssert r[0].kind == nkSym
|
||||||
|
let m = r[0].sym
|
||||||
|
case m.kind
|
||||||
|
of skMacro: return semMacroExpr(c, r, r, m, {efNoSemCheck})
|
||||||
|
of skTemplate: return semTemplateExpr(c, r, m, {efNoSemCheck})
|
||||||
|
else: doAssert(false, "cannot happen")
|
||||||
|
|
||||||
proc semProcTypeWithScope(c: PContext, n: PNode,
|
proc semProcTypeWithScope(c: PContext, n: PNode,
|
||||||
prev: PType, kind: TSymKind): PType =
|
prev: PType, kind: TSymKind): PType =
|
||||||
|
|
|
||||||
|
|
@ -335,3 +335,14 @@ ProcDef
|
||||||
|
|
||||||
static: assert bar("x") == "x"
|
static: assert bar("x") == "x"
|
||||||
|
|
||||||
|
#------------------------------------------------------
|
||||||
|
# issue #13909
|
||||||
|
|
||||||
|
template dependency*(id: string, weight = 0.0) {.pragma.}
|
||||||
|
|
||||||
|
type
|
||||||
|
MyObject* = object
|
||||||
|
provider*: proc(obj: string): pointer {.dependency("Data/" & obj, 16.1), noSideEffect.}
|
||||||
|
|
||||||
|
proc myproc(obj: string): string {.dependency("Data/" & obj, 16.1).} =
|
||||||
|
result = obj
|
||||||
Loading…
Add table
Add a link
Reference in a new issue