Skip to content

Commit

Permalink
Cosmetic: Move nkError to the front of of branches
Browse files Browse the repository at this point in the history
  • Loading branch information
Clyybber committed Mar 8, 2024
1 parent 35da9be commit 32ce9cc
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions compiler/ast/treetab.nim
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ proc hashTree*(n: PNode): Hash =
return
result = ord(n.kind)
case n.kind
of nkEmpty, nkNilLit, nkType, nkCommentStmt, nkError:
of nkError, nkEmpty, nkNilLit, nkType, nkCommentStmt:
discard
of nkIdent:
result = result !& n.ident.h
Expand All @@ -43,7 +43,7 @@ proc treesEquivalent(a, b: PNode): bool =
result = true
elif (a != nil) and (b != nil) and (a.kind == b.kind):
case a.kind
of nkEmpty, nkNilLit, nkType, nkCommentStmt, nkError: result = true
of nkError, nkEmpty, nkNilLit, nkType, nkCommentStmt: result = true
of nkSym: result = a.sym.id == b.sym.id
of nkIdent: result = a.ident.id == b.ident.id
of nkIntLiterals: result = a.intVal == b.intVal
Expand Down
6 changes: 3 additions & 3 deletions compiler/ic/ic.nim
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ proc toString*(tree: PackedTree; n: NodePos; m: PackedModule; nesting: int;

result.add $tree[pos].kind
case tree.nodes[pos].kind
of nkEmpty, nkNilLit, nkType, nkCommentStmt, nkError: discard
of nkError, nkEmpty, nkNilLit, nkType, nkCommentStmt: discard
of nkIdent, nkStrLiterals:
result.add " "
result.add m.strings[LitId tree.nodes[pos].operand]
Expand Down Expand Up @@ -446,7 +446,7 @@ proc toPackedNode*(n: PNode; ir: var PackedTree; c: var PackedEncoder; m: var Pa
return
let info = toPackedInfo(n.info, c, m)
case n.kind
of nkEmpty, nkNilLit, nkType, nkCommentStmt, nkError:
of nkError, nkEmpty, nkNilLit, nkType, nkCommentStmt:
ir.nodes.add PackedNode(kind: n.kind, flags: n.flags, operand: 0,
typeId: storeTypeLater(n.typ, c, m), info: info)
of nkIdent:
Expand Down Expand Up @@ -776,7 +776,7 @@ proc loadNodes*(c: var PackedDecoder; g: var PackedModuleGraph; thisModule: int;
result.flags = n.flags

case k
of nkEmpty, nkNilLit, nkType, nkCommentStmt, nkError:
of nkError, nkEmpty, nkNilLit, nkType, nkCommentStmt:
discard
of nkIdent:
result.ident = getIdent(c.cache, g[thisModule].fromDisk.strings[n.litId])
Expand Down
4 changes: 2 additions & 2 deletions compiler/sem/guards.nim
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,8 @@ proc sameTree*(a, b: PNode): bool =
result = true
elif a != nil and b != nil and a.kind == b.kind:
case a.kind
of nkError:
unreachable()
of nkSym:
result = a.sym == b.sym
if not result and a.sym.magic != mNone:
Expand All @@ -458,8 +460,6 @@ proc sameTree*(a, b: PNode): bool =
of nkType: result = a.typ == b.typ
of nkEmpty, nkNilLit, nkCommentStmt:
result = true # Ignore comments
of nkError:
unreachable()
of nkWithSons:
if a.len == b.len:
for i in 0..<a.len:
Expand Down
6 changes: 3 additions & 3 deletions compiler/sem/patterns.nim
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ proc sameTrees*(a, b: PNode): bool =
of nkIntLiterals: result = a.intVal == b.intVal
of nkFloatLiterals: result = a.floatVal == b.floatVal
of nkStrLiterals: result = a.strVal == b.strVal
of nkEmpty, nkNilLit, nkCommentStmt, nkError:
of nkError, nkEmpty, nkNilLit, nkCommentStmt:
result = true # XXX: Should nkCommentStmt, nkError be handled?
of nkType: result = sameTypeOrNil(a.typ, b.typ)
of nkWithSons:
Expand Down Expand Up @@ -180,15 +180,15 @@ proc matches(c: PPatternContext, p, n: PNode): bool =
result = bindOrCheck(c, p[1].sym, n)
elif sameKinds(p, n):
case p.kind
of nkError:
unreachable()
of nkSym: result = p.sym == n.sym
of nkIdent: result = p.ident.id == n.ident.id
of nkIntLiterals: result = p.intVal == n.intVal
of nkFloatLiterals: result = p.floatVal == n.floatVal
of nkStrLiterals: result = p.strVal == n.strVal
of nkEmpty, nkNilLit, nkType, nkCommentStmt:
result = true # Ignore comments
of nkError:
unreachable()
of nkWithSons:
# special rule for p(X) ~ f(...); this also works for stuff like
# partial case statements, etc! - Not really ... :-/
Expand Down
2 changes: 1 addition & 1 deletion compiler/sem/sem.nim
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ proc tryConstExpr(c: PContext, n: PNode): PNode =

result = evalConstExpr(c.module, c.idgen, c.graph, result)
case result.kind
of nkEmpty, nkError:
of nkError, nkEmpty:
result = nil
else:
discard
Expand Down
8 changes: 4 additions & 4 deletions compiler/sem/sighashes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ proc hashTree(c: var MD5Context, n: PNode; flags: set[ConsiderFlag]) =
# we really must not hash line information. 'n.typ' is debatable but
# shouldn't be necessary for now and avoids potential infinite recursions.
case n.kind
of nkEmpty, nkNilLit, nkType, nkCommentStmt:
discard # ignore comments (could appear in a tyFromExpr)
of nkError:
unreachable()
of nkEmpty, nkNilLit, nkType, nkCommentStmt:
discard # ignore comments (could appear in a tyFromExpr)
of nkIdent:
c &= n.ident.s
of nkSym:
Expand Down Expand Up @@ -354,10 +354,10 @@ proc hashBodyTree(graph: ModuleGraph, c: var MD5Context, n: PNode) =
return
c &= char(n.kind)
case n.kind
of nkEmpty, nkNilLit, nkType, nkCommentStmt:
discard # ignore comments
of nkError:
unreachable()
of nkEmpty, nkNilLit, nkType, nkCommentStmt:
discard # ignore comments
of nkIdent:
c &= n.ident.s
of nkSym:
Expand Down

0 comments on commit 32ce9cc

Please sign in to comment.