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
509 stars 63 forks source link

ignore defines inside enums #205

Closed royneary closed 3 years ago

royneary commented 3 years ago

Some C libraries have the terrible practice of putting defines in their enum definitions, e.g. (from gnutls/x509.h):

typedef enum gnutls_trust_list_flags_t {
    GNUTLS_TL_VERIFY_CRL = 1,
#define GNUTLS_TL_VERIFY_CRL 1
    GNUTLS_TL_USE_IN_TLS = (1<<1),
#define GNUTLS_TL_USE_IN_TLS (1<<1)
    GNUTLS_TL_NO_DUPLICATES = (1<<2),
#define GNUTLS_TL_NO_DUPLICATES (1<<2)
    GNUTLS_TL_NO_DUPLICATE_KEY = (1<<3),
#define GNUTLS_TL_NO_DUPLICATE_KEY (1<<3)
    GNUTLS_TL_GET_COPY = (1<<4),
#define GNUTLS_TL_GET_COPY (1<<4)
    GNUTLS_TL_FAIL_ON_INVALID_CRL = (1<<5)
#define GNUTLS_TL_FAIL_ON_INVALID_CRL (1<<5)
} gnutls_trust_list_flags_t;

This PR makes c2nim ignore those defines (currently the error Error: identifier expected, but got: # is produced).