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

@ -275,7 +275,7 @@ template wholeSymTab(cond, section: untyped) {.dirty.} =
pm, c.inTypeContext > 0, scopeN))
proc suggestSymList(c: PContext, list, f: PNode; info: TLineInfo, outputs: var Suggestions) =
for i in 0 ..< sonsLen(list):
for i in 0 ..< len(list):
if list.sons[i].kind == nkSym:
suggestField(c, list.sons[i].sym, f, info, outputs)
#else: InternalError(list.info, "getSymFromList")
@ -283,9 +283,9 @@ proc suggestSymList(c: PContext, list, f: PNode; info: TLineInfo, outputs: var S
proc suggestObject(c: PContext, n, f: PNode; info: TLineInfo, outputs: var Suggestions) =
case n.kind
of nkRecList:
for i in 0 ..< sonsLen(n): suggestObject(c, n.sons[i], f, info, outputs)
for i in 0 ..< len(n): suggestObject(c, n.sons[i], f, info, outputs)
of nkRecCase:
var L = sonsLen(n)
var L = len(n)
if L > 0:
suggestObject(c, n.sons[0], f, info, outputs)
for i in 1 ..< L: suggestObject(c, lastSon(n.sons[i]), f, info, outputs)
@ -318,7 +318,7 @@ proc suggestCall(c: PContext, n, nOrig: PNode, outputs: var Suggestions) =
ideCon)
proc typeFits(c: PContext, s: PSym, firstArg: PType): bool {.inline.} =
if s.typ != nil and sonsLen(s.typ) > 1 and s.typ.sons[1] != nil:
if s.typ != nil and len(s.typ) > 1 and s.typ.sons[1] != nil:
# special rule: if system and some weird generic match via 'tyUntyped'
# or 'tyGenericParam' we won't list it either to reduce the noise (nobody
# wants 'system.`-|` as suggestion
@ -595,7 +595,7 @@ proc suggestExprNoCheck*(c: PContext, n: PNode) =
var x = safeSemExpr(c, n.sons[0])
if x.kind == nkEmpty or x.typ == nil: x = n.sons[0]
addSon(a, x)
for i in 1..sonsLen(n)-1:
for i in 1..len(n)-1:
# use as many typed arguments as possible:
var x = safeSemExpr(c, n.sons[i])
if x.kind == nkEmpty or x.typ == nil: break