# Add a pre-defined string constant to $PSI_CONSTS_H
psi_add_str_const() {
PSI_CONSTS="$PSI_CONSTS
- {PSI_T_STRING, \"string\", \"psi\\\\$1\", $2, PSI_T_QUOTED_STRING},"
+ {PSI_T_STRING, \"string\", \"psi\\\\$1\", {.ptr = $1}},"
}
# psi_add_int_const(name, value)
# Add a pre-defined int constant to $PSI_CONSTS_H
psi_add_int_const() {
PSI_CONSTS="$PSI_CONSTS
- {PSI_T_INT, \"int\", \"psi\\\\$1\", \"$2\", PSI_T_NUMBER},"
+ {PSI_T_INT, \"int\", \"psi\\\\$1\", {.zend.lval = (zend_long) $1}},"
}
dnl PSI_CONST(const name, type)
dnl Check the value of a str/int constant and add it to the list of pre-defined
dnl constants.
AC_DEFUN(PSI_CONST, [
- AC_CACHE_CHECK(value of $1, psi_cv_const_$1, [
- psi_const_val=
- case $2 in
- str*)
- if test "$cross_compiling" = "yes"
- then
- AC_TRY_CPP(PSI_INCLUDES $1, psi_const_val=`eval "$ac_try|tail -n1"`, psi_const_val=)
- else
- PSI_COMPUTE_STR(psi_const_val, $1, PSI_INCLUDES)
- fi
- ;;
- int)
- AC_COMPUTE_INT(psi_const_val, $1, PSI_INCLUDES)
- ;;
- esac
- psi_cv_const_$1=$psi_const_val
- ])
- if test "$psi_cv_const_$1"
- then
- case $2 in
- str*)
- psi_add_str_const "$1" "$psi_cv_const_$1"
- ;;
- int)
- psi_add_int_const "$1" "$psi_cv_const_$1"
- ;;
- esac
- fi
+ AC_CHECK_DECL($1, [
+ if test "$psi_cv_const_$1"
+ then
+ case $2 in
+ str*)
+ psi_add_str_const "$1"
+ ;;
+ int)
+ psi_add_int_const "$1"
+ ;;
+ esac
+ fi
+ ],, [PSI_INCLUDES])
])
token_t type_tag;
const char *type_name;
const char *var_name;
- const char *val_text;
- token_t val_type_tag;
+ impl_val value;
} psi_predef_consts[] = {
@PSI_CONSTS@
{0}
T.types = psi_plist_add(T.types, &def);
}
for (predef_const = &psi_predef_consts[0]; predef_const->type_tag; ++predef_const) {
- struct psi_impl_def_val *val = psi_impl_def_val_init(predef_const->val_type_tag, predef_const->val_text);
struct psi_const_type *type = psi_const_type_init(predef_const->type_tag, predef_const->type_name);
- struct psi_const *constant = psi_const_init(type, predef_const->var_name, val);
+ struct psi_impl_def_val *val;
+ struct psi_const *constant;
+ switch (type->type) {
+ case PSI_T_INT:
+ val = psi_impl_def_val_init(PSI_T_INT, NULL);
+ val->ival.zend.lval = predef_const->value.lval;
+ break;
+ case PSI_T_STRING:
+ val = psi_impl_def_val_init(PSI_T_STRING, NULL);
+ val->ival.zend.str = zend_string_init(predef_const->value.ptr, strlen(predef_const->value.ptr), 1);
+ break;
+ default:
+ assert(0);
+ break;
+ }
+
+ constant = psi_const_init(type, predef_const->var_name, val);
T.consts = psi_plist_add(T.consts, &constant);
}
for (predef_composite = &psi_predef_composites[0]; predef_composite->type_tag; ++predef_composite) {
continue;
}
- zc.name = zend_string_init(c->name + (c->name[0] == '\\'), strlen(c->name) - (c->name[0] == '\\'), 1);
+ zc.name = zend_string_init(c->name, strlen(c->name), 1);
switch (c->type->type) {
case PSI_T_BOOL:
break;
case PSI_T_STRING:
case PSI_T_QUOTED_STRING:
- ZVAL_NEW_STR(&zc.value, zend_string_init(c->val->text, strlen(c->val->text), 1));
+ ZVAL_NEW_STR(&zc.value, zend_string_copy(c->val->ival.zend.str));
break;
default:
assert(0);
struct psi_impl_def_val *def = calloc(1, sizeof(*def));
def->type = t;
- def->text = strdup(text);
+ def->text = text ? strdup(text) : NULL;
return def;
}
}
switch (def->type) {
case PSI_T_STRING:
- assert(0);
- /* no break */
case PSI_T_QUOTED_STRING:
if (def->ival.zend.str) {
zend_string_release(def->ival.zend.str);
}
break;
}
- free(def->text);
+ if (def->text) {
+ free(def->text);
+ }
free(def);
}
}
break;
case PSI_T_STRING:
/* used for consts */
- /* no break */
+ def->ival.zend.str = zend_string_init(def->text, strlen(def->text), 1);
+ break;
case PSI_T_QUOTED_STRING:
def->ival.zend.str = zend_string_init(&def->text[1], strlen(def->text) - 2, 1);
break;
void psi_impl_def_val_dump(int fd, struct psi_impl_def_val *val) {
switch (val->type) {
+ case PSI_T_INT:
+ dprintf(fd, "%ld", val->ival.zend.lval);
+ break;
+ case PSI_T_FLOAT:
+ case PSI_T_DOUBLE:
+ dprintf(fd, "%f", val->ival.dval);
+ break;
case PSI_T_STRING:
- assert(0);
- /* no break */
+ dprintf(fd, "\"%s\"", val->ival.zend.str->val);
+ break;
case PSI_T_QUOTED_STRING:
dprintf(fd, "\"%s\"", val->text);
break;
default:
- dprintf(fd, "%s", val->text);
+ if (val->text) {
+ dprintf(fd, "%s", val->text);
+ } else {
+ assert(0);
+ }
+ break;
}
}