Partial fix for #139
This commit is contained in:
parent
531843a82a
commit
48955b3aa1
6 changed files with 58 additions and 18 deletions
|
|
@ -86,15 +86,30 @@ proc searchAstForNode(ast: ref Ast, node: TSNode, nimState: NimState): bool =
|
||||||
ast.getAstChildByName($nodeChild.tsNodeType())
|
ast.getAstChildByName($nodeChild.tsNodeType())
|
||||||
else:
|
else:
|
||||||
ast
|
ast
|
||||||
|
|
||||||
|
if nimState.gState.debug:
|
||||||
|
nimState.nodeBranch.add $node.tsNodeType()
|
||||||
|
echo "#" & spaces(nimState.nodeBranch.len) & nimState.nodeBranch[^1]
|
||||||
|
|
||||||
if not searchAstForNode(astChild, nodeChild, nimState):
|
if not searchAstForNode(astChild, nodeChild, nimState):
|
||||||
|
if nimState.gState.debug:
|
||||||
|
echo "#" & spaces(nimState.nodeBranch.len) & &" {$nodeChild.tsNodeType()} unexpected"
|
||||||
|
discard nimState.nodeBranch.pop()
|
||||||
flag = false
|
flag = false
|
||||||
break
|
break
|
||||||
|
|
||||||
|
if nimState.gState.debug:
|
||||||
|
discard nimState.nodeBranch.pop()
|
||||||
|
if nimState.nodeBranch.len == 0:
|
||||||
|
echo ""
|
||||||
|
|
||||||
if flag:
|
if flag:
|
||||||
return node.saveNodeData(nimState)
|
return node.saveNodeData(nimState)
|
||||||
else:
|
else:
|
||||||
|
echo "#" & spaces(nimState.nodeBranch.len+1) & $node.tsNodeType()
|
||||||
return node.saveNodeData(nimState)
|
return node.saveNodeData(nimState)
|
||||||
elif node.getTSNodeNamedChildCountSansComments() == 0:
|
elif node.getTSNodeNamedChildCountSansComments() == 0:
|
||||||
|
echo "#" & spaces(nimState.nodeBranch.len+1) & $node.tsNodeType()
|
||||||
return node.saveNodeData(nimState)
|
return node.saveNodeData(nimState)
|
||||||
|
|
||||||
proc searchAst(root: TSNode, astTable: AstTable, nimState: NimState) =
|
proc searchAst(root: TSNode, astTable: AstTable, nimState: NimState) =
|
||||||
|
|
|
||||||
|
|
@ -72,6 +72,8 @@ type
|
||||||
|
|
||||||
data*: seq[tuple[name, val: string]]
|
data*: seq[tuple[name, val: string]]
|
||||||
|
|
||||||
|
nodeBranch*: seq[string]
|
||||||
|
|
||||||
var
|
var
|
||||||
gStateCT {.compiletime, used.} = new(State)
|
gStateCT {.compiletime, used.} = new(State)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,19 @@ proc initGrammar(): Grammar =
|
||||||
)
|
)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
arrGrammar = &"""
|
||||||
|
(array_declarator!
|
||||||
|
(pointer_declarator!
|
||||||
|
(pointer_declarator!
|
||||||
|
(type_identifier)
|
||||||
|
)
|
||||||
|
(type_identifier)
|
||||||
|
)
|
||||||
|
(type_identifier|identifier)
|
||||||
|
(identifier|number_literal)
|
||||||
|
)
|
||||||
|
"""
|
||||||
|
|
||||||
paramListGrammar = &"""
|
paramListGrammar = &"""
|
||||||
(parameter_list
|
(parameter_list
|
||||||
(parameter_declaration*
|
(parameter_declaration*
|
||||||
|
|
@ -52,10 +65,13 @@ proc initGrammar(): Grammar =
|
||||||
(type_qualifier?)
|
(type_qualifier?)
|
||||||
(pointer_declarator!
|
(pointer_declarator!
|
||||||
(type_qualifier?)
|
(type_qualifier?)
|
||||||
|
{arrGrammar}
|
||||||
(identifier|type_identifier)
|
(identifier|type_identifier)
|
||||||
)
|
)
|
||||||
|
{arrGrammar}
|
||||||
(identifier|type_identifier)
|
(identifier|type_identifier)
|
||||||
)
|
)
|
||||||
|
{arrGrammar}
|
||||||
(abstract_pointer_declarator?
|
(abstract_pointer_declarator?
|
||||||
(abstract_pointer_declarator?)
|
(abstract_pointer_declarator?)
|
||||||
)
|
)
|
||||||
|
|
@ -77,20 +93,7 @@ proc initGrammar(): Grammar =
|
||||||
)
|
)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
arrGrammar = &"""
|
template funcParamCommon(fname, pname, ptyp, pptr, pout, count, i, flen: untyped): untyped =
|
||||||
(array_declarator!
|
|
||||||
(pointer_declarator!
|
|
||||||
(pointer_declarator!
|
|
||||||
(type_identifier)
|
|
||||||
)
|
|
||||||
(type_identifier)
|
|
||||||
)
|
|
||||||
(type_identifier)
|
|
||||||
(identifier|number_literal)
|
|
||||||
)
|
|
||||||
"""
|
|
||||||
|
|
||||||
template funcParamCommon(fname, pname, ptyp, pptr, pout, count, i: untyped): untyped =
|
|
||||||
ptyp = nimState.getIdentifier(nimState.data[i].val, nskType, fname).getType()
|
ptyp = nimState.getIdentifier(nimState.data[i].val, nskType, fname).getType()
|
||||||
|
|
||||||
pptr = ""
|
pptr = ""
|
||||||
|
|
@ -106,7 +109,14 @@ proc initGrammar(): Grammar =
|
||||||
count += 1
|
count += 1
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
if pptr.len != 0 or ptyp != "object":
|
if i < nimState.data.len and nimState.data[i].name in ["identifier", "number_literal"]:
|
||||||
|
flen = nimState.data[i].val
|
||||||
|
if nimState.data[i].name == "identifier":
|
||||||
|
flen = nimState.getIdentifier(flen, nskConst, fname)
|
||||||
|
|
||||||
|
pout &= &"{pname}: array[{flen}, {getPtrType(pptr&ptyp)}], "
|
||||||
|
i += 1
|
||||||
|
elif pptr.len != 0 or ptyp != "object":
|
||||||
pout &= &"{pname}: {getPtrType(pptr&ptyp)}, "
|
pout &= &"{pname}: {getPtrType(pptr&ptyp)}, "
|
||||||
|
|
||||||
# typedef int X
|
# typedef int X
|
||||||
|
|
@ -171,12 +181,13 @@ proc initGrammar(): Grammar =
|
||||||
fname = nname
|
fname = nname
|
||||||
pout, pname, ptyp, pptr = ""
|
pout, pname, ptyp, pptr = ""
|
||||||
count = 1
|
count = 1
|
||||||
|
flen = ""
|
||||||
|
|
||||||
while i < nimState.data.len:
|
while i < nimState.data.len:
|
||||||
if nimState.data[i].name == "function_declarator":
|
if nimState.data[i].name == "function_declarator":
|
||||||
break
|
break
|
||||||
|
|
||||||
funcParamCommon(fname, pname, ptyp, pptr, pout, count, i)
|
funcParamCommon(fname, pname, ptyp, pptr, pout, count, i, flen)
|
||||||
|
|
||||||
if pout.len != 0 and pout[^2 .. ^1] == ", ":
|
if pout.len != 0 and pout[^2 .. ^1] == ", ":
|
||||||
pout = pout[0 .. ^3]
|
pout = pout[0 .. ^3]
|
||||||
|
|
@ -277,6 +288,7 @@ proc initGrammar(): Grammar =
|
||||||
ftyp, fname: string
|
ftyp, fname: string
|
||||||
fptr = ""
|
fptr = ""
|
||||||
aptr = ""
|
aptr = ""
|
||||||
|
flen = ""
|
||||||
while i < nimState.data.len-fend:
|
while i < nimState.data.len-fend:
|
||||||
fptr = ""
|
fptr = ""
|
||||||
aptr = ""
|
aptr = ""
|
||||||
|
|
@ -323,7 +335,7 @@ proc initGrammar(): Grammar =
|
||||||
if nimState.data[i].name == "field_declaration":
|
if nimState.data[i].name == "field_declaration":
|
||||||
break
|
break
|
||||||
|
|
||||||
funcParamCommon(fname, pname, ptyp, pptr, pout, count, i)
|
funcParamCommon(fname, pname, ptyp, pptr, pout, count, i, flen)
|
||||||
|
|
||||||
if pout.len != 0 and pout[^2 .. ^1] == ", ":
|
if pout.len != 0 and pout[^2 .. ^1] == ", ":
|
||||||
pout = pout[0 .. ^3]
|
pout = pout[0 .. ^3]
|
||||||
|
|
@ -575,13 +587,14 @@ proc initGrammar(): Grammar =
|
||||||
fnname = nimState.getIdentifier(fname, nskProc)
|
fnname = nimState.getIdentifier(fname, nskProc)
|
||||||
pout, pname, ptyp, pptr = ""
|
pout, pname, ptyp, pptr = ""
|
||||||
count = 1
|
count = 1
|
||||||
|
flen = ""
|
||||||
|
|
||||||
i += 1
|
i += 1
|
||||||
while i < nimState.data.len:
|
while i < nimState.data.len:
|
||||||
if nimState.data[i].name == "function_declarator":
|
if nimState.data[i].name == "function_declarator":
|
||||||
break
|
break
|
||||||
|
|
||||||
funcParamCommon(fnname, pname, ptyp, pptr, pout, count, i)
|
funcParamCommon(fnname, pname, ptyp, pptr, pout, count, i, flen)
|
||||||
|
|
||||||
if pout.len != 0 and pout[^2 .. ^1] == ", ":
|
if pout.len != 0 and pout[^2 .. ^1] == ", ":
|
||||||
pout = pout[0 .. ^3]
|
pout = pout[0 .. ^3]
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,10 @@ void **test_call10(int **param1) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *test_array_param(int arr[5]) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
void multiline1(void) {}
|
void multiline1(void) {}
|
||||||
|
|
||||||
void *multiline2(void) {
|
void *multiline2(void) {
|
||||||
|
|
|
||||||
|
|
@ -119,6 +119,7 @@ int test_call_param7(union UNION1 param1);
|
||||||
float test_call_param8(int *param1);
|
float test_call_param8(int *param1);
|
||||||
void *test_call9();
|
void *test_call9();
|
||||||
void **test_call10(int **param1);
|
void **test_call10(int **param1);
|
||||||
|
char *test_array_param(int arr[5]);
|
||||||
|
|
||||||
// Issue #58
|
// Issue #58
|
||||||
void
|
void
|
||||||
|
|
|
||||||
|
|
@ -178,3 +178,8 @@ check TDEFL_OUT_BUF_SIZE == 85196
|
||||||
check TDEFL_BOGUS_1 == 2
|
check TDEFL_BOGUS_1 == 2
|
||||||
check TDEFL_BOGUS_2 == 1024
|
check TDEFL_BOGUS_2 == 1024
|
||||||
check TDEFL_BOGUS_3 == (85196 / 2).int
|
check TDEFL_BOGUS_3 == (85196 / 2).int
|
||||||
|
|
||||||
|
var
|
||||||
|
arr: array[5, cint]
|
||||||
|
|
||||||
|
check test_array_param(arr) == nil
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue