diff options
| author | Ganesh Viswanathan <dev@genotrance.com> | 2019-01-23 09:37:25 -0600 |
|---|---|---|
| committer | Ganesh Viswanathan <dev@genotrance.com> | 2019-01-23 09:37:25 -0600 |
| commit | 46f7940f30ca7ef41dfcb01c09c72ce21dc47b89 (patch) | |
| tree | 02538107e7ed7d658137eaf9bacc0e5158bae4ab | |
| parent | d6e9a491946a153e41b25eda524bd9335f1baaa6 (diff) | |
| download | nimterop-46f7940f30ca7ef41dfcb01c09c72ce21dc47b89.tar.gz nimterop-46f7940f30ca7ef41dfcb01c09c72ce21dc47b89.zip | |
Initial support for #56
| -rw-r--r-- | nimterop/cimport.nim | 45 | ||||
| -rw-r--r-- | nimterop/globals.nim | 2 |
2 files changed, 46 insertions, 1 deletions
diff --git a/nimterop/cimport.nim b/nimterop/cimport.nim index beaaeb2..ad9a4de 100644 --- a/nimterop/cimport.nim +++ b/nimterop/cimport.nim @@ -99,6 +99,9 @@ proc getToast(fullpath: string, recurse: bool = false): string = for i in gStateCT.includeDirs: cmd.add &"--includeDirs+={i.quoteShell} " + for i in gStateCT.symOverride: + cmd.add &"--symOverride+={i} " + cmd.add &"{fullpath.quoteShell}" echo cmd (result, ret) = gorgeEx(cmd, cache=getCacheValue(fullpath)) @@ -112,6 +115,48 @@ proc getGccPaths(mode = "c"): string = (result, ret) = gorgeEx("gcc -Wp,-v -x" & mmode & " " & nul) +macro cOverride*(body): untyped = + ## When the wrapper code generated by nimterop is missing certain symbols or not + ## accurate, it may be required to hand wrap them. Define them in a ``cOverride()`` + ## macro block so that Nimterop no longer defines these symbols. + ## + ## For example: + ## + ## .. code-block:: c + ## + ## int svGetCallerInfo(const char** fileName, int *lineNumber); + ## + ## This could get mapped to: + ## + ## .. code-block:: nim + ## + ## proc svGetCallerInfo(fileName: ptr cstring; lineNumber: var cint) + ## + ## Whereas it might mean: + ## + ## .. code-block:: nim + ## + ## cOverride: + ## proc svGetCallerInfo(fileName: var cstring; lineNumber: var cint) + ## + ## Using the ``cOverride()`` block, nimterop can be instructed to skip over + ## ``svGetCallerInfo()``. This works for procs, consts and types. + + for sym in body: + case sym.kind: + of nnkProcDef: + gStateCT.symOverride.add $sym[0] + of nnkConstSection, nnkTypeSection: + for ssym in sym: + gStateCT.symOverride.add $ssym[0] + else: + discard + + result = body + + if gStateCT.debug: + echo "Overriding " & gStateCT.symOverride.join(" ") + proc cSearchPath*(path: string): string {.compileTime.}= ## Return a file or directory found in search path configured using ## ``cSearchPath()`` diff --git a/nimterop/globals.nim b/nimterop/globals.nim index 1a96aa3..42abf8f 100644 --- a/nimterop/globals.nim +++ b/nimterop/globals.nim @@ -46,7 +46,7 @@ type regex*: Regex State = object - compile*, defines*, headers*, includeDirs*, searchDirs*: seq[string] + compile*, defines*, headers*, includeDirs*, searchDirs*, symOverride*: seq[string] nocache*, debug*, past*, preprocess*, pnim*, pretty*, recurse*: bool |
