aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoey Yakimowich-Payne <jyapayne@gmail.com>2018-07-11 13:36:45 +0900
committerJoey Yakimowich-Payne <jyapayne@gmail.com>2018-07-11 13:36:45 +0900
commit685081b6a99c0022e29863e8d70bd873d7fe5876 (patch)
tree4669f1a9b5ececdc62b55e8bcf1f97f351a03896
parentf62125a4aaed2a15970bdd186dddb7cb9a4bd862 (diff)
downloadnimgen-685081b6a99c0022e29863e8d70bd873d7fe5876.tar.gz
nimgen-685081b6a99c0022e29863e8d70bd873d7fe5876.zip
Modify removeStatic to comment out body, then re-comment
-rw-r--r--nimgen.nim44
1 files changed, 32 insertions, 12 deletions
diff --git a/nimgen.nim b/nimgen.nim
index 32e640b..d613386 100644
--- a/nimgen.nim
+++ b/nimgen.nim
@@ -25,7 +25,7 @@ var
type
c2nimConfigObj = object
flags, ppflags: string
- recurse, inline, preprocess, ctags, defines, removeStatic: bool
+ recurse, inline, preprocess, ctags, defines: bool
dynlib, compile, pragma: seq[string]
const DOC = """
@@ -126,7 +126,7 @@ proc gitReset() =
discard execProc("git reset --hard HEAD")
-proc gitCheckout(filename: string) =
+proc gitCheckout(filename: string) {.used.} =
echo "Resetting file: $#" % [filename]
setCurrentDir(gOutput)
@@ -335,10 +335,33 @@ proc comment(file: string, pattern: string, numlines: string) =
break
proc removeStatic(filename: string) =
- ## Replace static function bodies with a semicolon
+ ## Replace static function bodies with a semicolon and commented
+ ## out body
withFile(filename):
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) =
@@ -538,9 +561,6 @@ proc c2nim(fl, outfile: string, c2nimConfig: c2nimConfigObj) =
if c2nimConfig.defines and (c2nimConfig.preprocess or c2nimConfig.ctags):
prepend(cfile, getDefines(file, c2nimConfig.inline))
- if c2nimConfig.removeStatic:
- removeStatic(cfile)
-
var
extflags = ""
passC = ""
@@ -669,9 +689,6 @@ proc runFile(file: string, cfgin: OrderedTableRef) =
if action == "create":
createDir(file.splitPath().head)
writeFile(file, cfg[act])
- elif action == "removestatic":
- removeStatic(sfile)
- c2nimConfig.removeStatic = true
elif action in @["prepend", "append", "replace", "comment",
"rename", "compile", "dynlib", "pragma",
"pipe"] and sfile != "":
@@ -733,11 +750,14 @@ proc runFile(file: string, cfgin: OrderedTableRef) =
echo "Cannot use recurse and inline simultaneously"
quit(1)
+ # Remove static inline function bodies
+ removeStatic(sfile)
+
if not noprocess:
c2nim(file, getNimout(sfile), c2nimConfig)
- if c2nimConfig.removeStatic:
- gitCheckout(sfile)
+ # Add them back for compilation
+ reAddStatic(sfile)
proc runCfg(cfg: string) =
if not fileExists(cfg):