diff options
Diffstat (limited to 'compiler/semtempl.nim')
-rw-r--r-- | compiler/semtempl.nim | 42 |
1 files changed, 23 insertions, 19 deletions
diff --git a/compiler/semtempl.nim b/compiler/semtempl.nim index 2854c90ae..4b283f793 100644 --- a/compiler/semtempl.nim +++ b/compiler/semtempl.nim @@ -34,7 +34,7 @@ type spNone, spGenSym, spInject proc symBinding(n: PNode): TSymBinding = - for i in countup(0, sonsLen(n) - 1): + for i in 0 ..< sonsLen(n): var it = n.sons[i] var key = if it.kind == nkExprColonExpr: it.sons[0] else: it if key.kind == nkIdent: @@ -251,7 +251,7 @@ proc semRoutineInTemplName(c: var TemplCtx, n: PNode): PNode = result = newSymNode(s, n.info) onUse(n.info, s) else: - for i in countup(0, safeLen(n) - 1): + for i in 0 ..< safeLen(n): result.sons[i] = semRoutineInTemplName(c, n.sons[i]) proc semRoutineInTemplBody(c: var TemplCtx, n: PNode, k: TSymKind): PNode = @@ -286,7 +286,7 @@ proc semRoutineInTemplBody(c: var TemplCtx, n: PNode, k: TSymKind): PNode = closeScope(c) proc semTemplSomeDecl(c: var TemplCtx, n: PNode, symKind: TSymKind; start=0) = - for i in countup(start, sonsLen(n) - 1): + for i in start ..< sonsLen(n): var a = n.sons[i] if a.kind == nkCommentStmt: continue if (a.kind != nkIdentDefs) and (a.kind != nkVarTuple): illFormedAst(a, c.c.config) @@ -298,7 +298,7 @@ proc semTemplSomeDecl(c: var TemplCtx, n: PNode, symKind: TSymKind; start=0) = when defined(nimsuggest): dec c.c.inTypeContext a.sons[L-1] = semTemplBody(c, a.sons[L-1]) - for j in countup(0, L-3): + for j in 0 .. L-3: addLocalDecl(c, a.sons[j], symKind) proc semPattern(c: PContext, n: PNode): PNode @@ -342,7 +342,7 @@ proc semTemplBody(c: var TemplCtx, n: PNode): PNode = of nkEmpty, nkSym..nkNilLit, nkComesFrom: discard of nkIfStmt: - for i in countup(0, sonsLen(n)-1): + for i in 0 ..< sonsLen(n): var it = n.sons[i] if it.len == 2: openScope(c) @@ -353,17 +353,17 @@ proc semTemplBody(c: var TemplCtx, n: PNode): PNode = n.sons[i] = semTemplBodyScope(c, it) of nkWhileStmt: openScope(c) - for i in countup(0, sonsLen(n)-1): + for i in 0 ..< sonsLen(n): n.sons[i] = semTemplBody(c, n.sons[i]) closeScope(c) of nkCaseStmt: openScope(c) n.sons[0] = semTemplBody(c, n.sons[0]) - for i in countup(1, sonsLen(n)-1): + for i in 1 ..< sonsLen(n): var a = n.sons[i] checkMinSonsLen(a, 1, c.c.config) var L = sonsLen(a) - for j in countup(0, L-2): + for j in 0 .. L-2: a.sons[j] = semTemplBody(c, a.sons[j]) a.sons[L-1] = semTemplBodyScope(c, a.sons[L-1]) closeScope(c) @@ -371,8 +371,12 @@ proc semTemplBody(c: var TemplCtx, n: PNode): PNode = var L = sonsLen(n) openScope(c) n.sons[L-2] = semTemplBody(c, n.sons[L-2]) - for i in countup(0, L - 3): - addLocalDecl(c, n.sons[i], skForVar) + for i in 0 .. L - 3: + if n[i].kind == nkVarTuple: + for j in 0 ..< sonsLen(n[i])-1: + addLocalDecl(c, n[i][j], skForVar) + else: + addLocalDecl(c, n.sons[i], skForVar) openScope(c) n.sons[L-1] = semTemplBody(c, n.sons[L-1]) closeScope(c) @@ -394,12 +398,12 @@ proc semTemplBody(c: var TemplCtx, n: PNode): PNode = of nkTryStmt, nkHiddenTryStmt: checkMinSonsLen(n, 2, c.c.config) n.sons[0] = semTemplBodyScope(c, n.sons[0]) - for i in countup(1, sonsLen(n)-1): + for i in 1 ..< sonsLen(n): var a = n.sons[i] checkMinSonsLen(a, 1, c.c.config) var L = sonsLen(a) openScope(c) - for j in countup(0, L-2): + for j in 0 .. L-2: if a.sons[j].isInfixAs(): addLocalDecl(c, a.sons[j].sons[2], skLet) a.sons[j].sons[1] = semTemplBody(c, a.sons[j][1]) @@ -414,7 +418,7 @@ proc semTemplBody(c: var TemplCtx, n: PNode): PNode = n.sons[0] = semTemplBody(c, n.sons[0]) semTemplSomeDecl(c, n, skParam, 1) of nkConstSection: - for i in countup(0, sonsLen(n) - 1): + for i in 0 ..< sonsLen(n): var a = n.sons[i] if a.kind == nkCommentStmt: continue if (a.kind != nkConstDef): illFormedAst(a, c.c.config) @@ -423,13 +427,13 @@ proc semTemplBody(c: var TemplCtx, n: PNode): PNode = a.sons[1] = semTemplBody(c, a.sons[1]) a.sons[2] = semTemplBody(c, a.sons[2]) of nkTypeSection: - for i in countup(0, sonsLen(n) - 1): + for i in 0 ..< sonsLen(n): var a = n.sons[i] if a.kind == nkCommentStmt: continue if (a.kind != nkTypeDef): illFormedAst(a, c.c.config) checkSonsLen(a, 3, c.c.config) addLocalDecl(c, a.sons[0], skType) - for i in countup(0, sonsLen(n) - 1): + for i in 0 ..< sonsLen(n): var a = n.sons[i] if a.kind == nkCommentStmt: continue if (a.kind != nkTypeDef): illFormedAst(a, c.c.config) @@ -548,7 +552,7 @@ proc semTemplBodyDirty(c: var TemplCtx, n: PNode): PNode = if s != nil and contains(c.toBind, s.id): return symChoice(c.c, n, s, scClosed) result = n - for i in countup(0, sonsLen(n) - 1): + for i in 0 ..< sonsLen(n): result.sons[i] = semTemplBodyDirty(c, n.sons[i]) proc semTemplateDef(c: PContext, n: PNode): PNode = @@ -710,7 +714,7 @@ proc semPatternBody(c: var TemplCtx, n: PNode): PNode = if stupidStmtListExpr(n): result = semPatternBody(c, n.lastSon) else: - for i in countup(0, sonsLen(n) - 1): + for i in 0 ..< sonsLen(n): result.sons[i] = semPatternBody(c, n.sons[i]) of nkCallKinds: let s = qualifiedLookUp(c.c, n.sons[0], {}) @@ -743,7 +747,7 @@ proc semPatternBody(c: var TemplCtx, n: PNode): PNode = result.sons[1] = semPatternBody(c, n.sons[1]) return - for i in countup(0, sonsLen(n) - 1): + for i in 0 ..< sonsLen(n): result.sons[i] = semPatternBody(c, n.sons[i]) else: # dotExpr is ambiguous: note that we explicitly allow 'x.TemplateParam', @@ -759,7 +763,7 @@ proc semPatternBody(c: var TemplCtx, n: PNode): PNode = of nkPar: if n.len == 1: return semPatternBody(c, n.sons[0]) else: discard - for i in countup(0, sonsLen(n) - 1): + for i in 0 ..< sonsLen(n): result.sons[i] = semPatternBody(c, n.sons[i]) proc semPattern(c: PContext, n: PNode): PNode = |