nimfix can fix obsolete statement comments
This commit is contained in:
parent
ae53d1ecc8
commit
a90f73ca4c
3 changed files with 20 additions and 1 deletions
|
|
@ -54,9 +54,20 @@ proc replaceDeprecated*(info: TLineInfo; oldSym, newSym: PIdent) =
|
|||
|
||||
let last = first+identLen(line, first)-1
|
||||
if cmpIgnoreStyle(line[first..last], oldSym.s) == 0:
|
||||
var x = line.substr(0, first-1) & newSym.s & line.substr(last+1)
|
||||
var x = line.substr(0, first-1) & newSym.s & line.substr(last+1)
|
||||
system.shallowCopy(gSourceFiles[info.fileIndex].lines[info.line-1], x)
|
||||
gSourceFiles[info.fileIndex].dirty = true
|
||||
|
||||
proc replaceDeprecated*(info: TLineInfo; oldSym, newSym: PSym) =
|
||||
replaceDeprecated(info, oldSym.name, newSym.name)
|
||||
|
||||
proc replaceComment*(info: TLineInfo) =
|
||||
loadFile(info)
|
||||
|
||||
let line = gSourceFiles[info.fileIndex].lines[info.line-1]
|
||||
var first = info.col.int
|
||||
if line[first] != '#': inc first
|
||||
|
||||
var x = line.substr(0, first-1) & "discard " & line.substr(first+1).escape
|
||||
system.shallowCopy(gSourceFiles[info.fileIndex].lines[info.line-1], x)
|
||||
gSourceFiles[info.fileIndex].dirty = true
|
||||
|
|
|
|||
|
|
@ -18,6 +18,9 @@ import
|
|||
evaltempl, patterns, parampatterns, sempass2, pretty, semmacrosanity,
|
||||
semparallel, lowerings
|
||||
|
||||
when defined(nimfix):
|
||||
import prettybase
|
||||
|
||||
# implementation
|
||||
|
||||
proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode {.procvar.}
|
||||
|
|
|
|||
|
|
@ -1398,6 +1398,11 @@ proc semStmtList(c: PContext, n: PNode, flags: TExprFlags): PNode =
|
|||
else: discard
|
||||
if result.len == 1:
|
||||
result = result.sons[0]
|
||||
when defined(nimfix):
|
||||
if result.kind == nkCommentStmt and not result.comment.isNil and
|
||||
not (result.comment[0] == '#' and result.comment[1] == '#'):
|
||||
# it is an old-style comment statement: we replace it with 'discard ""':
|
||||
prettybase.replaceComment(result.info)
|
||||
when false:
|
||||
# a statement list (s; e) has the type 'e':
|
||||
if result.kind == nkStmtList and result.len > 0:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue