deprecated unary '<'

This commit is contained in:
Andreas Rumpf
2017-10-29 08:37:13 +01:00
parent c17f6c7837
commit 70ea45cdba
56 changed files with 259 additions and 258 deletions

View File

@@ -20,3 +20,5 @@
recursive types can be created across module boundaries. See
[package level objects](https://nim-lang.org/docs/manual.html#package-level-objects)
for more information.
- The **unary** ``<`` is now deprecated, for ``.. <`` use ``..<`` for other usages
use the ``pred`` proc.

View File

@@ -1604,10 +1604,10 @@ proc hasPattern*(s: PSym): bool {.inline.} =
result = isRoutine(s) and s.ast.sons[patternPos].kind != nkEmpty
iterator items*(n: PNode): PNode =
for i in 0.. <n.safeLen: yield n.sons[i]
for i in 0..<n.safeLen: yield n.sons[i]
iterator pairs*(n: PNode): tuple[i: int, n: PNode] =
for i in 0.. <n.len: yield (i, n.sons[i])
for i in 0..<n.len: yield (i, n.sons[i])
proc isAtom*(n: PNode): bool {.inline.} =
result = n.kind >= nkNone and n.kind <= nkNilLit

View File

@@ -102,7 +102,7 @@ proc hashTree(c: var MD5Context, n: PNode) =
of nkStrLit..nkTripleStrLit:
c &= n.strVal
else:
for i in 0.. <n.len: hashTree(c, n.sons[i])
for i in 0..<n.len: hashTree(c, n.sons[i])
proc hashType(c: var MD5Context, t: PType) =
# modelled after 'typeToString'
@@ -151,13 +151,13 @@ proc hashType(c: var MD5Context, t: PType) =
c.hashType(t.sons[0])
of tyProc:
c &= (if tfIterator in t.flags: "iterator " else: "proc ")
for i in 0.. <t.len: c.hashType(t.sons[i])
for i in 0..<t.len: c.hashType(t.sons[i])
md5Update(c, cast[cstring](addr(t.callConv)), 1)
if tfNoSideEffect in t.flags: c &= ".noSideEffect"
if tfThread in t.flags: c &= ".thread"
else:
for i in 0.. <t.len: c.hashType(t.sons[i])
for i in 0..<t.len: c.hashType(t.sons[i])
if tfNotNil in t.flags: c &= "not nil"
proc canonConst(n: PNode): TUid =

View File

@@ -11,7 +11,7 @@
proc leftAppearsOnRightSide(le, ri: PNode): bool =
if le != nil:
for i in 1 .. <ri.len:
for i in 1 ..< ri.len:
let r = ri[i]
if isPartOf(le, r) != arNo: return true
@@ -364,7 +364,7 @@ proc genPatternCall(p: BProc; ri: PNode; pat: string; typ: PType): Rope =
of '@':
if j < ri.len:
result.add genOtherArg(p, ri, j, typ)
for k in j+1 .. < ri.len:
for k in j+1 ..< ri.len:
result.add(~", ")
result.add genOtherArg(p, ri, k, typ)
inc i
@@ -377,7 +377,7 @@ proc genPatternCall(p: BProc; ri: PNode; pat: string; typ: PType): Rope =
result.add(~"(")
if 1 < ri.len:
result.add genOtherArg(p, ri, 1, typ)
for k in j+1 .. < ri.len:
for k in j+1 ..< ri.len:
result.add(~", ")
result.add genOtherArg(p, ri, k, typ)
result.add(~")")

View File

@@ -228,7 +228,7 @@ proc genOptAsgnTuple(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) =
else:
flags
let t = skipTypes(dest.t, abstractInst).getUniqueType()
for i in 0 .. <t.len:
for i in 0 ..< t.len:
let t = t.sons[i]
let field = "Field$1" % [i.rope]
genAssignment(p, optAsgnLoc(dest, t, field),
@@ -1218,7 +1218,7 @@ proc genObjConstr(p: BProc, e: PNode, d: var TLoc) =
constructLoc(p, tmp)
discard getTypeDesc(p.module, t)
let ty = getUniqueType(t)
for i in 1 .. <e.len:
for i in 1 ..< e.len:
let it = e.sons[i]
var tmp2: TLoc
tmp2.r = r

View File

@@ -235,7 +235,7 @@ proc genSingleVar(p: BProc, a: PNode) =
var params: Rope
let typ = skipTypes(value.sons[0].typ, abstractInst)
assert(typ.kind == tyProc)
for i in 1.. <value.len:
for i in 1..<value.len:
if params != nil: params.add(~", ")
assert(sonsLen(typ) == sonsLen(typ.n))
add(params, genOtherArg(p, value, i, typ))
@@ -386,7 +386,7 @@ proc genReturnStmt(p: BProc, t: PNode) =
lineF(p, cpsStmts, "goto BeforeRet_;$n", [])
proc genGotoForCase(p: BProc; caseStmt: PNode) =
for i in 1 .. <caseStmt.len:
for i in 1 ..< caseStmt.len:
startBlock(p)
let it = caseStmt.sons[i]
for j in 0 .. it.len-2:
@@ -402,7 +402,7 @@ proc genComputedGoto(p: BProc; n: PNode) =
# first pass: Generate array of computed labels:
var casePos = -1
var arraySize: int
for i in 0 .. <n.len:
for i in 0 ..< n.len:
let it = n.sons[i]
if it.kind == nkCaseStmt:
if lastSon(it).kind != nkOfBranch:
@@ -432,7 +432,7 @@ proc genComputedGoto(p: BProc; n: PNode) =
let oldBody = p.blocks[topBlock].sections[cpsStmts]
p.blocks[topBlock].sections[cpsStmts] = nil
for j in casePos+1 .. <n.len: genStmts(p, n.sons[j])
for j in casePos+1 ..< n.len: genStmts(p, n.sons[j])
let tailB = p.blocks[topBlock].sections[cpsStmts]
p.blocks[topBlock].sections[cpsStmts] = nil
@@ -447,7 +447,7 @@ proc genComputedGoto(p: BProc; n: PNode) =
# first goto:
lineF(p, cpsStmts, "goto *$#[$#];$n", [tmp, a.rdLoc])
for i in 1 .. <caseStmt.len:
for i in 1 ..< caseStmt.len:
startBlock(p)
let it = caseStmt.sons[i]
for j in 0 .. it.len-2:
@@ -457,7 +457,7 @@ proc genComputedGoto(p: BProc; n: PNode) =
let val = getOrdValue(it.sons[j])
lineF(p, cpsStmts, "TMP$#_:$n", [intLiteral(val+id+1)])
genStmts(p, it.lastSon)
#for j in casePos+1 .. <n.len: genStmts(p, n.sons[j]) # tailB
#for j in casePos+1 ..< n.len: genStmts(p, n.sons[j]) # tailB
#for j in 0 .. casePos-1: genStmts(p, n.sons[j]) # tailA
add(p.s(cpsStmts), tailB)
add(p.s(cpsStmts), tailA)
@@ -744,7 +744,7 @@ proc genOrdinalCase(p: BProc, n: PNode, d: var TLoc) =
if splitPoint+1 < n.len:
lineF(p, cpsStmts, "switch ($1) {$n", [rdCharLoc(a)])
var hasDefault = false
for i in splitPoint+1 .. < n.len:
for i in splitPoint+1 ..< n.len:
# bug #4230: avoid false sharing between branches:
if d.k == locTemp and isEmptyType(n.typ): d.k = locNone
var branch = n[i]

View File

@@ -809,7 +809,7 @@ proc getTypeDescAux(m: BModule, origTyp: PType, check: var IntSet): Rope =
var chunkStart = 0
while i < cppName.data.len:
if cppName.data[i] == '\'':
var chunkEnd = <i
var chunkEnd = i-1
var idx, stars: int
if scanCppGenericSlot(cppName.data, i, idx, stars):
result.add cppName.data.substr(chunkStart, chunkEnd)

View File

@@ -16,11 +16,11 @@ import
proc getPragmaStmt*(n: PNode, w: TSpecialWord): PNode =
case n.kind
of nkStmtList:
for i in 0 .. < n.len:
for i in 0 ..< n.len:
result = getPragmaStmt(n[i], w)
if result != nil: break
of nkPragma:
for i in 0 .. < n.len:
for i in 0 ..< n.len:
if whichPragma(n[i]) == w: return n[i]
else: discard

View File

@@ -920,7 +920,7 @@ proc getFileHeader(cfile: Cfile): Rope =
proc genFilenames(m: BModule): Rope =
discard cgsym(m, "dbgRegisterFilename")
result = nil
for i in 0.. <fileInfos.len:
for i in 0..<fileInfos.len:
result.addf("dbgRegisterFilename($1);$N", [fileInfos[i].projPath.makeCString])
proc genMainProc(m: BModule) =

View File

@@ -202,7 +202,7 @@ proc genCase(c: var Con; n: PNode) =
# Lend:
var endings: seq[TPosition] = @[]
c.gen(n.sons[0])
for i in 1 .. <n.len:
for i in 1 ..< n.len:
let it = n.sons[i]
if it.len == 1:
c.gen(it.sons[0])
@@ -219,7 +219,7 @@ proc genTry(c: var Con; n: PNode) =
let elsePos = c.forkI(n)
c.gen(n.sons[0])
c.patch(elsePos)
for i in 1 .. <n.len:
for i in 1 ..< n.len:
let it = n.sons[i]
if it.kind != nkFinally:
var blen = len(it)

View File

@@ -252,7 +252,7 @@ proc getName(d: PDoc, n: PNode, splitAfter = -1): string =
of nkIdent: result = esc(d.target, n.ident.s, splitAfter)
of nkAccQuoted:
result = esc(d.target, "`")
for i in 0.. <n.len: result.add(getName(d, n[i], splitAfter))
for i in 0..<n.len: result.add(getName(d, n[i], splitAfter))
result.add esc(d.target, "`")
of nkOpenSymChoice, nkClosedSymChoice:
result = getName(d, n[0], splitAfter)
@@ -268,7 +268,7 @@ proc getNameIdent(n: PNode): PIdent =
of nkIdent: result = n.ident
of nkAccQuoted:
var r = ""
for i in 0.. <n.len: r.add(getNameIdent(n[i]).s)
for i in 0..<n.len: r.add(getNameIdent(n[i]).s)
result = getIdent(r)
of nkOpenSymChoice, nkClosedSymChoice:
result = getNameIdent(n[0])
@@ -283,7 +283,7 @@ proc getRstName(n: PNode): PRstNode =
of nkIdent: result = newRstNode(rnLeaf, n.ident.s)
of nkAccQuoted:
result = getRstName(n.sons[0])
for i in 1 .. <n.len: result.text.add(getRstName(n[i]).text)
for i in 1 ..< n.len: result.text.add(getRstName(n[i]).text)
of nkOpenSymChoice, nkClosedSymChoice:
result = getRstName(n[0])
else:

View File

@@ -225,7 +225,7 @@ proc pack(v: PNode, typ: PType, res: pointer) =
awr(pointer, res +! sizeof(pointer))
of tyArray:
let baseSize = typ.sons[1].getSize
for i in 0 .. <v.len:
for i in 0 ..< v.len:
pack(v.sons[i], typ.sons[1], res +! i * baseSize)
of tyObject, tyTuple:
packObject(v, typ, res)
@@ -291,7 +291,7 @@ proc unpackArray(x: pointer, typ: PType, n: PNode): PNode =
if result.kind != nkBracket:
globalError(n.info, "cannot map value from FFI")
let baseSize = typ.sons[1].getSize
for i in 0 .. < result.len:
for i in 0 ..< result.len:
result.sons[i] = unpack(x +! i * baseSize, typ.sons[1], result.sons[i])
proc canonNodeKind(k: TNodeKind): TNodeKind =

View File

@@ -77,7 +77,7 @@ proc evalTemplateArgs(n: PNode, s: PSym; fromHlo: bool): PNode =
# now that we have working untyped parameters.
genericParams = if sfImmediate in s.flags or fromHlo: 0
else: s.ast[genericParamsPos].len
expectedRegularParams = <s.typ.len
expectedRegularParams = s.typ.len-1
givenRegularParams = totalParams - genericParams
if givenRegularParams < 0: givenRegularParams = 0

View File

@@ -45,13 +45,13 @@ proc counterInTree(n, loop: PNode; counter: PSym): bool =
for it in n:
if counterInTree(it.lastSon): return true
else:
for i in 0 .. <safeLen(n):
for i in 0 ..< safeLen(n):
if counterInTree(n[i], loop, counter): return true
proc copyExcept(n: PNode, x, dest: PNode) =
if x == n: return
if n.kind in {nkStmtList, nkStmtListExpr}:
for i in 0 .. <n.len: copyExcept(n[i], x, dest)
for i in 0 ..< n.len: copyExcept(n[i], x, dest)
else:
dest.add n

View File

@@ -247,7 +247,7 @@ proc canon*(n: PNode): PNode =
# XXX for now only the new code in 'semparallel' uses this
if n.safeLen >= 1:
result = shallowCopy(n)
for i in 0 .. < n.len:
for i in 0 ..< n.len:
result.sons[i] = canon(n.sons[i])
elif n.kind == nkSym and n.sym.kind == skLet and
n.sym.ast.getMagic in (someEq + someAdd + someMul + someMin +

View File

@@ -36,7 +36,7 @@ proc applyPatterns(c: PContext, n: PNode): PNode =
# we apply the last pattern first, so that pattern overriding is possible;
# however the resulting AST would better not trigger the old rule then
# anymore ;-)
for i in countdown(<c.patterns.len, 0):
for i in countdown(c.patterns.len-1, 0):
let pattern = c.patterns[i]
if not isNil(pattern):
let x = applyRule(c, pattern, result)
@@ -75,7 +75,7 @@ proc hlo(c: PContext, n: PNode): PNode =
result = applyPatterns(c, n)
if result == n:
# no optimization applied, try subtrees:
for i in 0 .. < safeLen(result):
for i in 0 ..< safeLen(result):
let a = result.sons[i]
let h = hlo(c, a)
if h != a: result.sons[i] = h

View File

@@ -1363,7 +1363,7 @@ proc genPatternCall(p: PProc; n: PNode; pat: string; typ: PType;
case pat[i]
of '@':
var generated = 0
for k in j .. < n.len:
for k in j ..< n.len:
if generated > 0: add(r.res, ", ")
genOtherArg(p, n, k, typ, generated, r)
inc i
@@ -1528,7 +1528,7 @@ proc createVar(p: PProc, typ: PType, indirect: bool): Rope =
of tyTuple:
if p.target == targetJS:
result = rope("{")
for i in 0.. <t.sonsLen:
for i in 0..<t.sonsLen:
if i > 0: add(result, ", ")
addf(result, "Field$1: $2", [i.rope,
createVar(p, t.sons[i], false)])
@@ -1536,7 +1536,7 @@ proc createVar(p: PProc, typ: PType, indirect: bool): Rope =
if indirect: result = "[$1]" % [result]
else:
result = rope("array(")
for i in 0.. <t.sonsLen:
for i in 0..<t.sonsLen:
if i > 0: add(result, ", ")
add(result, createVar(p, t.sons[i], false))
add(result, ")")

View File

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

View File

@@ -693,7 +693,7 @@ proc getEscapedChar(L: var TLexer, tok: var TToken) =
proc newString(s: cstring, len: int): string =
## XXX, how come there is no support for this?
result = newString(len)
for i in 0 .. <len:
for i in 0 ..< len:
result[i] = s[i]
proc handleCRLF(L: var TLexer, pos: int): int =

View File

@@ -39,7 +39,7 @@ proc considerQuotedIdent*(n: PNode, origin: PNode = nil): PIdent =
of 1: result = considerQuotedIdent(n.sons[0], origin)
else:
var id = ""
for i in 0.. <n.len:
for i in 0..<n.len:
let x = n.sons[i]
case x.kind
of nkIdent: id.add(x.ident.s)

View File

@@ -463,7 +463,7 @@ proc setupArgsForConcurrency(n: PNode; objType: PType; scratchObj: PSym,
varSection, varInit, result: PNode) =
let formals = n[0].typ.n
let tmpName = getIdent(genPrefix)
for i in 1 .. <n.len:
for i in 1 ..< n.len:
# we pick n's type here, which hopefully is 'tyArray' and not
# 'tyOpenArray':
var argType = n[i].typ.skipTypes(abstractInst)
@@ -519,7 +519,7 @@ proc setupArgsForParallelism(n: PNode; objType: PType; scratchObj: PSym;
let tmpName = getIdent(genPrefix)
# we need to copy the foreign scratch object fields into local variables
# for correctness: These are called 'threadLocal' here.
for i in 1 .. <n.len:
for i in 1 ..< n.len:
let n = n[i]
let argType = skipTypes(if i < formals.len: formals[i].typ else: n.typ,
abstractInst)

View File

@@ -122,7 +122,7 @@ proc semNodeKindConstraints*(p: PNode): PNode =
result.strVal = newStringOfCap(10)
result.strVal.add(chr(aqNone.ord))
if p.len >= 2:
for i in 1.. <p.len:
for i in 1..<p.len:
compileConstraints(p.sons[i], result.strVal)
if result.strVal.len > MaxStackSize-1:
internalError(p.info, "parameter pattern too complex")
@@ -152,7 +152,7 @@ proc checkForSideEffects*(n: PNode): TSideEffectAnalysis =
# indirect call: assume side effect:
return seSideEffect
# we need to check n[0] too: (FwithSideEffectButReturnsProcWithout)(args)
for i in 0 .. <n.len:
for i in 0 ..< n.len:
let ret = checkForSideEffects(n.sons[i])
if ret == seSideEffect: return ret
elif ret == seUnknown and result == seNoSideEffect:
@@ -163,7 +163,7 @@ proc checkForSideEffects*(n: PNode): TSideEffectAnalysis =
else:
# assume no side effect:
result = seNoSideEffect
for i in 0 .. <n.len:
for i in 0 ..< n.len:
let ret = checkForSideEffects(n.sons[i])
if ret == seSideEffect: return ret
elif ret == seUnknown and result == seNoSideEffect:

View File

@@ -63,7 +63,7 @@ proc sameTrees(a, b: PNode): bool =
proc inSymChoice(sc, x: PNode): bool =
if sc.kind == nkClosedSymChoice:
for i in 0.. <sc.len:
for i in 0..<sc.len:
if sc.sons[i].sym == x.sym: return true
elif sc.kind == nkOpenSymChoice:
# same name suffices for open sym choices!
@@ -83,7 +83,7 @@ proc isPatternParam(c: PPatternContext, p: PNode): bool {.inline.} =
result = p.kind == nkSym and p.sym.kind == skParam and p.sym.owner == c.owner
proc matchChoice(c: PPatternContext, p, n: PNode): bool =
for i in 1 .. <p.len:
for i in 1 ..< p.len:
if matches(c, p.sons[i], n): return true
proc bindOrCheck(c: PPatternContext, param: PSym, n: PNode): bool =
@@ -115,7 +115,7 @@ proc matchNested(c: PPatternContext, p, n: PNode, rpn: bool): bool =
if rpn: arglist.add(n.sons[0])
elif n.kind == nkHiddenStdConv and n.sons[1].kind == nkBracket:
let n = n.sons[1]
for i in 0.. <n.len:
for i in 0..<n.len:
if not matchStarAux(c, op, n[i], arglist, rpn): return false
elif checkTypes(c, p.sons[2].sym, n):
add(arglist, n)
@@ -186,7 +186,7 @@ proc matches(c: PPatternContext, p, n: PNode): bool =
# unpack varargs:
let n = lastSon(n).sons[1]
arglist = newNodeI(nkArgList, n.info, n.len)
for i in 0.. <n.len: arglist.sons[i] = n.sons[i]
for i in 0..<n.len: arglist.sons[i] = n.sons[i]
else:
arglist = newNodeI(nkArgList, n.info, sonsLen(n) - plen + 1)
# f(1, 2, 3)
@@ -206,7 +206,7 @@ proc matches(c: PPatternContext, p, n: PNode): bool =
proc matchStmtList(c: PPatternContext, p, n: PNode): PNode =
proc matchRange(c: PPatternContext, p, n: PNode, i: int): bool =
for j in 0 .. <p.len:
for j in 0 ..< p.len:
if not matches(c, p.sons[j], n.sons[i+j]):
# we need to undo any bindings:
if not isNil(c.mapping): c.mapping = nil
@@ -229,7 +229,7 @@ proc matchStmtList(c: PPatternContext, p, n: PNode): PNode =
proc aliasAnalysisRequested(params: PNode): bool =
if params.len >= 2:
for i in 1 .. < params.len:
for i in 1 ..< params.len:
let param = params.sons[i].sym
if whichAlias(param) != aqNone: return true
@@ -237,7 +237,7 @@ proc addToArgList(result, n: PNode) =
if n.typ != nil and n.typ.kind != tyStmt:
if n.kind != nkArgList: result.add(n)
else:
for i in 0 .. <n.len: result.add(n.sons[i])
for i in 0 ..< n.len: result.add(n.sons[i])
proc applyRule*(c: PContext, s: PSym, n: PNode): PNode =
## returns a tree to semcheck if the rule triggered; nil otherwise
@@ -256,7 +256,7 @@ proc applyRule*(c: PContext, s: PSym, n: PNode): PNode =
var args: PNode
if requiresAA:
args = newNodeI(nkArgList, n.info)
for i in 1 .. < params.len:
for i in 1 ..< params.len:
let param = params.sons[i].sym
let x = getLazy(ctx, param)
# couldn't bind parameter:
@@ -265,7 +265,7 @@ proc applyRule*(c: PContext, s: PSym, n: PNode): PNode =
if requiresAA: addToArgList(args, x)
# perform alias analysis here:
if requiresAA:
for i in 1 .. < params.len:
for i in 1 ..< params.len:
var rs = result.sons[i]
let param = params.sons[i].sym
case whichAlias(param)

View File

@@ -575,7 +575,7 @@ proc pragmaLockStmt(c: PContext; it: PNode) =
if n.kind != nkBracket:
localError(n.info, errGenerated, "locks pragma takes a list of expressions")
else:
for i in 0 .. <n.len:
for i in 0 ..< n.len:
n.sons[i] = c.semExpr(c, n.sons[i])
proc pragmaLocks(c: PContext, it: PNode): TLockLevel =

View File

@@ -1076,7 +1076,7 @@ proc gsub(g: var TSrcGen, n: PNode, c: TContext) =
of nkAccQuoted:
put(g, tkAccent, "`")
if n.len > 0: gsub(g, n.sons[0])
for i in 1 .. <n.len:
for i in 1 ..< n.len:
put(g, tkSpaces, Space)
gsub(g, n.sons[i])
put(g, tkAccent, "`")

View File

@@ -34,7 +34,7 @@ proc newDepN(id: int, pnode: PNode): DepN =
proc accQuoted(n: PNode): PIdent =
var id = ""
for i in 0 .. <n.len:
for i in 0 ..< n.len:
let x = n[i]
case x.kind
of nkIdent: id.add(x.ident.s)

View File

@@ -795,7 +795,7 @@ proc getReader(moduleId: int): PRodReader =
# the module ID! We could introduce a mapping ID->PRodReader but I'll leave
# this for later versions if benchmarking shows the linear search causes
# problems:
for i in 0 .. <gMods.len:
for i in 0 ..< gMods.len:
result = gMods[i].rd
if result != nil and result.moduleID == moduleId: return result
return nil

View File

@@ -122,7 +122,7 @@ proc commonType*(x, y: PType): PType =
if a.sons[idx].kind == tyEmpty: return y
elif a.kind == tyTuple and b.kind == tyTuple and a.len == b.len:
var nt: PType
for i in 0.. <a.len:
for i in 0..<a.len:
let aEmpty = isEmptyContainer(a.sons[i])
let bEmpty = isEmptyContainer(b.sons[i])
if aEmpty != bEmpty:

View File

@@ -32,7 +32,7 @@ proc at(a, i: PNode, elemType: PType): PNode =
result.typ = elemType
proc liftBodyTup(c: var TLiftCtx; t: PType; body, x, y: PNode) =
for i in 0 .. <t.len:
for i in 0 ..< t.len:
let lit = lowerings.newIntLit(i)
liftBodyAux(c, t.sons[i], body, x.at(lit, t.sons[i]), y.at(lit, t.sons[i]))
@@ -58,7 +58,7 @@ proc liftBodyObj(c: var TLiftCtx; n, body, x, y: PNode) =
var access = dotField(x, n[0].sym)
caseStmt.add(access)
# copy the branches over, but replace the fields with the for loop body:
for i in 1 .. <n.len:
for i in 1 ..< n.len:
var branch = copyTree(n[i])
let L = branch.len
branch.sons[L-1] = newNodeI(nkStmtList, c.info)
@@ -297,7 +297,7 @@ proc liftBody(c: PContext; typ: PType; kind: TTypeAttachedOp;
of attachedDestructor: typ.destructor = result
var n = newNodeI(nkProcDef, info, bodyPos+1)
for i in 0 .. < n.len: n.sons[i] = emptyNode
for i in 0 ..< n.len: n.sons[i] = emptyNode
n.sons[namePos] = newSymNode(result)
n.sons[paramsPos] = result.typ.n
n.sons[bodyPos] = body

View File

@@ -310,7 +310,7 @@ proc instGenericConvertersArg*(c: PContext, a: PNode, x: TCandidate) =
proc instGenericConvertersSons*(c: PContext, n: PNode, x: TCandidate) =
assert n.kind in nkCallKinds
if x.genericConverter:
for i in 1 .. <n.len:
for i in 1 ..< n.len:
instGenericConvertersArg(c, n.sons[i], x)
proc indexTypesMatch(c: PContext, f, a: PType, arg: PNode): PNode =
@@ -494,7 +494,7 @@ proc searchForBorrowProc(c: PContext, startScope: PScope, fn: PSym): PSym =
var call = newNodeI(nkCall, fn.info)
var hasDistinct = false
call.add(newIdentNode(fn.name, fn.info))
for i in 1.. <fn.typ.n.len:
for i in 1..<fn.typ.n.len:
let param = fn.typ.n.sons[i]
let t = skipTypes(param.typ, abstractVar-{tyTypeDesc, tyDistinct})
if t.kind == tyDistinct or param.typ.kind == tyDistinct: hasDistinct = true

View File

@@ -30,7 +30,7 @@ proc instantiateDestructor(c: PContext, typ: PType): PType
proc doDestructorStuff(c: PContext, s: PSym, n: PNode) =
var t = s.typ.sons[1].skipTypes({tyVar})
if t.kind == tyGenericInvocation:
for i in 1 .. <t.sonsLen:
for i in 1 ..< t.sonsLen:
if t.sons[i].kind != tyGenericParam:
localError(n.info, errDestructorNotGenericEnough)
return

View File

@@ -436,12 +436,12 @@ proc semArrayConstr(c: PContext, n: PNode, flags: TExprFlags): PNode =
#addSon(result, fitNode(c, typ, n.sons[i]))
inc(lastIndex)
addSonSkipIntLit(result.typ, typ)
for i in 0 .. <result.len:
for i in 0 ..< result.len:
result.sons[i] = fitNode(c, typ, result.sons[i], result.sons[i].info)
result.typ.sons[0] = makeRangeType(c, 0, sonsLen(result) - 1, n.info)
proc fixAbstractType(c: PContext, n: PNode) =
for i in 1 .. < n.len:
for i in 1 ..< n.len:
let it = n.sons[i]
# do not get rid of nkHiddenSubConv for OpenArrays, the codegen needs it:
if it.kind == nkHiddenSubConv and
@@ -539,7 +539,7 @@ proc evalAtCompileTime(c: PContext, n: PNode): PNode =
var call = newNodeIT(nkCall, n.info, n.typ)
call.add(n.sons[0])
var allConst = true
for i in 1 .. < n.len:
for i in 1 ..< n.len:
var a = getConstExpr(c.module, n.sons[i])
if a == nil:
allConst = false
@@ -558,7 +558,7 @@ proc evalAtCompileTime(c: PContext, n: PNode): PNode =
# done until we have a more robust infrastructure for
# implicit statics.
if n.len > 1:
for i in 1 .. <n.len:
for i in 1 ..< n.len:
# see bug #2113, it's possible that n[i].typ for errornous code:
if n[i].typ.isNil or n[i].typ.kind != tyStatic or
tfUnresolved notin n[i].typ.flags:
@@ -580,7 +580,7 @@ proc evalAtCompileTime(c: PContext, n: PNode): PNode =
var call = newNodeIT(nkCall, n.info, n.typ)
call.add(n.sons[0])
for i in 1 .. < n.len:
for i in 1 ..< n.len:
let a = getConstExpr(c.module, n.sons[i])
if a == nil: return n
call.add(a)
@@ -654,7 +654,7 @@ proc bracketedMacro(n: PNode): PSym =
result = nil
proc setGenericParams(c: PContext, n: PNode) =
for i in 1 .. <n.len:
for i in 1 ..< n.len:
n[i].typ = semTypeNode(c, n[i], nil)
proc afterCallActions(c: PContext; n, orig: PNode, flags: TExprFlags): PNode =
@@ -1464,7 +1464,7 @@ proc semYieldVarResult(c: PContext, n: PNode, restype: PType) =
n.sons[0] = takeImplicitAddr(c, n.sons[0])
of tyTuple:
for i in 0.. <t.sonsLen:
for i in 0..<t.sonsLen:
var e = skipTypes(t.sons[i], {tyGenericInst, tyAlias})
if e.kind == tyVar:
if n.sons[0].kind == nkPar:
@@ -1657,7 +1657,7 @@ proc processQuotations(n: var PNode, op: string,
elif n.kind == nkAccQuoted and op == "``":
returnQuote n[0]
for i in 0 .. <n.safeLen:
for i in 0 ..< n.safeLen:
processQuotations(n.sons[i], op, quotes, ids)
proc semQuoteAst(c: PContext, n: PNode): PNode =
@@ -1825,7 +1825,7 @@ proc semMagic(c: PContext, n: PNode, s: PSym, flags: TExprFlags): PNode =
dec c.inParallelStmt
of mSpawn:
result = setMs(n, s)
for i in 1 .. <n.len:
for i in 1 ..< n.len:
result.sons[i] = semExpr(c, n.sons[i])
let typ = result[^1].typ
if not typ.isEmptyType:
@@ -2076,7 +2076,7 @@ proc semBlock(c: PContext, n: PNode): PNode =
proc semExport(c: PContext, n: PNode): PNode =
var x = newNodeI(n.kind, n.info)
#let L = if n.kind == nkExportExceptStmt: L = 1 else: n.len
for i in 0.. <n.len:
for i in 0..<n.len:
let a = n.sons[i]
var o: TOverloadIter
var s = initOverloadIter(o, c, a)

View File

@@ -89,7 +89,7 @@ proc semForObjectFields(c: TFieldsCtx, typ, forLoop, father: PNode) =
access.sons[1] = newSymNode(typ.sons[0].sym, forLoop.info)
caseStmt.add(semExprWithType(c.c, access))
# copy the branches over, but replace the fields with the for loop body:
for i in 1 .. <typ.len:
for i in 1 ..< typ.len:
var branch = copyTree(typ[i])
let L = branch.len
branch.sons[L-1] = newNodeI(nkStmtList, forLoop.info)

View File

@@ -121,14 +121,14 @@ proc freshGenSyms(n: PNode, owner, orig: PSym, symMap: var TIdTable) =
idTablePut(symMap, s, x)
n.sym = x
else:
for i in 0 .. <safeLen(n): freshGenSyms(n.sons[i], owner, orig, symMap)
for i in 0 ..< safeLen(n): freshGenSyms(n.sons[i], owner, orig, symMap)
proc addParamOrResult(c: PContext, param: PSym, kind: TSymKind)
proc instantiateBody(c: PContext, n, params: PNode, result, orig: PSym) =
if n.sons[bodyPos].kind != nkEmpty:
let procParams = result.typ.n
for i in 1 .. <procParams.len:
for i in 1 ..< procParams.len:
addDecl(c, procParams[i].sym)
maybeAddResult(c, result, result.ast)
@@ -138,7 +138,7 @@ proc instantiateBody(c: PContext, n, params: PNode, result, orig: PSym) =
var symMap: TIdTable
initIdTable symMap
if params != nil:
for i in 1 .. <params.len:
for i in 1 ..< params.len:
let param = params[i].sym
if sfGenSym in param.flags:
idTablePut(symMap, params[i].sym, result.typ.n[param.position+1].sym)
@@ -211,7 +211,7 @@ proc instantiateProcType(c: PContext, pt: TIdTable,
let originalParams = result.n
result.n = originalParams.shallowCopy
for i in 1 .. <result.len:
for i in 1 ..< result.len:
# twrong_field_caching requires these 'resetIdTable' calls:
if i > 1:
resetIdTable(cl.symMap)

View File

@@ -42,7 +42,7 @@ proc annotateType*(n: PNode, t: PType) =
of nkObjConstr:
let x = t.skipTypes(abstractPtrs)
n.typ = t
for i in 1 .. <n.len:
for i in 1 ..< n.len:
var j = i-1
let field = x.n.ithField(j)
if field.isNil:
@@ -53,7 +53,7 @@ proc annotateType*(n: PNode, t: PType) =
of nkPar:
if x.kind == tyTuple:
n.typ = t
for i in 0 .. <n.len:
for i in 0 ..< n.len:
if i >= x.len: globalError n.info, "invalid field at index " & $i
else: annotateType(n.sons[i], x.sons[i])
elif x.kind == tyProc and x.callConv == ccClosure:

View File

@@ -42,7 +42,7 @@ proc mergeInitStatus(existing: var InitStatus, newStatus: InitStatus) =
proc locateFieldInInitExpr(field: PSym, initExpr: PNode): PNode =
# Returns the assignment nkExprColonExpr node or nil
let fieldId = field.name.id
for i in 1 .. <initExpr.len:
for i in 1 ..< initExpr.len:
let assignment = initExpr[i]
if assignment.kind != nkExprColonExpr:
localError(initExpr.info, "incorrect object construction syntax")
@@ -145,7 +145,7 @@ proc semConstructFields(c: PContext, recNode: PNode,
internalAssert discriminator.kind == nkSym
var selectedBranch = -1
for i in 1 .. <recNode.len:
for i in 1 ..< recNode.len:
let innerRecords = recNode[i]{-1}
let status = semConstructFields(c, innerRecords, initExpr, flags)
if status notin {initNone, initUnknown}:
@@ -220,7 +220,7 @@ proc semConstructFields(c: PContext, recNode: PNode,
else:
# All bets are off. If any of the branches has a mandatory
# fields we must produce an error:
for i in 1 .. <recNode.len: checkMissingFields recNode[i]
for i in 1 ..< recNode.len: checkMissingFields recNode[i]
of nkSym:
let field = recNode.sym
@@ -277,7 +277,7 @@ proc semObjConstr(c: PContext, n: PNode, flags: TExprFlags): PNode =
# Since we were traversing the object fields, it's possible that
# not all of the fields specified in the constructor was visited.
# We'll check for such fields here:
for i in 1.. <result.len:
for i in 1..<result.len:
let field = result[i]
if nfSem notin field.flags:
if field.kind != nkExprColonExpr:
@@ -286,7 +286,7 @@ proc semObjConstr(c: PContext, n: PNode, flags: TExprFlags): PNode =
let id = considerQuotedIdent(field[0])
# This node was not processed. There are two possible reasons:
# 1) It was shadowed by a field with the same name on the left
for j in 1 .. <i:
for j in 1 ..< i:
let prevId = considerQuotedIdent(result[j][0])
if prevId.id == id.id:
localError(field.info, errFieldInitTwice, id.s)

View File

@@ -81,7 +81,7 @@ proc initAnalysisCtx(): AnalysisCtx =
result.guards = @[]
proc lookupSlot(c: AnalysisCtx; s: PSym): int =
for i in 0.. <c.locals.len:
for i in 0..<c.locals.len:
if c.locals[i].v == s or c.locals[i].alias == s: return i
return -1
@@ -94,7 +94,7 @@ proc getSlot(c: var AnalysisCtx; v: PSym): ptr MonotonicVar =
return addr(c.locals[L])
proc gatherArgs(c: var AnalysisCtx; n: PNode) =
for i in 0.. <n.safeLen:
for i in 0..<n.safeLen:
let root = getRoot n[i]
if root != nil:
block addRoot:
@@ -119,7 +119,7 @@ proc checkLocal(c: AnalysisCtx; n: PNode) =
if s >= 0 and c.locals[s].stride != nil:
localError(n.info, "invalid usage of counter after increment")
else:
for i in 0 .. <n.safeLen: checkLocal(c, n.sons[i])
for i in 0 ..< n.safeLen: checkLocal(c, n.sons[i])
template `?`(x): untyped = x.renderTree
@@ -180,7 +180,7 @@ proc stride(c: AnalysisCtx; n: PNode): BiggestInt =
if s >= 0 and c.locals[s].stride != nil:
result = c.locals[s].stride.intVal
else:
for i in 0 .. <n.safeLen: result += stride(c, n.sons[i])
for i in 0 ..< n.safeLen: result += stride(c, n.sons[i])
proc subStride(c: AnalysisCtx; n: PNode): PNode =
# substitute with stride:
@@ -192,7 +192,7 @@ proc subStride(c: AnalysisCtx; n: PNode): PNode =
result = n
elif n.safeLen > 0:
result = shallowCopy(n)
for i in 0 .. <n.len: result.sons[i] = subStride(c, n.sons[i])
for i in 0 ..< n.len: result.sons[i] = subStride(c, n.sons[i])
else:
result = n
@@ -251,7 +251,7 @@ proc checkSlicesAreDisjoint(c: var AnalysisCtx) =
proc analyse(c: var AnalysisCtx; n: PNode)
proc analyseSons(c: var AnalysisCtx; n: PNode) =
for i in 0 .. <safeLen(n): analyse(c, n[i])
for i in 0 ..< safeLen(n): analyse(c, n[i])
proc min(a, b: PNode): PNode =
if a.isNil: result = b
@@ -293,11 +293,11 @@ proc analyseCall(c: var AnalysisCtx; n: PNode; op: PSym) =
proc analyseCase(c: var AnalysisCtx; n: PNode) =
analyse(c, n.sons[0])
let oldFacts = c.guards.len
for i in 1.. <n.len:
for i in 1..<n.len:
let branch = n.sons[i]
setLen(c.guards, oldFacts)
addCaseBranchFacts(c.guards, n, i)
for i in 0 .. <branch.len:
for i in 0 ..< branch.len:
analyse(c, branch.sons[i])
setLen(c.guards, oldFacts)
@@ -307,14 +307,14 @@ proc analyseIf(c: var AnalysisCtx; n: PNode) =
addFact(c.guards, canon(n.sons[0].sons[0]))
analyse(c, n.sons[0].sons[1])
for i in 1.. <n.len:
for i in 1..<n.len:
let branch = n.sons[i]
setLen(c.guards, oldFacts)
for j in 0..i-1:
addFactNeg(c.guards, canon(n.sons[j].sons[0]))
if branch.len > 1:
addFact(c.guards, canon(branch.sons[0]))
for i in 0 .. <branch.len:
for i in 0 ..< branch.len:
analyse(c, branch.sons[i])
setLen(c.guards, oldFacts)
@@ -407,7 +407,7 @@ proc transformSlices(n: PNode): PNode =
return result
if n.safeLen > 0:
result = shallowCopy(n)
for i in 0 .. < n.len:
for i in 0 ..< n.len:
result.sons[i] = transformSlices(n.sons[i])
else:
result = n
@@ -415,7 +415,7 @@ proc transformSlices(n: PNode): PNode =
proc transformSpawn(owner: PSym; n, barrier: PNode): PNode
proc transformSpawnSons(owner: PSym; n, barrier: PNode): PNode =
result = shallowCopy(n)
for i in 0 .. < n.len:
for i in 0 ..< n.len:
result.sons[i] = transformSpawn(owner, n.sons[i], barrier)
proc transformSpawn(owner: PSym; n, barrier: PNode): PNode =

View File

@@ -248,7 +248,7 @@ type
TIntersection = seq[tuple[id, count: int]] # a simple count table
proc addToIntersection(inter: var TIntersection, s: int) =
for j in 0.. <inter.len:
for j in 0..<inter.len:
if s == inter[j].id:
inc inter[j].count
return
@@ -282,7 +282,7 @@ proc createTag(n: PNode): PNode =
proc addEffect(a: PEffects, e: PNode, useLineInfo=true) =
assert e.kind != nkRaiseStmt
var aa = a.exc
for i in a.bottom .. <aa.len:
for i in a.bottom ..< aa.len:
if sameType(aa[i].excType, e.excType):
if not useLineInfo or gCmd == cmdDoc: return
elif aa[i].info == e.info: return
@@ -290,7 +290,7 @@ proc addEffect(a: PEffects, e: PNode, useLineInfo=true) =
proc addTag(a: PEffects, e: PNode, useLineInfo=true) =
var aa = a.tags
for i in 0 .. <aa.len:
for i in 0 ..< aa.len:
if sameType(aa[i].typ.skipTypes(skipPtrs), e.typ.skipTypes(skipPtrs)):
if not useLineInfo or gCmd == cmdDoc: return
elif aa[i].info == e.info: return
@@ -345,12 +345,12 @@ proc trackTryStmt(tracked: PEffects, n: PNode) =
inc tracked.inTryStmt
track(tracked, n.sons[0])
dec tracked.inTryStmt
for i in oldState.. <tracked.init.len:
for i in oldState..<tracked.init.len:
addToIntersection(inter, tracked.init[i])
var branches = 1
var hasFinally = false
for i in 1 .. < n.len:
for i in 1 ..< n.len:
let b = n.sons[i]
let blen = sonsLen(b)
if b.kind == nkExceptBranch:
@@ -364,7 +364,7 @@ proc trackTryStmt(tracked: PEffects, n: PNode) =
setLen(tracked.init, oldState)
track(tracked, b.sons[blen-1])
for i in oldState.. <tracked.init.len:
for i in oldState..<tracked.init.len:
addToIntersection(inter, tracked.init[i])
else:
assert b.kind == nkFinally
@@ -420,7 +420,7 @@ proc documentEffect(n, x: PNode, effectType: TSpecialWord, idx: int): PNode =
# warning: hack ahead:
var effects = newNodeI(nkBracket, n.info, real.len)
for i in 0 .. <real.len:
for i in 0 ..< real.len:
var t = typeToString(real[i].typ)
if t.startsWith("ref "): t = substr(t, 4)
effects.sons[i] = newIdentNode(getIdent(t), n.info)
@@ -613,16 +613,16 @@ proc trackCase(tracked: PEffects, n: PNode) =
warnProveField in gNotes
var inter: TIntersection = @[]
var toCover = 0
for i in 1.. <n.len:
for i in 1..<n.len:
let branch = n.sons[i]
setLen(tracked.init, oldState)
if interesting:
setLen(tracked.guards, oldFacts)
addCaseBranchFacts(tracked.guards, n, i)
for i in 0 .. <branch.len:
for i in 0 ..< branch.len:
track(tracked, branch.sons[i])
if not breaksBlock(branch.lastSon): inc toCover
for i in oldState.. <tracked.init.len:
for i in oldState..<tracked.init.len:
addToIntersection(inter, tracked.init[i])
setLen(tracked.init, oldState)
@@ -642,10 +642,10 @@ proc trackIf(tracked: PEffects, n: PNode) =
var toCover = 0
track(tracked, n.sons[0].sons[1])
if not breaksBlock(n.sons[0].sons[1]): inc toCover
for i in oldState.. <tracked.init.len:
for i in oldState..<tracked.init.len:
addToIntersection(inter, tracked.init[i])
for i in 1.. <n.len:
for i in 1..<n.len:
let branch = n.sons[i]
setLen(tracked.guards, oldFacts)
for j in 0..i-1:
@@ -653,10 +653,10 @@ proc trackIf(tracked: PEffects, n: PNode) =
if branch.len > 1:
addFact(tracked.guards, branch.sons[0])
setLen(tracked.init, oldState)
for i in 0 .. <branch.len:
for i in 0 ..< branch.len:
track(tracked, branch.sons[i])
if not breaksBlock(branch.lastSon): inc toCover
for i in oldState.. <tracked.init.len:
for i in oldState..<tracked.init.len:
addToIntersection(inter, tracked.init[i])
setLen(tracked.init, oldState)
if lastSon(n).len == 1:
@@ -668,7 +668,7 @@ proc trackIf(tracked: PEffects, n: PNode) =
proc trackBlock(tracked: PEffects, n: PNode) =
if n.kind in {nkStmtList, nkStmtListExpr}:
var oldState = -1
for i in 0.. <n.len:
for i in 0..<n.len:
if hasSubnodeWith(n.sons[i], nkBreakStmt):
# block:
# x = def
@@ -701,7 +701,7 @@ proc track(tracked: PEffects, n: PNode) =
n.sons[0].info = n.info
#throws(tracked.exc, n.sons[0])
addEffect(tracked, n.sons[0], useLineInfo=false)
for i in 0 .. <safeLen(n):
for i in 0 ..< safeLen(n):
track(tracked, n.sons[i])
of nkCallKinds:
# p's effects are ours too:
@@ -752,11 +752,11 @@ proc track(tracked: PEffects, n: PNode) =
discard
else:
message(arg.info, warnProveInit, $arg)
for i in 0 .. <safeLen(n):
for i in 0 ..< safeLen(n):
track(tracked, n.sons[i])
of nkDotExpr:
guardDotAccess(tracked, n)
for i in 0 .. <len(n): track(tracked, n.sons[i])
for i in 0 ..< len(n): track(tracked, n.sons[i])
of nkCheckedFieldExpr:
track(tracked, n.sons[0])
if warnProveField in gNotes: checkFieldAccess(tracked.guards, n)
@@ -804,13 +804,13 @@ proc track(tracked: PEffects, n: PNode) =
of nkForStmt, nkParForStmt:
# we are very conservative here and assume the loop is never executed:
let oldState = tracked.init.len
for i in 0 .. <len(n):
for i in 0 ..< len(n):
track(tracked, n.sons[i])
setLen(tracked.init, oldState)
of nkObjConstr:
when false: track(tracked, n.sons[0])
let oldFacts = tracked.guards.len
for i in 1 .. <len(n):
for i in 1 ..< len(n):
let x = n.sons[i]
track(tracked, x)
if x.sons[0].kind == nkSym and sfDiscriminant in x.sons[0].sym.flags:
@@ -821,7 +821,7 @@ proc track(tracked: PEffects, n: PNode) =
let oldLocked = tracked.locked.len
let oldLockLevel = tracked.currLockLevel
var enforcedGcSafety = false
for i in 0 .. <pragmaList.len:
for i in 0 ..< pragmaList.len:
let pragma = whichPragma(pragmaList.sons[i])
if pragma == wLocks:
lockLocations(tracked, pragmaList.sons[i])
@@ -840,7 +840,7 @@ proc track(tracked: PEffects, n: PNode) =
of nkObjUpConv, nkObjDownConv, nkChckRange, nkChckRangeF, nkChckRange64:
if n.len == 1: track(tracked, n.sons[0])
else:
for i in 0 .. <safeLen(n): track(tracked, n.sons[i])
for i in 0 ..< safeLen(n): track(tracked, n.sons[i])
proc subtypeRelation(spec, real: PNode): bool =
result = safeInheritanceDiff(real.excType, spec.typ) <= 0
@@ -852,7 +852,7 @@ proc checkRaisesSpec(spec, real: PNode, msg: string, hints: bool;
var used = initIntSet()
for r in items(real):
block search:
for s in 0 .. <spec.len:
for s in 0 ..< spec.len:
if effectPredicate(spec[s], r):
used.incl(s)
break search
@@ -862,7 +862,7 @@ proc checkRaisesSpec(spec, real: PNode, msg: string, hints: bool;
popInfoContext()
# hint about unnecessarily listed exception types:
if hints:
for s in 0 .. <spec.len:
for s in 0 ..< spec.len:
if not used.contains(s):
message(spec[s].info, hintXDeclaredButNotUsed, renderTree(spec[s]))

View File

@@ -858,7 +858,7 @@ proc checkCovariantParamsUsages(genericType: PType) =
of tyGenericInvocation:
let targetBody = t[0]
for i in 1 .. <t.len:
for i in 1 ..< t.len:
let param = t[i]
if param.kind == tyGenericParam:
if tfCovariant in param.flags:
@@ -1005,7 +1005,7 @@ proc checkForMetaFields(n: PNode) =
of tySequence, tySet, tyArray, tyOpenArray, tyVar, tyPtr, tyRef,
tyProc, tyGenericInvocation, tyGenericInst, tyAlias:
let start = ord(t.kind in {tyGenericInvocation, tyGenericInst})
for i in start .. <t.sons.len:
for i in start ..< t.sons.len:
checkMeta(t.sons[i])
else:
checkMeta(t)
@@ -1131,7 +1131,7 @@ proc addResultNode(c: PContext, n: PNode) =
proc copyExcept(n: PNode, i: int): PNode =
result = copyNode(n)
for j in 0.. <n.len:
for j in 0..<n.len:
if j != i: result.add(n.sons[j])
proc lookupMacro(c: PContext, n: PNode): PSym =
@@ -1145,7 +1145,7 @@ proc semProcAnnotation(c: PContext, prc: PNode;
validPragmas: TSpecialWords): PNode =
var n = prc.sons[pragmasPos]
if n == nil or n.kind == nkEmpty: return
for i in countup(0, <n.len):
for i in countup(0, n.len-1):
var it = n.sons[i]
var key = if it.kind == nkExprColonExpr: it.sons[0] else: it
let m = lookupMacro(c, key)
@@ -1296,7 +1296,7 @@ proc activate(c: PContext, n: PNode) =
of nkLambdaKinds:
discard semLambda(c, n, {})
of nkCallKinds:
for i in 1 .. <n.len: activate(c, n[i])
for i in 1 ..< n.len: activate(c, n[i])
else:
discard
@@ -1719,7 +1719,7 @@ proc evalInclude(c: PContext, n: PNode): PNode =
excl(c.includedFiles, f)
proc setLine(n: PNode, info: TLineInfo) =
for i in 0 .. <safeLen(n): setLine(n.sons[i], info)
for i in 0 ..< safeLen(n): setLine(n.sons[i], info)
n.info = info
proc semPragmaBlock(c: PContext, n: PNode): PNode =
@@ -1727,7 +1727,7 @@ proc semPragmaBlock(c: PContext, n: PNode): PNode =
pragma(c, nil, pragmaList, exprPragmas)
result = semExpr(c, n.sons[1])
n.sons[1] = result
for i in 0 .. <pragmaList.len:
for i in 0 ..< pragmaList.len:
case whichPragma(pragmaList.sons[i])
of wLine: setLine(result, pragmaList.sons[i].info)
of wLocks, wGcSafe:

View File

@@ -75,7 +75,7 @@ proc symChoice(c: PContext, n: PNode, s: PSym, r: TSymChoiceRule): PNode =
a = nextOverloadIter(o, c, n)
proc semBindStmt(c: PContext, n: PNode, toBind: var IntSet): PNode =
for i in 0 .. < n.len:
for i in 0 ..< n.len:
var a = n.sons[i]
# If 'a' is an overloaded symbol, we used to use the first symbol
# as a 'witness' and use the fact that subsequent lookups will yield
@@ -95,7 +95,7 @@ proc semBindStmt(c: PContext, n: PNode, toBind: var IntSet): PNode =
result = newNodeI(nkEmpty, n.info)
proc semMixinStmt(c: PContext, n: PNode, toMixin: var IntSet): PNode =
for i in 0 .. < n.len:
for i in 0 ..< n.len:
toMixin.incl(considerQuotedIdent(n.sons[i]).id)
result = newNodeI(nkEmpty, n.info)
@@ -163,7 +163,7 @@ proc onlyReplaceParams(c: var TemplCtx, n: PNode): PNode =
result = newSymNode(s, n.info)
styleCheckUse(n.info, s)
else:
for i in 0 .. <n.safeLen:
for i in 0 ..< n.safeLen:
result.sons[i] = onlyReplaceParams(c, n.sons[i])
proc newGenSym(kind: TSymKind, n: PNode, c: var TemplCtx): PSym =
@@ -301,7 +301,7 @@ proc semPattern(c: PContext, n: PNode): PNode
proc semTemplBodySons(c: var TemplCtx, n: PNode): PNode =
result = n
for i in 0.. < n.len:
for i in 0 ..< n.len:
result.sons[i] = semTemplBody(c, n.sons[i])
proc oprIsRoof(n: PNode): bool =

View File

@@ -515,7 +515,7 @@ proc semCaseBranch(c: PContext, t, branch: PNode, branchIndex: int,
# first element is special and will overwrite: branch.sons[i]:
branch.sons[i] = semCaseBranchSetElem(c, t, r[0], covered)
# other elements have to be added to ``branch``
for j in 1 .. <r.len:
for j in 1 ..< r.len:
branch.add(semCaseBranchSetElem(c, t, r[j], covered))
# caution! last son of branch must be the actions to execute:
var L = branch.len
@@ -846,7 +846,7 @@ proc liftParamType(c: PContext, procKind: TSymKind, genericParams: PNode,
@[newTypeS(paramType.kind, c)])
result = addImplicitGeneric(typ)
else:
for i in 0 .. <paramType.len:
for i in 0 ..< paramType.len:
if paramType.sons[i] == paramType:
globalError(info, errIllegalRecursionInTypeX, typeToString(paramType))
var lifted = liftingWalk(paramType.sons[i])
@@ -897,7 +897,7 @@ proc liftParamType(c: PContext, procKind: TSymKind, genericParams: PNode,
result.shouldHaveMeta
of tyGenericInvocation:
for i in 1 .. <paramType.len:
for i in 1 ..< paramType.len:
let lifted = liftingWalk(paramType.sons[i])
if lifted != nil: paramType.sons[i] = lifted
@@ -1146,7 +1146,7 @@ proc semGeneric(c: PContext, n: PNode, s: PSym, prev: PType): PType =
var isConcrete = true
for i in 1 .. <m.call.len:
for i in 1 ..< m.call.len:
var typ = m.call[i].typ
if typ.kind == tyTypeDesc and typ.sons[0].kind == tyNone:
isConcrete = false

View File

@@ -133,7 +133,7 @@ proc prepareNode(cl: var TReplTypeVars, n: PNode): PNode =
result.typ = t
if result.kind == nkSym: result.sym = replaceTypeVarsS(cl, n.sym)
let isCall = result.kind in nkCallKinds
for i in 0 .. <n.safeLen:
for i in 0 ..< n.safeLen:
# XXX HACK: ``f(a, b)``, avoid to instantiate `f`
if isCall and i == 0: result.add(n[i])
else: result.add(prepareNode(cl, n[i]))
@@ -151,7 +151,7 @@ proc hasGenericArguments*(n: PNode): bool =
(n.sym.kind == skType and
n.sym.typ.flags * {tfGenericTypeParam, tfImplicitTypeParam} != {})
else:
for i in 0.. <n.safeLen:
for i in 0..<n.safeLen:
if hasGenericArguments(n.sons[i]): return true
return false
@@ -166,13 +166,13 @@ proc reResolveCallsWithTypedescParams(cl: var TReplTypeVars, n: PNode): PNode =
# overload resolution is executed again (which may trigger generateInstance).
if n.kind in nkCallKinds and sfFromGeneric in n[0].sym.flags:
var needsFixing = false
for i in 1 .. <n.safeLen:
for i in 1 ..< n.safeLen:
if isTypeParam(n[i]): needsFixing = true
if needsFixing:
n.sons[0] = newSymNode(n.sons[0].sym.owner)
return cl.c.semOverloadedCall(cl.c, n, n, {skProc, skFunc}, {})
for i in 0 .. <n.safeLen:
for i in 0 ..< n.safeLen:
n.sons[i] = reResolveCallsWithTypedescParams(cl, n[i])
return n
@@ -385,11 +385,11 @@ proc eraseVoidParams*(t: PType) =
if t.sons[0] != nil and t.sons[0].kind == tyVoid:
t.sons[0] = nil
for i in 1 .. <t.sonsLen:
for i in 1 ..< t.sonsLen:
# don't touch any memory unless necessary
if t.sons[i].kind == tyVoid:
var pos = i
for j in i+1 .. <t.sonsLen:
for j in i+1 ..< t.sonsLen:
if t.sons[j].kind != tyVoid:
t.sons[pos] = t.sons[j]
t.n.sons[pos] = t.n.sons[j]
@@ -399,7 +399,7 @@ proc eraseVoidParams*(t: PType) =
return
proc skipIntLiteralParams*(t: PType) =
for i in 0 .. <t.sonsLen:
for i in 0 ..< t.sonsLen:
let p = t.sons[i]
if p == nil: continue
let skipped = p.skipIntLit
@@ -500,7 +500,7 @@ proc replaceTypeVarsTAux(cl: var TReplTypeVars, t: PType): PType =
bailout()
result = instCopyType(cl, t)
idTablePut(cl.localCache, t, result)
for i in 1 .. <result.sonsLen:
for i in 1 ..< result.sonsLen:
result.sons[i] = replaceTypeVarsT(cl, result.sons[i])
propagateToOwner(result, result.lastSon)

View File

@@ -136,7 +136,7 @@ proc hashTree(c: var MD5Context, n: PNode) =
of nkStrLit..nkTripleStrLit:
c &= n.strVal
else:
for i in 0.. <n.len: hashTree(c, n.sons[i])
for i in 0..<n.len: hashTree(c, n.sons[i])
proc hashType(c: var MD5Context, t: PType; flags: set[ConsiderFlag]) =
if t == nil:
@@ -230,14 +230,14 @@ proc hashType(c: var MD5Context, t: PType; flags: set[ConsiderFlag]) =
c &= ','
c.hashType(t.sons[0], flags)
else:
for i in 0.. <t.len: c.hashType(t.sons[i], flags)
for i in 0..<t.len: c.hashType(t.sons[i], flags)
c &= char(t.callConv)
if CoType notin flags:
if tfNoSideEffect in t.flags: c &= ".noSideEffect"
if tfThread in t.flags: c &= ".thread"
if tfVarargs in t.flags: c &= ".varargs"
else:
for i in 0.. <t.len: c.hashType(t.sons[i], flags)
for i in 0..<t.len: c.hashType(t.sons[i], flags)
if tfNotNil in t.flags and CoType notin flags: c &= "not nil"
when defined(debugSigHashes):

View File

@@ -200,7 +200,7 @@ proc sumGeneric(t: PType): int =
inc result
of tyGenericInvocation, tyTuple, tyProc, tyAnd:
result += ord(t.kind in {tyGenericInvocation, tyAnd})
for i in 0 .. <t.len:
for i in 0 ..< t.len:
if t.sons[i] != nil:
result += t.sons[i].sumGeneric
break
@@ -220,7 +220,7 @@ proc sumGeneric(t: PType): int =
proc complexDisambiguation(a, b: PType): int =
# 'a' matches better if *every* argument matches better or equal than 'b'.
var winner = 0
for i in 1 .. <min(a.len, b.len):
for i in 1 ..< min(a.len, b.len):
let x = a.sons[i].sumGeneric
let y = b.sons[i].sumGeneric
#if ggDebug:
@@ -240,8 +240,8 @@ proc complexDisambiguation(a, b: PType): int =
result = winner
when false:
var x, y: int
for i in 1 .. <a.len: x += a.sons[i].sumGeneric
for i in 1 .. <b.len: y += b.sons[i].sumGeneric
for i in 1 ..< a.len: x += a.sons[i].sumGeneric
for i in 1 ..< b.len: y += b.sons[i].sumGeneric
result = x - y
proc writeMatches*(c: TCandidate) =
@@ -276,7 +276,7 @@ proc cmpCandidates*(a, b: TCandidate): int =
proc argTypeToString(arg: PNode; prefer: TPreferedDesc): string =
if arg.kind in nkSymChoices:
result = typeToString(arg[0].typ, prefer)
for i in 1 .. <arg.len:
for i in 1 ..< arg.len:
result.add(" | ")
result.add typeToString(arg[i].typ, prefer)
elif arg.typ == nil:
@@ -581,7 +581,7 @@ proc procTypeRel(c: var TCandidate, f, a: PType): TTypeRelation =
# Note: We have to do unification for the parameters before the
# return type!
for i in 1 .. <f.sonsLen:
for i in 1 ..< f.sonsLen:
checkParam(f.sons[i], a.sons[i])
if f.sons[0] != nil:
@@ -659,7 +659,7 @@ proc matchUserTypeClass*(m: var TCandidate; ff, a: PType): PType =
var typeParams: seq[(PSym, PType)]
if ff.kind == tyUserTypeClassInst:
for i in 1 .. <(ff.len - 1):
for i in 1 ..< (ff.len - 1):
var
typeParamName = ff.base.sons[i-1].sym.name
typ = ff.sons[i]
@@ -2233,7 +2233,7 @@ proc matchesAux(c: PContext, n, nOrig: PNode,
proc semFinishOperands*(c: PContext, n: PNode) =
# this needs to be called to ensure that after overloading resolution every
# argument has been sem'checked:
for i in 1 .. <n.len:
for i in 1 ..< n.len:
n.sons[i] = prepareOperand(c, n.sons[i])
proc partialMatch*(c: PContext, n, nOrig: PNode, m: var TCandidate) =

View File

@@ -231,7 +231,7 @@ proc freshLabels(c: PTransf, n: PNode; symMap: var TIdTable) =
let x = PSym(idTableGet(symMap, n.sym))
if x != nil: n.sym = x
else:
for i in 0 .. <safeLen(n): freshLabels(c, n.sons[i], symMap)
for i in 0 ..< safeLen(n): freshLabels(c, n.sons[i], symMap)
proc transformBlock(c: PTransf, n: PNode): PTransNode =
var labl: PSym
@@ -275,7 +275,7 @@ proc transformWhile(c: PTransf; n: PNode): PTransNode =
var body = newTransNode(n)
for i in 0..n.len-2:
body[i] = transform(c, n.sons[i])
body[<n.len] = transformLoopBody(c, n.sons[<n.len])
body[n.len-1] = transformLoopBody(c, n.sons[n.len-1])
result[1] = body
discard c.breakSyms.pop
@@ -516,7 +516,7 @@ proc findWrongOwners(c: PTransf, n: PNode) =
internalError(x.info, "bah " & x.sym.name.s & " " &
x.sym.owner.name.s & " " & getCurrOwner(c).name.s)
else:
for i in 0 .. <safeLen(n): findWrongOwners(c, n.sons[i])
for i in 0 ..< safeLen(n): findWrongOwners(c, n.sons[i])
proc transformFor(c: PTransf, n: PNode): PTransNode =
# generate access statements for the parameters (unless they are constant)
@@ -646,7 +646,7 @@ proc transformArrayAccess(c: PTransf, n: PNode): PTransNode =
result = n.PTransNode
else:
result = newTransNode(n)
for i in 0 .. < n.len:
for i in 0 ..< n.len:
result[i] = transform(c, skipConv(n.sons[i]))
proc getMergeOp(n: PNode): PSym =
@@ -750,7 +750,7 @@ proc dontInlineConstant(orig, cnst: PNode): bool {.inline.} =
proc commonOptimizations*(c: PSym, n: PNode): PNode =
result = n
for i in 0 .. < n.safeLen:
for i in 0 ..< n.safeLen:
result.sons[i] = commonOptimizations(c, n.sons[i])
var op = getMergeOp(n)
if (op != nil) and (op.magic != mNone) and (sonsLen(n) >= 3):

View File

@@ -98,7 +98,7 @@ proc isDeepConstExpr*(n: PNode): bool =
of nkExprEqExpr, nkExprColonExpr, nkHiddenStdConv, nkHiddenSubConv:
result = isDeepConstExpr(n.sons[1])
of nkCurly, nkBracket, nkPar, nkObjConstr, nkClosure, nkRange:
for i in ord(n.kind == nkObjConstr) .. <n.len:
for i in ord(n.kind == nkObjConstr) ..< n.len:
if not isDeepConstExpr(n.sons[i]): return false
if n.typ.isNil: result = true
else:

View File

@@ -742,7 +742,7 @@ proc equalParam(a, b: PSym): TParamsEquality =
proc sameConstraints(a, b: PNode): bool =
if isNil(a) and isNil(b): return true
internalAssert a.len == b.len
for i in 1 .. <a.len:
for i in 1 ..< a.len:
if not exprStructuralEquivalent(a[i].sym.constraint,
b[i].sym.constraint):
return false
@@ -1509,7 +1509,7 @@ proc isCompileTimeOnly*(t: PType): bool {.inline.} =
proc containsCompileTimeOnly*(t: PType): bool =
if isCompileTimeOnly(t): return true
if t.sons != nil:
for i in 0 .. <t.sonsLen:
for i in 0 ..< t.sonsLen:
if t.sons[i] != nil and isCompileTimeOnly(t.sons[i]):
return true
return false

View File

@@ -20,7 +20,7 @@ proc renderPlainSymbolName*(n: PNode): string =
result = ""
case n.kind
of nkPostfix, nkAccQuoted:
result = renderPlainSymbolName(n[<n.len])
result = renderPlainSymbolName(n[n.len-1])
of nkIdent:
result = n.ident.s
of nkSym:
@@ -58,8 +58,8 @@ proc renderType(n: PNode): string =
assert params.kind == nkFormalParams
assert len(params) > 0
result = "proc("
for i in 1 .. <len(params): result.add(renderType(params[i]) & ',')
result[<len(result)] = ')'
for i in 1 ..< len(params): result.add(renderType(params[i]) & ',')
result[len(result)-1] = ')'
else:
result = "proc"
of nkIdentDefs:
@@ -67,18 +67,18 @@ proc renderType(n: PNode): string =
let typePos = len(n) - 2
let typeStr = renderType(n[typePos])
result = typeStr
for i in 1 .. <typePos:
for i in 1 ..< typePos:
assert n[i].kind == nkIdent
result.add(',' & typeStr)
of nkTupleTy:
result = "tuple["
for i in 0 .. <len(n): result.add(renderType(n[i]) & ',')
result[<len(result)] = ']'
for i in 0 ..< len(n): result.add(renderType(n[i]) & ',')
result[len(result)-1] = ']'
of nkBracketExpr:
assert len(n) >= 2
result = renderType(n[0]) & '['
for i in 1 .. <len(n): result.add(renderType(n[i]) & ',')
result[<len(result)] = ']'
for i in 1 ..< len(n): result.add(renderType(n[i]) & ',')
result[len(result)-1] = ']'
else: result = ""
assert(not result.isNil)
@@ -91,7 +91,7 @@ proc renderParamTypes(found: var seq[string], n: PNode) =
## generator does include the information.
case n.kind
of nkFormalParams:
for i in 1 .. <len(n): renderParamTypes(found, n[i])
for i in 1 ..< len(n): renderParamTypes(found, n[i])
of nkIdentDefs:
# These are parameter names + type + default value node.
let typePos = len(n) - 2
@@ -102,7 +102,7 @@ proc renderParamTypes(found: var seq[string], n: PNode) =
let typ = n[typePos+1].typ
if not typ.isNil: typeStr = typeToString(typ, preferExported)
if typeStr.len < 1: return
for i in 0 .. <typePos:
for i in 0 ..< typePos:
found.add(typeStr)
else:
internalError(n.info, "renderParamTypes(found,n) with " & $n.kind)

View File

@@ -322,7 +322,7 @@ proc opConv*(dest: var TFullReg, src: TFullReg, desttyp, srctyp: PType): bool =
if x <% n.len and (let f = n.sons[x].sym; f.position == x):
dest.node.strVal = if f.ast.isNil: f.name.s else: f.ast.strVal
else:
for i in 0.. <n.len:
for i in 0..<n.len:
if n.sons[i].kind != nkSym: internalError("opConv for enum")
let f = n.sons[i].sym
if f.position == x:
@@ -431,7 +431,7 @@ proc setLenSeq(c: PCtx; node: PNode; newLen: int; info: TLineInfo) =
setLen(node.sons, newLen)
if oldLen < newLen:
# TODO: This is still not correct for tyPtr, tyRef default value
for i in oldLen .. <newLen:
for i in oldLen ..< newLen:
node.sons[i] = newNodeI(typeKind, info)
proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
@@ -1078,7 +1078,7 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
regs[ra].node = newNodeI(nkBracket, c.debug[pc])
regs[ra].node.typ = typ
newSeq(regs[ra].node.sons, count)
for i in 0 .. <count:
for i in 0 ..< count:
regs[ra].node.sons[i] = getNullValue(typ.sons[0], c.debug[pc])
of opcNewStr:
decodeB(rkNode)
@@ -1213,7 +1213,7 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
var u = regs[rb].node
if u.kind notin {nkEmpty..nkNilLit}:
# XXX can be optimized:
for i in 0.. <x.len: u.add(x.sons[i])
for i in 0..<x.len: u.add(x.sons[i])
else:
stackTrace(c, tos, pc, errGenerated, "cannot add to node kind: " & $u.kind)
regs[ra].node = u
@@ -1555,7 +1555,7 @@ proc execProc*(c: PCtx; sym: PSym; args: openArray[PNode]): PNode =
if not isEmptyType(sym.typ.sons[0]) or sym.kind == skMacro:
putIntoReg(tos.slots[0], getNullValue(sym.typ.sons[0], sym.info))
# XXX We could perform some type checking here.
for i in 1.. <sym.typ.len:
for i in 1..<sym.typ.len:
putIntoReg(tos.slots[i], args[i-1])
result = rawExecute(c, start, tos).regToNode
@@ -1637,7 +1637,7 @@ proc evalConstExprAux(module: PSym; cache: IdentCache; prc: PSym, n: PNode,
when debugEchoCode: c.echoCode start
var tos = PStackFrame(prc: prc, comesFrom: 0, next: nil)
newSeq(tos.slots, c.prc.maxSlots)
#for i in 0 .. <c.prc.maxSlots: tos.slots[i] = newNode(nkEmpty)
#for i in 0 ..< c.prc.maxSlots: tos.slots[i] = newNode(nkEmpty)
result = rawExecute(c, start, tos).regToNode
if result.info.line < 0: result.info = n.info
@@ -1670,7 +1670,7 @@ proc setupMacroParam(x: PNode, typ: PType): TFullReg =
iterator genericParamsInMacroCall*(macroSym: PSym, call: PNode): (PSym, PNode) =
let gp = macroSym.ast[genericParamsPos]
for i in 0 .. <gp.len:
for i in 0 ..< gp.len:
let genericParam = gp[i].sym
let posInCall = macroSym.typ.len + i
yield (genericParam, call[posInCall])
@@ -1688,8 +1688,7 @@ proc evalMacroCall*(module: PSym; cache: IdentCache, n, nOrig: PNode,
# arity here too:
if sym.typ.len > n.safeLen and sym.typ.len > 1:
globalError(n.info, "in call '$#' got $#, but expected $# argument(s)" % [
n.renderTree,
$ <n.safeLen, $ <sym.typ.len])
n.renderTree, $(n.safeLen-1), $(sym.typ.len-1)])
setupGlobalCtx(module, cache)
var c = globalCtx
@@ -1713,11 +1712,11 @@ proc evalMacroCall*(module: PSym; cache: IdentCache, n, nOrig: PNode,
tos.slots[0].node = newNodeI(nkEmpty, n.info)
# setup parameters:
for i in 1.. <sym.typ.len:
for i in 1..<sym.typ.len:
tos.slots[i] = setupMacroParam(n.sons[i], sym.typ.sons[i])
let gp = sym.ast[genericParamsPos]
for i in 0 .. <gp.len:
for i in 0 ..< gp.len:
if sfImmediate notin sym.flags:
let idx = sym.typ.len + i
if idx < n.len:
@@ -1732,7 +1731,7 @@ proc evalMacroCall*(module: PSym; cache: IdentCache, n, nOrig: PNode,
c.callsite = nil
globalError(n.info, "static[T] or typedesc nor supported for .immediate macros")
# temporary storage:
#for i in L .. <maxSlots: tos.slots[i] = newNode(nkEmpty)
#for i in L ..< maxSlots: tos.slots[i] = newNode(nkEmpty)
result = rawExecute(c, start, tos).regToNode
if result.info.line < 0: result.info = n.info
if cyclicTree(result): globalError(n.info, errCyclicTree)

View File

@@ -41,7 +41,7 @@ proc mapTypeToBracketX(name: string; m: TMagic; t: PType; info: TLineInfo;
inst=false): PNode =
result = newNodeIT(nkBracketExpr, if t.n.isNil: info else: t.n.info, t)
result.add atomicTypeX(name, m, t, info)
for i in 0 .. < t.len:
for i in 0 ..< t.len:
if t.sons[i] == nil:
let void = atomicTypeX("void", mVoid, t, info)
void.typ = newType(tyVoid, t.owner)
@@ -119,7 +119,7 @@ proc mapTypeToAstX(t: PType; info: TLineInfo;
result = atomicType("typeDesc", mTypeDesc)
of tyGenericInvocation:
result = newNodeIT(nkBracketExpr, if t.n.isNil: info else: t.n.info, t)
for i in 0 .. < t.len:
for i in 0 ..< t.len:
result.add mapTypeToAst(t.sons[i], info)
of tyGenericInst, tyAlias:
if inst:
@@ -128,7 +128,7 @@ proc mapTypeToAstX(t: PType; info: TLineInfo;
else:
result = newNodeX(nkBracketExpr)
result.add mapTypeToAst(t.lastSon, info)
for i in 1 .. < t.len-1:
for i in 1 ..< t.len-1:
result.add mapTypeToAst(t.sons[i], info)
else:
result = mapTypeToAstX(t.lastSon, info, inst, allowRecursion)

View File

@@ -401,7 +401,7 @@ proc sameConstant*(a, b: PNode): bool =
proc genLiteral(c: PCtx; n: PNode): int =
# types do not matter here:
for i in 0 .. <c.constants.len:
for i in 0 ..< c.constants.len:
if sameConstant(c.constants[i], n): return i
result = rawGenLiteral(c, n)
@@ -430,7 +430,7 @@ proc genCase(c: PCtx; n: PNode; dest: var TDest) =
c.gen(n.sons[0], tmp)
# branch tmp, codeIdx
# fjmp elseLabel
for i in 1 .. <n.len:
for i in 1 ..< n.len:
let it = n.sons[i]
if it.len == 1:
# else stmt:
@@ -460,7 +460,7 @@ proc genTry(c: PCtx; n: PNode; dest: var TDest) =
c.gen(n.sons[0], dest)
c.clearDest(n, dest)
c.patch(elsePos)
for i in 1 .. <n.len:
for i in 1 ..< n.len:
let it = n.sons[i]
if it.kind != nkFinally:
var blen = len(it)
@@ -518,7 +518,7 @@ proc genCall(c: PCtx; n: PNode; dest: var TDest) =
let x = c.getTempRange(n.len, slotTempUnknown)
# varargs need 'opcSetType' for the FFI support:
let fntyp = skipTypes(n.sons[0].typ, abstractInst)
for i in 0.. <n.len:
for i in 0..<n.len:
#if i > 0 and i < sonsLen(fntyp):
# let paramType = fntyp.n.sons[i]
# if paramType.typ.isCompileTimeOnly: continue
@@ -995,7 +995,7 @@ proc genMagic(c: PCtx; n: PNode; dest: var TDest; m: TMagic) =
let n = n[1].skipConv
let x = c.getTempRange(n.len, slotTempUnknown)
internalAssert n.kind == nkBracket
for i in 0.. <n.len:
for i in 0..<n.len:
var r: TRegister = x+i
c.gen(n.sons[i], r)
c.gABC(n, opcEcho, x, n.len)
@@ -1645,7 +1645,7 @@ proc genObjConstr(c: PCtx, n: PNode, dest: var TDest) =
c.gABx(n, opcNew, dest, c.genType(t.sons[0]))
else:
c.gABx(n, opcLdNull, dest, c.genType(n.typ))
for i in 1.. <n.len:
for i in 1..<n.len:
let it = n.sons[i]
if it.kind == nkExprColonExpr and it.sons[0].kind == nkSym:
let idx = genField(it.sons[0])
@@ -1660,7 +1660,7 @@ proc genTupleConstr(c: PCtx, n: PNode, dest: var TDest) =
if dest < 0: dest = c.getTemp(n.typ)
c.gABx(n, opcLdNull, dest, c.genType(n.typ))
# XXX x = (x.old, 22) produces wrong code ... stupid self assignments
for i in 0.. <n.len:
for i in 0..<n.len:
let it = n.sons[i]
if it.kind == nkExprColonExpr:
let idx = genField(it.sons[0])
@@ -1796,7 +1796,7 @@ proc gen(c: PCtx; n: PNode; dest: var TDest; flags: TGenFlags = {}) =
for x in n: gen(c, x)
of nkStmtListExpr:
let L = n.len-1
for i in 0 .. <L: gen(c, n.sons[i])
for i in 0 ..< L: gen(c, n.sons[i])
gen(c, n.sons[L], dest, flags)
of nkPragmaBlock:
gen(c, n.lastSon, dest, flags)
@@ -1882,7 +1882,7 @@ proc genExpr*(c: PCtx; n: PNode, requiresValue = true): int =
proc genParams(c: PCtx; params: PNode) =
# res.sym.position is already 0
c.prc.slots[0] = (inUse: true, kind: slotFixedVar)
for i in 1.. <params.len:
for i in 1..<params.len:
c.prc.slots[i] = (inUse: true, kind: slotFixedLet)
c.prc.maxSlots = max(params.len, 1)
@@ -1895,7 +1895,7 @@ proc finalJumpTarget(c: PCtx; pc, diff: int) =
proc genGenericParams(c: PCtx; gp: PNode) =
var base = c.prc.maxSlots
for i in 0.. <gp.len:
for i in 0..<gp.len:
var param = gp.sons[i].sym
param.position = base + i # XXX: fix this earlier; make it consistent with templates
c.prc.slots[base + i] = (inUse: true, kind: slotFixedLet)
@@ -1903,7 +1903,7 @@ proc genGenericParams(c: PCtx; gp: PNode) =
proc optimizeJumps(c: PCtx; start: int) =
const maxIterations = 10
for i in start .. <c.code.len:
for i in start ..< c.code.len:
let opc = c.code[i].opcode
case opc
of opcTJmp, opcFJmp:

View File

@@ -78,7 +78,7 @@ proc storeAny(s: var string; t: PType; a: PNode; stored: var IntSet) =
s.add("]")
of tyTuple:
s.add("{")
for i in 0.. <t.len:
for i in 0..<t.len:
if i > 0: s.add(", ")
s.add("\"Field" & $i)
s.add("\": ")
@@ -90,7 +90,7 @@ proc storeAny(s: var string; t: PType; a: PNode; stored: var IntSet) =
s.add("}")
of tySet:
s.add("[")
for i in 0.. <a.len:
for i in 0..<a.len:
if i > 0: s.add(", ")
if a[i].kind == nkRange:
var x = copyNode(a[i][0])

View File

@@ -123,7 +123,7 @@ proc returnsNewExpr*(n: PNode): NewLocation =
of nkCurly, nkBracket, nkPar, nkObjConstr, nkClosure,
nkIfExpr, nkIfStmt, nkWhenStmt, nkCaseStmt, nkTryStmt:
result = newLit
for i in ord(n.kind == nkObjConstr) .. <n.len:
for i in ord(n.kind == nkObjConstr) ..< n.len:
let x = returnsNewExpr(n.sons[i])
case x
of newNone: return newNone

View File

@@ -72,7 +72,7 @@ proc cycle*[T](s: openArray[T], n: Natural): seq[T] =
## assert total == @[1, 2, 3, 1, 2, 3, 1, 2, 3]
result = newSeq[T](n * s.len)
var o = 0
for x in 0 .. <n:
for x in 0 ..< n:
for e in s:
result[o] = e
inc o
@@ -88,7 +88,7 @@ proc repeat*[T](x: T, n: Natural): seq[T] =
## total = repeat(5, 3)
## assert total == @[5, 5, 5]
result = newSeq[T](n)
for i in 0 .. <n:
for i in 0 ..< n:
result[i] = x
proc deduplicate*[T](s: openArray[T]): seq[T] =
@@ -132,7 +132,7 @@ proc zip*[S, T](s1: openArray[S], s2: openArray[T]): seq[tuple[a: S, b: T]] =
## assert zip2[2].b == "three"
var m = min(s1.len, s2.len)
newSeq(result, m)
for i in 0 .. <m:
for i in 0 ..< m:
result[i] = (s1[i], s2[i])
proc distribute*[T](s: seq[T], num: Positive, spread = true): seq[seq[T]] =
@@ -180,22 +180,22 @@ proc distribute*[T](s: seq[T], num: Positive, spread = true): seq[seq[T]] =
# Use an algorithm which overcounts the stride and minimizes reading limits.
if extra > 0: inc(stride)
for i in 0 .. <num:
for i in 0 ..< num:
result[i] = newSeq[T]()
for g in first .. <min(s.len, first + stride):
for g in first ..< min(s.len, first + stride):
result[i].add(s[g])
first += stride
else:
# Use an undercounting algorithm which *adds* the remainder each iteration.
for i in 0 .. <num:
for i in 0 ..< num:
last = first + stride
if extra > 0:
extra -= 1
inc(last)
result[i] = newSeq[T]()
for g in first .. <last:
for g in first ..< last:
result[i].add(s[g])
first = last
@@ -215,7 +215,7 @@ proc map*[T, S](s: openArray[T], op: proc (x: T): S {.closure.}):
## b = map(a, proc(x: int): string = $x)
## assert b == @["1", "2", "3", "4"]
newSeq(result, s.len)
for i in 0 .. <s.len:
for i in 0 ..< s.len:
result[i] = op(s[i])
proc map*[T](s: var openArray[T], op: proc (x: var T) {.closure.})
@@ -235,7 +235,7 @@ proc map*[T](s: var openArray[T], op: proc (x: var T) {.closure.})
## echo repr(a)
## # --> ["142", "242", "342", "442"]
## **Deprecated since version 0.12.0:** Use the ``apply`` proc instead.
for i in 0 .. <s.len: op(s[i])
for i in 0 ..< s.len: op(s[i])
proc apply*[T](s: var openArray[T], op: proc (x: var T) {.closure.})
{.inline.} =
@@ -255,7 +255,7 @@ proc apply*[T](s: var openArray[T], op: proc (x: var T) {.closure.})
## echo repr(a)
## # --> ["142", "242", "342", "442"]
##
for i in 0 .. <s.len: op(s[i])
for i in 0 ..< s.len: op(s[i])
proc apply*[T](s: var openArray[T], op: proc (x: T): T {.closure.})
{.inline.} =
@@ -275,7 +275,7 @@ proc apply*[T](s: var openArray[T], op: proc (x: T): T {.closure.})
## echo repr(a)
## # --> ["142", "242", "342", "442"]
##
for i in 0 .. <s.len: s[i] = op(s[i])
for i in 0 ..< s.len: s[i] = op(s[i])
iterator filter*[T](s: openArray[T], pred: proc(x: T): bool {.closure.}): T =
## Iterates through a container and yields every item that fulfills the
@@ -288,7 +288,7 @@ iterator filter*[T](s: openArray[T], pred: proc(x: T): bool {.closure.}): T =
## for n in filter(numbers, proc (x: int): bool = x mod 2 == 0):
## echo($n)
## # echoes 4, 8, 4 in separate lines
for i in 0 .. <s.len:
for i in 0 ..< s.len:
if pred(s[i]):
yield s[i]
@@ -306,7 +306,7 @@ proc filter*[T](s: openArray[T], pred: proc(x: T): bool {.closure.}): seq[T]
## assert f1 == @["red", "black"]
## assert f2 == @["yellow"]
result = newSeq[T]()
for i in 0 .. <s.len:
for i in 0 ..< s.len:
if pred(s[i]):
result.add(s[i])
@@ -322,7 +322,7 @@ proc keepIf*[T](s: var seq[T], pred: proc(x: T): bool {.closure.})
## keepIf(floats, proc(x: float): bool = x > 10)
## assert floats == @[13.0, 12.5, 10.1]
var pos = 0
for i in 0 .. <len(s):
for i in 0 ..< len(s):
if pred(s[i]):
if pos != i:
shallowCopy(s[pos], s[i])
@@ -413,7 +413,7 @@ template keepItIf*(varSeq: seq, pred: untyped) =
## keepItIf(candidates, it.len == 3 and it[0] == 'b')
## assert candidates == @["bar", "baz"]
var pos = 0
for i in 0 .. <len(varSeq):
for i in 0 ..< len(varSeq):
let it {.inject.} = varSeq[i]
if pred:
if pos != i:
@@ -680,7 +680,7 @@ template applyIt*(varSeq, op: untyped) =
## var nums = @[1, 2, 3, 4]
## nums.applyIt(it * 3)
## assert nums[0] + nums[3] == 15
for i in 0 .. <varSeq.len:
for i in 0 ..< varSeq.len:
let it {.inject.} = varSeq[i]
varSeq[i] = op
@@ -700,7 +700,7 @@ template newSeqWith*(len: int, init: untyped): untyped =
## var seqRand = newSeqWith(20, random(10))
## echo seqRand
var result = newSeq[type(init)](len)
for i in 0 .. <len:
for i in 0 ..< len:
result[i] = init
result

View File

@@ -652,13 +652,17 @@ proc sizeof*[T](x: T): int {.magic: "SizeOf", noSideEffect.}
when defined(nimtypedescfixed):
proc sizeof*(x: typedesc): int {.magic: "SizeOf", noSideEffect.}
proc `<`*[T](x: Ordinal[T]): T {.magic: "UnaryLt", noSideEffect.}
proc `<`*[T](x: Ordinal[T]): T {.magic: "UnaryLt", noSideEffect, deprecated.}
## unary ``<`` that can be used for nice looking excluding ranges:
##
## .. code-block:: nim
## for i in 0 .. <10: echo i #=> 0 1 2 3 4 5 6 7 8 9
##
## Semantically this is the same as ``pred``.
##
## **Deprecated since version 0.18.0**. For the common excluding range
## write ``0 ..< 10`` instead of ``0 .. < 10`` (look at the spacing).
## For ``<x`` write ``pred(x)``.
proc succ*[T](x: Ordinal[T], y = 1): T {.magic: "Succ", noSideEffect.}
## returns the ``y``-th successor of the value ``x``. ``T`` has to be
@@ -3410,6 +3414,30 @@ proc `/`*(x, y: int): float {.inline, noSideEffect.} =
## integer division that results in a float.
result = toFloat(x) / toFloat(y)
proc `^`*[T](x: int; y: openArray[T]): int {.noSideEffect, magic: "Roof".}
proc `^`*(x: int): int {.noSideEffect, magic: "Roof".} =
## builtin `roof`:idx: operator that can be used for convenient array access.
## ``a[^x]`` is rewritten to ``a[a.len-x]``. However currently the ``a``
## expression must not have side effects for this to compile. Note that since
## this is a builtin, it automatically works for all kinds of
## overloaded ``[]`` or ``[]=`` accessors.
discard
template `..^`*(a, b: untyped): untyped =
## a shortcut for '.. ^' to avoid the common gotcha that a space between
## '..' and '^' is required.
a .. ^b
template `..<`*(a, b: untyped): untyped {.dirty.} =
## a shortcut for 'a..pred(b)'.
a .. pred(b)
iterator `..<`*[S,T](a: S, b: T): T =
var i = T(a)
while i < b:
yield i
inc i
template spliceImpl(s, a, L, b: untyped): untyped =
# make room for additional elements or cut:
var shift = b.len - max(0,L) # ignore negative slice size
@@ -3423,7 +3451,7 @@ template spliceImpl(s, a, L, b: untyped): untyped =
# cut down:
setLen(s, newLen)
# fill the hole:
for i in 0 .. <b.len: s[a+i] = b[i]
for i in 0 ..< b.len: s[a+i] = b[i]
when hasAlloc or defined(nimscript):
proc `[]`*(s: string, x: Slice[int]): string {.inline.} =
@@ -3447,7 +3475,7 @@ when hasAlloc or defined(nimscript):
var a = x.a
var L = x.b - a + 1
if L == b.len:
for i in 0 .. <L: s[i+a] = b[i]
for i in 0..<L: s[i+a] = b[i]
else:
spliceImpl(s, a, L, b)
@@ -3462,7 +3490,7 @@ proc `[]`*[Idx, T](a: array[Idx, T], x: Slice[int]): seq[T] =
{.error: "Slicing for arrays with negative indices is unsupported.".}
var L = x.b - x.a + 1
result = newSeq[T](L)
for i in 0.. <L: result[i] = a[i + x.a]
for i in 0..<L: result[i] = a[i + x.a]
proc `[]=`*[Idx, T](a: var array[Idx, T], x: Slice[int], b: openArray[T]) =
## slice assignment for arrays.
@@ -3470,7 +3498,7 @@ proc `[]=`*[Idx, T](a: var array[Idx, T], x: Slice[int], b: openArray[T]) =
{.error: "Slicing for arrays with negative indices is unsupported.".}
var L = x.b - x.a + 1
if L == b.len:
for i in 0 .. <L: a[i+x.a] = b[i]
for i in 0..<L: a[i+x.a] = b[i]
else:
sysFatal(RangeError, "different lengths for slice assignment")
@@ -3478,14 +3506,14 @@ proc `[]`*[Idx, T](a: array[Idx, T], x: Slice[Idx]): seq[T] =
## slice operation for arrays.
var L = ord(x.b) - ord(x.a) + 1
newSeq(result, L)
for i in 0.. <L:
for i in 0..<L:
result[i] = a[Idx(ord(x.a) + i)]
proc `[]=`*[Idx, T](a: var array[Idx, T], x: Slice[Idx], b: openArray[T]) =
## slice assignment for arrays.
var L = ord(x.b) - ord(x.a) + 1
if L == b.len:
for i in 0 .. <L:
for i in 0..<L:
a[Idx(ord(x.a) + i)] = b[i]
else:
sysFatal(RangeError, "different lengths for slice assignment")
@@ -3500,7 +3528,7 @@ proc `[]`*[T](s: seq[T], x: Slice[int]): seq[T] =
var a = x.a
var L = x.b - a + 1
newSeq(result, L)
for i in 0.. <L: result[i] = s[i + a]
for i in 0 ..< L: result[i] = s[i + a]
proc `[]=`*[T](s: var seq[T], x: Slice[int], b: openArray[T]) =
## slice assignment for sequences. If
@@ -3509,7 +3537,7 @@ proc `[]=`*[T](s: var seq[T], x: Slice[int], b: openArray[T]) =
var a = x.a
var L = x.b - a + 1
if L == b.len:
for i in 0 .. <L: s[i+a] = b[i]
for i in 0 ..< L: s[i+a] = b[i]
else:
spliceImpl(s, a, L, b)
@@ -3853,31 +3881,6 @@ proc procCall*(x: untyped) {.magic: "ProcCall", compileTime.} =
## procCall someMethod(a, b)
discard
proc `^`*[T](x: int; y: openArray[T]): int {.noSideEffect, magic: "Roof".}
proc `^`*(x: int): int {.noSideEffect, magic: "Roof".} =
## builtin `roof`:idx: operator that can be used for convenient array access.
## ``a[^x]`` is rewritten to ``a[a.len-x]``. However currently the ``a``
## expression must not have side effects for this to compile. Note that since
## this is a builtin, it automatically works for all kinds of
## overloaded ``[]`` or ``[]=`` accessors.
discard
template `..^`*(a, b: untyped): untyped =
## a shortcut for '.. ^' to avoid the common gotcha that a space between
## '..' and '^' is required.
a .. ^b
template `..<`*(a, b: untyped): untyped {.dirty.} =
## a shortcut for '.. <' to avoid the common gotcha that a space between
## '..' and '<' is required.
a .. <b
iterator `..<`*[S,T](a: S, b: T): T =
var i = T(a)
while i < b:
yield i
inc i
proc xlen*(x: string): int {.magic: "XLenStr", noSideEffect.} = discard
proc xlen*[T](x: seq[T]): int {.magic: "XLenSeq", noSideEffect.} =
## returns the length of a sequence or a string without testing for 'nil'.

View File

@@ -3,7 +3,6 @@ version 1.0 battle plan
- make nimresolve part of the Nim compiler and add support for
'import staticExec()'
- deprecate unary '<'
- remove 'mod x' type rule
- implement x[^1] differently, no compiler magic
- fix "high priority" bugs
@@ -24,8 +23,6 @@ Not critical for 1.0
'static[T]' mess in the compiler!
- ``not`` or ``~`` for the effects system
- figure out why C++ bootstrapping is so much slower
- The bitwise 'not' operator cold be renamed to 'bnot' to
prevent 'not 4 == 5' from compiling. -> requires 'mixin' annotation for procs!
- make 'nil' work for 'add':
- resizeString
- incrSeq