mirror of
https://github.com/nim-lang/Nim.git
synced 2026-05-02 12:04:44 +00:00
more replacements for the deprecated '<'
This commit is contained in:
@@ -839,7 +839,7 @@ proc newNilLit*(): NimNode {.compileTime.} =
|
||||
## New nil literal shortcut
|
||||
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]`
|
||||
|
||||
|
||||
@@ -887,7 +887,7 @@ proc newIfStmt*(branches: varargs[tuple[cond, body: NimNode]]):
|
||||
|
||||
proc copyChildrenTo*(src, dest: NimNode) {.compileTime.}=
|
||||
## Copy all children from `src` to `dest`
|
||||
for i in 0 .. < src.len:
|
||||
for i in 0 ..< src.len:
|
||||
dest.add src[i].copyNimTree
|
||||
|
||||
template expectRoutine(node: NimNode) =
|
||||
@@ -1107,7 +1107,7 @@ proc eqIdent*(node: NimNode; s: string): bool {.compileTime.} =
|
||||
proc hasArgOfName* (params: NimNode; name: string): bool {.compiletime.}=
|
||||
## Search nnkFormalParams for an argument.
|
||||
assert params.kind == nnkFormalParams
|
||||
for i in 1 .. <params.len:
|
||||
for i in 1 ..< params.len:
|
||||
template node: untyped = params[i]
|
||||
if name.eqIdent( $ node[0]):
|
||||
return true
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
## var
|
||||
## a: ActorPool[int, void]
|
||||
## createActorPool(a)
|
||||
## for i in 0 .. < 300:
|
||||
## for i in 0 ..< 300:
|
||||
## a.spawn(i, proc (x: int) {.thread.} = echo x)
|
||||
## a.join()
|
||||
##
|
||||
@@ -133,7 +133,7 @@ proc createActorPool*[In, Out](a: var ActorPool[In, Out], poolSize = 4) =
|
||||
newSeq(a.actors, poolSize)
|
||||
when Out isnot void:
|
||||
open(a.outputs)
|
||||
for i in 0 .. < a.actors.len:
|
||||
for i in 0 ..< a.actors.len:
|
||||
a.actors[i] = spawn(poolWorker[In, Out])
|
||||
|
||||
proc sync*[In, Out](a: var ActorPool[In, Out], polling=50) =
|
||||
@@ -227,7 +227,7 @@ when not defined(testing) and isMainModule:
|
||||
var
|
||||
a: ActorPool[int, void]
|
||||
createActorPool(a)
|
||||
for i in 0 .. < 300:
|
||||
for i in 0 ..< 300:
|
||||
a.spawn(i, proc (x: int) {.thread.} = echo x)
|
||||
|
||||
when false:
|
||||
|
||||
@@ -257,7 +257,7 @@ proc allprefixedAux[T](c: CritBitTree[T], key: string; longestMatch: bool): Node
|
||||
p = p.child[dir]
|
||||
if q.byte < key.len: top = p
|
||||
if not longestMatch:
|
||||
for i in 0 .. <key.len:
|
||||
for i in 0 ..< key.len:
|
||||
if p.key[i] != key[i]: return
|
||||
result = top
|
||||
|
||||
|
||||
@@ -149,7 +149,7 @@ template delImpl() {.dirty.} =
|
||||
delImplIdx(t, i)
|
||||
|
||||
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
|
||||
t.data[i].hcode = 0
|
||||
t.data[i].key = default(type(t.data[i].key))
|
||||
|
||||
@@ -149,7 +149,7 @@ proc selectWorker(w: ptr Worker; fn: WorkerProc; data: pointer): bool =
|
||||
proc cleanFlowVars(w: ptr Worker) =
|
||||
let q = addr(w.q)
|
||||
acquire(q.lock)
|
||||
for i in 0 .. <q.len:
|
||||
for i in 0 ..< q.len:
|
||||
GC_unref(cast[RootRef](q.data[i]))
|
||||
#echo "GC_unref"
|
||||
q.len = 0
|
||||
@@ -543,7 +543,7 @@ proc sync*() =
|
||||
var toRelease = 0
|
||||
while true:
|
||||
var allReady = true
|
||||
for i in 0 .. <currentPoolSize:
|
||||
for i in 0 ..< currentPoolSize:
|
||||
if not allReady: break
|
||||
allReady = allReady and workersData[i].ready
|
||||
if allReady: break
|
||||
|
||||
@@ -22,7 +22,7 @@ proc createProcType(p, b: NimNode): NimNode {.compileTime.} =
|
||||
|
||||
case p.kind
|
||||
of nnkPar:
|
||||
for i in 0 .. <p.len:
|
||||
for i in 0 ..< p.len:
|
||||
let ident = p[i]
|
||||
var identDefs = newNimNode(nnkIdentDefs)
|
||||
case ident.kind
|
||||
@@ -77,7 +77,7 @@ macro `=>`*(p, b: untyped): untyped =
|
||||
if c[0].kind == nnkIdent and c[0].ident == !"->":
|
||||
var procTy = createProcType(c[1], c[2])
|
||||
params[0] = procTy[0][0]
|
||||
for i in 1 .. <procTy[0].len:
|
||||
for i in 1 ..< procTy[0].len:
|
||||
params.add(procTy[0][i])
|
||||
else:
|
||||
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 == !"->":
|
||||
var procTy = createProcType(p[1], p[2])
|
||||
params[0] = procTy[0][0]
|
||||
for i in 1 .. <procTy[0].len:
|
||||
for i in 1 ..< procTy[0].len:
|
||||
params.add(procTy[0][i])
|
||||
else:
|
||||
error("Expected proc type (->) got (" & $p[0].ident & ").")
|
||||
|
||||
@@ -823,13 +823,13 @@ proc toJson(x: NimNode): NimNode {.compiletime.} =
|
||||
of nnkBracket: # array
|
||||
if x.len == 0: return newCall(bindSym"newJArray")
|
||||
result = newNimNode(nnkBracket)
|
||||
for i in 0 .. <x.len:
|
||||
for i in 0 ..< x.len:
|
||||
result.add(toJson(x[i]))
|
||||
result = newCall(bindSym"%", result)
|
||||
of nnkTableConstr: # object
|
||||
if x.len == 0: return newCall(bindSym"newJObject")
|
||||
result = newNimNode(nnkTableConstr)
|
||||
for i in 0 .. <x.len:
|
||||
for i in 0 ..< x.len:
|
||||
x[i].expectKind nnkExprColonExpr
|
||||
result.add newTree(nnkExprColonExpr, x[i][0], toJson(x[i][1]))
|
||||
result = newCall(bindSym"%", result)
|
||||
@@ -1303,7 +1303,7 @@ else:
|
||||
case getVarType(x)
|
||||
of JArray:
|
||||
result = newJArray()
|
||||
for i in 0 .. <x.len:
|
||||
for i in 0 ..< x.len:
|
||||
result.add(x[i].convertObject())
|
||||
of JObject:
|
||||
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 can then negate it to get ``else``.
|
||||
var cond = newIdentNode("false")
|
||||
for i in 1 .. <len(recCaseNode):
|
||||
for i in 1 ..< len(recCaseNode):
|
||||
if recCaseNode[i].kind == nnkElse:
|
||||
break
|
||||
|
||||
@@ -1511,7 +1511,7 @@ proc processObjField(field, jsonNode: NimNode): seq[NimNode] =
|
||||
exprColonExpr.add(getEnumCall)
|
||||
|
||||
# Iterate through each `of` branch.
|
||||
for i in 1 .. <field.len:
|
||||
for i in 1 ..< field.len:
|
||||
case field[i].kind
|
||||
of nnkOfBranch:
|
||||
result.add processOfBranch(field[i], jsonNode, kindType, kindJsonNode)
|
||||
@@ -1640,7 +1640,7 @@ proc createConstructor(typeSym, jsonNode: NimNode): NimNode =
|
||||
(
|
||||
var list: `typeSym` = @[];
|
||||
verifyJsonKind(`jsonNode`, {JArray}, astToStr(`jsonNode`));
|
||||
for `forLoopI` in 0 .. <`jsonNode`.len: list.add(`constructorNode`);
|
||||
for `forLoopI` in 0 ..< `jsonNode`.len: list.add(`constructorNode`);
|
||||
list
|
||||
)
|
||||
of "array":
|
||||
@@ -1654,7 +1654,7 @@ proc createConstructor(typeSym, jsonNode: NimNode): NimNode =
|
||||
(
|
||||
var list: `typeSym`;
|
||||
verifyJsonKind(`jsonNode`, {JArray}, astToStr(`jsonNode`));
|
||||
for `forLoopI` in 0 .. <`jsonNode`.len: list[`forLoopI`] =`constructorNode`;
|
||||
for `forLoopI` in 0 ..< `jsonNode`.len: list[`forLoopI`] =`constructorNode`;
|
||||
list
|
||||
)
|
||||
|
||||
@@ -1683,7 +1683,7 @@ proc postProcessValue(value: NimNode): NimNode =
|
||||
result = postProcess(value)
|
||||
else:
|
||||
result = value
|
||||
for i in 0 .. <len(result):
|
||||
for i in 0 ..< len(result):
|
||||
result[i] = postProcessValue(result[i])
|
||||
|
||||
proc postProcessExprColonExpr(exprColonExpr, resIdent: NimNode): NimNode =
|
||||
|
||||
@@ -283,7 +283,7 @@ proc to*[T](data: string): T =
|
||||
loadAny(newStringStream(data), toAny(result), tab)
|
||||
|
||||
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]] = [
|
||||
["test", "1", "2", "3", "4"], ["test", "1", "2", "3", "4"],
|
||||
|
||||
@@ -162,7 +162,7 @@ elif defined(linux):
|
||||
return @[]
|
||||
raiseOSError(err)
|
||||
if evNum == 0: return @[]
|
||||
for i in 0 .. <evNum:
|
||||
for i in 0 ..< evNum:
|
||||
let fd = s.events[i].data.fd.SocketHandle
|
||||
|
||||
var evSet: set[Event] = {}
|
||||
@@ -253,7 +253,7 @@ elif defined(macosx) or defined(freebsd) or defined(openbsd) or defined(netbsd):
|
||||
return @[]
|
||||
raiseOSError(err)
|
||||
if evNum == 0: return @[]
|
||||
for i in 0 .. <evNum:
|
||||
for i in 0 ..< evNum:
|
||||
let fd = s.events[i].ident.SocketHandle
|
||||
|
||||
var evSet: set[Event] = {}
|
||||
|
||||
@@ -1199,7 +1199,7 @@ proc unindent*(s: string, count: Natural, padding: string = " "): string
|
||||
var indentCount = 0
|
||||
for j in 0..<count.int:
|
||||
indentCount.inc
|
||||
if line[j .. j + <padding.len] != padding:
|
||||
if line[j .. j + padding.len-1] != padding:
|
||||
indentCount = j
|
||||
break
|
||||
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.
|
||||
if sub.len > s.len:
|
||||
return -1
|
||||
|
||||
|
||||
if sub.len == 1:
|
||||
return find(s, sub[0], start, last)
|
||||
|
||||
|
||||
var a {.noinit.}: SkipTable
|
||||
initSkipTable(a, sub)
|
||||
result = find(a, s, sub, start, last)
|
||||
|
||||
@@ -250,7 +250,7 @@ proc combine*(base: Uri, reference: Uri): Uri =
|
||||
proc combine*(uris: varargs[Uri]): Uri =
|
||||
## Combines multiple URIs together.
|
||||
result = uris[0]
|
||||
for i in 1 .. <uris.len:
|
||||
for i in 1 ..< uris.len:
|
||||
result = combine(result, uris[i])
|
||||
|
||||
proc isAbsolute*(uri: Uri): bool =
|
||||
|
||||
@@ -127,7 +127,7 @@ proc fileMatches(c, bp: cstring): bool =
|
||||
|
||||
proc canonFilename*(filename: cstring): cstring =
|
||||
## returns 'nil' if the filename cannot be found.
|
||||
for i in 0 .. <dbgFilenameLen:
|
||||
for i in 0 ..< dbgFilenameLen:
|
||||
result = dbgFilenames[i]
|
||||
if fileMatches(result, filename): return result
|
||||
result = nil
|
||||
|
||||
@@ -643,9 +643,9 @@ when useMarkForDebug or useBackupGc:
|
||||
forAllChildren(d, waMarkPrecise)
|
||||
|
||||
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
|
||||
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:
|
||||
var
|
||||
@@ -653,7 +653,7 @@ when logGC:
|
||||
cycleCheckALen = 0
|
||||
|
||||
proc alreadySeen(c: PCell): bool =
|
||||
for i in 0 .. <cycleCheckALen:
|
||||
for i in 0 .. cycleCheckALen-1:
|
||||
if cycleCheckA[i] == c: return true
|
||||
if cycleCheckALen == len(cycleCheckA):
|
||||
gcAssert(false, "cycle detection overflow")
|
||||
|
||||
@@ -487,12 +487,12 @@ proc GC_dumpHeap*(file: File) =
|
||||
var spaceIter: ObjectSpaceIter
|
||||
when false:
|
||||
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]):
|
||||
c_fprintf(file, "onstack %p\n", d[i])
|
||||
else:
|
||||
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:
|
||||
let x = allObjectsAsProc(gch.region, addr spaceIter)
|
||||
if spaceIter.state < 0: break
|
||||
@@ -579,7 +579,7 @@ proc markIncremental(gch: var GcHeap): bool =
|
||||
result = true
|
||||
|
||||
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) =
|
||||
if p == nil: return
|
||||
|
||||
@@ -450,9 +450,9 @@ when false:
|
||||
quit 1
|
||||
|
||||
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
|
||||
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.} =
|
||||
# the addresses are not as cells on the stack, so turn them to cells:
|
||||
|
||||
@@ -41,7 +41,7 @@ proc `$`(x: uint64): string =
|
||||
|
||||
let half = i div 2
|
||||
# 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) =
|
||||
if cast[pointer](s) == nil:
|
||||
|
||||
@@ -50,7 +50,7 @@ proc reprChar(x: char): string {.compilerRtl.} =
|
||||
|
||||
proc reprStrAux(result: var string, s: cstring, len: int) =
|
||||
add(result, "\"")
|
||||
for i in 0 .. <len:
|
||||
for i in 0 ..< len:
|
||||
let c = s[i]
|
||||
case c
|
||||
of '"': add(result, "\\\"")
|
||||
@@ -149,7 +149,7 @@ proc reprArray(a: pointer, typ: PNimType,
|
||||
|
||||
{. emit: "`len` = `a`.length;\n" .}
|
||||
var dereffed: pointer = a
|
||||
for i in 0 .. < len:
|
||||
for i in 0 ..< len:
|
||||
if i > 0 :
|
||||
add(result, ", ")
|
||||
# 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)
|
||||
else:
|
||||
# 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
|
||||
else: add(result, ",\n")
|
||||
|
||||
|
||||
@@ -278,7 +278,7 @@ proc setLengthSeq(seq: PGenericSeq, elemSize, newLen: int): PGenericSeq {.
|
||||
GenericSeqSize +% (i*%elemSize)),
|
||||
extGetCellType(result).base, waPush)
|
||||
let len1 = gch.tempStack.len
|
||||
for i in len0 .. <len1:
|
||||
for i in len0 ..< len1:
|
||||
doDecRef(gch.tempStack.d[i], LocalHeap, MaybeCyclic)
|
||||
gch.tempStack.len = len0
|
||||
else:
|
||||
|
||||
@@ -593,7 +593,7 @@ from strutils import toHex, toLowerAscii
|
||||
proc hexStr(buf: cstring): string =
|
||||
# turn md5s output into a nice hex str
|
||||
result = newStringOfCap(32)
|
||||
for i in 0 .. <16:
|
||||
for i in 0 ..< 16:
|
||||
result.add toHex(buf[i].ord, 2).toLowerAscii
|
||||
|
||||
proc md5_File*(file: string): string {.raises: [IOError,Exception].} =
|
||||
|
||||
Reference in New Issue
Block a user