lift single lib statement restriction
[m6w6/ext-psi] / src / types / let_func.c
index 27c37027ad5c7f2cd6f98693bde452e5782e1831..fdb89a06fc7ade78a509117d71805e4716546784 100644 (file)
@@ -82,7 +82,7 @@ void psi_let_func_dump(int fd, struct psi_let_func *func, unsigned level)
 }
 
 static inline int validate_let_func_type(struct psi_data *data,
-               struct psi_let_func *func, struct psi_impl *impl)
+               struct psi_let_func *func, struct psi_validate_scope *scope)
 {
        switch (func->type) {
        case PSI_T_BOOLVAL:
@@ -108,15 +108,16 @@ static inline int validate_let_func_type(struct psi_data *data,
        default:
                data->error(data, func->var->token, PSI_WARNING,
                                "Unknown `let` cast function '%s' of implementation '%s'",
-                               func->name, impl->func->name);
+                               func->name, scope->impl->func->name);
                return false;
        }
 }
 
 static inline bool validate_let_func_inner(struct psi_data *data,
-               struct psi_let_exp *exp, struct psi_let_func *func,
-               struct psi_impl *impl)
+               struct psi_let_func *func, struct psi_validate_scope *scope)
 {
+       struct psi_let_exp *exp = scope->current_let;
+
        if (func->inner) {
                struct psi_decl_var *let_var = psi_let_exp_get_decl_var(exp);
                struct psi_decl_type *var_typ;
@@ -144,8 +145,13 @@ static inline bool validate_let_func_inner(struct psi_data *data,
                                        /* remove expr for portability with different struct members */
                                        psi_plist_del(func->inner, --i, NULL);
                                        psi_let_exp_free(&inner);
-                               } else if (!psi_let_exp_validate(data, inner, impl)) {
-                                       return false;
+                               } else {
+                                       scope->current_let = inner;
+                                       if (!psi_let_exp_validate(data, inner, scope)) {
+                                               scope->current_let = exp;
+                                               return false;
+                                       }
+                                       scope->current_let = exp;
                                }
                        }
                } else if (func->type == PSI_T_ARRVAL
@@ -169,9 +175,12 @@ static inline bool validate_let_func_inner(struct psi_data *data,
                                                                " reference the same variable");
                                return false;
                        }
-                       if (!psi_let_exp_validate(data, inner, impl)) {
+                       scope->current_let = inner;
+                       if (!psi_let_exp_validate(data, inner, scope)) {
+                               scope->current_let = exp;
                                return false;
                        }
+                       scope->current_let = exp;
                } else {
                        data->error(data, let_var->token, PSI_WARNING,
                                        "Inner let statement's values must refer to a structure or"
@@ -191,22 +200,22 @@ static inline bool validate_let_func_inner(struct psi_data *data,
        return true;
 }
 
-bool psi_let_func_validate(struct psi_data *data, struct psi_let_exp *val,
-               struct psi_let_func *func, struct psi_impl *impl)
+bool psi_let_func_validate(struct psi_data *data, struct psi_let_func *func,
+               struct psi_validate_scope *scope)
 {
-       if (impl->func->args) {
+       if (scope->impl->func->args) {
                /* FIXME, func->var does not need to be referring to a func arg */
-               psi_impl_get_arg(impl, func->var);
+               psi_impl_get_arg(scope->impl, func->var);
        }
 
-       if (!psi_impl_var_validate(data, func->var, impl, val, NULL)) {
+       if (!psi_impl_var_validate(data, func->var, scope)) {
                return false;
        }
 
-       if (!validate_let_func_type(data, func, impl)) {
+       if (!validate_let_func_type(data, func, scope)) {
                return false;
        }
-       if (!validate_let_func_inner(data, val, func, impl)) {
+       if (!validate_let_func_inner(data, func, scope)) {
                return false;
        }
        return 1;
@@ -255,12 +264,12 @@ static void *exec_let_func_arrval(struct psi_let_exp *val,
                struct psi_call_frame *frame);
 
 void exec_let_func_arrval_seq(struct psi_let_func *func,
-               struct psi_decl_arg *darg, struct psi_decl_type *darg_type,
+               struct psi_decl_arg *darg,
                struct psi_call_frame_argument *frame_arg,
                struct psi_let_exp *inner_let_exp, void *container,
                struct psi_call_frame *frame)
 {
-       zval *zval_ptr;
+       zval *zval_ptr = NULL;
        psi_marshal_let let_fn;
        size_t i = 0, size;
        struct psi_decl_var *dvar;
@@ -287,7 +296,7 @@ void exec_let_func_arrval_seq(struct psi_let_func *func,
                impl_val val = {0}, *ptr, *sub;
 
                if (let_fn) {
-                       ptr = let_fn(&val, darg_type, 0, NULL, zval_ptr, &temp);
+                       ptr = let_fn(&val, darg, 0, NULL, zval_ptr, &temp);
                        if (temp) {
                                psi_call_frame_push_auto(frame, temp);
                        }
@@ -315,10 +324,9 @@ static void *exec_let_func_arrval(struct psi_let_exp *val,
 {
        void *container = NULL;
        struct psi_call_frame_argument *frame_arg;
-       struct psi_decl_type *darg_type;
        struct psi_plist *darg_members;
 
-       darg_members = psi_decl_type_get_args(darg->type, &darg_type);
+       darg_members = psi_decl_type_get_args(darg->type, NULL);
        frame_arg = psi_call_frame_get_argument(frame, func->var->fqn);
 
        if (frame_arg->zval_ptr && Z_TYPE_P(frame_arg->zval_ptr) != IS_ARRAY) {
@@ -368,8 +376,7 @@ static void *exec_let_func_arrval(struct psi_let_exp *val,
                container = ecalloc(arcount + 1, psi_decl_var_get_size(inner->var));
                inner->var->pointer_level -= inner->is_reference;
 
-               exec_let_func_arrval_seq(func, darg, darg_type, frame_arg, inner,
-                               container, frame);
+               exec_let_func_arrval_seq(func, darg, frame_arg, inner, container, frame);
        } else {
                assert(0);
        }
@@ -393,8 +400,7 @@ void *psi_let_func_exec(struct psi_let_exp *val, struct psi_let_func *func,
 
                assert(iarg);
 
-               frame_sym->ival_ptr = let_fn(&frame_sym->temp_val,
-                               psi_decl_type_get_real(darg->type),
+               frame_sym->ival_ptr = let_fn(&frame_sym->temp_val, darg,
                                iarg->spec ? iarg->spec->type->type : 0, iarg->ival_ptr,
                                iarg->zval_ptr, &temp);
                if (temp) {