libctf, types: ctf_type_kind_{iter,next} et al

These new functions let you iterate over types by kind, letting you get all
variables, all enums, all datasecs, etc.  (This is amenable to future
optimization, and some is expected shortly.)

We also add new iternal functions ctf_type_kind_{forwarded_,unsliced_,}tp
which are like the corresponding non-_tp functions except that they
take a ctf_type_t rather than a type ID: doing this allows the deduplicator
to use these nearly-public functions more.  The public ctf_type_kind*
functions are reimplemented in terms of these.

This machinery is the principal place where the magic encoding of forwards
is encoded.
This commit is contained in:
Nick Alcock
2025-04-24 18:00:32 +01:00
parent ea21a1b2ae
commit a632f3ed33
4 changed files with 194 additions and 27 deletions

View File

@@ -310,8 +310,6 @@ _CTF_ERRORS
typedef int ctf_visit_f (const char *name, ctf_id_t type, unsigned long offset,
int depth, void *arg);
typedef int ctf_type_f (ctf_id_t type, void *arg);
typedef int ctf_type_all_f (ctf_id_t type, int flag, void *arg);
void *arg);
typedef int ctf_member_f (ctf_dict_t *, const char *name, ctf_id_t membtype,
size_t offset, int bit_width, void *arg);
@@ -321,6 +319,9 @@ typedef int ctf_variable_f (ctf_dict_t *, const char *name, ctf_id_t type,
void *arg);
typedef int ctf_datasec_var_f (ctf_dict_t *fp, ctf_id_t type, size_t offset,
size_t datasec_size, void *arg);
typedef int ctf_type_f (ctf_dict_t *, ctf_id_t type, void *arg);
typedef int ctf_type_all_f (ctf_dict_t *, ctf_id_t type, int flag, void *arg);
typedef int ctf_type_kind_f (ctf_dict_t *, ctf_id_t type, int kind, void *arg);
typedef int ctf_archive_member_f (ctf_dict_t *fp, const char *name, void *arg);
typedef int ctf_archive_raw_member_f (const char *name, const void *content,
size_t len, void *arg);
@@ -793,8 +794,10 @@ extern ctf_id_t ctf_arc_lookup_enumerator_next (ctf_archive_t *, const char *nam
extern int ctf_type_iter (ctf_dict_t *, ctf_type_f *, void *);
extern int ctf_type_iter_all (ctf_dict_t *, ctf_type_all_f *, void *);
extern int ctf_type_kind_iter (ctf_dict_t *, int kind, ctf_type_kind_f *, void *);
extern ctf_id_t ctf_type_next (ctf_dict_t *, ctf_next_t **,
int *flag, int want_hidden);
extern ctf_id_t ctf_type_kind_next (ctf_dict_t *, ctf_next_t **, int kind);
extern int ctf_variable_iter (ctf_dict_t *, ctf_variable_f *, void *);
extern ctf_id_t ctf_variable_next (ctf_dict_t *, ctf_next_t **,