This commit is contained in:
Andreas Rumpf 2016-03-04 22:41:17 +01:00
commit dae175b3c4
2 changed files with 32 additions and 17 deletions

View file

@ -812,6 +812,13 @@ proc gsub(g: var TSrcGen; n: PNode; i: int) =
else: else:
put(g, tkOpr, "<<" & $i & "th child missing for " & $n.kind & " >>") put(g, tkOpr, "<<" & $i & "th child missing for " & $n.kind & " >>")
proc isBracket*(n: PNode): bool =
case n.kind
of nkClosedSymChoice, nkOpenSymChoice:
if n.len > 0: result = isBracket(n[0])
of nkSym: result = n.sym.name.s == "[]"
else: result = false
proc gsub(g: var TSrcGen, n: PNode, c: TContext) = proc gsub(g: var TSrcGen, n: PNode, c: TContext) =
if isNil(n): return if isNil(n): return
var var
@ -841,6 +848,12 @@ proc gsub(g: var TSrcGen, n: PNode, c: TContext) =
of nkCharLit: put(g, tkCharLit, atom(n)) of nkCharLit: put(g, tkCharLit, atom(n))
of nkNilLit: put(g, tkNil, atom(n)) # complex expressions of nkNilLit: put(g, tkNil, atom(n)) # complex expressions
of nkCall, nkConv, nkDotCall, nkPattern, nkObjConstr: of nkCall, nkConv, nkDotCall, nkPattern, nkObjConstr:
if n.len > 0 and isBracket(n[0]):
gsub(g, n, 1)
put(g, tkBracketLe, "[")
gcomma(g, n, 2)
put(g, tkBracketRi, "]")
else:
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)
@ -913,6 +926,7 @@ proc gsub(g: var TSrcGen, n: PNode, c: TContext) =
gcomma(g, n, 1) gcomma(g, n, 1)
put(g, tkParRi, ")") put(g, tkParRi, ")")
of nkClosedSymChoice, nkOpenSymChoice: of nkClosedSymChoice, nkOpenSymChoice:
if renderIds in g.flags:
put(g, tkParLe, "(") put(g, tkParLe, "(")
for i in countup(0, sonsLen(n) - 1): for i in countup(0, sonsLen(n) - 1):
if i > 0: put(g, tkOpr, "|") if i > 0: put(g, tkOpr, "|")
@ -925,6 +939,8 @@ proc gsub(g: var TSrcGen, n: PNode, c: TContext) =
else: else:
gsub(g, n.sons[i], c) gsub(g, n.sons[i], c)
put(g, tkParRi, if n.kind == nkOpenSymChoice: "|...)" else: ")") put(g, tkParRi, if n.kind == nkOpenSymChoice: "|...)" else: ")")
else:
gsub(g, n, 0)
of nkPar, nkClosure: of nkPar, nkClosure:
put(g, tkParLe, "(") put(g, tkParLe, "(")
gcomma(g, n, c) gcomma(g, n, c)

View file

@ -100,7 +100,6 @@ proc renderParamTypes(found: var seq[string], n: PNode) =
if not typ.isNil: typeStr = typeToString(typ, preferExported) if not typ.isNil: typeStr = typeToString(typ, preferExported)
if typeStr.len < 1: return if typeStr.len < 1: return
for i in 0 .. <typePos: for i in 0 .. <typePos:
assert ((n[i].kind == nkIdent) or (n[i].kind == nkAccQuoted))
found.add(typeStr) found.add(typeStr)
else: else:
internalError(n.info, "renderParamTypes(found,n) with " & $n.kind) internalError(n.info, "renderParamTypes(found,n) with " & $n.kind)