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
|
let last = first+identLen(line, first)-1
|
||||||
if cmpIgnoreStyle(line[first..last], oldSym.s) == 0:
|
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)
|
system.shallowCopy(gSourceFiles[info.fileIndex].lines[info.line-1], x)
|
||||||
gSourceFiles[info.fileIndex].dirty = true
|
gSourceFiles[info.fileIndex].dirty = true
|
||||||
|
|
||||||
proc replaceDeprecated*(info: TLineInfo; oldSym, newSym: PSym) =
|
proc replaceDeprecated*(info: TLineInfo; oldSym, newSym: PSym) =
|
||||||
replaceDeprecated(info, oldSym.name, newSym.name)
|
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,
|
evaltempl, patterns, parampatterns, sempass2, pretty, semmacrosanity,
|
||||||
semparallel, lowerings
|
semparallel, lowerings
|
||||||
|
|
||||||
|
when defined(nimfix):
|
||||||
|
import prettybase
|
||||||
|
|
||||||
# implementation
|
# implementation
|
||||||
|
|
||||||
proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode {.procvar.}
|
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
|
else: discard
|
||||||
if result.len == 1:
|
if result.len == 1:
|
||||||
result = result.sons[0]
|
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:
|
when false:
|
||||||
# a statement list (s; e) has the type 'e':
|
# a statement list (s; e) has the type 'e':
|
||||||
if result.kind == nkStmtList and result.len > 0:
|
if result.kind == nkStmtList and result.len > 0:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue