From: Philippe Waroquiers Date: Sat, 26 Jan 2019 11:32:45 +0000 (+0100) Subject: Factorize macro definition code in macrotab.c X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ab9268d2f88414f202651eb5ffbd61c7927fb0c3;p=binutils-gdb.git Factorize macro definition code in macrotab.c When first fixing splay tree key leaks in macrotab.c, some duplicated code logic was factorized. The key leaks will be fixed in libiberty, but the code factorization is better kept in any case. gdb/ChangeLog 2019-02-06 Philippe Waroquiers * macrotab.c (macro_define_internal): New function that factorizes macro_define_object_internal and macro_define_function code. (macro_define_object_internal): Use macro_define_internal. (macro_define_function): Likewise. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 87cba1c40ee..c5c08ec0329 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,11 @@ +2019-02-06 Philippe Waroquiers + + * macrotab.c (macro_define_internal): New function that + factorizes macro_define_object_internal and macro_define_function + code. + (macro_define_object_internal): Use macro_define_internal. + (macro_define_function): Likewise. + 2019-02-06 Philippe Waroquiers * macrocmd.c (extract_identifier): Return diff --git a/gdb/macrotab.c b/gdb/macrotab.c index 7fcab4691bc..f7ce26f850d 100644 --- a/gdb/macrotab.c +++ b/gdb/macrotab.c @@ -743,21 +743,26 @@ check_for_redefinition (struct macro_source_file *source, int line, return 0; } -/* A helper function to define a new object-like macro. */ +/* A helper function to define a new object-like or function-like macro + according to KIND. When KIND is macro_object_like, + the macro_special_kind must be provided as ARGC, and ARGV must be NULL. + When KIND is macro_function_like, ARGC and ARGV are giving the function + arguments. */ static void -macro_define_object_internal (struct macro_source_file *source, int line, - const char *name, const char *replacement, - enum macro_special_kind kind) +macro_define_internal (struct macro_source_file *source, int line, + const char *name, enum macro_kind kind, + int argc, const char **argv, + const char *replacement) { struct macro_table *t = source->table; struct macro_key *k = NULL; struct macro_definition *d; if (! t->redef_ok) - k = check_for_redefinition (source, line, - name, macro_object_like, - 0, 0, + k = check_for_redefinition (source, line, + name, kind, + argc, argv, replacement); /* If we're redefining a symbol, and the existing key would be @@ -774,10 +779,23 @@ macro_define_object_internal (struct macro_source_file *source, int line, return; k = new_macro_key (t, name, source, line); - d = new_macro_definition (t, macro_object_like, kind, 0, replacement); + d = new_macro_definition (t, kind, argc, argv, replacement); splay_tree_insert (t->definitions, (splay_tree_key) k, (splay_tree_value) d); } +/* A helper function to define a new object-like macro. */ + +static void +macro_define_object_internal (struct macro_source_file *source, int line, + const char *name, const char *replacement, + enum macro_special_kind special_kind) +{ + macro_define_internal (source, line, + name, macro_object_like, + special_kind, NULL, + replacement); +} + void macro_define_object (struct macro_source_file *source, int line, const char *name, const char *replacement) @@ -802,29 +820,12 @@ macro_define_function (struct macro_source_file *source, int line, const char *name, int argc, const char **argv, const char *replacement) { - struct macro_table *t = source->table; - struct macro_key *k = NULL; - struct macro_definition *d; - - if (! t->redef_ok) - k = check_for_redefinition (source, line, - name, macro_function_like, - argc, argv, - replacement); - - /* See comments about duplicate keys in macro_define_object. */ - if (k && ! key_compare (k, name, source, line)) - return; - - /* We should also check here that all the argument names in ARGV are - distinct. */ - - k = new_macro_key (t, name, source, line); - d = new_macro_definition (t, macro_function_like, argc, argv, replacement); - splay_tree_insert (t->definitions, (splay_tree_key) k, (splay_tree_value) d); + macro_define_internal (source, line, + name, macro_function_like, + argc, argv, + replacement); } - void macro_undef (struct macro_source_file *source, int line, const char *name)