aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--nimterop/ast.nim14
-rw-r--r--nimterop/grammar.nim17
-rw-r--r--tests/tpcre.nim7
3 files changed, 28 insertions, 10 deletions
diff --git a/nimterop/ast.nim b/nimterop/ast.nim
index b5176fb..128a7e6 100644
--- a/nimterop/ast.nim
+++ b/nimterop/ast.nim
@@ -47,14 +47,16 @@ proc saveNodeData(node: TSNode, nimState: NimState): bool =
nimState.data.add((name, val))
- if name == "field_identifier" and
- pname == "pointer_declarator" and
+ if pname == "pointer_declarator" and
ppname == "function_declarator":
- if pppname == "pointer_declarator":
- nimState.data.insert(("pointer_declarator", ""), nimState.data.len-1)
- if ppppname == "pointer_declarator":
+ if name == "field_identifier":
+ if pppname == "pointer_declarator":
nimState.data.insert(("pointer_declarator", ""), nimState.data.len-1)
- nimState.data.add(("function_declarator", ""))
+ if ppppname == "pointer_declarator":
+ nimState.data.insert(("pointer_declarator", ""), nimState.data.len-1)
+ nimState.data.add(("function_declarator", ""))
+ elif name == "identifier":
+ nimState.data.add(("pointer_declarator", ""))
elif name in gExpressions and name != "escape_sequence":
if $node.tsNodeParent.tsNodeType() notin gExpressions:
diff --git a/nimterop/grammar.nim b/nimterop/grammar.nim
index bd9a851..8d98dde 100644
--- a/nimterop/grammar.nim
+++ b/nimterop/grammar.nim
@@ -86,7 +86,7 @@ proc initGrammar(): Grammar =
(pointer_declarator!
(type_identifier)
)
- (type_identifier)
+ (type_identifier|identifier)
)
{paramListGrammar}
(noexcept|throw_specifier?)
@@ -588,8 +588,13 @@ proc initGrammar(): Grammar =
pout, pname, ptyp, pptr = ""
count = 1
flen = ""
+ fVar = false
i += 1
+ if i < nimState.data.len and nimState.data[i].name == "pointer_declarator":
+ fVar = true
+ i += 1
+
while i < nimState.data.len:
if nimState.data[i].name == "function_declarator":
break
@@ -605,9 +610,15 @@ proc initGrammar(): Grammar =
pragma = nimState.getPragma(nimState.getImportC(fname, fnname), "cdecl")
if fptr.len != 0 or ftyp != "object":
- nimState.procStr &= &"{nimState.getComments(true)}\nproc {fnname}*({pout}): {getPtrType(fptr&ftyp)}{pragma}"
+ if fVar:
+ nimState.procStr &= &"{nimState.getComments(true)}\nvar {fnname}*: proc ({pout}): {getPtrType(fptr&ftyp)}{{.cdecl.}}"
+ else:
+ nimState.procStr &= &"{nimState.getComments(true)}\nproc {fnname}*({pout}): {getPtrType(fptr&ftyp)}{pragma}"
else:
- nimState.procStr &= &"{nimState.getComments(true)}\nproc {fnname}*({pout}){pragma}"
+ if fVar:
+ nimState.procStr &= &"{nimState.getComments(true)}\nvar {fnname}*: proc ({pout}){{.cdecl.}}"
+ else:
+ nimState.procStr &= &"{nimState.getComments(true)}\nproc {fnname}*({pout}){pragma}"
))
# // comment
diff --git a/tests/tpcre.nim b/tests/tpcre.nim
index 5bc97da..41809cb 100644
--- a/tests/tpcre.nim
+++ b/tests/tpcre.nim
@@ -1,6 +1,6 @@
import os
-import nimterop/[cimport, build, paths]
+import nimterop/[cimport, build]
const
baseDir = getProjectCacheDir("nimterop" / "tests" / "pcre")
@@ -33,3 +33,8 @@ cPlugin:
cImport(pcreH, dynlib="dynpcre")
echo version()
+
+proc my_malloc(a1: cuint) {.cdecl.} =
+ discard
+
+malloc = my_malloc