Modify removeStatic to comment out body, then re-comment
This commit is contained in:
parent
f62125a4aa
commit
685081b6a9
1 changed files with 32 additions and 12 deletions
44
nimgen.nim
44
nimgen.nim
|
|
@ -25,7 +25,7 @@ var
|
||||||
type
|
type
|
||||||
c2nimConfigObj = object
|
c2nimConfigObj = object
|
||||||
flags, ppflags: string
|
flags, ppflags: string
|
||||||
recurse, inline, preprocess, ctags, defines, removeStatic: bool
|
recurse, inline, preprocess, ctags, defines: bool
|
||||||
dynlib, compile, pragma: seq[string]
|
dynlib, compile, pragma: seq[string]
|
||||||
|
|
||||||
const DOC = """
|
const DOC = """
|
||||||
|
|
@ -126,7 +126,7 @@ proc gitReset() =
|
||||||
|
|
||||||
discard execProc("git reset --hard HEAD")
|
discard execProc("git reset --hard HEAD")
|
||||||
|
|
||||||
proc gitCheckout(filename: string) =
|
proc gitCheckout(filename: string) {.used.} =
|
||||||
echo "Resetting file: $#" % [filename]
|
echo "Resetting file: $#" % [filename]
|
||||||
|
|
||||||
setCurrentDir(gOutput)
|
setCurrentDir(gOutput)
|
||||||
|
|
@ -335,10 +335,33 @@ proc comment(file: string, pattern: string, numlines: string) =
|
||||||
break
|
break
|
||||||
|
|
||||||
proc removeStatic(filename: string) =
|
proc removeStatic(filename: string) =
|
||||||
## Replace static function bodies with a semicolon
|
## Replace static function bodies with a semicolon and commented
|
||||||
|
## out body
|
||||||
withFile(filename):
|
withFile(filename):
|
||||||
content = content.replace(
|
content = content.replace(
|
||||||
re"(?m)(static inline.*?\))(\s*\{(\s*?.*?$)*[\n\r]\})", "$1;"
|
re"(?m)(static inline.*?\))(\s*\{(\s*?.*?$)*[\n\r]\})",
|
||||||
|
proc (match: RegexMatch): string =
|
||||||
|
let funcDecl = match.captures[0]
|
||||||
|
let body = match.captures[1].strip()
|
||||||
|
result = ""
|
||||||
|
|
||||||
|
result.add("$#;" % [funcDecl])
|
||||||
|
result.add(body.replace(re"(?m)^", "//"))
|
||||||
|
)
|
||||||
|
|
||||||
|
proc reAddStatic(filename: string) =
|
||||||
|
## Uncomment out the body and remove the semicolon. Undoes
|
||||||
|
## removeStatic
|
||||||
|
withFile(filename):
|
||||||
|
content = content.replace(
|
||||||
|
re"(?m)(static inline.*?\));(\/\/\s*\{(\s*?.*?$)*[\n\r]\/\/\})",
|
||||||
|
proc (match: RegexMatch): string =
|
||||||
|
let funcDecl = match.captures[0]
|
||||||
|
let body = match.captures[1].strip()
|
||||||
|
result = ""
|
||||||
|
|
||||||
|
result.add("$# " % [funcDecl])
|
||||||
|
result.add(body.replace(re"(?m)^\/\/", ""))
|
||||||
)
|
)
|
||||||
|
|
||||||
proc rename(file: string, renfile: string) =
|
proc rename(file: string, renfile: string) =
|
||||||
|
|
@ -538,9 +561,6 @@ proc c2nim(fl, outfile: string, c2nimConfig: c2nimConfigObj) =
|
||||||
if c2nimConfig.defines and (c2nimConfig.preprocess or c2nimConfig.ctags):
|
if c2nimConfig.defines and (c2nimConfig.preprocess or c2nimConfig.ctags):
|
||||||
prepend(cfile, getDefines(file, c2nimConfig.inline))
|
prepend(cfile, getDefines(file, c2nimConfig.inline))
|
||||||
|
|
||||||
if c2nimConfig.removeStatic:
|
|
||||||
removeStatic(cfile)
|
|
||||||
|
|
||||||
var
|
var
|
||||||
extflags = ""
|
extflags = ""
|
||||||
passC = ""
|
passC = ""
|
||||||
|
|
@ -669,9 +689,6 @@ proc runFile(file: string, cfgin: OrderedTableRef) =
|
||||||
if action == "create":
|
if action == "create":
|
||||||
createDir(file.splitPath().head)
|
createDir(file.splitPath().head)
|
||||||
writeFile(file, cfg[act])
|
writeFile(file, cfg[act])
|
||||||
elif action == "removestatic":
|
|
||||||
removeStatic(sfile)
|
|
||||||
c2nimConfig.removeStatic = true
|
|
||||||
elif action in @["prepend", "append", "replace", "comment",
|
elif action in @["prepend", "append", "replace", "comment",
|
||||||
"rename", "compile", "dynlib", "pragma",
|
"rename", "compile", "dynlib", "pragma",
|
||||||
"pipe"] and sfile != "":
|
"pipe"] and sfile != "":
|
||||||
|
|
@ -733,11 +750,14 @@ proc runFile(file: string, cfgin: OrderedTableRef) =
|
||||||
echo "Cannot use recurse and inline simultaneously"
|
echo "Cannot use recurse and inline simultaneously"
|
||||||
quit(1)
|
quit(1)
|
||||||
|
|
||||||
|
# Remove static inline function bodies
|
||||||
|
removeStatic(sfile)
|
||||||
|
|
||||||
if not noprocess:
|
if not noprocess:
|
||||||
c2nim(file, getNimout(sfile), c2nimConfig)
|
c2nim(file, getNimout(sfile), c2nimConfig)
|
||||||
|
|
||||||
if c2nimConfig.removeStatic:
|
# Add them back for compilation
|
||||||
gitCheckout(sfile)
|
reAddStatic(sfile)
|
||||||
|
|
||||||
proc runCfg(cfg: string) =
|
proc runCfg(cfg: string) =
|
||||||
if not fileExists(cfg):
|
if not fileExists(cfg):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue