1 /* MIT (BSD) license - see LICENSE file for details */
4 #include <ccan/strmap/strmap.h>
5 #include <ccan/tal/tal.h>
19 const char *qualifiers;
20 struct cdump_type *type;
23 struct cdump_enum_val {
25 /* Either NULL, or whatever follows '=' sign */
31 struct cdump_type *type;
35 enum cdump_type_kind kind;
38 /* CDUMP_STRUCT / CDUMP_UNION: array */
39 struct cdump_member *members;
40 /* CDUMP_ENUM: array */
41 struct cdump_enum_val *enum_vals;
43 struct cdump_array arr;
45 const struct cdump_type *ptr;
49 /* The map of typenames to definitions */
51 STRMAP_MEMBERS(struct cdump_type *);
54 struct cdump_definitions {
55 struct cdump_map enums;
56 struct cdump_map structs;
57 struct cdump_map unions;
61 * cdump_extract - extract definitions from simple C code.
62 * @ctx: context to tal() the return and @problems from (or NULL)
63 * @code: a nul-terminated string of C definitions
64 * @problems: a pointer to a char * to report problems (or NULL)
66 * This function parses @code and extracts enum, struct and union definitions
67 * into the return. If there is a parse error, it will return NULL and
68 * allocate a problem string for human consumption.
71 * // Returns name of first field of 'struct @name' in @code.
72 * static const char *first_field_of_struct(const char *code,
76 * struct cdump_definitions *defs;
77 * struct cdump_type *t;
79 * defs = cdump_extract(NULL, code, &problems);
81 * fprintf(stderr, "%s", problems);
85 * t = strmap_get(&defs->structs, name);
87 * fprintf(stderr, "Couldn't find struct %s", name);
90 * assert(t->kind == CDUMP_STRUCT);
91 * return t->u.members[0].name;
94 struct cdump_definitions *cdump_extract(const tal_t *ctx, const char *code,
96 #endif /* CCAN_CDUMP_H */