Remove Deprecated Nimfix (#22062)

* Remove Deprecated Nimfix
* Trailing whitespace cleanups
This commit is contained in:
Juan Carlos
2023-06-10 02:09:03 -03:00
committed by GitHub
parent 65c412e3f0
commit b2d7761975
17 changed files with 25 additions and 288 deletions

View File

@@ -7,7 +7,7 @@
# distribution, for details about the copyright.
#
## Helpers for binaries that use compiler passes, e.g.: nim, nimsuggest, nimfix
## Helpers for binaries that use compiler passes, e.g.: nim, nimsuggest
import
options, idents, nimconf, extccomp, commands, msgs,

View File

@@ -277,7 +277,7 @@ type
# and parsed; usually "" but is used
# for 'nimsuggest'
hash*: string # the checksum of the file
dirty*: bool # for 'nimfix' / 'nimpretty' like tooling
dirty*: bool # for 'nimpretty' like tooling
when defined(nimpretty):
fullContent*: string
FileIndex* = distinct int32

View File

@@ -332,10 +332,10 @@ proc addDeclAt*(c: PContext; scope: PScope, sym: PSym, info: TLineInfo) =
if sym.name.id == ord(wUnderscore): return
let conflict = scope.addUniqueSym(sym)
if conflict != nil:
if sym.kind == skModule and conflict.kind == skModule:
if sym.kind == skModule and conflict.kind == skModule:
# e.g.: import foo; import foo
# xxx we could refine this by issuing a different hint for the case
# where a duplicate import happens inside an include.
# where a duplicate import happens inside an include.
if c.importModuleMap[sym.id] == c.importModuleMap[conflict.id]:
#only hints if the conflict is the actual module not just a shared name
localError(c.config, info, hintDuplicateModuleImport,
@@ -428,13 +428,6 @@ proc mergeShadowScope*(c: PContext) =
else:
c.addInterfaceDecl(sym)
when false:
# `nimfix` used to call `altSpelling` and prettybase.replaceDeprecated(n.info, ident, alt)
proc altSpelling(c: PContext, x: PIdent): PIdent =
case x.s[0]
of 'A'..'Z': result = getIdent(c.cache, toLowerAscii(x.s[0]) & x.s.substr(1))
of 'a'..'z': result = getIdent(c.cache, toLowerAscii(x.s[0]) & x.s.substr(1))
else: result = x
import std/editdistance, heapqueue

View File

@@ -417,7 +417,7 @@ proc mainCommand*(graph: ModuleGraph) =
of cmdJsonscript:
setOutFile(graph.config)
commandJsonScript(graph)
of cmdUnknown, cmdNone, cmdIdeTools, cmdNimfix:
of cmdUnknown, cmdNone, cmdIdeTools:
rawMessage(conf, errGenerated, "invalid command: " & conf.command)
if conf.errorCounter == 0 and conf.cmd notin {cmdTcc, cmdDump, cmdNop}:

View File

@@ -1,111 +0,0 @@
#
#
# The Nim Compiler
# (c) Copyright 2015 Andreas Rumpf
#
# See the file "copying.txt", included in this
# distribution, for details about the copyright.
#
## Nimfix is a tool that helps to convert old-style Nimrod code to Nim code.
import strutils, os, parseopt
import compiler/[options, commands, modules, sem,
passes, passaux, linter,
msgs, nimconf,
extccomp, condsyms,
modulegraphs, idents]
const Usage = """
Nimfix - Tool to patch Nim code
Usage:
nimfix [options] projectfile.nim
Options:
--overwriteFiles:on|off overwrite the original nim files.
DEFAULT is ON!
--wholeProject overwrite every processed file.
--checkExtern:on|off style check also extern names
--styleCheck:on|off|auto performs style checking for identifiers
and suggests an alternative spelling;
'auto' corrects the spelling.
--bestEffort try to fix the code even when there
are errors.
In addition, all command line options of Nim are supported.
"""
proc mainCommand =
registerPass verbosePass
registerPass semPass
conf.setCmd cmdNimfix
searchPaths.add options.libpath
if gProjectFull.len != 0:
# current path is always looked first for modules
searchPaths.insert(gProjectPath, 0)
compileProject(newModuleGraph(), newIdentCache())
pretty.overwriteFiles()
proc processCmdLine*(pass: TCmdLinePass, cmd: string, config: ConfigRef) =
var p = parseopt.initOptParser(cmd)
var argsCount = 0
gOnlyMainfile = true
while true:
parseopt.next(p)
case p.kind
of cmdEnd: break
of cmdLongoption, cmdShortOption:
case p.key.normalize
of "overwritefiles":
case p.val.normalize
of "on": gOverWrite = true
of "off": gOverWrite = false
else: localError(gCmdLineInfo, errOnOrOffExpected)
of "checkextern":
case p.val.normalize
of "on": gCheckExtern = true
of "off": gCheckExtern = false
else: localError(gCmdLineInfo, errOnOrOffExpected)
of "stylecheck":
case p.val.normalize
of "off": gStyleCheck = StyleCheck.None
of "on": gStyleCheck = StyleCheck.Warn
of "auto": gStyleCheck = StyleCheck.Auto
else: localError(gCmdLineInfo, errOnOrOffExpected)
of "wholeproject": gOnlyMainfile = false
of "besteffort": msgs.gErrorMax = high(int) # don't stop after first error
else:
processSwitch(pass, p, config)
of cmdArgument:
options.gProjectName = unixToNativePath(p.key)
# if processArgument(pass, p, argsCount): break
proc handleCmdLine(config: ConfigRef) =
if paramCount() == 0:
stdout.writeLine(Usage)
else:
processCmdLine(passCmd1, "", config)
if gProjectName != "":
try:
gProjectFull = canonicalizePath(gProjectName)
except OSError:
gProjectFull = gProjectName
var p = splitFile(gProjectFull)
gProjectPath = p.dir
gProjectName = p.name
else:
gProjectPath = getCurrentDir()
loadConfigs(DefaultConfig, config) # load all config files
# now process command line arguments again, because some options in the
# command line can overwrite the config file's settings
extccomp.initVars()
processCmdLine(passCmd2, "", config)
mainCommand()
when compileOption("gc", "refc"):
GC_disableMarkAndSweep()
condsyms.initDefines()
defineSymbol "nimfix"
handleCmdline newConfigRef()

View File

@@ -1,17 +0,0 @@
# Special configuration file for the Nim project
# gc:markAndSweep
hint[XDeclaredButNotUsed]:off
path:"$projectPath/.."
path:"$lib/packages/docutils"
path:"$nim"
define:useStdoutAsStdmsg
symbol:nimfix
define:nimfix
cs:partial
#define:useNodeIds
define:booting
define:noDocgen

View File

@@ -1,45 +0,0 @@
#
#
# The Nim Compiler
# (c) Copyright 2015 Andreas Rumpf
#
# See the file "copying.txt", included in this
# distribution, for details about the copyright.
#
import strutils except Letters
import ".." / [ast, msgs, lineinfos, idents, options, linter]
proc replaceDeprecated*(conf: ConfigRef; info: TLineInfo; oldSym, newSym: PIdent) =
let line = sourceLine(conf, info)
var first = min(info.col.int, line.len)
if first < 0: return
#inc first, skipIgnoreCase(line, "proc ", first)
while first > 0 and line[first-1] in Letters: dec first
if first < 0: return
if line[first] == '`': inc first
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)
when defined(gcArc) or defined(gcOrc) or defined(gcAtomicArc):
conf.m.fileInfos[info.fileIndex.int32].lines[info.line.int-1] = move x
else:
system.shallowCopy(conf.m.fileInfos[info.fileIndex.int32].lines[info.line.int-1], x)
conf.m.fileInfos[info.fileIndex.int32].dirty = true
#if newSym.s == "File": writeStackTrace()
proc replaceDeprecated*(conf: ConfigRef; info: TLineInfo; oldSym, newSym: PSym) =
replaceDeprecated(conf, info, oldSym.name, newSym.name)
proc replaceComment*(conf: ConfigRef; info: TLineInfo) =
let line = sourceLine(conf, info)
var first = info.col.int
if line[first] != '#': inc first
var x = line.substr(0, first-1) & "discard " & line.substr(first+1).escape
when defined(gcArc) or defined(gcOrc) or defined(gcAtomicArc):
conf.m.fileInfos[info.fileIndex.int32].lines[info.line.int-1] = move x
else:
system.shallowCopy(conf.m.fileInfos[info.fileIndex.int32].lines[info.line.int-1], x)
conf.m.fileInfos[info.fileIndex.int32].dirty = true

View File

@@ -166,7 +166,6 @@ type
cmdInteractive # start interactive session
cmdNop
cmdJsonscript # compile a .json build file
cmdNimfix
# old unused: cmdInterpret, cmdDef: def feature (find definition for IDEs)
const

View File

@@ -174,9 +174,7 @@ proc setExternName(c: PContext; s: PSym, extname: string, info: TLineInfo) =
localError(c.config, info, "invalid extern name: '" & extname & "'. (Forgot to escape '$'?)")
when hasFFI:
s.cname = $s.loc.r
if c.config.cmd == cmdNimfix and '$' notin extname:
# note that '{.importc.}' is transformed into '{.importc: "$1".}'
s.loc.flags.incl(lfFullExternalName)
proc makeExternImport(c: PContext; s: PSym, extname: string, info: TLineInfo) =
setExternName(c, s, extname, info)
@@ -249,7 +247,7 @@ proc processVirtual(c: PContext, n: PNode, s: PSym) =
s.constraint = newEmptyStrNode(c, n, getOptionalStr(c, n, "$1"))
s.constraint.strVal = s.constraint.strVal % s.name.s
s.flags.incl {sfVirtual, sfInfixCall, sfExportc, sfMangleCpp}
s.typ.callConv = ccNoConvention
incl c.config.globalOptions, optMixedMode
@@ -1281,7 +1279,7 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int,
sym.flags.incl sfSystemRaisesDefect
of wVirtual:
processVirtual(c, it, sym)
else: invalidPragma(c, it)
elif comesFromPush and whichKeyword(ident) != wInvalid:
discard "ignore the .push pragma; it doesn't apply"

View File

@@ -21,8 +21,6 @@ import
lowerings, plugins/active, lineinfos, strtabs, int128,
isolation_check, typeallowed, modulegraphs, enumtostr, concepts, astmsgs
when defined(nimfix):
import nimfix/prettybase
when not defined(leanCompiler):
import spawn

View File

@@ -2614,7 +2614,7 @@ proc semSetConstr(c: PContext, n: PNode, expectedType: PType = nil): PNode =
typ = makeRangeType(c, 0, MaxSetElements-1, n.info)
elif isIntLit(typ):
# set of int literal, use a default range smaller than the max range
typ = makeRangeType(c, 0, DefaultSetElements-1, n.info)
typ = makeRangeType(c, 0, DefaultSetElements-1, n.info)
elif lengthOrd(c.config, typ) > MaxSetElements:
message(c.config, n.info, warnAboveMaxSizeSet, "type '" &
typeToString(typ, preferDesc) & "' is too big to be a `set` element, " &
@@ -3107,8 +3107,6 @@ proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}, expectedType: PType
c.isAmbiguous = false
var s = qualifiedLookUp(c, n[0], mode)
if s != nil:
#if c.config.cmd == cmdNimfix and n[0].kind == nkDotExpr:
# pretty.checkUse(n[0][1].info, s)
case s.kind
of skMacro, skTemplate:
result = semDirectOp(c, n, flags, expectedType)

View File

@@ -1655,11 +1655,11 @@ proc swapResult(n: PNode, sRes: PSym, dNode: PNode) =
swapResult(n[i], sRes, dNode)
proc addThis(c: PContext, n: PNode, t: PType, owner: TSymKind) =
proc addThis(c: PContext, n: PNode, t: PType, owner: TSymKind) =
var s = newSym(skResult, getIdent(c.cache, "this"), c.idgen,
getCurrOwner(c), n.info)
getCurrOwner(c), n.info)
s.typ = t
incl(s.flags, sfUsed)
incl(s.flags, sfUsed)
c.p.resultSym = s
n.add newSymNode(c.p.resultSym)
addParamOrResult(c, c.p.resultSym, owner)
@@ -2198,17 +2198,17 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind,
if sfBorrow in s.flags and c.config.cmd notin cmdDocLike:
result[bodyPos] = c.graph.emptyNode
if {sfVirtual, sfConstructor} * s.flags != {} and sfImportc notin s.flags:
let isVirtual = sfVirtual in s.flags
let pragmaName = if isVirtual: "virtual" else: "constructor"
if c.config.backend == backendCpp:
if s.typ.sons.len < 2 and isVirtual:
localError(c.config, n.info, "virtual must have at least one parameter")
localError(c.config, n.info, "virtual must have at least one parameter")
for son in s.typ.sons:
if son!=nil and son.isMetaType:
localError(c.config, n.info, pragmaName & " unsupported for generic routine")
var typ: PType
var typ: PType
if sfConstructor in s.flags:
typ = s.typ.sons[0]
if typ == nil or typ.kind != tyObject:
@@ -2222,7 +2222,7 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind,
if typ.owner.id == s.owner.id and c.module.id == s.owner.id:
c.graph.memberProcsPerType.mgetOrPut(typ.itemId, @[]).add s
else:
localError(c.config, n.info,
localError(c.config, n.info,
pragmaName & " procs must be defined in the same scope as the type they are virtual for and it must be a top level scope")
else:
localError(c.config, n.info, pragmaName & " procs are only supported in C++")
@@ -2577,12 +2577,6 @@ proc semStmtList(c: PContext, n: PNode, flags: TExprFlags, expectedType: PType =
result[0].kind != nkDefer:
result = result[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)
proc semStmt(c: PContext, n: PNode; flags: TExprFlags): PNode =
if efInTypeof notin flags:
result = semExprNoType(c, n)

View File

@@ -11,7 +11,7 @@ Contributing
Contributing happens via "Pull requests" (PR) on GitHub. Every PR needs to be
reviewed before it can be merged and the Continuous Integration should be green.
The title of a PR should contain a brief description. If it fixes an issue,
in addition to the number of the issue, the title should also contain a description
in addition to the number of the issue, the title should also contain a description
of the issue.
The PR has to be approved by two core developers or by Araq.
@@ -198,7 +198,7 @@ tell you if any new tests passed/failed.
Deprecation
===========
Backwards compatibility is important. When renaming types, procedures, etc. the old name
Backwards compatibility is important. When renaming types, procedures, etc. the old name
must be marked as deprecated using the `deprecated` pragma:
```nim
@@ -513,7 +513,7 @@ General commit rules
https://github.com/nim-lang/Nim/pull/9356
8. Do not mix pure formatting changes (e.g. whitespace changes, nimpretty) or
automated changes (e.g. nimfix) with other code changes: these should be in
automated changes with other code changes: these should be in
separate commits (and the merge on GitHub should not squash these into 1).

View File

@@ -1,65 +0,0 @@
.. default-role:: code
=====================
Nimfix User Guide
=====================
:Author: Andreas Rumpf
:Version: |nimversion|
**WARNING**: Nimfix is currently beta-quality.
Nimfix is a tool to help you upgrade from Nimrod (<= version 0.9.6) to
Nim (=> version 0.10.0).
It performs 3 different actions:
1. It makes your code case consistent.
2. It renames every symbol that has a deprecation rule. So if a module has a
rule `{.deprecated: [TFoo: Foo].}` then `TFoo` is replaced by `Foo`.
3. It can also check that your identifiers adhere to the official style guide
and optionally modify them to do so (via `--styleCheck:auto`).
Note that `nimfix` defaults to **overwrite** your code unless you
use `--overwriteFiles:off`! But hey, if you do not use a version control
system by this day and age, your project is already in big trouble.
Installation
------------
Nimfix is part of the compiler distribution. Compile via:
```cmd
nim c compiler/nimfix/nimfix.nim
mv compiler/nimfix/nimfix bin
```
Or on windows:
```cmd
nim c compiler\nimfix\nimfix.nim
move compiler\nimfix\nimfix.exe bin
```
Usage
-----
Usage:
```cmd
nimfix [options] projectfile.nim
```
Options:
--overwriteFiles:on|off overwrite the original nim files. DEFAULT is ON!
--wholeProject overwrite every processed file.
--checkExtern:on|off style check also extern names
--styleCheck:on|off|auto performs style checking for identifiers
and suggests an alternative spelling;
'auto' corrects the spelling.
In addition, all command line options of Nim are supported.

View File

@@ -10,10 +10,10 @@
## OpenSSL wrapper. Supports OpenSSL >= 1.1.0 dynamically (as default) or statically linked
## using `--dynlibOverride:ssl`.
##
## `-d:sslVersion=1.2.3` can be used to force an SSL version.
## `-d:sslVersion=1.2.3` can be used to force an SSL version.
## This version must be included in the library name.
## `-d:useOpenssl3` may be set for OpenSSL 3 instead.
##
##
## There is also limited support for OpenSSL 1.0.x which may require `-d:openssl10`.
##
## Build and test examples:
@@ -529,11 +529,8 @@ proc BIO_do_handshake*(bio: BIO): int =
proc BIO_do_connect*(bio: BIO): int =
return BIO_do_handshake(bio)
when not defined(nimfix):
proc BIO_read*(b: BIO, data: cstring, length: cint): cint{.cdecl,
dynlib: DLLUtilName, importc.}
proc BIO_write*(b: BIO, data: cstring, length: cint): cint{.cdecl,
dynlib: DLLUtilName, importc.}
proc BIO_read*(b: BIO, data: cstring, length: cint): cint{.cdecl, dynlib: DLLUtilName, importc.}
proc BIO_write*(b: BIO, data: cstring, length: cint): cint{.cdecl, dynlib: DLLUtilName, importc.}
proc BIO_free*(b: BIO): cint{.cdecl, dynlib: DLLUtilName, importc.}

View File

@@ -130,8 +130,7 @@ standard library are welcomed and appreciated. Before you start contributing,
you should familiarize yourself with the following repository structure:
* ``bin/``, ``build/`` - these directories are empty, but are used when Nim is built.
* ``compiler/`` - the compiler source code. Also includes nimfix, and plugins within
``compiler/nimfix`` and ``compiler/plugins`` respectively.
* ``compiler/`` - the compiler source code. Also includes plugins within ``compiler/plugins``.
* ``nimsuggest`` - the nimsuggest tool that previously lived in the [``nim-lang/nimsuggest``][nimsuggest-repo] repository.
* ``config/`` - the configuration for the compiler and documentation generator.
* ``doc/`` - the documentation files in reStructuredText format.

View File

@@ -97,11 +97,10 @@ proc getMd2html(): seq[string] =
for a in walkDirRecFilter("doc"):
let path = a.path
if a.kind == pcFile and path.splitFile.ext == ".md" and path.lastPathPart notin
["docs.md", "nimfix.md",
["docs.md",
"docstyle.md" # docstyle.md shouldn't be converted to html separately;
# it's included in contributing.md.
]:
# maybe we should still show nimfix, could help reviving it
# `docs` is redundant with `overview`, might as well remove that file?
result.add path
doAssert "doc/manual/var_t_return.md".unixToNativePath in result # sanity check