dearimgui / dear_bindings

C header (and language binding metadata) generator for Dear ImGui
MIT License
221 stars 12 forks source link

Output is missing fields from conditional groups #28

Closed paralaxsd closed 1 year ago

paralaxsd commented 1 year ago

Hi, I found that for recent commits of dear_bindings, generated .json files will miss field entries that are enclosed in conditional groups. One example for that is the following excerpt from the ImGuiIO struct (v1.89.1):

#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
    void*       ImeWindowHandle;                // = NULL           // [Obsolete] Set ImGuiViewport::PlatformHandleRaw instead. Set this to your HWND to get automatic IME cursor positioning.
#else
    void*       _UnusedPadding;                                     // Unused field to keep data structure the same size.
#endif

The json output of dearbindings is now missing the corresponding metadata:

{
    "names": [
        {
            "name": "ImeWindowHandle",
            "is_array": false
        }
    ],
    "type": {
        "declaration": "void*"
    },
    "comments": {
        "attached": "// = NULL           // [Obsolete] Set ImGuiViewport::PlatformHandleRaw instead. Set this to your HWND to get automatic IME cursor positioning."
    },
    "conditionals": [
        {
            "condition": "ifndef",
            "expression": "IMGUI_DISABLE_OBSOLETE_FUNCTIONS"
        }
    ]
},
{
    "names": [
        {
            "name": "_UnusedPadding",
            "is_array": false
        }
    ],
    "type": {
        "declaration": "void*"
    },
    "comments": {
        "attached": "// Unused field to keep data structure the same size."
    },
    "conditionals": [
        {
            "condition": "ifdef",
            "expression": "IMGUI_DISABLE_OBSOLETE_FUNCTIONS"
        }
    ]
},

I bisected the issue and found that it is first introduced at feef033. I hope that helps! :)

ShironekoBen commented 1 year ago

Very well spotted! Sorry, yeah - I forgot about that case when fixing another bug where struct field lists incorrectly included fields from nested types, and the resulting code was overenthusiastic about not including anything it didn't think was a direct child of the struct being emitted.

Thanks very much for tracking that down - should hopefully be fixed now!

paralaxsd commented 1 year ago

Perfect, can confirm that this fixes the regression. Thanks for the super quick fix!