Skip to content

Commit

Permalink
streamline type info
Browse files Browse the repository at this point in the history
Signed-off-by: Pantelis Antoniou <[email protected]>
  • Loading branch information
pantoniou committed Jan 16, 2025
1 parent d7a58d1 commit c8ea36f
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 109 deletions.
10 changes: 6 additions & 4 deletions src/reflection/fy-clang-backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,8 @@ fy_import_backend_root_visitor(CXCursor cursor, CXCursor parent, CXClientData cl

decl->type = ft;

ret = fy_type_append_unique(ft, decl);
ft->decl = decl;
ret = fy_type_create_info(ft);
if (ret)
goto err_out;

Expand Down Expand Up @@ -922,7 +923,8 @@ clang_create_single_primitive_type(struct fy_import *imp, CXType type)

ft->is_synthetic = true;

ret = fy_type_append_unique(ft, decl);
ft->decl = decl;
ret = fy_type_create_info(ft);
if (ret)
goto err_out;

Expand Down Expand Up @@ -1454,7 +1456,7 @@ static void clang_type_resolve(struct fy_type *ft_new)
tiwn = udep->tiw;

ti = &tiwn->type_info;
ft = tiwn->ft;
ft = fy_type_from_info_wrapper(tiwn);

assert(!ti->dependent_type);

Expand Down Expand Up @@ -1510,7 +1512,7 @@ static int clang_import_done(struct fy_import *imp)

tiwn = udep->tiw;
ti = &tiwn->type_info;
ft = tiwn->ft;
ft = fy_type_from_info_wrapper(tiwn);

ftb = ft->backend;
if (!ftb || ft->type_kind != FYTK_PTR)
Expand Down
14 changes: 10 additions & 4 deletions src/reflection/fy-packed-backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -379,9 +379,12 @@ static int packed_do_import(struct fy_import *imp)
free(type_name);
if (!ft)
goto err_out;
ret = fy_type_append_unique(ft, decl);

ft->decl = decl;
ret = fy_type_create_info(ft);
if (ret)
goto err_out;

fy_type_list_add_tail(&rfl->types, ft);

decl->type = ft;
Expand Down Expand Up @@ -419,9 +422,12 @@ static int packed_do_import(struct fy_import *imp)
free(type_name);
if (!ft)
goto err_out;
ret = fy_type_append_unique(ft, decl);

ft->decl = decl;
ret = fy_type_create_info(ft);
if (ret)
goto err_out;

fy_type_list_add_tail(&rfl->types, ft);

decl->type = ft;
Expand Down Expand Up @@ -792,7 +798,7 @@ static void type_generate_one_fp(struct fy_packed_generator *pg, struct fy_type
ft->id,
fy_type_kind_info_get_internal(ft->type_kind)->enum_name);

decl = fy_type_first_decl(ft);
decl = ft->decl;
if (decl)
fprintf(fp, ".decl.id = %d, ", decl->id);

Expand Down Expand Up @@ -906,7 +912,7 @@ static void type_generate_one_blob(struct fy_packed_generator *pg, struct fy_typ
struct fy_decl *decl;
uint8_t flags;

decl = fy_type_first_decl(ft);
decl = ft->decl;

br_w8(&bw->Tr, (uint8_t)ft->type_kind);
flags = 0;
Expand Down
32 changes: 12 additions & 20 deletions src/reflection/fy-reflection-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,12 @@ static inline const struct fy_type_kind_info *fy_type_kind_info_get_internal(enu
FY_TYPE_FWD_DECL_LIST(type_info_wrapper);
struct fy_type_info_wrapper {
struct list_head node;
struct fy_type *ft;
struct fy_decl *decl;
struct fy_type_info type_info;
struct fy_decl **field_decls;
struct fy_field_info *fields;
};
FY_TYPE_DECL_LIST(type_info_wrapper);

enum fy_unresolved_dep_type {
FYUDT_DEPENDENT_TYPE,
FYUDT_FIELD_TYPE,
};

FY_TYPE_FWD_DECL_LIST(unresolved_dep);
struct fy_unresolved_dep {
struct list_head node;
Expand All @@ -76,6 +70,7 @@ struct fy_type {
char *fullname; /* including the prefix i.e. struct */
const char *name; /* points in full name */
char *normalized_name;
struct fy_decl *decl;

size_t size;
size_t align;
Expand All @@ -98,12 +93,6 @@ struct fy_type {
};
FY_TYPE_DECL_LIST(type);

static inline struct fy_decl *
fy_type_first_decl(struct fy_type *ft)
{
return ft ? ft->tiw.decl : NULL;
}

static inline struct fy_type_info_wrapper *
fy_type_info_wrapper_from_info(const struct fy_type_info *ti)
{
Expand All @@ -113,14 +102,17 @@ fy_type_info_wrapper_from_info(const struct fy_type_info *ti)
}

static inline struct fy_type *
fy_type_from_info(const struct fy_type_info *ti)
fy_type_from_info_wrapper(struct fy_type_info_wrapper *tiw)
{
struct fy_type_info_wrapper *tiw;

tiw = fy_type_info_wrapper_from_info(ti);
if (!tiw)
return NULL;
return tiw->ft;
return container_of(tiw, struct fy_type, tiw);
}

static inline struct fy_type *
fy_type_from_info(const struct fy_type_info *ti)
{
return fy_type_from_info_wrapper(fy_type_info_wrapper_from_info(ti));
}

FY_TYPE_FWD_DECL_LIST(source_file);
Expand Down Expand Up @@ -306,7 +298,7 @@ struct fy_reflection {

struct fy_type *fy_type_create(struct fy_reflection *rfl, enum fy_type_kind type_kind, const char *name, struct fy_decl *decl, void *user);
struct fy_type_info_wrapper *fy_type_get_info_wrapper(struct fy_type *ft, struct fy_decl *decl);
int fy_type_append_unique(struct fy_type *ft, struct fy_decl *decl);
int fy_type_create_info(struct fy_type *ft);
void fy_type_destroy(struct fy_type *ft);
struct fy_type *fy_type_create_ptr_dep(struct fy_type *ft); /* for final reference resolution */

Expand Down Expand Up @@ -374,7 +366,7 @@ static inline bool fy_type_is_anonymous(const struct fy_type *ft)

static inline bool fy_type_is_declared(struct fy_type *ft)
{
return ft && !!fy_type_first_decl(ft);
return ft && ft->decl;
}

static inline bool fy_type_is_resolved(struct fy_type *ft)
Expand Down
Loading

0 comments on commit c8ea36f

Please sign in to comment.