basic support for builtins
[m6w6/ext-psi] / src / types / const.c
index 449f04a1221e493e366d392825f7fb47d7eea477..b839d5f701897aa952fd2e7b6a24585942e63b05 100644 (file)
 #include "php_psi_stdinc.h"
 #include "data.h"
 
-struct psi_const *psi_const_init(struct psi_const_type *type, const char *name,
+struct psi_const *psi_const_init(struct psi_impl_type *type, zend_string *name,
                struct psi_impl_def_val *val)
 {
-       struct psi_const *c = calloc(1, sizeof(*c));
+       struct psi_const *c = pecalloc(1, sizeof(*c), 1);
+
+       if (name->val[0] == '\\') {
+               c->name = zend_string_init(&name->val[1], name->len-1, 1);
+       } else {
+               c->name = zend_string_copy(name);
+       }
        c->type = type;
-       c->name = strdup(name[0] == '\\' ? &name[1] : name);
        c->val = val;
        return c;
 }
@@ -42,11 +47,9 @@ void psi_const_free(struct psi_const **constant_ptr)
                struct psi_const *constant = *constant_ptr;
 
                *constant_ptr = NULL;
-               if (constant->token) {
-                       free(constant->token);
-               }
-               psi_const_type_free(&constant->type);
-               free(constant->name);
+               psi_token_free(&constant->token);
+               psi_impl_type_free(&constant->type);
+               zend_string_release(constant->name);
                psi_impl_def_val_free(&constant->val);
                free(constant);
        }
@@ -55,15 +58,18 @@ void psi_const_free(struct psi_const **constant_ptr)
 void psi_const_dump(int fd, struct psi_const *cnst)
 {
        dprintf(fd, "const ");
-       psi_const_type_dump(fd, cnst->type);
-       dprintf(fd, " %s = ", cnst->name);
+       if (cnst->type) {
+               psi_impl_type_dump(fd, cnst->type);
+       }
+       dprintf(fd, " %s = ", cnst->name->val);
        psi_impl_def_val_dump(fd, cnst->val);
        dprintf(fd, ";");
 }
 
-bool psi_const_validate(struct psi_data *data, struct psi_const *c)
+bool psi_const_validate(struct psi_data *data, struct psi_const *c,
+               struct psi_validate_scope *scope)
 {
-       if (!psi_impl_def_val_validate(data, c->val, c->type->type, c->type->name)) {
+       if (!psi_impl_def_val_validate(data, c->val, c->type, scope)) {
                return false;
        }
        return true;