From dae175b3c4f0bfd577be0f8ef64f1723af0b04e1 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Fri, 4 Mar 2016 22:41:17 +0100 Subject: [PATCH] fixes #3868 --- compiler/renderer.nim | 48 +++++++++++++++++++++++++------------- compiler/typesrenderer.nim | 1 - 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/compiler/renderer.nim b/compiler/renderer.nim index 12852ba3d7..03f6d48325 100644 --- a/compiler/renderer.nim +++ b/compiler/renderer.nim @@ -812,6 +812,13 @@ proc gsub(g: var TSrcGen; n: PNode; i: int) = else: 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) = if isNil(n): return var @@ -841,10 +848,16 @@ proc gsub(g: var TSrcGen, n: PNode, c: TContext) = of nkCharLit: put(g, tkCharLit, atom(n)) of nkNilLit: put(g, tkNil, atom(n)) # complex expressions of nkCall, nkConv, nkDotCall, nkPattern, nkObjConstr: - if sonsLen(n) >= 1: gsub(g, n.sons[0]) - put(g, tkParLe, "(") - gcomma(g, n, 1) - put(g, tkParRi, ")") + 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]) + put(g, tkParLe, "(") + gcomma(g, n, 1) + put(g, tkParRi, ")") of nkCallStrLit: gsub(g, n, 0) 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) put(g, tkParRi, ")") of nkClosedSymChoice, nkOpenSymChoice: - put(g, tkParLe, "(") - for i in countup(0, sonsLen(n) - 1): - if i > 0: put(g, tkOpr, "|") - if n.sons[i].kind == nkSym: - let s = n[i].sym - if s.owner != nil: - put g, tkSymbol, n[i].sym.owner.name.s - put g, tkOpr, "." - put g, tkSymbol, n[i].sym.name.s - else: - gsub(g, n.sons[i], c) - put(g, tkParRi, if n.kind == nkOpenSymChoice: "|...)" else: ")") + if renderIds in g.flags: + put(g, tkParLe, "(") + for i in countup(0, sonsLen(n) - 1): + if i > 0: put(g, tkOpr, "|") + if n.sons[i].kind == nkSym: + let s = n[i].sym + if s.owner != nil: + put g, tkSymbol, n[i].sym.owner.name.s + put g, tkOpr, "." + put g, tkSymbol, n[i].sym.name.s + else: + gsub(g, n.sons[i], c) + put(g, tkParRi, if n.kind == nkOpenSymChoice: "|...)" else: ")") + else: + gsub(g, n, 0) of nkPar, nkClosure: put(g, tkParLe, "(") gcomma(g, n, c) diff --git a/compiler/typesrenderer.nim b/compiler/typesrenderer.nim index 700356ab75..d050a86b22 100644 --- a/compiler/typesrenderer.nim +++ b/compiler/typesrenderer.nim @@ -100,7 +100,6 @@ proc renderParamTypes(found: var seq[string], n: PNode) = if not typ.isNil: typeStr = typeToString(typ, preferExported) if typeStr.len < 1: return for i in 0 ..