aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGanesh Viswanathan <dev@genotrance.com>2020-04-13 10:18:49 -0500
committerGanesh Viswanathan <dev@genotrance.com>2020-04-13 10:19:34 -0500
commit7925e31126085dd20c1be6472e81f8a6a14d2611 (patch)
treeb427568ab706faff0a65894d03b6da39bd993fbc
parent9cd39600d43c90045b0da6873900881449e6d609 (diff)
downloadnimterop-issue185.tar.gz
nimterop-issue185.zip
Fix #185 - forward decl symbol changeissue185
-rw-r--r--nimterop/ast2.nim11
-rw-r--r--tests/include/tast2.h16
-rw-r--r--tests/tast2.nim16
3 files changed, 36 insertions, 7 deletions
diff --git a/nimterop/ast2.nim b/nimterop/ast2.nim
index ed7c2a9..708b473 100644
--- a/nimterop/ast2.nim
+++ b/nimterop/ast2.nim
@@ -811,9 +811,16 @@ proc addTypeObject(nimState: NimState, node: TSNode, typeDef: PNode = nil, fname
if not fdlist.isNil and fdlist.len > 0:
# Current node has fields
let
- name = nimState.getNodeVal(node.getAtom())
+ origname = nimState.getNodeVal(node.getAtom())
- if nimState.identifierNodes.hasKey(name):
+ # Fix issue #185
+ name =
+ if origname.nBl:
+ nimState.getIdentifier(origname, nskType)
+ else:
+ ""
+
+ if name.nBl and nimState.identifierNodes.hasKey(name):
let
def = nimState.identifierNodes[name]
# Duplicate nkTypeDef for `name` with empty fields
diff --git a/tests/include/tast2.h b/tests/include/tast2.h
index 4854eb7..76aadc9 100644
--- a/tests/include/tast2.h
+++ b/tests/include/tast2.h
@@ -162,6 +162,14 @@ struct GPU_Target
char *x, y, **z;
};
+// Issue #185
+struct SDL_AudioCVT;
+
+typedef struct SDL_AudioCVT
+{
+ int needed;
+} SDL_AudioCVT;
+
// DUPLICATES
@@ -318,6 +326,14 @@ struct GPU_Target
char *x, y, **z;
};
+// Issue #185
+struct SDL_AudioCVT;
+
+typedef struct SDL_AudioCVT
+{
+ int needed;
+} SDL_AudioCVT;
+
#endif
diff --git a/tests/tast2.nim b/tests/tast2.nim
index de0e743..4741062 100644
--- a/tests/tast2.nim
+++ b/tests/tast2.nim
@@ -32,7 +32,7 @@ cOverride:
type
A1* = A0
-cImport(path, flags="-f:ast2 -ENK_" & flags)
+cImport(path, flags="-f:ast2 -ENK_,SDL_" & flags)
proc getPragmas(n: NimNode): HashSet[string] =
# Find all pragmas in AST, return as "name" or "name:value" in set
@@ -57,7 +57,8 @@ proc getRecList(n: NimNode): NimNode =
if not rl.isNil:
return rl
-macro checkPragmas(t: typed, pragmas: static[seq[string]], istype: static[bool] = true): untyped =
+macro checkPragmas(t: typed, pragmas: static[seq[string]], istype: static[bool] = true,
+ prefix: static[string] = ""): untyped =
# Verify that type has expected pragmas defined
# `istype` is true when typedef X
var
@@ -67,9 +68,9 @@ macro checkPragmas(t: typed, pragmas: static[seq[string]], istype: static[bool]
when defined(HEADER):
if not istype:
if "union" in exprag:
- exprag.incl "importc:union " & $t
+ exprag.incl "importc:union " & $prefix & $t
else:
- exprag.incl "importc:struct " & $t
+ exprag.incl "importc:struct " & $prefix & $t
doAssert symmetricDifference(prag, exprag).len == 0,
"\nWrong number of pragmas in " & $t & "\n" & $prag & " vs " & $exprag
@@ -361,4 +362,9 @@ checkPragmas(BASS_DEVICEINFO, pHeaderImpBy)
# Issue #183
assert GPU_Target is object
testFields(GPU_Target, "w|h|x|y|z!cint|ptr cint|cstring|cchar|ptr cstring")
-checkPragmas(GPU_Target, pHeaderBy, istype = false) \ No newline at end of file
+checkPragmas(GPU_Target, pHeaderBy, istype = false)
+
+# Issue #185
+assert AudioCVT is object
+testFields(AudioCVT, "needed!cint")
+checkPragmas(AudioCVT, pHeaderBy, istype = false, "SDL_") \ No newline at end of file