Skip to content

Commit 70ea45c

Browse files
committed
deprecated unary '<'
1 parent c17f6c7 commit 70ea45c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+259
-258
lines changed

changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@
2020
recursive types can be created across module boundaries. See
2121
[package level objects](https://nim-lang.org/docs/manual.html#package-level-objects)
2222
for more information.
23+
- The **unary** ``<`` is now deprecated, for ``.. <`` use ``..<`` for other usages
24+
use the ``pred`` proc.

compiler/ast.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1604,10 +1604,10 @@ proc hasPattern*(s: PSym): bool {.inline.} =
16041604
result = isRoutine(s) and s.ast.sons[patternPos].kind != nkEmpty
16051605

16061606
iterator items*(n: PNode): PNode =
1607-
for i in 0.. <n.safeLen: yield n.sons[i]
1607+
for i in 0..<n.safeLen: yield n.sons[i]
16081608

16091609
iterator pairs*(n: PNode): tuple[i: int, n: PNode] =
1610-
for i in 0.. <n.len: yield (i, n.sons[i])
1610+
for i in 0..<n.len: yield (i, n.sons[i])
16111611

16121612
proc isAtom*(n: PNode): bool {.inline.} =
16131613
result = n.kind >= nkNone and n.kind <= nkNilLit

compiler/canonicalizer.nim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ proc hashTree(c: var MD5Context, n: PNode) =
102102
of nkStrLit..nkTripleStrLit:
103103
c &= n.strVal
104104
else:
105-
for i in 0.. <n.len: hashTree(c, n.sons[i])
105+
for i in 0..<n.len: hashTree(c, n.sons[i])
106106

107107
proc hashType(c: var MD5Context, t: PType) =
108108
# modelled after 'typeToString'
@@ -151,13 +151,13 @@ proc hashType(c: var MD5Context, t: PType) =
151151
c.hashType(t.sons[0])
152152
of tyProc:
153153
c &= (if tfIterator in t.flags: "iterator " else: "proc ")
154-
for i in 0.. <t.len: c.hashType(t.sons[i])
154+
for i in 0..<t.len: c.hashType(t.sons[i])
155155
md5Update(c, cast[cstring](addr(t.callConv)), 1)
156156

157157
if tfNoSideEffect in t.flags: c &= ".noSideEffect"
158158
if tfThread in t.flags: c &= ".thread"
159159
else:
160-
for i in 0.. <t.len: c.hashType(t.sons[i])
160+
for i in 0..<t.len: c.hashType(t.sons[i])
161161
if tfNotNil in t.flags: c &= "not nil"
162162

163163
proc canonConst(n: PNode): TUid =

compiler/ccgcalls.nim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
proc leftAppearsOnRightSide(le, ri: PNode): bool =
1313
if le != nil:
14-
for i in 1 .. <ri.len:
14+
for i in 1 ..< ri.len:
1515
let r = ri[i]
1616
if isPartOf(le, r) != arNo: return true
1717

@@ -364,7 +364,7 @@ proc genPatternCall(p: BProc; ri: PNode; pat: string; typ: PType): Rope =
364364
of '@':
365365
if j < ri.len:
366366
result.add genOtherArg(p, ri, j, typ)
367-
for k in j+1 .. < ri.len:
367+
for k in j+1 ..< ri.len:
368368
result.add(~", ")
369369
result.add genOtherArg(p, ri, k, typ)
370370
inc i
@@ -377,7 +377,7 @@ proc genPatternCall(p: BProc; ri: PNode; pat: string; typ: PType): Rope =
377377
result.add(~"(")
378378
if 1 < ri.len:
379379
result.add genOtherArg(p, ri, 1, typ)
380-
for k in j+1 .. < ri.len:
380+
for k in j+1 ..< ri.len:
381381
result.add(~", ")
382382
result.add genOtherArg(p, ri, k, typ)
383383
result.add(~")")

compiler/ccgexprs.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ proc genOptAsgnTuple(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) =
228228
else:
229229
flags
230230
let t = skipTypes(dest.t, abstractInst).getUniqueType()
231-
for i in 0 .. <t.len:
231+
for i in 0 ..< t.len:
232232
let t = t.sons[i]
233233
let field = "Field$1" % [i.rope]
234234
genAssignment(p, optAsgnLoc(dest, t, field),
@@ -1218,7 +1218,7 @@ proc genObjConstr(p: BProc, e: PNode, d: var TLoc) =
12181218
constructLoc(p, tmp)
12191219
discard getTypeDesc(p.module, t)
12201220
let ty = getUniqueType(t)
1221-
for i in 1 .. <e.len:
1221+
for i in 1 ..< e.len:
12221222
let it = e.sons[i]
12231223
var tmp2: TLoc
12241224
tmp2.r = r

compiler/ccgstmts.nim

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ proc genSingleVar(p: BProc, a: PNode) =
235235
var params: Rope
236236
let typ = skipTypes(value.sons[0].typ, abstractInst)
237237
assert(typ.kind == tyProc)
238-
for i in 1.. <value.len:
238+
for i in 1..<value.len:
239239
if params != nil: params.add(~", ")
240240
assert(sonsLen(typ) == sonsLen(typ.n))
241241
add(params, genOtherArg(p, value, i, typ))
@@ -386,7 +386,7 @@ proc genReturnStmt(p: BProc, t: PNode) =
386386
lineF(p, cpsStmts, "goto BeforeRet_;$n", [])
387387

388388
proc genGotoForCase(p: BProc; caseStmt: PNode) =
389-
for i in 1 .. <caseStmt.len:
389+
for i in 1 ..< caseStmt.len:
390390
startBlock(p)
391391
let it = caseStmt.sons[i]
392392
for j in 0 .. it.len-2:
@@ -402,7 +402,7 @@ proc genComputedGoto(p: BProc; n: PNode) =
402402
# first pass: Generate array of computed labels:
403403
var casePos = -1
404404
var arraySize: int
405-
for i in 0 .. <n.len:
405+
for i in 0 ..< n.len:
406406
let it = n.sons[i]
407407
if it.kind == nkCaseStmt:
408408
if lastSon(it).kind != nkOfBranch:
@@ -432,7 +432,7 @@ proc genComputedGoto(p: BProc; n: PNode) =
432432
let oldBody = p.blocks[topBlock].sections[cpsStmts]
433433
p.blocks[topBlock].sections[cpsStmts] = nil
434434

435-
for j in casePos+1 .. <n.len: genStmts(p, n.sons[j])
435+
for j in casePos+1 ..< n.len: genStmts(p, n.sons[j])
436436
let tailB = p.blocks[topBlock].sections[cpsStmts]
437437

438438
p.blocks[topBlock].sections[cpsStmts] = nil
@@ -447,7 +447,7 @@ proc genComputedGoto(p: BProc; n: PNode) =
447447
# first goto:
448448
lineF(p, cpsStmts, "goto *$#[$#];$n", [tmp, a.rdLoc])
449449

450-
for i in 1 .. <caseStmt.len:
450+
for i in 1 ..< caseStmt.len:
451451
startBlock(p)
452452
let it = caseStmt.sons[i]
453453
for j in 0 .. it.len-2:
@@ -457,7 +457,7 @@ proc genComputedGoto(p: BProc; n: PNode) =
457457
let val = getOrdValue(it.sons[j])
458458
lineF(p, cpsStmts, "TMP$#_:$n", [intLiteral(val+id+1)])
459459
genStmts(p, it.lastSon)
460-
#for j in casePos+1 .. <n.len: genStmts(p, n.sons[j]) # tailB
460+
#for j in casePos+1 ..< n.len: genStmts(p, n.sons[j]) # tailB
461461
#for j in 0 .. casePos-1: genStmts(p, n.sons[j]) # tailA
462462
add(p.s(cpsStmts), tailB)
463463
add(p.s(cpsStmts), tailA)
@@ -744,7 +744,7 @@ proc genOrdinalCase(p: BProc, n: PNode, d: var TLoc) =
744744
if splitPoint+1 < n.len:
745745
lineF(p, cpsStmts, "switch ($1) {$n", [rdCharLoc(a)])
746746
var hasDefault = false
747-
for i in splitPoint+1 .. < n.len:
747+
for i in splitPoint+1 ..< n.len:
748748
# bug #4230: avoid false sharing between branches:
749749
if d.k == locTemp and isEmptyType(n.typ): d.k = locNone
750750
var branch = n[i]

compiler/ccgtypes.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ proc getTypeDescAux(m: BModule, origTyp: PType, check: var IntSet): Rope =
809809
var chunkStart = 0
810810
while i < cppName.data.len:
811811
if cppName.data[i] == '\'':
812-
var chunkEnd = <i
812+
var chunkEnd = i-1
813813
var idx, stars: int
814814
if scanCppGenericSlot(cppName.data, i, idx, stars):
815815
result.add cppName.data.substr(chunkStart, chunkEnd)

compiler/ccgutils.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ import
1616
proc getPragmaStmt*(n: PNode, w: TSpecialWord): PNode =
1717
case n.kind
1818
of nkStmtList:
19-
for i in 0 .. < n.len:
19+
for i in 0 ..< n.len:
2020
result = getPragmaStmt(n[i], w)
2121
if result != nil: break
2222
of nkPragma:
23-
for i in 0 .. < n.len:
23+
for i in 0 ..< n.len:
2424
if whichPragma(n[i]) == w: return n[i]
2525
else: discard
2626

compiler/cgen.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,7 @@ proc getFileHeader(cfile: Cfile): Rope =
920920
proc genFilenames(m: BModule): Rope =
921921
discard cgsym(m, "dbgRegisterFilename")
922922
result = nil
923-
for i in 0.. <fileInfos.len:
923+
for i in 0..<fileInfos.len:
924924
result.addf("dbgRegisterFilename($1);$N", [fileInfos[i].projPath.makeCString])
925925

926926
proc genMainProc(m: BModule) =

compiler/dfa.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ proc genCase(c: var Con; n: PNode) =
202202
# Lend:
203203
var endings: seq[TPosition] = @[]
204204
c.gen(n.sons[0])
205-
for i in 1 .. <n.len:
205+
for i in 1 ..< n.len:
206206
let it = n.sons[i]
207207
if it.len == 1:
208208
c.gen(it.sons[0])
@@ -219,7 +219,7 @@ proc genTry(c: var Con; n: PNode) =
219219
let elsePos = c.forkI(n)
220220
c.gen(n.sons[0])
221221
c.patch(elsePos)
222-
for i in 1 .. <n.len:
222+
for i in 1 ..< n.len:
223223
let it = n.sons[i]
224224
if it.kind != nkFinally:
225225
var blen = len(it)

compiler/docgen.nim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ proc getName(d: PDoc, n: PNode, splitAfter = -1): string =
252252
of nkIdent: result = esc(d.target, n.ident.s, splitAfter)
253253
of nkAccQuoted:
254254
result = esc(d.target, "`")
255-
for i in 0.. <n.len: result.add(getName(d, n[i], splitAfter))
255+
for i in 0..<n.len: result.add(getName(d, n[i], splitAfter))
256256
result.add esc(d.target, "`")
257257
of nkOpenSymChoice, nkClosedSymChoice:
258258
result = getName(d, n[0], splitAfter)
@@ -268,7 +268,7 @@ proc getNameIdent(n: PNode): PIdent =
268268
of nkIdent: result = n.ident
269269
of nkAccQuoted:
270270
var r = ""
271-
for i in 0.. <n.len: r.add(getNameIdent(n[i]).s)
271+
for i in 0..<n.len: r.add(getNameIdent(n[i]).s)
272272
result = getIdent(r)
273273
of nkOpenSymChoice, nkClosedSymChoice:
274274
result = getNameIdent(n[0])
@@ -283,7 +283,7 @@ proc getRstName(n: PNode): PRstNode =
283283
of nkIdent: result = newRstNode(rnLeaf, n.ident.s)
284284
of nkAccQuoted:
285285
result = getRstName(n.sons[0])
286-
for i in 1 .. <n.len: result.text.add(getRstName(n[i]).text)
286+
for i in 1 ..< n.len: result.text.add(getRstName(n[i]).text)
287287
of nkOpenSymChoice, nkClosedSymChoice:
288288
result = getRstName(n[0])
289289
else:

compiler/evalffi.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ proc pack(v: PNode, typ: PType, res: pointer) =
225225
awr(pointer, res +! sizeof(pointer))
226226
of tyArray:
227227
let baseSize = typ.sons[1].getSize
228-
for i in 0 .. <v.len:
228+
for i in 0 ..< v.len:
229229
pack(v.sons[i], typ.sons[1], res +! i * baseSize)
230230
of tyObject, tyTuple:
231231
packObject(v, typ, res)
@@ -291,7 +291,7 @@ proc unpackArray(x: pointer, typ: PType, n: PNode): PNode =
291291
if result.kind != nkBracket:
292292
globalError(n.info, "cannot map value from FFI")
293293
let baseSize = typ.sons[1].getSize
294-
for i in 0 .. < result.len:
294+
for i in 0 ..< result.len:
295295
result.sons[i] = unpack(x +! i * baseSize, typ.sons[1], result.sons[i])
296296

297297
proc canonNodeKind(k: TNodeKind): TNodeKind =

compiler/evaltempl.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ proc evalTemplateArgs(n: PNode, s: PSym; fromHlo: bool): PNode =
7777
# now that we have working untyped parameters.
7878
genericParams = if sfImmediate in s.flags or fromHlo: 0
7979
else: s.ast[genericParamsPos].len
80-
expectedRegularParams = <s.typ.len
80+
expectedRegularParams = s.typ.len-1
8181
givenRegularParams = totalParams - genericParams
8282
if givenRegularParams < 0: givenRegularParams = 0
8383

compiler/forloops.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ proc counterInTree(n, loop: PNode; counter: PSym): bool =
4545
for it in n:
4646
if counterInTree(it.lastSon): return true
4747
else:
48-
for i in 0 .. <safeLen(n):
48+
for i in 0 ..< safeLen(n):
4949
if counterInTree(n[i], loop, counter): return true
5050

5151
proc copyExcept(n: PNode, x, dest: PNode) =
5252
if x == n: return
5353
if n.kind in {nkStmtList, nkStmtListExpr}:
54-
for i in 0 .. <n.len: copyExcept(n[i], x, dest)
54+
for i in 0 ..< n.len: copyExcept(n[i], x, dest)
5555
else:
5656
dest.add n
5757

compiler/guards.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ proc canon*(n: PNode): PNode =
247247
# XXX for now only the new code in 'semparallel' uses this
248248
if n.safeLen >= 1:
249249
result = shallowCopy(n)
250-
for i in 0 .. < n.len:
250+
for i in 0 ..< n.len:
251251
result.sons[i] = canon(n.sons[i])
252252
elif n.kind == nkSym and n.sym.kind == skLet and
253253
n.sym.ast.getMagic in (someEq + someAdd + someMul + someMin +

compiler/hlo.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ proc applyPatterns(c: PContext, n: PNode): PNode =
3636
# we apply the last pattern first, so that pattern overriding is possible;
3737
# however the resulting AST would better not trigger the old rule then
3838
# anymore ;-)
39-
for i in countdown(<c.patterns.len, 0):
39+
for i in countdown(c.patterns.len-1, 0):
4040
let pattern = c.patterns[i]
4141
if not isNil(pattern):
4242
let x = applyRule(c, pattern, result)
@@ -75,7 +75,7 @@ proc hlo(c: PContext, n: PNode): PNode =
7575
result = applyPatterns(c, n)
7676
if result == n:
7777
# no optimization applied, try subtrees:
78-
for i in 0 .. < safeLen(result):
78+
for i in 0 ..< safeLen(result):
7979
let a = result.sons[i]
8080
let h = hlo(c, a)
8181
if h != a: result.sons[i] = h

compiler/jsgen.nim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,7 +1363,7 @@ proc genPatternCall(p: PProc; n: PNode; pat: string; typ: PType;
13631363
case pat[i]
13641364
of '@':
13651365
var generated = 0
1366-
for k in j .. < n.len:
1366+
for k in j ..< n.len:
13671367
if generated > 0: add(r.res, ", ")
13681368
genOtherArg(p, n, k, typ, generated, r)
13691369
inc i
@@ -1528,15 +1528,15 @@ proc createVar(p: PProc, typ: PType, indirect: bool): Rope =
15281528
of tyTuple:
15291529
if p.target == targetJS:
15301530
result = rope("{")
1531-
for i in 0.. <t.sonsLen:
1531+
for i in 0..<t.sonsLen:
15321532
if i > 0: add(result, ", ")
15331533
addf(result, "Field$1: $2", [i.rope,
15341534
createVar(p, t.sons[i], false)])
15351535
add(result, "}")
15361536
if indirect: result = "[$1]" % [result]
15371537
else:
15381538
result = rope("array(")
1539-
for i in 0.. <t.sonsLen:
1539+
for i in 0..<t.sonsLen:
15401540
if i > 0: add(result, ", ")
15411541
add(result, createVar(p, t.sons[i], false))
15421542
add(result, ")")

compiler/jstypes.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ proc genObjectInfo(p: PProc, typ: PType, name: Rope) =
8484

8585
proc genTupleFields(p: PProc, typ: PType): Rope =
8686
var s: Rope = nil
87-
for i in 0 .. <typ.len:
87+
for i in 0 ..< typ.len:
8888
if i > 0: add(s, ", " & tnl)
8989
s.addf("{kind: 1, offset: \"Field$1\", len: 0, " &
9090
"typ: $2, name: \"Field$1\", sons: null}",

compiler/lexer.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ proc getEscapedChar(L: var TLexer, tok: var TToken) =
693693
proc newString(s: cstring, len: int): string =
694694
## XXX, how come there is no support for this?
695695
result = newString(len)
696-
for i in 0 .. <len:
696+
for i in 0 ..< len:
697697
result[i] = s[i]
698698

699699
proc handleCRLF(L: var TLexer, pos: int): int =

compiler/lookups.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ proc considerQuotedIdent*(n: PNode, origin: PNode = nil): PIdent =
3939
of 1: result = considerQuotedIdent(n.sons[0], origin)
4040
else:
4141
var id = ""
42-
for i in 0.. <n.len:
42+
for i in 0..<n.len:
4343
let x = n.sons[i]
4444
case x.kind
4545
of nkIdent: id.add(x.ident.s)

compiler/lowerings.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ proc setupArgsForConcurrency(n: PNode; objType: PType; scratchObj: PSym,
463463
varSection, varInit, result: PNode) =
464464
let formals = n[0].typ.n
465465
let tmpName = getIdent(genPrefix)
466-
for i in 1 .. <n.len:
466+
for i in 1 ..< n.len:
467467
# we pick n's type here, which hopefully is 'tyArray' and not
468468
# 'tyOpenArray':
469469
var argType = n[i].typ.skipTypes(abstractInst)
@@ -519,7 +519,7 @@ proc setupArgsForParallelism(n: PNode; objType: PType; scratchObj: PSym;
519519
let tmpName = getIdent(genPrefix)
520520
# we need to copy the foreign scratch object fields into local variables
521521
# for correctness: These are called 'threadLocal' here.
522-
for i in 1 .. <n.len:
522+
for i in 1 ..< n.len:
523523
let n = n[i]
524524
let argType = skipTypes(if i < formals.len: formals[i].typ else: n.typ,
525525
abstractInst)

compiler/parampatterns.nim

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ proc semNodeKindConstraints*(p: PNode): PNode =
122122
result.strVal = newStringOfCap(10)
123123
result.strVal.add(chr(aqNone.ord))
124124
if p.len >= 2:
125-
for i in 1.. <p.len:
125+
for i in 1..<p.len:
126126
compileConstraints(p.sons[i], result.strVal)
127127
if result.strVal.len > MaxStackSize-1:
128128
internalError(p.info, "parameter pattern too complex")
@@ -152,7 +152,7 @@ proc checkForSideEffects*(n: PNode): TSideEffectAnalysis =
152152
# indirect call: assume side effect:
153153
return seSideEffect
154154
# we need to check n[0] too: (FwithSideEffectButReturnsProcWithout)(args)
155-
for i in 0 .. <n.len:
155+
for i in 0 ..< n.len:
156156
let ret = checkForSideEffects(n.sons[i])
157157
if ret == seSideEffect: return ret
158158
elif ret == seUnknown and result == seNoSideEffect:
@@ -163,7 +163,7 @@ proc checkForSideEffects*(n: PNode): TSideEffectAnalysis =
163163
else:
164164
# assume no side effect:
165165
result = seNoSideEffect
166-
for i in 0 .. <n.len:
166+
for i in 0 ..< n.len:
167167
let ret = checkForSideEffects(n.sons[i])
168168
if ret == seSideEffect: return ret
169169
elif ret == seUnknown and result == seNoSideEffect:

0 commit comments

Comments
 (0)