Small cleanup (#11185)

* Remove mStaticTy and mTypeTy

* Replace countup(x, y-1) with x ..< y

* Replace countup(x, y) with x .. y
This commit is contained in:
Andreas Rumpf 2019-05-08 17:18:46 +02:00 • committed by GitHub
commit 61380d0a07
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
65 changed files with 418 additions and 424 deletions

View file

@ -102,7 +102,7 @@ proc getProcHeader*(conf: ConfigRef; sym: PSym; prefer: TPreferedDesc = preferNa
if sym.kind in routineKinds:
result.add '('
var n = sym.typ.n
for i in countup(1, sonsLen(n) - 1):
for i in 1 ..< sonsLen(n):
let p = n.sons[i]
if p.kind == nkSym:
add(result, p.sym.name.s)
@ -150,7 +150,7 @@ proc iterOverNode(marker: var IntSet, n: PNode, iter: TTypeIter,
# a leaf
result = iterOverTypeAux(marker, n.typ, iter, closure)
else:
for i in countup(0, sonsLen(n) - 1):
for i in 0 ..< sonsLen(n):
result = iterOverNode(marker, n.sons[i], iter, closure)
if result: return
@ -165,7 +165,7 @@ proc iterOverTypeAux(marker: var IntSet, t: PType, iter: TTypeIter,
of tyGenericInst, tyGenericBody, tyAlias, tySink, tyInferred:
result = iterOverTypeAux(marker, lastSon(t), iter, closure)
else:
for i in countup(0, sonsLen(t) - 1):
for i in 0 ..< sonsLen(t):
result = iterOverTypeAux(marker, t.sons[i], iter, closure)
if result: return
if t.n != nil: result = iterOverNode(marker, t.n, iter, closure)
@ -182,14 +182,14 @@ proc searchTypeNodeForAux(n: PNode, p: TTypePredicate,
result = false
case n.kind
of nkRecList:
for i in countup(0, sonsLen(n) - 1):
for i in 0 ..< sonsLen(n):
result = searchTypeNodeForAux(n.sons[i], p, marker)
if result: return
of nkRecCase:
assert(n.sons[0].kind == nkSym)
result = searchTypeNodeForAux(n.sons[0], p, marker)
if result: return
for i in countup(1, sonsLen(n) - 1):
for i in 1 ..< sonsLen(n):
case n.sons[i].kind
of nkOfBranch, nkElse:
result = searchTypeNodeForAux(lastSon(n.sons[i]), p, marker)
@ -215,7 +215,7 @@ proc searchTypeForAux(t: PType, predicate: TTypePredicate,
of tyGenericInst, tyDistinct, tyAlias, tySink:
result = searchTypeForAux(lastSon(t), predicate, marker)
of tyArray, tySet, tyTuple:
for i in countup(0, sonsLen(t) - 1):
for i in 0 ..< sonsLen(t):
result = searchTypeForAux(t.sons[i], predicate, marker)
if result: return
else:
@ -252,7 +252,7 @@ proc analyseObjectWithTypeFieldAux(t: PType,
if t.n != nil:
if searchTypeNodeForAux(t.n, isObjectWithTypeFieldPredicate, marker):
return frEmbedded
for i in countup(0, sonsLen(t) - 1):
for i in 0 ..< sonsLen(t):
var x = t.sons[i]
if x != nil: x = x.skipTypes(skipPtrs)
res = analyseObjectWithTypeFieldAux(x, marker)
@ -264,7 +264,7 @@ proc analyseObjectWithTypeFieldAux(t: PType,
of tyGenericInst, tyDistinct, tyAlias, tySink:
result = analyseObjectWithTypeFieldAux(lastSon(t), marker)
of tyArray, tyTuple:
for i in countup(0, sonsLen(t) - 1):
for i in 0 ..< sonsLen(t):
res = analyseObjectWithTypeFieldAux(t.sons[i], marker)
if res != frNone:
return frEmbedded
@ -314,7 +314,7 @@ proc canFormAcycleNode(marker: var IntSet, n: PNode, startId: int): bool =
of nkNone..nkNilLit:
discard
else:
for i in countup(0, sonsLen(n) - 1):
for i in 0 ..< sonsLen(n):
result = canFormAcycleNode(marker, n.sons[i], startId)
if result: return
@ -325,7 +325,7 @@ proc canFormAcycleAux(marker: var IntSet, typ: PType, startId: int): bool =
case t.kind
of tyTuple, tyObject, tyRef, tySequence, tyArray, tyOpenArray, tyVarargs:
if not containsOrIncl(marker, t.id):
for i in countup(0, sonsLen(t) - 1):
for i in 0 ..< sonsLen(t):
result = canFormAcycleAux(marker, t.sons[i], startId)
if result: return
if t.n != nil: result = canFormAcycleNode(marker, t.n, startId)
@ -361,7 +361,7 @@ proc mutateNode(marker: var IntSet, n: PNode, iter: TTypeMutator,
# a leaf
discard
else:
for i in countup(0, sonsLen(n) - 1):
for i in 0 ..< sonsLen(n):
addSon(result, mutateNode(marker, n.sons[i], iter, closure))
proc mutateTypeAux(marker: var IntSet, t: PType, iter: TTypeMutator,
@ -370,7 +370,7 @@ proc mutateTypeAux(marker: var IntSet, t: PType, iter: TTypeMutator,
if t == nil: return
result = iter(t, closure)
if not containsOrIncl(marker, t.id):
for i in countup(0, sonsLen(t) - 1):
for i in 0 ..< sonsLen(t):
result.sons[i] = mutateTypeAux(marker, result.sons[i], iter, closure)
if t.n != nil: result.n = mutateNode(marker, t.n, iter, closure)
assert(result != nil)
@ -459,13 +459,13 @@ proc typeToString(typ: PType, prefer: TPreferedDesc = preferName): string =
result = "int literal(" & $t.n.intVal & ")"
of tyGenericInst, tyGenericInvocation:
result = typeToString(t.sons[0]) & '['
for i in countup(1, sonsLen(t)-1-ord(t.kind != tyGenericInvocation)):
for i in 1 ..< sonsLen(t)-ord(t.kind != tyGenericInvocation):
if i > 1: add(result, ", ")
add(result, typeToString(t.sons[i], preferGenericArg))
add(result, ']')
of tyGenericBody:
result = typeToString(t.lastSon) & '['
for i in countup(0, sonsLen(t)-2):
for i in 0 .. sonsLen(t)-2:
if i > 0: add(result, ", ")
add(result, typeToString(t.sons[i], preferTypeName))
add(result, ']')
@ -506,7 +506,7 @@ proc typeToString(typ: PType, prefer: TPreferedDesc = preferName): string =
of tyUserTypeClassInst:
let body = t.base
result = body.sym.name.s & "["
for i in countup(1, sonsLen(t) - 2):
for i in 1 .. sonsLen(t) - 2:
if i > 1: add(result, ", ")
add(result, typeToString(t.sons[i]))
result.add "]"
@ -557,7 +557,7 @@ proc typeToString(typ: PType, prefer: TPreferedDesc = preferName): string =
if t.n != nil:
result = "tuple["
assert(sonsLen(t.n) == sonsLen(t))
for i in countup(0, sonsLen(t.n) - 1):
for i in 0 ..< sonsLen(t.n):
assert(t.n.sons[i].kind == nkSym)
add(result, t.n.sons[i].sym.name.s & ": " & typeToString(t.sons[i]))
if i < sonsLen(t.n) - 1: add(result, ", ")
@ -567,7 +567,7 @@ proc typeToString(typ: PType, prefer: TPreferedDesc = preferName): string =
else:
if prefer == preferTypeName: result = "("
else: result = "tuple of ("
for i in countup(0, sonsLen(t) - 1):
for i in 0 ..< sonsLen(t):
add(result, typeToString(t.sons[i]))
if i < sonsLen(t) - 1: add(result, ", ")
add(result, ')')
@ -576,7 +576,7 @@ proc typeToString(typ: PType, prefer: TPreferedDesc = preferName): string =
if t.len >= 2:
setLen(result, result.len-1)
result.add '['
for i in countup(0, sonsLen(t) - 1):
for i in 0 ..< sonsLen(t):
add(result, typeToString(t.sons[i]))
if i < sonsLen(t) - 1: add(result, ", ")
result.add ']'
@ -600,7 +600,7 @@ proc typeToString(typ: PType, prefer: TPreferedDesc = preferName): string =
"proc "
if tfUnresolved in t.flags: result.add "[*missing parameters*]"
result.add "("
for i in countup(1, sonsLen(t) - 1):
for i in 1 ..< sonsLen(t):
if t.n != nil and i < t.n.len and t.n[i].kind == nkSym:
add(result, t.n[i].sym.name.s)
add(result, ": ")
@ -843,7 +843,7 @@ proc equalParams(a, b: PNode): TParamsEquality =
if length != sonsLen(b):
result = paramsNotEqual
else:
for i in countup(1, length - 1):
for i in 1 ..< length:
var m = a.sons[i].sym
var n = b.sons[i].sym
assert((m.kind == skParam) and (n.kind == skParam))
@ -872,7 +872,7 @@ proc sameTuple(a, b: PType, c: var TSameTypeClosure): bool =
# complicates the matter a bit.
if sonsLen(a) == sonsLen(b):
result = true
for i in countup(0, sonsLen(a) - 1):
for i in 0 ..< sonsLen(a):
var x = a.sons[i]
var y = b.sons[i]
if IgnoreTupleFields in c.flags:
@ -882,7 +882,7 @@ proc sameTuple(a, b: PType, c: var TSameTypeClosure): bool =
result = sameTypeAux(x, y, c)
if not result: return
if a.n != nil and b.n != nil and IgnoreTupleFields notin c.flags:
for i in countup(0, sonsLen(a.n) - 1):
for i in 0 ..< sonsLen(a.n):
# check field names:
if a.n.sons[i].kind == nkSym and b.n.sons[i].kind == nkSym:
var x = a.n.sons[i].sym
@ -946,14 +946,14 @@ proc sameObjectTree(a, b: PNode, c: var TSameTypeClosure): bool =
of nkEmpty, nkNilLit, nkType: result = true
else:
if sonsLen(a) == sonsLen(b):
for i in countup(0, sonsLen(a) - 1):
for i in 0 ..< sonsLen(a):
if not sameObjectTree(a.sons[i], b.sons[i], c): return
result = true
proc sameObjectStructures(a, b: PType, c: var TSameTypeClosure): bool =
# check base types:
if sonsLen(a) != sonsLen(b): return
for i in countup(0, sonsLen(a) - 1):
for i in 0 ..< sonsLen(a):
if not sameTypeOrNilAux(a.sons[i], b.sons[i], c): return
if not sameObjectTree(a.n, b.n, c): return
result = true
@ -961,7 +961,7 @@ proc sameObjectStructures(a, b: PType, c: var TSameTypeClosure): bool =
proc sameChildrenAux(a, b: PType, c: var TSameTypeClosure): bool =
if sonsLen(a) != sonsLen(b): return false
result = true
for i in countup(0, sonsLen(a) - 1):
for i in 0 ..< sonsLen(a):
result = sameTypeOrNilAux(a.sons[i], b.sons[i], c)
if not result: return
@ -1168,7 +1168,7 @@ proc typeAllowedNode(marker: var IntSet, n: PNode, kind: TSymKind,
else:
if n.kind == nkRecCase and kind in {skProc, skFunc, skConst}:
return n[0].typ
for i in countup(0, sonsLen(n) - 1):
for i in 0 ..< sonsLen(n):
let it = n.sons[i]
result = typeAllowedNode(marker, it, kind, flags)
if result != nil: break
@ -1207,7 +1207,7 @@ proc typeAllowedAux(marker: var IntSet, typ: PType, kind: TSymKind,
else: result = typeAllowedAux(marker, t2, kind, flags)
of tyProc:
if kind == skConst and t.callConv == ccClosure: return t
for i in countup(1, sonsLen(t) - 1):
for i in 1 ..< sonsLen(t):
result = typeAllowedAux(marker, t.sons[i], skParam, flags)
if result != nil: break
if result.isNil and t.sons[0] != nil:
@ -1266,14 +1266,14 @@ proc typeAllowedAux(marker: var IntSet, typ: PType, kind: TSymKind,
of tyPtr:
result = typeAllowedAux(marker, t.lastSon, skVar, flags+{taHeap})
of tySet:
for i in countup(0, sonsLen(t) - 1):
for i in 0 ..< sonsLen(t):
result = typeAllowedAux(marker, t.sons[i], kind, flags)
if result != nil: break
of tyObject, tyTuple:
if kind in {skProc, skFunc, skConst} and
t.kind == tyObject and t.sons[0] != nil: return t
let flags = flags+{taField}
for i in countup(0, sonsLen(t) - 1):
for i in 0 ..< sonsLen(t):
result = typeAllowedAux(marker, t.sons[i], kind, flags)
if result != nil: break
if result.isNil and t.n != nil: