Skip to content

Commit

Permalink
sanity is back
Browse files Browse the repository at this point in the history
Signed-off-by: Pantelis Antoniou <[email protected]>
  • Loading branch information
pantoniou committed Jan 13, 2025
1 parent 6364aeb commit 75655c1
Showing 1 changed file with 16 additions and 33 deletions.
49 changes: 16 additions & 33 deletions src/tool/fy-tool.c
Original file line number Diff line number Diff line change
Expand Up @@ -2169,7 +2169,7 @@ enum reflection_type_data_flags {

RTDF_PURITY_MASK = (RTDF_IMPURE | RTDF_PTR_PURE),

RTDF_RECURSIVE_COPY = FY_BIT(2),
RTDF_MUTATED = FY_BIT(2),
};

struct reflection_type_data {
Expand Down Expand Up @@ -5388,7 +5388,7 @@ void reflection_type_data_destroy(struct reflection_type_data *rtd)
if (!rtd)
return;

fprintf(stderr, A_BRIGHT_RED "%s: destroy %s" A_RESET "\n", __func__, rtd->ti->fullname);
fprintf(stderr, A_BRIGHT_RED "%s: destroy T#%d/%s" A_RESET "\n", __func__, rtd->idx, rtd->ti->fullname);

if (rtd->rtd_dep && !rtd->rtd_dep_recursive)
reflection_type_data_unref(rtd->rtd_dep);
Expand Down Expand Up @@ -5726,10 +5726,11 @@ void reflection_type_data_dump(struct reflection_type_data *rtd_root)
printf("#%d:'%s' r%d", rtd->idx, rtd->ti->fullname, rtd->refs);
// printf(" T#%d", fy_type_info_get_id(rtd->ti));

printf("%s%s%s",
printf("%s%s%s%s",
(rtd->flags & RTDF_PURITY_MASK) == 0 ? " PURE" : "",
(rtd->flags & RTDF_IMPURE) ? " IMPURE" : "",
(rtd->flags & RTDF_PTR_PURE) ? " PTR_PURE" : "");
(rtd->flags & RTDF_PTR_PURE) ? " PTR_PURE" : "",
(rtd->flags & RTDF_MUTATED) ? " MUTATED" : "");
if (rtd->rtd_dep)
printf(" dep: #%d:'%s'%s", rtd->rtd_dep->idx, rtd->rtd_dep->ti->fullname,
rtd->rtd_dep_recursive ? " (recursive)" : "");
Expand All @@ -5740,7 +5741,7 @@ void reflection_type_data_dump(struct reflection_type_data *rtd_root)
rfd = rtd->fields[j];
assert(rfd->rtd);
printf("\t#%d:'%s' %s", rfd->rtd->idx, rfd->rtd->ti->fullname, rfd->fi->name);
if (rfd->field_name)
if (strcmp(rfd->fi->name, rfd->field_name))
printf(" (%s)", rfd->field_name);
if (rfd->rtd_recursive)
printf(" (recursive)");
Expand Down Expand Up @@ -6142,6 +6143,7 @@ reflection_field_data_specialize(struct reflection_field_data *rfd)
if (counter || fyn_terminator || (rfd->rtd->rtd_dep && rfd->rtd->rtd_dep->ti->kind == FYTK_PTR)) {

rfd->rtd->ops = &dyn_array_ops;
rfd->rtd->flags |= RTDF_MUTATED;

if (counter) {
rfd_ref = reflection_type_data_lookup_field(rfd->rtd_parent, counter);
Expand Down Expand Up @@ -6243,11 +6245,13 @@ reflection_type_data_specialize(struct reflection_type_data *rtd)
case FYTK_CHAR:
/* char * -> text */
rtd->ops = &ptr_char_ops;
rtd->flags |= RTDF_MUTATED;
break;

case FYTK_VOID:
/* void * -> doc */
rtd->ops = &ptr_doc_ops;
rtd->flags |= RTDF_MUTATED;
break;

default:
Expand All @@ -6261,6 +6265,7 @@ reflection_type_data_specialize(struct reflection_type_data *rtd)
switch (rtd->ti->dependent_type->kind) {
case FYTK_CHAR:
rtd->ops = &constarray_char_ops;
rtd->flags |= RTDF_MUTATED;
break;

default:
Expand Down Expand Up @@ -6345,7 +6350,6 @@ int
reflection_setup_type(struct reflection_type_system *rts,
const struct fy_type_info *ti,
struct reflection_type_data_stack *rtds,
struct reflection_type_data_stack *rtds_created,
struct reflection_type_data **rtdp)
{
struct reflection_type_data *rtd = NULL, *rtd_dep, **rtd_depp;
Expand Down Expand Up @@ -6448,16 +6452,8 @@ reflection_setup_type(struct reflection_type_system *rts,
continue;
}

#if 0
rtd_dep = reflection_type_data_stack_find_by_type_info(rtds_created, ti_dep);
if (rtd_dep) {
*rtd_depp = reflection_type_data_ref(rtd_dep);
continue;
}
#endif

/* create now */
rc = reflection_setup_type(rts, ti_dep, rtds, rtds_created, rtd_depp);
rc = reflection_setup_type(rts, ti_dep, rtds, rtd_depp);
if (rc) {
fprintf(stderr, A_RED "%s %s:%d goto err_out;" A_RESET "\n", __func__, __FILE__, __LINE__);
goto err_out;
Expand Down Expand Up @@ -6504,13 +6500,6 @@ reflection_setup_type(struct reflection_type_system *rts,
/* and remove it from the setup stack */
(void)reflection_type_data_stack_pop(rtds);

/* add to the created list */
rc = reflection_type_data_stack_push(rtds_created, rtd);
if (rc) {
fprintf(stderr, A_RED "%s %s:%d goto err_out;" A_RESET "\n", __func__, __FILE__, __LINE__);
goto err_out;
}

// fprintf(stderr, "%s: ti->fullname='%s' T#%d OK\n", __func__, ti->fullname, rtd->idx);

return 0;
Expand Down Expand Up @@ -6542,18 +6531,14 @@ reflection_type_data_simplify(struct reflection_type_data *rtd_root)
/* skip over the deleted ones */
if (rtd1 == (void *)(uintptr_t)-1)
continue;

rtdsp2 = rtdsp1;
while ((rtd2 = *rtdsp2++) != NULL) {
if (rtd2 == (void *)(uintptr_t)-1)
continue;

/* for equal types, replace with aliases */
eq = reflection_type_data_equal(rtd1, rtd2);

fprintf(stderr, A_BRIGHT_YELLOW "%s %s:%d compare %p/#%d/%s <-> %p/#%d/%s%s" A_RESET "\n", __func__, __FILE__, __LINE__,
rtd1, rtd1->idx, rtd1->ti->fullname,
rtd2, rtd2->idx, rtd2->ti->fullname,
eq ? " " A_BRIGHT_RED "match" : "");

if (!eq)
continue;

Expand Down Expand Up @@ -6608,7 +6593,7 @@ reflection_type_system_create(const struct reflection_type_system_config *cfg)
struct fy_reflection *rfl;
struct reflection_type_system *rts = NULL;
const struct fy_type_info *ti_entry;
struct reflection_type_data_stack rtds, rtds_created;
struct reflection_type_data_stack rtds;
int rc;

if (!cfg || !cfg->rfl || !cfg->entry_type)
Expand All @@ -6631,9 +6616,7 @@ reflection_type_system_create(const struct reflection_type_system_config *cfg)
fprintf(stderr, A_BLUE "%s: ti_root->fullname=%s DONE" A_RESET "\n", __func__, rts->ti_root->fullname);

reflection_type_data_stack_setup(&rtds);
reflection_type_data_stack_setup(&rtds_created);
rc = reflection_setup_type(rts, rts->ti_root, &rtds, &rtds_created, &rts->rtd_root);
reflection_type_data_stack_cleanup(&rtds_created);
rc = reflection_setup_type(rts, rts->ti_root, &rtds, &rts->rtd_root);
reflection_type_data_stack_cleanup(&rtds);

if (rc)
Expand Down Expand Up @@ -6712,7 +6695,7 @@ reflection_compose_process_event(struct fy_parser *fyp, struct fy_event *fye, st
assert(rd);

#ifndef NDEBUG
fy_parser_info(fyp, "%s: %c%c%c%c%c %3d - %-32s\n",
fy_parser_debug(fyp, "%s: %c%c%c%c%c %3d - %-32s\n",
fy_event_type_get_text(fye->type),
fy_path_in_root(path) ? 'R' : '-',
fy_path_in_sequence(path) ? 'S' : '-',
Expand Down

0 comments on commit 75655c1

Please sign in to comment.