Skip to content

Commit

Permalink
properly handle note override logic/verbosity/config/cmdline using mo…
Browse files Browse the repository at this point in the history
…difiedyNotes, cmdlineNotes
  • Loading branch information
timotheecour authored and Araq committed Feb 27, 2020
1 parent c1cbf94 commit 1056f9e
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 32 deletions.
41 changes: 20 additions & 21 deletions compiler/commands.nim
Original file line number Diff line number Diff line change
Expand Up @@ -199,23 +199,21 @@ proc processSpecificNote*(arg: string, state: TSpecialWord, pass: TCmdLinePass,
let x = findStr(lineinfos.WarningsToStr, id)
if x >= 0: n = TNoteKind(x + ord(warnMin))
else: localError(conf, info, "unknown warning: " & id)
case substr(arg, i).normalize
of "on":
incl(conf.notes, n)
incl(conf.mainPackageNotes, n)
incl(conf.enableNotes, n)
if pass == passCmd1:
incl(conf.cmdLineNotes, n)
excl(conf.cmdLineDisabledNotes, n)
of "off":
excl(conf.notes, n)
excl(conf.mainPackageNotes, n)
incl(conf.disableNotes, n)
excl(conf.foreignPackageNotes, n)
if pass == passCmd1:
incl(conf.cmdLineDisabledNotes, n)
excl(conf.cmdLineNotes, n)
else: localError(conf, info, errOnOrOffExpectedButXFound % arg)

let val = substr(arg, i).normalize
if val notin ["on", "off"]:
localError(conf, info, errOnOrOffExpectedButXFound % arg)
elif n notin conf.cmdlineNotes or pass == passCmd1:
if pass == passCmd1: incl(conf.cmdlineNotes, n)
incl(conf.modifiedyNotes, n)
case val
of "on":
incl(conf.notes, n)
incl(conf.mainPackageNotes, n)
of "off":
excl(conf.notes, n)
excl(conf.mainPackageNotes, n)
excl(conf.foreignPackageNotes, n)

proc processCompile(conf: ConfigRef; filename: string) =
var found = findFile(conf, filename)
Expand Down Expand Up @@ -598,7 +596,7 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
of "deadcodeelim": discard # deprecated, dead code elim always on
of "threads":
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 "taintmode": processOnOffSwitchG(conf, {optTaintMode}, arg, pass, info)
of "implicitstatic":
Expand Down Expand Up @@ -710,9 +708,10 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
if verbosity notin {0..3}:
localError(conf, info, "invalid verbosity level: '$1'" % arg)
conf.verbosity = verbosity
conf.notes = NotesVerbosity[conf.verbosity]
incl(conf.notes, conf.enableNotes)
excl(conf.notes, conf.disableNotes)
var verb = NotesVerbosity[conf.verbosity]
## We override the default `verb` by explicitly modified (set/unset) notes.
conf.notes = (conf.modifiedyNotes * conf.notes + verb) -
(conf.modifiedyNotes * verb - conf.notes)
conf.mainPackageNotes = conf.notes
of "parallelbuild":
expectArg(conf, switch, arg, pass, info)
Expand Down
5 changes: 1 addition & 4 deletions compiler/msgs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -418,10 +418,7 @@ proc rawMessage*(conf: ConfigRef; msg: TMsgKind, args: openArray[string]) =
inc(conf.warnCounter)
of hintMin..hintMax:
sev = Severity.Hint
if msg in conf.cmdLineDisabledNotes: return # eg: `--hints:conf:off` passed on cmdline
# 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
if not conf.hasHint(msg): return
title = HintTitle
color = HintColor
if msg != hintUserRaw: kind = HintsToStr[ord(msg) - ord(hintMin)]
Expand Down
12 changes: 7 additions & 5 deletions compiler/options.nim
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,11 @@ type
ideCmd*: IdeCmd
oldNewlines*: bool
cCompiler*: TSystemCC
enableNotes*: TNoteKinds
disableNotes*: TNoteKinds
modifiedyNotes*: TNoteKinds # notes that have been set/unset from either cmdline/configs
cmdlineNotes*: TNoteKinds # notes that have been set/unset from cmdline
foreignPackageNotes*: TNoteKinds
notes*: TNoteKinds
notes*: TNoteKinds # notes after resolving all logic(defaults, verbosity)/cmdline/configs
mainPackageNotes*: TNoteKinds
cmdLineNotes*: TNoteKinds
cmdLineDisabledNotes*: TNoteKinds
mainPackageId*: int
errorCounter*: int
hintCounter*: int
Expand Down Expand Up @@ -289,6 +287,10 @@ type
severity: Severity) {.closure, gcsafe.}
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 =
optHints in conf.options and note in conf.notes

Expand Down
4 changes: 2 additions & 2 deletions compiler/passaux.nim
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ proc verboseProcess(context: PPassContext, n: PNode): PNode =
let v = VerboseRef(context)
if v.config.verbosity == 3:
# system.nim deactivates all hints, for verbosity:3 we want the processing
# messages nonetheless, so we activate them again unconditionally:
incl(v.config.notes, hintProcessing)
# messages nonetheless, so we activate them again (but honor cmdlineNotes)
v.config.setNote(hintProcessing)
message(v.config, n.info, hintProcessing, $idgen.gFrontEndId)

const verbosePass* = makePass(open = verboseOpen, process = verboseProcess)
1 change: 1 addition & 0 deletions compiler/pragmas.nim
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ proc processNote(c: PContext, n: PNode) =
n[1] = x
if x.kind == nkIntLit and x.intVal != 0: incl(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:
invalidPragma(c, n)

Expand Down

0 comments on commit 1056f9e

Please sign in to comment.