1 /* MIT (BSD) license - see LICENSE file for details */
4 #include <ccan/strmap/strmap.h>
5 #include <ccan/tal/tal.h>
20 const char *qualifiers;
21 struct cdump_type *type;
24 struct cdump_enum_val {
27 /* Either NULL, or whatever follows '=' sign */
33 struct cdump_type *type;
37 enum cdump_type_kind kind;
41 /* CDUMP_STRUCT / CDUMP_UNION: array */
42 struct cdump_member *members;
43 /* CDUMP_ENUM: array */
44 struct cdump_enum_val *enum_vals;
46 struct cdump_array arr;
48 const struct cdump_type *ptr;
52 /* The map of typenames to definitions */
54 STRMAP_MEMBERS(struct cdump_type *);
57 struct cdump_definitions {
58 struct cdump_map enums;
59 struct cdump_map structs;
60 struct cdump_map unions;
64 * cdump_extract - extract definitions from simple C code.
65 * @ctx: context to tal() the return and @problems from (or NULL)
66 * @code: a nul-terminated string of C definitions
67 * @problems: a pointer to a char * to report problems (or NULL)
69 * This function parses @code and extracts enum, struct and union definitions
70 * into the return. If there is a parse error, it will return NULL and
71 * allocate a problem string for human consumption.
73 * Annotations can be attached to structures, unions, enums, members
74 * and enum values using CDUMP(). This comes after the name (or
75 * after [] for array member declarations) and usually is removed from
76 * C compilation using "#define CDUMP(x)".
79 * // Returns name of first field of 'struct @name' in @code.
80 * static const char *first_field_of_struct(const char *code,
84 * struct cdump_definitions *defs;
85 * struct cdump_type *t;
87 * defs = cdump_extract(NULL, code, &problems);
89 * fprintf(stderr, "%s", problems);
93 * t = strmap_get(&defs->structs, name);
95 * fprintf(stderr, "Couldn't find struct %s", name);
98 * assert(t->kind == CDUMP_STRUCT);
100 * printf("Note on struct %s: %s\n", name, t->note);
101 * return t->u.members[0].name;
104 struct cdump_definitions *cdump_extract(const tal_t *ctx, const char *code,
106 #endif /* CCAN_CDUMP_H */