diff --git a/src/reflection/fy-clang-backend.c b/src/reflection/fy-clang-backend.c index 2236e4ea..41fa9fce 100644 --- a/src/reflection/fy-clang-backend.c +++ b/src/reflection/fy-clang-backend.c @@ -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; @@ -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; } @@ -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; @@ -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) : ""); - 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) : ""); + 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 { @@ -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; @@ -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; @@ -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: diff --git a/src/reflection/fy-reflection.c b/src/reflection/fy-reflection.c index 94caa81a..dd5c3eef 100644 --- a/src/reflection/fy-reflection.c +++ b/src/reflection/fy-reflection.c @@ -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); @@ -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; } diff --git a/src/tool/fy-tool.c b/src/tool/fy-tool.c index 2fa41000..b779f1cb 100644 --- a/src/tool/fy-tool.c +++ b/src/tool/fy-tool.c @@ -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; }