diff options
| author | Ganesh Viswanathan <dev@genotrance.com> | 2018-11-25 12:27:28 -0600 |
|---|---|---|
| committer | Ganesh Viswanathan <dev@genotrance.com> | 2018-11-25 12:27:28 -0600 |
| commit | 50eba9a485691f984947af70ff3b94556825a7ee (patch) | |
| tree | 5b74128ae8626fe951c9865cc7c18074ab6700ab | |
| parent | b9b5174759b6dd1f94404b2f63637d406aec4983 (diff) | |
| download | nimterop-50eba9a485691f984947af70ff3b94556825a7ee.tar.gz nimterop-50eba9a485691f984947af70ff3b94556825a7ee.zip | |
Minor changes
| -rw-r--r-- | nimterop/cimport.nim | 16 | ||||
| -rw-r--r-- | nimterop/getters.nim | 38 |
2 files changed, 36 insertions, 18 deletions
diff --git a/nimterop/cimport.nim b/nimterop/cimport.nim index a47443c..8a85145 100644 --- a/nimterop/cimport.nim +++ b/nimterop/cimport.nim @@ -34,16 +34,20 @@ macro cDebug*(): untyped = macro cDefine*(name: static string, val: static string = ""): untyped = result = newNimNode(nnkStmtList) - var str = "-D" & name + var str = name if val.nBl: str &= &"=\"{val}\"" - result.add(quote do: - {.passC: `str`.} - ) + if str notin gDefines: + gDefines.add(str) + str = "-D" & str - if gDebug: - echo result.repr + result.add(quote do: + {.passC: `str`.} + ) + + if gDebug: + echo result.repr macro cAddSearchDir*(dir: static string): untyped = result = newNimNode(nnkStmtList) diff --git a/nimterop/getters.nim b/nimterop/getters.nim index 0412522..6ba83e8 100644 --- a/nimterop/getters.nim +++ b/nimterop/getters.nim @@ -1,15 +1,15 @@ -import macros, strutils +import macros, strformat, strutils import regex -import globals +import git, globals proc getIdentifier*(str: string): string = result = str.strip(chars={'_'}) proc getType*(str: string): string = result = str.strip(chars={'_'}).replace(re"([u]?int[\d]+)_t", "$1").replace(re"^void$", "object") - + proc getLit*(str: string): string = if str.contains(re"^[\-]?[\d]+$") or str.contains(re"^[\-]?[\d]*\.[\d]+$") or @@ -19,15 +19,8 @@ proc getLit*(str: string): string = proc getNodeValIf*(node: ref Ast, esym: Sym): string = if esym != node.sym: return - - return gCode[node.start .. node.stop-1].strip() -proc getGccPaths*(mode = "c"): string = - var - nul = when defined(Windows): "nul" else: "/dev/null" - mmode = if mode == "cpp": "c++" else: mode - - return staticExec("gcc -Wp,-v -x" & mmode & " " & nul) + return gCode[node.start .. node.stop-1].strip() proc getLineCol*(node: ref Ast): tuple[line, col: int] = result.line = 1 @@ -36,4 +29,25 @@ proc getLineCol*(node: ref Ast): tuple[line, col: int] = if gCode[i] == '\n': result.col = 0 result.line += 1 - result.col += 1
\ No newline at end of file + result.col += 1 + +proc getGccPaths*(mode = "c"): string = + var + nul = when defined(Windows): "nul" else: "/dev/null" + mmode = if mode == "cpp": "c++" else: mode + + return staticExec("gcc -Wp,-v -x" & mmode & " " & nul) + +proc getPreprocessor*(fullpath: string, mode = "cpp"): string = + var + mmode = if mode == "cpp": "c++" else: mode + cmd = &"gcc -E -dD -x{mmode} " + + for inc in gIncludeDirs: + cmd &= &"-I\"{inc}\" " + + for def in gDefines: + cmd &= &"-D{def} " + + cmd &= &"\"{fullpath}\"" + return staticExec(cmd)
\ No newline at end of file |
