don't use stdout for nimsuggest server mode

This commit is contained in:
Araq
2015-02-27 16:44:43 +01:00
parent 05233de66c
commit 3bfcfeb0cf
8 changed files with 34 additions and 29 deletions

View File

@@ -1413,7 +1413,7 @@ proc copyTree*(src: PNode): PNode =
for i in countup(0, sonsLen(src) - 1):
result.sons[i] = copyTree(src.sons[i])
proc hasSonWith(n: PNode, kind: TNodeKind): bool =
proc hasSonWith*(n: PNode, kind: TNodeKind): bool =
for i in countup(0, sonsLen(n) - 1):
if n.sons[i].kind == kind:
return true

View File

@@ -445,21 +445,21 @@ proc debugTree(n: PNode, indent: int, maxRecDepth: int;
proc debug(n: PSym) =
if n == nil:
writeln(stdout, "null")
msgWriteln("null")
elif n.kind == skUnknown:
writeln(stdout, "skUnknown")
msgWriteln("skUnknown")
else:
#writeln(stdout, ropeToStr(symToYaml(n, 0, 1)))
writeln(stdout, "$1_$2: $3, $4, $5, $6" % [
msgWriteln("$1_$2: $3, $4, $5, $6" % [
n.name.s, $n.id, flagsToStr(n.flags).ropeToStr,
flagsToStr(n.loc.flags).ropeToStr, lineInfoToStr(n.info).ropeToStr,
$n.kind])
proc debug(n: PType) =
writeln(stdout, ropeToStr(debugType(n)))
msgWriteln(ropeToStr(debugType(n)))
proc debug(n: PNode) =
writeln(stdout, ropeToStr(debugTree(n, 0, 100)))
msgWriteln(ropeToStr(debugTree(n, 0, 100)))
const
EmptySeq = @[]

View File

@@ -382,7 +382,7 @@ proc processSwitch(switch, arg: string, pass: TCmdLinePass, info: TLineInfo) =
of "off":
gOptions.excl optEndb
undefSymbol("endb")
of "native":
of "native", "gdb":
incl(gGlobalOptions, optCDebug)
gOptions = gOptions + {optLineDir} - {optEndb}
undefSymbol("endb")

View File

@@ -181,10 +181,8 @@ proc prettyTok*(tok: TToken): string =
else: result = tokToStr(tok)
proc printTok*(tok: TToken) =
write(stdout, tok.line, ":", tok.col, "\t")
write(stdout, TokTypeToStr[tok.tokType])
write(stdout, " ")
writeln(stdout, tokToStr(tok))
msgWriteln($tok.line & ":" & $tok.col & "\t" &
TokTypeToStr[tok.tokType] & " " & tokToStr(tok))
var dummyIdent: PIdent

View File

@@ -330,7 +330,7 @@ const
errUsingNoSymbol: "'$1' is not a variable, constant or a proc name",
errMacroBodyDependsOnGenericTypes: "the macro body cannot be compiled, " &
"because the parameter '$1' has a generic type",
errDestructorNotGenericEnough: "Destructor signarue is too specific. " &
errDestructorNotGenericEnough: "Destructor signature is too specific. " &
"A destructor must be associated will all instantiations of a generic type",
errInlineIteratorsAsProcParams: "inline iterators can be used as parameters only for " &
"templates, macros and other inline iterators",
@@ -443,7 +443,7 @@ type
TNoteKind* = range[warnMin..hintMax] # "notes" are warnings or hints
TNoteKinds* = set[TNoteKind]
TFileInfo*{.final.} = object
TFileInfo* = object
fullPath: string # This is a canonical full filesystem path
projPath*: string # This is relative to the project's root
shortName*: string # short name of the module
@@ -458,7 +458,7 @@ type
# and parsed; usually 'nil' but is used
# for 'nimsuggest'
TLineInfo*{.final.} = object # This is designed to be as small as possible,
TLineInfo* = object # This is designed to be as small as possible,
# because it is used
# in syntax nodes. We save space here by using
# two int16 and an int32.
@@ -493,7 +493,7 @@ proc toCChar*(c: char): string =
proc makeCString*(s: string): PRope =
# BUGFIX: We have to split long strings into many ropes. Otherwise
# this could trigger an InternalError(). See the ropes module for
# this could trigger an internalError(). See the ropes module for
# further information.
const
MaxLineLength = 64
@@ -696,7 +696,9 @@ proc msgWriteln*(s: string) =
#if gCmd == cmdIdeTools and optCDebug notin gGlobalOptions: return
if optStdout in gGlobalOptions:
if not isNil(writelnHook):
writelnHook(s)
elif optStdout in gGlobalOptions:
if eStdErr in errorOutputs: writeln(stderr, s)
else:
if eStdOut in errorOutputs: writeln(stdout, s)
@@ -720,7 +722,7 @@ type
proc handleError(msg: TMsgKind, eh: TErrorHandling, s: string) =
template quit =
if defined(debug) or gVerbosity >= 3 or msg == errInternal:
if stackTraceAvailable():
if stackTraceAvailable() and isNil(writelnHook):
writeStackTrace()
else:
msgWriteln("No stack traceback available\nTo create a stacktrace, rerun compilation with ./koch temp " & options.command & " <file>")

View File

@@ -283,19 +283,19 @@ when noTimeMachine:
var p = startProcess("/usr/bin/tmutil", args = ["addexclusion", dir])
discard p.waitForExit
p.close
except E_Base, EOS:
except Exception:
discard
proc completeGeneratedFilePath*(f: string, createSubDir: bool = true): string =
proc completeGeneratedFilePath*(f: string, createSubDir: bool = true): string =
var (head, tail) = splitPath(f)
#if len(head) > 0: head = removeTrailingDirSep(shortenDir(head & dirSep))
var subdir = getGeneratedPath() # / head
if createSubDir:
try:
try:
createDir(subdir)
when noTimeMachine:
excludeDirFromTimeMachine(subdir)
except OSError:
except OSError:
writeln(stdout, "cannot create directory: " & subdir)
quit(1)
result = joinPath(subdir, tail)

View File

@@ -776,10 +776,14 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
stackTrace(c, tos, pc, errNilAccess)
of opcEcho:
let rb = instr.regB
for i in ra..ra+rb-1:
#if regs[i].kind != rkNode: debug regs[i]
write(stdout, regs[i].node.strVal)
writeln(stdout, "")
if rb == 1:
msgWriteln(regs[ra].node.strVal)
else:
var outp = ""
for i in ra..ra+rb-1:
#if regs[i].kind != rkNode: debug regs[i]
outp.add(regs[i].node.strVal)
msgWriteln(outp)
of opcContainsSet:
decodeBC(rkInt)
regs[ra].intVal = ord(inSet(regs[rb].node, regs[rc].regToNode))

View File

@@ -456,10 +456,11 @@ proc lispRepr*(n: PNimrodNode): string {.compileTime, benign.} =
of nnkSym: add(result, $n.symbol)
of nnkNone: assert false
else:
add(result, lispRepr(n[0]))
for j in 1..n.len-1:
add(result, ", ")
add(result, lispRepr(n[j]))
if n.len > 0:
add(result, lispRepr(n[0]))
for j in 1..n.len-1:
add(result, ", ")
add(result, lispRepr(n[j]))
add(result, ")")