aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoey Yakimowich-Payne <jyapayne@gmail.com>2020-05-12 16:22:53 -0600
committergenotrance <dev@genotrance.com>2020-05-15 11:20:00 -0500
commit32c98435486cff69f7ecbcfb2be3c8f1739fe177 (patch)
tree62e0b0b528aa7631a970ce57fc4c64a0f3a3f54a
parentfc587fae037c0443cc1a2ca64685ba1d3b9d62d3 (diff)
downloadnimterop-32c98435486cff69f7ecbcfb2be3c8f1739fe177.tar.gz
nimterop-32c98435486cff69f7ecbcfb2be3c8f1739fe177.zip
Fix undefined identifiers resulting in incorrect types
-rw-r--r--nimterop/ast2.nim14
-rw-r--r--tests/include/tast2.h15
-rw-r--r--tests/tast2.nim3
3 files changed, 30 insertions, 2 deletions
diff --git a/nimterop/ast2.nim b/nimterop/ast2.nim
index 4a9b048..574870f 100644
--- a/nimterop/ast2.nim
+++ b/nimterop/ast2.nim
@@ -573,8 +573,12 @@ iterator newIdentDefs(gState: State, name: string, node: TSNode, offset: SomeInt
(pname, _, pinfo) = gState.getNameInfo(node[i].getAtom(), nskField, parent = name)
pident = gState.getIdent(pname, pinfo, exported)
result.add pident
- result.add gState.getTypeArray(node[i], tident, name)
- result.add newNode(nkEmpty)
+ let tyArray = gState.getTypeArray(node[i], tident, name)
+ if tyArray.kind != nkNone:
+ result.add tyArray
+ result.add newNode(nkEmpty)
+ else:
+ result = nil
else:
result = nil
@@ -955,6 +959,8 @@ proc getTypeArray(gState: State, node: TSNode, tident: PNode, name: string): PNo
if size.kind != nkNone:
result = gState.newArrayTree(cnode, result, size)
cnode = cnode[0]
+ else:
+ result = newNode(nkNone)
elif cnode.len == 1:
# type name[] = UncheckedArray[type]
result = gState.newArrayTree(cnode, result)
@@ -985,6 +991,10 @@ proc addTypeArray(gState: State, node: TSNode) =
name = typeDef.getIdentName()
typ = gState.getTypeArray(node[i], tident, name)
+ if typ.kind == nkNone:
+ gecho (&"{gState.getNodeVal(node)} skipped").getCommented()
+ continue
+
typeDef.add typ
# type X* = [ptr] array[x, [ptr] Y]
diff --git a/tests/include/tast2.h b/tests/include/tast2.h
index bbb3315..f28c003 100644
--- a/tests/include/tast2.h
+++ b/tests/include/tast2.h
@@ -49,6 +49,21 @@ extern "C" {
#define ALLSHL (SHL1 | SHL2 | SHL3)
+// const not supported yet
+const int SOME_CONST = 8;
+
+struct some_struct_s
+{
+ int x;
+};
+
+struct parent_struct_s
+{
+ struct some_struct_s s[SOME_CONST];
+};
+
+typedef struct some_struct_s SOME_ARRAY[SOME_CONST];
+
struct A0;
struct A1 {};
typedef struct A2;
diff --git a/tests/tast2.nim b/tests/tast2.nim
index 4fd16cc..058ad0b 100644
--- a/tests/tast2.nim
+++ b/tests/tast2.nim
@@ -155,6 +155,9 @@ assert typeof(POINTERPOINTERPOINTEREXPR) is (ptr ptr ptr cint)
assert ALLSHL == (SHL1 or SHL2 or SHL3)
+assert not compiles(parent_struct_s().s)
+assert not defined(SOME_ARRAY)
+
assert A0 is object
testFields(A0, "f1!cint")
checkPragmas(A0, pHeaderBy, istype = false)