mirror of
https://github.com/nim-lang/Nim.git
synced 2026-08-29 01:51:43 +00:00
prepare for dependency tracking
This commit is contained in:
@@ -115,6 +115,7 @@ let
|
||||
type
|
||||
Writer = object
|
||||
dest: TokenBuf
|
||||
deps: TokenBuf
|
||||
inner: LineInfoWriter
|
||||
currentModule: int32
|
||||
writtenSyms: HashSet[ItemId]
|
||||
@@ -282,6 +283,12 @@ proc addLocalSyms(w: var Writer; n: PNode) =
|
||||
elif n.kind == nkSym:
|
||||
addLocalSym(w, n)
|
||||
|
||||
proc trInclude(w: var Writer; n: PNode) =
|
||||
discard
|
||||
|
||||
proc trImport(w: var Writer; n: PNode) =
|
||||
discard
|
||||
|
||||
proc writeNode(w: var Writer; n: PNode) =
|
||||
if n == nil:
|
||||
w.dest.addDotToken
|
||||
@@ -348,6 +355,11 @@ proc writeNode(w: var Writer; n: PNode) =
|
||||
for i in 0 ..< ast.len:
|
||||
writeNode(w, ast[i])
|
||||
dec w.inProc
|
||||
of nkImportStmt:
|
||||
# this has been transformed for us, see `importer.nim` to contain a list of module syms:
|
||||
trImport w, n
|
||||
of nkIncludeStmt:
|
||||
trInclude w, n
|
||||
else:
|
||||
w.withNode(n):
|
||||
for i in 0 ..< n.len:
|
||||
|
||||
@@ -2801,7 +2801,7 @@ proc semMacroDef(c: PContext, n: PNode): PNode =
|
||||
if n[bodyPos].kind == nkEmpty:
|
||||
localError(c.config, n.info, errImplOfXexpected % s.name.s)
|
||||
|
||||
proc incMod(c: PContext, n: PNode, it: PNode, includeStmtResult: PNode) =
|
||||
proc incMod(c: PContext, n: PNode, it: PNode, includeStmtResult, resolvedIncStmt: PNode) =
|
||||
var f = checkModuleName(c.config, it)
|
||||
if f != InvalidFileIdx:
|
||||
addIncludeFileDep(c, f)
|
||||
@@ -2809,12 +2809,22 @@ proc incMod(c: PContext, n: PNode, it: PNode, includeStmtResult: PNode) =
|
||||
if containsOrIncl(c.includedFiles, f.int):
|
||||
localError(c.config, n.info, errRecursiveDependencyX % toMsgFilename(c.config, f))
|
||||
else:
|
||||
if resolvedIncStmt != nil:
|
||||
resolvedIncStmt.add newStrNode(toFullPath(c.config, f), it.info)
|
||||
includeStmtResult.add semStmt(c, c.graph.includeFileCallback(c.graph, c.module, f), {})
|
||||
excl(c.includedFiles, f.int)
|
||||
|
||||
proc evalInclude(c: PContext, n: PNode): PNode =
|
||||
result = newNodeI(nkStmtList, n.info)
|
||||
result.add n
|
||||
var resolvedIncStmt: PNode = nil
|
||||
if optCompress in c.config.globalOptions:
|
||||
# New resolve the include filenames to string literals that contain absolute paths,
|
||||
# nicer for IC:
|
||||
resolvedIncStmt = newNodeI(nkIncludeStmt, n.info)
|
||||
result.add resolvedIncStmt
|
||||
else:
|
||||
# Legacy: Keep `include` statement as is:
|
||||
result.add n
|
||||
template checkAs(it: PNode) =
|
||||
if it.kind == nkInfix and it.len == 3:
|
||||
let op = it[0].getPIdent
|
||||
@@ -2832,9 +2842,9 @@ proc evalInclude(c: PContext, n: PNode): PNode =
|
||||
for x in it[lastPos]:
|
||||
checkAs(x)
|
||||
imp[lastPos] = x
|
||||
incMod(c, n, imp, result)
|
||||
incMod(c, n, imp, result, resolvedIncStmt)
|
||||
else:
|
||||
incMod(c, n, it, result)
|
||||
incMod(c, n, it, result, resolvedIncStmt)
|
||||
|
||||
proc recursiveSetFlag(n: PNode, flag: TNodeFlag) =
|
||||
if n != nil:
|
||||
|
||||
Reference in New Issue
Block a user