* fix #7405 and #8195

* control pushInfoContext in semExprNoType,genStmts via a new hintExtendedContext; make NotesVerbosity computation more DRY

* addressed comments
This commit is contained in:
Timothee Cour 2018-07-16 04:34:44 -07:00 • committed by Andreas Rumpf
commit d07489abf4
3 changed files with 25 additions and 26 deletions

View file

@ -1146,5 +1146,9 @@ proc genAsgn(p: BProc, e: PNode, fastAsgn: bool) =
proc genStmts(p: BProc, t: PNode) = proc genStmts(p: BProc, t: PNode) =
var a: TLoc var a: TLoc
let isPush = hintExtendedContext in p.config.notes
if isPush: pushInfoContext(p.config, t.info)
expr(p, t, a) expr(p, t, a)
if isPush: popInfoContext(p.config)
internalAssert p.config, a.k in {locNone, locTemp, locLocalVar} internalAssert p.config, a.k in {locNone, locTemp, locLocalVar}

View file

@ -45,7 +45,8 @@ type
hintExecuting, hintLinking, hintDependency, hintExecuting, hintLinking, hintDependency,
hintSource, hintPerformance, hintStackTrace, hintGCStats, hintSource, hintPerformance, hintStackTrace, hintGCStats,
hintGlobalVar, hintGlobalVar,
hintUser, hintUserRaw hintUser, hintUserRaw,
hintExtendedContext
const const
MsgKindToStr*: array[TMsgKind, string] = [ MsgKindToStr*: array[TMsgKind, string] = [
@ -116,7 +117,9 @@ const
hintGCStats: "$1", hintGCStats: "$1",
hintGlobalVar: "global variable declared here", hintGlobalVar: "global variable declared here",
hintUser: "$1", hintUser: "$1",
hintUserRaw: "$1"] hintUserRaw: "$1",
hintExtendedContext: "$1",
]
const const
WarningsToStr* = ["CannotOpenFile", "OctalEscape", WarningsToStr* = ["CannotOpenFile", "OctalEscape",
@ -132,12 +135,14 @@ const
"GcMem", "Destructor", "LockLevel", "ResultShadowed", "GcMem", "Destructor", "LockLevel", "ResultShadowed",
"Spacing", "User"] "Spacing", "User"]
HintsToStr* = ["Success", "SuccessX", "LineTooLong", HintsToStr* = [
"Success", "SuccessX", "LineTooLong",
"XDeclaredButNotUsed", "ConvToBaseNotNeeded", "ConvFromXtoItselfNotNeeded", "XDeclaredButNotUsed", "ConvToBaseNotNeeded", "ConvFromXtoItselfNotNeeded",
"ExprAlwaysX", "QuitCalled", "Processing", "CodeBegin", "CodeEnd", "Conf", "ExprAlwaysX", "QuitCalled", "Processing", "CodeBegin", "CodeEnd", "Conf",
"Path", "CondTrue", "Name", "Pattern", "Exec", "Link", "Dependency", "Path", "CondTrue", "Name", "Pattern", "Exec", "Link", "Dependency",
"Source", "Performance", "StackTrace", "GCStats", "GlobalVar", "Source", "Performance", "StackTrace", "GCStats", "GlobalVar",
"User", "UserRaw"] "User", "UserRaw", "ExtendedContext",
]
const const
fatalMin* = errUnknown fatalMin* = errUnknown
@ -157,30 +162,17 @@ type
TNoteKind* = range[warnMin..hintMax] # "notes" are warnings or hints TNoteKind* = range[warnMin..hintMax] # "notes" are warnings or hints
TNoteKinds* = set[TNoteKind] TNoteKinds* = set[TNoteKind]
const proc computeNotesVerbosity(): array[0..3, TNoteKinds] =
NotesVerbosity*: array[0..3, TNoteKinds] = [ result[3] = {low(TNoteKind)..high(TNoteKind)} - {}
{low(TNoteKind)..high(TNoteKind)} - {warnShadowIdent, warnUninit, result[2] = result[3] - {hintStackTrace, warnUninit, hintExtendedContext}
warnProveField, warnProveIndex, result[1] = result[2] - {warnShadowIdent, warnProveField, warnProveIndex,
warnGcUnsafe, warnGcUnsafe, hintPath, hintDependency, hintCodeBegin, hintCodeEnd,
hintSuccessX, hintPath, hintConf, hintSource, hintGlobalVar, hintGCStats}
hintProcessing, hintPattern, result[0] = result[1] - {hintSuccessX, hintConf, hintProcessing,
hintDependency, hintPattern, hintExecuting, hintLinking}
hintExecuting, hintLinking,
hintCodeBegin, hintCodeEnd,
hintSource, hintStackTrace,
hintGlobalVar, hintGCStats},
{low(TNoteKind)..high(TNoteKind)} - {warnShadowIdent, warnUninit,
warnProveField, warnProveIndex,
warnGcUnsafe,
hintPath,
hintDependency,
hintCodeBegin, hintCodeEnd,
hintSource, hintStackTrace,
hintGlobalVar, hintGCStats},
{low(TNoteKind)..high(TNoteKind)} - {hintStackTrace, warnUninit},
{low(TNoteKind)..high(TNoteKind)}]
const const
NotesVerbosity* = computeNotesVerbosity()
errXMustBeCompileTime* = "'$1' can only be used in compile-time context" errXMustBeCompileTime* = "'$1' can only be used in compile-time context"
errArgsNeedRunOption* = "arguments can only be given if the '--run' option is selected" errArgsNeedRunOption* = "arguments can only be given if the '--run' option is selected"

View file

@ -907,8 +907,11 @@ proc buildEchoStmt(c: PContext, n: PNode): PNode =
result = semExpr(c, result) result = semExpr(c, result)
proc semExprNoType(c: PContext, n: PNode): PNode = proc semExprNoType(c: PContext, n: PNode): PNode =
let isPush = hintExtendedContext in c.config.notes
if isPush: pushInfoContext(c.config, n.info)
result = semExpr(c, n, {efWantStmt}) result = semExpr(c, n, {efWantStmt})
discardCheck(c, result) discardCheck(c, result)
if isPush: popInfoContext(c.config)
proc isTypeExpr(n: PNode): bool = proc isTypeExpr(n: PNode): bool =
case n.kind case n.kind