Skip to content

Commit

Permalink
wip unions
Browse files Browse the repository at this point in the history
Signed-off-by: Pantelis Antoniou <[email protected]>
  • Loading branch information
pantoniou committed Jan 17, 2025
1 parent c8ea36f commit 4dc5eec
Show file tree
Hide file tree
Showing 2 changed files with 249 additions and 43 deletions.
77 changes: 77 additions & 0 deletions src/reflection/fy-reflection.c
Original file line number Diff line number Diff line change
Expand Up @@ -2871,3 +2871,80 @@ fy_type_info_get_id(const struct fy_type_info *ti)
ft = fy_type_from_info(ti);
return ft ? ft->id : -1;
}

#if 0
struct fy_type_stack {
int top;
int alloc;
struct fy_type **fts;
};

static inline void
fy_type_stack_setup(struct fy_type_stack *fts)
{
if (!fts)
return;
memset(fts, 0, sizeof(*fts));
}

static inline void
fy_type_stack_cleanup(struct fy_type_stack *fts)
{
if (!fts)
return;

if (fts->fts)
free(fts->fts);
}

static inline struct type *
fy_type_stack_pop(struct fy_type_stack *fts)
{
if (!fts || fts->top <= 0)
return NULL;

return fts->fts[--fts->top];
}

static inline int
fy_type_stack_push(struct fy_type_stack *fts, struct type *rtd)
{
int new_alloc;
struct type **new_rtds;

if (!fts || !rtd)
return -1;

/* add */
if (fts->top >= fts->alloc) {
new_alloc = fts->alloc * 2;
if (!new_alloc)
new_alloc = 16;
if (new_alloc < 0) /* overflow */
return -1;
new_rtds = realloc(fts->fts, sizeof(*fts->fts) * new_alloc);
if (!new_rtds)
return -1;
fts->fts = new_rtds;
fts->alloc = new_alloc;
}
fts->fts[fts->top++] = rtd;
return 0;
}

static inline struct fy_type *
fy_type_stack_find(struct fy_type_stack *fts, const struct fy_type *ft)
{
struct type *rtd;
int i;

if (!fts || !ft)
return NULL;

for (i = 0; i < fts->top; i++) {
if (fts->fts[i] == ft)
return fts->fts[i];
}
return NULL;
}
#endif
Loading

0 comments on commit 4dc5eec

Please sign in to comment.