the compiler can now deal with multiple modules of the same name
This commit is contained in:
parent
c085a1b4f0
commit
a0b82db402
13 changed files with 74 additions and 18 deletions
|
|
@ -992,12 +992,15 @@ proc genMainProc(m: BModule) =
|
|||
gBreakpoints, mainModInit, toRope(m.labels)])
|
||||
if optNoMain notin gGlobalOptions:
|
||||
appcg(m, m.s[cfsProcs], otherMain, [])
|
||||
|
||||
proc getInitName(m: PSym): PRope =
|
||||
result = ropeff("$1Init", "@$1Init", [toRope(m.name.s)])
|
||||
|
||||
proc getDatInitName(m: PSym): PRope =
|
||||
result = ropeff("$1DatInit", "@$1DatInit", [toRope(m.name.s)])
|
||||
proc getSomeInitName(m: PSym, suffix: string): PRope =
|
||||
if {sfSystemModule, sfMainModule} * m.flags == {}:
|
||||
result = m.info.toFullPath.getPackageName.mangle.toRope
|
||||
result.app m.name.s
|
||||
result.app suffix
|
||||
|
||||
proc getInitName(m: PSym): PRope = getSomeInitName(m, "Init")
|
||||
proc getDatInitName(m: PSym): PRope = getSomeInitName(m, "DatInit")
|
||||
|
||||
proc registerModuleToMain(m: PSym) =
|
||||
var
|
||||
|
|
@ -1167,7 +1170,7 @@ proc resetCgenModules* =
|
|||
for m in cgenModules(): resetModule(m)
|
||||
|
||||
proc rawNewModule(module: PSym): BModule =
|
||||
result = rawNewModule(module, module.filename)
|
||||
result = rawNewModule(module, module.position.int32.toFullPath)
|
||||
|
||||
proc newModule(module: PSym): BModule =
|
||||
# we should create only one cgen module for each module sym
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ proc getModuleName*(n: PNode): string =
|
|||
proc checkModuleName*(n: PNode): int32 =
|
||||
# This returns the full canonical path for a given module import
|
||||
let modulename = n.getModuleName
|
||||
let fullPath = findModule(modulename)
|
||||
let fullPath = findModule(modulename, n.info.toFullPath)
|
||||
if fullPath.len == 0:
|
||||
LocalError(n.info, errCannotOpenFile, modulename)
|
||||
result = InvalidFileIDX
|
||||
|
|
|
|||
|
|
@ -18,5 +18,5 @@ const
|
|||
VersionPatch* = 3
|
||||
VersionAsString* = $VersionMajor & "." & $VersionMinor & "." & $VersionPatch
|
||||
|
||||
RodFileVersion* = "1212" # modify this if the rod-format changes!
|
||||
RodFileVersion* = "1214" # modify this if the rod-format changes!
|
||||
|
||||
|
|
|
|||
|
|
@ -209,7 +209,7 @@ proc getGeneratedPath: string =
|
|||
result = if nimcacheDir.len > 0: nimcacheDir else: gProjectPath.shortenDir /
|
||||
genSubDir
|
||||
|
||||
proc getPackageName(path: string): string =
|
||||
proc getPackageName*(path: string): string =
|
||||
var q = 1
|
||||
var b = 0
|
||||
if path[len(path)-1] in {dirsep, altsep}: q = 2
|
||||
|
|
@ -221,10 +221,11 @@ proc getPackageName(path: string): string =
|
|||
case x.normalize
|
||||
of "lib", "src", "source", "package", "pckg", "library": b = i
|
||||
else: return x
|
||||
result = ""
|
||||
|
||||
proc withPackageName*(path: string): string =
|
||||
let x = path.getPackageName
|
||||
if x.isNil:
|
||||
if x.len == 0:
|
||||
result = path
|
||||
else:
|
||||
let (p, file, ext) = path.splitFile
|
||||
|
|
@ -282,9 +283,13 @@ proc FindFile*(f: string): string {.procvar.} =
|
|||
if result.len == 0:
|
||||
result = f.toLower.rawFindFile2
|
||||
|
||||
proc findModule*(modulename: string): string {.inline.} =
|
||||
proc findModule*(modulename, currentModule: string): string =
|
||||
# returns path to module
|
||||
result = FindFile(AddFileExt(modulename, nimExt))
|
||||
let m = addFileExt(modulename, nimExt)
|
||||
let currentPath = currentModule.splitFile.dir
|
||||
result = currentPath / m
|
||||
if not existsFile(result):
|
||||
result = FindFile(m)
|
||||
|
||||
proc libCandidates*(s: string, dest: var seq[string]) =
|
||||
var le = strutils.find(s, '(')
|
||||
|
|
|
|||
|
|
@ -140,6 +140,7 @@ type
|
|||
memfile: TMemFile # unfortunately there is no point in time where we
|
||||
# can close this! XXX
|
||||
methods*: TSymSeq
|
||||
origFile: string
|
||||
inViewMode: bool
|
||||
|
||||
PRodReader* = ref TRodReader
|
||||
|
|
@ -558,6 +559,9 @@ proc processRodFile(r: PRodReader, crc: TCrc32) =
|
|||
inc(r.pos) # skip ':'
|
||||
r.moduleID = decodeVInt(r.s, r.pos)
|
||||
setID(r.moduleID)
|
||||
of "ORIGFILE":
|
||||
inc(r.pos)
|
||||
r.origFile = decodeStr(r.s, r.pos)
|
||||
of "OPTIONS":
|
||||
inc(r.pos) # skip ':'
|
||||
r.options = cast[TOptions](int32(decodeVInt(r.s, r.pos)))
|
||||
|
|
@ -585,7 +589,7 @@ proc processRodFile(r: PRodReader, crc: TCrc32) =
|
|||
inc(r.line)
|
||||
while r.s[r.pos] != ')':
|
||||
let relativePath = decodeStr(r.s, r.pos)
|
||||
let resolvedPath = relativePath.findModule
|
||||
let resolvedPath = relativePath.findModule(r.origFile)
|
||||
let finalPath = if resolvedPath.len > 0: resolvedPath else: relativePath
|
||||
r.files.add(finalPath.fileInfoIdx)
|
||||
inc(r.pos) # skip #10
|
||||
|
|
@ -1036,6 +1040,10 @@ proc viewFile(rodfile: string) =
|
|||
r.moduleID = decodeVInt(r.s, r.pos)
|
||||
setID(r.moduleID)
|
||||
outf.writeln("ID:", $r.moduleID)
|
||||
of "ORIGFILE":
|
||||
inc(r.pos)
|
||||
r.origFile = decodeStr(r.s, r.pos)
|
||||
outf.writeln("ORIGFILE:", r.origFile)
|
||||
of "OPTIONS":
|
||||
inc(r.pos) # skip ':'
|
||||
r.options = cast[TOptions](int32(decodeVInt(r.s, r.pos)))
|
||||
|
|
@ -1058,13 +1066,13 @@ proc viewFile(rodfile: string) =
|
|||
outf.write(" ", w)
|
||||
if r.s[r.pos] == ' ': inc(r.pos)
|
||||
outf.write("\n")
|
||||
of "FILES":
|
||||
of "FILES":
|
||||
inc(r.pos, 2) # skip "(\10"
|
||||
inc(r.line)
|
||||
outf.write("FILES(\n")
|
||||
while r.s[r.pos] != ')':
|
||||
let relativePath = decodeStr(r.s, r.pos)
|
||||
let resolvedPath = relativePath.findModule
|
||||
let resolvedPath = relativePath.findModule(r.origFile)
|
||||
let finalPath = if resolvedPath.len > 0: resolvedPath else: relativePath
|
||||
r.files.add(finalPath.fileInfoIdx)
|
||||
inc(r.pos) # skip #10
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ type
|
|||
sstack: TSymSeq # a stack of symbols to process
|
||||
tstack: TTypeSeq # a stack of types to process
|
||||
files: TStringSeq
|
||||
origFile: string
|
||||
|
||||
PRodWriter = ref TRodWriter
|
||||
|
||||
|
|
@ -81,6 +82,7 @@ proc newRodWriter(crc: TCrc32, module: PSym): PRodWriter =
|
|||
result.converters = ""
|
||||
result.methods = ""
|
||||
result.init = ""
|
||||
result.origFile = module.info.toFilename
|
||||
result.data = newStringOfCap(12_000)
|
||||
|
||||
proc addModDep(w: PRodWriter, dep: string) =
|
||||
|
|
@ -91,7 +93,7 @@ const
|
|||
rodNL = "\x0A"
|
||||
|
||||
proc addInclDep(w: PRodWriter, dep: string) =
|
||||
var resolved = dep.findModule
|
||||
var resolved = dep.findModule(w.module.info.toFullPath)
|
||||
encodeVInt(fileIdx(w, dep), w.inclDeps)
|
||||
add(w.inclDeps, " ")
|
||||
encodeVInt(crcFromFile(resolved), w.inclDeps)
|
||||
|
|
@ -434,6 +436,11 @@ proc writeRod(w: PRodWriter) =
|
|||
encodeVInt(w.module.id, id)
|
||||
f.write(id)
|
||||
f.write(rodNL)
|
||||
|
||||
var orig = "ORIGFILE:"
|
||||
encodeStr(w.origFile, orig)
|
||||
f.write(orig)
|
||||
f.write(rodNL)
|
||||
|
||||
var crc = "CRC:"
|
||||
encodeVInt(w.crc, crc)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue