PMunch / futhark

Automatic wrapping of C headers in Nim
MIT License
374 stars 20 forks source link

Alias ignored when casting #57

Open arkanoid87 opened 1 year ago

arkanoid87 commented 1 year ago

Adding this test

talias.h

#define SCARD_S_SUCCESS                 ((long)0x00000000)

talias.nim

doAssert SCARD_S_SUCCESS == 0

results in

futhark/tests/talias.nim(26, 6) Error: undeclared identifier: 'SCARD_S_SUCCESS'

I've faced this problem while trying to wrap this

PMunch commented 1 year ago

Ah, the notorious C defines. This is essentially caused by macros being a pre-processor thing and as such they don't have a representation in the Clang translation unit output. So Øpir resorts to just parsing the value itself: https://github.com/PMunch/futhark/blob/master/src/opir.nim#L323-L368. So to fix this it's just a matter of improving the capabilities of that parser to support casting to long.