refactoring: make projectMainIdx typesafe
This commit is contained in:
parent
40ec7be45c
commit
545b1582cd
7 changed files with 17 additions and 21 deletions
|
|
@ -33,22 +33,22 @@ when declared(echo):
|
||||||
|
|
||||||
template mdbg*: bool {.dirty.} =
|
template mdbg*: bool {.dirty.} =
|
||||||
when compiles(c.module):
|
when compiles(c.module):
|
||||||
c.module.fileIdx.int32 == c.config.projectMainIdx
|
c.module.fileIdx == c.config.projectMainIdx
|
||||||
elif compiles(c.c.module):
|
elif compiles(c.c.module):
|
||||||
c.c.module.fileIdx.int32 == c.c.config.projectMainIdx
|
c.c.module.fileIdx == c.c.config.projectMainIdx
|
||||||
elif compiles(m.c.module):
|
elif compiles(m.c.module):
|
||||||
m.c.module.fileIdx.int32 == m.c.config.projectMainIdx
|
m.c.module.fileIdx == m.c.config.projectMainIdx
|
||||||
elif compiles(cl.c.module):
|
elif compiles(cl.c.module):
|
||||||
cl.c.module.fileIdx.int32 == cl.c.config.projectMainIdx
|
cl.c.module.fileIdx == cl.c.config.projectMainIdx
|
||||||
elif compiles(p):
|
elif compiles(p):
|
||||||
when compiles(p.lex):
|
when compiles(p.lex):
|
||||||
p.lex.fileIdx.int32 == p.lex.config.projectMainIdx
|
p.lex.fileIdx == p.lex.config.projectMainIdx
|
||||||
else:
|
else:
|
||||||
p.module.module.fileIdx.int32 == p.config.projectMainIdx
|
p.module.module.fileIdx == p.config.projectMainIdx
|
||||||
elif compiles(m.module.fileIdx):
|
elif compiles(m.module.fileIdx):
|
||||||
m.module.fileIdx.int32 == m.config.projectMainIdx
|
m.module.fileIdx == m.config.projectMainIdx
|
||||||
elif compiles(L.fileIdx):
|
elif compiles(L.fileIdx):
|
||||||
L.fileIdx.int32 == L.config.projectMainIdx
|
L.fileIdx == L.config.projectMainIdx
|
||||||
else:
|
else:
|
||||||
error()
|
error()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -807,7 +807,7 @@ proc writeOutputJson*(d: PDoc, filename, outExt: string,
|
||||||
discard "fixme: error report"
|
discard "fixme: error report"
|
||||||
|
|
||||||
proc commandDoc*(cache: IdentCache, conf: ConfigRef) =
|
proc commandDoc*(cache: IdentCache, conf: ConfigRef) =
|
||||||
var ast = parseFile(conf.projectMainIdx.FileIndex, newIdentCache(), conf)
|
var ast = parseFile(conf.projectMainIdx, cache, conf)
|
||||||
if ast == nil: return
|
if ast == nil: return
|
||||||
var d = newDocumentor(conf.projectFull, cache, conf)
|
var d = newDocumentor(conf.projectFull, cache, conf)
|
||||||
d.hasToc = true
|
d.hasToc = true
|
||||||
|
|
@ -857,7 +857,7 @@ proc commandRst2TeX*(cache: IdentCache, conf: ConfigRef) =
|
||||||
commandRstAux(cache, conf, conf.projectFull, TexExt)
|
commandRstAux(cache, conf, conf.projectFull, TexExt)
|
||||||
|
|
||||||
proc commandJson*(cache: IdentCache, conf: ConfigRef) =
|
proc commandJson*(cache: IdentCache, conf: ConfigRef) =
|
||||||
var ast = parseFile(conf.projectMainIdx.FileIndex, newIdentCache(), conf)
|
var ast = parseFile(conf.projectMainIdx, cache, conf)
|
||||||
if ast == nil: return
|
if ast == nil: return
|
||||||
var d = newDocumentor(conf.projectFull, cache, conf)
|
var d = newDocumentor(conf.projectFull, cache, conf)
|
||||||
d.hasToc = true
|
d.hasToc = true
|
||||||
|
|
@ -874,7 +874,7 @@ proc commandJson*(cache: IdentCache, conf: ConfigRef) =
|
||||||
rawMessage(conf, errCannotOpenFile, filename)
|
rawMessage(conf, errCannotOpenFile, filename)
|
||||||
|
|
||||||
proc commandTags*(cache: IdentCache, conf: ConfigRef) =
|
proc commandTags*(cache: IdentCache, conf: ConfigRef) =
|
||||||
var ast = parseFile(conf.projectMainIdx.FileIndex, newIdentCache(), conf)
|
var ast = parseFile(conf.projectMainIdx, cache, conf)
|
||||||
if ast == nil: return
|
if ast == nil: return
|
||||||
var d = newDocumentor(conf.projectFull, cache, conf)
|
var d = newDocumentor(conf.projectFull, cache, conf)
|
||||||
d.hasToc = true
|
d.hasToc = true
|
||||||
|
|
|
||||||
|
|
@ -261,7 +261,7 @@ proc mainCommand*(graph: ModuleGraph; cache: IdentCache) =
|
||||||
of "parse":
|
of "parse":
|
||||||
conf.cmd = cmdParse
|
conf.cmd = cmdParse
|
||||||
wantMainModule(conf)
|
wantMainModule(conf)
|
||||||
discard parseFile(FileIndex conf.projectMainIdx, cache, conf)
|
discard parseFile(conf.projectMainIdx, cache, conf)
|
||||||
of "scan":
|
of "scan":
|
||||||
conf.cmd = cmdScan
|
conf.cmd = cmdScan
|
||||||
wantMainModule(conf)
|
wantMainModule(conf)
|
||||||
|
|
|
||||||
|
|
@ -124,7 +124,7 @@ proc compileSystemModule*(graph: ModuleGraph; cache: IdentCache) =
|
||||||
proc wantMainModule*(conf: ConfigRef) =
|
proc wantMainModule*(conf: ConfigRef) =
|
||||||
if conf.projectFull.len == 0:
|
if conf.projectFull.len == 0:
|
||||||
fatal(conf, newLineInfo(conf, "command line", 1, 1), errGenerated, "command expects a filename")
|
fatal(conf, newLineInfo(conf, "command line", 1, 1), errGenerated, "command expects a filename")
|
||||||
conf.projectMainIdx = int32 fileInfoIdx(conf, addFileExt(conf.projectFull, NimExt))
|
conf.projectMainIdx = fileInfoIdx(conf, addFileExt(conf.projectFull, NimExt))
|
||||||
|
|
||||||
passes.gIncludeFile = includeModule
|
passes.gIncludeFile = includeModule
|
||||||
passes.gImportModule = importModule
|
passes.gImportModule = importModule
|
||||||
|
|
@ -134,7 +134,7 @@ proc compileProject*(graph: ModuleGraph; cache: IdentCache;
|
||||||
let conf = graph.config
|
let conf = graph.config
|
||||||
wantMainModule(conf)
|
wantMainModule(conf)
|
||||||
let systemFileIdx = fileInfoIdx(conf, conf.libpath / "system.nim")
|
let systemFileIdx = fileInfoIdx(conf, conf.libpath / "system.nim")
|
||||||
let projectFile = if projectFileIdx == InvalidFileIDX: FileIndex(conf.projectMainIdx) else: projectFileIdx
|
let projectFile = if projectFileIdx == InvalidFileIDX: conf.projectMainIdx else: projectFileIdx
|
||||||
graph.importStack.add projectFile
|
graph.importStack.add projectFile
|
||||||
if projectFile == systemFileIdx:
|
if projectFile == systemFileIdx:
|
||||||
discard graph.compileModule(projectFile, cache, {sfMainModule, sfSystemModule})
|
discard graph.compileModule(projectFile, cache, {sfMainModule, sfSystemModule})
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,7 @@ proc handleCmdLine(cache: IdentCache; conf: ConfigRef) =
|
||||||
conf.projectName = p.name
|
conf.projectName = p.name
|
||||||
else:
|
else:
|
||||||
conf.projectPath = canonicalizePath(conf, getCurrentDir())
|
conf.projectPath = canonicalizePath(conf, getCurrentDir())
|
||||||
loadConfigs(DefaultConfig, conf) # load all config files
|
loadConfigs(DefaultConfig, cache, conf) # load all config files
|
||||||
let scriptFile = conf.projectFull.changeFileExt("nims")
|
let scriptFile = conf.projectFull.changeFileExt("nims")
|
||||||
if fileExists(scriptFile):
|
if fileExists(scriptFile):
|
||||||
runNimScript(cache, scriptFile, freshDefines=false, conf)
|
runNimScript(cache, scriptFile, freshDefines=false, conf)
|
||||||
|
|
|
||||||
|
|
@ -253,7 +253,3 @@ proc loadConfigs*(cfg: string; cache: IdentCache; conf: ConfigRef) =
|
||||||
if not fileExists(projectConfig):
|
if not fileExists(projectConfig):
|
||||||
projectConfig = changeFileExt(conf.projectFull, "nim.cfg")
|
projectConfig = changeFileExt(conf.projectFull, "nim.cfg")
|
||||||
readConfigFile(projectConfig, cache, conf)
|
readConfigFile(projectConfig, cache, conf)
|
||||||
|
|
||||||
proc loadConfigs*(cfg: string; conf: ConfigRef) =
|
|
||||||
# for backwards compatibility only.
|
|
||||||
loadConfigs(cfg, newIdentCache(), conf)
|
|
||||||
|
|
|
||||||
|
|
@ -204,7 +204,7 @@ type
|
||||||
projectPath*: string # holds a path like /home/alice/projects/nim/compiler/
|
projectPath*: string # holds a path like /home/alice/projects/nim/compiler/
|
||||||
projectFull*: string # projectPath/projectName
|
projectFull*: string # projectPath/projectName
|
||||||
projectIsStdin*: bool # whether we're compiling from stdin
|
projectIsStdin*: bool # whether we're compiling from stdin
|
||||||
projectMainIdx*: int32 # the canonical path id of the main module
|
projectMainIdx*: FileIndex # the canonical path id of the main module
|
||||||
command*: string # the main command (e.g. cc, check, scan, etc)
|
command*: string # the main command (e.g. cc, check, scan, etc)
|
||||||
commandArgs*: seq[string] # any arguments after the main command
|
commandArgs*: seq[string] # any arguments after the main command
|
||||||
keepComments*: bool # whether the parser needs to keep comments
|
keepComments*: bool # whether the parser needs to keep comments
|
||||||
|
|
@ -278,7 +278,7 @@ proc newConfigRef*(): ConfigRef =
|
||||||
projectPath: "", # holds a path like /home/alice/projects/nim/compiler/
|
projectPath: "", # holds a path like /home/alice/projects/nim/compiler/
|
||||||
projectFull: "", # projectPath/projectName
|
projectFull: "", # projectPath/projectName
|
||||||
projectIsStdin: false, # whether we're compiling from stdin
|
projectIsStdin: false, # whether we're compiling from stdin
|
||||||
projectMainIdx: 0'i32, # the canonical path id of the main module
|
projectMainIdx: FileIndex(0'i32), # the canonical path id of the main module
|
||||||
command: "", # the main command (e.g. cc, check, scan, etc)
|
command: "", # the main command (e.g. cc, check, scan, etc)
|
||||||
commandArgs: @[], # any arguments after the main command
|
commandArgs: @[], # any arguments after the main command
|
||||||
keepComments: true, # whether the parser needs to keep comments
|
keepComments: true, # whether the parser needs to keep comments
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue