Skip to content

Commit

Permalink
fix anonymous
Browse files Browse the repository at this point in the history
Signed-off-by: Pantelis Antoniou <[email protected]>
  • Loading branch information
pantoniou committed Jan 2, 2025
1 parent 4a17f9d commit 0e59687
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
31 changes: 25 additions & 6 deletions src/reflection/fy-clang-backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ clang_register_type(struct fy_reflection *rfl, struct fy_decl *decl, CXCursor cu
CXType type;
enum fy_type_kind type_kind;
const char *type_name;
const char *s;
bool elaborated, anonymous;
int ret;

Expand All @@ -344,7 +345,7 @@ clang_register_type(struct fy_reflection *rfl, struct fy_decl *decl, CXCursor cu
type = clang_Type_getNamedType(type);

/* we don't want to register a declaration of an elaborated type */
decl = NULL;
// decl = NULL;
elaborated = true;
}

Expand All @@ -366,6 +367,11 @@ clang_register_type(struct fy_reflection *rfl, struct fy_decl *decl, CXCursor cu
type_name = clang_str_get_alloca(clang_getCursorUSR(cursor));
}

/* fixup unnamed types of the form struct|union|... (unamed */
s = strstr(type_name, " (unnamed at");
if (s)
type_name = s + 1;

memset(ftu, 0, sizeof(*ftu));
ftu->type = type;

Expand All @@ -389,11 +395,16 @@ clang_register_type(struct fy_reflection *rfl, struct fy_decl *decl, CXCursor cu

/* base type match found, try to append unique type info wrapper */
if (ft) {
fprintf(stderr, "%s: %s:%d appending type '%s':%s\n", __func__, __FILE__, __LINE__, type_name, decl ? fy_decl_get_yaml_comment(decl) : "<NULL>");
ret = fy_type_append_unique(ft, decl, ftu);
if (ret) {
fprintf(stderr, "%s: fy_type_append_unique() failed for type_name=%s\n", __func__, type_name);
goto err_out;
if (elaborated) {
fprintf(stderr, "%s: do not append elaborated type_name=%s\n", __func__, type_name);

} else {
fprintf(stderr, "%s: %s:%d appending type '%s':%s\n", __func__, __FILE__, __LINE__, type_name, decl ? fy_decl_get_yaml_comment(decl) : "<NULL>");
ret = fy_type_append_unique(ft, decl, ftu);
if (ret) {
fprintf(stderr, "%s: fy_type_append_unique() failed for type_name=%s\n", __func__, type_name);
goto err_out;
}
}

} else {
Expand Down Expand Up @@ -432,6 +443,7 @@ fy_import_backend_root_visitor(CXCursor cursor, CXCursor parent, CXClientData cl
enum CXCursorKind cursor_kind;
const char *cursor_spelling;
const char *cursor_kind_spelling;
const char *s;
struct fy_decl *decl = NULL;
unsigned int ret;
bool visit_children;
Expand Down Expand Up @@ -483,6 +495,12 @@ fy_import_backend_root_visitor(CXCursor cursor, CXCursor parent, CXClientData cl
#endif

cursor_spelling = clang_str_get_alloca(clang_getCursorSpelling(cursor));

/* fixup unnamed types of the form struct|union|... (unamed */
s = strstr(cursor_spelling, " (unnamed at");
if (s)
cursor_spelling = s + 1;

cursor_kind_spelling = clang_str_get_alloca(clang_getCursorKindSpelling(cursor_kind));
(void)cursor_kind_spelling;

Expand Down Expand Up @@ -946,6 +964,7 @@ static int clang_decl_setup(struct fy_decl *decl, void *user)
declb->typedef_info.underlying.cursor = clang_getTypeDeclaration(declb->typedef_info.underlying.type);
clang_str_setup(&declb->typedef_info.underlying.type_kind_spelling, clang_getTypeKindSpelling(declb->typedef_info.underlying.type.kind));
clang_str_setup(&declb->typedef_info.underlying.type_spelling, clang_getTypeSpelling(declb->typedef_info.underlying.type));
break;

case FYDT_STRUCT:
case FYDT_UNION:
Expand Down
5 changes: 4 additions & 1 deletion src/reflection/fy-reflection.c
Original file line number Diff line number Diff line change
Expand Up @@ -527,10 +527,12 @@ struct fy_type_info_wrapper *fy_type_get_info_wrapper(struct fy_type *ft, struct
{
struct fy_type_info_wrapper *tiw;
const char *c1, *c2;
bool is_primitive;

if (!ft)
return NULL;

is_primitive = fy_type_kind_is_primitive(ft->type_kind);
c1 = decl ? fy_decl_get_yaml_comment(decl) : NULL;

for (tiw = fy_type_info_wrapper_list_head(&ft->typeinfos);
Expand All @@ -539,7 +541,8 @@ struct fy_type_info_wrapper *fy_type_get_info_wrapper(struct fy_type *ft, struct

c2 = tiw->decl ? fy_decl_get_yaml_comment(tiw->decl) : NULL;

if (tiw->decl == decl || (!c1 && !c2) || (c1 && c2 && !strcmp(c1, c2)))
/* non primitives (i.e. typedefs, structs etc, don't differentiate */
if (!is_primitive || tiw->decl == decl || (!c1 && !c2) || (c1 && c2 && !strcmp(c1, c2)))
break;
}

Expand Down
2 changes: 1 addition & 1 deletion src/tool/fy-tool.c
Original file line number Diff line number Diff line change
Expand Up @@ -5867,7 +5867,7 @@ reflection_setup_type_specialize_one(struct reflection_type_data *rtd)

return 0;
err_out:
fprintf(stderr, "\e[31%s: error\e[0m\n", __func__);
fprintf(stderr, "\e[31m%s: error\e[0m\n", __func__);
return -1;
}

Expand Down

0 comments on commit 0e59687

Please sign in to comment.