Fix skip bug on _, parent in Symbol
This commit is contained in:
parent
b86a128456
commit
45c3487500
7 changed files with 23 additions and 15 deletions
|
|
@ -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__
|
||||
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import macros
|
|||
type
|
||||
Symbol* = object
|
||||
name*: string
|
||||
parent*: string
|
||||
kind*: NimSymKind
|
||||
|
||||
OnSymbol* = proc(sym: var Symbol) {.cdecl.}
|
||||
|
|
@ -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
|
||||
|
|
@ -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()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue