summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorTimothee Cour <timothee.cour2@gmail.com>2020-02-26 01:26:47 -0800
committerGitHub <noreply@github.com>2020-02-26 10:26:47 +0100
commitbd90199a2fd37568a5f5a6c7c394b160b229e90c (patch)
tree99c1b0ba5bdc017df101794483435e9f18dcfd7a
parent94b0d6bb63e354c71bf072953d27c097eb7b38ca (diff)
downloadNim-bd90199a2fd37568a5f5a6c7c394b160b229e90c.tar.gz
fix #8312 --hints:off and --warnings:off now honored everywhere (#13489)
-rw-r--r--compiler/ccgstmts.nim2
-rw-r--r--compiler/extccomp.nim2
-rw-r--r--compiler/hlo.nim4
-rw-r--r--compiler/msgs.nim14
-rw-r--r--compiler/nim.nim2
-rw-r--r--compiler/options.nim6
-rw-r--r--compiler/semexprs.nim2
-rw-r--r--compiler/sempass2.nim14
-rw-r--r--compiler/syntaxes.nim2
9 files changed, 26 insertions, 22 deletions
diff --git a/compiler/ccgstmts.nim b/compiler/ccgstmts.nim
index b9e26789f..c430dd062 100644
--- a/compiler/ccgstmts.nim
+++ b/compiler/ccgstmts.nim
@@ -1412,7 +1412,7 @@ proc genAsgn(p: BProc, e: PNode, fastAsgn: bool) =
 proc genStmts(p: BProc, t: PNode) =
   var a: TLoc
 
-  let isPush = hintExtendedContext in p.config.notes
+  let isPush = p.config.hasHint(hintExtendedContext)
   if isPush: pushInfoContext(p.config, t.info)
   expr(p, t, a)
   if isPush: popInfoContext(p.config)
diff --git a/compiler/extccomp.nim b/compiler/extccomp.nim
index 7cc43d56e..c6f062c78 100644
--- a/compiler/extccomp.nim
+++ b/compiler/extccomp.nim
@@ -715,7 +715,7 @@ proc compileCFiles(conf: ConfigRef; list: CfileList, script: var Rope, cmds: var
     if optCompileOnly notin conf.globalOptions:
       cmds.add(compileCmd)
       let (_, name, _) = splitFile(it.cname)
-      prettyCmds.add(if hintCC in conf.notes: "CC: " & demanglePackageName(name) else: "")
+      prettyCmds.add(if conf.hasHint(hintCC): "CC: " & demanglePackageName(name) else: "")
     if optGenScript in conf.globalOptions:
       script.add(compileCmd)
       script.add("\n")
diff --git a/compiler/hlo.nim b/compiler/hlo.nim
index 6756bdc2a..bb69a1477 100644
--- a/compiler/hlo.nim
+++ b/compiler/hlo.nim
@@ -17,7 +17,7 @@ proc evalPattern(c: PContext, n, orig: PNode): PNode =
   # awful to semcheck before macro invocation, so we don't and treat
   # templates and macros as immediate in this context.
   var rule: string
-  if optHints in c.config.options and hintPattern in c.config.notes:
+  if c.config.hasHint(hintPattern):
     rule = renderTree(n, {renderNoComments})
   let s = n[0].sym
   case s.kind
@@ -27,7 +27,7 @@ proc evalPattern(c: PContext, n, orig: PNode): PNode =
     result = semTemplateExpr(c, n, s, {efFromHlo})
   else:
     result = semDirectOp(c, n, {})
-  if optHints in c.config.options and hintPattern in c.config.notes:
+  if c.config.hasHint(hintPattern):
     message(c.config, orig.info, hintPattern, rule & " --> '" &
       renderTree(result, {renderNoComments}) & "'")
 
diff --git a/compiler/msgs.nim b/compiler/msgs.nim
index 91fad9ac1..6d1ecb2b1 100644
--- a/compiler/msgs.nim
+++ b/compiler/msgs.nim
@@ -340,7 +340,7 @@ proc log*(s: string) =
     close(f)
 
 proc quit(conf: ConfigRef; msg: TMsgKind) {.gcsafe.} =
-  if defined(debug) or msg == errInternal or hintStackTrace in conf.notes:
+  if defined(debug) or msg == errInternal or conf.hasHint(hintStackTrace):
     {.gcsafe.}:
       if stackTraceAvailable() and isNil(conf.writelnHook):
         writeStackTrace()
@@ -410,8 +410,7 @@ proc rawMessage*(conf: ConfigRef; msg: TMsgKind, args: openArray[string]) =
     color = ErrorColor
   of warnMin..warnMax:
     sev = Severity.Warning
-    if optWarns notin conf.options: return
-    if msg notin conf.notes: return
+    if not conf.hasWarn(msg): return
     writeContext(conf, unknownLineInfo)
     title = WarningTitle
     color = WarningColor
@@ -419,8 +418,7 @@ proc rawMessage*(conf: ConfigRef; msg: TMsgKind, args: openArray[string]) =
     inc(conf.warnCounter)
   of hintMin..hintMax:
     sev = Severity.Hint
-    if optHints notin conf.options: return
-    if msg notin conf.notes: return
+    if not conf.hasHint(msg): return
     title = HintTitle
     color = HintColor
     if msg != hintUserRaw: kind = HintsToStr[ord(msg) - ord(hintMin)]
@@ -500,7 +498,7 @@ proc liMessage(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg: string,
     conf.m.lastError = info
   of warnMin..warnMax:
     sev = Severity.Warning
-    ignoreMsg = optWarns notin conf.options or msg notin conf.notes
+    ignoreMsg = not conf.hasWarn(msg)
     if not ignoreMsg: writeContext(conf, info)
     title = WarningTitle
     color = WarningColor
@@ -508,7 +506,7 @@ proc liMessage(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg: string,
     inc(conf.warnCounter)
   of hintMin..hintMax:
     sev = Severity.Hint
-    ignoreMsg = optHints notin conf.options or msg notin conf.notes
+    ignoreMsg = not conf.hasHint(msg)
     title = HintTitle
     color = HintColor
     if msg != hintUserRaw: kind = HintsToStr[ord(msg) - ord(hintMin)]
@@ -526,7 +524,7 @@ proc liMessage(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg: string,
                          KindColor, `%`(KindFormat, kind))
       else:
         styledMsgWriteln(styleBright, x, resetStyle, color, title, resetStyle, s)
-      if hintSource in conf.notes:
+      if conf.hasHint(hintSource):
         conf.writeSurroundingSrc(info)
   handleError(conf, msg, eh, s)
 
diff --git a/compiler/nim.nim b/compiler/nim.nim
index cc1dc2fe7..b916f0d85 100644
--- a/compiler/nim.nim
+++ b/compiler/nim.nim
@@ -93,7 +93,7 @@ proc handleCmdLine(cache: IdentCache; conf: ConfigRef) =
 
   self.processCmdLineAndProjectPath(conf)
   if not self.loadConfigsAndRunMainCommand(cache, conf): return
-  if optHints in conf.options and hintGCStats in conf.notes: echo(GC_getStatistics())
+  if conf.hasHint(hintGCStats): echo(GC_getStatistics())
   #echo(GC_getStatistics())
   if conf.errorCounter != 0: return
   when hasTinyCBackend:
diff --git a/compiler/options.nim b/compiler/options.nim
index c39ffa792..7a7ab0bcd 100644
--- a/compiler/options.nim
+++ b/compiler/options.nim
@@ -287,6 +287,12 @@ type
                                 severity: Severity) {.closure, gcsafe.}
     cppCustomNamespace*: string
 
+proc hasHint*(conf: ConfigRef, note: TNoteKind): bool =
+  optHints in conf.options and note in conf.notes
+
+proc hasWarn*(conf: ConfigRef, note: TNoteKind): bool =
+  optWarns in conf.options and note in conf.notes
+
 proc hcrOn*(conf: ConfigRef): bool = return optHotCodeReloading in conf.globalOptions
 
 template depConfigFields*(fn) {.dirty.} =
diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim
index 375ea1cb1..f75642bcb 100644
--- a/compiler/semexprs.nim
+++ b/compiler/semexprs.nim
@@ -990,7 +990,7 @@ proc buildEchoStmt(c: PContext, n: PNode): PNode =
   result = semExpr(c, result)
 
 proc semExprNoType(c: PContext, n: PNode): PNode =
-  let isPush = hintExtendedContext in c.config.notes
+  let isPush = c.config.hasHint(hintExtendedContext)
   if isPush: pushInfoContext(c.config, n.info)
   result = semExpr(c, n, {efWantStmt})
   discardCheck(c, result, {})
diff --git a/compiler/sempass2.nim b/compiler/sempass2.nim
index 82287c675..98ef8cf85 100644
--- a/compiler/sempass2.nim
+++ b/compiler/sempass2.nim
@@ -262,7 +262,7 @@ proc useVar(a: PEffects, n: PNode) =
     if s.guard != nil: guardGlobal(a, n, s.guard)
     if {sfGlobal, sfThread} * s.flags == {sfGlobal} and
         (tfHasGCedMem in s.typ.flags or s.typ.isGCedMem):
-      #if warnGcUnsafe in gNotes: warnAboutGcUnsafe(n)
+      #if a.config.hasWarn(warnGcUnsafe): warnAboutGcUnsafe(n)
       markGcUnsafe(a, s)
       markSideEffect(a, s)
     else:
@@ -463,7 +463,7 @@ proc propagateEffects(tracked: PEffects, n: PNode, s: PSym) =
   mergeTags(tracked, tagSpec, n)
 
   if notGcSafe(s.typ) and sfImportc notin s.flags:
-    if warnGcUnsafe in tracked.config.notes: warnAboutGcUnsafe(n, tracked.config)
+    if tracked.config.hasWarn(warnGcUnsafe): warnAboutGcUnsafe(n, tracked.config)
     markGcUnsafe(tracked, s)
   if tfNoSideEffect notin s.typ.flags:
     markSideEffect(tracked, s)
@@ -544,7 +544,7 @@ proc trackOperand(tracked: PEffects, n: PNode, paramType: PType; caller: PNode)
         assumeTheWorst(tracked, n, op)
       # assume GcUnsafe unless in its type; 'forward' does not matter:
       if notGcSafe(op) and not isOwnedProcVar(a, tracked.owner):
-        if warnGcUnsafe in tracked.config.notes: warnAboutGcUnsafe(n, tracked.config)
+        if tracked.config.hasWarn(warnGcUnsafe): warnAboutGcUnsafe(n, tracked.config)
         markGcUnsafe(tracked, a)
       elif tfNoSideEffect notin op.flags and not isOwnedProcVar(a, tracked.owner):
         markSideEffect(tracked, a)
@@ -552,7 +552,7 @@ proc trackOperand(tracked: PEffects, n: PNode, paramType: PType; caller: PNode)
       mergeEffects(tracked, effectList[exceptionEffects], n)
       mergeTags(tracked, effectList[tagEffects], n)
       if notGcSafe(op):
-        if warnGcUnsafe in tracked.config.notes: warnAboutGcUnsafe(n, tracked.config)
+        if tracked.config.hasWarn(warnGcUnsafe): warnAboutGcUnsafe(n, tracked.config)
         markGcUnsafe(tracked, a)
       elif tfNoSideEffect notin op.flags:
         markSideEffect(tracked, a)
@@ -584,7 +584,7 @@ proc trackCase(tracked: PEffects, n: PNode) =
   let stringCase = skipTypes(n[0].typ,
         abstractVarRange-{tyTypeDesc}).kind in {tyFloat..tyFloat128, tyString}
   let interesting = not stringCase and interestingCaseExpr(n[0]) and
-        warnProveField in tracked.config.notes
+        tracked.config.hasWarn(warnProveField)
   var inter: TIntersection = @[]
   var toCover = 0
   for i in 1..<n.len:
@@ -678,7 +678,7 @@ proc track(tracked: PEffects, n: PNode) =
     if notGcSafe(op) and not importedFromC(a):
       # and it's not a recursive call:
       if not (a.kind == nkSym and a.sym == tracked.owner):
-        if warnGcUnsafe in tracked.config.notes: warnAboutGcUnsafe(n, tracked.config)
+        if tracked.config.hasWarn(warnGcUnsafe): warnAboutGcUnsafe(n, tracked.config)
         markGcUnsafe(tracked, a)
     if tfNoSideEffect notin op.flags and not importedFromC(a):
       # and it's not a recursive call:
@@ -779,7 +779,7 @@ proc track(tracked: PEffects, n: PNode) =
     for i in 0..<n.len: track(tracked, n[i])
   of nkCheckedFieldExpr:
     track(tracked, n[0])
-    if warnProveField in tracked.config.notes:
+    if tracked.config.hasWarn(warnProveField):
       checkFieldAccess(tracked.guards, n, tracked.config)
   of nkTryStmt: trackTryStmt(tracked, n)
   of nkPragma: trackPragmaStmt(tracked, n)
diff --git a/compiler/syntaxes.nim b/compiler/syntaxes.nim
index 59016b2b6..29ccf4794 100644
--- a/compiler/syntaxes.nim
+++ b/compiler/syntaxes.nim
@@ -120,7 +120,7 @@ proc applyFilter(p: var TParsers, n: PNode, filename: AbsoluteFile,
     result = filterReplace(p.config, stdin, filename, n)
   if f != filtNone:
     assert p.config != nil
-    if hintCodeBegin in p.config.notes:
+    if p.config.hasHint(hintCodeBegin):
       rawMessage(p.config, hintCodeBegin, [])
       msgWriteln(p.config, result.s)
       rawMessage(p.config, hintCodeEnd, [])