aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoey Yakimowich-Payne <jyapayne@gmail.com>2020-05-13 17:29:26 -0600
committergenotrance <dev@genotrance.com>2020-05-15 11:20:00 -0500
commit9895303578c5313a775b9226d051dfe63905495a (patch)
tree0c537b239f538c8216d8bae508d192fcbb4769db
parented26911436a2107d287a8f1d4f4df7727d6de53d (diff)
downloadnimterop-9895303578c5313a775b9226d051dfe63905495a.tar.gz
nimterop-9895303578c5313a775b9226d051dfe63905495a.zip
Make undefined constants keep types
-rw-r--r--nimterop/ast2.nim29
-rw-r--r--nimterop/toast.nim2
-rw-r--r--tests/include/tast2.h12
-rw-r--r--tests/tast2.nim6
4 files changed, 22 insertions, 27 deletions
diff --git a/nimterop/ast2.nim b/nimterop/ast2.nim
index 574870f..3b708b5 100644
--- a/nimterop/ast2.nim
+++ b/nimterop/ast2.nim
@@ -574,11 +574,8 @@ iterator newIdentDefs(gState: State, name: string, node: TSNode, offset: SomeInt
pident = gState.getIdent(pname, pinfo, exported)
result.add pident
let tyArray = gState.getTypeArray(node[i], tident, name)
- if tyArray.kind != nkNone:
- result.add tyArray
- result.add newNode(nkEmpty)
- else:
- result = nil
+ result.add tyArray
+ result.add newNode(nkEmpty)
else:
result = nil
@@ -953,14 +950,16 @@ proc getTypeArray(gState: State, node: TSNode, tident: PNode, name: string): PNo
for i in 0 ..< acount:
if cnode.len == 2:
# type name[X] => array[X, type]
- let
- # Size of array could be a Nim expression
- size = gState.parseCExpression(gState.getNodeVal(cnode[1]))
- if size.kind != nkNone:
- result = gState.newArrayTree(cnode, result, size)
- cnode = cnode[0]
- else:
- result = newNode(nkNone)
+ var size: PNode
+ let cnodeVal = gState.getNodeVal(cnode[1])
+ # Size of array could be a Nim expression
+ size = gState.parseCExpression(cnodeVal)
+ if size.kind == nkNone:
+ # If the size could not be parsed, leave it alone
+ size = gState.getIdent(cnodeVal)
+
+ result = gState.newArrayTree(cnode, result, size)
+ cnode = cnode[0]
elif cnode.len == 1:
# type name[] = UncheckedArray[type]
result = gState.newArrayTree(cnode, result)
@@ -991,10 +990,6 @@ 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/nimterop/toast.nim b/nimterop/toast.nim
index b1f910c..f54aa67 100644
--- a/nimterop/toast.nim
+++ b/nimterop/toast.nim
@@ -4,6 +4,8 @@ import "."/treesitter/[api, c, cpp]
import "."/[ast, ast2, build, globals, getters, grammar, tshelp]
+{.passC: "-DNIMTEROP".}
+
proc process(gState: State, path: string, astTable: AstTable) =
doAssert existsFile(path), &"Invalid path {path}"
diff --git a/tests/include/tast2.h b/tests/include/tast2.h
index 57c060e..b8433f9 100644
--- a/tests/include/tast2.h
+++ b/tests/include/tast2.h
@@ -42,17 +42,16 @@ extern "C" {
#define REG_STR "regular string"
#define NOTSUPPORTEDSTR "not a " REG_STR
-#define NULLCHAR '\0'/* comments should not break things*/
-#define OCTCHAR '\012' // nor should this comment
+#define NULLCHAR '\0'
+#define OCTCHAR '\012'
#define HEXCHAR '\xFE'
#define TRICKYSTR "\x4E\034\nfoo\0\'\"\r\v\a\b\e\f\t\\\?bar"
#define ALLSHL (SHL1 | SHL2 | SHL3)
-// disable for windows for now
-#ifndef _WIN32
-// const not supported yet
-const int SOME_CONST = 8;
+#ifdef NIMTEROP
+#define SOME_CONST 8
+#endif
struct some_struct_s
{
@@ -65,7 +64,6 @@ struct parent_struct_s
};
typedef struct some_struct_s SOME_ARRAY[SOME_CONST];
-#endif
struct A0;
struct A1 {};
diff --git a/tests/tast2.nim b/tests/tast2.nim
index f132609..8deb99e 100644
--- a/tests/tast2.nim
+++ b/tests/tast2.nim
@@ -35,6 +35,7 @@ cOverride:
type
A1* = A0
+cDefine("SOME_CONST=100")
cImport(path, flags="-f:ast2 -ENK_,SDL_ -GVICE=SLICE -TMyInt=cint" & flags)
proc getPragmas(n: NimNode): HashSet[string] =
@@ -155,9 +156,8 @@ assert typeof(POINTERPOINTERPOINTEREXPR) is (ptr ptr ptr cint)
assert ALLSHL == (SHL1 or SHL2 or SHL3)
-when not defined(windows):
- assert not compiles(parent_struct_s().s)
- assert not defined(SOME_ARRAY)
+assert typeof(parent_struct_s().s) is array[100, some_struct_s]
+assert typeof(SOME_ARRAY) is array[100, some_struct_s]
assert A0 is object
testFields(A0, "f1!cint")