From 14e6ff678053c98a156d47f431c1f6c3c2cb1400 Mon Sep 17 00:00:00 2001 From: Adam Strzelecki Date: Sat, 6 Jun 2015 11:07:23 +0200 Subject: [PATCH] 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. --- compiler/commands.nim | 15 +++++++++++++-- compiler/main.nim | 5 ++--- compiler/msgs.nim | 19 ++++++++++++++++--- compiler/nimblecmd.nim | 2 +- compiler/nimconf.nim | 2 +- compiler/passaux.nim | 2 +- compiler/rodread.nim | 2 +- compiler/syntaxes.nim | 2 +- 8 files changed, 36 insertions(+), 13 deletions(-) diff --git a/compiler/commands.nim b/compiler/commands.nim index e3d3bc4325..8d54488cb6 100644 --- a/compiler/commands.nim +++ b/compiler/commands.nim @@ -141,6 +141,10 @@ proc expectArg(switch, arg: string, pass: TCmdLinePass, info: TLineInfo) = proc expectNoArg(switch, arg: string, pass: TCmdLinePass, info: TLineInfo) = if arg != "": localError(info, errCmdLineNoArgExpected, addPrefix(switch)) +var + enableNotes: TNoteKinds + disableNotes: TNoteKinds + proc processSpecificNote(arg: string, state: TSpecialWord, pass: TCmdLinePass, info: TLineInfo; orig: string) = 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)) else: localError(info, "unknown warning: " & id) case whichKeyword(substr(arg, i)) - of wOn: incl(gNotes, n) - of wOff: excl(gNotes, n) + of wOn: + incl(gNotes, n) + incl(enableNotes, n) + of wOff: + excl(gNotes, n) + incl(disableNotes, n) else: localError(info, errOnOrOffExpectedButXFound, arg) proc processCompile(filename: string) = @@ -508,6 +516,9 @@ proc processSwitch(switch, arg: string, pass: TCmdLinePass, info: TLineInfo) = of "verbosity": expectArg(switch, arg, pass, info) gVerbosity = parseInt(arg) + gNotes = NotesVerbosity[gVerbosity] + incl(gNotes, enableNotes) + excl(gNotes, disableNotes) of "parallelbuild": expectArg(switch, arg, pass, info) gNumberOfProcessors = parseInt(arg) diff --git a/compiler/main.nim b/compiler/main.nim index 6bac4b77ae..1fe764541e 100644 --- a/compiler/main.nim +++ b/compiler/main.nim @@ -359,9 +359,8 @@ proc mainCommand* = else: rawMessage(errInvalidCommandX, command) - if (msgs.gErrorCounter == 0 and - gCmd notin {cmdInterpret, cmdRun, cmdDump} and - gVerbosity > 0): + if msgs.gErrorCounter == 0 and + gCmd notin {cmdInterpret, cmdRun, cmdDump}: rawMessage(hintSuccessX, [$gLinesCompiled, formatFloat(epochTime() - gLastCmdTime, ffDecimal, 3), formatSize(getTotalMem()), diff --git a/compiler/msgs.nim b/compiler/msgs.nim index 937b4bd614..ec6aa16040 100644 --- a/compiler/msgs.nim +++ b/compiler/msgs.nim @@ -483,6 +483,21 @@ type ERecoverableError* = object of ValueError 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 InvalidFileIDX* = int32(-1) @@ -571,9 +586,7 @@ proc raiseRecoverableError*(msg: string) {.noinline, noreturn.} = proc sourceLine*(i: TLineInfo): Rope var - gNotes*: TNoteKinds = {low(TNoteKind)..high(TNoteKind)} - - {warnShadowIdent, warnUninit, - warnProveField, warnProveIndex, warnGcUnsafe} + gNotes*: TNoteKinds = NotesVerbosity[1] # defaults to verbosity of 1 gErrorCounter*: int = 0 # counts the number of errors gHintCounter*: int = 0 gWarnCounter*: int = 0 diff --git a/compiler/nimblecmd.nim b/compiler/nimblecmd.nim index 23f3331a23..2044f104f7 100644 --- a/compiler/nimblecmd.nim +++ b/compiler/nimblecmd.nim @@ -60,7 +60,7 @@ iterator chosen(packages: StringTableRef): string = proc addNimblePath(p: string, info: TLineInfo) = if not contains(options.searchPaths, p): - if gVerbosity >= 1: message(info, hintPath, p) + message(info, hintPath, p) lists.prependStr(options.lazyPaths, p) proc addPathWithNimFiles(p: string, info: TLineInfo) = diff --git a/compiler/nimconf.nim b/compiler/nimconf.nim index 711b476e65..b9c78cecc8 100644 --- a/compiler/nimconf.nim +++ b/compiler/nimconf.nim @@ -211,7 +211,7 @@ proc readConfigFile(filename: string) = while tok.tokType != tkEof: parseAssignment(L, tok) if len(condStack) > 0: lexMessage(L, errTokenExpected, "@end") closeLexer(L) - if gVerbosity >= 1: rawMessage(hintConf, filename) + rawMessage(hintConf, filename) proc getUserConfigPath(filename: string): string = result = joinPath(getConfigDir(), filename) diff --git a/compiler/passaux.nim b/compiler/passaux.nim index f754c80e51..c3bafe7dfd 100644 --- a/compiler/passaux.nim +++ b/compiler/passaux.nim @@ -15,7 +15,7 @@ import proc verboseOpen(s: PSym): PPassContext = #MessageOut('compiling ' + s.name.s); 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 = result = n diff --git a/compiler/rodread.nim b/compiler/rodread.nim index c1c27aedba..080c93a26f 100644 --- a/compiler/rodread.nim +++ b/compiler/rodread.nim @@ -838,7 +838,7 @@ proc checkDep(fileIdx: int32): TReasonForRecompile = if res != rrNone: result = rrModDeps # we cannot break here, because of side-effects of `checkDep` - if result != rrNone and gVerbosity > 0: + if result != rrNone: rawMessage(hintProcessing, reasonToFrmt[result] % filename) if result != rrNone or optForceFullMake in gGlobalOptions: # recompilation is necessary: diff --git a/compiler/syntaxes.nim b/compiler/syntaxes.nim index 7f9e25f82f..5fd81d87e3 100644 --- a/compiler/syntaxes.nim +++ b/compiler/syntaxes.nim @@ -139,7 +139,7 @@ proc applyFilter(p: var TParsers, n: PNode, filename: string, of filtReplace: result = filterReplace(stdin, filename, n) if f != filtNone: - if gVerbosity >= 2: + if hintCodeBegin in gNotes: rawMessage(hintCodeBegin, []) msgWriteln(result.s) rawMessage(hintCodeEnd, [])