mirror of
https://github.com/nim-lang/Nim.git
synced 2026-07-12 04:09:34 +00:00
cleans up ast2nif.nim (#25604)
In `createTypeStub` proc, `k`, `itemId` and `suffix` are used only when `c.types.getOrDefault(name)[0]` returned nil. So moves them under `if result == nil:` branch. In `extractLocalSymsFromTree` proc, removes unnecessary `inc depth` and `dec depth`.
This commit is contained in:
@@ -910,20 +910,20 @@ proc loadSymFromCursor(c: var DecodeContext; s: PSym; n: var Cursor; thisModule:
|
|||||||
proc createTypeStub(c: var DecodeContext; t: SymId): PType =
|
proc createTypeStub(c: var DecodeContext; t: SymId): PType =
|
||||||
let name = pool.syms[t]
|
let name = pool.syms[t]
|
||||||
assert name.startsWith("`t")
|
assert name.startsWith("`t")
|
||||||
var i = len("`t")
|
|
||||||
var k = 0
|
|
||||||
while i < name.len and name[i] in {'0'..'9'}:
|
|
||||||
k = k * 10 + name[i].ord - ord('0')
|
|
||||||
inc i
|
|
||||||
if i < name.len and name[i] == '.': inc i
|
|
||||||
var itemId = 0'i32
|
|
||||||
while i < name.len and name[i] in {'0'..'9'}:
|
|
||||||
itemId = itemId * 10'i32 + int32(name[i].ord - ord('0'))
|
|
||||||
inc i
|
|
||||||
if i < name.len and name[i] == '.': inc i
|
|
||||||
let suffix = name.substr(i)
|
|
||||||
result = c.types.getOrDefault(name)[0]
|
result = c.types.getOrDefault(name)[0]
|
||||||
if result == nil:
|
if result == nil:
|
||||||
|
var i = len("`t")
|
||||||
|
var k = 0
|
||||||
|
while i < name.len and name[i] in {'0'..'9'}:
|
||||||
|
k = k * 10 + name[i].ord - ord('0')
|
||||||
|
inc i
|
||||||
|
if i < name.len and name[i] == '.': inc i
|
||||||
|
var itemId = 0'i32
|
||||||
|
while i < name.len and name[i] in {'0'..'9'}:
|
||||||
|
itemId = itemId * 10'i32 + int32(name[i].ord - ord('0'))
|
||||||
|
inc i
|
||||||
|
if i < name.len and name[i] == '.': inc i
|
||||||
|
let suffix = name.substr(i)
|
||||||
let id = ItemId(module: moduleId(c, suffix).int32, item: itemId)
|
let id = ItemId(module: moduleId(c, suffix).int32, item: itemId)
|
||||||
let offs = c.getOffset(id.module.FileIndex, name)
|
let offs = c.getOffset(id.module.FileIndex, name)
|
||||||
result = PType(itemId: id, uniqueId: id, kind: TTypeKind(k), state: Partial)
|
result = PType(itemId: id, uniqueId: id, kind: TTypeKind(k), state: Partial)
|
||||||
@@ -944,30 +944,26 @@ proc extractLocalSymsFromTree(c: var DecodeContext; n: var Cursor; thisModule: s
|
|||||||
if n.tagId == sdefTag:
|
if n.tagId == sdefTag:
|
||||||
# Found an sdef - check if it's local
|
# Found an sdef - check if it's local
|
||||||
let name = n.firstSon
|
let name = n.firstSon
|
||||||
if name.kind == SymbolDef:
|
expect name, SymbolDef
|
||||||
let symName = pool.syms[name.symId]
|
let symName = pool.syms[name.symId]
|
||||||
let sn = parseSymName(symName)
|
let sn = parseSymName(symName)
|
||||||
if sn.module.len == 0 and symName notin localSyms:
|
if sn.module.len == 0 and symName notin localSyms:
|
||||||
# Local symbol - create stub and immediately load it fully
|
# Local symbol - create stub and immediately load it fully
|
||||||
# since local symbols have no index offsets for lazy loading
|
# since local symbols have no index offsets for lazy loading
|
||||||
let module = moduleId(c, thisModule)
|
let module = moduleId(c, thisModule)
|
||||||
let val = addr c.mods[module].symCounter
|
let val = addr c.mods[module].symCounter
|
||||||
inc val[]
|
inc val[]
|
||||||
let id = ItemId(module: module.int32, item: val[])
|
let id = ItemId(module: module.int32, item: val[])
|
||||||
let sym = PSym(itemId: id, kindImpl: skStub, name: c.cache.getIdent(sn.name),
|
let sym = PSym(itemId: id, kindImpl: skStub, name: c.cache.getIdent(sn.name),
|
||||||
disamb: sn.count.int32, state: Complete)
|
disamb: sn.count.int32, state: Complete)
|
||||||
localSyms[symName] = sym
|
localSyms[symName] = sym
|
||||||
# Load the full symbol definition immediately
|
# Load the full symbol definition immediately
|
||||||
# We're currently at the `(sd` position, need to skip to SymbolDef
|
# We're currently at the `(sd` position, need to skip to SymbolDef
|
||||||
inc n # skip past `sd` tag to get to SymbolDef
|
inc n # skip past `sd` tag to get to SymbolDef
|
||||||
inc depth # account for the opening `(` of the sdef
|
loadSymFromCursor(c, sym, n, thisModule, localSyms)
|
||||||
loadSymFromCursor(c, sym, n, thisModule, localSyms)
|
sym.state = Sealed # mark as fully loaded
|
||||||
sym.state = Sealed # mark as fully loaded
|
# Continue processing - loadSymFromCursor already advanced n past the closing `)`
|
||||||
# loadSymFromCursor consumed everything including the closing `)`,
|
continue
|
||||||
# so we need to account for it in depth tracking
|
|
||||||
dec depth
|
|
||||||
# Continue processing - loadSymFromCursor already advanced n past the closing `)`
|
|
||||||
continue
|
|
||||||
inc depth
|
inc depth
|
||||||
elif n.kind == ParRi:
|
elif n.kind == ParRi:
|
||||||
dec depth
|
dec depth
|
||||||
|
|||||||
Reference in New Issue
Block a user