From 5f67b95d218e1ef3473c39bca2f6491503aeeabe Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 29 Dec 2021 18:59:27 -0800 Subject: Eliminate declaration-after-statement everywhere. The use of -ansi doesn't by itself diagnose instances of some constructs we don't want in the project, like mixed declarations and statements. * configure (diag_flags): Add -Werror=declaration-after-statement. This is C only, so filter it out for C++. Also add -Werror=vla. * HACKING: Update inaccurate statements about what dialect we are using. TXR isn't pure C90: some GCC extensions are used. We even use long long if the configure script detects it as working, and some C99 library features. * buf.c (replace_buf, buf_list): Fix by reordering. * eval.c (op_dohash, op_load_time_lit): Fix by reordering. * ffi.c (ffi_simple_release): Fix by reordering. (align_sw_get): Fix empty macro to expand to dummy declaration so a semicolon after it isn't interpreted as a statement. On platforms with alignment, remove a semicolon from the macro so that it requires one. (ffi_i8_put, ffi_u8_put): Fix by reordering. * gc.c (gc_init): Fix with extra braces. * hash.c (hash_init): Fix by reordering. * lib.c (list_collect_revappend, sub_iter, replace_str, replace_vec, mapcar_listout, mappend, mapdo, window_map_list, subst): Fix by reordering. (gensym, find, rfind, pos, rpos, in, search_common): Fix by renaming optional argument and using declaration instead of assignment. * linenoise/linenoise.c (edit_in_editor): Fix by reordering. * parser.c (is_balanced_line): Fix by reordering. * regex.c (nfa_count_one, print_rec): Fix by reordering. * signal.c (sig_mask): Fix by reordering. * stream.c (get_string): Fix by renaming optional argument and using declaration instead of assignment. * struct.c (lookup_static_slot_desc): Fix by turning mutated variable into block local. (umethod_args_fun): Fix by reordering. (get_special_slot): Fix by new scope via braces. * sysif.c (usleep_wrap): Fix by new scope via braces. (setrlimit_wrap): Fix by new scope via braces. * time.c (time_string_meth, time_parse_meth): Fix by reordering. * tree.c (tr_do_delete_spec): Fix by new scope via braces. * unwind.h (uw_block_beg): New macro which doesn't define RESULTVAR but expects it to refers to an existing one. (uw_block_begin): Replace do while (0) with enum trick so that we have a declaration that requires a semicolon, rather than a statement, allowing declarations to follow. (uw_match_env_begin): Now opens a scope and features the same enum trick as in uw_block_begin. This fixes a declaration-follows-statement issue in the v_output function in match.c. (uw_match_env_end): Closes scope opened by uw_match_env_begin. * unwind.c (revive_cont): Fix by introducing variable, and using new uw_block_beg macro. * vm.c (vm_execute_closure): Fix using combination of local variable and reordering. --- tree.c | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) (limited to 'tree.c') diff --git a/tree.c b/tree.c index 8b3230e3..0c803d8e 100644 --- a/tree.c +++ b/tree.c @@ -537,28 +537,30 @@ static val tr_do_delete_specific(val tree, struct tree *tr, val subtree, return subtree; } - val tr_key = if3(tr->key_fn, - funcall1(tr->key_fn, subtree->tn.key), - subtree->tn.key); - - if (if3(tr->less_fn, - funcall2(tr->less_fn, key, tr_key), - less(key, tr_key))) { - val le = subtree->tn.left; - return tr_do_delete_specific(tree, tr, le, subtree, key, thisnode); - } else if (if3(tr->equal_fn == nil, - equal(key, tr_key), - funcall2(tr->equal_fn, key, tr_key))) - { - uses_or2; - val le = subtree->tn.left; - val ri = subtree->tn.right; - return or2(tr_do_delete_specific(tree, tr, le, subtree, key, thisnode), - tr_do_delete_specific(tree, tr, ri, subtree, key, thisnode)); - } else { - val ri = subtree->tn.right; - return tr_do_delete_specific(tree, tr, ri, subtree, key, thisnode); + val tr_key = if3(tr->key_fn, + funcall1(tr->key_fn, subtree->tn.key), + subtree->tn.key); + + if (if3(tr->less_fn, + funcall2(tr->less_fn, key, tr_key), + less(key, tr_key))) + { + val le = subtree->tn.left; + return tr_do_delete_specific(tree, tr, le, subtree, key, thisnode); + } else if (if3(tr->equal_fn == nil, + equal(key, tr_key), + funcall2(tr->equal_fn, key, tr_key))) + { + uses_or2; + val le = subtree->tn.left; + val ri = subtree->tn.right; + return or2(tr_do_delete_specific(tree, tr, le, subtree, key, thisnode), + tr_do_delete_specific(tree, tr, ri, subtree, key, thisnode)); + } else { + val ri = subtree->tn.right; + return tr_do_delete_specific(tree, tr, ri, subtree, key, thisnode); + } } } -- cgit v1.2.3