+typedef struct decl_enum_item {
+ PSI_Token *token;
+ char *name;
+ num_exp *num;
+ num_exp inc;
+ struct decl_enum_item *prev;
+} decl_enum_item;
+
+static inline decl_enum_item *init_decl_enum_item(const char *name, num_exp *num) {
+ decl_enum_item *i = calloc(1, sizeof(*i));
+
+ i->name = strdup(name);
+ i->num = num;
+ return i;
+}
+
+static inline void free_decl_enum_item(decl_enum_item *i) {
+ if (i->token) {
+ free(i->token);
+ }
+ if (i->num && i->num != &i->inc) {
+ free_num_exp(i->num);
+ }
+ free(i->name);
+ free(i);
+}
+
+typedef struct decl_enum_items {
+ decl_enum_item **list;
+ size_t count;
+} decl_enum_items;
+
+static inline decl_enum_items *init_decl_enum_items(decl_enum_item *i) {
+ decl_enum_items *l = calloc(1, sizeof(*l));
+
+ if (i) {
+ l->count = 1;
+ l->list = calloc(1, sizeof(*l->list));
+ l->list[0] = i;
+ }
+ return l;
+}
+
+static inline decl_enum_items *add_decl_enum_item(decl_enum_items *l, decl_enum_item *i) {
+ l->list = realloc(l->list, sizeof(*l->list) * (l->count + 1));
+ l->list[l->count] = i;
+ if (l->count) {
+ i->prev = l->list[l->count - 1];
+ }
+ ++l->count;
+ return l;
+}
+
+static inline void free_decl_enum_items(decl_enum_items *l) {
+ if (l->list) {
+ size_t j;
+
+ for (j = 0; j < l->count; ++j) {
+ free_decl_enum_item(l->list[j]);
+ }
+ free(l->list);
+ }
+ free(l);
+}
+
+typedef struct decl_enum {
+ PSI_Token *token;
+ char *name;
+ decl_enum_items *items;
+} decl_enum;
+
+static inline decl_enum *init_decl_enum(const char *name, decl_enum_items *l) {
+ decl_enum *e = calloc(1, sizeof(*e));
+
+ e->name = strdup(name);
+ e->items = l;
+ return e;
+}
+
+static inline void free_decl_enum(decl_enum *e) {
+ if (e->token) {
+ free(e->token);
+ }
+ if (e->items) {
+ free_decl_enum_items(e->items);
+ }
+ free(e->name);
+ free(e);
+}
+
+typedef struct decl_enums {
+ decl_enum **list;
+ size_t count;
+} decl_enums;
+
+static inline decl_enums* add_decl_enum(decl_enums *es, decl_enum *e) {
+ if (!es) {
+ es = calloc(1, sizeof(*es));
+ }
+ es->list = realloc(es->list, ++es->count * sizeof(*es->list));
+ es->list[es->count-1] = e;
+ return es;
+}
+
+static inline void free_decl_enums(decl_enums *es) {
+ if (es->list) {
+ size_t j;
+
+ for (j = 0; j < es->count; ++j) {
+ free_decl_enum(es->list[j]);
+ }
+ }
+ free(es->list);
+ free(es);
+}
+