Fix #50 - ptr object to pointer
This commit is contained in:
parent
783cf70fbf
commit
22d8181073
6 changed files with 32 additions and 19 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
import sets, strformat, strutils, tables
|
import sequtils, sets, strformat, strutils, tables
|
||||||
|
|
||||||
import regex
|
import regex
|
||||||
|
|
||||||
|
|
@ -20,8 +20,9 @@ proc saveNodeData(node: TSNode): bool =
|
||||||
val = val.getType()
|
val = val.getType()
|
||||||
|
|
||||||
let
|
let
|
||||||
pname = node.getPName()
|
pname = node.getPxName(1)
|
||||||
ppname = node.tsNodeParent().getPName()
|
ppname = node.getPxName(2)
|
||||||
|
pppname = node.getPxName(3)
|
||||||
|
|
||||||
if node.tsNodePrevNamedSibling().tsNodeIsNull():
|
if node.tsNodePrevNamedSibling().tsNodeIsNull():
|
||||||
if pname == "pointer_declarator":
|
if pname == "pointer_declarator":
|
||||||
|
|
@ -37,8 +38,9 @@ proc saveNodeData(node: TSNode): bool =
|
||||||
|
|
||||||
if node.tsNodeType() == "field_identifier" and
|
if node.tsNodeType() == "field_identifier" and
|
||||||
pname == "pointer_declarator" and
|
pname == "pointer_declarator" and
|
||||||
ppname == "function_declarator":
|
ppname == "function_declarator" and
|
||||||
gStateRT.data.add(("function_declarator", ""))
|
pppname == "pointer_declarator":
|
||||||
|
gStateRT.data.insert(("pointer_declarator", ""), gStateRT.data.len-1)
|
||||||
|
|
||||||
elif name in gExpressions:
|
elif name in gExpressions:
|
||||||
if $node.tsNodeParent.tsNodeType() notin gExpressions:
|
if $node.tsNodeParent.tsNodeType() notin gExpressions:
|
||||||
|
|
|
||||||
|
|
@ -283,16 +283,14 @@ proc getAstChildByName*(ast: ref Ast, name: string): ref Ast =
|
||||||
if name in ast.children[i].name.split("|"):
|
if name in ast.children[i].name.split("|"):
|
||||||
return ast.children[i]
|
return ast.children[i]
|
||||||
|
|
||||||
proc getPName*(node: TSNode): string =
|
proc getPxName*(node: TSNode, offset: int): string =
|
||||||
if not node.tsNodeIsNull():
|
var
|
||||||
let
|
np = node
|
||||||
nparent = node.tsNodeParent()
|
count = 0
|
||||||
if not nparent.tsNodeIsNull():
|
|
||||||
return $nparent.tsNodeType()
|
|
||||||
|
|
||||||
proc isPName*(node: TSNode, name: string): bool =
|
while not np.tsNodeIsNull() and count < offset:
|
||||||
return node.getPName() == name
|
np = np.tsNodeParent()
|
||||||
|
count += 1
|
||||||
|
|
||||||
proc isPPName*(node: TSNode, name: string): bool =
|
if count == offset and not np.tsNodeIsNull():
|
||||||
if node.getPName().len != 0:
|
return $np.tsNodeType()
|
||||||
return node.tsNodeParent().isPName(name)
|
|
||||||
|
|
|
||||||
|
|
@ -137,7 +137,8 @@ proc initGrammar() =
|
||||||
|
|
||||||
if pout.len != 0 and pout[^1] == ',':
|
if pout.len != 0 and pout[^1] == ',':
|
||||||
pout = pout[0 .. ^2]
|
pout = pout[0 .. ^2]
|
||||||
if typ != "object":
|
|
||||||
|
if tptr == "ptr " or typ != "object":
|
||||||
gStateRT.typeStr &= &" {name}* = proc({pout}): {getPtrType(tptr&typ)} {{.nimcall.}}\n"
|
gStateRT.typeStr &= &" {name}* = proc({pout}): {getPtrType(tptr&typ)} {{.nimcall.}}\n"
|
||||||
else:
|
else:
|
||||||
gStateRT.typeStr &= &" {name}* = proc({pout}) {{.nimcall.}}\n"
|
gStateRT.typeStr &= &" {name}* = proc({pout}) {{.nimcall.}}\n"
|
||||||
|
|
@ -232,7 +233,7 @@ proc initGrammar() =
|
||||||
|
|
||||||
if pout.len != 0 and pout[^1] == ',':
|
if pout.len != 0 and pout[^1] == ',':
|
||||||
pout = pout[0 .. ^2]
|
pout = pout[0 .. ^2]
|
||||||
if ftyp != "object":
|
if fptr == "ptr " or ftyp != "object":
|
||||||
gStateRT.typeStr &= &" {fname}*: proc({pout}): {getPtrType(fptr&ftyp)} {{.nimcall.}}\n"
|
gStateRT.typeStr &= &" {fname}*: proc({pout}): {getPtrType(fptr&ftyp)} {{.nimcall.}}\n"
|
||||||
else:
|
else:
|
||||||
gStateRT.typeStr &= &" {fname}*: proc({pout}) {{.nimcall.}}\n"
|
gStateRT.typeStr &= &" {fname}*: proc({pout}) {{.nimcall.}}\n"
|
||||||
|
|
@ -445,7 +446,7 @@ proc initGrammar() =
|
||||||
pout = pout[0 .. ^2]
|
pout = pout[0 .. ^2]
|
||||||
|
|
||||||
if gStateRT.procs.addNewIdentifer(fnname):
|
if gStateRT.procs.addNewIdentifer(fnname):
|
||||||
if ftyp != "object":
|
if fptr == "ptr " or ftyp != "object":
|
||||||
gStateRT.procStr &= &"proc {fnname}*({pout}): {getPtrType(fptr&ftyp)} {{.importc: \"{fname}\", header: {gStateRT.currentHeader}.}}\n"
|
gStateRT.procStr &= &"proc {fnname}*({pout}): {getPtrType(fptr&ftyp)} {{.importc: \"{fname}\", header: {gStateRT.currentHeader}.}}\n"
|
||||||
else:
|
else:
|
||||||
gStateRT.procStr &= &"proc {fnname}*({pout}) {{.importc: \"{fname}\", header: {gStateRT.currentHeader}.}}\n"
|
gStateRT.procStr &= &"proc {fnname}*({pout}) {{.importc: \"{fname}\", header: {gStateRT.currentHeader}.}}\n"
|
||||||
|
|
|
||||||
|
|
@ -54,4 +54,8 @@ float test_call_param8(int *param1) {
|
||||||
*param1 = 5 * *param1;
|
*param1 = 5 * *param1;
|
||||||
|
|
||||||
return 1.0 * *param1;
|
return 1.0 * *param1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *test_call9() {
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -81,6 +83,7 @@ typedef struct struct5 {
|
||||||
int (*tci)();
|
int (*tci)();
|
||||||
struct STRUCT1 (*tcp)(int);
|
struct STRUCT1 (*tcp)(int);
|
||||||
float (*tcp8)(int *i);
|
float (*tcp8)(int *i);
|
||||||
|
void *(*tcv)();
|
||||||
} STRUCT5;
|
} STRUCT5;
|
||||||
|
|
||||||
union UNION1 {
|
union UNION1 {
|
||||||
|
|
@ -102,6 +105,7 @@ union UNION1 test_call_param5(float param1);
|
||||||
unsigned char test_call_param6(UNION2 param1);
|
unsigned char test_call_param6(UNION2 param1);
|
||||||
int test_call_param7(union UNION1 param1);
|
int test_call_param7(union UNION1 param1);
|
||||||
float test_call_param8(int *param1);
|
float test_call_param8(int *param1);
|
||||||
|
void *test_call9();
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -64,8 +64,10 @@ s5.tci = test_call_int
|
||||||
s5.tcp = test_call_param
|
s5.tcp = test_call_param
|
||||||
s5.tcp8 = test_call_param8
|
s5.tcp8 = test_call_param8
|
||||||
s51.tci = test_call_int
|
s51.tci = test_call_int
|
||||||
|
s51.tcv = test_call9
|
||||||
check s5.tci() == 5
|
check s5.tci() == 5
|
||||||
check s51.tci() == 5
|
check s51.tci() == 5
|
||||||
|
check s51.tcv() == nil
|
||||||
|
|
||||||
e = enum1
|
e = enum1
|
||||||
e2 = enum4
|
e2 = enum4
|
||||||
|
|
@ -97,6 +99,8 @@ else:
|
||||||
check test_call_param8(addr i) == 25.0
|
check test_call_param8(addr i) == 25.0
|
||||||
check i == 25
|
check i == 25
|
||||||
|
|
||||||
|
check test_call9() == nil
|
||||||
|
|
||||||
check e3 == enum7
|
check e3 == enum7
|
||||||
check e4 == enum11
|
check e4 == enum11
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue