Cosmetic compiler cleanup (#12718)

* Cleanup compiler code base

* Unify add calls

* Unify len invocations

* Unify range operators

* Fix oversight

* Remove {.procvar.} pragma

* initCandidate -> newCandidate where reasonable

* Unify safeLen calls
This commit is contained in:
Clyybber 2019-11-28 17:13:04 +01:00 • committed by Andreas Rumpf
commit 7e747d11c6
109 changed files with 6115 additions and 6254 deletions

View file

@ -16,17 +16,17 @@ proc ithField(n: PNode, field: var int): PSym =
result = nil
case n.kind
of nkRecList:
for i in 0 ..< len(n):
result = ithField(n.sons[i], field)
for i in 0..<n.len:
result = ithField(n[i], field)
if result != nil: return
of nkRecCase:
if n.sons[0].kind != nkSym: return
result = ithField(n.sons[0], field)
if n[0].kind != nkSym: return
result = ithField(n[0], field)
if result != nil: return
for i in 1 ..< len(n):
case n.sons[i].kind
for i in 1..<n.len:
case n[i].kind
of nkOfBranch, nkElse:
result = ithField(lastSon(n.sons[i]), field)
result = ithField(lastSon(n[i]), field)
if result != nil: return
else: discard
of nkSym:
@ -35,12 +35,12 @@ proc ithField(n: PNode, field: var int): PSym =
else: discard
proc ithField(t: PType, field: var int): PSym =
var base = t.sons[0]
var base = t[0]
while base != nil:
let b = skipTypes(base, skipPtrs)
result = ithField(b.n, field)
if result != nil: return result
base = b.sons[0]
base = b[0]
result = ithField(t.n, field)
proc annotateType*(n: PNode, t: PType; conf: ConfigRef) =
@ -51,20 +51,20 @@ proc annotateType*(n: PNode, t: PType; conf: ConfigRef) =
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.ithField(j)
if field.isNil:
globalError conf, n.info, "invalid field at index " & $i
else:
internalAssert(conf, n.sons[i].kind == nkExprColonExpr)
annotateType(n.sons[i].sons[1], field.typ, conf)
internalAssert(conf, n[i].kind == nkExprColonExpr)
annotateType(n[i][1], field.typ, conf)
of nkPar, nkTupleConstr:
if x.kind == tyTuple:
n.typ = t
for i in 0 ..< n.len:
for i in 0..<n.len:
if i >= x.len: globalError conf, n.info, "invalid field at index " & $i
else: annotateType(n.sons[i], x.sons[i], conf)
else: annotateType(n[i], x[i], conf)
elif x.kind == tyProc and x.callConv == ccClosure:
n.typ = t
else: