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

@ -160,14 +160,14 @@ proc lookupInRecord(n: PNode, field: PIdent): PSym =
result = nil
case n.kind
of nkRecList:
for i in 0 ..< sonsLen(n):
for i in 0 ..< len(n):
result = lookupInRecord(n.sons[i], field)
if result != nil: return
of nkRecCase:
if (n.sons[0].kind != nkSym): return nil
result = lookupInRecord(n.sons[0], field)
if result != nil: return
for i in 1 ..< sonsLen(n):
for i in 1 ..< len(n):
case n.sons[i].kind
of nkOfBranch, nkElse:
result = lookupInRecord(lastSon(n.sons[i]), field)
@ -183,7 +183,7 @@ proc getModule*(s: PSym): PSym =
while result != nil and result.kind != skModule: result = result.owner
proc getSymFromList*(list: PNode, ident: PIdent, start: int = 0): PSym =
for i in start ..< sonsLen(list):
for i in start ..< len(list):
if list.sons[i].kind == nkSym:
result = list.sons[i].sym
if result.name.id == ident.id: return
@ -326,9 +326,9 @@ proc typeToYamlAux(conf: ConfigRef; n: PType, marker: var IntSet, indent: int,
sonsRope = "\"$1 @$2\"" % [rope($n.kind), rope(
strutils.toHex(cast[ByteAddress](n), sizeof(n) * 2))]
else:
if sonsLen(n) > 0:
if len(n) > 0:
sonsRope = rope("[")
for i in 0 ..< sonsLen(n):
for i in 0 ..< len(n):
if i > 0: add(sonsRope, ",")
addf(sonsRope, "$N$1$2", [rspaces(indent + 4), typeToYamlAux(conf, n.sons[i],
marker, indent + 4, maxRecDepth - 1)])
@ -375,9 +375,9 @@ proc treeToYamlAux(conf: ConfigRef; n: PNode, marker: var IntSet, indent: int,
else:
addf(result, ",$N$1\"ident\": null", [istr])
else:
if sonsLen(n) > 0:
if len(n) > 0:
addf(result, ",$N$1\"sons\": [", [istr])
for i in 0 ..< sonsLen(n):
for i in 0 ..< len(n):
if i > 0: add(result, ",")
addf(result, "$N$1$2", [rspaces(indent + 4), treeToYamlAux(conf, n.sons[i],
marker, indent + 4, maxRecDepth - 1)])
@ -562,12 +562,12 @@ proc value(this: var DebugPrinter; value: PType) =
this.key "n"
this.value value.n
if sonsLen(value) > 0:
if len(value) > 0:
this.key "sons"
this.openBracket
for i in 0 ..< sonsLen(value):
for i in 0 ..< len(value):
this.value value.sons[i]
if i != sonsLen(value) - 1:
if i != len(value) - 1:
this.comma
this.closeBracket
@ -615,12 +615,12 @@ proc value(this: var DebugPrinter; value: PNode) =
if this.renderSymType and value.typ != nil:
this.key "typ"
this.value value.typ
if sonsLen(value) > 0:
if len(value) > 0:
this.key "sons"
this.openBracket
for i in 0 ..< sonsLen(value):
for i in 0 ..< len(value):
this.value value.sons[i]
if i != sonsLen(value) - 1:
if i != len(value) - 1:
this.comma
this.closeBracket