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  <philippe.waroquiers@skynet.be>

	* 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.
This commit is contained in:
Philippe Waroquiers 2019-01-26 12:32:45 +01:00
parent bb0da2b496
commit ab9268d2f8
2 changed files with 38 additions and 29 deletions

View file

@ -1,3 +1,11 @@
2019-02-06 Philippe Waroquiers <philippe.waroquiers@skynet.be>
* 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 <philippe.waroquiers@skynet.be>
* macrocmd.c (extract_identifier): Return

View file

@ -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)