Skip to content

Commit

Permalink
add --warning:BackendWarning:off to suppress backend warnings if ev…
Browse files Browse the repository at this point in the history
…er needed, as alternative to `--passc:-w` (so that it remains compiler/OS platform independent)
  • Loading branch information
timotheecour committed Mar 11, 2020
1 parent fc8dc00 commit 6bb6961
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
10 changes: 10 additions & 0 deletions compiler/commands.nim
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,15 @@ proc expectNoArg(conf: ConfigRef; switch, arg: string, pass: TCmdLinePass, info:
if arg != "":
localError(conf, info, "invalid argument for command line option: '$1'" % addPrefix(switch))

proc handleSpecialNotes(conf: ConfigRef, pass: TCmdLinePass, note: TNoteKind) =
## some notes require special handling so that cmdline flags overrides work
## as expected.
case note
of warnBackendWarning:
if pass in {passCmd2, passPP}:
extccomp.addCompileOptionCmd(conf, warningsOff, isRemove = conf.hasWarn(note))
else: discard

proc processSpecificNote*(arg: string, state: TSpecialWord, pass: TCmdLinePass,
info: TLineInfo; orig: string; conf: ConfigRef) =
var id = "" # arg = key:val or [key]:val; with val=on|off
Expand Down Expand Up @@ -214,6 +223,7 @@ proc processSpecificNote*(arg: string, state: TSpecialWord, pass: TCmdLinePass,
excl(conf.notes, n)
excl(conf.mainPackageNotes, n)
excl(conf.foreignPackageNotes, n)
handleSpecialNotes(conf, pass, n)

proc processCompile(conf: ConfigRef; filename: string) =
var found = findFile(conf, filename)
Expand Down
9 changes: 7 additions & 2 deletions compiler/extccomp.nim
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ template compiler(name, settings: untyped): untyped =

const
gnuAsmListing = "-Wa,-acdl=$asmfile -g -fverbose-asm -masm=intel"
warningsOff* = "-w" # if needed, can be compiler specific

# GNU C and C++ Compiler
compiler gcc:
Expand Down Expand Up @@ -448,8 +449,12 @@ proc addCompileOption*(conf: ConfigRef; option: string) =
proc addLinkOptionCmd*(conf: ConfigRef; option: string) =
addOpt(conf.linkOptionsCmd, option)

proc addCompileOptionCmd*(conf: ConfigRef; option: string) =
conf.compileOptionsCmd.add(option)
proc addCompileOptionCmd*(conf: ConfigRef; option: string, isRemove = false) =
if isRemove:
if (var index = conf.compileOptionsCmd.find(option); index >= 0):
conf.compileOptionsCmd.delete(index)
else:
conf.compileOptionsCmd.add(option)

proc initVars*(conf: ConfigRef) =
# we need to define the symbol here, because ``CC`` may have never been set!
Expand Down
9 changes: 7 additions & 2 deletions compiler/lineinfos.nim
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const

type
TMsgKind* = enum
# errors
errUnknown, errInternal, errIllFormedAstX, errCannotOpenFile,
errXExpected,
errGridTableNotImplemented,
Expand All @@ -25,6 +26,7 @@ type
errInvalidDirectiveX,
errGenerated,
errUser,
# warnings
warnCannotOpenFile,
warnOctalEscape, warnXIsNeverRead, warnXmightNotBeenInit,
warnDeprecated, warnConfigDeprecated,
Expand All @@ -37,7 +39,9 @@ type
warnEachIdentIsTuple,
warnProveInit, warnProveField, warnProveIndex, warnGcUnsafe, warnGcUnsafe2,
warnUninit, warnGcMem, warnDestructor, warnLockLevel, warnResultShadowed,
warnInconsistentSpacing, warnCaseTransition, warnCycleCreated, warnUser,
warnInconsistentSpacing, warnCaseTransition, warnCycleCreated,
warnBackendWarning, warnUser,
# hints
hintSuccess, hintSuccessX, hintCC,
hintLineTooLong, hintXDeclaredButNotUsed,
hintConvToBaseNotNeeded,
Expand Down Expand Up @@ -95,6 +99,7 @@ const
warnInconsistentSpacing: "Number of spaces around '$#' is not consistent",
warnCaseTransition: "Potential object case transition, instantiate new object instead",
warnCycleCreated: "$1",
warnBackendWarning: "$1",
warnUser: "$1",
hintSuccess: "operation successful: $#",
# keep in sync with `pegSuccess` see testament.nim
Expand Down Expand Up @@ -141,7 +146,7 @@ const
"UnsafeCode", "UnusedImport", "EachIdentIsTuple",
"ProveInit", "ProveField", "ProveIndex", "GcUnsafe", "GcUnsafe2", "Uninit",
"GcMem", "Destructor", "LockLevel", "ResultShadowed",
"Spacing", "CaseTransition", "CycleCreated", "User"]
"Spacing", "CaseTransition", "CycleCreated", "BackendWarning", "User"]

HintsToStr* = [
"Success", "SuccessX", "CC", "LineTooLong",
Expand Down

0 comments on commit 6bb6961

Please sign in to comment.