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:
def 2015-05-16 12:38:53 +02:00
commit def61c9fcd
4 changed files with 23 additions and 22 deletions

View file

@ -63,7 +63,7 @@ proc commandCompileToC =
compileProject()
cgenWriteModules()
if gCmd != cmdRun:
extccomp.callCCompiler(if gProjectName == "-": "stdinfile" else: changeFileExt(gProjectFull, ""))
extccomp.callCCompiler(changeFileExt(gProjectFull, ""))
if isServing:
# caas will keep track only of the compilation commands

View file

@ -11,7 +11,7 @@
import
ast, astalgo, magicsys, crc, rodread, msgs, cgendata, sigmatch, options,
idents, os, lexer, idgen, passes, syntaxes
idents, os, lexer, idgen, passes, syntaxes, llstream
type
TNeedRecompile* = enum Maybe, No, Yes, Probing, Recompiled
@ -116,7 +116,7 @@ proc newModule(fileIdx: int32): PSym =
result.kind = skModule
let filename = fileIdx.toFullPath
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)
result.info = newLineInfo(fileIdx, 1, 1)
@ -148,7 +148,10 @@ proc compileModule*(fileIdx: int32, flags: TSymFlags): PSym =
return
else:
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:
gMemCacheData[fileIdx].compiledAt = gLastCmdTime
gMemCacheData[fileIdx].needsRecompile = Recompiled

View file

@ -38,7 +38,11 @@ proc handleCmdLine() =
else:
# Process command line arguments:
processCmdLine(passCmd1, "")
if gProjectName != "":
if gProjectName == "-":
gProjectName = "stdinfile"
gProjectFull = "stdinfile"
gProjectPath = getCurrentDir()
elif gProjectName != "":
try:
gProjectFull = canonicalizePath(gProjectName)
except OSError:
@ -61,8 +65,6 @@ proc handleCmdLine() =
if gCmd == cmdRun:
tccgen.run(commands.arguments)
if optRun in gGlobalOptions:
if gProjectName == "-":
gProjectFull = "stdinfile"
if gCmd == cmdCompileToJS:
var ex: string
if options.outFile.len > 0:

View file

@ -170,11 +170,7 @@ proc processModule(module: PSym, stream: PLLStream, rd: PRodReader) =
openPasses(a, module)
if stream == nil:
let filename = fileIdx.toFullPathConsiderDirty
if module.name.s == "-":
module.name.s = "stdinfile"
s = llStreamOpen(stdin)
else:
s = llStreamOpen(filename, fmRead)
s = llStreamOpen(filename, fmRead)
if s == nil:
rawMessage(errCannotOpenFile, filename)
return