diff --git a/compiler/prettybase.nim b/compiler/prettybase.nim index dca6bcdaaa..eb0cf983db 100644 --- a/compiler/prettybase.nim +++ b/compiler/prettybase.nim @@ -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 diff --git a/compiler/sem.nim b/compiler/sem.nim index 5f2e77781b..71e60f0b69 100644 --- a/compiler/sem.nim +++ b/compiler/sem.nim @@ -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.} diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index 93a1994a72..cb5bcdde89 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -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: