don't use stdout for nimsuggest server mode

This commit is contained in:
Araq 2015-02-27 16:44:43 +01:00
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): for i in countup(0, sonsLen(src) - 1):
result.sons[i] = copyTree(src.sons[i]) 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): for i in countup(0, sonsLen(n) - 1):
if n.sons[i].kind == kind: if n.sons[i].kind == kind:
return true return true

View file

@ -445,21 +445,21 @@ proc debugTree(n: PNode, indent: int, maxRecDepth: int;
proc debug(n: PSym) = proc debug(n: PSym) =
if n == nil: if n == nil:
writeln(stdout, "null") msgWriteln("null")
elif n.kind == skUnknown: elif n.kind == skUnknown:
writeln(stdout, "skUnknown") msgWriteln("skUnknown")
else: else:
#writeln(stdout, ropeToStr(symToYaml(n, 0, 1))) #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, n.name.s, $n.id, flagsToStr(n.flags).ropeToStr,
flagsToStr(n.loc.flags).ropeToStr, lineInfoToStr(n.info).ropeToStr, flagsToStr(n.loc.flags).ropeToStr, lineInfoToStr(n.info).ropeToStr,
$n.kind]) $n.kind])
proc debug(n: PType) = proc debug(n: PType) =
writeln(stdout, ropeToStr(debugType(n))) msgWriteln(ropeToStr(debugType(n)))
proc debug(n: PNode) = proc debug(n: PNode) =
writeln(stdout, ropeToStr(debugTree(n, 0, 100))) msgWriteln(ropeToStr(debugTree(n, 0, 100)))
const const
EmptySeq = @[] EmptySeq = @[]

View file

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

View file

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

View file

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

View file

@ -283,7 +283,7 @@ when noTimeMachine:
var p = startProcess("/usr/bin/tmutil", args = ["addexclusion", dir]) var p = startProcess("/usr/bin/tmutil", args = ["addexclusion", dir])
discard p.waitForExit discard p.waitForExit
p.close p.close
except E_Base, EOS: except Exception:
discard discard
proc completeGeneratedFilePath*(f: string, createSubDir: bool = true): string = proc completeGeneratedFilePath*(f: string, createSubDir: bool = true): string =

View file

@ -776,10 +776,14 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
stackTrace(c, tos, pc, errNilAccess) stackTrace(c, tos, pc, errNilAccess)
of opcEcho: of opcEcho:
let rb = instr.regB let rb = instr.regB
for i in ra..ra+rb-1: if rb == 1:
#if regs[i].kind != rkNode: debug regs[i] msgWriteln(regs[ra].node.strVal)
write(stdout, regs[i].node.strVal) else:
writeln(stdout, "") 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: of opcContainsSet:
decodeBC(rkInt) decodeBC(rkInt)
regs[ra].intVal = ord(inSet(regs[rb].node, regs[rc].regToNode)) 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 nnkSym: add(result, $n.symbol)
of nnkNone: assert false of nnkNone: assert false
else: else:
add(result, lispRepr(n[0])) if n.len > 0:
for j in 1..n.len-1: add(result, lispRepr(n[0]))
add(result, ", ") for j in 1..n.len-1:
add(result, lispRepr(n[j])) add(result, ", ")
add(result, lispRepr(n[j]))
add(result, ")") add(result, ")")