From: Michael Wallner Date: Tue, 22 Dec 2015 08:19:58 +0000 (+0100) Subject: flush X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=6bc2d7ee8421401fc11225e09e4bb1fab03594b8;p=m6w6%2Fext-psi flush --- diff --git a/src/context.c b/src/context.c index 3c86f99..709c6b4 100644 --- a/src/context.c +++ b/src/context.c @@ -734,6 +734,11 @@ static inline int validate_impl_let_stmts(PSI_Data *data, impl *impl) { return 0; } } + if (let->val && let->val->num) { + if (!validate_num_exp(data, impl->decl->args, impl->decl->func, let->val->num)) { + return 0; + } + } } return 1; } diff --git a/src/module.c b/src/module.c index 57c9399..9d97a3e 100644 --- a/src/module.c +++ b/src/module.c @@ -598,26 +598,25 @@ static inline void *psi_do_calloc(let_calloc *alloc) static inline void *psi_do_let(let_stmt *let) { decl_arg *darg = let->var->arg; - impl_arg *iarg = darg->let->arg; impl_val *arg_val = darg->ptr; - if (!iarg) { - /* let foo = calloc(1, long); - * let foo = NULL; - * let foo; - */ - if (darg->let->val->func && darg->let->val->func->type == PSI_T_CALLOC) { - arg_val->ptr = psi_do_calloc(darg->let->val->func->alloc); - darg->mem = arg_val->ptr; - } else if (darg->var->array_size) { + if (!let->val) { + if (darg->var->array_size) { arg_val->ptr = ecalloc(darg->var->array_size, sizeof(*arg_val)); darg->mem = arg_val->ptr; } else { memset(arg_val, 0, sizeof(*arg_val)); } + } else if (let->val->num) { + arg_val->zend.lval = psi_long_num_exp(darg->let->val->num, NULL); } else { + impl_arg *iarg = darg->let->arg; - switch (darg->let->val->func->type) { + switch (let->val->func->type) { + case PSI_T_CALLOC: + arg_val->ptr = psi_do_calloc(let->val->func->alloc); + darg->mem = arg_val->ptr; + break; case PSI_T_BOOLVAL: if (iarg->type->type == PSI_T_BOOL) { arg_val->cval = iarg->val.zend.bval; @@ -707,11 +706,6 @@ static inline void psi_do_return(zval *return_value, return_stmt *ret) ret->set->func->handler(return_value, ret->set, ret->set->vars->vars[0]->arg->ptr); } -static inline void psi_do_return2(zval *return_value, return_stmt *ret, impl_val *ret_val) -{ - ret->set->func->handler(return_value, ret->set, ret_val); -} - static inline void psi_do_free(free_stmt *fre) { size_t i, j; diff --git a/src/parser.h b/src/parser.h index 4df5354..0bac3ef 100644 --- a/src/parser.h +++ b/src/parser.h @@ -639,6 +639,7 @@ static inline void free_let_func(let_func *func) { typedef struct let_value { let_func *func; impl_var *var; + num_exp *num; unsigned is_reference:1; } let_value; diff --git a/src/parser_proc.y b/src/parser_proc.y index c90062a..06e4be5 100644 --- a/src/parser_proc.y +++ b/src/parser_proc.y @@ -349,6 +349,24 @@ impl_stmt(stmt) ::= free_stmt(free). { stmt = init_impl_stmt(PSI_T_FREE, free); } +%token_class num_exp_token NUMBER NSNAME. +%token_class num_exp_op_token PLUS MINUS ASTERISK SLASH. +%type num_exp {num_exp*} +%destructor num_exp {free_num_exp($$);} +num_exp(exp) ::= num_exp_token(tok). { + exp = init_num_exp(tok->type, tok->text); + free(tok); +} +num_exp(exp) ::= decl_var(var). { + exp = init_num_exp(PSI_T_NAME, var); +} +num_exp(exp) ::= num_exp(exp_) num_exp_op_token(operator_) num_exp(operand_). { + exp_->operator = operator_->type; + exp_->operand = operand_; + exp = exp_; + free(operator_); +} + %type let_stmt {let_stmt*} %destructor let_stmt {free_let_stmt($$);} let_stmt(let) ::= LET decl_var(var) EOS. { @@ -357,38 +375,26 @@ let_stmt(let) ::= LET decl_var(var) EOS. { let_stmt(let) ::= LET decl_var(var) EQUALS let_value(val) EOS. { let = init_let_stmt(var, val); } +let_stmt(let) ::= decl_arg(arg) EQUALS decl_var(var_) EOS. { + let = init_let_stmt(arg->var, NULL); +} %type let_value {let_value*} %destructor let_value {free_let_value($$);} -let_value(val) ::= CALLOC(F) LPAREN let_calloc(alloc) RPAREN. { - val = init_let_value(init_let_func(F->type, F->text, alloc), NULL, 0); +let_value(val) ::= reference(r) CALLOC(F) LPAREN let_calloc(alloc) RPAREN. { + val = init_let_value(init_let_func(F->type, F->text, alloc), NULL, r); free(F); } - %type let_calloc {let_calloc*} %destructor let_calloc {free_let_calloc($$);} let_calloc(alloc) ::= num_exp(nmemb) COMMA num_exp(size). { alloc = init_let_calloc(nmemb, size); } -%token_class num_exp_token NUMBER NSNAME. -%token_class num_exp_op_token PLUS MINUS ASTERISK SLASH. -%type num_exp {num_exp*} -%destructor num_exp {free_num_exp($$);} -num_exp(exp) ::= num_exp_token(tok). { - exp = init_num_exp(tok->type, tok->text); - free(tok); -} -num_exp(exp) ::= decl_var(var). { - exp = init_num_exp(PSI_T_NAME, var); -} -num_exp(exp) ::= num_exp(exp_) num_exp_op_token(operator_) num_exp(operand_). { - exp_->operator = operator_->type; - exp_->operand = operand_; - exp = exp_; - free(operator_); +let_value(val) ::= reference(r) num_exp(exp). { + val = init_let_value(NULL, NULL, r); + val->num = exp; } - let_value(val) ::= reference(r) let_func(func) LPAREN impl_var(var) RPAREN. { val = init_let_value(func, var, r); }