php_error(type, buf);
}
+size_t psi_t_alignment(token_t t)
+{
+ size_t align;
+#define PSI_TAS_D(T) struct PSI_TAS_ ##T { \
+ char c; \
+ T x; \
+}
+#define PSI_TAS_P(T) struct PSI_TAS_ ## T ## _pointer { \
+ char c; \
+ T *x; \
+}
+#define PSI_TAS_C(T) align = offsetof(struct PSI_TAS_ ##T, x)
+#define PSI_TAS_CASE(T) { \
+ PSI_TAS_D(T); \
+ PSI_TAS_C(T); \
+}
+ switch (t) {
+ case PSI_T_INT8:
+ PSI_TAS_CASE(int8_t);
+ break;
+ case PSI_T_UINT8:
+ PSI_TAS_CASE(uint8_t);
+ break;
+ case PSI_T_INT16:
+ PSI_TAS_CASE(int16_t);
+ break;
+ case PSI_T_UINT16:
+ PSI_TAS_CASE(uint16_t);
+ break;
+ case PSI_T_INT32:
+ PSI_TAS_CASE(int32_t);
+ break;
+ case PSI_T_UINT32:
+ PSI_TAS_CASE(uint32_t);
+ break;
+ case PSI_T_INT64:
+ PSI_TAS_CASE(int64_t);
+ break;
+ case PSI_T_UINT64:
+ PSI_TAS_CASE(uint64_t);
+ break;
+ case PSI_T_FLOAT:
+ PSI_TAS_CASE(float);
+ break;
+ case PSI_T_DOUBLE:
+ PSI_TAS_CASE(double);
+ break;
+ case PSI_T_POINTER:
+ {
+ PSI_TAS_P(char);
+ PSI_TAS_C(char_pointer);
+ }
+ break;
+ EMPTY_SWITCH_DEFAULT_CASE();
+ }
+
+ return align;
+}
+
+size_t psi_t_size(token_t t)
+{
+ size_t size;
+
+ switch (t) {
+ case PSI_T_INT8:
+ case PSI_T_UINT8:
+ size = 1;
+ break;
+ case PSI_T_INT16:
+ case PSI_T_UINT16:
+ size = 2;
+ break;
+ case PSI_T_INT:
+ size = sizeof(int);
+ break;
+ case PSI_T_INT32:
+ case PSI_T_UINT32:
+ size = 4;
+ break;
+ case PSI_T_INT64:
+ case PSI_T_UINT64:
+ size = 8;
+ break;
+ case PSI_T_FLOAT:
+ size = sizeof(float);
+ break;
+ case PSI_T_DOUBLE:
+ size = sizeof(double);
+ break;
+ case PSI_T_POINTER:
+ size = sizeof(char *);
+ break;
+ EMPTY_SWITCH_DEFAULT_CASE();
+ }
+ return size;
+}
+
+size_t psi_t_align(token_t t, size_t s)
+{
+ size_t a = psi_t_alignment(t);
+ return ((s - 1) | (a - 1)) + 1;
+}
+
int psi_internal_type(impl_type *type)
{
switch (type->type) {
return n;
}
-void psi_to_bool(zval *return_value, token_t t, impl_val *ret_val, decl_var *var)
+void psi_to_bool(zval *return_value, token_t t, impl_val *ret_val, set_value *set, decl_var *var)
{
+ impl_val *v = deref_impl_val(ret_val, var);
+
switch (t) {
case PSI_T_FLOAT:
- RETVAL_DOUBLE((double) deref_impl_val(ret_val, var)->fval);
- convert_to_boolean(return_value);
+ RETVAL_DOUBLE((double) v->fval);
break;
case PSI_T_DOUBLE:
- RETVAL_DOUBLE(deref_impl_val(ret_val, var)->dval);
- convert_to_boolean(return_value);
+ RETVAL_DOUBLE(v->dval);
break;
default:
- RETVAL_LONG(deref_impl_val(ret_val, var)->lval);
- convert_to_boolean(return_value);
+ RETVAL_LONG(v->lval);
break;
}
+ convert_to_boolean(return_value);
}
-void psi_to_int(zval *return_value, token_t t, impl_val *ret_val, decl_var *var)
+void psi_to_int(zval *return_value, token_t t, impl_val *ret_val, set_value *set, decl_var *var)
{
+ impl_val *v = deref_impl_val(ret_val, var);
+
switch (t) {
case PSI_T_FLOAT:
- RETVAL_DOUBLE((double) deref_impl_val(ret_val, var)->fval);
- convert_to_long(return_value);
+ RETVAL_DOUBLE((double) v->fval);
break;
case PSI_T_DOUBLE:
- RETVAL_DOUBLE(deref_impl_val(ret_val, var)->dval);
- convert_to_long(return_value);
+ RETVAL_DOUBLE(v->dval);
break;
default:
- RETVAL_LONG(deref_impl_val(ret_val, var)->lval);
+ RETVAL_LONG(v->lval);
+ return;
}
+ convert_to_long(return_value);
}
-void psi_to_double(zval *return_value, token_t t, impl_val *ret_val, decl_var *var)
+void psi_to_double(zval *return_value, token_t t, impl_val *ret_val, set_value *set, decl_var *var)
{
+ impl_val *v = deref_impl_val(ret_val, var);
+
switch (t) {
case PSI_T_FLOAT:
- RETVAL_DOUBLE((double) deref_impl_val(ret_val, var)->fval);
+ RETVAL_DOUBLE((double) v->fval);
break;
case PSI_T_DOUBLE:
- RETVAL_DOUBLE(deref_impl_val(ret_val, var)->dval);
+ RETVAL_DOUBLE(v->dval);
break;
default:
- RETVAL_DOUBLE((double) deref_impl_val(ret_val, var)->lval);
+ RETVAL_DOUBLE((double) v->lval);
break;
}
}
-void psi_to_string(zval *return_value, token_t t, impl_val *ret_val, decl_var *var)
+void psi_to_string(zval *return_value, token_t t, impl_val *ret_val, set_value *set, decl_var *var)
{
switch (t) {
case PSI_T_INT8:
RETVAL_EMPTY_STRING();
}
}
- break;
+ return;
case PSI_T_FLOAT:
RETVAL_DOUBLE((double) deref_impl_val(ret_val, var)->fval);
- convert_to_string(return_value);
break;
case PSI_T_DOUBLE:
RETVAL_DOUBLE(deref_impl_val(ret_val, var)->dval);
- convert_to_string(return_value);
break;
default:
RETVAL_LONG(deref_impl_val(ret_val, var)->lval);
- convert_to_string(return_value);
break;
}
+ convert_to_string(return_value);
}
-size_t psi_t_alignment(token_t t)
-{
- size_t align;
-#define PSI_TAS_D(T) struct PSI_TAS_ ##T { \
- char c; \
- T x; \
-}
-#define PSI_TAS_P(T) struct PSI_TAS_ ## T ## _pointer { \
- char c; \
- T *x; \
-}
-#define PSI_TAS_C(T) align = offsetof(struct PSI_TAS_ ##T, x)
-#define PSI_TAS_CASE(T) { \
- PSI_TAS_D(T); \
- PSI_TAS_C(T); \
-}
- switch (t) {
- case PSI_T_INT8:
- PSI_TAS_CASE(int8_t);
- break;
- case PSI_T_UINT8:
- PSI_TAS_CASE(uint8_t);
- break;
- case PSI_T_INT16:
- PSI_TAS_CASE(int16_t);
- break;
- case PSI_T_UINT16:
- PSI_TAS_CASE(uint16_t);
- break;
- case PSI_T_INT32:
- PSI_TAS_CASE(int32_t);
- break;
- case PSI_T_UINT32:
- PSI_TAS_CASE(uint32_t);
- break;
- case PSI_T_INT64:
- PSI_TAS_CASE(int64_t);
- break;
- case PSI_T_UINT64:
- PSI_TAS_CASE(uint64_t);
- break;
- case PSI_T_FLOAT:
- PSI_TAS_CASE(float);
- break;
- case PSI_T_DOUBLE:
- PSI_TAS_CASE(double);
- break;
- case PSI_T_POINTER:
- {
- PSI_TAS_P(char);
- PSI_TAS_C(char_pointer);
- }
- break;
- EMPTY_SWITCH_DEFAULT_CASE();
- }
-
- return align;
-}
-
-size_t psi_t_size(token_t t)
-{
- size_t size;
-
- switch (t) {
- case PSI_T_INT8:
- case PSI_T_UINT8:
- size = 1;
- break;
- case PSI_T_INT16:
- case PSI_T_UINT16:
- size = 2;
- break;
- case PSI_T_INT:
- size = sizeof(int);
- break;
- case PSI_T_INT32:
- case PSI_T_UINT32:
- size = 4;
- break;
- case PSI_T_INT64:
- case PSI_T_UINT64:
- size = 8;
- break;
- case PSI_T_FLOAT:
- size = sizeof(float);
- break;
- case PSI_T_DOUBLE:
- size = sizeof(double);
- break;
- case PSI_T_POINTER:
- size = sizeof(char *);
- break;
- EMPTY_SWITCH_DEFAULT_CASE();
- }
- return size;
-}
-
-size_t psi_t_align(token_t t, size_t s)
-{
- size_t a = psi_t_alignment(t);
- return ((s - 1) | (a - 1)) + 1;
-}
static impl_val *iterate(impl_val *val, token_t t, unsigned i, impl_val *tmp)
{
return mem;
}
-void psi_to_array(zval *return_value, token_t t, impl_val *ret_val, decl_var *var)
+void psi_to_array(zval *return_value, token_t t, impl_val *ret_val, set_value *set, decl_var *var)
{
zval ele;
unsigned i;
ret_val = deref_impl_val(ret_val, var);
ZEND_ASSERT(s);
- for (i = 0; i < s->args->count; ++i) {
- decl_arg *darg = s->args->args[i];
- impl_val tmp, tmp_ptr;
- zval ztmp;
- char *ptr = (char *) ret_val->ptr + darg->layout->pos;
- tmp_ptr.ptr = &tmp;
- memset(&tmp, 0, sizeof(tmp));
- memcpy(&tmp, ptr, darg->layout->len);
- switch (real_decl_type(darg->type)->type) {
- case PSI_T_FLOAT:
- case PSI_T_DOUBLE:
- psi_to_double(&ztmp, real_decl_type(darg->type)->type, &tmp, darg->var);
- break;
- case PSI_T_INT8:
- case PSI_T_UINT8:
- if (darg->var->pointer_level) {
- psi_to_string(&ztmp, real_decl_type(darg->type)->type, &tmp_ptr, darg->var);
- break;
+ if (set->count) {
+ /* explicit member casts */
+ for (i = 0; i < set->count; ++i) {
+ zval ztmp;
+ impl_val *tmp_ptr;
+ set_value *sub_set = set->inner[i];
+ decl_var *sub_var = sub_set->vars->vars[0];
+ decl_arg *sub_arg = sub_var->arg;
+ token_t t = real_decl_type(sub_arg->type)->type;
+ void *ptr = malloc(sub_arg->layout->len);
+
+ memcpy(ptr, (char *) ret_val->ptr + sub_arg->layout->pos,
+ sub_arg->layout->len);
+ tmp_ptr = enref_impl_val(ptr, sub_arg->var);
+ sub_set->func->handler(&ztmp, t, tmp_ptr, sub_set, sub_var);
+ add_assoc_zval(return_value, sub_var->name, &ztmp);
+ free(tmp_ptr);
+ if (tmp_ptr != ptr) {
+ free(ptr);
}
- /* no break */
- case PSI_T_INT16:
- case PSI_T_UINT16:
- case PSI_T_INT32:
- case PSI_T_UINT32:
- case PSI_T_INT64:
- case PSI_T_UINT64:
- psi_to_int(&ztmp, real_decl_type(darg->type)->type, &tmp, darg->var);
- break;
- case PSI_T_STRUCT:
- psi_to_array(&ztmp, real_decl_type(darg->type)->type, &tmp_ptr, darg->var);
- break;
- default:
- printf("t=%d\n", real_decl_type(darg->type)->type);
- abort();
}
- add_assoc_zval(return_value, darg->var->name, &ztmp);
}
return;
+
+// for (i = 0; i < s->args->count; ++i) {
+// decl_arg *darg = s->args->args[i];
+// impl_val tmp, tmp_ptr;
+// zval ztmp;
+// char *ptr = (char *) ret_val->ptr + darg->layout->pos;
+//
+// tmp_ptr.ptr = &tmp;
+// memset(&tmp, 0, sizeof(tmp));
+// memcpy(&tmp, ptr, darg->layout->len);
+// switch (real_decl_type(darg->type)->type) {
+// case PSI_T_FLOAT:
+// case PSI_T_DOUBLE:
+// psi_to_double(&ztmp, real_decl_type(darg->type)->type, &tmp, darg->var);
+// break;
+// case PSI_T_INT8:
+// case PSI_T_UINT8:
+// if (darg->var->pointer_level) {
+// psi_to_string(&ztmp, real_decl_type(darg->type)->type, &tmp_ptr, darg->var);
+// break;
+// }
+// /* no break */
+// case PSI_T_INT16:
+// case PSI_T_UINT16:
+// case PSI_T_INT32:
+// case PSI_T_UINT32:
+// case PSI_T_INT64:
+// case PSI_T_UINT64:
+// psi_to_int(&ztmp, real_decl_type(darg->type)->type, &tmp, darg->var);
+// break;
+// case PSI_T_STRUCT:
+// psi_to_array(&ztmp, real_decl_type(darg->type)->type, &tmp_ptr, darg->var);
+// break;
+// default:
+// printf("t=%d\n", real_decl_type(darg->type)->type);
+// abort();
+// }
+// add_assoc_zval(return_value, darg->var->name, &ztmp);
+// }
+ return;
}
ret_val = deref_impl_val(ret_val, var);
for (i = 0; i < var->arg->var->array_size; ++i) {
ZVAL_DEREF(return_value);
zval_dtor(return_value);
- set->func->handler(return_value, t, val, set->vars->vars[0]);
+ set->func->handler(return_value, t, val, set, set->vars->vars[0]);
}
void psi_do_return(zval *return_value, return_stmt *ret, impl_val *ret_val)
{
token_t t = real_decl_type(ret->decl->type)->type;
- ret->set->func->handler(return_value, t, ret_val, ret->decl->var);
+ ret->set->func->handler(return_value, t, ret_val, ret->set, ret->decl->var);
}
void psi_do_free(free_stmt *fre)