Skip to content

Commit

Permalink
refs
Browse files Browse the repository at this point in the history
Signed-off-by: Pantelis Antoniou <pantelis.antoniou@konsulko.com>
  • Loading branch information
pantoniou committed Jan 10, 2025
1 parent 457527d commit d38b5b9
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 50 deletions.
32 changes: 20 additions & 12 deletions src/reflection/fy-clang-backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -846,9 +846,10 @@ clang_create_primitive_types(struct fy_import *imp, CXType type)
struct fy_type *ft = NULL;
struct clang_type_user ftu_local, *ftu = &ftu_local;
CXType orig_type, ttype, *types;
int i, pass, level, ret, res = 0;
int i, pass, level, ret;
const char *type_name;
enum fy_type_kind type_kind;
int created_count;

if (!imp)
return -1;
Expand All @@ -861,6 +862,7 @@ clang_create_primitive_types(struct fy_import *imp, CXType type)
if (ft || !clang_typeIsLikePtrOrPrimitive(type))
return 0;

created_count = 0;
orig_type = type;

/* collect all the types, including the final one */
Expand Down Expand Up @@ -954,19 +956,19 @@ clang_create_primitive_types(struct fy_import *imp, CXType type)

declf = NULL;
ft = NULL;

created_count++;
}

out:
return res;
return created_count;

err_out:
if (declf)
fy_decl_destroy(declf);
if (ft)
fy_type_destroy(ft);

res = -1;
goto out;
return -1;
}

static int
Expand Down Expand Up @@ -1006,7 +1008,7 @@ clang_field_visitor(CXCursor cursor, CXCursor parent, struct fy_decl *parent_dec
goto err_out;

ret = clang_create_primitive_types(imp, cd->type);
if (ret)
if (ret < 0)
goto err_out;

ft = clang_lookup_type_by_type(rfl, cd->type);
Expand All @@ -1028,13 +1030,19 @@ clang_field_visitor(CXCursor cursor, CXCursor parent, struct fy_decl *parent_dec
/* add to the parent */
fy_decl_list_add_tail(&parent_decl->children, decl);

ret = fy_type_append_unique(ft, decl, ftu);
if (ret) {
fprintf(stderr, "%s: fy_type_append_unique() failed for type_name=%s.%s\n", __func__,
cd->type_name, cd->cursor_spelling);
goto err_out;
}
if (fy_type_info_wrapper_list_empty(&ft->typeinfos)) {
fprintf(stderr, "%s: calling fy_type_append_unique() for type_name=%s field=%s.%s ft=%s/%p decl->type=%s/%p\n", __func__,
cd->type_name, parent_decl->name, cd->cursor_spelling,
ft->fullname, ft,
decl->type->fullname, decl->type);

ret = fy_type_append_unique(ft, decl, ftu);
if (ret) {
fprintf(stderr, "%s: fy_type_append_unique() failed for type_name=%s field=%s.%s\n", __func__,
cd->type_name, parent_decl->name, cd->cursor_spelling);
goto err_out;
}
}
res = 0;
out:
clang_release_cursor_data(cd);
Expand Down
3 changes: 2 additions & 1 deletion src/reflection/fy-reflection-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ fy_type_from_info(const struct fy_type_info *ti)
return tiw->ft;
}


FY_TYPE_FWD_DECL_LIST(source_file);
struct fy_source_file {
struct list_head node;
Expand Down Expand Up @@ -266,6 +265,8 @@ struct fy_decl {
size_t bit_width;
} bitfield_decl;
};

struct fy_field_info field_info;
};
FY_TYPE_DECL_LIST(decl);

Expand Down
14 changes: 12 additions & 2 deletions src/reflection/fy-reflection.c
Original file line number Diff line number Diff line change
Expand Up @@ -548,12 +548,14 @@ struct fy_type *fy_type_create(struct fy_reflection *rfl, enum fy_type_kind type
struct fy_type_info_wrapper *fy_type_get_info_wrapper(struct fy_type *ft, struct fy_decl *decl)
{
struct fy_type_info_wrapper *tiw;
const char *c1, *c2;
bool is_primitive;

if (!ft)
return NULL;

#if 0
const char *c1, *c2;
bool is_primitive;

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

Expand All @@ -567,6 +569,9 @@ struct fy_type_info_wrapper *fy_type_get_info_wrapper(struct fy_type *ft, struct
if (!is_primitive || tiw->decl == decl || (!c1 && !c2) || (c1 && c2 && !strcmp(c1, c2)))
break;
}
#endif

tiw = fy_type_info_wrapper_list_head(&ft->typeinfos);

return tiw;
}
Expand Down Expand Up @@ -655,6 +660,11 @@ int fy_type_append_unique(struct fy_type *ft, struct fy_decl *decl, void *user)
if (tiw)
return 0;

if (!fy_type_info_wrapper_list_empty(&ft->typeinfos))
*(char *)0 = 0;

assert(fy_type_info_wrapper_list_empty(&ft->typeinfos));

tiw = malloc(sizeof(*tiw));
if (!tiw)
return -1;
Expand Down
Loading

0 comments on commit d38b5b9

Please sign in to comment.