aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--nimterop/ast2.nim30
-rw-r--r--tests/include/tast2.h10
-rw-r--r--tests/tast2.nim12
3 files changed, 44 insertions, 8 deletions
diff --git a/nimterop/ast2.nim b/nimterop/ast2.nim
index 7a4b70a..a9624ac 100644
--- a/nimterop/ast2.nim
+++ b/nimterop/ast2.nim
@@ -460,11 +460,18 @@ proc newPtrTree(nimState: NimState, count: int, typ: PNode): PNode =
parent.add result
result = nresult
-proc newArrayTree(nimState: NimState, node: TSNode, typ, size: PNode): PNode =
+proc newArrayTree(nimState: NimState, node: TSNode, typ, size: PNode = nil): PNode =
# Create nkBracketExpr tree depending on input
+ #
+ # If `size` is nil, create UncheckedArray[typ]
let
info = nimState.getLineInfo(node.getAtom())
- ident = nimState.getIdent("array", info, exported = false)
+ tname =
+ if size.isNil:
+ "UncheckedArray"
+ else:
+ "array"
+ ident = nimState.getIdent(tname, info, exported = false)
# array[size, typ]
#
@@ -475,7 +482,8 @@ proc newArrayTree(nimState: NimState, node: TSNode, typ, size: PNode): PNode =
# )
result = newNode(nkBracketExpr)
result.add ident
- result.add size
+ if not size.isNil:
+ result.add size
result.add typ
proc getTypeArray(nimState: NimState, node, tnode: TSNode, name: string): PNode
@@ -906,11 +914,17 @@ proc getTypeArray(nimState: NimState, node, tnode: TSNode, name: string): PNode
result = nimState.newPtrTree(tcount, result)
for i in 0 ..< acount:
- let
- # Size of array could be a Nim expression
- size = nimState.getLit(nimState.getNodeVal(cnode[1]), expression = true)
- if size.kind != nkNilLit:
- result = nimState.newArrayTree(cnode, result, size)
+ if cnode.len == 2:
+ # type name[X] => array[X, type]
+ let
+ # Size of array could be a Nim expression
+ size = nimState.getLit(nimState.getNodeVal(cnode[1]), expression = true)
+ if size.kind != nkNilLit:
+ result = nimState.newArrayTree(cnode, result, size)
+ cnode = cnode[0]
+ elif cnode.len == 1:
+ # type name[] = UncheckedArray[type]
+ result = nimState.newArrayTree(cnode, result)
cnode = cnode[0]
if ncount > 0:
diff --git a/tests/include/tast2.h b/tests/include/tast2.h
index 348e225..a819f5e 100644
--- a/tests/include/tast2.h
+++ b/tests/include/tast2.h
@@ -133,6 +133,16 @@ void
int sqlite3_bind_blob(struct A1*, int, const void*, int n, void(*)(void*));
+// Issue #174 - type name[] => UncheckedArray[type]
+int ucArrFunc1(int text[]);
+int ucArrFunc2(int text[][5], int (*func)(int text[]));
+
+typedef int ucArrType1[][5];
+struct ucArrType2 {
+ float f1[5][5];
+ int *f2[][5];
+};
+
diff --git a/tests/tast2.nim b/tests/tast2.nim
index d1b0f26..f2816eb 100644
--- a/tests/tast2.nim
+++ b/tests/tast2.nim
@@ -335,3 +335,15 @@ 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.}
+
+# Issue #174 - type name[] => UncheckedArray[type]
+assert ucArrFunc1 is proc(text: UncheckedArray[cint]): cint {.cdecl.}
+assert ucArrFunc2 is
+ proc(text: UncheckedArray[array[5, cint]], `func`: proc(text: UncheckedArray[cint]): cint {.cdecl.}): cint {.cdecl.}
+
+assert ucArrType1 is UncheckedArray[array[5, cint]]
+checkPragmas(ucArrType1, pHeaderImp)
+
+assert ucArrType2 is object
+testFields(ucArrType2, "f1|f2:array[5, array[5, cfloat]]|UncheckedArray[array[5, ptr cint]]")
+checkPragmas(ucArrType2, pHeaderBy, istype = false)