more replacements for the deprecated '<'

This commit is contained in:
Andreas Rumpf 2017-10-29 08:55:30 +01:00
commit 6a3288a60e
19 changed files with 43 additions and 43 deletions

View file

@ -839,7 +839,7 @@ proc newNilLit*(): NimNode {.compileTime.} =
## New nil literal shortcut ## New nil literal shortcut
result = newNimNode(nnkNilLit) result = newNimNode(nnkNilLit)
proc last*(node: NimNode): NimNode {.compileTime.} = node[<node.len] proc last*(node: NimNode): NimNode {.compileTime.} = node[node.len-1]
## Return the last item in nodes children. Same as `node[^1]` ## Return the last item in nodes children. Same as `node[^1]`
@ -887,7 +887,7 @@ proc newIfStmt*(branches: varargs[tuple[cond, body: NimNode]]):
proc copyChildrenTo*(src, dest: NimNode) {.compileTime.}= proc copyChildrenTo*(src, dest: NimNode) {.compileTime.}=
## Copy all children from `src` to `dest` ## Copy all children from `src` to `dest`
for i in 0 .. < src.len: for i in 0 ..< src.len:
dest.add src[i].copyNimTree dest.add src[i].copyNimTree
template expectRoutine(node: NimNode) = template expectRoutine(node: NimNode) =
@ -1107,7 +1107,7 @@ proc eqIdent*(node: NimNode; s: string): bool {.compileTime.} =
proc hasArgOfName* (params: NimNode; name: string): bool {.compiletime.}= proc hasArgOfName* (params: NimNode; name: string): bool {.compiletime.}=
## Search nnkFormalParams for an argument. ## Search nnkFormalParams for an argument.
assert params.kind == nnkFormalParams assert params.kind == nnkFormalParams
for i in 1 .. <params.len: for i in 1 ..< params.len:
template node: untyped = params[i] template node: untyped = params[i]
if name.eqIdent( $ node[0]): if name.eqIdent( $ node[0]):
return true return true

View file

@ -18,7 +18,7 @@
## var ## var
## a: ActorPool[int, void] ## a: ActorPool[int, void]
## createActorPool(a) ## createActorPool(a)
## for i in 0 .. < 300: ## for i in 0 ..< 300:
## a.spawn(i, proc (x: int) {.thread.} = echo x) ## a.spawn(i, proc (x: int) {.thread.} = echo x)
## a.join() ## a.join()
## ##
@ -133,7 +133,7 @@ proc createActorPool*[In, Out](a: var ActorPool[In, Out], poolSize = 4) =
newSeq(a.actors, poolSize) newSeq(a.actors, poolSize)
when Out isnot void: when Out isnot void:
open(a.outputs) open(a.outputs)
for i in 0 .. < a.actors.len: for i in 0 ..< a.actors.len:
a.actors[i] = spawn(poolWorker[In, Out]) a.actors[i] = spawn(poolWorker[In, Out])
proc sync*[In, Out](a: var ActorPool[In, Out], polling=50) = proc sync*[In, Out](a: var ActorPool[In, Out], polling=50) =
@ -227,7 +227,7 @@ when not defined(testing) and isMainModule:
var var
a: ActorPool[int, void] a: ActorPool[int, void]
createActorPool(a) createActorPool(a)
for i in 0 .. < 300: for i in 0 ..< 300:
a.spawn(i, proc (x: int) {.thread.} = echo x) a.spawn(i, proc (x: int) {.thread.} = echo x)
when false: when false:

View file

@ -257,7 +257,7 @@ proc allprefixedAux[T](c: CritBitTree[T], key: string; longestMatch: bool): Node
p = p.child[dir] p = p.child[dir]
if q.byte < key.len: top = p if q.byte < key.len: top = p
if not longestMatch: if not longestMatch:
for i in 0 .. <key.len: for i in 0 ..< key.len:
if p.key[i] != key[i]: return if p.key[i] != key[i]: return
result = top result = top

View file

@ -149,7 +149,7 @@ template delImpl() {.dirty.} =
delImplIdx(t, i) delImplIdx(t, i)
template clearImpl() {.dirty.} = template clearImpl() {.dirty.} =
for i in 0 .. <t.data.len: for i in 0 ..< t.data.len:
when compiles(t.data[i].hcode): # CountTable records don't contain a hcode when compiles(t.data[i].hcode): # CountTable records don't contain a hcode
t.data[i].hcode = 0 t.data[i].hcode = 0
t.data[i].key = default(type(t.data[i].key)) t.data[i].key = default(type(t.data[i].key))

View file

@ -149,7 +149,7 @@ proc selectWorker(w: ptr Worker; fn: WorkerProc; data: pointer): bool =
proc cleanFlowVars(w: ptr Worker) = proc cleanFlowVars(w: ptr Worker) =
let q = addr(w.q) let q = addr(w.q)
acquire(q.lock) acquire(q.lock)
for i in 0 .. <q.len: for i in 0 ..< q.len:
GC_unref(cast[RootRef](q.data[i])) GC_unref(cast[RootRef](q.data[i]))
#echo "GC_unref" #echo "GC_unref"
q.len = 0 q.len = 0
@ -543,7 +543,7 @@ proc sync*() =
var toRelease = 0 var toRelease = 0
while true: while true:
var allReady = true var allReady = true
for i in 0 .. <currentPoolSize: for i in 0 ..< currentPoolSize:
if not allReady: break if not allReady: break
allReady = allReady and workersData[i].ready allReady = allReady and workersData[i].ready
if allReady: break if allReady: break

View file

@ -22,7 +22,7 @@ proc createProcType(p, b: NimNode): NimNode {.compileTime.} =
case p.kind case p.kind
of nnkPar: of nnkPar:
for i in 0 .. <p.len: for i in 0 ..< p.len:
let ident = p[i] let ident = p[i]
var identDefs = newNimNode(nnkIdentDefs) var identDefs = newNimNode(nnkIdentDefs)
case ident.kind case ident.kind
@ -77,7 +77,7 @@ macro `=>`*(p, b: untyped): untyped =
if c[0].kind == nnkIdent and c[0].ident == !"->": if c[0].kind == nnkIdent and c[0].ident == !"->":
var procTy = createProcType(c[1], c[2]) var procTy = createProcType(c[1], c[2])
params[0] = procTy[0][0] params[0] = procTy[0][0]
for i in 1 .. <procTy[0].len: for i in 1 ..< procTy[0].len:
params.add(procTy[0][i]) params.add(procTy[0][i])
else: else:
error("Expected proc type (->) got (" & $c[0].ident & ").") error("Expected proc type (->) got (" & $c[0].ident & ").")
@ -96,7 +96,7 @@ macro `=>`*(p, b: untyped): untyped =
if p[0].kind == nnkIdent and p[0].ident == !"->": if p[0].kind == nnkIdent and p[0].ident == !"->":
var procTy = createProcType(p[1], p[2]) var procTy = createProcType(p[1], p[2])
params[0] = procTy[0][0] params[0] = procTy[0][0]
for i in 1 .. <procTy[0].len: for i in 1 ..< procTy[0].len:
params.add(procTy[0][i]) params.add(procTy[0][i])
else: else:
error("Expected proc type (->) got (" & $p[0].ident & ").") error("Expected proc type (->) got (" & $p[0].ident & ").")

View file

@ -823,13 +823,13 @@ proc toJson(x: NimNode): NimNode {.compiletime.} =
of nnkBracket: # array of nnkBracket: # array
if x.len == 0: return newCall(bindSym"newJArray") if x.len == 0: return newCall(bindSym"newJArray")
result = newNimNode(nnkBracket) result = newNimNode(nnkBracket)
for i in 0 .. <x.len: for i in 0 ..< x.len:
result.add(toJson(x[i])) result.add(toJson(x[i]))
result = newCall(bindSym"%", result) result = newCall(bindSym"%", result)
of nnkTableConstr: # object of nnkTableConstr: # object
if x.len == 0: return newCall(bindSym"newJObject") if x.len == 0: return newCall(bindSym"newJObject")
result = newNimNode(nnkTableConstr) result = newNimNode(nnkTableConstr)
for i in 0 .. <x.len: for i in 0 ..< x.len:
x[i].expectKind nnkExprColonExpr x[i].expectKind nnkExprColonExpr
result.add newTree(nnkExprColonExpr, x[i][0], toJson(x[i][1])) result.add newTree(nnkExprColonExpr, x[i][0], toJson(x[i][1]))
result = newCall(bindSym"%", result) result = newCall(bindSym"%", result)
@ -1303,7 +1303,7 @@ else:
case getVarType(x) case getVarType(x)
of JArray: of JArray:
result = newJArray() result = newJArray()
for i in 0 .. <x.len: for i in 0 ..< x.len:
result.add(x[i].convertObject()) result.add(x[i].convertObject())
of JObject: of JObject:
result = newJObject() result = newJObject()
@ -1449,7 +1449,7 @@ proc processElseBranch(recCaseNode, elseBranch, jsonNode, kindType,
# We need to build up a list of conditions from each ``of`` branch so that # We need to build up a list of conditions from each ``of`` branch so that
# we can then negate it to get ``else``. # we can then negate it to get ``else``.
var cond = newIdentNode("false") var cond = newIdentNode("false")
for i in 1 .. <len(recCaseNode): for i in 1 ..< len(recCaseNode):
if recCaseNode[i].kind == nnkElse: if recCaseNode[i].kind == nnkElse:
break break
@ -1511,7 +1511,7 @@ proc processObjField(field, jsonNode: NimNode): seq[NimNode] =
exprColonExpr.add(getEnumCall) exprColonExpr.add(getEnumCall)
# Iterate through each `of` branch. # Iterate through each `of` branch.
for i in 1 .. <field.len: for i in 1 ..< field.len:
case field[i].kind case field[i].kind
of nnkOfBranch: of nnkOfBranch:
result.add processOfBranch(field[i], jsonNode, kindType, kindJsonNode) result.add processOfBranch(field[i], jsonNode, kindType, kindJsonNode)
@ -1640,7 +1640,7 @@ proc createConstructor(typeSym, jsonNode: NimNode): NimNode =
( (
var list: `typeSym` = @[]; var list: `typeSym` = @[];
verifyJsonKind(`jsonNode`, {JArray}, astToStr(`jsonNode`)); verifyJsonKind(`jsonNode`, {JArray}, astToStr(`jsonNode`));
for `forLoopI` in 0 .. <`jsonNode`.len: list.add(`constructorNode`); for `forLoopI` in 0 ..< `jsonNode`.len: list.add(`constructorNode`);
list list
) )
of "array": of "array":
@ -1654,7 +1654,7 @@ proc createConstructor(typeSym, jsonNode: NimNode): NimNode =
( (
var list: `typeSym`; var list: `typeSym`;
verifyJsonKind(`jsonNode`, {JArray}, astToStr(`jsonNode`)); verifyJsonKind(`jsonNode`, {JArray}, astToStr(`jsonNode`));
for `forLoopI` in 0 .. <`jsonNode`.len: list[`forLoopI`] =`constructorNode`; for `forLoopI` in 0 ..< `jsonNode`.len: list[`forLoopI`] =`constructorNode`;
list list
) )
@ -1683,7 +1683,7 @@ proc postProcessValue(value: NimNode): NimNode =
result = postProcess(value) result = postProcess(value)
else: else:
result = value result = value
for i in 0 .. <len(result): for i in 0 ..< len(result):
result[i] = postProcessValue(result[i]) result[i] = postProcessValue(result[i])
proc postProcessExprColonExpr(exprColonExpr, resIdent: NimNode): NimNode = proc postProcessExprColonExpr(exprColonExpr, resIdent: NimNode): NimNode =

View file

@ -283,7 +283,7 @@ proc to*[T](data: string): T =
loadAny(newStringStream(data), toAny(result), tab) loadAny(newStringStream(data), toAny(result), tab)
when not defined(testing) and isMainModule: when not defined(testing) and isMainModule:
template testit(x: expr) = echo($$to[type(x)]($$x)) template testit(x: untyped) = echo($$to[type(x)]($$x))
var x: array[0..4, array[0..4, string]] = [ var x: array[0..4, array[0..4, string]] = [
["test", "1", "2", "3", "4"], ["test", "1", "2", "3", "4"], ["test", "1", "2", "3", "4"], ["test", "1", "2", "3", "4"],

View file

@ -162,7 +162,7 @@ elif defined(linux):
return @[] return @[]
raiseOSError(err) raiseOSError(err)
if evNum == 0: return @[] if evNum == 0: return @[]
for i in 0 .. <evNum: for i in 0 ..< evNum:
let fd = s.events[i].data.fd.SocketHandle let fd = s.events[i].data.fd.SocketHandle
var evSet: set[Event] = {} var evSet: set[Event] = {}
@ -253,7 +253,7 @@ elif defined(macosx) or defined(freebsd) or defined(openbsd) or defined(netbsd):
return @[] return @[]
raiseOSError(err) raiseOSError(err)
if evNum == 0: return @[] if evNum == 0: return @[]
for i in 0 .. <evNum: for i in 0 ..< evNum:
let fd = s.events[i].ident.SocketHandle let fd = s.events[i].ident.SocketHandle
var evSet: set[Event] = {} var evSet: set[Event] = {}

View file

@ -1199,7 +1199,7 @@ proc unindent*(s: string, count: Natural, padding: string = " "): string
var indentCount = 0 var indentCount = 0
for j in 0..<count.int: for j in 0..<count.int:
indentCount.inc indentCount.inc
if line[j .. j + <padding.len] != padding: if line[j .. j + padding.len-1] != padding:
indentCount = j indentCount = j
break break
result.add(line[indentCount*padding.len .. ^1]) result.add(line[indentCount*padding.len .. ^1])
@ -1407,10 +1407,10 @@ proc find*(s, sub: string, start: Natural = 0, last: Natural = 0): int {.noSideE
## Searching is case-sensitive. If `sub` is not in `s`, -1 is returned. ## Searching is case-sensitive. If `sub` is not in `s`, -1 is returned.
if sub.len > s.len: if sub.len > s.len:
return -1 return -1
if sub.len == 1: if sub.len == 1:
return find(s, sub[0], start, last) return find(s, sub[0], start, last)
var a {.noinit.}: SkipTable var a {.noinit.}: SkipTable
initSkipTable(a, sub) initSkipTable(a, sub)
result = find(a, s, sub, start, last) result = find(a, s, sub, start, last)

View file

@ -250,7 +250,7 @@ proc combine*(base: Uri, reference: Uri): Uri =
proc combine*(uris: varargs[Uri]): Uri = proc combine*(uris: varargs[Uri]): Uri =
## Combines multiple URIs together. ## Combines multiple URIs together.
result = uris[0] result = uris[0]
for i in 1 .. <uris.len: for i in 1 ..< uris.len:
result = combine(result, uris[i]) result = combine(result, uris[i])
proc isAbsolute*(uri: Uri): bool = proc isAbsolute*(uri: Uri): bool =

View file

@ -127,7 +127,7 @@ proc fileMatches(c, bp: cstring): bool =
proc canonFilename*(filename: cstring): cstring = proc canonFilename*(filename: cstring): cstring =
## returns 'nil' if the filename cannot be found. ## returns 'nil' if the filename cannot be found.
for i in 0 .. <dbgFilenameLen: for i in 0 ..< dbgFilenameLen:
result = dbgFilenames[i] result = dbgFilenames[i]
if fileMatches(result, filename): return result if fileMatches(result, filename): return result
result = nil result = nil

View file

@ -643,9 +643,9 @@ when useMarkForDebug or useBackupGc:
forAllChildren(d, waMarkPrecise) forAllChildren(d, waMarkPrecise)
proc markGlobals(gch: var GcHeap) = proc markGlobals(gch: var GcHeap) =
for i in 0 .. < globalMarkersLen: globalMarkers[i]() for i in 0 .. globalMarkersLen-1: globalMarkers[i]()
let d = gch.additionalRoots.d let d = gch.additionalRoots.d
for i in 0 .. < gch.additionalRoots.len: markS(gch, d[i]) for i in 0 .. gch.additionalRoots.len-1: markS(gch, d[i])
when logGC: when logGC:
var var
@ -653,7 +653,7 @@ when logGC:
cycleCheckALen = 0 cycleCheckALen = 0
proc alreadySeen(c: PCell): bool = proc alreadySeen(c: PCell): bool =
for i in 0 .. <cycleCheckALen: for i in 0 .. cycleCheckALen-1:
if cycleCheckA[i] == c: return true if cycleCheckA[i] == c: return true
if cycleCheckALen == len(cycleCheckA): if cycleCheckALen == len(cycleCheckA):
gcAssert(false, "cycle detection overflow") gcAssert(false, "cycle detection overflow")

View file

@ -487,12 +487,12 @@ proc GC_dumpHeap*(file: File) =
var spaceIter: ObjectSpaceIter var spaceIter: ObjectSpaceIter
when false: when false:
var d = gch.decStack.d var d = gch.decStack.d
for i in 0 .. < gch.decStack.len: for i in 0 .. gch.decStack.len-1:
if isAllocatedPtr(gch.region, d[i]): if isAllocatedPtr(gch.region, d[i]):
c_fprintf(file, "onstack %p\n", d[i]) c_fprintf(file, "onstack %p\n", d[i])
else: else:
c_fprintf(file, "onstack_invalid %p\n", d[i]) c_fprintf(file, "onstack_invalid %p\n", d[i])
for i in 0 .. < globalMarkersLen: globalMarkers[i]() for i in 0 .. globalMarkersLen-1: globalMarkers[i]()
while true: while true:
let x = allObjectsAsProc(gch.region, addr spaceIter) let x = allObjectsAsProc(gch.region, addr spaceIter)
if spaceIter.state < 0: break if spaceIter.state < 0: break
@ -579,7 +579,7 @@ proc markIncremental(gch: var GcHeap): bool =
result = true result = true
proc markGlobals(gch: var GcHeap) = proc markGlobals(gch: var GcHeap) =
for i in 0 .. < globalMarkersLen: globalMarkers[i]() for i in 0 .. globalMarkersLen-1: globalMarkers[i]()
proc doOperation(p: pointer, op: WalkOp) = proc doOperation(p: pointer, op: WalkOp) =
if p == nil: return if p == nil: return

View file

@ -450,9 +450,9 @@ when false:
quit 1 quit 1
proc markGlobals(gch: var GcHeap) = proc markGlobals(gch: var GcHeap) =
for i in 0 .. < globalMarkersLen: globalMarkers[i]() for i in 0 .. globalMarkersLen-1: globalMarkers[i]()
let d = gch.additionalRoots.d let d = gch.additionalRoots.d
for i in 0 .. < gch.additionalRoots.len: mark(gch, d[i]) for i in 0 .. gch.additionalRoots.len-1: mark(gch, d[i])
proc gcMark(gch: var GcHeap, p: pointer) {.inline.} = proc gcMark(gch: var GcHeap, p: pointer) {.inline.} =
# the addresses are not as cells on the stack, so turn them to cells: # the addresses are not as cells on the stack, so turn them to cells:

View file

@ -41,7 +41,7 @@ proc `$`(x: uint64): string =
let half = i div 2 let half = i div 2
# Reverse # Reverse
for t in 0 .. < half: swap(result[t], result[i-t-1]) for t in 0 .. half-1: swap(result[t], result[i-t-1])
proc reprStrAux(result: var string, s: cstring; len: int) = proc reprStrAux(result: var string, s: cstring; len: int) =
if cast[pointer](s) == nil: if cast[pointer](s) == nil:

View file

@ -50,7 +50,7 @@ proc reprChar(x: char): string {.compilerRtl.} =
proc reprStrAux(result: var string, s: cstring, len: int) = proc reprStrAux(result: var string, s: cstring, len: int) =
add(result, "\"") add(result, "\"")
for i in 0 .. <len: for i in 0 ..< len:
let c = s[i] let c = s[i]
case c case c
of '"': add(result, "\\\"") of '"': add(result, "\\\"")
@ -149,7 +149,7 @@ proc reprArray(a: pointer, typ: PNimType,
{. emit: "`len` = `a`.length;\n" .} {. emit: "`len` = `a`.length;\n" .}
var dereffed: pointer = a var dereffed: pointer = a
for i in 0 .. < len: for i in 0 ..< len:
if i > 0 : if i > 0 :
add(result, ", ") add(result, ", ")
# advance pointer and point to element at index # advance pointer and point to element at index
@ -192,7 +192,7 @@ proc reprRecordAux(result: var string, o: pointer, typ: PNimType, cl: var ReprCl
reprAux(result, val, typ.node.typ, cl) reprAux(result, val, typ.node.typ, cl)
else: else:
# if the object has more than one field, sons is not nil and contains the fields. # if the object has more than one field, sons is not nil and contains the fields.
for i in 0 .. <typ.node.len: for i in 0 ..< typ.node.len:
if first: first = false if first: first = false
else: add(result, ",\n") else: add(result, ",\n")

View file

@ -278,7 +278,7 @@ proc setLengthSeq(seq: PGenericSeq, elemSize, newLen: int): PGenericSeq {.
GenericSeqSize +% (i*%elemSize)), GenericSeqSize +% (i*%elemSize)),
extGetCellType(result).base, waPush) extGetCellType(result).base, waPush)
let len1 = gch.tempStack.len let len1 = gch.tempStack.len
for i in len0 .. <len1: for i in len0 ..< len1:
doDecRef(gch.tempStack.d[i], LocalHeap, MaybeCyclic) doDecRef(gch.tempStack.d[i], LocalHeap, MaybeCyclic)
gch.tempStack.len = len0 gch.tempStack.len = len0
else: else:

View file

@ -593,7 +593,7 @@ from strutils import toHex, toLowerAscii
proc hexStr(buf: cstring): string = proc hexStr(buf: cstring): string =
# turn md5s output into a nice hex str # turn md5s output into a nice hex str
result = newStringOfCap(32) result = newStringOfCap(32)
for i in 0 .. <16: for i in 0 ..< 16:
result.add toHex(buf[i].ord, 2).toLowerAscii result.add toHex(buf[i].ord, 2).toLowerAscii
proc md5_File*(file: string): string {.raises: [IOError,Exception].} = proc md5_File*(file: string): string {.raises: [IOError,Exception].} =