Clean up stdin file reading of compiler.
Uses "stdinfile" as the module identifier now, which prevents problems with - colliding with the minus operator. This fixes #2422 and #2702.
This commit is contained in:
parent
1c0bbcff5a
commit
def61c9fcd
4 changed files with 23 additions and 22 deletions
|
|
@ -63,7 +63,7 @@ proc commandCompileToC =
|
||||||
compileProject()
|
compileProject()
|
||||||
cgenWriteModules()
|
cgenWriteModules()
|
||||||
if gCmd != cmdRun:
|
if gCmd != cmdRun:
|
||||||
extccomp.callCCompiler(if gProjectName == "-": "stdinfile" else: changeFileExt(gProjectFull, ""))
|
extccomp.callCCompiler(changeFileExt(gProjectFull, ""))
|
||||||
|
|
||||||
if isServing:
|
if isServing:
|
||||||
# caas will keep track only of the compilation commands
|
# caas will keep track only of the compilation commands
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,8 @@
|
||||||
## implements the module handling
|
## implements the module handling
|
||||||
|
|
||||||
import
|
import
|
||||||
ast, astalgo, magicsys, crc, rodread, msgs, cgendata, sigmatch, options,
|
ast, astalgo, magicsys, crc, rodread, msgs, cgendata, sigmatch, options,
|
||||||
idents, os, lexer, idgen, passes, syntaxes
|
idents, os, lexer, idgen, passes, syntaxes, llstream
|
||||||
|
|
||||||
type
|
type
|
||||||
TNeedRecompile* = enum Maybe, No, Yes, Probing, Recompiled
|
TNeedRecompile* = enum Maybe, No, Yes, Probing, Recompiled
|
||||||
|
|
@ -39,12 +39,12 @@ template crc(x: PSym): expr =
|
||||||
|
|
||||||
proc crcChanged(fileIdx: int32): bool =
|
proc crcChanged(fileIdx: int32): bool =
|
||||||
internalAssert fileIdx >= 0 and fileIdx < gMemCacheData.len
|
internalAssert fileIdx >= 0 and fileIdx < gMemCacheData.len
|
||||||
|
|
||||||
template updateStatus =
|
template updateStatus =
|
||||||
gMemCacheData[fileIdx].crcStatus = if result: crcHasChanged
|
gMemCacheData[fileIdx].crcStatus = if result: crcHasChanged
|
||||||
else: crcNotChanged
|
else: crcNotChanged
|
||||||
# echo "TESTING CRC: ", fileIdx.toFilename, " ", result
|
# echo "TESTING CRC: ", fileIdx.toFilename, " ", result
|
||||||
|
|
||||||
case gMemCacheData[fileIdx].crcStatus:
|
case gMemCacheData[fileIdx].crcStatus:
|
||||||
of crcHasChanged:
|
of crcHasChanged:
|
||||||
result = true
|
result = true
|
||||||
|
|
@ -96,7 +96,7 @@ proc checkDepMem(fileIdx: int32): TNeedRecompile =
|
||||||
if optForceFullMake in gGlobalOptions or
|
if optForceFullMake in gGlobalOptions or
|
||||||
crcChanged(fileIdx):
|
crcChanged(fileIdx):
|
||||||
markDirty
|
markDirty
|
||||||
|
|
||||||
if gMemCacheData[fileIdx].deps != nil:
|
if gMemCacheData[fileIdx].deps != nil:
|
||||||
gMemCacheData[fileIdx].needsRecompile = Probing
|
gMemCacheData[fileIdx].needsRecompile = Probing
|
||||||
for dep in gMemCacheData[fileIdx].deps:
|
for dep in gMemCacheData[fileIdx].deps:
|
||||||
|
|
@ -104,30 +104,30 @@ proc checkDepMem(fileIdx: int32): TNeedRecompile =
|
||||||
if d in {Yes, Recompiled}:
|
if d in {Yes, Recompiled}:
|
||||||
# echo fileIdx.toFilename, " depends on ", dep.toFilename, " ", d
|
# echo fileIdx.toFilename, " depends on ", dep.toFilename, " ", d
|
||||||
markDirty
|
markDirty
|
||||||
|
|
||||||
gMemCacheData[fileIdx].needsRecompile = No
|
gMemCacheData[fileIdx].needsRecompile = No
|
||||||
return No
|
return No
|
||||||
|
|
||||||
proc newModule(fileIdx: int32): PSym =
|
proc newModule(fileIdx: int32): PSym =
|
||||||
# We cannot call ``newSym`` here, because we have to circumvent the ID
|
# We cannot call ``newSym`` here, because we have to circumvent the ID
|
||||||
# mechanism, which we do in order to assign each module a persistent ID.
|
# mechanism, which we do in order to assign each module a persistent ID.
|
||||||
new(result)
|
new(result)
|
||||||
result.id = - 1 # for better error checking
|
result.id = - 1 # for better error checking
|
||||||
result.kind = skModule
|
result.kind = skModule
|
||||||
let filename = fileIdx.toFullPath
|
let filename = fileIdx.toFullPath
|
||||||
result.name = getIdent(splitFile(filename).name)
|
result.name = getIdent(splitFile(filename).name)
|
||||||
if result.name.s != "-" and not isNimIdentifier(result.name.s):
|
if not isNimIdentifier(result.name.s):
|
||||||
rawMessage(errInvalidModuleName, result.name.s)
|
rawMessage(errInvalidModuleName, result.name.s)
|
||||||
|
|
||||||
result.info = newLineInfo(fileIdx, 1, 1)
|
result.info = newLineInfo(fileIdx, 1, 1)
|
||||||
result.owner = newSym(skPackage, getIdent(getPackageName(filename)), nil,
|
result.owner = newSym(skPackage, getIdent(getPackageName(filename)), nil,
|
||||||
result.info)
|
result.info)
|
||||||
result.position = fileIdx
|
result.position = fileIdx
|
||||||
|
|
||||||
growCache gMemCacheData, fileIdx
|
growCache gMemCacheData, fileIdx
|
||||||
growCache gCompiledModules, fileIdx
|
growCache gCompiledModules, fileIdx
|
||||||
gCompiledModules[result.position] = result
|
gCompiledModules[result.position] = result
|
||||||
|
|
||||||
incl(result.flags, sfUsed)
|
incl(result.flags, sfUsed)
|
||||||
initStrTable(result.tab)
|
initStrTable(result.tab)
|
||||||
strTableAdd(result.tab, result) # a module knows itself
|
strTableAdd(result.tab, result) # a module knows itself
|
||||||
|
|
@ -143,12 +143,15 @@ proc compileModule*(fileIdx: int32, flags: TSymFlags): PSym =
|
||||||
result.flags = result.flags + flags
|
result.flags = result.flags + flags
|
||||||
if gCmd in {cmdCompileToC, cmdCompileToCpp, cmdCheck, cmdIdeTools}:
|
if gCmd in {cmdCompileToC, cmdCompileToCpp, cmdCheck, cmdIdeTools}:
|
||||||
rd = handleSymbolFile(result)
|
rd = handleSymbolFile(result)
|
||||||
if result.id < 0:
|
if result.id < 0:
|
||||||
internalError("handleSymbolFile should have set the module\'s ID")
|
internalError("handleSymbolFile should have set the module\'s ID")
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
result.id = getID()
|
result.id = getID()
|
||||||
processModule(result, nil, rd)
|
if sfMainModule in flags and gProjectName == "-":
|
||||||
|
processModule(result, llStreamOpen(stdin), rd)
|
||||||
|
else:
|
||||||
|
processModule(result, nil, rd)
|
||||||
if optCaasEnabled in gGlobalOptions:
|
if optCaasEnabled in gGlobalOptions:
|
||||||
gMemCacheData[fileIdx].compiledAt = gLastCmdTime
|
gMemCacheData[fileIdx].compiledAt = gLastCmdTime
|
||||||
gMemCacheData[fileIdx].needsRecompile = Recompiled
|
gMemCacheData[fileIdx].needsRecompile = Recompiled
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,11 @@ proc handleCmdLine() =
|
||||||
else:
|
else:
|
||||||
# Process command line arguments:
|
# Process command line arguments:
|
||||||
processCmdLine(passCmd1, "")
|
processCmdLine(passCmd1, "")
|
||||||
if gProjectName != "":
|
if gProjectName == "-":
|
||||||
|
gProjectName = "stdinfile"
|
||||||
|
gProjectFull = "stdinfile"
|
||||||
|
gProjectPath = getCurrentDir()
|
||||||
|
elif gProjectName != "":
|
||||||
try:
|
try:
|
||||||
gProjectFull = canonicalizePath(gProjectName)
|
gProjectFull = canonicalizePath(gProjectName)
|
||||||
except OSError:
|
except OSError:
|
||||||
|
|
@ -61,8 +65,6 @@ proc handleCmdLine() =
|
||||||
if gCmd == cmdRun:
|
if gCmd == cmdRun:
|
||||||
tccgen.run(commands.arguments)
|
tccgen.run(commands.arguments)
|
||||||
if optRun in gGlobalOptions:
|
if optRun in gGlobalOptions:
|
||||||
if gProjectName == "-":
|
|
||||||
gProjectFull = "stdinfile"
|
|
||||||
if gCmd == cmdCompileToJS:
|
if gCmd == cmdCompileToJS:
|
||||||
var ex: string
|
var ex: string
|
||||||
if options.outFile.len > 0:
|
if options.outFile.len > 0:
|
||||||
|
|
|
||||||
|
|
@ -170,11 +170,7 @@ proc processModule(module: PSym, stream: PLLStream, rd: PRodReader) =
|
||||||
openPasses(a, module)
|
openPasses(a, module)
|
||||||
if stream == nil:
|
if stream == nil:
|
||||||
let filename = fileIdx.toFullPathConsiderDirty
|
let filename = fileIdx.toFullPathConsiderDirty
|
||||||
if module.name.s == "-":
|
s = llStreamOpen(filename, fmRead)
|
||||||
module.name.s = "stdinfile"
|
|
||||||
s = llStreamOpen(stdin)
|
|
||||||
else:
|
|
||||||
s = llStreamOpen(filename, fmRead)
|
|
||||||
if s == nil:
|
if s == nil:
|
||||||
rawMessage(errCannotOpenFile, filename)
|
rawMessage(errCannotOpenFile, filename)
|
||||||
return
|
return
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue