'nirmod pretty': almost working
This commit is contained in:
parent
e5be2e9f97
commit
805959378d
3 changed files with 27 additions and 4 deletions
|
|
@ -601,7 +601,7 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: int,
|
||||||
processDynLib(c, it, sym)
|
processDynLib(c, it, sym)
|
||||||
of wCompilerProc:
|
of wCompilerProc:
|
||||||
noVal(it) # compilerproc may not get a string!
|
noVal(it) # compilerproc may not get a string!
|
||||||
makeExternExport(sym, sym.name.s)
|
makeExternExport(sym, "$1")
|
||||||
incl(sym.flags, sfCompilerProc)
|
incl(sym.flags, sfCompilerProc)
|
||||||
incl(sym.flags, sfUsed) # suppress all those stupid warnings
|
incl(sym.flags, sfUsed) # suppress all those stupid warnings
|
||||||
registerCompilerProc(sym)
|
registerCompilerProc(sym)
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
import
|
import
|
||||||
strutils, os, options, ast, astalgo, msgs, ropes, idents, passes, pegs,
|
strutils, os, options, ast, astalgo, msgs, ropes, idents, passes, pegs,
|
||||||
intsets
|
intsets, strtabs
|
||||||
|
|
||||||
type
|
type
|
||||||
TGen = object of TPassContext
|
TGen = object of TPassContext
|
||||||
|
|
@ -26,6 +26,7 @@ type
|
||||||
|
|
||||||
var
|
var
|
||||||
gSourceFiles: seq[TSourceFile] = @[]
|
gSourceFiles: seq[TSourceFile] = @[]
|
||||||
|
rules: PStringTable
|
||||||
|
|
||||||
proc loadFile(info: TLineInfo) =
|
proc loadFile(info: TLineInfo) =
|
||||||
let i = info.fileIndex
|
let i = info.fileIndex
|
||||||
|
|
@ -108,12 +109,13 @@ proc processSym(c: PPassContext, n: PNode): PNode =
|
||||||
if n.info.fileIndex < 0: return
|
if n.info.fileIndex < 0: return
|
||||||
let s = n.sym
|
let s = n.sym
|
||||||
# operators stay as they are:
|
# operators stay as they are:
|
||||||
if s.kind == skTemp or s.name.s[0] notin Letters: return
|
if s.kind in {skResult, skTemp} or s.name.s[0] notin Letters: return
|
||||||
if s.kind in {skType, skGenericParam} and sfAnon in s.flags: return
|
if s.kind in {skType, skGenericParam} and sfAnon in s.flags: return
|
||||||
|
|
||||||
if s.id in cannotRename: return
|
if s.id in cannotRename: return
|
||||||
|
|
||||||
let newName = beautifyName(s.name.s, n.sym.kind)
|
let newName = if rules.hasKey(s.name.s): rules[s.name.s]
|
||||||
|
else: beautifyName(s.name.s, n.sym.kind)
|
||||||
|
|
||||||
loadFile(n.info)
|
loadFile(n.info)
|
||||||
|
|
||||||
|
|
@ -121,6 +123,7 @@ proc processSym(c: PPassContext, n: PNode): PNode =
|
||||||
var first = n.info.col.int
|
var first = n.info.col.int
|
||||||
if first < 0: return
|
if first < 0: return
|
||||||
#inc first, skipIgnoreCase(line, "proc ", first)
|
#inc first, skipIgnoreCase(line, "proc ", first)
|
||||||
|
while first > 0 and line[first-1] in Letters: dec first
|
||||||
if line[first] == '`': inc first
|
if line[first] == '`': inc first
|
||||||
|
|
||||||
if {sfImportc, sfExportc} * s.flags != {}:
|
if {sfImportc, sfExportc} * s.flags != {}:
|
||||||
|
|
@ -139,6 +142,7 @@ proc processSym(c: PPassContext, n: PNode): PNode =
|
||||||
# becomes 'X = X'. We remove those lines:
|
# becomes 'X = X'. We remove those lines:
|
||||||
if x.match(peg"\s* {\ident} \s* '=' \s* y$1 ('#' .*)?"):
|
if x.match(peg"\s* {\ident} \s* '=' \s* y$1 ('#' .*)?"):
|
||||||
x = ""
|
x = ""
|
||||||
|
|
||||||
system.shallowCopy(gSourceFiles[n.info.fileIndex].lines[n.info.line-1], x)
|
system.shallowCopy(gSourceFiles[n.info.fileIndex].lines[n.info.line-1], x)
|
||||||
gSourceFiles[n.info.fileIndex].dirty = true
|
gSourceFiles[n.info.fileIndex].dirty = true
|
||||||
else:
|
else:
|
||||||
|
|
@ -150,6 +154,16 @@ proc myOpen(module: PSym): PPassContext =
|
||||||
new(g)
|
new(g)
|
||||||
g.module = module
|
g.module = module
|
||||||
result = g
|
result = g
|
||||||
|
if rules.isNil:
|
||||||
|
rules = newStringTable(modeStyleInsensitive)
|
||||||
|
let path = joinPath([getPrefixDir(), "config", "rename.rules.cfg"])
|
||||||
|
for line in lines(path):
|
||||||
|
if line.len > 0:
|
||||||
|
let colon = line.find(':')
|
||||||
|
if colon > 0:
|
||||||
|
rules[line.substr(0, colon-1)] = line.substr(colon+1)
|
||||||
|
else:
|
||||||
|
rules[line] = line
|
||||||
|
|
||||||
const prettyPass* = makePass(open = myOpen, process = processSym)
|
const prettyPass* = makePass(open = myOpen, process = processSym)
|
||||||
|
|
||||||
|
|
|
||||||
9
config/rename.rules.cfg
Normal file
9
config/rename.rules.cfg
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
TSignedInt
|
||||||
|
TUnsignedInt
|
||||||
|
TOrdinal
|
||||||
|
TReal
|
||||||
|
TNumber
|
||||||
|
TEnum
|
||||||
|
TObject
|
||||||
|
TResult
|
||||||
|
TOpenArray
|
||||||
Loading…
Add table
Add a link
Reference in a new issue