diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2023-12-13 10:29:58 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-13 10:29:58 +0100 |
commit | e51e98997ba0aae748ff51eea8133e83370a7df5 (patch) | |
tree | 6df6ec97662bf49d13cda7d33f1b451f9e45aa98 /compiler/sempass2.nim | |
parent | df6cb645f7834de0c43afe2deb023c3e01093503 (diff) | |
download | Nim-e51e98997ba0aae748ff51eea8133e83370a7df5.tar.gz |
type refactoring: part 2 (#23059)
Diffstat (limited to 'compiler/sempass2.nim')
-rw-r--r-- | compiler/sempass2.nim | 24 |
1 files changed, 9 insertions, 15 deletions
diff --git a/compiler/sempass2.nim b/compiler/sempass2.nim index 448f4d26a..8fc218955 100644 --- a/compiler/sempass2.nim +++ b/compiler/sempass2.nim @@ -24,9 +24,6 @@ when defined(useDfa): import liftdestructors include sinkparameter_inference - -import std/options as opt - #[ Second semantic checking pass over the AST. Necessary because the old way had some inherent problems. Performs: @@ -94,29 +91,26 @@ const errXCannotBeAssignedTo = "'$1' cannot be assigned to" errLetNeedsInit = "'let' symbol requires an initialization" -proc getObjDepth(t: PType): Option[tuple[depth: int, root: ItemId]] = +proc getObjDepth(t: PType): (int, ItemId) = var x = t - var res: tuple[depth: int, root: ItemId] - res.depth = -1 + result = (-1, default(ItemId)) var stack = newSeq[ItemId]() while x != nil: x = skipTypes(x, skipPtrs) if x.kind != tyObject: - return none(tuple[depth: int, root: ItemId]) + return (-3, default(ItemId)) stack.add x.itemId - x = x[0] - inc(res.depth) - res.root = stack[^2] - result = some(res) + x = x.baseClass + inc(result[0]) + result[1] = stack[^2] proc collectObjectTree(graph: ModuleGraph, n: PNode) = for section in n: if section.kind == nkTypeDef and section[^1].kind in {nkObjectTy, nkRefTy, nkPtrTy}: let typ = section[^1].typ.skipTypes(skipPtrs) - if typ.len > 0 and typ[0] != nil: - let depthItem = getObjDepth(typ) - if isSome(depthItem): - let (depthLevel, root) = depthItem.unsafeGet + if typ.kind == tyObject and typ.baseClass != nil: + let (depthLevel, root) = getObjDepth(typ) + if depthLevel != -3: if depthLevel == 1: graph.objectTree[root] = @[] else: |