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:
parent
b662842bd0
commit
7e747d11c6
109 changed files with 6115 additions and 6254 deletions
|
|
@ -162,11 +162,10 @@ proc getCurrOwner*(c: PContext): PSym =
|
|||
result = c.graph.owners[^1]
|
||||
|
||||
proc pushOwner*(c: PContext; owner: PSym) =
|
||||
add(c.graph.owners, owner)
|
||||
c.graph.owners.add(owner)
|
||||
|
||||
proc popOwner*(c: PContext) =
|
||||
var length = len(c.graph.owners)
|
||||
if length > 0: setLen(c.graph.owners, length - 1)
|
||||
if c.graph.owners.len > 0: setLen(c.graph.owners, c.graph.owners.len - 1)
|
||||
else: internalError(c.config, "popOwner")
|
||||
|
||||
proc lastOptionEntry*(c: PContext): POptionEntry =
|
||||
|
|
@ -203,7 +202,7 @@ proc considerGenSyms*(c: PContext; n: PNode) =
|
|||
n.sym = s
|
||||
else:
|
||||
for i in 0..<n.safeLen:
|
||||
considerGenSyms(c, n.sons[i])
|
||||
considerGenSyms(c, n[i])
|
||||
|
||||
proc newOptionEntry*(conf: ConfigRef): POptionEntry =
|
||||
new(result)
|
||||
|
|
@ -250,11 +249,9 @@ proc newContext*(graph: ModuleGraph; module: PSym): PContext =
|
|||
result.features = graph.config.features
|
||||
|
||||
proc inclSym(sq: var seq[PSym], s: PSym) =
|
||||
var L = len(sq)
|
||||
for i in 0 ..< L:
|
||||
for i in 0..<sq.len:
|
||||
if sq[i].id == s.id: return
|
||||
setLen(sq, L + 1)
|
||||
sq[L] = s
|
||||
sq.add s
|
||||
|
||||
proc addConverter*(c: PContext, conv: PSym) =
|
||||
inclSym(c.converters, conv)
|
||||
|
|
@ -407,8 +404,8 @@ proc makeRangeType*(c: PContext; first, last: BiggestInt;
|
|||
info: TLineInfo; intType: PType = nil): PType =
|
||||
let intType = if intType != nil: intType else: getSysType(c.graph, info, tyInt)
|
||||
var n = newNodeI(nkRange, info)
|
||||
addSon(n, newIntTypeNode(first, intType))
|
||||
addSon(n, newIntTypeNode(last, intType))
|
||||
n.add newIntTypeNode(first, intType)
|
||||
n.add newIntTypeNode(last, intType)
|
||||
result = newTypeS(tyRange, c)
|
||||
result.n = n
|
||||
addSonSkipIntLit(result, intType) # basetype of range
|
||||
|
|
@ -425,16 +422,16 @@ proc illFormedAstLocal*(n: PNode; conf: ConfigRef) =
|
|||
localError(conf, n.info, errIllFormedAstX, renderTree(n, {renderNoComments}))
|
||||
|
||||
proc checkSonsLen*(n: PNode, length: int; conf: ConfigRef) =
|
||||
if len(n) != length: illFormedAst(n, conf)
|
||||
if n.len != length: illFormedAst(n, conf)
|
||||
|
||||
proc checkMinSonsLen*(n: PNode, length: int; conf: ConfigRef) =
|
||||
if len(n) < length: illFormedAst(n, conf)
|
||||
if n.len < length: illFormedAst(n, conf)
|
||||
|
||||
proc isTopLevel*(c: PContext): bool {.inline.} =
|
||||
result = c.currentScope.depthLevel <= 2
|
||||
|
||||
proc pushCaseContext*(c: PContext, caseNode: PNode) =
|
||||
add(c.p.caseContext, (caseNode, 0))
|
||||
c.p.caseContext.add((caseNode, 0))
|
||||
|
||||
proc popCaseContext*(c: PContext) =
|
||||
discard pop(c.p.caseContext)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue