well-typed / hs-bindgen

Automatically generate Haskell bindings from C header files
20 stars 0 forks source link

More libclang bindings #118

Closed edsko closed 2 months ago

edsko commented 2 months ago

This is a failed attempt at two things:

  1. Distinguish between the tag of a struct (which may be absent) and the name of the surrounding typedef. In llvm18 the struct tag (at least when using clang_getCursorSpelling or clang_getCursorDisplayName) is set to the name of the surrounding typedef, which is causing some compatibility trouble against different llvm vesions (https://github.com/well-typed/hs-bindgen/pull/110#issuecomment-2306844665). So far the only way that I've found to figure out if this name is a "fake" name is by asking for the source location, then looking up that source location in the file, and looking at what's there; for "fake" names, the source location will point to the struct keyword instead of the actual name. But this feels a bit ugly. Neither clang_Type_isTransparentTagTypedef nor clang_Cursor_isAnonymous seems to help here; since the docs of the former refer to NS_ENUM, perhaps that is an Objective C thing; the latter refers to structs that are truly anonymous (see examples/anonymous.h for an example).
  2. Distinguish between the definition of a struct, and its reference in a typedef, for example as in

    typedef struct {
        char a;
    } S3_t;

    When we fold over this AST, we see this struct definition twice; first as a standalone thing, and then repeated inside the body of the typedef. I was hoping that we'd be able to use clang_isCursorDefinition to distinguish between these two cases, but it seems to report True for absolutely everything.