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,10 +848,16 @@ 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 sonsLen(n) >= 1: gsub(g, n.sons[0]) if n.len > 0 and isBracket(n[0]):
put(g, tkParLe, "(") gsub(g, n, 1)
gcomma(g, n, 1) put(g, tkBracketLe, "[")
put(g, tkParRi, ")") gcomma(g, n, 2)
put(g, tkBracketRi, "]")
else:
if sonsLen(n) >= 1: gsub(g, n.sons[0])
put(g, tkParLe, "(")
gcomma(g, n, 1)
put(g, tkParRi, ")")
of nkCallStrLit: of nkCallStrLit:
gsub(g, n, 0) gsub(g, n, 0)
if n.len > 1 and n.sons[1].kind == nkRStrLit: if n.len > 1 and n.sons[1].kind == nkRStrLit:
@ -913,18 +926,21 @@ 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:
put(g, tkParLe, "(") if renderIds in g.flags:
for i in countup(0, sonsLen(n) - 1): put(g, tkParLe, "(")
if i > 0: put(g, tkOpr, "|") for i in countup(0, sonsLen(n) - 1):
if n.sons[i].kind == nkSym: if i > 0: put(g, tkOpr, "|")
let s = n[i].sym if n.sons[i].kind == nkSym:
if s.owner != nil: let s = n[i].sym
put g, tkSymbol, n[i].sym.owner.name.s if s.owner != nil:
put g, tkOpr, "." put g, tkSymbol, n[i].sym.owner.name.s
put g, tkSymbol, n[i].sym.name.s put g, tkOpr, "."
else: put g, tkSymbol, n[i].sym.name.s
gsub(g, n.sons[i], c) else:
put(g, tkParRi, if n.kind == nkOpenSymChoice: "|...)" else: ")") gsub(g, n.sons[i], c)
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)