Small ast.nim cleanup (#12156)

* Remove sonsLen
* Use Indexable
This commit is contained in:
Clyybber 2019-09-09 11:54:15 +02:00 • committed by Andreas Rumpf
commit ed1d41c51e
54 changed files with 559 additions and 573 deletions

View file

@ -120,7 +120,7 @@ proc hashType(c: var MD5Context, t: PType) =
case t.kind
of tyGenericBody, tyGenericInst, tyGenericInvocation:
for i in 0 ..< sonsLen(t)-ord(t.kind != tyGenericInvocation):
for i in 0 ..< len(t)-ord(t.kind != tyGenericInvocation):
c.hashType t.sons[i]
of tyUserTypeClass:
internalAssert t.sym != nil and t.sym.owner != nil
@ -128,7 +128,7 @@ proc hashType(c: var MD5Context, t: PType) =
of tyUserTypeClassInst:
let body = t.base
c.hashSym body.sym
for i in 1 .. sonsLen(t) - 2:
for i in 1 .. len(t) - 2:
c.hashType t.sons[i]
of tyFromExpr:
c.hashTree(t.n)
@ -137,15 +137,15 @@ proc hashType(c: var MD5Context, t: PType) =
c.hashType(t.sons[1])
of tyTuple:
if t.n != nil:
assert(sonsLen(t.n) == sonsLen(t))
for i in 0 ..< sonsLen(t.n):
assert(len(t.n) == len(t))
for i in 0 ..< len(t.n):
assert(t.n.sons[i].kind == nkSym)
c &= t.n.sons[i].sym.name.s
c &= ":"
c.hashType(t.sons[i])
c &= ","
else:
for i in 0 ..< sonsLen(t): c.hashType t.sons[i]
for i in 0 ..< len(t): c.hashType t.sons[i]
of tyRange:
c.hashTree(t.n)
c.hashType(t.sons[0])
@ -238,7 +238,7 @@ proc encodeNode(w: PRodWriter, fInfo: TLineInfo, n: PNode,
encodeVInt(n.sym.id, result)
pushSym(w, n.sym)
else:
for i in 0 ..< sonsLen(n):
for i in 0 ..< len(n):
encodeNode(w, n.info, n.sons[i], result)
add(result, ')')
@ -304,7 +304,7 @@ proc encodeType(w: PRodWriter, t: PType, result: var string) =
add(result, '=')
encodeVInt(t.align, result)
encodeLoc(w, t.loc, result)
for i in 0 ..< sonsLen(t):
for i in 0 ..< len(t):
if t.sons[i] == nil:
add(result, "^()")
else: