Eliminate make_symbol_overload_list-related globals & cleanup

This gets rid of a few globals and a cleanup.

make_symbol_overload_list & friends currently maintain a global
open-coded vector.  Reimplement that with a std::vector, trickled down
through the functions.  Rename a few functions from "make_" to "add_"
for clarity.

gdb/ChangeLog:
2018-11-21  Pedro Alves  <palves@redhat.com>

	* cp-support.c (sym_return_val_size, sym_return_val_index)
	(sym_return_val): Delete.
	(overload_list_add_symbol): Add std::vector parameter.  Adjust to
	add to the vector.
	(make_symbol_overload_list): Adjust to return a std::vector
	instead of maintaining a global open coded vector.
	(make_symbol_overload_list_block): Add std::vector parameter.
	(make_symbol_overload_list_block): Rename to ...
	(add_symbol_overload_list_block): ... this and add std::vector
	parameter.
	(make_symbol_overload_list_namespace): Rename to ...
	(add_symbol_overload_list_namespace): ... this and add std::vector
	parameter.
	(make_symbol_overload_list_adl_namespace): Rename to ...
	(add_symbol_overload_list_adl_namespace): ... this and add
	std::vector parameter.
	(make_symbol_overload_list_adl): Delete.
	(add_symbol_overload_list_adl): New.
	(make_symbol_overload_list_using): Rename to ...
	(add_symbol_overload_list_using): ... this and add std::vector
	parameter.
	(make_symbol_overload_list_qualified): Rename to ...
	(add_symbol_overload_list_qualified): ... this and add std::vector
	parameter.
	* cp-support.h: Include "common/array-view.h" and <vector>.
	(make_symbol_overload_list): Change return type to std::vector.
	(make_symbol_overload_list_adl): Delete declaration.
	(add_symbol_overload_list_adl): New declaration.
	* valops.c (find_overload_match): Local 'oload_syms' now a
	std::vector.
	(find_oload_champ_namespace): 'oload_syms' parameter now a
	std::vector pointer.
	(find_oload_champ_namespace_loop): 'oload_syms' parameter now a
	std::vector pointer.  Adjust to new make_symbol_overload_list
	interface.
This commit is contained in:
Pedro Alves 2018-11-21 11:55:13 +00:00
parent 6b1747cd13
commit 0891c3cc13
4 changed files with 124 additions and 106 deletions

View file

@ -48,19 +48,19 @@ static unsigned int cp_find_first_component_aux (const char *name,
static void demangled_name_complaint (const char *name);
/* Functions/variables related to overload resolution. */
static int sym_return_val_size = -1;
static int sym_return_val_index;
static struct symbol **sym_return_val;
/* Functions related to overload resolution. */
static void overload_list_add_symbol (struct symbol *sym,
const char *oload_name);
const char *oload_name,
std::vector<symbol *> *overload_list);
static void make_symbol_overload_list_using (const char *func_name,
const char *the_namespace);
static void add_symbol_overload_list_using
(const char *func_name, const char *the_namespace,
std::vector<symbol *> *overload_list);
static void make_symbol_overload_list_qualified (const char *func_name);
static void add_symbol_overload_list_qualified
(const char *func_name,
std::vector<symbol *> *overload_list);
/* The list of "maint cplus" commands. */
@ -1137,30 +1137,28 @@ cp_entire_prefix_len (const char *name)
/* Overload resolution functions. */
/* Test to see if SYM is a symbol that we haven't seen corresponding
to a function named OLOAD_NAME. If so, add it to the current
completion list. */
to a function named OLOAD_NAME. If so, add it to
OVERLOAD_LIST. */
static void
overload_list_add_symbol (struct symbol *sym,
const char *oload_name)
const char *oload_name,
std::vector<symbol *> *overload_list)
{
int newsize;
int i;
gdb::unique_xmalloc_ptr<char> sym_name;
/* If there is no type information, we can't do anything, so
skip. */
if (SYMBOL_TYPE (sym) == NULL)
return;
/* skip any symbols that we've already considered. */
for (i = 0; i < sym_return_val_index; ++i)
for (symbol *listed_sym : *overload_list)
if (strcmp (SYMBOL_LINKAGE_NAME (sym),
SYMBOL_LINKAGE_NAME (sym_return_val[i])) == 0)
SYMBOL_LINKAGE_NAME (listed_sym)) == 0)
return;
/* Get the demangled name without parameters */
sym_name = cp_remove_params (SYMBOL_NATURAL_NAME (sym));
gdb::unique_xmalloc_ptr<char> sym_name
= cp_remove_params (SYMBOL_NATURAL_NAME (sym));
if (!sym_name)
return;
@ -1168,36 +1166,22 @@ overload_list_add_symbol (struct symbol *sym,
if (strcmp (sym_name.get (), oload_name) != 0)
return;
/* We have a match for an overload instance, so add SYM to the
current list of overload instances */
if (sym_return_val_index + 3 > sym_return_val_size)
{
newsize = (sym_return_val_size *= 2) * sizeof (struct symbol *);
sym_return_val = (struct symbol **)
xrealloc ((char *) sym_return_val, newsize);
}
sym_return_val[sym_return_val_index++] = sym;
sym_return_val[sym_return_val_index] = NULL;
overload_list->push_back (sym);
}
/* Return a null-terminated list of pointers to function symbols that
are named FUNC_NAME and are visible within NAMESPACE. */
struct symbol **
struct std::vector<symbol *>
make_symbol_overload_list (const char *func_name,
const char *the_namespace)
{
struct cleanup *old_cleanups;
const char *name;
std::vector<symbol *> overload_list;
sym_return_val_size = 100;
sym_return_val_index = 0;
sym_return_val = XNEWVEC (struct symbol *, sym_return_val_size + 1);
sym_return_val[0] = NULL;
overload_list.reserve (100);
old_cleanups = make_cleanup (xfree, sym_return_val);
make_symbol_overload_list_using (func_name, the_namespace);
add_symbol_overload_list_using (func_name, the_namespace, &overload_list);
if (the_namespace[0] == '\0')
name = func_name;
@ -1211,19 +1195,17 @@ make_symbol_overload_list (const char *func_name,
name = concatenated_name;
}
make_symbol_overload_list_qualified (name);
discard_cleanups (old_cleanups);
return sym_return_val;
add_symbol_overload_list_qualified (name, &overload_list);
return overload_list;
}
/* Add all symbols with a name matching NAME in BLOCK to the overload
list. */
static void
make_symbol_overload_list_block (const char *name,
const struct block *block)
add_symbol_overload_list_block (const char *name,
const struct block *block,
std::vector<symbol *> *overload_list)
{
struct block_iterator iter;
struct symbol *sym;
@ -1231,14 +1213,15 @@ make_symbol_overload_list_block (const char *name,
lookup_name_info lookup_name (name, symbol_name_match_type::FULL);
ALL_BLOCK_SYMBOLS_WITH_NAME (block, lookup_name, iter, sym)
overload_list_add_symbol (sym, name);
overload_list_add_symbol (sym, name, overload_list);
}
/* Adds the function FUNC_NAME from NAMESPACE to the overload set. */
static void
make_symbol_overload_list_namespace (const char *func_name,
const char *the_namespace)
add_symbol_overload_list_namespace (const char *func_name,
const char *the_namespace,
std::vector<symbol *> *overload_list)
{
const char *name;
const struct block *block = NULL;
@ -1259,12 +1242,12 @@ make_symbol_overload_list_namespace (const char *func_name,
/* Look in the static block. */
block = block_static_block (get_selected_block (0));
if (block)
make_symbol_overload_list_block (name, block);
add_symbol_overload_list_block (name, block, overload_list);
/* Look in the global block. */
block = block_global_block (block);
if (block)
make_symbol_overload_list_block (name, block);
add_symbol_overload_list_block (name, block, overload_list);
}
@ -1272,8 +1255,9 @@ make_symbol_overload_list_namespace (const char *func_name,
base types. */
static void
make_symbol_overload_list_adl_namespace (struct type *type,
const char *func_name)
add_symbol_overload_list_adl_namespace (struct type *type,
const char *func_name,
std::vector<symbol *> *overload_list)
{
char *the_namespace;
const char *type_name;
@ -1303,7 +1287,8 @@ make_symbol_overload_list_adl_namespace (struct type *type,
strncpy (the_namespace, type_name, prefix_len);
the_namespace[prefix_len] = '\0';
make_symbol_overload_list_namespace (func_name, the_namespace);
add_symbol_overload_list_namespace (func_name, the_namespace,
overload_list);
}
/* Check public base type */
@ -1311,28 +1296,23 @@ make_symbol_overload_list_adl_namespace (struct type *type,
for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
{
if (BASETYPE_VIA_PUBLIC (type, i))
make_symbol_overload_list_adl_namespace (TYPE_BASECLASS (type,
i),
func_name);
add_symbol_overload_list_adl_namespace (TYPE_BASECLASS (type, i),
func_name,
overload_list);
}
}
/* Adds the overload list overload candidates for FUNC_NAME found
through argument dependent lookup. */
/* Adds to OVERLOAD_LIST the overload list overload candidates for
FUNC_NAME found through argument dependent lookup. */
struct symbol **
make_symbol_overload_list_adl (struct type **arg_types, int nargs,
const char *func_name)
void
add_symbol_overload_list_adl (gdb::array_view<type *> arg_types,
const char *func_name,
std::vector<symbol *> *overload_list)
{
int i;
gdb_assert (sym_return_val_size != -1);
for (i = 1; i <= nargs; i++)
make_symbol_overload_list_adl_namespace (arg_types[i - 1],
func_name);
return sym_return_val;
for (type *arg_type : arg_types)
add_symbol_overload_list_adl_namespace (arg_type, func_name,
overload_list);
}
/* This applies the using directives to add namespaces to search in,
@ -1341,8 +1321,9 @@ make_symbol_overload_list_adl (struct type **arg_types, int nargs,
make_symbol_overload_list. */
static void
make_symbol_overload_list_using (const char *func_name,
const char *the_namespace)
add_symbol_overload_list_using (const char *func_name,
const char *the_namespace,
std::vector<symbol *> *overload_list)
{
struct using_direct *current;
const struct block *block;
@ -1374,13 +1355,15 @@ make_symbol_overload_list_using (const char *func_name,
scoped_restore reset_directive_searched
= make_scoped_restore (&current->searched, 1);
make_symbol_overload_list_using (func_name,
current->import_src);
add_symbol_overload_list_using (func_name,
current->import_src,
overload_list);
}
}
/* Now, add names for this namespace. */
make_symbol_overload_list_namespace (func_name, the_namespace);
add_symbol_overload_list_namespace (func_name, the_namespace,
overload_list);
}
/* This does the bulk of the work of finding overloaded symbols.
@ -1388,7 +1371,8 @@ make_symbol_overload_list_using (const char *func_name,
(possibly including namespace info). */
static void
make_symbol_overload_list_qualified (const char *func_name)
add_symbol_overload_list_qualified (const char *func_name,
std::vector<symbol *> *overload_list)
{
struct compunit_symtab *cust;
struct objfile *objfile;
@ -1407,7 +1391,7 @@ make_symbol_overload_list_qualified (const char *func_name)
complete on local vars. */
for (b = get_selected_block (0); b != NULL; b = BLOCK_SUPERBLOCK (b))
make_symbol_overload_list_block (func_name, b);
add_symbol_overload_list_block (func_name, b, overload_list);
surrounding_static_block = block_static_block (get_selected_block (0));
@ -1418,7 +1402,7 @@ make_symbol_overload_list_qualified (const char *func_name)
{
QUIT;
b = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust), GLOBAL_BLOCK);
make_symbol_overload_list_block (func_name, b);
add_symbol_overload_list_block (func_name, b, overload_list);
}
ALL_COMPUNITS (objfile, cust)
@ -1428,7 +1412,7 @@ make_symbol_overload_list_qualified (const char *func_name)
/* Don't do this block twice. */
if (b == surrounding_static_block)
continue;
make_symbol_overload_list_block (func_name, b);
add_symbol_overload_list_block (func_name, b, overload_list);
}
}