Introduce NotesVerbosity defining verbosity levels

This solves two issues:

1. Some notes were enabled explicitly for some verbosity levels, so
   --hintName:on has no effect if verbosity level was too low.

2. Verbosity level for notes is not longer scattered across the source code,
   instead if now lives in msgs.nim NotesVerbosity array

3. Individual note settings have stronger effect than verbosity setting,
   so --hintName:off will disable hint regardless of high verbosity setting,
   and vice-versa --hintName:on will enable hint even on low verbosity setting.
This commit is contained in:
Adam Strzelecki 2015-06-06 11:07:23 +02:00
commit 14e6ff6780
8 changed files with 36 additions and 13 deletions

View file

@ -141,6 +141,10 @@ proc expectArg(switch, arg: string, pass: TCmdLinePass, info: TLineInfo) =
proc expectNoArg(switch, arg: string, pass: TCmdLinePass, info: TLineInfo) = proc expectNoArg(switch, arg: string, pass: TCmdLinePass, info: TLineInfo) =
if arg != "": localError(info, errCmdLineNoArgExpected, addPrefix(switch)) if arg != "": localError(info, errCmdLineNoArgExpected, addPrefix(switch))
var
enableNotes: TNoteKinds
disableNotes: TNoteKinds
proc processSpecificNote(arg: string, state: TSpecialWord, pass: TCmdLinePass, proc processSpecificNote(arg: string, state: TSpecialWord, pass: TCmdLinePass,
info: TLineInfo; orig: string) = info: TLineInfo; orig: string) =
var id = "" # arg = "X]:on|off" var id = "" # arg = "X]:on|off"
@ -162,8 +166,12 @@ proc processSpecificNote(arg: string, state: TSpecialWord, pass: TCmdLinePass,
if x >= 0: n = TNoteKind(x + ord(warnMin)) if x >= 0: n = TNoteKind(x + ord(warnMin))
else: localError(info, "unknown warning: " & id) else: localError(info, "unknown warning: " & id)
case whichKeyword(substr(arg, i)) case whichKeyword(substr(arg, i))
of wOn: incl(gNotes, n) of wOn:
of wOff: excl(gNotes, n) incl(gNotes, n)
incl(enableNotes, n)
of wOff:
excl(gNotes, n)
incl(disableNotes, n)
else: localError(info, errOnOrOffExpectedButXFound, arg) else: localError(info, errOnOrOffExpectedButXFound, arg)
proc processCompile(filename: string) = proc processCompile(filename: string) =
@ -508,6 +516,9 @@ proc processSwitch(switch, arg: string, pass: TCmdLinePass, info: TLineInfo) =
of "verbosity": of "verbosity":
expectArg(switch, arg, pass, info) expectArg(switch, arg, pass, info)
gVerbosity = parseInt(arg) gVerbosity = parseInt(arg)
gNotes = NotesVerbosity[gVerbosity]
incl(gNotes, enableNotes)
excl(gNotes, disableNotes)
of "parallelbuild": of "parallelbuild":
expectArg(switch, arg, pass, info) expectArg(switch, arg, pass, info)
gNumberOfProcessors = parseInt(arg) gNumberOfProcessors = parseInt(arg)

View file

@ -359,9 +359,8 @@ proc mainCommand* =
else: else:
rawMessage(errInvalidCommandX, command) rawMessage(errInvalidCommandX, command)
if (msgs.gErrorCounter == 0 and if msgs.gErrorCounter == 0 and
gCmd notin {cmdInterpret, cmdRun, cmdDump} and gCmd notin {cmdInterpret, cmdRun, cmdDump}:
gVerbosity > 0):
rawMessage(hintSuccessX, [$gLinesCompiled, rawMessage(hintSuccessX, [$gLinesCompiled,
formatFloat(epochTime() - gLastCmdTime, ffDecimal, 3), formatFloat(epochTime() - gLastCmdTime, ffDecimal, 3),
formatSize(getTotalMem()), formatSize(getTotalMem()),

View file

@ -483,6 +483,21 @@ type
ERecoverableError* = object of ValueError ERecoverableError* = object of ValueError
ESuggestDone* = object of Exception ESuggestDone* = object of Exception
const
NotesVerbosity*: array[0..3, TNoteKinds] = [
{low(TNoteKind)..high(TNoteKind)} - {warnShadowIdent, warnUninit,
warnProveField, warnProveIndex,
warnGcUnsafe,
hintSuccessX, hintPath, hintConf,
hintProcessing,
hintCodeBegin, hintCodeEnd},
{low(TNoteKind)..high(TNoteKind)} - {warnShadowIdent, warnUninit,
warnProveField, warnProveIndex,
warnGcUnsafe,
hintCodeBegin, hintCodeEnd},
{low(TNoteKind)..high(TNoteKind)},
{low(TNoteKind)..high(TNoteKind)}]
const const
InvalidFileIDX* = int32(-1) InvalidFileIDX* = int32(-1)
@ -571,9 +586,7 @@ proc raiseRecoverableError*(msg: string) {.noinline, noreturn.} =
proc sourceLine*(i: TLineInfo): Rope proc sourceLine*(i: TLineInfo): Rope
var var
gNotes*: TNoteKinds = {low(TNoteKind)..high(TNoteKind)} - gNotes*: TNoteKinds = NotesVerbosity[1] # defaults to verbosity of 1
{warnShadowIdent, warnUninit,
warnProveField, warnProveIndex, warnGcUnsafe}
gErrorCounter*: int = 0 # counts the number of errors gErrorCounter*: int = 0 # counts the number of errors
gHintCounter*: int = 0 gHintCounter*: int = 0
gWarnCounter*: int = 0 gWarnCounter*: int = 0

View file

@ -60,7 +60,7 @@ iterator chosen(packages: StringTableRef): string =
proc addNimblePath(p: string, info: TLineInfo) = proc addNimblePath(p: string, info: TLineInfo) =
if not contains(options.searchPaths, p): if not contains(options.searchPaths, p):
if gVerbosity >= 1: message(info, hintPath, p) message(info, hintPath, p)
lists.prependStr(options.lazyPaths, p) lists.prependStr(options.lazyPaths, p)
proc addPathWithNimFiles(p: string, info: TLineInfo) = proc addPathWithNimFiles(p: string, info: TLineInfo) =

View file

@ -211,7 +211,7 @@ proc readConfigFile(filename: string) =
while tok.tokType != tkEof: parseAssignment(L, tok) while tok.tokType != tkEof: parseAssignment(L, tok)
if len(condStack) > 0: lexMessage(L, errTokenExpected, "@end") if len(condStack) > 0: lexMessage(L, errTokenExpected, "@end")
closeLexer(L) closeLexer(L)
if gVerbosity >= 1: rawMessage(hintConf, filename) rawMessage(hintConf, filename)
proc getUserConfigPath(filename: string): string = proc getUserConfigPath(filename: string): string =
result = joinPath(getConfigDir(), filename) result = joinPath(getConfigDir(), filename)

View file

@ -15,7 +15,7 @@ import
proc verboseOpen(s: PSym): PPassContext = proc verboseOpen(s: PSym): PPassContext =
#MessageOut('compiling ' + s.name.s); #MessageOut('compiling ' + s.name.s);
result = nil # we don't need a context result = nil # we don't need a context
if gVerbosity > 0: rawMessage(hintProcessing, s.name.s) rawMessage(hintProcessing, s.name.s)
proc verboseProcess(context: PPassContext, n: PNode): PNode = proc verboseProcess(context: PPassContext, n: PNode): PNode =
result = n result = n

View file

@ -838,7 +838,7 @@ proc checkDep(fileIdx: int32): TReasonForRecompile =
if res != rrNone: if res != rrNone:
result = rrModDeps result = rrModDeps
# we cannot break here, because of side-effects of `checkDep` # we cannot break here, because of side-effects of `checkDep`
if result != rrNone and gVerbosity > 0: if result != rrNone:
rawMessage(hintProcessing, reasonToFrmt[result] % filename) rawMessage(hintProcessing, reasonToFrmt[result] % filename)
if result != rrNone or optForceFullMake in gGlobalOptions: if result != rrNone or optForceFullMake in gGlobalOptions:
# recompilation is necessary: # recompilation is necessary:

View file

@ -139,7 +139,7 @@ proc applyFilter(p: var TParsers, n: PNode, filename: string,
of filtReplace: of filtReplace:
result = filterReplace(stdin, filename, n) result = filterReplace(stdin, filename, n)
if f != filtNone: if f != filtNone:
if gVerbosity >= 2: if hintCodeBegin in gNotes:
rawMessage(hintCodeBegin, []) rawMessage(hintCodeBegin, [])
msgWriteln(result.s) msgWriteln(result.s)
rawMessage(hintCodeEnd, []) rawMessage(hintCodeEnd, [])