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).
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.
This is a failed attempt at two things:
clang_getCursorSpelling
orclang_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 thestruct
keyword instead of the actual name. But this feels a bit ugly. Neitherclang_Type_isTransparentTagTypedef
norclang_Cursor_isAnonymous
seems to help here; since the docs of the former refer toNS_ENUM
, perhaps that is an Objective C thing; the latter refers to structs that are truly anonymous (seeexamples/anonymous.h
for an example).Distinguish between the definition of a struct, and its reference in a typedef, for example as in
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 useclang_isCursorDefinition
to distinguish between these two cases, but it seems to reportTrue
for absolutely everything.