aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGanesh Viswanathan <dev@genotrance.com>2019-01-28 09:36:25 -0600
committerGanesh Viswanathan <dev@genotrance.com>2019-01-28 09:36:25 -0600
commit45c3487500659975c28b3cae0a6aa11348eab768 (patch)
tree71b67ed5fb19e798b94721770344c049e8fe4509
parentb86a128456858c2669a4e7aab0899fb792b56c56 (diff)
downloadnimterop-45c3487500659975c28b3cae0a6aa11348eab768.tar.gz
nimterop-45c3487500659975c28b3cae0a6aa11348eab768.zip
Fix skip bug on _, parent in Symbol
-rw-r--r--README.md2
-rw-r--r--nimterop.nimble1
-rw-r--r--nimterop/getters.nim8
-rw-r--r--nimterop/grammar.nim17
-rw-r--r--nimterop/plugin.nim1
-rw-r--r--tests/include/test.h2
-rw-r--r--tests/tnimterop_c.nim7
7 files changed, 23 insertions, 15 deletions
diff --git a/README.md b/README.md
index b262905..ca180c1 100644
--- a/README.md
+++ b/README.md
@@ -49,7 +49,7 @@ Refer to the ```tests``` directory for examples on how the library can be used.
The `toast` binary can also be used directly on the CLI. The `--help` flag provides more details.
-Detailed documentation is available for [cimport](https://genotrance.github.io/nimterop/cimport.html) and [git](https://genotrance.github.io/nimterop/git.html).
+Detailed documentation is available: [cimport](https://genotrance.github.io/nimterop/cimport.html), [plugin](https://genotrance.github.io/nimterop/plugin.html), [git](https://genotrance.github.io/nimterop/git.html)
__Implementation Details__
diff --git a/nimterop.nimble b/nimterop.nimble
index 8ba0a58..77853a5 100644
--- a/nimterop.nimble
+++ b/nimterop.nimble
@@ -45,4 +45,5 @@ task docs, "Generate docs":
# Uses: pip install ghp-import
execCmd "nim doc --project --index:on nimterop/cimport"
execCmd "nim doc --project --index:on nimterop/git"
+ execCmd "nim doc --project --index:on nimterop/plugin"
execCmd "ghp-import --no-jekyll -fp nimterop/htmldocs"
diff --git a/nimterop/getters.nim b/nimterop/getters.nim
index b03ecc5..8b6b15d 100644
--- a/nimterop/getters.nim
+++ b/nimterop/getters.nim
@@ -91,17 +91,19 @@ template checkUnderscores(name, errmsg: string): untyped =
if name.len != 0:
doAssert name[0] != '_' and name[^1] != '_', errmsg
-proc getIdentifier*(name: string, kind: NimSymKind): string =
+proc getIdentifier*(name: string, kind: NimSymKind, parent=""): string =
doAssert name.len != 0, "Blank identifier error"
- if name notin gStateRT.symOverride:
+ if name notin gStateRT.symOverride or parent.nBl:
if gStateRT.onSymbol != nil:
var
- sym = Symbol(name: name, kind: kind)
+ sym = Symbol(name: name, parent: parent, kind: kind)
gStateRT.onSymbol(sym)
result = sym.name
checkUnderscores(result, &"Identifier '{name}' still contains leading/trailing underscores '_' after 'cPlugin:onSymbol()': result '{result}'")
+
+ doAssert result.nBl, &"Blank {kind} '{result}', originally '{name}', child of '{parent}' so cannot be empty"
else:
result = name
checkUnderscores(result, &"Identifier '{result}' contains unsupported leading/trailing underscores '_': use 'cPlugin:onSymbol()' to remove")
diff --git a/nimterop/grammar.nim b/nimterop/grammar.nim
index bfc9998..aae3b17 100644
--- a/nimterop/grammar.nim
+++ b/nimterop/grammar.nim
@@ -70,8 +70,7 @@ proc initGrammar(): Grammar =
"""
template funcParamCommon(fname, pname, ptyp, pptr, pout, count, i: untyped): untyped =
- ptyp = nimState.data[i].val.getIdentifier(nskType)
- doAssert ptyp.nBl, &"Blank param type for '{fname}', originally '{nimState.data[i].val}'"
+ ptyp = nimState.data[i].val.getIdentifier(nskType, fname)
if i+1 < nimState.data.len and nimState.data[i+1].name == "pointer_declarator":
pptr = "ptr "
@@ -80,8 +79,7 @@ proc initGrammar(): Grammar =
pptr = ""
if i+1 < nimState.data.len and nimState.data[i+1].name == "identifier":
- pname = nimState.data[i+1].val.getIdentifier(nskParam)
- doAssert pname.nBl, &"Blank param name for '{fname}', originally '{nimState.data[i+1].val}'"
+ pname = nimState.data[i+1].val.getIdentifier(nskParam, fname)
i += 2
else:
pname = "a" & $count
@@ -155,8 +153,7 @@ proc initGrammar(): Grammar =
var
flen = nimState.data[i].val
if nimState.data[i].name == "identifier":
- flen = flen.getIdentifier(nskConst)
- doAssert flen.len != 0, &"Blank array length for '{name}', originally '{nimState.data[i].val}'"
+ flen = flen.getIdentifier(nskConst, name)
nimState.typeStr &= &" {name}* = {aptr}array[{flen}, {getPtrType(tptr&typ)}]\n"
else:
@@ -243,8 +240,7 @@ proc initGrammar(): Grammar =
aptr = "ptr "
i += 1
- fname = nimState.data[i].val.getIdentifier(nskField)
- doAssert fname.len != 0, &"Blank field name for '{nname}', originally '{nimState.data[i].val}'"
+ fname = nimState.data[i].val.getIdentifier(nskField, nname)
if i+1 < nimState.data.len-fend and nimState.data[i+1].name in gEnumVals:
let
@@ -461,7 +457,6 @@ proc initGrammar(): Grammar =
""",
proc (ast: ref Ast, node: TSNode, nimState: NimState) =
var
- ftyp = nimState.data[0].val.getIdentifier(nskType)
fptr = ""
i = 1
@@ -492,7 +487,9 @@ proc initGrammar(): Grammar =
if pout.len != 0 and pout[^1] == ',':
pout = pout[0 .. ^2]
- if ftyp.nBl and fnname.nBl and nimState.identifiers.addNewIdentifer(fnname):
+ if fnname.nBl and nimState.identifiers.addNewIdentifer(fnname):
+ let ftyp = nimState.data[0].val.getIdentifier(nskType, fnname)
+
if fptr == "ptr " or ftyp != "object":
nimState.procStr &= &"proc {fnname}*({pout}): {getPtrType(fptr&ftyp)} {{.importc: \"{fname}\", header: {nimState.currentHeader}.}}\n"
else:
diff --git a/nimterop/plugin.nim b/nimterop/plugin.nim
index 325abe5..646c83c 100644
--- a/nimterop/plugin.nim
+++ b/nimterop/plugin.nim
@@ -3,6 +3,7 @@ import macros
type
Symbol* = object
name*: string
+ parent*: string
kind*: NimSymKind
OnSymbol* = proc(sym: var Symbol) {.cdecl.} \ No newline at end of file
diff --git a/tests/include/test.h b/tests/include/test.h
index 29048a7..e85acfd 100644
--- a/tests/include/test.h
+++ b/tests/include/test.h
@@ -129,6 +129,8 @@ ENUM6 test_call_etype_ptr6();
union union3 test_call_utype3();
UNION3 test_call_etype_ptr3();
+typedef struct _Kernel { char name; } *Kernel;
+
#ifdef __cplusplus
}
#endif \ No newline at end of file
diff --git a/tests/tnimterop_c.nim b/tests/tnimterop_c.nim
index 457db7b..ece78db 100644
--- a/tests/tnimterop_c.nim
+++ b/tests/tnimterop_c.nim
@@ -13,7 +13,10 @@ cPlugin:
import strutils
proc onSymbol*(sym: var Symbol) {.exportc, dynlib.} =
- sym.name = sym.name.strip(chars={'_'})
+ if sym.name == "_Kernel":
+ sym.name = "uKernel"
+ else:
+ sym.name = sym.name.strip(chars={'_'})
cImport cSearchPath "test.h"
@@ -130,6 +133,8 @@ var
e6p: ENUM6
u3: union3
u3p: UNION3
+ k: uKernel
+ kp: Kernel
cAddStdDir()