jacob-carlborg / dstep

A tool for converting C and Objective-C headers to D modules
204 stars 37 forks source link

Allow anonymous enum conversion #246

Open ahmetsait opened 4 years ago

ahmetsait commented 4 years ago
--generate-anonymous-enum=true    [default: false]

It seems like a valuable enchanment. Instead of generating a named enum:

enum hb_memory_mode_t
{
    HB_MEMORY_MODE_DUPLICATE = 0,
    HB_MEMORY_MODE_READONLY = 1,
    HB_MEMORY_MODE_WRITABLE = 2,
    HB_MEMORY_MODE_READONLY_MAY_MAKE_WRITABLE = 3
}

Which can get verbose to use and finding which enum contains the corresponding member from C code can be a problem: hb_memory_mode_t.HB_MEMORY_MODE_READONLY_MAY_MAKE_WRITABLE

We can instead generate an anonymous enum:

enum : int
{
    HB_MEMORY_MODE_DUPLICATE = 0,
    HB_MEMORY_MODE_READONLY = 1,
    HB_MEMORY_MODE_WRITABLE = 2,
    HB_MEMORY_MODE_READONLY_MAY_MAKE_WRITABLE = 3
}
alias hb_memory_mode_t = int;

I'm aware of --rename-enum-members=true but it is not recommended to rename symbol names in pure bindings so this seems to me like the best solution for preserving original names. There is also --alias-enum-members=true but aliasing every single enum member makes no sense to me aside from the type-safetyness but I think that's a job of a wrapper not binding. (Also it doesn't work properly right now)

Temtaime commented 4 years ago

+1 for proposed solution