commit after reset fuckup
[m6w6/ext-psi] / src / types / const.c
index b839d5f701897aa952fd2e7b6a24585942e63b05..fd1a165ee65841943e1667138866da8e0c27f58d 100644 (file)
@@ -55,20 +55,36 @@ void psi_const_free(struct psi_const **constant_ptr)
        }
 }
 
-void psi_const_dump(int fd, struct psi_const *cnst)
+void psi_const_dump(struct psi_dump *dump, struct psi_const *cnst)
 {
-       dprintf(fd, "const ");
+       PSI_DUMP(dump, "const ");
        if (cnst->type) {
-               psi_impl_type_dump(fd, cnst->type);
+               psi_impl_type_dump(dump, cnst->type);
        }
-       dprintf(fd, " %s = ", cnst->name->val);
-       psi_impl_def_val_dump(fd, cnst->val);
-       dprintf(fd, ";");
+       PSI_DUMP(dump, " %s = ", cnst->name->val);
+       psi_impl_def_val_dump(dump, cnst->val);
+       PSI_DUMP(dump, ";");
 }
 
 bool psi_const_validate(struct psi_data *data, struct psi_const *c,
                struct psi_validate_scope *scope)
 {
+       if (c->type) {
+               switch (c->type->type) {
+               case PSI_T_BOOL:
+               case PSI_T_INT:
+               case PSI_T_FLOAT:
+               case PSI_T_DOUBLE:
+               case PSI_T_STRING:
+                       break;
+               default:
+                       data->error(data, val->token, PSI_WARNING,
+                                       "Invalid default value type '%s', "
+                                       "expected one of bool, int, float/double or string.",
+                                       type->name->val);
+               return false;
+               }
+       }
        if (!psi_impl_def_val_validate(data, c->val, c->type, scope)) {
                return false;
        }