close #1: do not check for constants value
authorMichael Wallner <mike@php.net>
Mon, 6 Feb 2017 19:39:44 +0000 (20:39 +0100)
committerMichael Wallner <mike@php.net>
Mon, 6 Feb 2017 19:39:44 +0000 (20:39 +0100)
m4/psi/psi_const.m4
php_psi_posix.h.in
src/context.c
src/types/impl_def_val.c

index 6210ef9ec0f7f6d7a62394756f77784e61a7ecd4..57edff4a39032d0ec5c08dbcfa5b0a114f675d7f 100644 (file)
@@ -2,46 +2,31 @@
 # 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])
 ])
index 4cd316c9cf4292760c34548e451b737ce90a8efb..1b2f07ada45432eb1f1fcda99112f1c846495071 100644 (file)
@@ -54,8 +54,7 @@ static struct psi_predef_const {
        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}
index 11b2abd00dcf1265e607e8b23e378aeaa7dfa316..f10f4c49e76e288c38c3c1384c99939231750a33 100644 (file)
@@ -97,10 +97,25 @@ struct psi_context *psi_context_init(struct psi_context *C, struct psi_context_o
                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) {
@@ -289,7 +304,7 @@ zend_function_entry *psi_context_compile(struct psi_context *C)
                                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:
@@ -303,7 +318,7 @@ zend_function_entry *psi_context_compile(struct psi_context *C)
                                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);
index efbd793feb438086e2cad8188ecd2b4512673e38..e24b4c28fd38ea19c3ddf75078088374bb288c40 100644 (file)
@@ -33,7 +33,7 @@ struct psi_impl_def_val *psi_impl_def_val_init(token_t t, const char *text)
        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;
 }
@@ -49,15 +49,15 @@ void psi_impl_def_val_free(struct psi_impl_def_val **def_ptr)
                }
                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);
        }
 }
@@ -79,7 +79,8 @@ bool psi_impl_def_val_validate(struct psi_data *data,
                        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;
@@ -95,13 +96,25 @@ bool psi_impl_def_val_validate(struct psi_data *data,
 
 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;
        }
 }