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
|
|
@ -14,14 +14,14 @@ import
|
|||
ast, astalgo, msgs, semdata, types, trees, strutils
|
||||
|
||||
proc equalGenericParams(procA, procB: PNode): bool =
|
||||
if len(procA) != len(procB): return false
|
||||
for i in 0 ..< len(procA):
|
||||
if procA.sons[i].kind != nkSym:
|
||||
if procA.len != procB.len: return false
|
||||
for i in 0..<procA.len:
|
||||
if procA[i].kind != nkSym:
|
||||
return false
|
||||
if procB.sons[i].kind != nkSym:
|
||||
if procB[i].kind != nkSym:
|
||||
return false
|
||||
let a = procA.sons[i].sym
|
||||
let b = procB.sons[i].sym
|
||||
let a = procA[i].sym
|
||||
let b = procB[i].sym
|
||||
if a.name.id != b.name.id or
|
||||
not sameTypeOrNil(a.typ, b.typ, {ExactTypeDescValues}): return
|
||||
if a.ast != nil and b.ast != nil:
|
||||
|
|
@ -40,11 +40,11 @@ proc searchForProcOld*(c: PContext, scope: PScope, fn: PSym): PSym =
|
|||
# not kept in the AST ..
|
||||
while result != nil:
|
||||
if result.kind == fn.kind and isGenericRoutine(result):
|
||||
let genR = result.ast.sons[genericParamsPos]
|
||||
let genF = fn.ast.sons[genericParamsPos]
|
||||
let genR = result.ast[genericParamsPos]
|
||||
let genF = fn.ast[genericParamsPos]
|
||||
if exprStructuralEquivalent(genR, genF) and
|
||||
exprStructuralEquivalent(result.ast.sons[paramsPos],
|
||||
fn.ast.sons[paramsPos]) and
|
||||
exprStructuralEquivalent(result.ast[paramsPos],
|
||||
fn.ast[paramsPos]) and
|
||||
equalGenericParams(genR, genF):
|
||||
return
|
||||
result = nextIdentIter(it, scope.symbols)
|
||||
|
|
@ -95,15 +95,14 @@ proc searchForProc*(c: PContext, scope: PScope, fn: PSym): PSym =
|
|||
|
||||
when false:
|
||||
proc paramsFitBorrow(child, parent: PNode): bool =
|
||||
var length = len(child)
|
||||
result = false
|
||||
if length == len(parent):
|
||||
for i in 1 ..< length:
|
||||
var m = child.sons[i].sym
|
||||
var n = parent.sons[i].sym
|
||||
if child.len == parent.len:
|
||||
for i in 1..<child.len:
|
||||
var m = child[i].sym
|
||||
var n = parent[i].sym
|
||||
assert((m.kind == skParam) and (n.kind == skParam))
|
||||
if not compareTypes(m.typ, n.typ, dcEqOrDistinctOf): return
|
||||
if not compareTypes(child.sons[0].typ, parent.sons[0].typ,
|
||||
if not compareTypes(child[0].typ, parent[0].typ,
|
||||
dcEqOrDistinctOf): return
|
||||
result = true
|
||||
|
||||
|
|
@ -116,7 +115,7 @@ when false:
|
|||
while result != nil:
|
||||
# watchout! result must not be the same as fn!
|
||||
if (result.Kind == fn.kind) and (result.id != fn.id):
|
||||
if equalGenericParams(result.ast.sons[genericParamsPos],
|
||||
fn.ast.sons[genericParamsPos]):
|
||||
if equalGenericParams(result.ast[genericParamsPos],
|
||||
fn.ast[genericParamsPos]):
|
||||
if paramsFitBorrow(fn.typ.n, result.typ.n): return
|
||||
result = NextIdentIter(it, scope.symbols)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue