Merge branch 'slimconfigure'
[m6w6/ext-psi] / src / types / return_stmt.c
index 5df84814355635e6e748f2c4ebf020fd54b51385..b4bcb523d6f42b2ed104d2a5eb9051f33a233014 100644 (file)
 #include "data.h"
 #include "call.h"
 
-struct psi_return_stmt *psi_return_stmt_init(struct psi_set_exp *val)
+struct psi_return_stmt *psi_return_stmt_init(struct psi_return_exp *exp)
 {
        struct psi_return_stmt *ret = calloc(1, sizeof(*ret));
-       ret->set = val;
+       ret->exp = exp;
        return ret;
 }
 
 void psi_return_stmt_exec(struct psi_return_stmt *ret, zval *return_value,
                struct psi_call_frame *frame)
 {
-       psi_set_exp_exec_ex(ret->set, return_value, frame->rpointer, frame);
+       psi_return_exp_exec(ret->exp, return_value, frame);
 }
 
 void psi_return_stmt_free(struct psi_return_stmt **ret_ptr)
@@ -49,7 +49,7 @@ void psi_return_stmt_free(struct psi_return_stmt **ret_ptr)
                if (ret->token) {
                        free(ret->token);
                }
-               psi_set_exp_free(&ret->set);
+               psi_return_exp_free(&ret->exp);
                free(ret);
        }
 }
@@ -57,18 +57,17 @@ void psi_return_stmt_free(struct psi_return_stmt **ret_ptr)
 void psi_return_stmt_dump(int fd, struct psi_return_stmt *ret)
 {
        dprintf(fd, "\treturn ");
-       psi_set_exp_dump(fd, ret->set, 1, 1);
+       psi_return_exp_dump(fd, ret->exp);
        dprintf(fd, ";\n");
 }
 
-bool psi_return_stmt_validate(struct psi_data *data, struct psi_impl *impl)
+bool psi_return_stmt_validate(struct psi_data *data,
+               struct psi_validate_scope *scope)
 {
-       size_t i = 0;
-       struct psi_decl *decl;
        struct psi_return_stmt *ret;
-       size_t count = psi_plist_count(impl->stmts.ret);
+       size_t count = psi_plist_count(scope->impl->stmts.ret);
 
-       psi_plist_get(impl->stmts.ret, 0, &ret);
+       psi_plist_get(scope->impl->stmts.ret, 0, &ret);
 
        /*
         * we must have exactly one ret stmt declaring the native func to call
@@ -79,32 +78,18 @@ bool psi_return_stmt_validate(struct psi_data *data, struct psi_impl *impl)
                data->error(data, ret->token, PSI_WARNING,
                                "Too many `return` statements for implementation %s;"
                                " found %zu, exactly one is required",
-                               impl->func->name, count);
+                               scope->impl->func->name, count);
                return false;
        case 0:
-               data->error(data, impl->func->token, PSI_WARNING,
+               data->error(data, scope->impl->func->token, PSI_WARNING,
                                "Missing `return` statement for implementation %s",
-                               impl->func->name);
+                               scope->impl->func->name);
                return false;
        case 1:
                break;
        }
 
-       while (psi_plist_get(data->decls, i++, &decl)) {
-               if (!strcmp(decl->func->var->name, ret->set->data.func->var->name)) {
-                       impl->decl = decl;
-                       break;
-               }
-       }
-
-       if (!impl->decl) {
-               data->error(data, ret->token, PSI_WARNING,
-                               "Missing declaration '%s' for `return` statement of implementation %s",
-                               ret->set->data.func->var->name, impl->func->name);
-               return false;
-       }
-
-       if (!psi_set_exp_validate(data, ret->set, impl, NULL)) {
+       if (!psi_return_exp_validate(data, ret->exp, scope)) {
                return false;
        }