refactorings

This commit is contained in:
Araq
2025-12-12 07:43:38 +01:00
parent 97ebe740e8
commit e1b56cc5f8
5 changed files with 12 additions and 18 deletions

View File

@@ -82,9 +82,6 @@ proc setOwner*(s: PType; owner: PSym) {.inline.} =
if s.state == Partial: loadType(s)
s.ownerFieldImpl = owner
# Accessor procs for TSym fields
# Note: kind is kept as a direct field for case statement compatibility
# but we still provide an accessor that checks state
proc kind*(s: PSym): TSymKind {.inline.} =
if s.state == Partial: loadSym(s)
result = s.kindImpl

View File

@@ -61,7 +61,7 @@ proc hcrOn(p: BProc): bool = p.module.config.hcrOn
proc addForwardedProc(m: BModule, prc: PSym) =
m.g.forwardedProcs.add(prc)
proc newModule*(g: BModuleList; module: PSym; conf: ConfigRef): BModule
proc newModule*(g: BModuleList; module: PSym; conf: ConfigRef; idgen: IdGenerator): BModule
proc findPendingModule(m: BModule, s: PSym): BModule =
# TODO fixme
@@ -72,7 +72,7 @@ proc findPendingModule(m: BModule, s: PSym): BModule =
var ms = getModule(s)
result = m.g.modules[ms.position]
if result == nil:
result = newModule(m.g, ms, m.config)
result = newModule(m.g, ms, m.config, idGeneratorFromModule(ms))
proc initLoc(k: TLocKind, lode: PNode, s: TStorageLoc, flags: TLocFlags = {}): TLoc =
result = TLoc(k: k, storage: s, lode: lode,
@@ -2372,9 +2372,10 @@ proc rawNewModule(g: BModuleList; module: PSym, filename: AbsoluteFile): BModule
proc rawNewModule(g: BModuleList; module: PSym; conf: ConfigRef): BModule =
result = rawNewModule(g, module, AbsoluteFile toFullPath(conf, module.position.FileIndex))
proc newModule(g: BModuleList; module: PSym; conf: ConfigRef): BModule =
proc newModule(g: BModuleList; module: PSym; conf: ConfigRef; idgen: IdGenerator): BModule =
# we should create only one cgen module for each module sym
result = rawNewModule(g, module, conf)
result.idgen = idgen
if module.position >= g.modules.len:
setLen(g.modules, module.position + 1)
#growCache g.modules, module.position
@@ -2387,8 +2388,7 @@ template injectG() {.dirty.} =
proc setupCgen*(graph: ModuleGraph; module: PSym; idgen: IdGenerator): PPassContext =
injectG()
result = newModule(g, module, graph.config)
result.idgen = idgen
result = newModule(g, module, graph.config, idgen)
if optGenIndex in graph.config.globalOptions and g.generatedHeader == nil:
let f = if graph.config.headerFile.len > 0: AbsoluteFile graph.config.headerFile
else: graph.config.projectFull

View File

@@ -37,8 +37,7 @@ proc setupBackendModule(g: ModuleGraph; m: var LoadedModule) =
if g.backend == nil:
g.backend = cgendata.newModuleList(g)
assert g.backend != nil
var bmod = cgen.newModule(BModuleList(g.backend), m.module, g.config)
bmod.idgen = idgenFromLoadedModule(m)
var bmod = cgen.newModule(BModuleList(g.backend), m.module, g.config, idgenFromLoadedModule(m))
proc generateCodeForModule(g: ModuleGraph; m: var LoadedModule; alive: var AliveSyms) =
var bmod = BModuleList(g.backend).modules[m.module.position]

View File

@@ -52,7 +52,7 @@ proc setupNifBackendModule(g: ModuleGraph; module: PSym): BModule =
## Set up a BModule for code generation from a NIF module.
if g.backend == nil:
g.backend = cgendata.newModuleList(g)
result = cgen.newModule(BModuleList(g.backend), module, g.config)
result = cgen.newModule(BModuleList(g.backend), module, g.config, idGeneratorFromModule(module))
proc generateCodeForModule(g: ModuleGraph; module: PSym) =
## Generate C code for a single module.

View File

@@ -65,16 +65,14 @@ proc newTransNode(a: PNode): PNode {.inline.} =
proc newTransNode(kind: TNodeKind, info: TLineInfo,
sons: int): PNode {.inline.} =
var x = newNodeI(kind, info)
newSeq(x.sons, sons)
result = x
result = newNodeI(kind, info)
newSeq(result.sons, sons)
proc newTransNode(kind: TNodeKind, n: PNode,
sons: int): PNode {.inline.} =
var x = newNodeIT(kind, n.info, n.typ)
newSeq(x.sons, sons)
# x.flags = n.flags
result = x
result = newNodeIT(kind, n.info, n.typ)
newSeq(result.sons, sons)
# x.flags = n.flags
proc newTransCon(owner: PSym): PTransCon =
assert owner != nil