Replace countup(x, y) with x .. y

This commit is contained in:
Clyybber 2019-05-07 12:37:28 +02:00
commit cc28eef38e
35 changed files with 103 additions and 103 deletions

View file

@ -1158,17 +1158,17 @@ const # for all kind of hash tables:
proc copyStrTable*(dest: var TStrTable, src: TStrTable) = proc copyStrTable*(dest: var TStrTable, src: TStrTable) =
dest.counter = src.counter dest.counter = src.counter
setLen(dest.data, len(src.data)) setLen(dest.data, len(src.data))
for i in countup(0, high(src.data)): dest.data[i] = src.data[i] for i in 0 .. high(src.data): dest.data[i] = src.data[i]
proc copyIdTable*(dest: var TIdTable, src: TIdTable) = proc copyIdTable*(dest: var TIdTable, src: TIdTable) =
dest.counter = src.counter dest.counter = src.counter
newSeq(dest.data, len(src.data)) newSeq(dest.data, len(src.data))
for i in countup(0, high(src.data)): dest.data[i] = src.data[i] for i in 0 .. high(src.data): dest.data[i] = src.data[i]
proc copyObjectSet*(dest: var TObjectSet, src: TObjectSet) = proc copyObjectSet*(dest: var TObjectSet, src: TObjectSet) =
dest.counter = src.counter dest.counter = src.counter
setLen(dest.data, len(src.data)) setLen(dest.data, len(src.data))
for i in countup(0, high(src.data)): dest.data[i] = src.data[i] for i in 0 .. high(src.data): dest.data[i] = src.data[i]
proc discardSons*(father: PNode) = proc discardSons*(father: PNode) =
when defined(nimNoNilSeqs): when defined(nimNoNilSeqs):
@ -1520,7 +1520,7 @@ proc delSon*(father: PNode, idx: int) =
else: else:
if isNil(father.sons): return if isNil(father.sons): return
var length = sonsLen(father) var length = sonsLen(father)
for i in countup(idx, length - 2): father.sons[i] = father.sons[i + 1] for i in idx .. length - 2: father.sons[i] = father.sons[i + 1]
setLen(father.sons, length - 1) setLen(father.sons, length - 1)
proc copyNode*(src: PNode): PNode = proc copyNode*(src: PNode): PNode =

View file

@ -630,7 +630,7 @@ proc objectSetRawInsert(data: var TObjectSeq, obj: RootRef) =
proc objectSetEnlarge(t: var TObjectSet) = proc objectSetEnlarge(t: var TObjectSet) =
var n: TObjectSeq var n: TObjectSeq
newSeq(n, len(t.data) * GrowthFactor) newSeq(n, len(t.data) * GrowthFactor)
for i in countup(0, high(t.data)): for i in 0 .. high(t.data):
if t.data[i] != nil: objectSetRawInsert(n, t.data[i]) if t.data[i] != nil: objectSetRawInsert(n, t.data[i])
swap(t.data, n) swap(t.data, n)
@ -709,7 +709,7 @@ proc symTabReplace*(t: var TStrTable, prevSym: PSym, newSym: PSym) =
proc strTableEnlarge(t: var TStrTable) = proc strTableEnlarge(t: var TStrTable) =
var n: seq[PSym] var n: seq[PSym]
newSeq(n, len(t.data) * GrowthFactor) newSeq(n, len(t.data) * GrowthFactor)
for i in countup(0, high(t.data)): for i in 0 .. high(t.data):
if t.data[i] != nil: strTableRawInsert(n, t.data[i]) if t.data[i] != nil: strTableRawInsert(n, t.data[i])
swap(t.data, n) swap(t.data, n)
@ -845,7 +845,7 @@ iterator items*(tab: TStrTable): PSym =
s = nextIter(it, tab) s = nextIter(it, tab)
proc hasEmptySlot(data: TIdPairSeq): bool = proc hasEmptySlot(data: TIdPairSeq): bool =
for h in countup(0, high(data)): for h in 0 .. high(data):
if data[h].key == nil: if data[h].key == nil:
return true return true
result = false result = false
@ -900,7 +900,7 @@ proc idTablePut(t: var TIdTable, key: PIdObj, val: RootRef) =
else: else:
if mustRehash(len(t.data), t.counter): if mustRehash(len(t.data), t.counter):
newSeq(n, len(t.data) * GrowthFactor) newSeq(n, len(t.data) * GrowthFactor)
for i in countup(0, high(t.data)): for i in 0 .. high(t.data):
if t.data[i].key != nil: if t.data[i].key != nil:
idTableRawInsert(n, t.data[i].key, t.data[i].val) idTableRawInsert(n, t.data[i].key, t.data[i].val)
assert(hasEmptySlot(n)) assert(hasEmptySlot(n))
@ -946,7 +946,7 @@ proc idNodeTablePut(t: var TIdNodeTable, key: PIdObj, val: PNode) =
if mustRehash(len(t.data), t.counter): if mustRehash(len(t.data), t.counter):
var n: TIdNodePairSeq var n: TIdNodePairSeq
newSeq(n, len(t.data) * GrowthFactor) newSeq(n, len(t.data) * GrowthFactor)
for i in countup(0, high(t.data)): for i in 0 .. high(t.data):
if t.data[i].key != nil: if t.data[i].key != nil:
idNodeTableRawInsert(n, t.data[i].key, t.data[i].val) idNodeTableRawInsert(n, t.data[i].key, t.data[i].val)
swap(t.data, n) swap(t.data, n)
@ -994,8 +994,8 @@ proc iiTablePut(t: var TIITable, key, val: int) =
if mustRehash(len(t.data), t.counter): if mustRehash(len(t.data), t.counter):
var n: TIIPairSeq var n: TIIPairSeq
newSeq(n, len(t.data) * GrowthFactor) newSeq(n, len(t.data) * GrowthFactor)
for i in countup(0, high(n)): n[i].key = InvalidKey for i in 0 .. high(n): n[i].key = InvalidKey
for i in countup(0, high(t.data)): for i in 0 .. high(t.data):
if t.data[i].key != InvalidKey: if t.data[i].key != InvalidKey:
iiTableRawInsert(n, t.data[i].key, t.data[i].val) iiTableRawInsert(n, t.data[i].key, t.data[i].val)
swap(t.data, n) swap(t.data, n)

View file

@ -48,25 +48,25 @@ proc bitSetInit(b: var TBitSet, length: int) =
newSeq(b, length) newSeq(b, length)
proc bitSetUnion(x: var TBitSet, y: TBitSet) = proc bitSetUnion(x: var TBitSet, y: TBitSet) =
for i in countup(0, high(x)): x[i] = x[i] or y[i] for i in 0 .. high(x): x[i] = x[i] or y[i]
proc bitSetDiff(x: var TBitSet, y: TBitSet) = proc bitSetDiff(x: var TBitSet, y: TBitSet) =
for i in countup(0, high(x)): x[i] = x[i] and not y[i] for i in 0 .. high(x): x[i] = x[i] and not y[i]
proc bitSetSymDiff(x: var TBitSet, y: TBitSet) = proc bitSetSymDiff(x: var TBitSet, y: TBitSet) =
for i in countup(0, high(x)): x[i] = x[i] xor y[i] for i in 0 .. high(x): x[i] = x[i] xor y[i]
proc bitSetIntersect(x: var TBitSet, y: TBitSet) = proc bitSetIntersect(x: var TBitSet, y: TBitSet) =
for i in countup(0, high(x)): x[i] = x[i] and y[i] for i in 0 .. high(x): x[i] = x[i] and y[i]
proc bitSetEquals(x, y: TBitSet): bool = proc bitSetEquals(x, y: TBitSet): bool =
for i in countup(0, high(x)): for i in 0 .. high(x):
if x[i] != y[i]: if x[i] != y[i]:
return false return false
result = true result = true
proc bitSetContains(x, y: TBitSet): bool = proc bitSetContains(x, y: TBitSet): bool =
for i in countup(0, high(x)): for i in 0 .. high(x):
if (x[i] and not y[i]) != int8(0): if (x[i] and not y[i]) != int8(0):
return false return false
result = true result = true

View file

@ -128,7 +128,7 @@ proc hashType(c: var MD5Context, t: PType) =
of tyUserTypeClassInst: of tyUserTypeClassInst:
let body = t.base let body = t.base
c.hashSym body.sym c.hashSym body.sym
for i in countup(1, sonsLen(t) - 2): for i in 1 .. sonsLen(t) - 2:
c.hashType t.sons[i] c.hashType t.sons[i]
of tyFromExpr: of tyFromExpr:
c.hashTree(t.n) c.hashTree(t.n)

View file

@ -1134,7 +1134,7 @@ proc genStrConcat(p: BProc, e: PNode, d: var TLoc) =
var L = 0 var L = 0
var appends: Rope = nil var appends: Rope = nil
var lens: Rope = nil var lens: Rope = nil
for i in countup(0, sonsLen(e) - 2): for i in 0 .. sonsLen(e) - 2:
# compute the length expression: # compute the length expression:
initLocExpr(p, e.sons[i + 1], a) initLocExpr(p, e.sons[i + 1], a)
if skipTypes(e.sons[i + 1].typ, abstractVarRange).kind == tyChar: if skipTypes(e.sons[i + 1].typ, abstractVarRange).kind == tyChar:
@ -1173,7 +1173,7 @@ proc genStrAppend(p: BProc, e: PNode, d: var TLoc) =
assert(d.k == locNone) assert(d.k == locNone)
var L = 0 var L = 0
initLocExpr(p, e.sons[1], dest) initLocExpr(p, e.sons[1], dest)
for i in countup(0, sonsLen(e) - 3): for i in 0 .. sonsLen(e) - 3:
# compute the length expression: # compute the length expression:
initLocExpr(p, e.sons[i + 2], a) initLocExpr(p, e.sons[i + 2], a)
if skipTypes(e.sons[i + 2].typ, abstractVarRange).kind == tyChar: if skipTypes(e.sons[i + 2].typ, abstractVarRange).kind == tyChar:
@ -2477,7 +2477,7 @@ proc downConv(p: BProc, n: PNode, d: var TLoc) =
add(r, "->Sup") add(r, "->Sup")
else: else:
add(r, ".Sup") add(r, ".Sup")
for i in countup(2, abs(inheritanceDiff(dest, src))): add(r, ".Sup") for i in 2 .. abs(inheritanceDiff(dest, src)): add(r, ".Sup")
if isRef: if isRef:
# it can happen that we end up generating '&&x->Sup' here, so we pack # it can happen that we end up generating '&&x->Sup' here, so we pack
# the '&x->Sup' into a temporary and then those address is taken # the '&x->Sup' into a temporary and then those address is taken
@ -2806,7 +2806,7 @@ proc genConstObjConstr(p: BProc; n: PNode): Rope =
proc genConstSimpleList(p: BProc, n: PNode): Rope = proc genConstSimpleList(p: BProc, n: PNode): Rope =
var length = sonsLen(n) var length = sonsLen(n)
result = rope("{") result = rope("{")
for i in countup(0, length - 2): for i in 0 .. length - 2:
addf(result, "$1,$n", [genNamedConstExpr(p, n.sons[i])]) addf(result, "$1,$n", [genNamedConstExpr(p, n.sons[i])])
if length > 0: if length > 0:
add(result, genNamedConstExpr(p, n.sons[length - 1])) add(result, genNamedConstExpr(p, n.sons[length - 1]))

View file

@ -65,7 +65,7 @@ proc genVarTuple(p: BProc, n: PNode) =
var L = sonsLen(n) var L = sonsLen(n)
# if we have a something that's been captured, use the lowering instead: # if we have a something that's been captured, use the lowering instead:
for i in countup(0, L-3): for i in 0 .. L-3:
if n[i].kind != nkSym: if n[i].kind != nkSym:
genStmts(p, lowerTupleUnpacking(p.module.g.graph, n, p.prc)) genStmts(p, lowerTupleUnpacking(p.module.g.graph, n, p.prc))
return return
@ -99,7 +99,7 @@ proc genVarTuple(p: BProc, n: PNode) =
genLineDir(p, n) genLineDir(p, n)
initLocExpr(p, n.sons[L-1], tup) initLocExpr(p, n.sons[L-1], tup)
var t = tup.t.skipTypes(abstractInst) var t = tup.t.skipTypes(abstractInst)
for i in countup(0, L-3): for i in 0 .. L-3:
let vn = n.sons[i] let vn = n.sons[i]
let v = vn.sym let v = vn.sym
if sfCompileTime in v.flags: continue if sfCompileTime in v.flags: continue
@ -202,7 +202,7 @@ proc blockLeaveActions(p: BProc, howManyTrys, howManyExcepts: int) =
var stack = newSeq[tuple[n: PNode, inExcept: bool]](0) var stack = newSeq[tuple[n: PNode, inExcept: bool]](0)
for i in countup(1, howManyTrys): for i in 1 .. howManyTrys:
let tryStmt = p.nestedTryStmts.pop let tryStmt = p.nestedTryStmts.pop
if not p.module.compileToCpp or optNoCppExceptions in p.config.globalOptions: if not p.module.compileToCpp or optNoCppExceptions in p.config.globalOptions:
# Pop safe points generated by try # Pop safe points generated by try
@ -709,7 +709,7 @@ template genCaseGenericBranch(p: BProc, b: PNode, e: TLoc,
var var
x, y: TLoc x, y: TLoc
var length = sonsLen(b) var length = sonsLen(b)
for i in countup(0, length - 2): for i in 0 .. length - 2:
if b.sons[i].kind == nkRange: if b.sons[i].kind == nkRange:
initLocExpr(p, b.sons[i].sons[0], x) initLocExpr(p, b.sons[i].sons[0], x)
initLocExpr(p, b.sons[i].sons[1], y) initLocExpr(p, b.sons[i].sons[1], y)
@ -768,7 +768,7 @@ proc genCaseStringBranch(p: BProc, b: PNode, e: TLoc, labl: TLabel,
branches: var openArray[Rope]) = branches: var openArray[Rope]) =
var x: TLoc var x: TLoc
var length = sonsLen(b) var length = sonsLen(b)
for i in countup(0, length - 2): for i in 0 .. length - 2:
assert(b.sons[i].kind != nkRange) assert(b.sons[i].kind != nkRange)
initLocExpr(p, b.sons[i], x) initLocExpr(p, b.sons[i], x)
assert(b.sons[i].kind in {nkStrLit..nkTripleStrLit}) assert(b.sons[i].kind in {nkStrLit..nkTripleStrLit})
@ -799,7 +799,7 @@ proc genStringCase(p: BProc, t: PNode, d: var TLoc) =
discard discard
linefmt(p, cpsStmts, "switch (#hashString($1) & $2) {$n", linefmt(p, cpsStmts, "switch (#hashString($1) & $2) {$n",
[rdLoc(a), bitMask]) [rdLoc(a), bitMask])
for j in countup(0, high(branches)): for j in 0 .. high(branches):
if branches[j] != nil: if branches[j] != nil:
lineF(p, cpsStmts, "case $1: $n$2break;$n", lineF(p, cpsStmts, "case $1: $n$2break;$n",
[intLiteral(j), branches[j]]) [intLiteral(j), branches[j]])
@ -813,7 +813,7 @@ proc genStringCase(p: BProc, t: PNode, d: var TLoc) =
genCaseGeneric(p, t, d, "", "if (#eqStrings($1, $2)) goto $3;$n") genCaseGeneric(p, t, d, "", "if (#eqStrings($1, $2)) goto $3;$n")
proc branchHasTooBigRange(b: PNode): bool = proc branchHasTooBigRange(b: PNode): bool =
for i in countup(0, sonsLen(b)-2): for i in 0 .. sonsLen(b)-2:
# last son is block # last son is block
if (b.sons[i].kind == nkRange) and if (b.sons[i].kind == nkRange) and
b.sons[i].sons[1].intVal - b.sons[i].sons[0].intVal > RangeExpandLimit: b.sons[i].sons[1].intVal - b.sons[i].sons[0].intVal > RangeExpandLimit:
@ -1054,7 +1054,7 @@ proc genTry(p: BProc, t: PNode, d: var TLoc) =
endBlock(p) endBlock(p)
else: else:
var orExpr: Rope = nil var orExpr: Rope = nil
for j in countup(0, blen - 2): for j in 0 .. blen - 2:
assert(t.sons[i].sons[j].kind == nkType) assert(t.sons[i].sons[j].kind == nkType)
if orExpr != nil: add(orExpr, "||") if orExpr != nil: add(orExpr, "||")
let checkFor = if optNimV2 in p.config.globalOptions: let checkFor = if optNimV2 in p.config.globalOptions:

View file

@ -1080,7 +1080,7 @@ proc genObjectFields(m: BModule, typ, origType: PType, n: PNode, expr: Rope;
of nkOfBranch: of nkOfBranch:
if sonsLen(b) < 2: if sonsLen(b) < 2:
internalError(m.config, b.info, "genObjectFields; nkOfBranch broken") internalError(m.config, b.info, "genObjectFields; nkOfBranch broken")
for j in countup(0, sonsLen(b) - 2): for j in 0 .. sonsLen(b) - 2:
if b.sons[j].kind == nkRange: if b.sons[j].kind == nkRange:
var x = int(getOrdValue(b.sons[j].sons[0])) var x = int(getOrdValue(b.sons[j].sons[0]))
var y = int(getOrdValue(b.sons[j].sons[1])) var y = int(getOrdValue(b.sons[j].sons[1]))

View file

@ -664,7 +664,7 @@ proc loadDynamicLib(m: BModule, lib: PLib) =
libCandidates(lib.path.strVal, s) libCandidates(lib.path.strVal, s)
rawMessage(m.config, hintDependency, lib.path.strVal) rawMessage(m.config, hintDependency, lib.path.strVal)
var loadlib: Rope = nil var loadlib: Rope = nil
for i in countup(0, high(s)): for i in 0 .. high(s):
inc(m.labels) inc(m.labels)
if i > 0: add(loadlib, "||") if i > 0: add(loadlib, "||")
let n = newStrNode(nkStrLit, s[i]) let n = newStrNode(nkStrLit, s[i])
@ -1710,7 +1710,7 @@ proc genModule(m: BModule, cfile: Cfile): Rope =
add(result, "#define nimfr_(x, y)\n#define nimln_(x, y)\n") add(result, "#define nimfr_(x, y)\n#define nimln_(x, y)\n")
add(result, genSectionEnd(cfsFrameDefines, m.config)) add(result, genSectionEnd(cfsFrameDefines, m.config))
for i in countup(cfsForwardTypes, cfsProcs): for i in cfsForwardTypes .. cfsProcs:
if m.s[i].len > 0: if m.s[i].len > 0:
moduleIsEmpty = false moduleIsEmpty = false
add(result, genSectionStart(i, m.config)) add(result, genSectionStart(i, m.config))
@ -1811,7 +1811,7 @@ proc writeHeader(m: BModule) =
generateHeaders(m) generateHeaders(m)
generateThreadLocalStorage(m) generateThreadLocalStorage(m)
for i in countup(cfsHeaders, cfsProcs): for i in cfsHeaders .. cfsProcs:
add(result, genSectionStart(i, m.config)) add(result, genSectionStart(i, m.config))
add(result, m.s[i]) add(result, m.s[i])
add(result, genSectionEnd(i, m.config)) add(result, genSectionEnd(i, m.config))

View file

@ -192,7 +192,7 @@ proc relevantCol(methods: seq[PSym], col: int): bool =
# returns true iff the position is relevant # returns true iff the position is relevant
var t = methods[0].typ.sons[col].skipTypes(skipPtrs) var t = methods[0].typ.sons[col].skipTypes(skipPtrs)
if t.kind == tyObject: if t.kind == tyObject:
for i in countup(1, high(methods)): for i in 1 .. high(methods):
let t2 = skipTypes(methods[i].typ.sons[col], skipPtrs) let t2 = skipTypes(methods[i].typ.sons[col], skipPtrs)
if not sameType(t2, t): if not sameType(t2, t):
return true return true
@ -240,7 +240,7 @@ proc genDispatcher(g: ModuleGraph; methods: seq[PSym], relevantCols: IntSet): PS
if param.typ.skipTypes(abstractInst).kind in {tyRef, tyPtr}: if param.typ.skipTypes(abstractInst).kind in {tyRef, tyPtr}:
addSon(nilchecks, newTree(nkCall, addSon(nilchecks, newTree(nkCall,
newSymNode(getCompilerProc(g, "chckNilDisp")), newSymNode(param))) newSymNode(getCompilerProc(g, "chckNilDisp")), newSymNode(param)))
for meth in countup(0, high(methods)): for meth in 0 .. high(methods):
var curr = methods[meth] # generate condition: var curr = methods[meth] # generate condition:
var cond: PNode = nil var cond: PNode = nil
for col in 1 ..< paramLen: for col in 1 ..< paramLen:

View file

@ -177,7 +177,7 @@ template dispA(conf: ConfigRef; dest: var Rope, xml, tex: string, args: openArra
else: addf(dest, tex, args) else: addf(dest, tex, args)
proc getVarIdx(varnames: openArray[string], id: string): int = proc getVarIdx(varnames: openArray[string], id: string): int =
for i in countup(0, high(varnames)): for i in 0 .. high(varnames):
if cmpIgnoreStyle(varnames[i], id) == 0: if cmpIgnoreStyle(varnames[i], id) == 0:
return i return i
result = -1 result = -1
@ -971,12 +971,12 @@ proc genOutFile(d: PDoc): Rope =
var tmp = "" var tmp = ""
renderTocEntries(d[], j, 1, tmp) renderTocEntries(d[], j, 1, tmp)
var toc = tmp.rope var toc = tmp.rope
for i in countup(low(TSymKind), high(TSymKind)): for i in low(TSymKind) .. high(TSymKind):
genSection(d, i) genSection(d, i)
add(toc, d.toc[i]) add(toc, d.toc[i])
if toc != nil: if toc != nil:
toc = ropeFormatNamedVars(d.conf, getConfigVar(d.conf, "doc.toc"), ["content"], [toc]) toc = ropeFormatNamedVars(d.conf, getConfigVar(d.conf, "doc.toc"), ["content"], [toc])
for i in countup(low(TSymKind), high(TSymKind)): add(code, d.section[i]) for i in low(TSymKind) .. high(TSymKind): add(code, d.section[i])
# Extract the title. Non API modules generate an entry in the index table. # Extract the title. Non API modules generate an entry in the index table.
if d.meta[metaTitle].len != 0: if d.meta[metaTitle].len != 0:

View file

@ -370,7 +370,7 @@ proc libNameTmpl(conf: ConfigRef): string {.inline.} =
proc nameToCC*(name: string): TSystemCC = proc nameToCC*(name: string): TSystemCC =
## Returns the kind of compiler referred to by `name`, or ccNone ## Returns the kind of compiler referred to by `name`, or ccNone
## if the name doesn't refer to any known compiler. ## if the name doesn't refer to any known compiler.
for i in countup(succ(ccNone), high(TSystemCC)): for i in succ(ccNone) .. high(TSystemCC):
if cmpIgnoreStyle(name, CC[i].name) == 0: if cmpIgnoreStyle(name, CC[i].name) == 0:
return i return i
result = ccNone result = ccNone
@ -412,7 +412,7 @@ proc setCC*(conf: ConfigRef; ccname: string; info: TLineInfo) =
conf.compileOptions = getConfigVar(conf, conf.cCompiler, ".options.always") conf.compileOptions = getConfigVar(conf, conf.cCompiler, ".options.always")
conf.linkOptions = "" conf.linkOptions = ""
conf.ccompilerpath = getConfigVar(conf, conf.cCompiler, ".path") conf.ccompilerpath = getConfigVar(conf, conf.cCompiler, ".path")
for i in countup(low(CC), high(CC)): undefSymbol(conf.symbols, CC[i].name) for i in low(CC) .. high(CC): undefSymbol(conf.symbols, CC[i].name)
defineSymbol(conf.symbols, CC[conf.cCompiler].name) defineSymbol(conf.symbols, CC[conf.cCompiler].name)
proc addOpt(dest: var string, src: string) = proc addOpt(dest: var string, src: string) =
@ -434,7 +434,7 @@ proc addCompileOptionCmd*(conf: ConfigRef; option: string) =
proc initVars*(conf: ConfigRef) = proc initVars*(conf: ConfigRef) =
# we need to define the symbol here, because ``CC`` may have never been set! # we need to define the symbol here, because ``CC`` may have never been set!
for i in countup(low(CC), high(CC)): undefSymbol(conf.symbols, CC[i].name) for i in low(CC) .. high(CC): undefSymbol(conf.symbols, CC[i].name)
defineSymbol(conf.symbols, CC[conf.cCompiler].name) defineSymbol(conf.symbols, CC[conf.cCompiler].name)
addCompileOption(conf, getConfigVar(conf, conf.cCompiler, ".options.always")) addCompileOption(conf, getConfigVar(conf, conf.cCompiler, ".options.always"))
#addLinkOption(getConfigVar(cCompiler, ".options.linker")) #addLinkOption(getConfigVar(cCompiler, ".options.linker"))
@ -787,7 +787,7 @@ proc execCmdsInParallel(conf: ConfigRef; cmds: seq[string]; prettyCb: proc (idx:
if conf.numberOfProcessors == 0: conf.numberOfProcessors = countProcessors() if conf.numberOfProcessors == 0: conf.numberOfProcessors = countProcessors()
var res = 0 var res = 0
if conf.numberOfProcessors <= 1: if conf.numberOfProcessors <= 1:
for i in countup(0, high(cmds)): for i in 0 .. high(cmds):
tryExceptOSErrorMessage(conf, "invocation of external compiler program failed."): tryExceptOSErrorMessage(conf, "invocation of external compiler program failed."):
res = execWithEcho(conf, cmds[i]) res = execWithEcho(conf, cmds[i])
if res != 0: if res != 0:

View file

@ -110,7 +110,7 @@ proc newIdentCache*(): IdentCache =
result.idDelegator = result.getIdent":delegator" result.idDelegator = result.getIdent":delegator"
result.emptyIdent = result.getIdent("") result.emptyIdent = result.getIdent("")
# initialize the keywords: # initialize the keywords:
for s in countup(succ(low(specialWords)), high(specialWords)): for s in succ(low(specialWords)) .. high(specialWords):
result.getIdent(specialWords[s], hashIgnoreStyle(specialWords[s])).id = ord(s) result.getIdent(specialWords[s], hashIgnoreStyle(specialWords[s])).id = ord(s)
proc whichKeyword*(id: PIdent): TSpecialWord = proc whichKeyword*(id: PIdent): TSpecialWord =

View file

@ -780,7 +780,7 @@ proc genTry(p: PProc, n: PNode, r: var TCompRes) =
var excAlias: PNode = nil var excAlias: PNode = nil
useMagic(p, "isObj") useMagic(p, "isObj")
for j in countup(0, blen - 2): for j in 0 .. blen - 2:
var throwObj: PNode var throwObj: PNode
let it = n.sons[i].sons[j] let it = n.sons[i].sons[j]
@ -862,7 +862,7 @@ proc genCaseJS(p: PProc, n: PNode, r: var TCompRes) =
let it = n.sons[i] let it = n.sons[i]
case it.kind case it.kind
of nkOfBranch: of nkOfBranch:
for j in countup(0, sonsLen(it) - 2): for j in 0 .. sonsLen(it) - 2:
let e = it.sons[j] let e = it.sons[j]
if e.kind == nkRange: if e.kind == nkRange:
var v = copyNode(e.sons[0]) var v = copyNode(e.sons[0])
@ -1811,7 +1811,7 @@ proc genConStrStr(p: PProc, n: PNode, r: var TCompRes) =
else: else:
r.res.add("($1 || []).concat(" % [a.res]) r.res.add("($1 || []).concat(" % [a.res])
for i in countup(2, sonsLen(n) - 2): for i in 2 .. sonsLen(n) - 2:
gen(p, n.sons[i], a) gen(p, n.sons[i], a)
if skipTypes(n.sons[i].typ, abstractVarRange).kind == tyChar: if skipTypes(n.sons[i].typ, abstractVarRange).kind == tyChar:
r.res.add("[$1]," % [a.res]) r.res.add("[$1]," % [a.res])

View file

@ -48,7 +48,7 @@ proc genObjectFields(p: PProc, typ: PType, n: PNode): Rope =
of nkOfBranch: of nkOfBranch:
if sonsLen(b) < 2: if sonsLen(b) < 2:
internalError(p.config, b.info, "genObjectFields; nkOfBranch broken") internalError(p.config, b.info, "genObjectFields; nkOfBranch broken")
for j in countup(0, sonsLen(b) - 2): for j in 0 .. sonsLen(b) - 2:
if u != nil: add(u, ", ") if u != nil: add(u, ", ")
if b.sons[j].kind == nkRange: if b.sons[j].kind == nkRange:
addf(u, "[$1, $2]", [rope(getOrdValue(b.sons[j].sons[0])), addf(u, "[$1, $2]", [rope(getOrdValue(b.sons[j].sons[0])),

View file

@ -133,7 +133,7 @@ proc equalSets*(conf: ConfigRef; a, b: PNode): bool =
proc complement*(conf: ConfigRef; a: PNode): PNode = proc complement*(conf: ConfigRef; a: PNode): PNode =
var x: TBitSet var x: TBitSet
toBitSet(conf, a, x) toBitSet(conf, a, x)
for i in countup(0, high(x)): x[i] = not x[i] for i in 0 .. high(x): x[i] = not x[i]
result = toTreeSet(conf, x, a.typ, a.info) result = toTreeSet(conf, x, a.typ, a.info)
proc deduplicate*(conf: ConfigRef; a: PNode): PNode = proc deduplicate*(conf: ConfigRef; a: PNode): PNode =

View file

@ -182,7 +182,7 @@ proc matches(c: PPatternContext, p, n: PNode): bool =
if isPatternParam(c, v) and v.sym.typ.kind == tyVarargs: if isPatternParam(c, v) and v.sym.typ.kind == tyVarargs:
var arglist: PNode var arglist: PNode
if plen <= sonsLen(n): if plen <= sonsLen(n):
for i in countup(0, plen - 2): for i in 0 .. plen - 2:
if not matches(c, p.sons[i], n.sons[i]): return if not matches(c, p.sons[i], n.sons[i]): return
if plen == sonsLen(n) and lastSon(n).kind == nkHiddenStdConv and if plen == sonsLen(n) and lastSon(n).kind == nkHiddenStdConv and
lastSon(n).sons[1].kind == nkBracket: lastSon(n).sons[1].kind == nkBracket:
@ -194,11 +194,11 @@ proc matches(c: PPatternContext, p, n: PNode): bool =
arglist = newNodeI(nkArgList, n.info, sonsLen(n) - plen + 1) arglist = newNodeI(nkArgList, n.info, sonsLen(n) - plen + 1)
# f(1, 2, 3) # f(1, 2, 3)
# p(X) # p(X)
for i in countup(0, sonsLen(n) - plen): for i in 0 .. sonsLen(n) - plen:
arglist.sons[i] = n.sons[i + plen - 1] arglist.sons[i] = n.sons[i + plen - 1]
return bindOrCheck(c, v.sym, arglist) return bindOrCheck(c, v.sym, arglist)
elif plen-1 == sonsLen(n): elif plen-1 == sonsLen(n):
for i in countup(0, plen - 2): for i in 0 .. plen - 2:
if not matches(c, p.sons[i], n.sons[i]): return if not matches(c, p.sons[i], n.sons[i]): return
arglist = newNodeI(nkArgList, n.info) arglist = newNodeI(nkArgList, n.info)
return bindOrCheck(c, v.sym, arglist) return bindOrCheck(c, v.sym, arglist)

View file

@ -237,13 +237,13 @@ proc setTarget*(t: var Target; o: TSystemOS, c: TSystemCPU) =
t.tnl = OS[o].newLine t.tnl = OS[o].newLine
proc nameToOS*(name: string): TSystemOS = proc nameToOS*(name: string): TSystemOS =
for i in countup(succ(osNone), high(TSystemOS)): for i in succ(osNone) .. high(TSystemOS):
if cmpIgnoreStyle(name, OS[i].name) == 0: if cmpIgnoreStyle(name, OS[i].name) == 0:
return i return i
result = osNone result = osNone
proc nameToCPU*(name: string): TSystemCPU = proc nameToCPU*(name: string): TSystemCPU =
for i in countup(succ(cpuNone), high(TSystemCPU)): for i in succ(cpuNone) .. high(TSystemCPU):
if cmpIgnoreStyle(name, CPU[i].name) == 0: if cmpIgnoreStyle(name, CPU[i].name) == 0:
return i return i
result = cpuNone result = cpuNone

View file

@ -209,7 +209,7 @@ proc processMagic(c: PContext, n: PNode, s: PSym) =
var v: string var v: string
if n.sons[1].kind == nkIdent: v = n.sons[1].ident.s if n.sons[1].kind == nkIdent: v = n.sons[1].ident.s
else: v = expectStrLit(c, n) else: v = expectStrLit(c, n)
for m in countup(low(TMagic), high(TMagic)): for m in low(TMagic) .. high(TMagic):
if substr($m, 1) == v: if substr($m, 1) == v:
s.magic = m s.magic = m
break break

View file

@ -302,7 +302,7 @@ proc gcom(g: var TSrcGen, n: PNode) =
putComment(g, n.comment) #assert(g.comStack[high(g.comStack)] = n); putComment(g, n.comment) #assert(g.comStack[high(g.comStack)] = n);
proc gcoms(g: var TSrcGen) = proc gcoms(g: var TSrcGen) =
for i in countup(0, high(g.comStack)): gcom(g, g.comStack[i]) for i in 0 .. high(g.comStack): gcom(g, g.comStack[i])
popAllComs(g) popAllComs(g)
proc lsub(g: TSrcGen; n: PNode): int proc lsub(g: TSrcGen; n: PNode): int
@ -393,7 +393,7 @@ proc atom(g: TSrcGen; n: PNode): string =
proc lcomma(g: TSrcGen; n: PNode, start: int = 0, theEnd: int = - 1): int = proc lcomma(g: TSrcGen; n: PNode, start: int = 0, theEnd: int = - 1): int =
assert(theEnd < 0) assert(theEnd < 0)
result = 0 result = 0
for i in countup(start, sonsLen(n) + theEnd): for i in start .. sonsLen(n) + theEnd:
let param = n.sons[i] let param = n.sons[i]
if nfDefaultParam notin param.flags: if nfDefaultParam notin param.flags:
inc(result, lsub(g, param)) inc(result, lsub(g, param))
@ -404,7 +404,7 @@ proc lcomma(g: TSrcGen; n: PNode, start: int = 0, theEnd: int = - 1): int =
proc lsons(g: TSrcGen; n: PNode, start: int = 0, theEnd: int = - 1): int = proc lsons(g: TSrcGen; n: PNode, start: int = 0, theEnd: int = - 1): int =
assert(theEnd < 0) assert(theEnd < 0)
result = 0 result = 0
for i in countup(start, sonsLen(n) + theEnd): inc(result, lsub(g, n.sons[i])) for i in start .. sonsLen(n) + theEnd: inc(result, lsub(g, n.sons[i]))
proc lsub(g: TSrcGen; n: PNode): int = proc lsub(g: TSrcGen; n: PNode): int =
# computes the length of a tree # computes the length of a tree
@ -563,7 +563,7 @@ proc putWithSpace(g: var TSrcGen, kind: TTokType, s: string) =
proc gcommaAux(g: var TSrcGen, n: PNode, ind: int, start: int = 0, proc gcommaAux(g: var TSrcGen, n: PNode, ind: int, start: int = 0,
theEnd: int = - 1, separator = tkComma) = theEnd: int = - 1, separator = tkComma) =
for i in countup(start, sonsLen(n) + theEnd): for i in start .. sonsLen(n) + theEnd:
var c = i < sonsLen(n) + theEnd var c = i < sonsLen(n) + theEnd
var sublen = lsub(g, n.sons[i]) + ord(c) var sublen = lsub(g, n.sons[i]) + ord(c)
if not fits(g, sublen) and (ind + sublen < MaxLineLen): optNL(g, ind) if not fits(g, sublen) and (ind + sublen < MaxLineLen): optNL(g, ind)
@ -598,7 +598,7 @@ proc gsemicolon(g: var TSrcGen, n: PNode, start: int = 0, theEnd: int = - 1) =
proc gsons(g: var TSrcGen, n: PNode, c: TContext, start: int = 0, proc gsons(g: var TSrcGen, n: PNode, c: TContext, start: int = 0,
theEnd: int = - 1) = theEnd: int = - 1) =
for i in countup(start, sonsLen(n) + theEnd): gsub(g, n.sons[i], c) for i in start .. sonsLen(n) + theEnd: gsub(g, n.sons[i], c)
proc gsection(g: var TSrcGen, n: PNode, c: TContext, kind: TTokType, proc gsection(g: var TSrcGen, n: PNode, c: TContext, kind: TTokType,
k: string) = k: string) =
@ -616,7 +616,7 @@ proc longMode(g: TSrcGen; n: PNode, start: int = 0, theEnd: int = - 1): bool =
result = n.comment.len > 0 result = n.comment.len > 0
if not result: if not result:
# check further # check further
for i in countup(start, sonsLen(n) + theEnd): for i in start .. sonsLen(n) + theEnd:
if (lsub(g, n.sons[i]) > MaxLineLen): if (lsub(g, n.sons[i]) > MaxLineLen):
result = true result = true
break break

View file

@ -75,7 +75,7 @@ proc computeDeps(cache: IdentCache; n: PNode, declares, uses: var IntSet; topLev
of nkLetSection, nkVarSection, nkUsingStmt: of nkLetSection, nkVarSection, nkUsingStmt:
for a in n: for a in n:
if a.kind in {nkIdentDefs, nkVarTuple}: if a.kind in {nkIdentDefs, nkVarTuple}:
for j in countup(0, a.len-3): decl(a[j]) for j in 0 .. a.len-3: decl(a[j])
for j in a.len-2..a.len-1: deps(a[j]) for j in a.len-2..a.len-1: deps(a[j])
of nkConstSection, nkTypeSection: of nkConstSection, nkTypeSection:
for a in n: for a in n:

View file

@ -157,7 +157,7 @@ proc `&`*(a: string, b: Rope): Rope =
proc `&`*(a: openArray[Rope]): Rope = proc `&`*(a: openArray[Rope]): Rope =
## the concatenation operator for an openarray of ropes. ## the concatenation operator for an openarray of ropes.
for i in countup(0, high(a)): result = result & a[i] for i in 0 .. high(a): result = result & a[i]
proc add*(a: var Rope, b: Rope) = proc add*(a: var Rope, b: Rope) =
## adds `b` to the rope `a`. ## adds `b` to the rope `a`.
@ -206,7 +206,7 @@ proc `$`*(r: Rope): string =
proc ropeConcat*(a: varargs[Rope]): Rope = proc ropeConcat*(a: varargs[Rope]): Rope =
# not overloaded version of concat to speed-up `rfmt` a little bit # not overloaded version of concat to speed-up `rfmt` a little bit
for i in countup(0, high(a)): result = result & a[i] for i in 0 .. high(a): result = result & a[i]
proc prepend*(a: var Rope, b: Rope) = a = b & a proc prepend*(a: var Rope, b: Rope) = a = b & a
proc prepend*(a: var Rope, b: string) = a = b & a proc prepend*(a: var Rope, b: string) = a = b & a

View file

@ -984,7 +984,7 @@ proc lookupInRecordAndBuildCheck(c: PContext, n, r: PNode, field: PIdent,
check = newNodeI(nkCheckedFieldExpr, n.info) check = newNodeI(nkCheckedFieldExpr, n.info)
addSon(check, c.graph.emptyNode) # make space for access node addSon(check, c.graph.emptyNode) # make space for access node
s = newNodeIT(nkCurly, n.info, setType) s = newNodeIT(nkCurly, n.info, setType)
for j in countup(0, sonsLen(it) - 2): addSon(s, copyTree(it.sons[j])) for j in 0 .. sonsLen(it) - 2: addSon(s, copyTree(it.sons[j]))
var inExpr = newNodeIT(nkCall, n.info, getSysType(c.graph, n.info, tyBool)) var inExpr = newNodeIT(nkCall, n.info, getSysType(c.graph, n.info, tyBool))
addSon(inExpr, newSymNode(c.graph.opContains, n.info)) addSon(inExpr, newSymNode(c.graph.opContains, n.info))
addSon(inExpr, s) addSon(inExpr, s)
@ -1046,7 +1046,7 @@ proc readTypeParameter(c: PContext, typ: PType,
let ty = if typ.kind == tyCompositeTypeClass: typ.sons[1].skipGenericAlias let ty = if typ.kind == tyCompositeTypeClass: typ.sons[1].skipGenericAlias
else: typ.skipGenericAlias else: typ.skipGenericAlias
let tbody = ty.sons[0] let tbody = ty.sons[0]
for s in countup(0, tbody.len-2): for s in 0 .. tbody.len-2:
let tParam = tbody.sons[s] let tParam = tbody.sons[s]
if tParam.sym.name.id == paramName.id: if tParam.sym.name.id == paramName.id:
let rawTyp = ty.sons[s + 1] let rawTyp = ty.sons[s + 1]

View file

@ -343,7 +343,7 @@ proc semGenericStmt(c: PContext, n: PNode,
var a = n.sons[i] var a = n.sons[i]
checkMinSonsLen(a, 1, c.config) checkMinSonsLen(a, 1, c.config)
var L = sonsLen(a) var L = sonsLen(a)
for j in countup(0, L-2): for j in 0 .. L-2:
a.sons[j] = semGenericStmt(c, a.sons[j], flags, ctx) a.sons[j] = semGenericStmt(c, a.sons[j], flags, ctx)
a.sons[L - 1] = semGenericStmtScope(c, a.sons[L-1], flags, ctx) a.sons[L - 1] = semGenericStmtScope(c, a.sons[L-1], flags, ctx)
closeScope(c) closeScope(c)
@ -351,7 +351,7 @@ proc semGenericStmt(c: PContext, n: PNode,
var L = sonsLen(n) var L = sonsLen(n)
openScope(c) openScope(c)
n.sons[L - 2] = semGenericStmt(c, n.sons[L-2], flags, ctx) n.sons[L - 2] = semGenericStmt(c, n.sons[L-2], flags, ctx)
for i in countup(0, L - 3): for i in 0 .. L - 3:
if (n.sons[i].kind == nkVarTuple): if (n.sons[i].kind == nkVarTuple):
for s in n.sons[i]: for s in n.sons[i]:
if (s.kind == nkIdent): if (s.kind == nkIdent):
@ -377,7 +377,7 @@ proc semGenericStmt(c: PContext, n: PNode,
checkMinSonsLen(a, 1, c.config) checkMinSonsLen(a, 1, c.config)
var L = sonsLen(a) var L = sonsLen(a)
openScope(c) openScope(c)
for j in countup(0, L-2): for j in 0 .. L-2:
if a.sons[j].isInfixAs(): if a.sons[j].isInfixAs():
addTempDecl(c, getIdentNode(c, a.sons[j][2]), skLet) addTempDecl(c, getIdentNode(c, a.sons[j][2]), skLet)
a.sons[j].sons[1] = semGenericStmt(c, a.sons[j][1], flags+{withinTypeDesc}, ctx) a.sons[j].sons[1] = semGenericStmt(c, a.sons[j][1], flags+{withinTypeDesc}, ctx)
@ -395,7 +395,7 @@ proc semGenericStmt(c: PContext, n: PNode,
var L = sonsLen(a) var L = sonsLen(a)
a.sons[L-2] = semGenericStmt(c, a.sons[L-2], flags+{withinTypeDesc}, ctx) a.sons[L-2] = semGenericStmt(c, a.sons[L-2], flags+{withinTypeDesc}, ctx)
a.sons[L-1] = semGenericStmt(c, a.sons[L-1], flags, ctx) a.sons[L-1] = semGenericStmt(c, a.sons[L-1], flags, ctx)
for j in countup(0, L-3): for j in 0 .. L-3:
addTempDecl(c, getIdentNode(c, a.sons[j]), skVar) addTempDecl(c, getIdentNode(c, a.sons[j]), skVar)
of nkGenericParams: of nkGenericParams:
for i in 0 ..< sonsLen(n): for i in 0 ..< sonsLen(n):
@ -405,7 +405,7 @@ proc semGenericStmt(c: PContext, n: PNode,
var L = sonsLen(a) var L = sonsLen(a)
a.sons[L-2] = semGenericStmt(c, a.sons[L-2], flags+{withinTypeDesc}, ctx) a.sons[L-2] = semGenericStmt(c, a.sons[L-2], flags+{withinTypeDesc}, ctx)
# do not perform symbol lookup for default expressions # do not perform symbol lookup for default expressions
for j in countup(0, L-3): for j in 0 .. L-3:
addTempDecl(c, getIdentNode(c, a.sons[j]), skType) addTempDecl(c, getIdentNode(c, a.sons[j]), skType)
of nkConstSection: of nkConstSection:
for i in 0 ..< sonsLen(n): for i in 0 ..< sonsLen(n):
@ -459,7 +459,7 @@ proc semGenericStmt(c: PContext, n: PNode,
var L = sonsLen(a) var L = sonsLen(a)
a.sons[L-2] = semGenericStmt(c, a.sons[L-2], flags+{withinTypeDesc}, ctx) a.sons[L-2] = semGenericStmt(c, a.sons[L-2], flags+{withinTypeDesc}, ctx)
a.sons[L-1] = semGenericStmt(c, a.sons[L-1], flags, ctx) a.sons[L-1] = semGenericStmt(c, a.sons[L-1], flags, ctx)
for j in countup(0, L-3): for j in 0 .. L-3:
addTempDecl(c, getIdentNode(c, a.sons[j]), skParam) addTempDecl(c, getIdentNode(c, a.sons[j]), skParam)
of nkProcDef, nkMethodDef, nkConverterDef, nkMacroDef, nkTemplateDef, of nkProcDef, nkMethodDef, nkConverterDef, nkMacroDef, nkTemplateDef,
nkFuncDef, nkIteratorDef, nkLambdaKinds: nkFuncDef, nkIteratorDef, nkLambdaKinds:

View file

@ -386,7 +386,7 @@ proc trackTryStmt(tracked: PEffects, n: PNode) =
if blen == 1: if blen == 1:
catchesAll(tracked) catchesAll(tracked)
else: else:
for j in countup(0, blen - 2): for j in 0 .. blen - 2:
if b.sons[j].isInfixAs(): if b.sons[j].isInfixAs():
assert(b.sons[j][1].kind == nkType) assert(b.sons[j][1].kind == nkType)
catches(tracked, b.sons[j][1].typ) catches(tracked, b.sons[j][1].typ)

View file

@ -207,7 +207,7 @@ proc semTry(c: PContext, n: PNode; flags: TExprFlags): PNode =
var last = sonsLen(n) - 1 var last = sonsLen(n) - 1
var catchAllExcepts = 0 var catchAllExcepts = 0
for i in countup(1, last): for i in 1 .. last:
let a = n.sons[i] let a = n.sons[i]
checkMinSonsLen(a, 1, c.config) checkMinSonsLen(a, 1, c.config)
openScope(c) openScope(c)
@ -365,7 +365,7 @@ proc semUsing(c: PContext; n: PNode): PNode =
var length = sonsLen(a) var length = sonsLen(a)
if a.sons[length-2].kind != nkEmpty: if a.sons[length-2].kind != nkEmpty:
let typ = semTypeNode(c, a.sons[length-2], nil) let typ = semTypeNode(c, a.sons[length-2], nil)
for j in countup(0, length-3): for j in 0 .. length-3:
let v = semIdentDef(c, a.sons[j], skParam) let v = semIdentDef(c, a.sons[j], skParam)
styleCheckDef(c.config, v) styleCheckDef(c.config, v)
onDef(a[j].info, v) onDef(a[j].info, v)
@ -504,7 +504,7 @@ proc semVarOrLet(c: PContext, n: PNode, symkind: TSymKind): PNode =
a.kind == nkIdentDefs and a.len > 3: a.kind == nkIdentDefs and a.len > 3:
message(c.config, a.info, warnEachIdentIsTuple) message(c.config, a.info, warnEachIdentIsTuple)
for j in countup(0, length-3): for j in 0 .. length-3:
if a[j].kind == nkDotExpr: if a[j].kind == nkDotExpr:
fillPartialObject(c, a[j], fillPartialObject(c, a[j],
if a.kind != nkVarTuple: typ else: tup.sons[j]) if a.kind != nkVarTuple: typ else: tup.sons[j])
@ -624,7 +624,7 @@ proc semConst(c: PContext, n: PNode): PNode =
b.sons[length-2] = a.sons[length-2] b.sons[length-2] = a.sons[length-2]
b.sons[length-1] = def b.sons[length-1] = def
for j in countup(0, length-3): for j in 0 .. length-3:
var v = semIdentDef(c, a.sons[j], skConst) var v = semIdentDef(c, a.sons[j], skConst)
if sfGenSym notin v.flags: addInterfaceDecl(c, v) if sfGenSym notin v.flags: addInterfaceDecl(c, v)
elif v.owner == nil: v.owner = getCurrOwner(c) elif v.owner == nil: v.owner = getCurrOwner(c)
@ -699,7 +699,7 @@ proc semForVars(c: PContext, n: PNode; flags: TExprFlags): PNode =
elif length-2 != sonsLen(iter): elif length-2 != sonsLen(iter):
localError(c.config, n.info, errWrongNumberOfVariables) localError(c.config, n.info, errWrongNumberOfVariables)
else: else:
for i in countup(0, length - 3): for i in 0 .. length - 3:
if n.sons[i].kind == nkVarTuple: if n.sons[i].kind == nkVarTuple:
var mutable = false var mutable = false
if iter[i].kind == tyVar: if iter[i].kind == tyVar:

View file

@ -298,7 +298,7 @@ proc semTemplSomeDecl(c: var TemplCtx, n: PNode, symKind: TSymKind; start=0) =
when defined(nimsuggest): when defined(nimsuggest):
dec c.c.inTypeContext dec c.c.inTypeContext
a.sons[L-1] = semTemplBody(c, a.sons[L-1]) 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) addLocalDecl(c, a.sons[j], symKind)
proc semPattern(c: PContext, n: PNode): PNode proc semPattern(c: PContext, n: PNode): PNode
@ -363,7 +363,7 @@ proc semTemplBody(c: var TemplCtx, n: PNode): PNode =
var a = n.sons[i] var a = n.sons[i]
checkMinSonsLen(a, 1, c.c.config) checkMinSonsLen(a, 1, c.c.config)
var L = sonsLen(a) 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[j] = semTemplBody(c, a.sons[j])
a.sons[L-1] = semTemplBodyScope(c, a.sons[L-1]) a.sons[L-1] = semTemplBodyScope(c, a.sons[L-1])
closeScope(c) closeScope(c)
@ -371,7 +371,7 @@ proc semTemplBody(c: var TemplCtx, n: PNode): PNode =
var L = sonsLen(n) var L = sonsLen(n)
openScope(c) openScope(c)
n.sons[L-2] = semTemplBody(c, n.sons[L-2]) n.sons[L-2] = semTemplBody(c, n.sons[L-2])
for i in countup(0, L - 3): for i in 0 .. L - 3:
if n[i].kind == nkVarTuple: if n[i].kind == nkVarTuple:
for j in 0 ..< sonsLen(n[i])-1: for j in 0 ..< sonsLen(n[i])-1:
addLocalDecl(c, n[i][j], skForVar) addLocalDecl(c, n[i][j], skForVar)
@ -403,7 +403,7 @@ proc semTemplBody(c: var TemplCtx, n: PNode): PNode =
checkMinSonsLen(a, 1, c.c.config) checkMinSonsLen(a, 1, c.c.config)
var L = sonsLen(a) var L = sonsLen(a)
openScope(c) openScope(c)
for j in countup(0, L-2): for j in 0 .. L-2:
if a.sons[j].isInfixAs(): if a.sons[j].isInfixAs():
addLocalDecl(c, a.sons[j].sons[2], skLet) addLocalDecl(c, a.sons[j].sons[2], skLet)
a.sons[j].sons[1] = semTemplBody(c, a.sons[j][1]) a.sons[j].sons[1] = semTemplBody(c, a.sons[j][1])

View file

@ -431,7 +431,7 @@ proc semTuple(c: PContext, n: PNode, prev: PType): PType =
typ = errorType(c) typ = errorType(c)
if a.sons[length - 1].kind != nkEmpty: if a.sons[length - 1].kind != nkEmpty:
localError(c.config, a.sons[length - 1].info, errInitHereNotAllowed) localError(c.config, a.sons[length - 1].info, errInitHereNotAllowed)
for j in countup(0, length - 3): for j in 0 .. length - 3:
var field = newSymG(skField, a.sons[j], c) var field = newSymG(skField, a.sons[j], c)
field.typ = typ field.typ = typ
field.position = counter field.position = counter
@ -489,8 +489,8 @@ proc semIdentWithPragma(c: PContext, kind: TSymKind, n: PNode,
proc checkForOverlap(c: PContext, t: PNode, currentEx, branchIndex: int) = proc checkForOverlap(c: PContext, t: PNode, currentEx, branchIndex: int) =
let ex = t[branchIndex][currentEx].skipConv let ex = t[branchIndex][currentEx].skipConv
for i in countup(1, branchIndex): for i in 1 .. branchIndex:
for j in countup(0, sonsLen(t.sons[i]) - 2): for j in 0 .. sonsLen(t.sons[i]) - 2:
if i == branchIndex and j == currentEx: break if i == branchIndex and j == currentEx: break
if overlap(t.sons[i].sons[j].skipConv, ex): if overlap(t.sons[i].sons[j].skipConv, ex):
localError(c.config, ex.info, errDuplicateCaseLabel) localError(c.config, ex.info, errDuplicateCaseLabel)
@ -699,7 +699,7 @@ proc semRecordNodeAux(c: PContext, n: PNode, check: var IntSet, pos: var int,
propagateToOwner(rectype, typ) propagateToOwner(rectype, typ)
var fieldOwner = if c.inGenericContext > 0: c.getCurrOwner var fieldOwner = if c.inGenericContext > 0: c.getCurrOwner
else: rectype.sym else: rectype.sym
for i in countup(0, sonsLen(n)-3): for i in 0 .. sonsLen(n)-3:
var f = semIdentWithPragma(c, skField, n.sons[i], {sfExported}) var f = semIdentWithPragma(c, skField, n.sons[i], {sfExported})
suggestSym(c.config, n.sons[i].info, f, c.graph.usageSym) suggestSym(c.config, n.sons[i].info, f, c.graph.usageSym)
f.typ = typ f.typ = typ
@ -1159,7 +1159,7 @@ proc semProcTypeNode(c: PContext, n, genericParams: PNode,
elif skipTypes(typ, {tyGenericInst, tyAlias, tySink}).kind == tyVoid: elif skipTypes(typ, {tyGenericInst, tyAlias, tySink}).kind == tyVoid:
continue continue
for j in countup(0, length-3): for j in 0 .. length-3:
var arg = newSymG(skParam, a.sons[j], c) var arg = newSymG(skParam, a.sons[j], c)
if not hasType and not hasDefault and kind notin {skTemplate, skMacro}: if not hasType and not hasDefault and kind notin {skTemplate, skMacro}:
let param = strTableGet(c.signatures, arg.name) let param = strTableGet(c.signatures, arg.name)
@ -1237,7 +1237,7 @@ proc semProcTypeNode(c: PContext, n, genericParams: PNode,
proc semStmtListType(c: PContext, n: PNode, prev: PType): PType = proc semStmtListType(c: PContext, n: PNode, prev: PType): PType =
checkMinSonsLen(n, 1, c.config) checkMinSonsLen(n, 1, c.config)
var length = sonsLen(n) var length = sonsLen(n)
for i in countup(0, length - 2): for i in 0 .. length - 2:
n.sons[i] = semStmt(c, n.sons[i], {}) n.sons[i] = semStmt(c, n.sons[i], {})
if length > 0: if length > 0:
result = semTypeNode(c, n.sons[length - 1], prev) result = semTypeNode(c, n.sons[length - 1], prev)
@ -1917,7 +1917,7 @@ proc semGenericParamList(c: PContext, n: PNode, father: PType = nil): PNode =
typ.flags.incl tfGenericTypeParam typ.flags.incl tfGenericTypeParam
for j in countup(0, L-3): for j in 0 .. L-3:
let finalType = if j == 0: typ let finalType = if j == 0: typ
else: copyType(typ, typ.owner, false) else: copyType(typ, typ.owner, false)
# it's important the we create an unique # it's important the we create an unique

View file

@ -134,7 +134,7 @@ proc hashType(c: var MD5Context, t: PType; flags: set[ConsiderFlag]) =
let inst = t.typeInst let inst = t.typeInst
t.typeInst = nil t.typeInst = nil
assert inst.kind == tyGenericInst assert inst.kind == tyGenericInst
for i in countup(0, inst.len - 2): for i in 0 .. inst.len - 2:
c.hashType inst.sons[i], flags c.hashType inst.sons[i], flags
t.typeInst = inst t.typeInst = inst
return return

View file

@ -85,13 +85,13 @@ proc parsePipe(filename: AbsoluteFile, inputStream: PLLStream; cache: IdentCache
llStreamClose(s) llStreamClose(s)
proc getFilter(ident: PIdent): TFilterKind = proc getFilter(ident: PIdent): TFilterKind =
for i in countup(low(TFilterKind), high(TFilterKind)): for i in low(TFilterKind) .. high(TFilterKind):
if cmpIgnoreStyle(ident.s, filterNames[i]) == 0: if cmpIgnoreStyle(ident.s, filterNames[i]) == 0:
return i return i
result = filtNone result = filtNone
proc getParser(conf: ConfigRef; n: PNode; ident: PIdent): TParserKind = proc getParser(conf: ConfigRef; n: PNode; ident: PIdent): TParserKind =
for i in countup(low(TParserKind), high(TParserKind)): for i in low(TParserKind) .. high(TParserKind):
if cmpIgnoreStyle(ident.s, parserNames[i]) == 0: if cmpIgnoreStyle(ident.s, parserNames[i]) == 0:
return i return i
localError(conf, n.info, "unknown parser: " & ident.s) localError(conf, n.info, "unknown parser: " & ident.s)
@ -131,7 +131,7 @@ proc evalPipe(p: var TParsers, n: PNode, filename: AbsoluteFile,
result = start result = start
if n.kind == nkEmpty: return if n.kind == nkEmpty: return
if n.kind == nkInfix and n[0].kind == nkIdent and n[0].ident.s == "|": if n.kind == nkInfix and n[0].kind == nkIdent and n[0].ident.s == "|":
for i in countup(1, 2): for i in 1 .. 2:
if n.sons[i].kind == nkInfix: if n.sons[i].kind == nkInfix:
result = evalPipe(p, n.sons[i], filename, result) result = evalPipe(p, n.sons[i], filename, result)
else: else:

View file

@ -203,7 +203,7 @@ proc transformVarSection(c: PTransf, v: PNode): PTransNode =
internalError(c.graph.config, it.info, "transformVarSection: not nkVarTuple") internalError(c.graph.config, it.info, "transformVarSection: not nkVarTuple")
var L = sonsLen(it) var L = sonsLen(it)
var defs = newTransNode(it.kind, it.info, L) var defs = newTransNode(it.kind, it.info, L)
for j in countup(0, L-3): for j in 0 .. L-3:
if it[j].kind == nkSym: if it[j].kind == nkSym:
let x = freshVar(c, it.sons[j].sym) let x = freshVar(c, it.sons[j].sym)
idNodeTablePut(c.transCon.mapping, it.sons[j].sym, x) idNodeTablePut(c.transCon.mapping, it.sons[j].sym, x)
@ -390,7 +390,7 @@ proc transformYield(c: PTransf, n: PNode): PTransNode =
else: else:
# Unpack the tuple into the loop variables # Unpack the tuple into the loop variables
# XXX: BUG: what if `n` is an expression with side-effects? # XXX: BUG: what if `n` is an expression with side-effects?
for i in countup(0, sonsLen(c.transCon.forStmt) - 3): for i in 0 .. sonsLen(c.transCon.forStmt) - 3:
let lhs = c.transCon.forStmt.sons[i] let lhs = c.transCon.forStmt.sons[i]
let rhs = transform(c, newTupleAccess(c.graph, e, i)) let rhs = transform(c, newTupleAccess(c.graph, e, i))
add(result, asgnTo(lhs, rhs)) add(result, asgnTo(lhs, rhs))
@ -620,7 +620,7 @@ proc transformFor(c: PTransf, n: PNode): PTransNode =
discard c.breakSyms.pop discard c.breakSyms.pop
var v = newNodeI(nkVarSection, n.info) var v = newNodeI(nkVarSection, n.info)
for i in countup(0, length - 3): for i in 0 .. length - 3:
if n[i].kind == nkVarTuple: if n[i].kind == nkVarTuple:
for j in 0 ..< sonsLen(n[i])-1: for j in 0 ..< sonsLen(n[i])-1:
addVar(v, copyTree(n[i][j])) # declare new vars addVar(v, copyTree(n[i][j])) # declare new vars

View file

@ -84,7 +84,7 @@ proc nodeTablePut*(t: var TNodeTable, key: PNode, val: int) =
else: else:
if mustRehash(len(t.data), t.counter): if mustRehash(len(t.data), t.counter):
newSeq(n, len(t.data) * GrowthFactor) newSeq(n, len(t.data) * GrowthFactor)
for i in countup(0, high(t.data)): for i in 0 .. high(t.data):
if t.data[i].key != nil: if t.data[i].key != nil:
nodeTableRawInsert(n, t.data[i].h, t.data[i].key, t.data[i].val) nodeTableRawInsert(n, t.data[i].h, t.data[i].key, t.data[i].val)
swap(t.data, n) swap(t.data, n)
@ -101,7 +101,7 @@ proc nodeTableTestOrSet*(t: var TNodeTable, key: PNode, val: int): int =
else: else:
if mustRehash(len(t.data), t.counter): if mustRehash(len(t.data), t.counter):
newSeq(n, len(t.data) * GrowthFactor) newSeq(n, len(t.data) * GrowthFactor)
for i in countup(0, high(t.data)): for i in 0 .. high(t.data):
if t.data[i].key != nil: if t.data[i].key != nil:
nodeTableRawInsert(n, t.data[i].h, t.data[i].key, t.data[i].val) nodeTableRawInsert(n, t.data[i].h, t.data[i].key, t.data[i].val)
swap(t.data, n) swap(t.data, n)

View file

@ -465,7 +465,7 @@ proc typeToString(typ: PType, prefer: TPreferedDesc = preferName): string =
add(result, ']') add(result, ']')
of tyGenericBody: of tyGenericBody:
result = typeToString(t.lastSon) & '[' result = typeToString(t.lastSon) & '['
for i in countup(0, sonsLen(t)-2): for i in 0 .. sonsLen(t)-2:
if i > 0: add(result, ", ") if i > 0: add(result, ", ")
add(result, typeToString(t.sons[i], preferTypeName)) add(result, typeToString(t.sons[i], preferTypeName))
add(result, ']') add(result, ']')
@ -506,7 +506,7 @@ proc typeToString(typ: PType, prefer: TPreferedDesc = preferName): string =
of tyUserTypeClassInst: of tyUserTypeClassInst:
let body = t.base let body = t.base
result = body.sym.name.s & "[" result = body.sym.name.s & "["
for i in countup(1, sonsLen(t) - 2): for i in 1 .. sonsLen(t) - 2:
if i > 1: add(result, ", ") if i > 1: add(result, ", ")
add(result, typeToString(t.sons[i])) add(result, typeToString(t.sons[i]))
result.add "]" result.add "]"

View file

@ -1154,7 +1154,7 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
# we know the next instruction is a 'fjmp': # we know the next instruction is a 'fjmp':
let branch = c.constants[instr.regBx-wordExcess] let branch = c.constants[instr.regBx-wordExcess]
var cond = false var cond = false
for j in countup(0, sonsLen(branch) - 2): for j in 0 .. sonsLen(branch) - 2:
if overlap(regs[ra].regToNode, branch.sons[j]): if overlap(regs[ra].regToNode, branch.sons[j]):
cond = true cond = true
break break

View file

@ -510,7 +510,7 @@ proc genTry(c: PCtx; n: PNode; dest: var TDest) =
var blen = len(it) var blen = len(it)
# first opcExcept contains the end label of the 'except' block: # first opcExcept contains the end label of the 'except' block:
let endExcept = c.xjmp(it, opcExcept, 0) let endExcept = c.xjmp(it, opcExcept, 0)
for j in countup(0, blen - 2): for j in 0 .. blen - 2:
assert(it.sons[j].kind == nkType) assert(it.sons[j].kind == nkType)
let typ = it.sons[j].typ.skipTypes(abstractPtrs-{tyTypeDesc}) let typ = it.sons[j].typ.skipTypes(abstractPtrs-{tyTypeDesc})
c.gABx(it, opcExcept, 0, c.genType(typ)) c.gABx(it, opcExcept, 0, c.genType(typ))

View file

@ -180,7 +180,7 @@ const
] ]
proc findStr*(a: openArray[string], s: string): int = proc findStr*(a: openArray[string], s: string): int =
for i in countup(low(a), high(a)): for i in low(a) .. high(a):
if cmpIgnoreStyle(a[i], s) == 0: if cmpIgnoreStyle(a[i], s) == 0:
return i return i
result = - 1 result = - 1