prettybase.nim 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #
  2. #
  3. # The Nim Compiler
  4. # (c) Copyright 2015 Andreas Rumpf
  5. #
  6. # See the file "copying.txt", included in this
  7. # distribution, for details about the copyright.
  8. #
  9. import strutils except Letters
  10. import ".." / [ast, msgs, lineinfos, idents, options, linter]
  11. proc replaceDeprecated*(conf: ConfigRef; info: TLineInfo; oldSym, newSym: PIdent) =
  12. let line = sourceLine(conf, info)
  13. var first = min(info.col.int, line.len)
  14. if first < 0: return
  15. #inc first, skipIgnoreCase(line, "proc ", first)
  16. while first > 0 and line[first-1] in Letters: dec first
  17. if first < 0: return
  18. if line[first] == '`': inc first
  19. let last = first+identLen(line, first)-1
  20. if cmpIgnoreStyle(line[first..last], oldSym.s) == 0:
  21. var x = line.substr(0, first-1) & newSym.s & line.substr(last+1)
  22. when defined(gcArc) or defined(gcOrc):
  23. conf.m.fileInfos[info.fileIndex.int32].lines[info.line.int-1] = move x
  24. else:
  25. system.shallowCopy(conf.m.fileInfos[info.fileIndex.int32].lines[info.line.int-1], x)
  26. conf.m.fileInfos[info.fileIndex.int32].dirty = true
  27. #if newSym.s == "File": writeStackTrace()
  28. proc replaceDeprecated*(conf: ConfigRef; info: TLineInfo; oldSym, newSym: PSym) =
  29. replaceDeprecated(conf, info, oldSym.name, newSym.name)
  30. proc replaceComment*(conf: ConfigRef; info: TLineInfo) =
  31. let line = sourceLine(conf, info)
  32. var first = info.col.int
  33. if line[first] != '#': inc first
  34. var x = line.substr(0, first-1) & "discard " & line.substr(first+1).escape
  35. when defined(gcArc) or defined(gcOrc):
  36. conf.m.fileInfos[info.fileIndex.int32].lines[info.line.int-1] = move x
  37. else:
  38. system.shallowCopy(conf.m.fileInfos[info.fileIndex.int32].lines[info.line.int-1], x)
  39. conf.m.fileInfos[info.fileIndex.int32].dirty = true