Fix #185 - forward decl symbol change

This commit is contained in:
Ganesh Viswanathan 2020-04-13 10:18:49 -05:00
commit f23d17d0b2
3 changed files with 36 additions and 7 deletions

View file

@ -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

View file

@ -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

View file

@ -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)
checkPragmas(GPU_Target, pHeaderBy, istype = false)
# Issue #185
assert AudioCVT is object
testFields(AudioCVT, "needed!cint")
checkPragmas(AudioCVT, pHeaderBy, istype = false, "SDL_")