summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorTimothee Cour <timothee.cour2@gmail.com>2020-02-26 12:49:44 -0800
committerAndreas Rumpf <rumpf_a@web.de>2020-02-27 13:22:18 +0100
commit1056f9ecff60f624522f24e508d0976994bcef80 (patch)
treeadc7f492f880d575a29457bf27d5824d253210b4
parentc1cbf94e2d41911fe11ea98e86000f9a851fc01a (diff)
downloadNim-1056f9ecff60f624522f24e508d0976994bcef80.tar.gz
properly handle note override logic/verbosity/config/cmdline using modifiedyNotes, cmdlineNotes
-rw-r--r--compiler/commands.nim41
-rw-r--r--compiler/msgs.nim5
-rw-r--r--compiler/options.nim12
-rw-r--r--compiler/passaux.nim4
-rw-r--r--compiler/pragmas.nim1
5 files changed, 31 insertions, 32 deletions
diff --git a/compiler/commands.nim b/compiler/commands.nim
index d2f1f78b3..0545ee2b0 100644
--- a/compiler/commands.nim
+++ b/compiler/commands.nim
@@ -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)
@@ -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":
@@ -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)
diff --git a/compiler/msgs.nim b/compiler/msgs.nim
index 197295249..6d1ecb2b1 100644
--- a/compiler/msgs.nim
+++ b/compiler/msgs.nim
@@ -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)]
diff --git a/compiler/options.nim b/compiler/options.nim
index 9d073ce45..c93fc0648 100644
--- a/compiler/options.nim
+++ b/compiler/options.nim
@@ -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
@@ -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
 
diff --git a/compiler/passaux.nim b/compiler/passaux.nim
index 2ac89c24e..155b956df 100644
--- a/compiler/passaux.nim
+++ b/compiler/passaux.nim
@@ -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)
diff --git a/compiler/pragmas.nim b/compiler/pragmas.nim
index 029128086..559c1c064 100644
--- a/compiler/pragmas.nim
+++ b/compiler/pragmas.nim
@@ -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)