parent
ac3c4a94ad
commit
231a83a6b1
2 changed files with 30 additions and 6 deletions
|
|
@ -416,7 +416,7 @@ proc lsub(g: TSrcGen; n: PNode): int =
|
||||||
of nkCast: result = lsub(g, n.sons[0]) + lsub(g, n.sons[1]) + len("cast[]()")
|
of nkCast: result = lsub(g, n.sons[0]) + lsub(g, n.sons[1]) + len("cast[]()")
|
||||||
of nkAddr: result = (if n.len>0: lsub(g, n.sons[0]) + len("addr()") else: 4)
|
of nkAddr: result = (if n.len>0: lsub(g, n.sons[0]) + len("addr()") else: 4)
|
||||||
of nkStaticExpr: result = lsub(g, n.sons[0]) + len("static_")
|
of nkStaticExpr: result = lsub(g, n.sons[0]) + len("static_")
|
||||||
of nkHiddenAddr, nkHiddenDeref: result = lsub(g, n.sons[0])
|
of nkHiddenAddr, nkHiddenDeref, nkStringToCString, nkCStringToString: result = lsub(g, n.sons[0])
|
||||||
of nkCommand: result = lsub(g, n.sons[0]) + lcomma(g, n, 1) + 1
|
of nkCommand: result = lsub(g, n.sons[0]) + lcomma(g, n, 1) + 1
|
||||||
of nkExprEqExpr, nkAsgn, nkFastAsgn: result = lsons(g, n) + 3
|
of nkExprEqExpr, nkAsgn, nkFastAsgn: result = lsons(g, n) + 3
|
||||||
of nkPar, nkCurly, nkBracket, nkClosure: result = lcomma(g, n) + 2
|
of nkPar, nkCurly, nkBracket, nkClosure: result = lcomma(g, n) + 2
|
||||||
|
|
@ -446,7 +446,7 @@ proc lsub(g: TSrcGen; n: PNode): int =
|
||||||
of nkChckRangeF: result = len("chckRangeF") + 2 + lcomma(g, n)
|
of nkChckRangeF: result = len("chckRangeF") + 2 + lcomma(g, n)
|
||||||
of nkChckRange64: result = len("chckRange64") + 2 + lcomma(g, n)
|
of nkChckRange64: result = len("chckRange64") + 2 + lcomma(g, n)
|
||||||
of nkChckRange: result = len("chckRange") + 2 + lcomma(g, n)
|
of nkChckRange: result = len("chckRange") + 2 + lcomma(g, n)
|
||||||
of nkObjDownConv, nkObjUpConv, nkStringToCString, nkCStringToString:
|
of nkObjDownConv, nkObjUpConv:
|
||||||
result = 2
|
result = 2
|
||||||
if sonsLen(n) >= 1: result = result + lsub(g, n.sons[0])
|
if sonsLen(n) >= 1: result = result + lsub(g, n.sons[0])
|
||||||
result = result + lcomma(g, n, 1)
|
result = result + lcomma(g, n, 1)
|
||||||
|
|
@ -968,7 +968,7 @@ proc gsub(g: var TSrcGen, n: PNode, c: TContext) =
|
||||||
put(g, tkParLe, "(")
|
put(g, tkParLe, "(")
|
||||||
gcomma(g, n)
|
gcomma(g, n)
|
||||||
put(g, tkParRi, ")")
|
put(g, tkParRi, ")")
|
||||||
of nkObjDownConv, nkObjUpConv, nkStringToCString, nkCStringToString:
|
of nkObjDownConv, nkObjUpConv:
|
||||||
if sonsLen(n) >= 1: gsub(g, n.sons[0])
|
if sonsLen(n) >= 1: gsub(g, n.sons[0])
|
||||||
put(g, tkParLe, "(")
|
put(g, tkParLe, "(")
|
||||||
gcomma(g, n, 1)
|
gcomma(g, n, 1)
|
||||||
|
|
@ -1020,7 +1020,7 @@ proc gsub(g: var TSrcGen, n: PNode, c: TContext) =
|
||||||
of nkBind:
|
of nkBind:
|
||||||
putWithSpace(g, tkBind, "bind")
|
putWithSpace(g, tkBind, "bind")
|
||||||
gsub(g, n, 0)
|
gsub(g, n, 0)
|
||||||
of nkCheckedFieldExpr, nkHiddenAddr, nkHiddenDeref:
|
of nkCheckedFieldExpr, nkHiddenAddr, nkHiddenDeref, nkStringToCString, nkCStringToString:
|
||||||
gsub(g, n, 0)
|
gsub(g, n, 0)
|
||||||
of nkLambda:
|
of nkLambda:
|
||||||
putWithSpace(g, tkProc, "proc")
|
putWithSpace(g, tkProc, "proc")
|
||||||
|
|
@ -1073,9 +1073,13 @@ proc gsub(g: var TSrcGen, n: PNode, c: TContext) =
|
||||||
elif n[0].kind == nkSym: n[0].sym.name
|
elif n[0].kind == nkSym: n[0].sym.name
|
||||||
elif n[0].kind in {nkOpenSymChoice, nkClosedSymChoice}: n[0][0].sym.name
|
elif n[0].kind in {nkOpenSymChoice, nkClosedSymChoice}: n[0][0].sym.name
|
||||||
else: nil
|
else: nil
|
||||||
if n[1].kind == nkPrefix or (opr != nil and renderer.isKeyword(opr)):
|
var n_next = n[1]
|
||||||
|
while n_next.kind in {nkCheckedFieldExpr, nkHiddenAddr, nkHiddenDeref,
|
||||||
|
nkStringToCString, nkCStringToString} and n_next.len > 0:
|
||||||
|
n_next = n_next[0]
|
||||||
|
if n_next.kind == nkPrefix or (opr != nil and renderer.isKeyword(opr)):
|
||||||
put(g, tkSpaces, Space)
|
put(g, tkSpaces, Space)
|
||||||
if n.sons[1].kind == nkInfix:
|
if n_next.kind == nkInfix:
|
||||||
put(g, tkParLe, "(")
|
put(g, tkParLe, "(")
|
||||||
gsub(g, n.sons[1])
|
gsub(g, n.sons[1])
|
||||||
put(g, tkParRi, ")")
|
put(g, tkParRi, ")")
|
||||||
|
|
|
||||||
|
|
@ -24,3 +24,23 @@ macro foo: typed =
|
||||||
else: echo "Does not compute! (test OK)"
|
else: echo "Does not compute! (test OK)"
|
||||||
|
|
||||||
foo()
|
foo()
|
||||||
|
|
||||||
|
#------------------------------------
|
||||||
|
# bug #8287
|
||||||
|
type MyString = distinct string
|
||||||
|
|
||||||
|
proc `$` (c: MyString): string {.borrow.}
|
||||||
|
|
||||||
|
proc `!!` (c: cstring): int =
|
||||||
|
c.len
|
||||||
|
|
||||||
|
proc f(name: MyString): int =
|
||||||
|
!! $ name
|
||||||
|
|
||||||
|
macro repr_and_parse(fn: typed): typed =
|
||||||
|
let fn_impl = fn.getImpl
|
||||||
|
fn_impl.name = genSym(nskProc, $fn_impl.name)
|
||||||
|
echo fn_impl.repr
|
||||||
|
result = parseStmt(fn_impl.repr)
|
||||||
|
|
||||||
|
repr_and_parse(f)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue