mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-30 01:44:37 +00:00
use an auxiliary map
This commit is contained in:
@@ -14,6 +14,7 @@ import
|
||||
semdata, modulepaths, sigmatch, lineinfos,
|
||||
modulegraphs, wordrecg
|
||||
from std/strutils import `%`, startsWith
|
||||
from std/sequtils import addUnique
|
||||
import std/[sets, tables, intsets]
|
||||
|
||||
when defined(nimPreviewSlimSystem):
|
||||
@@ -255,7 +256,7 @@ proc importModuleAs(c: PContext; n: PNode, realModule: PSym, importHidden, track
|
||||
if trackUnusedImport:
|
||||
c.unusedImports.add((result, result.info))
|
||||
c.importModuleMap[result.id] = realModule.id
|
||||
c.importModuleLookup.mgetOrPut(result.name.id, @[]).addUniqueModule(realModule.id, result.info)
|
||||
c.importModuleLookup.mgetOrPut(result.name.id, @[]).addUnique realModule.id
|
||||
|
||||
proc transformImportAs(c: PContext; n: PNode): tuple[node: PNode, importHidden: bool] =
|
||||
result = (nil, false)
|
||||
@@ -339,13 +340,13 @@ proc afterImport(c: PContext, m: PSym) =
|
||||
|
||||
proc impMod(c: PContext; it: PNode; importStmtResult: PNode) =
|
||||
var it = it
|
||||
var oldImportModuleMap = c.importModuleLookup
|
||||
let m = myImportModule(c, it, importStmtResult)
|
||||
if m != nil:
|
||||
# ``addDecl`` needs to be done before ``importAllSymbols``!
|
||||
swap oldImportModuleMap, c.importModuleLookup
|
||||
addDecl(c, m) # add symbol to symbol table of module
|
||||
swap oldImportModuleMap, c.importModuleLookup
|
||||
|
||||
let realModuleId = c.importModuleMap[m.id]
|
||||
c.importModuleLookupInfo.mgetOrPut(m.name.id, @[]).addUniqueModule(realModuleId, m.info)
|
||||
importAllSymbols(c, m)
|
||||
#importForwarded(c, m.ast, emptySet, m)
|
||||
afterImport(c, m)
|
||||
|
||||
@@ -397,8 +397,8 @@ proc addDeclAt*(c: PContext; scope: PScope, sym: PSym, info: TLineInfo) =
|
||||
localError(c.config, info, hintDuplicateModuleImport,
|
||||
"duplicate import of '$1'; previous import here: $2" %
|
||||
[sym.name.s, c.config $ conflict.info])
|
||||
else:
|
||||
for (module, prevInfo) in c.importModuleLookup[sym.name.id]:
|
||||
elif sym.name.id in c.importModuleLookupInfo:
|
||||
for (module, prevInfo) in c.importModuleLookupInfo[sym.name.id]:
|
||||
if c.importModuleMap[sym.id] == module:
|
||||
localError(c.config, info, hintDuplicateModuleImport,
|
||||
"duplicate import of '$1'; previous import here: $2" %
|
||||
|
||||
@@ -171,7 +171,8 @@ type
|
||||
lastTLineInfo*: TLineInfo
|
||||
sideEffects*: Table[int, seq[(TLineInfo, PSym)]] # symbol.id index
|
||||
inUncheckedAssignSection*: int
|
||||
importModuleLookup*: Table[int, seq[(int, TLineInfo)]] # (module.ident.id, [module.id])
|
||||
importModuleLookup*: Table[int, seq[int]] # (module.ident.id, [module.id])
|
||||
importModuleLookupInfo*: Table[int, seq[(int, TLineInfo)]] # (module.ident.id, [module.id])
|
||||
forwardTypeUpdates*: seq[(PType, PNode)]
|
||||
# types that need to be updated in a type section
|
||||
# due to containing forward types, and their corresponding nodes
|
||||
|
||||
Reference in New Issue
Block a user