summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorZahary Karadjov <zahary@gmail.com>2012-04-15 02:53:32 +0300
committerZahary Karadjov <zahary@gmail.com>2012-04-15 02:53:32 +0300
commit57fe3e8c41c6c046b2ad91ea382ce7c31061f04d (patch)
tree9606d2f1b29e9a569fe34eb05dc0e26cab8ec5bf
parent20d56875de743d23988a2b0d6a17709e899881c9 (diff)
downloadNim-57fe3e8c41c6c046b2ad91ea382ce7c31061f04d.tar.gz
avoid duplicated variable names in unrolled loops
-rwxr-xr-xcompiler/semdata.nim1
-rwxr-xr-xcompiler/semstmts.nim8
2 files changed, 7 insertions, 2 deletions
diff --git a/compiler/semdata.nim b/compiler/semdata.nim
index 80aed2fd4..f97da4717 100755
--- a/compiler/semdata.nim
+++ b/compiler/semdata.nim
@@ -62,6 +62,7 @@ type
     AmbiguousSymbols*: TIntSet # ids of all ambiguous symbols (cannot
                                # store this info in the syms themselves!)
     InGenericContext*: int     # > 0 if we are in a generic
+    InUnrolledContext*: int    # > 0 if we are unrolling a loop
     converters*: TSymSeq       # sequence of converters
     optionStack*: TLinkedList
     libs*: TLinkedList         # all libs used by this module
diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim
index b9b418c98..9e879ad0b 100755
--- a/compiler/semstmts.nim
+++ b/compiler/semstmts.nim
@@ -274,8 +274,10 @@ proc semVarOrLet(c: PContext, n: PNode, symkind: TSymKind): PNode =
       var v = semIdentDef(c, a.sons[j], symkind)
       addInterfaceDecl(c, v)
       when oKeepVariableNames:
-        let shadowed = findShadowedVar(c, v)
-        if shadowed != nil: shadowed.flags.incl(sfShadowed)
+        if c.InUnrolledContext > 0: v.flags.incl(sfShadowed)
+        else:
+          let shadowed = findShadowedVar(c, v)
+          if shadowed != nil: shadowed.flags.incl(sfShadowed)
       if def != nil and def.kind != nkEmpty:
         # this is only needed for the evaluation pass:
         v.ast = def
@@ -401,7 +403,9 @@ proc semForFields(c: PContext, n: PNode, m: TMagic): PNode =
     openScope(c.tab)
     var body = transfFieldLoopBody(loopBody, n, tupleTypeA, i,
                                    ord(m==mFieldPairs))
+    inc c.InUnrolledContext
     stmts.add(SemStmt(c, body))
+    dec c.InUnrolledContext
     closeScope(c.tab)
   Dec(c.p.nestedLoopCounter)
   var b = newNodeI(nkBreakStmt, n.info)