#include "php.h"
#include "libjit.h"
#include "parser_proc.h"
+#include "parser.h"
+
+#include <jit/jit.h>
static void init(PSI_Context *C)
{
- C->opaque = jit_context_create();
+ C->context = jit_context_create();
}
static void dtor(PSI_Context *C)
{
- jit_context_destroy(C->opaque);
-}
-
-typedef struct PSI_ClosureData {
- void *context;
- impl *impl;
- jit_type_t signature;
- zval return_value;
-} PSI_ClosureData;
-
-static inline PSI_ClosureData *PSI_ClosureDataAlloc(void *context, impl *impl) {
- PSI_ClosureData *data = malloc(sizeof(*data));
-
- data->context = context;
- data->impl = impl;
-
- return data;
+ jit_context_destroy(C->context);
+ C->context = NULL;
}
static inline size_t impl_num_min_args(impl *impl) {
}
static inline jit_type_t psi_jit_type(token_t t) {
switch (t) {
+ default:
+ ZEND_ASSERT(0);
+ /* no break */
case PSI_T_VOID:
return jit_type_void;
case PSI_T_SINT8:
return jit_type_sys_float;
case PSI_T_DOUBLE:
return jit_type_sys_double;
- default:
- abort();
}
}
static inline jit_type_t psi_jit_decl_type(decl_type *type) {
return psi_jit_decl_type(darg->type);
}
}
-static void handler(jit_type_t _sig, void *result, void **_args, void *_data)
-{
- zend_execute_data *execute_data = *(zend_execute_data **)_args[0];
- zval *return_value = *(zval **)_args[1];
- PSI_ClosureData *data = _data;
- impl_arg *iarg;
- size_t i;
- void **arg_ptr = NULL, **arg_prm = NULL;
- impl_val ret_val, *arg_val = NULL;
- jit_type_t signature, *sig_prm;
- if (!data->impl->func->args->count) {
- if (SUCCESS != zend_parse_parameters_none()) {
- return;
+typedef struct PSI_ClosureData {
+ void *context;
+ impl *impl;
+ jit_type_t signature;
+ jit_type_t params[1];
+} PSI_ClosureData;
+
+static inline PSI_ClosureData *PSI_ClosureDataAlloc(void *context, impl *impl) {
+ size_t i, c = impl->decl->args->count;
+ PSI_ClosureData *data = malloc(sizeof(*data) + (c ? c-1 : c) * sizeof(jit_type_t));
+
+ data->context = context;
+ data->impl = impl;
+ for (i = 0; i < c; ++i) {
+ data->params[i] = psi_jit_decl_arg_type(impl->decl->args->args[i]);
+ }
+ data->signature = jit_type_create_signature(
+ psi_jit_abi(data->impl->decl->abi->convention),
+ psi_jit_decl_arg_type(data->impl->decl->func),
+ data->params,
+ data->impl->decl->args->count,
+ 1);
+ return data;
+}
+
+
+static inline impl_val *deref(unsigned level, impl_val *ret_val, decl_arg *darg) {
+ unsigned i;
+
+ for (i = level; i < darg->var->pointer_level; ++i) {
+ ret_val = *(void **)ret_val;
+ }
+
+ return ret_val;
+}
+static void to_int(impl_val *ret_val, decl_arg *func, zval *return_value) {
+ switch (real_decl_type(func->type)->type) {
+ case PSI_T_FLOAT:
+ case PSI_T_DOUBLE:
+ RETVAL_DOUBLE(deref(0, ret_val, func)->dval);
+ convert_to_long(return_value);
+ break;
+ default:
+ RETVAL_LONG(deref(0, ret_val, func)->lval);
+ }
+}
+static void to_string(impl_val *ret_val, decl_arg *func, zval *return_value) {
+ switch (real_decl_type(func->type)->type) {
+ case PSI_T_CHAR:
+ case PSI_T_SINT8:
+ case PSI_T_UINT8:
+ if (!func->var->pointer_level) {
+ char chr = ret_val->lval;
+ RETVAL_STRINGL(&chr, 1);
+ } else {
+ RETVAL_STRING(deref(1, ret_val, func)->ptr);
}
- } else
- ZEND_PARSE_PARAMETERS_START(impl_num_min_args(data->impl), data->impl->func->args->count)
+ break;
+ case PSI_T_FLOAT:
+ case PSI_T_DOUBLE:
+ RETVAL_DOUBLE(deref(0, ret_val, func)->dval);
+ convert_to_string(return_value);
+ break;
+ default:
+ RETVAL_LONG(deref(0, ret_val, func)->lval);
+ convert_to_string(return_value);
+ break;
+ }
+}
+
+static ZEND_RESULT_CODE handle_args(zend_execute_data *execute_data, impl *impl) {
+ impl_arg *iarg;
+
+ if (!impl->func->args->count) {
+ return zend_parse_parameters_none();
+ }
+
+ ZEND_PARSE_PARAMETERS_START(impl_num_min_args(impl), impl->func->args->count)
nextarg:
- iarg = data->impl->func->args->args[_i];
+ iarg = impl->func->args->args[_i];
if (iarg->def) {
Z_PARAM_OPTIONAL;
}
if (PSI_T_BOOL == iarg->type->type) {
if (iarg->def) {
- iarg->val.bval = iarg->def->type == PSI_T_TRUE ? 1 : 0;
+ iarg->val.cval = iarg->def->type == PSI_T_TRUE ? 1 : 0;
}
- Z_PARAM_BOOL(iarg->val.bval);
+ Z_PARAM_BOOL(iarg->val.cval);
} else if (PSI_T_INT == iarg->type->type) {
if (iarg->def) {
iarg->val.lval = zend_atol(iarg->def->text, strlen(iarg->def->text));
}
Z_PARAM_DOUBLE(iarg->val.dval);
} else if (PSI_T_STRING == iarg->type->type) {
+ struct {char *val; size_t len;} str;
if (iarg->def) {
/* FIXME */
- iarg->val.str.len = strlen(iarg->def->text) - 2;
- iarg->val.str.val = &iarg->def->text[1];
+ str.len = strlen(iarg->def->text) - 2;
+ str.val = &iarg->def->text[1];
+ }
+ Z_PARAM_STR_EX(iarg->val.str, 1, 0);
+ if (iarg->val.str) {
+ zend_string_addref(iarg->val.str);
+ } else if (iarg->def) {
+ iarg->val.str = zend_string_init(str.val, str.len, 0);
}
- Z_PARAM_STRING(iarg->val.str.val, iarg->val.str.len);
} else {
error_code = ZPP_ERROR_FAILURE;
break;
if (_i < _max_num_args) {
goto nextarg;
}
- ZEND_PARSE_PARAMETERS_END();
+ ZEND_PARSE_PARAMETERS_END_EX(return FAILURE);
+
+ return SUCCESS;
+}
+
+static impl_val *handle_let(decl_arg *darg, impl_arg *iarg) {
+ impl_val *arg_val = &darg->let->out;
+
+ if (!iarg) {
+ /* let foo = NULL */
+ memset(arg_val, 0, sizeof(*arg_val));
+ return arg_val;
+ }
+ switch (darg->let->val->func->type) {
+ case PSI_T_BOOLVAL:
+ if (iarg->type->type == PSI_T_BOOL) {
+ arg_val->cval = iarg->val.cval;
+ } else {
+ arg_val->cval = zend_is_true(iarg->_zv);
+ }
+ break;
+ case PSI_T_INTVAL:
+ if (iarg->type->type == PSI_T_INT) {
+ arg_val->lval = iarg->val.lval;
+ } else {
+ arg_val->lval = zval_get_long(iarg->_zv);
+ }
+ break;
+ case PSI_T_STRVAL:
+ if (iarg->type->type == PSI_T_STRING) {
+ arg_val->ptr = estrdup(iarg->val.str->val);
+ darg->let->mem = arg_val->ptr;
+ zend_string_release(iarg->val.str);
+ } else {
+ zend_string *zs = zval_get_string(iarg->_zv);
+ arg_val->ptr = estrdup(zs->val);
+ darg->let->mem = arg_val->ptr;
+ zend_string_release(zs);
+ }
+ break;
+ case PSI_T_STRLEN:
+ if (iarg->type->type == PSI_T_STRING) {
+ arg_val->lval = iarg->val.str->len;
+ zend_string_release(iarg->val.str);
+ } else {
+ zend_string *zs = zval_get_string(iarg->_zv);
+ arg_val->lval = zs->len;
+ zend_string_release(zs);
+ }
+ break;
+ EMPTY_SWITCH_DEFAULT_CASE();
+ }
+
+ return arg_val;
+}
+
+static void handle_rval(impl *impl, impl_val *ret_val, zval *return_value) {
+ switch (impl->stmts->ret.list[0]->func->type) {
+ case PSI_T_TO_STRING:
+ to_string(ret_val, impl->decl->func, return_value);
+ break;
+ case PSI_T_TO_INT:
+ to_int(ret_val, impl->decl->func, return_value);
+ break;
+ EMPTY_SWITCH_DEFAULT_CASE();
+ }
+}
+
+static void handle_set(zval *return_value, set_func *func, decl_vars *vars) {
+ impl_val *val = &vars->vars[0]->arg->let->ptr;
+
+ zval_dtor(return_value);
+
+ switch (func->type) {
+ case PSI_T_TO_STRING:
+ to_string(val, vars->vars[0]->arg, return_value);
+ break;
+ EMPTY_SWITCH_DEFAULT_CASE();
+ }
+}
+
+static void handle_free(free_stmt *fre) {
+ size_t i;
+
+ for (i = 0; i < fre->vars->count; ++i) {
+ decl_var *dvar = fre->vars->vars[i];
+
+ if (dvar->arg && dvar->arg->let->out.ptr) {
+ free(dvar->arg->let->out.ptr);
+ dvar->arg->let->out.ptr = NULL;
+ }
+ }
+}
+
+static void handler(jit_type_t _sig, void *result, void **_args, void *_data)
+{
+ PSI_ClosureData *data = _data;
+ size_t i;
+ void **arg_ptr = NULL, **arg_prm = NULL;
+ impl_val ret_val;
+
+ if (SUCCESS != handle_args(*(zend_execute_data **)_args[0], data->impl)) {
+ return;
+ }
if (data->impl->decl->args->count) {
arg_ptr = malloc(data->impl->decl->args->count * sizeof(*arg_ptr));
arg_prm = malloc(data->impl->decl->args->count * sizeof(*arg_prm));
- arg_val = malloc(data->impl->decl->args->count * sizeof(*arg_val));
- sig_prm = malloc(data->impl->decl->args->count * sizeof(*sig_prm));
for (i = 0; i < data->impl->decl->args->count; ++i) {
decl_arg *darg = data->impl->decl->args->args[i];
- impl_arg *iarg = darg->let->arg;
-
- switch (darg->let->val->func->type) {
- case PSI_T_BOOLVAL:
- if (iarg->type->type == PSI_T_BOOL) {
- arg_val[i].bval = iarg->val.bval;
- } else {
- arg_val[i].bval = zend_is_true(iarg->_zv);
- }
- break;
- case PSI_T_INTVAL:
- if (iarg->type->type == PSI_T_INT) {
- arg_val[i].lval = iarg->val.lval;
- } else {
- arg_val[i].lval = zval_get_long(iarg->_zv);
- }
- break;
- case PSI_T_STRVAL:
- if (iarg->type->type == PSI_T_STRING) {
- arg_val[i].str.val = estrndup(iarg->val.str.val, iarg->val.str.len);
- } else {
- zend_string *zs = zval_get_string(iarg->_zv);
- arg_val[i].str.val = estrndup(zs->val, zs->len);
- zend_string_release(zs);
- }
- break;
- case PSI_T_STRLEN:
- if (iarg->type->type == PSI_T_STRING) {
- arg_val[i].lval =iarg->val.str.len;
- } else {
- zend_string *zs = zval_get_string(iarg->_zv);
- arg_val[i].lval = zs->len;
- zend_string_release(zs);
- }
- break;
- }
- arg_ptr[i] = &arg_val[i];
+ impl_arg *iarg = darg->let ? darg->let->arg : NULL;
+
+ arg_ptr[i] = handle_let(darg, iarg);
arg_prm[i] = darg->let->val->is_reference ? &arg_ptr[i] : arg_ptr[i];
- sig_prm[i] = psi_jit_decl_arg_type(darg);
+
+ darg->let->ptr = arg_ptr[i];
}
}
- signature = jit_type_create_signature(
- psi_jit_abi(data->impl->decl->abi->convention),
- psi_jit_decl_arg_type(data->impl->decl->func),
- sig_prm,
- data->impl->decl->args->count,
- 1);
- jit_apply(signature, data->impl->decl->dlptr, arg_prm, data->impl->decl->args->count, &ret_val);
+ jit_apply(data->signature, data->impl->decl->dlptr, arg_prm, data->impl->decl->args->count, &ret_val);
- switch (data->impl->stmts->ret.list[0]->func->type) {
- case PSI_T_TO_STRING:
- if (data->impl->decl->func->var->pointer_level) {
- switch (real_decl_type(data->impl->decl->func->type)->type) {
- case PSI_T_CHAR:
- case PSI_T_SINT8:
- case PSI_T_UINT8:
- RETVAL_STRING(ret_val.str.val);
- break;
+ handle_rval(data->impl, &ret_val, *(zval **)_args[1]);
+
+ for (i = 0; i < data->impl->stmts->set.count; ++i) {
+ set_stmt *set = data->impl->stmts->set.list[i];
+
+ handle_set(set->arg->_zv, set->val->func, set->val->vars);
+ }
+
+ if (data->impl->decl->args->count) {
+ for (i = 0; i < data->impl->decl->args->count; ++i) {
+ decl_arg *darg = data->impl->decl->args->args[i];
+
+ if (darg->let && darg->let->mem) {
+ efree(darg->let->mem);
+ darg->let->mem = NULL;
}
}
- break;
+ free(arg_ptr);
+ free(arg_prm);
}
+
+ for (i = 0; i < data->impl->stmts->fre.count; ++i) {
+ free_stmt *fre = data->impl->stmts->fre.list[i];
+
+ handle_free(fre);
+ }
+}
+
+static inline int fill_type_hint(impl_type *type) {
+ switch (type->type) {
+ case PSI_T_BOOL:
+ return _IS_BOOL;
+ case PSI_T_INT:
+ case PSI_T_LONG:
+ return IS_LONG;
+ case PSI_T_FLOAT:
+ case PSI_T_DOUBLE:
+ return IS_DOUBLE;
+ case PSI_T_STRING:
+ return IS_STRING;
+ case PSI_T_ARRAY:
+ return IS_ARRAY;
+ default:
+ return 0;
+ }
+}
+
+static inline zend_internal_arg_info *fill_arginfo(impl *impl) {
+ size_t i;
+ zend_internal_arg_info *aip;
+ zend_internal_function_info *fi;
+
+ aip = calloc(impl->func->args->count + 1, sizeof(*aip));
+
+ fi = (zend_internal_function_info *) &aip[0];
+ fi->required_num_args = impl_num_min_args(impl);
+ fi->return_reference = impl->func->return_reference;
+ fi->type_hint = fill_type_hint(impl->func->return_type);
+
+ for (i = 0; i < impl->func->args->count; ++i) {
+ impl_arg *iarg = impl->func->args->args[i];
+ zend_internal_arg_info *ai = &aip[i+1];
+
+ ai->name = iarg->var->name;
+ ai->type_hint = fill_type_hint(iarg->type);
+ if (iarg->var->reference) {
+ ai->pass_by_reference = 1;
+ }
+ if (iarg->var->reference || (iarg->def && iarg->def->type == PSI_T_NULL)) {
+ ai->allow_null = 1;
+ }
+ }
+
+ return aip;
}
static zend_function_entry *compile(PSI_Context *C, PSI_Data *D)
};
zend_function_entry *zfe = calloc(D->impls->count + 1, sizeof(*zfe));
- jit_context_build_start(C->opaque);
+ jit_context_build_start(C->context);
for (i = 0; i < D->impls->count; ++i) {
- zend_function_entry *zf;
+ zend_function_entry *zf = &zfe[j];
PSI_ClosureData *data;
if (!D->impls->list[i]->decl) {
continue;
}
- zf = &zfe[j++];
data = PSI_ClosureDataAlloc(C, D->impls->list[i]);
signature = jit_type_create_signature(jit_abi_cdecl, jit_type_void, params, 2, 1);
zf->fname = D->impls->list[i]->func->name + (D->impls->list[i]->func->name[0] == '\\');
- zf->handler = jit_closure_create(C->opaque, signature, &handler, data);
+ zf->handler = jit_closure_create(C->context, signature, &handler, data);
+ zf->num_args = D->impls->list[i]->func->args->count;
+ zf->arg_info = fill_arginfo(D->impls->list[i]);
+ ++j;
}
- jit_context_build_end(C->opaque);
+ jit_context_build_end(C->context);
return zfe;
}
free(defs);
}
+typedef union impl_val {
+ char cval;
+ short sval;
+ int ival;
+ double dval;
+ zend_long lval;
+ zend_string *str;
+ void *ptr;
+} impl_val;
+
typedef struct decl_var {
char *name;
unsigned pointer_level;
+ struct decl_arg *arg;
} decl_var;
static inline decl_var *init_decl_var(char *name, unsigned pl) {
free(def);
}
-typedef union impl_val {
- unsigned char bval;
- zend_long lval;
- double dval;
- struct {
- char *val;
- size_t len;
- } str;
-} impl_val;
-
typedef struct impl_arg {
impl_type *type;
impl_var *var;
char *name;
impl_args *args;
impl_type *return_type;
+ unsigned return_reference:1;
} impl_func;
-static inline impl_func *init_impl_func(char *name, impl_args *args, impl_type *type) {
+static inline impl_func *init_impl_func(char *name, impl_args *args, impl_type *type, int ret_reference) {
impl_func *func = malloc(sizeof(*func));
func->name = strdup(name);
func->args = args ? args : init_impl_args(NULL);
func->return_type = type;
+ func->return_reference = ret_reference;
return func;
}
decl_var *var;
let_value *val;
impl_arg *arg;
+ impl_val out;
+ void *ptr;
+ void *mem;
} let_stmt;
static inline let_stmt *init_let_stmt(decl_var *var, let_value *val) {
- let_stmt *let = malloc(sizeof(*let));
+ let_stmt *let = calloc(1, sizeof(*let));
let->var = var;
let->val = val;
- let->arg = NULL;
return let;
}
typedef struct set_stmt {
impl_var *var;
set_value *val;
+ impl_arg *arg;
} set_stmt;
static inline set_stmt *init_set_stmt(impl_var *var, set_value *val) {
free(set);
}
-typedef struct ret_stmt {
+typedef struct return_stmt {
set_func *func;
decl_var *decl;
-} ret_stmt;
+} return_stmt;
-static inline ret_stmt *init_ret_stmt(set_func *func, decl_var *decl) {
- ret_stmt *ret = malloc(sizeof(*ret));
+static inline return_stmt *init_return_stmt(set_func *func, decl_var *decl) {
+ return_stmt *ret = malloc(sizeof(*ret));
ret->func = func;
ret->decl = decl;
return ret;
}
-static inline void free_ret_stmt(ret_stmt *ret) {
+static inline void free_return_stmt(return_stmt *ret) {
free_set_func(ret->func);
free_decl_var(ret->decl);
free(ret);
}
+typedef struct free_stmt {
+ decl_vars *vars;
+} free_stmt;
+
+static inline free_stmt *init_free_stmt(decl_vars *vars) {
+ free_stmt *free_ = malloc(sizeof(*free_));
+ free_->vars = vars;
+ return free_;
+}
+
+static inline void free_free_stmt(free_stmt *free_) {
+ free_decl_vars(free_->vars);
+ free(free_);
+}
+
typedef struct impl_stmt {
token_t type;
union {
let_stmt *let;
set_stmt *set;
- ret_stmt *ret;
+ return_stmt *ret;
+ free_stmt *fre;
void *ptr;
} s;
} impl_stmt;
case PSI_T_SET:
free_set_stmt(stmt->s.set);
break;
- case PSI_T_RET:
- free_ret_stmt(stmt->s.ret);
+ case PSI_T_RETURN:
+ free_return_stmt(stmt->s.ret);
+ break;
+ case PSI_T_FREE:
+ free_free_stmt(stmt->s.fre);
break;
}
free(stmt);
typedef struct impl_stmts {
struct {
- ret_stmt **list;
+ return_stmt **list;
size_t count;
} ret;
struct {
set_stmt **list;
size_t count;
} set;
+ struct {
+ free_stmt **list;
+ size_t count;
+ } fre;
} impl_stmts;
static inline void *add_impl_stmt_ex(void *list, size_t count, void *stmt) {
static inline impl_stmts *add_impl_stmt(impl_stmts *stmts, impl_stmt *stmt) {
switch (stmt->type) {
- case PSI_T_RET:
+ case PSI_T_RETURN:
stmts->ret.list = add_impl_stmt_ex(stmts->ret.list, ++stmts->ret.count, stmt->s.ret);
break;
case PSI_T_LET:
case PSI_T_SET:
stmts->set.list = add_impl_stmt_ex(stmts->set.list, ++stmts->set.count, stmt->s.set);
break;
+ case PSI_T_FREE:
+ stmts->fre.list = add_impl_stmt_ex(stmts->fre.list, ++stmts->fre.count, stmt->s.fre);
+ break;
}
return stmts;
}
}
free(stmts->let.list);
for (i = 0; i < stmts->ret.count; ++i) {
- free_ret_stmt(stmts->ret.list[i]);
+ free_return_stmt(stmts->ret.list[i]);
}
free(stmts->ret.list);
for (i = 0; i < stmts->set.count; ++i) {
free_set_stmt(stmts->set.list[i]);
}
free(stmts->set.list);
+ for (i = 0; i < stmts->fre.count; ++i) {
+ free_free_stmt(stmts->fre.list[i]);
+ }
+ free(stmts->fre.list);
free(stmts);
}
}
return 1;
}
+static const char * const abi_ccs[] = {
+ "default", /* \ */
+ "extern", /* > - all the same */
+ "cdecl", /* / */
+ "stdcall",
+ "fastcall",
+};
static inline int validate_decl_abi(PSI_Validator *V, decl_abi *abi) {
- if (strcasecmp(abi->convention, "default")) {
- V->error(PSI_WARNING, "Invalid calling convention: '%s'", abi->convention);
- return 0;
+ size_t i;
+
+ for (i = 0; i < sizeof(abi_ccs)/sizeof(char*); ++ i) {
+ if (strcasecmp(abi->convention, abi_ccs[i])) {
+ return 1;
+ }
}
- /* FIXME */
- return 1;
+ V->error(PSI_WARNING, "Invalid calling convention: '%s'", abi->convention);
+ return 0;
}
static inline int validate_decl_arg(PSI_Validator *V, decl *decl, decl_arg *arg) {
if (!validate_decl_type(V, arg, arg->type)) {
}
return 1;
}
-static inline decl *locate_impl_decl(decls *decls, ret_stmt *ret) {
+static inline decl *locate_impl_decl(decls *decls, return_stmt *ret) {
size_t i;
for (i = 0; i < decls->count; ++i) {
/* okay,
* - we must have exactly one ret stmt delcaring the native func to call and which type cast to apply
* - we can have multiple let stmts; every arg of the ret stmts var (the function to call) must have one
- * - we can have any count of set stmts; processing out vars, etc.
+ * - we can have any count of set stmts; processing out vars
+ * - we can have any count of free stmts; freeing any out vars
*/
- size_t i, j;
- ret_stmt *ret;
+ size_t i, j, k;
+ return_stmt *ret;
decl *decl;
if (!stmts) {
}
}
}
+ /* check that set stmts reference known variables */
+ for (i = 0; i < stmts->set.count; ++i) {
+ set_stmt *set = stmts->set.list[i];
+ int check = 0;
+
+ for (j = 0; j < impl->func->args->count; ++j) {
+ impl_arg *iarg = impl->func->args->args[j];
+
+ if (!strcmp(set->var->name, iarg->var->name)) {
+ set->arg = iarg;
+ check = 1;
+ break;
+ }
+ }
+ if (!check) {
+ V->error(PSI_WARNING, "Unknown variable '$%s' of `set` statement"
+ " of implementation '%s'",
+ set->var->name, impl->func->name);
+ return 0;
+ }
+
+ for (j = 0; j < set->val->vars->count; ++j) {
+ decl_var *set_var = set->val->vars->vars[j];
+
+ check = 0;
+ for (k = 0; k < decl->args->count; ++k) {
+ decl_arg *set_arg = decl->args->args[k];
+
+ if (!strcmp(set_var->name, set_arg->var->name)) {
+ check = 1;
+ set_var->arg = set_arg;
+ break;
+ }
+ }
+
+ if (!check) {
+ V->error(PSI_WARNING, "Unknown value '%s' of `set` statement"
+ " for variable '$%s' of implementation '%s'",
+ set_var->name, set->arg->var->name, impl->func->name);
+ return 0;
+ }
+ }
+ }
+ /* check free stmts */
+ for (i = 0; i < stmts->fre.count; ++i) {
+ free_stmt *fre = stmts->fre.list[i];
+
+ for (j = 0; j < fre->vars->count; ++j) {
+ decl_var *free_var = fre->vars->vars[j];
+ int check = 0;
+
+ if (!strcmp(free_var->name, decl->func->var->name)) {
+ continue;
+ }
+ for (k = 0; k < decl->args->count; ++k) {
+ decl_arg *free_arg = decl->args->args[k];
+
+ if (!strcmp(free_var->name, free_arg->var->name)) {
+ check = 1;
+ free_var->arg = free_arg;
+ break;
+ }
+ }
+
+ if (!check) {
+ V->error(PSI_WARNING, "Unknown variable '%s' of `free` statement"
+ " of implementation '%s'",
+ free_var->name, impl->func->name);
+ return 0;
+ }
+ }
+ }
impl->decl = decl;