reorder.nim: fixes the indentation
This commit is contained in:
parent
ea761419ad
commit
336f1e63d0
1 changed files with 39 additions and 40 deletions
|
|
@ -100,10 +100,9 @@ proc computeDeps(cache: IdentCache; n: PNode, declares, uses: var IntSet; topLev
|
||||||
for i in 0..<n.len: computeDeps(cache, n[i], declares, uses, topLevel)
|
for i in 0..<n.len: computeDeps(cache, n[i], declares, uses, topLevel)
|
||||||
of nkPragma:
|
of nkPragma:
|
||||||
let a = n[0]
|
let a = n[0]
|
||||||
if a.kind == nkExprColonExpr and a[0].kind == nkIdent and
|
if a.kind == nkExprColonExpr and a[0].kind == nkIdent and a[0].ident.s == "pragma":
|
||||||
a[0].ident.s == "pragma":
|
# user defined pragma
|
||||||
# user defined pragma
|
decl(a[1])
|
||||||
decl(a[1])
|
|
||||||
else:
|
else:
|
||||||
for i in 0..<n.safeLen: deps(n[i])
|
for i in 0..<n.safeLen: deps(n[i])
|
||||||
else:
|
else:
|
||||||
|
|
@ -209,42 +208,42 @@ proc mergeSections(conf: ConfigRef; comps: seq[seq[DepN]], res: PNode) =
|
||||||
sn.add dn.pnode[0]
|
sn.add dn.pnode[0]
|
||||||
res.add sn
|
res.add sn
|
||||||
else:
|
else:
|
||||||
# Problematic circular dependency, we arrange the nodes into
|
# Problematic circular dependency, we arrange the nodes into
|
||||||
# their original relative order and make sure to re-merge
|
# their original relative order and make sure to re-merge
|
||||||
# consecutive type and const sections
|
# consecutive type and const sections
|
||||||
var wmsg = "Circular dependency detected. `codeReordering` pragma may not be able to" &
|
var wmsg = "Circular dependency detected. `codeReordering` pragma may not be able to" &
|
||||||
" reorder some nodes properely"
|
" reorder some nodes properely"
|
||||||
when defined(debugReorder):
|
when defined(debugReorder):
|
||||||
wmsg &= ":\n"
|
wmsg &= ":\n"
|
||||||
for i in 0..<cs.len-1:
|
for i in 0..<cs.len-1:
|
||||||
for j in i..<cs.len:
|
for j in i..<cs.len:
|
||||||
for ci in 0..<cs[i].kids.len:
|
for ci in 0..<cs[i].kids.len:
|
||||||
if cs[i].kids[ci].id == cs[j].id:
|
if cs[i].kids[ci].id == cs[j].id:
|
||||||
wmsg &= "line " & $cs[i].pnode.info.line &
|
wmsg &= "line " & $cs[i].pnode.info.line &
|
||||||
" depends on line " & $cs[j].pnode.info.line &
|
" depends on line " & $cs[j].pnode.info.line &
|
||||||
": " & cs[i].expls[ci] & "\n"
|
": " & cs[i].expls[ci] & "\n"
|
||||||
for j in 0..<cs.len-1:
|
for j in 0..<cs.len-1:
|
||||||
for ci in 0..<cs[^1].kids.len:
|
for ci in 0..<cs[^1].kids.len:
|
||||||
if cs[^1].kids[ci].id == cs[j].id:
|
if cs[^1].kids[ci].id == cs[j].id:
|
||||||
wmsg &= "line " & $cs[^1].pnode.info.line &
|
wmsg &= "line " & $cs[^1].pnode.info.line &
|
||||||
" depends on line " & $cs[j].pnode.info.line &
|
" depends on line " & $cs[j].pnode.info.line &
|
||||||
": " & cs[^1].expls[ci] & "\n"
|
": " & cs[^1].expls[ci] & "\n"
|
||||||
message(conf, cs[0].pnode.info, warnUser, wmsg)
|
message(conf, cs[0].pnode.info, warnUser, wmsg)
|
||||||
|
|
||||||
var i = 0
|
var i = 0
|
||||||
while i < cs.len:
|
while i < cs.len:
|
||||||
if cs[i].pnode.kind in {nkTypeSection, nkConstSection}:
|
if cs[i].pnode.kind in {nkTypeSection, nkConstSection}:
|
||||||
let ckind = cs[i].pnode.kind
|
let ckind = cs[i].pnode.kind
|
||||||
var sn = newNode(ckind)
|
var sn = newNode(ckind)
|
||||||
|
sn.add cs[i].pnode[0]
|
||||||
|
inc i
|
||||||
|
while i < cs.len and cs[i].pnode.kind == ckind:
|
||||||
sn.add cs[i].pnode[0]
|
sn.add cs[i].pnode[0]
|
||||||
inc i
|
inc i
|
||||||
while i < cs.len and cs[i].pnode.kind == ckind:
|
res.add sn
|
||||||
sn.add cs[i].pnode[0]
|
else:
|
||||||
inc i
|
res.add cs[i].pnode
|
||||||
res.add sn
|
inc i
|
||||||
else:
|
|
||||||
res.add cs[i].pnode
|
|
||||||
inc i
|
|
||||||
|
|
||||||
proc hasImportStmt(n: PNode): bool =
|
proc hasImportStmt(n: PNode): bool =
|
||||||
# Checks if the node is an import statement or
|
# Checks if the node is an import statement or
|
||||||
|
|
@ -291,7 +290,7 @@ proc hasAccQuoted(n: PNode): bool =
|
||||||
if hasAccQuoted(a):
|
if hasAccQuoted(a):
|
||||||
return true
|
return true
|
||||||
|
|
||||||
const extandedProcDefs = procDefs + {nkMacroDef, nkTemplateDef}
|
const extandedProcDefs = procDefs + {nkMacroDef, nkTemplateDef}
|
||||||
|
|
||||||
proc hasAccQuotedDef(n: PNode): bool =
|
proc hasAccQuotedDef(n: PNode): bool =
|
||||||
# Checks if the node is a function, macro, template ...
|
# Checks if the node is a function, macro, template ...
|
||||||
|
|
@ -301,7 +300,7 @@ proc hasAccQuotedDef(n: PNode): bool =
|
||||||
result = n[0].hasAccQuoted
|
result = n[0].hasAccQuoted
|
||||||
of nkStmtList, nkStmtListExpr, nkWhenStmt, nkElifBranch, nkElse, nkStaticStmt:
|
of nkStmtList, nkStmtListExpr, nkWhenStmt, nkElifBranch, nkElse, nkStaticStmt:
|
||||||
for a in n:
|
for a in n:
|
||||||
if a.hasAccQuotedDef:
|
if hasAccQuotedDef(a):
|
||||||
return true
|
return true
|
||||||
else:
|
else:
|
||||||
result = false
|
result = false
|
||||||
|
|
@ -423,7 +422,7 @@ proc hasForbiddenPragma(n: PNode): bool =
|
||||||
for a in n:
|
for a in n:
|
||||||
if a.kind == nkPragma and a[0].kind == nkIdent and
|
if a.kind == nkPragma and a[0].kind == nkIdent and
|
||||||
a[0].ident.s == "push":
|
a[0].ident.s == "push":
|
||||||
return true
|
return true
|
||||||
|
|
||||||
proc reorder*(graph: ModuleGraph, n: PNode, module: PSym): PNode =
|
proc reorder*(graph: ModuleGraph, n: PNode, module: PSym): PNode =
|
||||||
if n.hasForbiddenPragma:
|
if n.hasForbiddenPragma:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue