properly handle note override logic/verbosity/config/cmdline using modifiedyNotes, cmdlineNotes

This commit is contained in:
Timothee Cour 2020-02-26 12:49:44 -08:00 • committed by Andreas Rumpf
commit 1056f9ecff
5 changed files with 31 additions and 32 deletions

View file

@ -199,23 +199,21 @@ proc processSpecificNote*(arg: string, state: TSpecialWord, pass: TCmdLinePass,
let x = findStr(lineinfos.WarningsToStr, id) let x = findStr(lineinfos.WarningsToStr, id)
if x >= 0: n = TNoteKind(x + ord(warnMin)) if x >= 0: n = TNoteKind(x + ord(warnMin))
else: localError(conf, info, "unknown warning: " & id) else: localError(conf, info, "unknown warning: " & id)
case substr(arg, i).normalize
of "on": let val = substr(arg, i).normalize
incl(conf.notes, n) if val notin ["on", "off"]:
incl(conf.mainPackageNotes, n) localError(conf, info, errOnOrOffExpectedButXFound % arg)
incl(conf.enableNotes, n) elif n notin conf.cmdlineNotes or pass == passCmd1:
if pass == passCmd1: if pass == passCmd1: incl(conf.cmdlineNotes, n)
incl(conf.cmdLineNotes, n) incl(conf.modifiedyNotes, n)
excl(conf.cmdLineDisabledNotes, n) case val
of "off": of "on":
excl(conf.notes, n) incl(conf.notes, n)
excl(conf.mainPackageNotes, n) incl(conf.mainPackageNotes, n)
incl(conf.disableNotes, n) of "off":
excl(conf.foreignPackageNotes, n) excl(conf.notes, n)
if pass == passCmd1: excl(conf.mainPackageNotes, n)
incl(conf.cmdLineDisabledNotes, n) excl(conf.foreignPackageNotes, n)
excl(conf.cmdLineNotes, n)
else: localError(conf, info, errOnOrOffExpectedButXFound % arg)
proc processCompile(conf: ConfigRef; filename: string) = proc processCompile(conf: ConfigRef; filename: string) =
var found = findFile(conf, filename) var found = findFile(conf, filename)
@ -598,7 +596,7 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
of "deadcodeelim": discard # deprecated, dead code elim always on of "deadcodeelim": discard # deprecated, dead code elim always on
of "threads": of "threads":
processOnOffSwitchG(conf, {optThreads}, arg, pass, info) processOnOffSwitchG(conf, {optThreads}, arg, pass, info)
#if optThreads in conf.globalOptions: incl(conf.notes, warnGcUnsafe) #if optThreads in conf.globalOptions: conf.setNote(warnGcUnsafe)
of "tlsemulation": processOnOffSwitchG(conf, {optTlsEmulation}, arg, pass, info) of "tlsemulation": processOnOffSwitchG(conf, {optTlsEmulation}, arg, pass, info)
of "taintmode": processOnOffSwitchG(conf, {optTaintMode}, arg, pass, info) of "taintmode": processOnOffSwitchG(conf, {optTaintMode}, arg, pass, info)
of "implicitstatic": of "implicitstatic":
@ -710,9 +708,10 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
if verbosity notin {0..3}: if verbosity notin {0..3}:
localError(conf, info, "invalid verbosity level: '$1'" % arg) localError(conf, info, "invalid verbosity level: '$1'" % arg)
conf.verbosity = verbosity conf.verbosity = verbosity
conf.notes = NotesVerbosity[conf.verbosity] var verb = NotesVerbosity[conf.verbosity]
incl(conf.notes, conf.enableNotes) ## We override the default `verb` by explicitly modified (set/unset) notes.
excl(conf.notes, conf.disableNotes) conf.notes = (conf.modifiedyNotes * conf.notes + verb) -
(conf.modifiedyNotes * verb - conf.notes)
conf.mainPackageNotes = conf.notes conf.mainPackageNotes = conf.notes
of "parallelbuild": of "parallelbuild":
expectArg(conf, switch, arg, pass, info) expectArg(conf, switch, arg, pass, info)

View file

@ -418,10 +418,7 @@ proc rawMessage*(conf: ConfigRef; msg: TMsgKind, args: openArray[string]) =
inc(conf.warnCounter) inc(conf.warnCounter)
of hintMin..hintMax: of hintMin..hintMax:
sev = Severity.Hint sev = Severity.Hint
if msg in conf.cmdLineDisabledNotes: return # eg: `--hints:conf:off` passed on cmdline if not conf.hasHint(msg): return
# handle `--hints:off` (regardless of cmdline/cfg file)
# handle `--hints:conf:on` on cmdline
if not conf.hasHint(msg) and not (optHints in conf.options and msg in conf.cmdLineNotes): return
title = HintTitle title = HintTitle
color = HintColor color = HintColor
if msg != hintUserRaw: kind = HintsToStr[ord(msg) - ord(hintMin)] if msg != hintUserRaw: kind = HintsToStr[ord(msg) - ord(hintMin)]

View file

@ -226,13 +226,11 @@ type
ideCmd*: IdeCmd ideCmd*: IdeCmd
oldNewlines*: bool oldNewlines*: bool
cCompiler*: TSystemCC cCompiler*: TSystemCC
enableNotes*: TNoteKinds modifiedyNotes*: TNoteKinds # notes that have been set/unset from either cmdline/configs
disableNotes*: TNoteKinds cmdlineNotes*: TNoteKinds # notes that have been set/unset from cmdline
foreignPackageNotes*: TNoteKinds foreignPackageNotes*: TNoteKinds
notes*: TNoteKinds notes*: TNoteKinds # notes after resolving all logic(defaults, verbosity)/cmdline/configs
mainPackageNotes*: TNoteKinds mainPackageNotes*: TNoteKinds
cmdLineNotes*: TNoteKinds
cmdLineDisabledNotes*: TNoteKinds
mainPackageId*: int mainPackageId*: int
errorCounter*: int errorCounter*: int
hintCounter*: int hintCounter*: int
@ -289,6 +287,10 @@ type
severity: Severity) {.closure, gcsafe.} severity: Severity) {.closure, gcsafe.}
cppCustomNamespace*: string cppCustomNamespace*: string
proc setNote*(conf: ConfigRef, note: TNoteKind, enabled = true) =
if note notin conf.cmdlineNotes:
if enabled: incl(conf.notes, note) else: excl(conf.notes, note)
proc hasHint*(conf: ConfigRef, note: TNoteKind): bool = proc hasHint*(conf: ConfigRef, note: TNoteKind): bool =
optHints in conf.options and note in conf.notes optHints in conf.options and note in conf.notes

View file

@ -28,8 +28,8 @@ proc verboseProcess(context: PPassContext, n: PNode): PNode =
let v = VerboseRef(context) let v = VerboseRef(context)
if v.config.verbosity == 3: if v.config.verbosity == 3:
# system.nim deactivates all hints, for verbosity:3 we want the processing # system.nim deactivates all hints, for verbosity:3 we want the processing
# messages nonetheless, so we activate them again unconditionally: # messages nonetheless, so we activate them again (but honor cmdlineNotes)
incl(v.config.notes, hintProcessing) v.config.setNote(hintProcessing)
message(v.config, n.info, hintProcessing, $idgen.gFrontEndId) message(v.config, n.info, hintProcessing, $idgen.gFrontEndId)
const verbosePass* = makePass(open = verboseOpen, process = verboseProcess) const verbosePass* = makePass(open = verboseOpen, process = verboseProcess)

View file

@ -328,6 +328,7 @@ proc processNote(c: PContext, n: PNode) =
n[1] = x n[1] = x
if x.kind == nkIntLit and x.intVal != 0: incl(c.config.notes, nk) if x.kind == nkIntLit and x.intVal != 0: incl(c.config.notes, nk)
else: excl(c.config.notes, nk) else: excl(c.config.notes, nk)
# checkme: honor cmdlineNotes with: c.setNote(nk, x.kind == nkIntLit and x.intVal != 0)
else: else:
invalidPragma(c, n) invalidPragma(c, n)