Implement var proc

This commit is contained in:
Ganesh Viswanathan 2019-10-16 21:25:31 -05:00
commit 8dc327d02b
3 changed files with 28 additions and 10 deletions

View file

@ -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:

View file

@ -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

View file

@ -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