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.
|
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__
|
__Implementation Details__
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -45,4 +45,5 @@ task docs, "Generate docs":
|
||||||
# Uses: pip install ghp-import
|
# Uses: pip install ghp-import
|
||||||
execCmd "nim doc --project --index:on nimterop/cimport"
|
execCmd "nim doc --project --index:on nimterop/cimport"
|
||||||
execCmd "nim doc --project --index:on nimterop/git"
|
execCmd "nim doc --project --index:on nimterop/git"
|
||||||
|
execCmd "nim doc --project --index:on nimterop/plugin"
|
||||||
execCmd "ghp-import --no-jekyll -fp nimterop/htmldocs"
|
execCmd "ghp-import --no-jekyll -fp nimterop/htmldocs"
|
||||||
|
|
|
||||||
|
|
@ -91,17 +91,19 @@ template checkUnderscores(name, errmsg: string): untyped =
|
||||||
if name.len != 0:
|
if name.len != 0:
|
||||||
doAssert name[0] != '_' and name[^1] != '_', errmsg
|
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"
|
doAssert name.len != 0, "Blank identifier error"
|
||||||
|
|
||||||
if name notin gStateRT.symOverride:
|
if name notin gStateRT.symOverride or parent.nBl:
|
||||||
if gStateRT.onSymbol != nil:
|
if gStateRT.onSymbol != nil:
|
||||||
var
|
var
|
||||||
sym = Symbol(name: name, kind: kind)
|
sym = Symbol(name: name, parent: parent, kind: kind)
|
||||||
gStateRT.onSymbol(sym)
|
gStateRT.onSymbol(sym)
|
||||||
|
|
||||||
result = sym.name
|
result = sym.name
|
||||||
checkUnderscores(result, &"Identifier '{name}' still contains leading/trailing underscores '_' after 'cPlugin:onSymbol()': result '{result}'")
|
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:
|
else:
|
||||||
result = name
|
result = name
|
||||||
checkUnderscores(result, &"Identifier '{result}' contains unsupported leading/trailing underscores '_': use 'cPlugin:onSymbol()' to remove")
|
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 =
|
template funcParamCommon(fname, pname, ptyp, pptr, pout, count, i: untyped): untyped =
|
||||||
ptyp = nimState.data[i].val.getIdentifier(nskType)
|
ptyp = nimState.data[i].val.getIdentifier(nskType, fname)
|
||||||
doAssert ptyp.nBl, &"Blank param type for '{fname}', originally '{nimState.data[i].val}'"
|
|
||||||
|
|
||||||
if i+1 < nimState.data.len and nimState.data[i+1].name == "pointer_declarator":
|
if i+1 < nimState.data.len and nimState.data[i+1].name == "pointer_declarator":
|
||||||
pptr = "ptr "
|
pptr = "ptr "
|
||||||
|
|
@ -80,8 +79,7 @@ proc initGrammar(): Grammar =
|
||||||
pptr = ""
|
pptr = ""
|
||||||
|
|
||||||
if i+1 < nimState.data.len and nimState.data[i+1].name == "identifier":
|
if i+1 < nimState.data.len and nimState.data[i+1].name == "identifier":
|
||||||
pname = nimState.data[i+1].val.getIdentifier(nskParam)
|
pname = nimState.data[i+1].val.getIdentifier(nskParam, fname)
|
||||||
doAssert pname.nBl, &"Blank param name for '{fname}', originally '{nimState.data[i+1].val}'"
|
|
||||||
i += 2
|
i += 2
|
||||||
else:
|
else:
|
||||||
pname = "a" & $count
|
pname = "a" & $count
|
||||||
|
|
@ -155,8 +153,7 @@ proc initGrammar(): Grammar =
|
||||||
var
|
var
|
||||||
flen = nimState.data[i].val
|
flen = nimState.data[i].val
|
||||||
if nimState.data[i].name == "identifier":
|
if nimState.data[i].name == "identifier":
|
||||||
flen = flen.getIdentifier(nskConst)
|
flen = flen.getIdentifier(nskConst, name)
|
||||||
doAssert flen.len != 0, &"Blank array length for '{name}', originally '{nimState.data[i].val}'"
|
|
||||||
|
|
||||||
nimState.typeStr &= &" {name}* = {aptr}array[{flen}, {getPtrType(tptr&typ)}]\n"
|
nimState.typeStr &= &" {name}* = {aptr}array[{flen}, {getPtrType(tptr&typ)}]\n"
|
||||||
else:
|
else:
|
||||||
|
|
@ -243,8 +240,7 @@ proc initGrammar(): Grammar =
|
||||||
aptr = "ptr "
|
aptr = "ptr "
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
fname = nimState.data[i].val.getIdentifier(nskField)
|
fname = nimState.data[i].val.getIdentifier(nskField, nname)
|
||||||
doAssert fname.len != 0, &"Blank field name for '{nname}', originally '{nimState.data[i].val}'"
|
|
||||||
|
|
||||||
if i+1 < nimState.data.len-fend and nimState.data[i+1].name in gEnumVals:
|
if i+1 < nimState.data.len-fend and nimState.data[i+1].name in gEnumVals:
|
||||||
let
|
let
|
||||||
|
|
@ -461,7 +457,6 @@ proc initGrammar(): Grammar =
|
||||||
""",
|
""",
|
||||||
proc (ast: ref Ast, node: TSNode, nimState: NimState) =
|
proc (ast: ref Ast, node: TSNode, nimState: NimState) =
|
||||||
var
|
var
|
||||||
ftyp = nimState.data[0].val.getIdentifier(nskType)
|
|
||||||
fptr = ""
|
fptr = ""
|
||||||
i = 1
|
i = 1
|
||||||
|
|
||||||
|
|
@ -492,7 +487,9 @@ proc initGrammar(): Grammar =
|
||||||
if pout.len != 0 and pout[^1] == ',':
|
if pout.len != 0 and pout[^1] == ',':
|
||||||
pout = pout[0 .. ^2]
|
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":
|
if fptr == "ptr " or ftyp != "object":
|
||||||
nimState.procStr &= &"proc {fnname}*({pout}): {getPtrType(fptr&ftyp)} {{.importc: \"{fname}\", header: {nimState.currentHeader}.}}\n"
|
nimState.procStr &= &"proc {fnname}*({pout}): {getPtrType(fptr&ftyp)} {{.importc: \"{fname}\", header: {nimState.currentHeader}.}}\n"
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import macros
|
||||||
type
|
type
|
||||||
Symbol* = object
|
Symbol* = object
|
||||||
name*: string
|
name*: string
|
||||||
|
parent*: string
|
||||||
kind*: NimSymKind
|
kind*: NimSymKind
|
||||||
|
|
||||||
OnSymbol* = proc(sym: var Symbol) {.cdecl.}
|
OnSymbol* = proc(sym: var Symbol) {.cdecl.}
|
||||||
|
|
@ -129,6 +129,8 @@ ENUM6 test_call_etype_ptr6();
|
||||||
union union3 test_call_utype3();
|
union union3 test_call_utype3();
|
||||||
UNION3 test_call_etype_ptr3();
|
UNION3 test_call_etype_ptr3();
|
||||||
|
|
||||||
|
typedef struct _Kernel { char name; } *Kernel;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -13,7 +13,10 @@ cPlugin:
|
||||||
import strutils
|
import strutils
|
||||||
|
|
||||||
proc onSymbol*(sym: var Symbol) {.exportc, dynlib.} =
|
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"
|
cImport cSearchPath "test.h"
|
||||||
|
|
||||||
|
|
@ -130,6 +133,8 @@ var
|
||||||
e6p: ENUM6
|
e6p: ENUM6
|
||||||
u3: union3
|
u3: union3
|
||||||
u3p: UNION3
|
u3p: UNION3
|
||||||
|
k: uKernel
|
||||||
|
kp: Kernel
|
||||||
|
|
||||||
cAddStdDir()
|
cAddStdDir()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue