From b1c7c64ca1d1d9dc79a59c0f612bd07e7a997a60 Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Tue, 20 Nov 2018 17:00:59 +0100 Subject: [PATCH] fix gdbinit; postprocessing macros --- .gdbinit | 64 ++++++++++++++++++++++----------------------- src/data.h | 10 ++++++- src/parser.c | 9 ++----- src/types/num_exp.c | 2 +- 4 files changed, 44 insertions(+), 41 deletions(-) diff --git a/.gdbinit b/.gdbinit index 9aad1bc..4e73683 100644 --- a/.gdbinit +++ b/.gdbinit @@ -1,130 +1,130 @@ define psi_assert_stmt_dump - call psi_assert_stmt_dump(1, $arg0) + call psi_assert_stmt_dump((void*)0, $arg0) echo \n end define psi_const_dump - call psi_const_dump(1, $arg0) + call psi_const_dump((void*)0, $arg0) echo \n end define psi_const_type_dump - call psi_const_type_dump(1, $arg0) + call psi_const_type_dump((void*)0, $arg0) echo \n end define psi_decl_abi_dump - call psi_decl_abi_dump(1, $arg0) + call psi_decl_abi_dump((void*)0, $arg0) echo \n end define psi_decl_arg_dump - call psi_decl_arg_dump(1, $arg0, 0) + call psi_decl_arg_dump((void*)0, $arg0, 0) echo \n end define psi_decl_enum_dump - call psi_decl_enum_dump(1, $arg0, 0) + call psi_decl_enum_dump((void*)0, $arg0, 0) echo \n end define psi_decl_enum_item_dump - call psi_decl_enum_item_dump(1, $arg0) + call psi_decl_enum_item_dump((void*)0, $arg0) echo \n end define psi_decl_dump - call psi_decl_dump(1, $arg0) + call psi_decl_dump((void*)0, $arg0) echo \n end define psi_decl_struct_dump - call psi_decl_struct_dump(1, $arg0) + call psi_decl_struct_dump((void*)0, $arg0) echo \n end define psi_decl_type_dump - call psi_decl_type_dump(1, $arg0, 0) + call psi_decl_type_dump((void*)0, $arg0, 0) echo \n end define psi_decl_type_dump_args_with_layout - call psi_decl_type_dump_args_with_layout(1, $arg0, 0) + call psi_decl_type_dump_args_with_layout((void*)0, $arg0, 0) echo \n end define psi_decl_union_dump - call psi_decl_union_dump(1, $arg0) + call psi_decl_union_dump((void*)0, $arg0) echo \n end define psi_decl_var_dump - call psi_decl_var_dump(1, $arg0) + call psi_decl_var_dump((void*)0, $arg0) echo \n end define psi_free_exp_dump - call psi_free_exp_dump(1, $arg0) + call psi_free_exp_dump((void*)0, $arg0) echo \n end define psi_free_stmt_dump - call psi_free_stmt_dump(1, $arg0) + call psi_free_stmt_dump((void*)0, $arg0) echo \n end define psi_impl_arg_dump - call psi_impl_arg_dump(1, $arg0) + call psi_impl_arg_dump((void*)0, $arg0) echo \n end define psi_impl_def_val_dump - call psi_impl_def_val_dump(1, $arg0) + call psi_impl_def_val_dump((void*)0, $arg0) echo \n end define psi_impl_func_dump - call psi_impl_func_dump(1, $arg0) + call psi_impl_func_dump((void*)0, $arg0) echo \n end define psi_impl_dump - call psi_impl_dump(1, $arg0) + call psi_impl_dump((void*)0, $arg0) echo \n end define psi_let_callback_dump - call psi_let_callback_dump(1, $arg0, 0) + call psi_let_callback_dump((void*)0, $arg0, 0) echo \n end define psi_let_calloc_dump - call psi_let_calloc_dump(1, $arg0) + call psi_let_calloc_dump((void*)0, $arg0) echo \n end define psi_let_exp_dump - call psi_let_exp_dump(1, $arg0, 0) + call psi_let_exp_dump((void*)0, $arg0, 0) echo \n end define psi_let_func_dump - call psi_let_func_dump(1, $arg0, 0) + call psi_let_func_dump((void*)0, $arg0, 0) echo \n end define psi_let_stmt_dump - call psi_let_stmt_dump(1, $arg0) + call psi_let_stmt_dump((void*)0, $arg0) echo \n end define psi_number_dump - call psi_number_dump(1, $arg0) + call psi_number_dump((void*)0, $arg0) echo \n end define psi_num_exp_dump - call psi_num_exp_dump(1, $arg0) + call psi_num_exp_dump((void*)0, $arg0) echo \n end define psi_return_stmt_dump - call psi_return_stmt_dump(1, $arg0) + call psi_return_stmt_dump((void*)0, $arg0) echo \n end define psi_set_exp_dump - call psi_set_exp_dump(1, $arg0, 0, 0) + call psi_set_exp_dump((void*)0, $arg0, 0, 0) echo \n end define psi_set_func_dump - call psi_set_func_dump(1, $arg0, 0) + call psi_set_func_dump((void*)0, $arg0, 0) echo \n end define psi_set_stmt_dump - call psi_set_stmt_dump(1, $arg0) + call psi_set_stmt_dump((void*)0, $arg0) echo \n end define psi_token_dump - call psi_token_dump(1, $arg0) + call psi_token_dump((void*)0, $arg0) end define psi_token_list_dump set $i = 0 while $i < $arg0->count - call psi_token_dump(1, ((struct psi_token **)$arg0->list)[$i++]) + call psi_token_dump((void*)0, ((struct psi_token **)$arg0->list)[$i++]) end end define psi_plist_dump diff --git a/src/data.h b/src/data.h index 6ab3490..9f41936 100644 --- a/src/data.h +++ b/src/data.h @@ -95,7 +95,15 @@ struct psi_dump { union psi_dump_arg ctx; psi_dump_cb fun; }; -#define PSI_DUMP(dump, ...) (dump)->fun((dump)->ctx, __VA_ARGS__) +#define PSI_DUMP(dump, ...) do { \ + struct psi_dump _dump_tmp, *_dump_ptr = dump; \ + if (!_dump_ptr) { \ + _dump_ptr = &_dump_tmp; \ + _dump_tmp.ctx.fd = STDOUT_FILENO; \ + _dump_tmp.fun = (psi_dump_cb) dprintf; \ + } \ + _dump_ptr->fun(_dump_ptr->ctx, __VA_ARGS__); \ +} while(0) #define PSI_DATA(D) ((struct psi_data *) (D)) diff --git a/src/parser.c b/src/parser.c index 9d3395c..cf576d5 100644 --- a/src/parser.c +++ b/src/parser.c @@ -147,14 +147,9 @@ static inline zend_string *macro_to_constant(struct psi_parser *parser, smart_str_append_printf(&str, "const psi\\%s = ", name->val); if (scope->macro->exp) { - impl_val res = {0}; - token_t typ = psi_num_exp_exec(scope->macro->exp, &res, NULL, scope->cpp); + struct psi_dump dump = {{.hn = &str}, .fun = (psi_dump_cb) smart_str_append_printf}; - switch (typ) { - CASE_IMPLVAL_NUM_PRINTF(smart_str_append_printf, &str, res, true); - default: - assert(0); - } + psi_num_exp_dump(&dump, scope->macro->exp); } else while (psi_plist_get(scope->macro->tokens, i++, &tok)) { if (tok->type == PSI_T_QUOTED_STRING) { smart_str_appendc(&str, '"'); diff --git a/src/types/num_exp.c b/src/types/num_exp.c index ce89de5..9388ad3 100644 --- a/src/types/num_exp.c +++ b/src/types/num_exp.c @@ -389,7 +389,7 @@ void psi_num_exp_dump(struct psi_dump *dump, struct psi_num_exp *exp) case PSI_T_CAST: PSI_DUMP(dump, "("); - psi_decl_type_dump(1, exp->data.c.typ, 0); + psi_decl_type_dump(dump, exp->data.c.typ, 0); PSI_DUMP(dump, ")"); break; -- 2.30.2