From 6af43d341ce260ffd7d5d443bc0b535692d5f67e Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Thu, 22 Oct 2015 10:35:14 +0200 Subject: [PATCH] flush --- php_psi.h | 1 + src/module.c | 5 +++++ src/parser.h | 4 +++- src/parser.re | 4 ++++ src/parser_proc.y | 14 ++++++++++++-- 5 files changed, 25 insertions(+), 3 deletions(-) diff --git a/php_psi.h b/php_psi.h index 29ecd28..3e582d0 100644 --- a/php_psi.h +++ b/php_psi.h @@ -27,6 +27,7 @@ int psi_internal_type(impl_type *type); zend_internal_arg_info *psi_internal_arginfo(impl *impl); size_t psi_num_min_args(impl *impl); void psi_to_int(impl_val *ret_val, decl_arg *func, zval *return_value); +void psi_to_double(impl_val *ret_val, decl_arg *func, zval *return_value); void psi_to_string(impl_val *ret_val, decl_arg *func, zval *return_value); ZEND_RESULT_CODE psi_parse_args(zend_execute_data *execute_data, impl *impl); impl_val *psi_do_let(decl_arg *darg); diff --git a/src/module.c b/src/module.c index 1665964..57fe9d6 100644 --- a/src/module.c +++ b/src/module.c @@ -107,6 +107,11 @@ void psi_to_int(impl_val *ret_val, decl_arg *func, zval *return_value) } } +void psi_to_double(impl_val *ret_val, decl_arg *func, zval *return_value) +{ + RETVAL_DOUBLE(deref_impl_val(0, ret_val, func)->dval); +} + void psi_to_string(impl_val *ret_val, decl_arg *func, zval *return_value) { switch (real_decl_type(func->type)->type) { diff --git a/src/parser.h b/src/parser.h index 9709a1d..ff0d4d6 100644 --- a/src/parser.h +++ b/src/parser.h @@ -92,13 +92,15 @@ static void free_decl_typedefs(decl_typedefs *defs) { typedef struct decl_var { char *name; unsigned pointer_level; + unsigned array_size; struct decl_arg *arg; } decl_var; -static inline decl_var *init_decl_var(char *name, unsigned pl) { +static inline decl_var *init_decl_var(char *name, unsigned pl, unsigned as) { decl_var *v = malloc(sizeof(*v)); v->name = (char *) strdup((const char *) name); v->pointer_level = pl; + v->array_size = as; return v; } diff --git a/src/parser.re b/src/parser.re index 0d13d79..1e106cd 100644 --- a/src/parser.re +++ b/src/parser.re @@ -217,6 +217,7 @@ token_t PSI_ParserScan(PSI_Parser *P) TO_FLOAT = 'to_float'; TO_BOOL = 'to_bool'; NUMBER = [+-]? [0-9]* "."? [0-9]+ ([eE] [+-]? [0-9]+)?; + DIGITS = [0-9]+; "#" .* "\n" { ++P->line; RETURN(PSI_T_COMMENT);} "(" {RETURN(PSI_T_LPAREN);} @@ -226,6 +227,8 @@ token_t PSI_ParserScan(PSI_Parser *P) ":" {RETURN(PSI_T_COLON);} "{" {RETURN(PSI_T_LBRACE);} "}" {RETURN(PSI_T_RBRACE);} + "[" {RETURN(PSI_T_LBRACKET);} + "]" {RETURN(PSI_T_RBRACKET);} "=" {RETURN(PSI_T_EQUALS);} "$" {RETURN(PSI_T_DOLLAR);} "*" {RETURN(PSI_T_POINTER);} @@ -272,6 +275,7 @@ token_t PSI_ParserScan(PSI_Parser *P) TO_FLOAT {RETURN(PSI_T_TO_FLOAT);} TO_BOOL {RETURN(PSI_T_TO_BOOL);} NUMBER {RETURN(PSI_T_NUMBER);} + DIGITS {RETURN(PSI_T_DIGITS);} NAME {RETURN(PSI_T_NAME);} NSNAME {RETURN(PSI_T_NSNAME);} QUOTED_STRING {RETURN(PSI_T_QUOTED_STRING);} diff --git a/src/parser_proc.y b/src/parser_proc.y index 85fac69..ed8b1b4 100644 --- a/src/parser_proc.y +++ b/src/parser_proc.y @@ -89,13 +89,23 @@ decl_abi(abi) ::= NAME(T). { %type decl_var {decl_var*} decl_var(var) ::= NAME(T). { - var = init_decl_var(T->text, 0); + var = init_decl_var(T->text, 0, 0); free(T); } decl_var(var) ::= pointers(p) NAME(T). { - var = init_decl_var(T->text, p); + var = init_decl_var(T->text, p, 0); free(T); } +decl_var(var) ::= NAME(T) LBRACKET DIGITS(D) RBRACKET. { + var = init_decl_var(T->text, 1, atol(D->text)); + free(T); + free(D); +} +decl_var(var) ::= pointers(p) NAME(T) LBRACKET DIGITS(D) RBRACKET. { + var = init_decl_var(T->text, p+1, atol(D->text)); + free(T); + free(D); +} %type decl_vars {decl_vars*} decl_vars(vars) ::= decl_var(var). { -- 2.30.2