From e8a409b21cb50f5931ab02ce6ab4f4406be94394 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Fri, 12 Feb 2016 15:49:17 +0100 Subject: [PATCH] zval passthru --- src/context_validate.c | 30 +++------- src/marshal.c | 12 ++++ src/marshal.h | 2 + src/parser.h | 2 +- src/parser.re | 1 + src/parser_proc.h | 129 +++++++++++++++++++++-------------------- src/parser_proc.y | 6 +- 7 files changed, 93 insertions(+), 89 deletions(-) diff --git a/src/context_validate.c b/src/context_validate.c index 435dc2d..180b34d 100644 --- a/src/context_validate.c +++ b/src/context_validate.c @@ -724,27 +724,14 @@ static inline int validate_decl_enum(PSI_Data *data, decl_enum *e) { static inline int validate_set_value_handler(set_value *set) { switch (set->func->type) { - case PSI_T_TO_BOOL: - set->func->handler = psi_to_bool; - break; - case PSI_T_TO_INT: - set->func->handler = psi_to_int; - break; - case PSI_T_TO_FLOAT: - set->func->handler = psi_to_double; - break; - case PSI_T_TO_STRING: - set->func->handler = psi_to_string; - break; - case PSI_T_TO_ARRAY: - set->func->handler = psi_to_array; - break; - case PSI_T_TO_OBJECT: - set->func->handler = psi_to_object; - break; - case PSI_T_VOID: - set->func->handler = psi_to_void; - break; + case PSI_T_TO_BOOL: set->func->handler = psi_to_bool; break; + case PSI_T_TO_INT: set->func->handler = psi_to_int; break; + case PSI_T_TO_FLOAT: set->func->handler = psi_to_double; break; + case PSI_T_TO_STRING: set->func->handler = psi_to_string; break; + case PSI_T_TO_ARRAY: set->func->handler = psi_to_array; break; + case PSI_T_TO_OBJECT: set->func->handler = psi_to_object; break; + case PSI_T_VOID: set->func->handler = psi_to_void; break; + case PSI_T_ZVAL: set->func->handler = psi_to_zval; break; case PSI_T_ELLIPSIS: if (set->outer.set && set->outer.set->func->type == PSI_T_TO_ARRAY) { set->func->handler = psi_to_recursive; @@ -943,6 +930,7 @@ static inline int validate_let_func(PSI_Data *data, let_func *func, impl *impl) case PSI_T_PATHVAL: func->handler = psi_let_pathval; break; case PSI_T_ARRVAL: func->handler = psi_let_arrval; break; case PSI_T_OBJVAL: func->handler = psi_let_objval; break; + case PSI_T_ZVAL: func->handler = psi_let_zval; break; EMPTY_SWITCH_DEFAULT_CASE(); } return 1; diff --git a/src/marshal.c b/src/marshal.c index 31ff9ba..f204753 100644 --- a/src/marshal.c +++ b/src/marshal.c @@ -13,6 +13,17 @@ void psi_to_void(zval *return_value, set_value *set, impl_val *ret_val) RETVAL_NULL(); } +void psi_to_zval(zval *return_value, set_value *set, impl_val *ret_val) { + RETVAL_ZVAL(ret_val->ptr, 1, 0); +} + +impl_val *psi_let_zval(impl_val *tmp, decl_type *type, impl_arg *iarg, void **to_free) +{ + *to_free = tmp->ptr = emalloc(sizeof(zval)); + ZVAL_COPY_VALUE(tmp->ptr, iarg->_zv); + return tmp; +} + void psi_to_bool(zval *return_value, set_value *set, impl_val *ret_val) { psi_to_int(return_value, set, ret_val); @@ -526,3 +537,4 @@ impl_val *psi_let_objval(impl_val *tmp, decl_type *type, impl_arg *iarg, void ** return tmp; } + diff --git a/src/marshal.h b/src/marshal.h index a6028dc..47402e4 100644 --- a/src/marshal.h +++ b/src/marshal.h @@ -9,6 +9,7 @@ void psi_to_string(zval *return_value, set_value *set, impl_val *ret_val); void psi_to_recursive(zval *return_value, set_value *set, impl_val *r_val); void psi_to_array(zval *return_value, set_value *set, impl_val *ret_val); void psi_to_object(zval *return_value, set_value *set, impl_val *ret_val); +void psi_to_zval(zval *return_value, set_value *set, impl_val *ret_val); void *psi_array_to_struct(decl_struct *s, HashTable *arr); void psi_from_zval(impl_val *mem, decl_arg *spec, zval *zv, void **tmp); @@ -21,5 +22,6 @@ impl_val *psi_let_pathval(impl_val *tmp, decl_type *type, impl_arg *iarg, void * impl_val *psi_let_strlen(impl_val *tmp, decl_type *type, impl_arg *iarg, void **to_free); impl_val *psi_let_arrval(impl_val *tmp, decl_type *type, impl_arg *iarg, void **to_free); impl_val *psi_let_objval(impl_val *tmp, decl_type *type, impl_arg *iarg, void **to_free); +impl_val *psi_let_zval(impl_val *tmp, decl_type *type, impl_arg *iarg, void **to_free); #endif diff --git a/src/parser.h b/src/parser.h index 0041155..f16f8b8 100644 --- a/src/parser.h +++ b/src/parser.h @@ -59,8 +59,8 @@ typedef union impl_val { zend_string *str; zend_fcall *cb; } zend; + zval zval; void *ptr; - uint8_t _dbg[sizeof(void *)]; } impl_val; typedef struct decl_type { diff --git a/src/parser.re b/src/parser.re index 25bb565..61c328d 100644 --- a/src/parser.re +++ b/src/parser.re @@ -235,6 +235,7 @@ token_t PSI_ParserScan(PSI_Parser *P) 'BOOLVAL' {RETURN(PSI_T_BOOLVAL);} 'ARRVAL' {RETURN(PSI_T_ARRVAL);} 'OBJVAL' {RETURN(PSI_T_OBJVAL);} + 'ZVAL' {RETURN(PSI_T_ZVAL);} 'CALLOC' {RETURN(PSI_T_CALLOC);} 'TO_OBJECT' {RETURN(PSI_T_TO_OBJECT);} 'TO_ARRAY' {RETURN(PSI_T_TO_ARRAY);} diff --git a/src/parser_proc.h b/src/parser_proc.h index d7f28a2..0ccde26 100644 --- a/src/parser_proc.h +++ b/src/parser_proc.h @@ -10,67 +10,68 @@ #define PSI_T_RETURN 10 #define PSI_T_CALLOC 11 #define PSI_T_CALLBACK 12 -#define PSI_T_LIB 13 -#define PSI_T_STRING 14 -#define PSI_T_EOF 15 -#define PSI_T_EOS 16 -#define PSI_T_QUOTED_STRING 17 -#define PSI_T_ENUM 18 -#define PSI_T_LBRACE 19 -#define PSI_T_RBRACE 20 -#define PSI_T_COMMA 21 -#define PSI_T_EQUALS 22 -#define PSI_T_UNION 23 -#define PSI_T_STRUCT 24 -#define PSI_T_COLON 25 -#define PSI_T_LPAREN 26 -#define PSI_T_NUMBER 27 -#define PSI_T_RPAREN 28 -#define PSI_T_BOOL 29 -#define PSI_T_INT 30 -#define PSI_T_FLOAT 31 -#define PSI_T_CONST 32 -#define PSI_T_NSNAME 33 -#define PSI_T_TYPEDEF 34 -#define PSI_T_VOID 35 -#define PSI_T_LBRACKET 36 -#define PSI_T_RBRACKET 37 -#define PSI_T_ELLIPSIS 38 -#define PSI_T_CHAR 39 -#define PSI_T_SHORT 40 -#define PSI_T_LONG 41 -#define PSI_T_DOUBLE 42 -#define PSI_T_UNSIGNED 43 -#define PSI_T_SIGNED 44 -#define PSI_T_INT8 45 -#define PSI_T_UINT8 46 -#define PSI_T_INT16 47 -#define PSI_T_UINT16 48 -#define PSI_T_INT32 49 -#define PSI_T_UINT32 50 -#define PSI_T_INT64 51 -#define PSI_T_UINT64 52 -#define PSI_T_FUNCTION 53 -#define PSI_T_NULL 54 -#define PSI_T_TRUE 55 -#define PSI_T_FALSE 56 -#define PSI_T_DOLLAR_NAME 57 -#define PSI_T_OBJVAL 58 -#define PSI_T_ARRVAL 59 -#define PSI_T_PATHVAL 60 -#define PSI_T_STRLEN 61 -#define PSI_T_STRVAL 62 -#define PSI_T_FLOATVAL 63 -#define PSI_T_INTVAL 64 -#define PSI_T_BOOLVAL 65 -#define PSI_T_TO_OBJECT 66 -#define PSI_T_TO_ARRAY 67 -#define PSI_T_TO_STRING 68 -#define PSI_T_TO_INT 69 -#define PSI_T_TO_FLOAT 70 -#define PSI_T_TO_BOOL 71 -#define PSI_T_MIXED 72 -#define PSI_T_ARRAY 73 -#define PSI_T_OBJECT 74 -#define PSI_T_CALLABLE 75 -#define PSI_T_AMPERSAND 76 +#define PSI_T_ZVAL 13 +#define PSI_T_LIB 14 +#define PSI_T_STRING 15 +#define PSI_T_EOF 16 +#define PSI_T_EOS 17 +#define PSI_T_QUOTED_STRING 18 +#define PSI_T_ENUM 19 +#define PSI_T_LBRACE 20 +#define PSI_T_RBRACE 21 +#define PSI_T_COMMA 22 +#define PSI_T_EQUALS 23 +#define PSI_T_UNION 24 +#define PSI_T_STRUCT 25 +#define PSI_T_COLON 26 +#define PSI_T_LPAREN 27 +#define PSI_T_NUMBER 28 +#define PSI_T_RPAREN 29 +#define PSI_T_BOOL 30 +#define PSI_T_INT 31 +#define PSI_T_FLOAT 32 +#define PSI_T_CONST 33 +#define PSI_T_NSNAME 34 +#define PSI_T_TYPEDEF 35 +#define PSI_T_VOID 36 +#define PSI_T_LBRACKET 37 +#define PSI_T_RBRACKET 38 +#define PSI_T_ELLIPSIS 39 +#define PSI_T_CHAR 40 +#define PSI_T_SHORT 41 +#define PSI_T_LONG 42 +#define PSI_T_DOUBLE 43 +#define PSI_T_UNSIGNED 44 +#define PSI_T_SIGNED 45 +#define PSI_T_INT8 46 +#define PSI_T_UINT8 47 +#define PSI_T_INT16 48 +#define PSI_T_UINT16 49 +#define PSI_T_INT32 50 +#define PSI_T_UINT32 51 +#define PSI_T_INT64 52 +#define PSI_T_UINT64 53 +#define PSI_T_FUNCTION 54 +#define PSI_T_NULL 55 +#define PSI_T_TRUE 56 +#define PSI_T_FALSE 57 +#define PSI_T_DOLLAR_NAME 58 +#define PSI_T_OBJVAL 59 +#define PSI_T_ARRVAL 60 +#define PSI_T_PATHVAL 61 +#define PSI_T_STRLEN 62 +#define PSI_T_STRVAL 63 +#define PSI_T_FLOATVAL 64 +#define PSI_T_INTVAL 65 +#define PSI_T_BOOLVAL 66 +#define PSI_T_TO_OBJECT 67 +#define PSI_T_TO_ARRAY 68 +#define PSI_T_TO_STRING 69 +#define PSI_T_TO_INT 70 +#define PSI_T_TO_FLOAT 71 +#define PSI_T_TO_BOOL 72 +#define PSI_T_MIXED 73 +#define PSI_T_ARRAY 74 +#define PSI_T_OBJECT 75 +#define PSI_T_CALLABLE 76 +#define PSI_T_AMPERSAND 77 diff --git a/src/parser_proc.y b/src/parser_proc.y index 50d54da..6a582cb 100644 --- a/src/parser_proc.y +++ b/src/parser_proc.y @@ -29,7 +29,7 @@ void psi_error(int, const char *, int, const char *, ...); %nonassoc NAME. %left PLUS MINUS. %left SLASH ASTERISK. -%fallback NAME TEMP FREE SET LET RETURN CALLOC CALLBACK LIB STRING. +%fallback NAME TEMP FREE SET LET RETURN CALLOC CALLBACK ZVAL LIB STRING. file ::= blocks. @@ -705,7 +705,7 @@ let_stmt(let) ::= TEMP decl_var(var) EQUALS decl_var(val) EOS. { let_calloc(alloc) ::= num_exp(nmemb) COMMA num_exp(size). { alloc = init_let_calloc(nmemb, size); } -%token_class let_func_token OBJVAL ARRVAL PATHVAL STRLEN STRVAL FLOATVAL INTVAL BOOLVAL. +%token_class let_func_token ZVAL OBJVAL ARRVAL PATHVAL STRLEN STRVAL FLOATVAL INTVAL BOOLVAL. %type let_func {let_func*} %destructor let_func {free_let_func($$);} let_func(func) ::= let_func_token(T) LPAREN impl_var(var) RPAREN. { @@ -789,7 +789,7 @@ set_vals(vals) ::= set_vals(vals_) COMMA set_value(val). { vals = add_inner_set_value(vals_, val); } -%token_class set_func_token TO_OBJECT TO_ARRAY TO_STRING TO_INT TO_FLOAT TO_BOOL VOID. +%token_class set_func_token TO_OBJECT TO_ARRAY TO_STRING TO_INT TO_FLOAT TO_BOOL ZVAL VOID. %type set_func {set_func*} %destructor set_func {free_set_func($$);} set_func(func) ::= set_func_token(T). { -- 2.30.2