nim-lang / c2nim

c2nim is a tool to translate Ansi C code to Nim. The output is human-readable Nim code that is meant to be tweaked by hand before and after the translation process.
MIT License
497 stars 63 forks source link

Both sides ignored in `#ifdef __cplusplus ... #else ... #endif` #185

Open snej opened 4 years ago

snej commented 4 years ago

c2nim skips both sides of an #ifdef __cplusplus ... #else ... #endif block, i.e. it parses neither the lines after #ifdef nor the lines after the #else. I'd expect it to parse the first set of lines if I used the --cpp flag, otherwise the second set.

Example

#ifdef __cplusplus
    typedef bool BAR;
#else
    typedef int BAR;
#endif

Expected result

The output file includes either type BAR = int, or type BAR = bool if I gave the --cpp flag.

Actual result

There is no declaration of BAR at all.

snej commented 4 years ago

Adding #assumendef __cplusplus to my .c2nim file doesn't help (has no effect.)

snej commented 4 years ago

The same bug occurs with input:

#ifdef __cplusplus
    typedef bool BAR;
#endif

#ifndef __cplusplus
    typedef int BAR;
#endif

Again, neither is parsed.

Araq commented 4 years ago

Irrc __cplusplus is special cased in c2nim, please create a PR.