the .deprecated pragma for procs now supports a user-definable deprecation message
This commit is contained in:
parent
1b22a3b346
commit
212457f5e0
5 changed files with 27 additions and 4 deletions
|
|
@ -238,3 +238,12 @@ styledEcho "Red on Green.", resetStyle
|
||||||
- Type inference for generic type parameters involving numeric types is now symetric. See
|
- Type inference for generic type parameters involving numeric types is now symetric. See
|
||||||
[Generic type inference for numeric types](https://nim-lang.org/docs/manual.html#generics-generic-type-inference-fornumeric-types)
|
[Generic type inference for numeric types](https://nim-lang.org/docs/manual.html#generics-generic-type-inference-fornumeric-types)
|
||||||
for more information.
|
for more information.
|
||||||
|
- The ``deprecated`` pragma now supports a user-definable warning message for procs.
|
||||||
|
|
||||||
|
```nim
|
||||||
|
|
||||||
|
proc bar {.deprecated: "use foo instead".} =
|
||||||
|
return
|
||||||
|
|
||||||
|
bar()
|
||||||
|
```
|
||||||
|
|
|
||||||
|
|
@ -810,7 +810,10 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: int,
|
||||||
of wExplain:
|
of wExplain:
|
||||||
sym.flags.incl sfExplain
|
sym.flags.incl sfExplain
|
||||||
of wDeprecated:
|
of wDeprecated:
|
||||||
if it.kind in nkPragmaCallKinds: deprecatedStmt(c, it)
|
if sym != nil and sym.kind in routineKinds:
|
||||||
|
if it.kind in nkPragmaCallKinds: discard getStrLitNode(c, it)
|
||||||
|
incl(sym.flags, sfDeprecated)
|
||||||
|
elif it.kind in nkPragmaCallKinds: deprecatedStmt(c, it)
|
||||||
elif sym != nil: incl(sym.flags, sfDeprecated)
|
elif sym != nil: incl(sym.flags, sfDeprecated)
|
||||||
else: incl(c.module.flags, sfDeprecated)
|
else: incl(c.module.flags, sfDeprecated)
|
||||||
of wVarargs:
|
of wVarargs:
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@
|
||||||
# included from sigmatch.nim
|
# included from sigmatch.nim
|
||||||
|
|
||||||
import algorithm, prefixmatches
|
import algorithm, prefixmatches
|
||||||
|
from wordrecg import wDeprecated
|
||||||
|
|
||||||
when defined(nimsuggest):
|
when defined(nimsuggest):
|
||||||
import passes, tables # importer
|
import passes, tables # importer
|
||||||
|
|
@ -479,12 +480,23 @@ proc suggestSym*(info: TLineInfo; s: PSym; usageSym: var PSym; isDecl=true) {.in
|
||||||
isDecl:
|
isDecl:
|
||||||
suggestResult(symToSuggest(s, isLocal=false, ideOutline, info, 100, PrefixMatch.None, false, 0))
|
suggestResult(symToSuggest(s, isLocal=false, ideOutline, info, 100, PrefixMatch.None, false, 0))
|
||||||
|
|
||||||
|
proc warnAboutDeprecated(info: TLineInfo; s: PSym) =
|
||||||
|
if s.kind in routineKinds:
|
||||||
|
let n = s.ast[pragmasPos]
|
||||||
|
if n.kind != nkEmpty:
|
||||||
|
for it in n:
|
||||||
|
if whichPragma(it) == wDeprecated and it.safeLen == 2 and
|
||||||
|
it[1].kind in {nkStrLit..nkTripleStrLit}:
|
||||||
|
message(info, warnDeprecated, it[1].strVal & "; " & s.name.s)
|
||||||
|
return
|
||||||
|
message(info, warnDeprecated, s.name.s)
|
||||||
|
|
||||||
proc markUsed(info: TLineInfo; s: PSym; usageSym: var PSym) =
|
proc markUsed(info: TLineInfo; s: PSym; usageSym: var PSym) =
|
||||||
incl(s.flags, sfUsed)
|
incl(s.flags, sfUsed)
|
||||||
if s.kind == skEnumField and s.owner != nil:
|
if s.kind == skEnumField and s.owner != nil:
|
||||||
incl(s.owner.flags, sfUsed)
|
incl(s.owner.flags, sfUsed)
|
||||||
if {sfDeprecated, sfError} * s.flags != {}:
|
if {sfDeprecated, sfError} * s.flags != {}:
|
||||||
if sfDeprecated in s.flags: message(info, warnDeprecated, s.name.s)
|
if sfDeprecated in s.flags: warnAboutDeprecated(info, s)
|
||||||
if sfError in s.flags: localError(info, errWrongSymbolX, s.name.s)
|
if sfError in s.flags: localError(info, errWrongSymbolX, s.name.s)
|
||||||
when defined(nimsuggest):
|
when defined(nimsuggest):
|
||||||
suggestSym(info, s, usageSym, false)
|
suggestSym(info, s, usageSym, false)
|
||||||
|
|
|
||||||
|
|
@ -118,7 +118,7 @@ proc isRange*(n: PNode): bool {.inline.} =
|
||||||
result = true
|
result = true
|
||||||
|
|
||||||
proc whichPragma*(n: PNode): TSpecialWord =
|
proc whichPragma*(n: PNode): TSpecialWord =
|
||||||
let key = if n.kind == nkExprColonExpr: n.sons[0] else: n
|
let key = if n.kind in nkPragmaCallKinds and n.len > 0: n.sons[0] else: n
|
||||||
if key.kind == nkIdent: result = whichKeyword(key.ident)
|
if key.kind == nkIdent: result = whichKeyword(key.ident)
|
||||||
|
|
||||||
proc unnestStmts(n, result: PNode) =
|
proc unnestStmts(n, result: PNode) =
|
||||||
|
|
|
||||||
|
|
@ -3769,7 +3769,6 @@ proc failedAssertImpl*(msg: string) {.raises: [], tags: [].} =
|
||||||
# by ``assert``.
|
# by ``assert``.
|
||||||
type Hide = proc (msg: string) {.noinline, raises: [], noSideEffect,
|
type Hide = proc (msg: string) {.noinline, raises: [], noSideEffect,
|
||||||
tags: [].}
|
tags: [].}
|
||||||
{.deprecated: [THide: Hide].}
|
|
||||||
Hide(raiseAssert)(msg)
|
Hide(raiseAssert)(msg)
|
||||||
|
|
||||||
template assert*(cond: bool, msg = "") =
|
template assert*(cond: bool, msg = "") =
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue