ast2 fix issue 156 - abstract function pointer
This commit is contained in:
parent
4c513a50de
commit
4ccde62d4f
5 changed files with 63 additions and 7 deletions
|
|
@ -10,7 +10,7 @@ installDirs = @["nimterop"]
|
||||||
installFiles = @["config.nims"]
|
installFiles = @["config.nims"]
|
||||||
|
|
||||||
# Dependencies
|
# Dependencies
|
||||||
requires "nim >= 0.20.2", "regex >= 0.13.1", "cligen >= 0.9.43"
|
requires "nim >= 0.20.2", "regex#v0.13.1", "cligen >= 0.9.43"
|
||||||
|
|
||||||
import nimterop/docs
|
import nimterop/docs
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -531,10 +531,11 @@ proc newIdentDefs(nimState: NimState, name: string, node: TSNode, offset: SomeIn
|
||||||
result = nil
|
result = nil
|
||||||
else:
|
else:
|
||||||
let
|
let
|
||||||
fdecl = node[start+1].anyChildInTree("function_declarator")
|
fdecl = node[start+1].firstChildInTree("function_declarator")
|
||||||
adecl = node[start+1].anyChildInTree("array_declarator")
|
afdecl = node[start+1].firstChildInTree("abstract_function_declarator")
|
||||||
|
adecl = node[start+1].firstChildInTree("array_declarator")
|
||||||
abst = node[start+1].getName() == "abstract_pointer_declarator"
|
abst = node[start+1].getName() == "abstract_pointer_declarator"
|
||||||
if fdecl.isNil and adecl.isNil:
|
if fdecl.isNil and afdecl.isNil and adecl.isNil:
|
||||||
if abst:
|
if abst:
|
||||||
# Only for proc with no named param with pointer type
|
# Only for proc with no named param with pointer type
|
||||||
# Create a param name based on offset
|
# Create a param name based on offset
|
||||||
|
|
@ -577,6 +578,18 @@ proc newIdentDefs(nimState: NimState, name: string, node: TSNode, offset: SomeIn
|
||||||
result.add pident
|
result.add pident
|
||||||
result.add nimState.getTypeProc(name, node[start+1], node[start])
|
result.add nimState.getTypeProc(name, node[start+1], node[start])
|
||||||
result.add newNode(nkEmpty)
|
result.add newNode(nkEmpty)
|
||||||
|
elif not afdecl.isNil:
|
||||||
|
# Only for proc with no named param with function pointer type
|
||||||
|
# Create a param name based on offset
|
||||||
|
#
|
||||||
|
# int func(int (*)(int *));
|
||||||
|
let
|
||||||
|
pname = "a" & $(offset+1)
|
||||||
|
pident = nimState.getIdent(pname, tinfo, exported)
|
||||||
|
procTy = nimState.getTypeProc(name, node[start+1], node[start])
|
||||||
|
result.add pident
|
||||||
|
result.add procTy
|
||||||
|
result.add newNode(nkEmpty)
|
||||||
elif not adecl.isNil:
|
elif not adecl.isNil:
|
||||||
# Named param, array type
|
# Named param, array type
|
||||||
let
|
let
|
||||||
|
|
@ -963,6 +976,9 @@ proc getTypeProc(nimState: NimState, name: string, node, rnode: TSNode): PNode =
|
||||||
# node could have nested pointers
|
# node could have nested pointers
|
||||||
tcount = node.getPtrCount()
|
tcount = node.getPtrCount()
|
||||||
|
|
||||||
|
# Nameless function pointer
|
||||||
|
afdecl = node.firstChildInTree("abstract_function_declarator")
|
||||||
|
|
||||||
# Name could be nested pointer to function
|
# Name could be nested pointer to function
|
||||||
#
|
#
|
||||||
# (..
|
# (..
|
||||||
|
|
@ -976,7 +992,12 @@ proc getTypeProc(nimState: NimState, name: string, node, rnode: TSNode): PNode =
|
||||||
# )
|
# )
|
||||||
# )
|
# )
|
||||||
# )
|
# )
|
||||||
ncount = node.getAtom().tsNodeParent().getPtrCount(reverse = true)
|
ncount =
|
||||||
|
if not afdecl.isNil:
|
||||||
|
# Pointer to function pointer
|
||||||
|
afdecl[0].getXCount("abstract_pointer_declarator")
|
||||||
|
else:
|
||||||
|
node.getAtom().tsNodeParent().getPtrCount(reverse = true)
|
||||||
|
|
||||||
# Return type
|
# Return type
|
||||||
var
|
var
|
||||||
|
|
|
||||||
|
|
@ -123,6 +123,17 @@ typedef MagickBooleanType
|
||||||
const int,void *),
|
const int,void *),
|
||||||
(*UpdateImageViewMethod)(ImageView *,const size_t,const int,void *);
|
(*UpdateImageViewMethod)(ImageView *,const size_t,const int,void *);
|
||||||
|
|
||||||
|
// Issue #156, math.h
|
||||||
|
void
|
||||||
|
*absfunptr1 (int (*)(struct A0 *)),
|
||||||
|
**absfunptr2 (int (**)(struct A1 *)),
|
||||||
|
absfunptr3 (int *(*)(struct A2 *)),
|
||||||
|
*absfunptr4 (int *(**)(struct A3 *)),
|
||||||
|
absfunptr5 (int (*a)(A4 *));
|
||||||
|
|
||||||
|
int sqlite3_bind_blob(struct A1*, int, const void*, int n, void(*)(void*));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -241,6 +252,7 @@ void
|
||||||
(*pcre_free)(void *),
|
(*pcre_free)(void *),
|
||||||
*(*pcre_stack_malloc)(size_t);
|
*(*pcre_stack_malloc)(size_t);
|
||||||
|
|
||||||
|
typedef int ImageView, MagickBooleanType;
|
||||||
typedef MagickBooleanType
|
typedef MagickBooleanType
|
||||||
(*DuplexTransferImageViewMethod)(const ImageView *,const ImageView *,
|
(*DuplexTransferImageViewMethod)(const ImageView *,const ImageView *,
|
||||||
ImageView *,const size_t,const int,void *),
|
ImageView *,const size_t,const int,void *),
|
||||||
|
|
@ -250,6 +262,18 @@ typedef MagickBooleanType
|
||||||
const int,void *),
|
const int,void *),
|
||||||
(*UpdateImageViewMethod)(ImageView *,const size_t,const int,void *);
|
(*UpdateImageViewMethod)(ImageView *,const size_t,const int,void *);
|
||||||
|
|
||||||
|
// Issue #156, math.h
|
||||||
|
void
|
||||||
|
*absfunptr1 (int (*)(struct A0 *)),
|
||||||
|
**absfunptr2 (int (**)(struct A1 *)),
|
||||||
|
absfunptr3 (int *(*)(struct A2 *)),
|
||||||
|
*absfunptr4 (int *(**)(struct A3 *)),
|
||||||
|
absfunptr5 (int (*a)(A4 *));
|
||||||
|
|
||||||
|
int sqlite3_bind_blob(struct A1*, int, const void*, int n, void(*)(void*));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -325,3 +325,13 @@ assert TransferImageViewMethod is
|
||||||
|
|
||||||
assert UpdateImageViewMethod is
|
assert UpdateImageViewMethod is
|
||||||
proc (a1: ptr ImageView; a2: uint; a3: cint; a4: pointer): MagickBooleanType {.cdecl.}
|
proc (a1: ptr ImageView; a2: uint; a3: cint; a4: pointer): MagickBooleanType {.cdecl.}
|
||||||
|
|
||||||
|
# Issue #156, math.h
|
||||||
|
assert absfunptr1 is proc(a1: proc(a1: ptr A0): cint {.cdecl.}): pointer {.cdecl.}
|
||||||
|
assert absfunptr2 is proc(a1: ptr proc(a1: ptr A1): cint {.cdecl.}): ptr pointer {.cdecl.}
|
||||||
|
assert absfunptr3 is proc(a1: proc(a1: ptr A2): ptr cint {.cdecl.}) {.cdecl.}
|
||||||
|
assert absfunptr4 is proc(a1: ptr proc(a1: ptr A3): ptr cint {.cdecl.}): pointer {.cdecl.}
|
||||||
|
assert absfunptr5 is proc(a1: proc(a1: ptr A4): cint {.cdecl.}) {.cdecl.}
|
||||||
|
|
||||||
|
assert sqlite3_bind_blob is
|
||||||
|
proc(a1: ptr A1, a2: cint, a3: pointer, n: cint, a5: proc(a1: pointer) {.cdecl.}): cint {.cdecl.}
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,8 @@ cPlugin:
|
||||||
proc onSymbol*(sym: var Symbol) {.exportc, dynlib.} =
|
proc onSymbol*(sym: var Symbol) {.exportc, dynlib.} =
|
||||||
sym.name = sym.name.strip(chars={'_'}).replace("__", "_")
|
sym.name = sym.name.strip(chars={'_'}).replace("__", "_")
|
||||||
|
|
||||||
cImport cSearchPath("math.h")
|
const FLAGS {.strdefine.} = ""
|
||||||
|
cImport(cSearchPath("math.h"), flags = FLAGS)
|
||||||
|
|
||||||
check sin(5) == -0.9589242746631385
|
check sin(5) == -0.9589242746631385
|
||||||
check abs(-5) == 5
|
check abs(-5) == 5
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue