+void psi_impl_def_val_free(struct psi_impl_def_val **def_ptr)
+{
+ if (*def_ptr) {
+ struct psi_impl_def_val *def = *def_ptr;
+
+ *def_ptr = NULL;
+ if (def->token) {
+ free(def->token);
+ }
+ switch (def->type) {
+ case PSI_T_NUMBER:
+ psi_num_exp_free(&def->data.num);
+ break;
+
+ case PSI_T_STRING:
+ if (def->ival.zend.str) {
+ zend_string_release(def->ival.zend.str);
+ }
+ break;
+ default:
+ break;
+ }
+ free(def);
+ }
+}
+
+bool psi_impl_def_val_validate(struct psi_data *data,
+ struct psi_impl_def_val *def, struct psi_impl_type *cmp,
+ struct psi_validate_scope *scope)
+{
+ if (def->type == PSI_T_NULL) {
+ return true;
+ }
+
+ switch (cmp->type) {
+ case PSI_T_BOOL:
+ def->ival.zend.bval = def->type == PSI_T_TRUE ? 1 : 0;
+ break;
+
+ /* macros */
+ case PSI_T_NUMBER:
+ if (def->type == PSI_T_NUMBER) {
+ token_t typ = psi_num_exp_exec(def->data.num, &def->ival, NULL, scope->defs);
+
+ switch (typ) {
+ case PSI_T_FLOAT:
+ def->ival.dval = def->ival.fval;
+ /* no break */
+ case PSI_T_DOUBLE:
+ def->type = PSI_T_FLOAT;
+ cmp->type = PSI_T_FLOAT;
+ strcpy(cmp->name, "float");
+ break;
+ default:
+ def->type = PSI_T_INT;
+ cmp->type = PSI_T_INT;
+ strcpy(cmp->name, "int");
+ break;
+ }
+ psi_num_exp_free(&def->data.num);
+ return true;
+ }
+ break;
+
+ case PSI_T_INT:
+ if (def->type == PSI_T_NUMBER) {
+ def->type = PSI_T_INT;
+ def->ival.zend.lval = psi_num_exp_get_long(def->data.num, NULL, scope->defs);
+ psi_num_exp_free(&def->data.num);
+ }
+ if (def->type == PSI_T_INT) {
+ return true;
+ }
+ break;
+
+ case PSI_T_FLOAT:
+ case PSI_T_DOUBLE:
+ if (def->type == PSI_T_NUMBER) {
+ def->type = PSI_T_DOUBLE;
+ def->ival.dval = psi_num_exp_get_double(def->data.num, NULL, scope->defs);
+ psi_num_exp_free(&def->data.num);
+ }
+ if (def->type == PSI_T_DOUBLE) {
+ return true;
+ }
+ break;
+
+ case PSI_T_STRING:
+ if (def->type == PSI_T_STRING) {
+ return true;
+ }
+ break;
+
+ default:
+ data->error(data, def->token, PSI_WARNING,
+ "Invalid default value type '%s', "
+ "expected one of bool, int, float, string.",
+ cmp->name);