+void psi_decl_enum_item_free(struct psi_decl_enum_item **i_ptr)
+{
+ if (*i_ptr) {
+ struct psi_decl_enum_item *i = *i_ptr;
+
+ *i_ptr = NULL;
+ if (i->token) {
+ free(i->token);
+ }
+ if (i->num) {
+ if (i->num == &i->inc) {
+ switch (i->inc.op) {
+ case PSI_T_NUMBER:
+ psi_number_free(&i->inc.data.n);
+ break;
+ case PSI_T_PLUS:
+ psi_num_exp_free(&i->inc.data.b.lhs);
+ psi_num_exp_free(&i->inc.data.b.rhs);
+ break;
+ default:
+ assert(0);
+ }
+ } else {
+ psi_num_exp_free(&i->num);
+ }
+ }
+ free(i->name);
+ free(i);
+ }
+}
+
+void psi_decl_enum_item_dump(int fd, struct psi_decl_enum_item *item)
+{
+ dprintf(fd, "%s", item->name);
+ if (item->num && item->num != &item->inc) {
+ dprintf(fd, " = ");
+ psi_num_exp_dump(fd, item->num);
+ }
+}
+
+bool psi_decl_enum_item_validate(struct psi_data *data,
+ struct psi_decl_enum *enm, struct psi_decl_enum_item *item, size_t seq)
+{
+ if (!item->num) {
+ if (seq) {
+ int64_t one = 1;
+
+ item->inc.op = PSI_T_PLUS;
+ item->inc.data.b.lhs = psi_num_exp_init_unary(PSI_T_LPAREN,
+ psi_num_exp_copy(item->prev->num));
+ item->inc.data.b.rhs = psi_num_exp_init_num(
+ psi_number_init(PSI_T_INT64, &one, 0));
+ item->num = &item->inc;
+ } else {
+ int64_t nil = 0;
+
+ item->inc.op = PSI_T_NUMBER;
+ item->inc.data.n = psi_number_init(PSI_T_INT64, &nil, 0);
+ item->num = &item->inc;
+ }