aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgenotrance <dev@genotrance.com>2018-07-11 00:04:36 -0500
committerGitHub <noreply@github.com>2018-07-11 00:04:36 -0500
commit6aca40808b7afadb9051d3bffa173ee4ffbfcdd0 (patch)
tree915d03ab5b6b4464d2e1ed172ee97b907eb58948
parentef59bd105d351edb5c969c6e4c153f2c4b71caf4 (diff)
parent15ba47946822a80d034c247c3f22b350d4651d74 (diff)
downloadnimgen-6aca40808b7afadb9051d3bffa173ee4ffbfcdd0.tar.gz
nimgen-6aca40808b7afadb9051d3bffa173ee4ffbfcdd0.zip
Merge pull request #19 from jyapayne/add_static_remove
Add preliminary support for removing static inline function bodies
-rw-r--r--nimgen.nim50
1 files changed, 49 insertions, 1 deletions
diff --git a/nimgen.nim b/nimgen.nim
index c6eb5a9..97f8809 100644
--- a/nimgen.nim
+++ b/nimgen.nim
@@ -92,7 +92,9 @@ proc execProc(cmd: string): string =
proc extractZip(zipfile: string) =
var cmd = "unzip -o $#"
if defined(Windows):
- cmd = "powershell -nologo -noprofile -command \"& { Add-Type -A 'System.IO.Compression.FileSystem'; [IO.Compression.ZipFile]::ExtractToDirectory('$#', '.'); }\""
+ cmd = "powershell -nologo -noprofile -command \"& { Add-Type -A " &
+ "'System.IO.Compression.FileSystem'; " &
+ "[IO.Compression.ZipFile]::ExtractToDirectory('$#', '.'); }\""
setCurrentDir(gOutput)
defer: setCurrentDir(gProjectDir)
@@ -124,6 +126,16 @@ proc gitReset() =
discard execProc("git reset --hard HEAD")
+proc gitCheckout(filename: string) {.used.} =
+ echo "Resetting file: $#" % [filename]
+
+ setCurrentDir(gOutput)
+ defer: setCurrentDir(gProjectDir)
+
+ let adjustedFile = filename.replace(gOutput & $DirSep, "")
+
+ discard execProc("git checkout $#" % [adjustedFile])
+
proc gitRemotePull(url: string, pull=true) =
if dirExists(gOutput/".git"):
if pull:
@@ -323,6 +335,36 @@ proc comment(file: string, pattern: string, numlines: string) =
idx += 1
break
+proc removeStatic(filename: string) =
+ ## Replace static function bodies with a semicolon and commented
+ ## out body
+ 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 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) =
if file.splitFile().ext == ".nim":
return
@@ -722,9 +764,15 @@ 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)
+ # Add them back for compilation
+ reAddStatic(sfile)
+
proc runCfg(cfg: string) =
if not fileExists(cfg):
echo "Config doesn't exist: " & cfg