mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-15 23:54:19 +00:00
add --declaredlocs (#15666)
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
|
||||
|
||||
## Compiler changes
|
||||
|
||||
add `--declaredlocs` to show symbol declaration location in messages
|
||||
|
||||
|
||||
## Tool changes
|
||||
|
||||
@@ -794,6 +794,8 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
|
||||
processOnOffSwitchG(conf, {optStdout}, arg, pass, info)
|
||||
of "listfullpaths":
|
||||
processOnOffSwitchG(conf, {optListFullPaths}, arg, pass, info)
|
||||
of "declaredlocs":
|
||||
processOnOffSwitchG(conf, {optDeclaredLocs}, arg, pass, info)
|
||||
of "dynliboverride":
|
||||
dynlibOverride(conf, switch, arg, pass, info)
|
||||
of "dynliboverrideall":
|
||||
|
||||
@@ -69,6 +69,7 @@ type
|
||||
hintUser, hintUserRaw,
|
||||
hintExtendedContext,
|
||||
hintMsgOrigin, # since 1.3.5
|
||||
hintDeclaredLoc, # since 1.5.1
|
||||
|
||||
const
|
||||
MsgKindToStr*: array[TMsgKind, string] = [
|
||||
@@ -159,6 +160,7 @@ const
|
||||
hintUserRaw: "$1",
|
||||
hintExtendedContext: "$1",
|
||||
hintMsgOrigin: "$1",
|
||||
hintDeclaredLoc: "$1",
|
||||
]
|
||||
|
||||
const
|
||||
@@ -186,7 +188,7 @@ const
|
||||
"ExprAlwaysX", "QuitCalled", "Processing", "CodeBegin", "CodeEnd", "Conf",
|
||||
"Path", "CondTrue", "CondFalse", "Name", "Pattern", "Exec", "Link", "Dependency",
|
||||
"Source", "Performance", "StackTrace", "GCStats", "GlobalVar", "ExpandMacro",
|
||||
"User", "UserRaw", "ExtendedContext", "MsgOrigin",
|
||||
"User", "UserRaw", "ExtendedContext", "MsgOrigin", "DeclaredLoc"
|
||||
]
|
||||
|
||||
const
|
||||
@@ -215,7 +217,7 @@ type
|
||||
|
||||
proc computeNotesVerbosity(): array[0..3, TNoteKinds] =
|
||||
result[3] = {low(TNoteKind)..high(TNoteKind)} - {warnObservableStores}
|
||||
result[2] = result[3] - {hintStackTrace, warnUninit, hintExtendedContext}
|
||||
result[2] = result[3] - {hintStackTrace, warnUninit, hintExtendedContext, hintDeclaredLoc}
|
||||
result[1] = result[2] - {warnProveField, warnProveIndex,
|
||||
warnGcUnsafe, hintPath, hintDependency, hintCodeBegin, hintCodeEnd,
|
||||
hintSource, hintGlobalVar, hintGCStats, hintMsgOrigin}
|
||||
|
||||
@@ -81,6 +81,7 @@ type # please make sure we have under 32 options
|
||||
optDocInternal # generate documentation for non-exported symbols
|
||||
optMixedMode # true if some module triggered C++ codegen
|
||||
optListFullPaths # use full paths in toMsgFilename
|
||||
optDeclaredLocs # show declaration locations in messages
|
||||
optNoNimblePath
|
||||
optHotCodeReloading
|
||||
optDynlibOverrideAll
|
||||
|
||||
@@ -208,6 +208,7 @@ proc presentFailedCandidates(c: PContext, n: PNode, errors: CandidateErrors):
|
||||
{renderNoBody, renderNoComments, renderNoPragmas}))
|
||||
else:
|
||||
candidates.add(getProcHeader(c.config, err.sym, prefer))
|
||||
candidates.addDeclaredLocMaybe(c.config, err.sym)
|
||||
candidates.add("\n")
|
||||
let nArg = if err.firstMismatch.arg < n.len: n[err.firstMismatch.arg] else: nil
|
||||
let nameParam = if err.firstMismatch.formal != nil: err.firstMismatch.formal.name.s else: ""
|
||||
@@ -230,9 +231,8 @@ proc presentFailedCandidates(c: PContext, n: PNode, errors: CandidateErrors):
|
||||
doAssert err.firstMismatch.formal != nil
|
||||
candidates.add("\n required type for " & nameParam & ": ")
|
||||
candidates.add typeToString(wanted)
|
||||
when false:
|
||||
if wanted.sym != nil:
|
||||
candidates.add "(" & (c.config $ wanted.sym.info) & ")"
|
||||
if wanted.sym != nil:
|
||||
candidates.addDeclaredLocMaybe(c.config, wanted.sym)
|
||||
candidates.add "\n but expression '"
|
||||
if err.firstMismatch.kind == kVarNeeded:
|
||||
candidates.add renderNotLValue(nArg)
|
||||
@@ -242,9 +242,8 @@ proc presentFailedCandidates(c: PContext, n: PNode, errors: CandidateErrors):
|
||||
candidates.add "' is of type: "
|
||||
var got = nArg.typ
|
||||
candidates.add typeToString(got)
|
||||
when false:
|
||||
if got.sym != nil:
|
||||
candidates.add "(" & (c.config $ got.sym.info) & ")"
|
||||
if got.sym != nil:
|
||||
candidates.addDeclaredLocMaybe(c.config, got.sym)
|
||||
|
||||
doAssert wanted != nil
|
||||
if got != nil: effectProblem(wanted, got, candidates, c)
|
||||
|
||||
@@ -123,8 +123,13 @@ proc isIntLit*(t: PType): bool {.inline.} =
|
||||
proc isFloatLit*(t: PType): bool {.inline.} =
|
||||
result = t.kind == tyFloat and t.n != nil and t.n.kind == nkFloatLit
|
||||
|
||||
proc addDeclaredLoc(result: var string, conf: ConfigRef; sym: PSym) =
|
||||
result.add " [declared in " & conf$sym.info & "]"
|
||||
proc addDeclaredLoc*(result: var string, conf: ConfigRef; sym: PSym) =
|
||||
# result.add " [declared in " & conf$sym.info & "]"
|
||||
result.add " [declared in " & toFileLineCol(conf, sym.info) & "]"
|
||||
|
||||
proc addDeclaredLocMaybe*(result: var string, conf: ConfigRef; sym: PSym) =
|
||||
if optDeclaredLocs in conf.globalOptions:
|
||||
addDeclaredLoc(result, conf, sym)
|
||||
|
||||
proc addTypeHeader*(result: var string, conf: ConfigRef; typ: PType; prefer: TPreferedDesc = preferMixed; getDeclarationPath = true) =
|
||||
result.add typeToString(typ, prefer)
|
||||
|
||||
@@ -35,6 +35,7 @@ Advanced options:
|
||||
--stdout:on|off output to stdout
|
||||
--colors:on|off turn compiler messages coloring on|off
|
||||
--listFullPaths:on|off list full paths in messages
|
||||
--declaredlocs:on|off show declaration locations in messages
|
||||
-w:on|off|list, --warnings:on|off|list
|
||||
turn all warnings on|off or list all available
|
||||
--warning[X]:on|off turn specific warning X on|off
|
||||
|
||||
Reference in New Issue
Block a user