the 'deprecated' pragma for modules now supports an error message

This commit is contained in:
Araq
2018-04-06 11:56:53 +02:00
parent c34cb101b8
commit 8518683dc7
3 changed files with 12 additions and 3 deletions

View File

@@ -847,6 +847,8 @@ type
constraint*: PNode # additional constraints like 'lit|result'; also
# misused for the codegenDecl pragma in the hope
# it won't cause problems
# for skModule the string literal to output for
# deprecated modules.
when defined(nimsuggest):
allUsages*: seq[TLineInfo]

View File

@@ -148,7 +148,10 @@ proc myImportModule(c: PContext, n: PNode): PSym =
result.info.fileIndex == n.info.fileIndex:
localError(n.info, errGenerated, "A module cannot import itself")
if sfDeprecated in result.flags:
message(n.info, warnDeprecated, result.name.s)
if result.constraint != nil:
message(n.info, warnDeprecated, result.constraint.strVal & "; " & result.name.s)
else:
message(n.info, warnDeprecated, result.name.s)
suggestSym(n.info, result, c.graph.usageSym, false)
proc impMod(c: PContext; it: PNode) =

View File

@@ -620,8 +620,12 @@ proc markCompilerProc(s: PSym) =
incl(s.flags, sfUsed)
registerCompilerProc(s)
proc deprecatedStmt(c: PContext; pragma: PNode) =
let pragma = pragma[1]
proc deprecatedStmt(c: PContext; outerPragma: PNode) =
let pragma = outerPragma[1]
if pragma.kind in {nkStrLit..nkTripleStrLit}:
incl(c.module.flags, sfDeprecated)
c.module.constraint = getStrLitNode(c, outerPragma)
return
if pragma.kind != nkBracket:
localError(pragma.info, "list of key:value pairs expected"); return
for n in pragma: