Remove last Ada cleanups

This removes the last cleanups from the Ada code by changing
ada_lookup_symbol_list's out parameter to be a std::vector, and then
fixing up the fallout.

This is a relatively shallow change.  Deeper changes are possible, for
example (1) changing various other functions to accept a vector rather
than a pointer, or (2) changing ada_lookup_symbol_list to return the
vector and omitting the length entirely.

Tested by the buildbot, but I'll wait for Joel to test these as well.

gdb/ChangeLog
2018-06-04  Tom Tromey  <tom@tromey.com>

	* ada-lang.h (ada_lookup_symbol_list): Update.
	* ada-lang.c (resolve_subexp): Update.
	(symbols_are_identical_enums): Change type of syms.  Remove nsyms
	parameter.
	(remove_extra_symbols, remove_irrelevant_renamings): Likewise.
	(ada_lookup_symbol_list_worker, ada_lookup_symbol_list): Change
	results parameter to std::vector.
	(ada_iterate_over_symbols, ada_lookup_symbol, get_var_value):
	Update.
	* ada-exp.y (block_lookup): Update.
	(select_possible_type_sym): Change type of syms.  Remove nsyms
	parameter.
	(write_var_or_type, write_name_assoc): Update.
This commit is contained in:
Tom Tromey 2018-05-25 13:32:20 -06:00
parent 178d6a6386
commit 54d343a240
4 changed files with 108 additions and 144 deletions

View file

@ -1,3 +1,19 @@
2018-06-04 Tom Tromey <tom@tromey.com>
* ada-lang.h (ada_lookup_symbol_list): Update.
* ada-lang.c (resolve_subexp): Update.
(symbols_are_identical_enums): Change type of syms. Remove nsyms
parameter.
(remove_extra_symbols, remove_irrelevant_renamings): Likewise.
(ada_lookup_symbol_list_worker, ada_lookup_symbol_list): Change
results parameter to std::vector.
(ada_iterate_over_symbols, ada_lookup_symbol, get_var_value):
Update.
* ada-exp.y (block_lookup): Update.
(select_possible_type_sym): Change type of syms. Remove nsyms
parameter.
(write_var_or_type, write_name_assoc): Update.
2018-06-04 Joel Brobecker <brobecker@adacore.com> 2018-06-04 Joel Brobecker <brobecker@adacore.com>
* windows-nat.c (windows_nat_target::xfer_partial): Return * windows-nat.c (windows_nat_target::xfer_partial): Return

View file

@ -950,10 +950,9 @@ static const struct block*
block_lookup (const struct block *context, const char *raw_name) block_lookup (const struct block *context, const char *raw_name)
{ {
const char *name; const char *name;
struct block_symbol *syms; std::vector<struct block_symbol> syms;
int nsyms; int nsyms;
struct symtab *symtab; struct symtab *symtab;
struct cleanup *old_chain;
const struct block *result = NULL; const struct block *result = NULL;
if (raw_name[0] == '\'') if (raw_name[0] == '\'')
@ -965,7 +964,6 @@ block_lookup (const struct block *context, const char *raw_name)
name = ada_encode (raw_name); name = ada_encode (raw_name);
nsyms = ada_lookup_symbol_list (name, context, VAR_DOMAIN, &syms); nsyms = ada_lookup_symbol_list (name, context, VAR_DOMAIN, &syms);
old_chain = make_cleanup (xfree, syms);
if (context == NULL if (context == NULL
&& (nsyms == 0 || SYMBOL_CLASS (syms[0].symbol) != LOC_BLOCK)) && (nsyms == 0 || SYMBOL_CLASS (syms[0].symbol) != LOC_BLOCK))
@ -989,19 +987,18 @@ block_lookup (const struct block *context, const char *raw_name)
result = SYMBOL_BLOCK_VALUE (syms[0].symbol); result = SYMBOL_BLOCK_VALUE (syms[0].symbol);
} }
do_cleanups (old_chain);
return result; return result;
} }
static struct symbol* static struct symbol*
select_possible_type_sym (struct block_symbol *syms, int nsyms) select_possible_type_sym (const std::vector<struct block_symbol> &syms)
{ {
int i; int i;
int preferred_index; int preferred_index;
struct type *preferred_type; struct type *preferred_type;
preferred_index = -1; preferred_type = NULL; preferred_index = -1; preferred_type = NULL;
for (i = 0; i < nsyms; i += 1) for (i = 0; i < syms.size (); i += 1)
switch (SYMBOL_CLASS (syms[i].symbol)) switch (SYMBOL_CLASS (syms[i].symbol))
{ {
case LOC_TYPEDEF: case LOC_TYPEDEF:
@ -1204,7 +1201,6 @@ write_var_or_type (struct parser_state *par_state,
int depth; int depth;
char *encoded_name; char *encoded_name;
int name_len; int name_len;
struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
if (block == NULL) if (block == NULL)
block = expression_context_block; block = expression_context_block;
@ -1221,7 +1217,7 @@ write_var_or_type (struct parser_state *par_state,
while (tail_index > 0) while (tail_index > 0)
{ {
int nsyms; int nsyms;
struct block_symbol *syms; std::vector<struct block_symbol> syms;
struct symbol *type_sym; struct symbol *type_sym;
struct symbol *renaming_sym; struct symbol *renaming_sym;
const char* renaming; const char* renaming;
@ -1232,7 +1228,6 @@ write_var_or_type (struct parser_state *par_state,
encoded_name[tail_index] = '\0'; encoded_name[tail_index] = '\0';
nsyms = ada_lookup_symbol_list (encoded_name, block, nsyms = ada_lookup_symbol_list (encoded_name, block,
VAR_DOMAIN, &syms); VAR_DOMAIN, &syms);
make_cleanup (xfree, syms);
encoded_name[tail_index] = terminator; encoded_name[tail_index] = terminator;
/* A single symbol may rename a package or object. */ /* A single symbol may rename a package or object. */
@ -1248,7 +1243,7 @@ write_var_or_type (struct parser_state *par_state,
syms[0].symbol = ren_sym; syms[0].symbol = ren_sym;
} }
type_sym = select_possible_type_sym (syms, nsyms); type_sym = select_possible_type_sym (syms);
if (type_sym != NULL) if (type_sym != NULL)
renaming_sym = type_sym; renaming_sym = type_sym;
@ -1279,7 +1274,6 @@ write_var_or_type (struct parser_state *par_state,
write_object_renaming (par_state, block, renaming, renaming_len, write_object_renaming (par_state, block, renaming, renaming_len,
renaming_expr, MAX_RENAMING_CHAIN_LENGTH); renaming_expr, MAX_RENAMING_CHAIN_LENGTH);
write_selectors (par_state, encoded_name + tail_index); write_selectors (par_state, encoded_name + tail_index);
do_cleanups (old_chain);
return NULL; return NULL;
default: default:
internal_error (__FILE__, __LINE__, internal_error (__FILE__, __LINE__,
@ -1291,10 +1285,7 @@ write_var_or_type (struct parser_state *par_state,
struct type *field_type; struct type *field_type;
if (tail_index == name_len) if (tail_index == name_len)
{ return SYMBOL_TYPE (type_sym);
do_cleanups (old_chain);
return SYMBOL_TYPE (type_sym);
}
/* We have some extraneous characters after the type name. /* We have some extraneous characters after the type name.
If this is an expression "TYPE_NAME.FIELD0.[...].FIELDN", If this is an expression "TYPE_NAME.FIELD0.[...].FIELDN",
@ -1302,10 +1293,7 @@ write_var_or_type (struct parser_state *par_state,
field_type field_type
= get_symbol_field_type (type_sym, encoded_name + tail_index); = get_symbol_field_type (type_sym, encoded_name + tail_index);
if (field_type != NULL) if (field_type != NULL)
{ return field_type;
do_cleanups (old_chain);
return field_type;
}
else else
error (_("Invalid attempt to select from type: \"%s\"."), error (_("Invalid attempt to select from type: \"%s\"."),
name0.ptr); name0.ptr);
@ -1316,17 +1304,13 @@ write_var_or_type (struct parser_state *par_state,
encoded_name); encoded_name);
if (type != NULL) if (type != NULL)
{ return type;
do_cleanups (old_chain);
return type;
}
} }
if (nsyms == 1) if (nsyms == 1)
{ {
write_var_from_sym (par_state, syms[0].block, syms[0].symbol); write_var_from_sym (par_state, syms[0].block, syms[0].symbol);
write_selectors (par_state, encoded_name + tail_index); write_selectors (par_state, encoded_name + tail_index);
do_cleanups (old_chain);
return NULL; return NULL;
} }
else if (nsyms == 0) else if (nsyms == 0)
@ -1338,7 +1322,6 @@ write_var_or_type (struct parser_state *par_state,
write_exp_msymbol (par_state, msym); write_exp_msymbol (par_state, msym);
/* Maybe cause error here rather than later? FIXME? */ /* Maybe cause error here rather than later? FIXME? */
write_selectors (par_state, encoded_name + tail_index); write_selectors (par_state, encoded_name + tail_index);
do_cleanups (old_chain);
return NULL; return NULL;
} }
@ -1354,7 +1337,6 @@ write_var_or_type (struct parser_state *par_state,
write_ambiguous_var (par_state, block, encoded_name, write_ambiguous_var (par_state, block, encoded_name,
tail_index); tail_index);
write_selectors (par_state, encoded_name + tail_index); write_selectors (par_state, encoded_name + tail_index);
do_cleanups (old_chain);
return NULL; return NULL;
} }
} }
@ -1393,17 +1375,14 @@ write_name_assoc (struct parser_state *par_state, struct stoken name)
{ {
if (strchr (name.ptr, '.') == NULL) if (strchr (name.ptr, '.') == NULL)
{ {
struct block_symbol *syms; std::vector<struct block_symbol> syms;
int nsyms = ada_lookup_symbol_list (name.ptr, expression_context_block, int nsyms = ada_lookup_symbol_list (name.ptr, expression_context_block,
VAR_DOMAIN, &syms); VAR_DOMAIN, &syms);
struct cleanup *old_chain = make_cleanup (xfree, syms);
if (nsyms != 1 || SYMBOL_CLASS (syms[0].symbol) == LOC_TYPEDEF) if (nsyms != 1 || SYMBOL_CLASS (syms[0].symbol) == LOC_TYPEDEF)
write_exp_op_with_string (par_state, OP_NAME, name); write_exp_op_with_string (par_state, OP_NAME, name);
else else
write_var_from_sym (par_state, syms[0].block, syms[0].symbol); write_var_from_sym (par_state, syms[0].block, syms[0].symbol);
do_cleanups (old_chain);
} }
else else
if (write_var_or_type (par_state, NULL, name) != NULL) if (write_var_or_type (par_state, NULL, name) != NULL)

View file

@ -3266,7 +3266,6 @@ resolve_subexp (expression_up *expp, int *pos, int deprocedure_p,
struct value **argvec; /* Vector of operand types (alloca'ed). */ struct value **argvec; /* Vector of operand types (alloca'ed). */
int nargs; /* Number of operands. */ int nargs; /* Number of operands. */
int oplen; int oplen;
struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
argvec = NULL; argvec = NULL;
nargs = 0; nargs = 0;
@ -3431,7 +3430,7 @@ resolve_subexp (expression_up *expp, int *pos, int deprocedure_p,
case OP_VAR_VALUE: case OP_VAR_VALUE:
if (SYMBOL_DOMAIN (exp->elts[pc + 2].symbol) == UNDEF_DOMAIN) if (SYMBOL_DOMAIN (exp->elts[pc + 2].symbol) == UNDEF_DOMAIN)
{ {
struct block_symbol *candidates; std::vector<struct block_symbol> candidates;
int n_candidates; int n_candidates;
n_candidates = n_candidates =
@ -3439,7 +3438,6 @@ resolve_subexp (expression_up *expp, int *pos, int deprocedure_p,
(exp->elts[pc + 2].symbol), (exp->elts[pc + 2].symbol),
exp->elts[pc + 1].block, VAR_DOMAIN, exp->elts[pc + 1].block, VAR_DOMAIN,
&candidates); &candidates);
make_cleanup (xfree, candidates);
if (n_candidates > 1) if (n_candidates > 1)
{ {
@ -3483,10 +3481,10 @@ resolve_subexp (expression_up *expp, int *pos, int deprocedure_p,
else if (n_candidates == 1) else if (n_candidates == 1)
i = 0; i = 0;
else if (deprocedure_p else if (deprocedure_p
&& !is_nonfunction (candidates, n_candidates)) && !is_nonfunction (candidates.data (), n_candidates))
{ {
i = ada_resolve_function i = ada_resolve_function
(candidates, n_candidates, NULL, 0, (candidates.data (), n_candidates, NULL, 0,
SYMBOL_LINKAGE_NAME (exp->elts[pc + 2].symbol), SYMBOL_LINKAGE_NAME (exp->elts[pc + 2].symbol),
context_type); context_type);
if (i < 0) if (i < 0)
@ -3497,7 +3495,7 @@ resolve_subexp (expression_up *expp, int *pos, int deprocedure_p,
{ {
printf_filtered (_("Multiple matches for %s\n"), printf_filtered (_("Multiple matches for %s\n"),
SYMBOL_PRINT_NAME (exp->elts[pc + 2].symbol)); SYMBOL_PRINT_NAME (exp->elts[pc + 2].symbol));
user_select_syms (candidates, n_candidates, 1); user_select_syms (candidates.data (), n_candidates, 1);
i = 0; i = 0;
} }
@ -3522,7 +3520,7 @@ resolve_subexp (expression_up *expp, int *pos, int deprocedure_p,
if (exp->elts[pc + 3].opcode == OP_VAR_VALUE if (exp->elts[pc + 3].opcode == OP_VAR_VALUE
&& SYMBOL_DOMAIN (exp->elts[pc + 5].symbol) == UNDEF_DOMAIN) && SYMBOL_DOMAIN (exp->elts[pc + 5].symbol) == UNDEF_DOMAIN)
{ {
struct block_symbol *candidates; std::vector<struct block_symbol> candidates;
int n_candidates; int n_candidates;
n_candidates = n_candidates =
@ -3530,14 +3528,13 @@ resolve_subexp (expression_up *expp, int *pos, int deprocedure_p,
(exp->elts[pc + 5].symbol), (exp->elts[pc + 5].symbol),
exp->elts[pc + 4].block, VAR_DOMAIN, exp->elts[pc + 4].block, VAR_DOMAIN,
&candidates); &candidates);
make_cleanup (xfree, candidates);
if (n_candidates == 1) if (n_candidates == 1)
i = 0; i = 0;
else else
{ {
i = ada_resolve_function i = ada_resolve_function
(candidates, n_candidates, (candidates.data (), n_candidates,
argvec, nargs, argvec, nargs,
SYMBOL_LINKAGE_NAME (exp->elts[pc + 5].symbol), SYMBOL_LINKAGE_NAME (exp->elts[pc + 5].symbol),
context_type); context_type);
@ -3575,17 +3572,16 @@ resolve_subexp (expression_up *expp, int *pos, int deprocedure_p,
case UNOP_ABS: case UNOP_ABS:
if (possible_user_operator_p (op, argvec)) if (possible_user_operator_p (op, argvec))
{ {
struct block_symbol *candidates; std::vector<struct block_symbol> candidates;
int n_candidates; int n_candidates;
n_candidates = n_candidates =
ada_lookup_symbol_list (ada_decoded_op_name (op), ada_lookup_symbol_list (ada_decoded_op_name (op),
(struct block *) NULL, VAR_DOMAIN, (struct block *) NULL, VAR_DOMAIN,
&candidates); &candidates);
make_cleanup (xfree, candidates);
i = ada_resolve_function (candidates, n_candidates, argvec, nargs, i = ada_resolve_function (candidates.data (), n_candidates, argvec,
ada_decoded_op_name (op), NULL); nargs, ada_decoded_op_name (op), NULL);
if (i < 0) if (i < 0)
break; break;
@ -3598,12 +3594,10 @@ resolve_subexp (expression_up *expp, int *pos, int deprocedure_p,
case OP_TYPE: case OP_TYPE:
case OP_REGISTER: case OP_REGISTER:
do_cleanups (old_chain);
return NULL; return NULL;
} }
*pos = pc; *pos = pc;
do_cleanups (old_chain);
if (exp->elts[pc].opcode == OP_VAR_MSYM_VALUE) if (exp->elts[pc].opcode == OP_VAR_MSYM_VALUE)
return evaluate_var_msym_value (EVAL_AVOID_SIDE_EFFECTS, return evaluate_var_msym_value (EVAL_AVOID_SIDE_EFFECTS,
exp->elts[pc + 1].objfile, exp->elts[pc + 1].objfile,
@ -5049,7 +5043,7 @@ ada_identical_enum_types_p (struct type *type1, struct type *type2)
So, for practical purposes, we consider them as the same. */ So, for practical purposes, we consider them as the same. */
static int static int
symbols_are_identical_enums (struct block_symbol *syms, int nsyms) symbols_are_identical_enums (const std::vector<struct block_symbol> &syms)
{ {
int i; int i;
@ -5061,17 +5055,17 @@ symbols_are_identical_enums (struct block_symbol *syms, int nsyms)
(see ada_identical_enum_types_p). */ (see ada_identical_enum_types_p). */
/* Quick check: All symbols should have an enum type. */ /* Quick check: All symbols should have an enum type. */
for (i = 0; i < nsyms; i++) for (i = 0; i < syms.size (); i++)
if (TYPE_CODE (SYMBOL_TYPE (syms[i].symbol)) != TYPE_CODE_ENUM) if (TYPE_CODE (SYMBOL_TYPE (syms[i].symbol)) != TYPE_CODE_ENUM)
return 0; return 0;
/* Quick check: They should all have the same value. */ /* Quick check: They should all have the same value. */
for (i = 1; i < nsyms; i++) for (i = 1; i < syms.size (); i++)
if (SYMBOL_VALUE (syms[i].symbol) != SYMBOL_VALUE (syms[0].symbol)) if (SYMBOL_VALUE (syms[i].symbol) != SYMBOL_VALUE (syms[0].symbol))
return 0; return 0;
/* Quick check: They should all have the same number of enumerals. */ /* Quick check: They should all have the same number of enumerals. */
for (i = 1; i < nsyms; i++) for (i = 1; i < syms.size (); i++)
if (TYPE_NFIELDS (SYMBOL_TYPE (syms[i].symbol)) if (TYPE_NFIELDS (SYMBOL_TYPE (syms[i].symbol))
!= TYPE_NFIELDS (SYMBOL_TYPE (syms[0].symbol))) != TYPE_NFIELDS (SYMBOL_TYPE (syms[0].symbol)))
return 0; return 0;
@ -5079,7 +5073,7 @@ symbols_are_identical_enums (struct block_symbol *syms, int nsyms)
/* All the sanity checks passed, so we might have a set of /* All the sanity checks passed, so we might have a set of
identical enumeration types. Perform a more complete identical enumeration types. Perform a more complete
comparison of the type of each symbol. */ comparison of the type of each symbol. */
for (i = 1; i < nsyms; i++) for (i = 1; i < syms.size (); i++)
if (!ada_identical_enum_types_p (SYMBOL_TYPE (syms[i].symbol), if (!ada_identical_enum_types_p (SYMBOL_TYPE (syms[i].symbol),
SYMBOL_TYPE (syms[0].symbol))) SYMBOL_TYPE (syms[0].symbol)))
return 0; return 0;
@ -5087,7 +5081,7 @@ symbols_are_identical_enums (struct block_symbol *syms, int nsyms)
return 1; return 1;
} }
/* Remove any non-debugging symbols in SYMS[0 .. NSYMS-1] that definitely /* Remove any non-debugging symbols in SYMS that definitely
duplicate other symbols in the list (The only case I know of where duplicate other symbols in the list (The only case I know of where
this happens is when object files containing stabs-in-ecoff are this happens is when object files containing stabs-in-ecoff are
linked with files containing ordinary ecoff debugging symbols (or no linked with files containing ordinary ecoff debugging symbols (or no
@ -5095,34 +5089,34 @@ symbols_are_identical_enums (struct block_symbol *syms, int nsyms)
Returns the number of items in the modified list. */ Returns the number of items in the modified list. */
static int static int
remove_extra_symbols (struct block_symbol *syms, int nsyms) remove_extra_symbols (std::vector<struct block_symbol> *syms)
{ {
int i, j; int i, j;
/* We should never be called with less than 2 symbols, as there /* We should never be called with less than 2 symbols, as there
cannot be any extra symbol in that case. But it's easy to cannot be any extra symbol in that case. But it's easy to
handle, since we have nothing to do in that case. */ handle, since we have nothing to do in that case. */
if (nsyms < 2) if (syms->size () < 2)
return nsyms; return syms->size ();
i = 0; i = 0;
while (i < nsyms) while (i < syms->size ())
{ {
int remove_p = 0; int remove_p = 0;
/* If two symbols have the same name and one of them is a stub type, /* If two symbols have the same name and one of them is a stub type,
the get rid of the stub. */ the get rid of the stub. */
if (TYPE_STUB (SYMBOL_TYPE (syms[i].symbol)) if (TYPE_STUB (SYMBOL_TYPE ((*syms)[i].symbol))
&& SYMBOL_LINKAGE_NAME (syms[i].symbol) != NULL) && SYMBOL_LINKAGE_NAME ((*syms)[i].symbol) != NULL)
{ {
for (j = 0; j < nsyms; j++) for (j = 0; j < syms->size (); j++)
{ {
if (j != i if (j != i
&& !TYPE_STUB (SYMBOL_TYPE (syms[j].symbol)) && !TYPE_STUB (SYMBOL_TYPE ((*syms)[j].symbol))
&& SYMBOL_LINKAGE_NAME (syms[j].symbol) != NULL && SYMBOL_LINKAGE_NAME ((*syms)[j].symbol) != NULL
&& strcmp (SYMBOL_LINKAGE_NAME (syms[i].symbol), && strcmp (SYMBOL_LINKAGE_NAME ((*syms)[i].symbol),
SYMBOL_LINKAGE_NAME (syms[j].symbol)) == 0) SYMBOL_LINKAGE_NAME ((*syms)[j].symbol)) == 0)
remove_p = 1; remove_p = 1;
} }
} }
@ -5130,30 +5124,26 @@ remove_extra_symbols (struct block_symbol *syms, int nsyms)
/* Two symbols with the same name, same class and same address /* Two symbols with the same name, same class and same address
should be identical. */ should be identical. */
else if (SYMBOL_LINKAGE_NAME (syms[i].symbol) != NULL else if (SYMBOL_LINKAGE_NAME ((*syms)[i].symbol) != NULL
&& SYMBOL_CLASS (syms[i].symbol) == LOC_STATIC && SYMBOL_CLASS ((*syms)[i].symbol) == LOC_STATIC
&& is_nondebugging_type (SYMBOL_TYPE (syms[i].symbol))) && is_nondebugging_type (SYMBOL_TYPE ((*syms)[i].symbol)))
{ {
for (j = 0; j < nsyms; j += 1) for (j = 0; j < syms->size (); j += 1)
{ {
if (i != j if (i != j
&& SYMBOL_LINKAGE_NAME (syms[j].symbol) != NULL && SYMBOL_LINKAGE_NAME ((*syms)[j].symbol) != NULL
&& strcmp (SYMBOL_LINKAGE_NAME (syms[i].symbol), && strcmp (SYMBOL_LINKAGE_NAME ((*syms)[i].symbol),
SYMBOL_LINKAGE_NAME (syms[j].symbol)) == 0 SYMBOL_LINKAGE_NAME ((*syms)[j].symbol)) == 0
&& SYMBOL_CLASS (syms[i].symbol) && SYMBOL_CLASS ((*syms)[i].symbol)
== SYMBOL_CLASS (syms[j].symbol) == SYMBOL_CLASS ((*syms)[j].symbol)
&& SYMBOL_VALUE_ADDRESS (syms[i].symbol) && SYMBOL_VALUE_ADDRESS ((*syms)[i].symbol)
== SYMBOL_VALUE_ADDRESS (syms[j].symbol)) == SYMBOL_VALUE_ADDRESS ((*syms)[j].symbol))
remove_p = 1; remove_p = 1;
} }
} }
if (remove_p) if (remove_p)
{ syms->erase (syms->begin () + i);
for (j = i + 1; j < nsyms; j += 1)
syms[j - 1] = syms[j];
nsyms -= 1;
}
i += 1; i += 1;
} }
@ -5170,10 +5160,10 @@ remove_extra_symbols (struct block_symbol *syms, int nsyms)
to ask the user to disambiguate anyways. And if we have to to ask the user to disambiguate anyways. And if we have to
present a multiple-choice menu, it's less confusing if the list present a multiple-choice menu, it's less confusing if the list
isn't missing some choices that were identical and yet distinct. */ isn't missing some choices that were identical and yet distinct. */
if (symbols_are_identical_enums (syms, nsyms)) if (symbols_are_identical_enums (*syms))
nsyms = 1; syms->resize (1);
return nsyms; return syms->size ();
} }
/* Given a type that corresponds to a renaming entity, use the type name /* Given a type that corresponds to a renaming entity, use the type name
@ -5301,8 +5291,8 @@ old_renaming_is_invisible (const struct symbol *sym, const char *function_name)
the user will be unable to print such rename entities. */ the user will be unable to print such rename entities. */
static int static int
remove_irrelevant_renamings (struct block_symbol *syms, remove_irrelevant_renamings (std::vector<struct block_symbol> *syms,
int nsyms, const struct block *current_block) const struct block *current_block)
{ {
struct symbol *current_function; struct symbol *current_function;
const char *current_function_name; const char *current_function_name;
@ -5313,10 +5303,10 @@ remove_irrelevant_renamings (struct block_symbol *syms,
a simple variable foo in the same block, discard the latter. a simple variable foo in the same block, discard the latter.
First, zero out such symbols, then compress. */ First, zero out such symbols, then compress. */
is_new_style_renaming = 0; is_new_style_renaming = 0;
for (i = 0; i < nsyms; i += 1) for (i = 0; i < syms->size (); i += 1)
{ {
struct symbol *sym = syms[i].symbol; struct symbol *sym = (*syms)[i].symbol;
const struct block *block = syms[i].block; const struct block *block = (*syms)[i].block;
const char *name; const char *name;
const char *suffix; const char *suffix;
@ -5331,22 +5321,22 @@ remove_irrelevant_renamings (struct block_symbol *syms,
int j; int j;
is_new_style_renaming = 1; is_new_style_renaming = 1;
for (j = 0; j < nsyms; j += 1) for (j = 0; j < syms->size (); j += 1)
if (i != j && syms[j].symbol != NULL if (i != j && (*syms)[j].symbol != NULL
&& strncmp (name, SYMBOL_LINKAGE_NAME (syms[j].symbol), && strncmp (name, SYMBOL_LINKAGE_NAME ((*syms)[j].symbol),
name_len) == 0 name_len) == 0
&& block == syms[j].block) && block == (*syms)[j].block)
syms[j].symbol = NULL; (*syms)[j].symbol = NULL;
} }
} }
if (is_new_style_renaming) if (is_new_style_renaming)
{ {
int j, k; int j, k;
for (j = k = 0; j < nsyms; j += 1) for (j = k = 0; j < syms->size (); j += 1)
if (syms[j].symbol != NULL) if ((*syms)[j].symbol != NULL)
{ {
syms[k] = syms[j]; (*syms)[k] = (*syms)[j];
k += 1; k += 1;
} }
return k; return k;
@ -5356,38 +5346,33 @@ remove_irrelevant_renamings (struct block_symbol *syms,
Abort if unable to do so. */ Abort if unable to do so. */
if (current_block == NULL) if (current_block == NULL)
return nsyms; return syms->size ();
current_function = block_linkage_function (current_block); current_function = block_linkage_function (current_block);
if (current_function == NULL) if (current_function == NULL)
return nsyms; return syms->size ();
current_function_name = SYMBOL_LINKAGE_NAME (current_function); current_function_name = SYMBOL_LINKAGE_NAME (current_function);
if (current_function_name == NULL) if (current_function_name == NULL)
return nsyms; return syms->size ();
/* Check each of the symbols, and remove it from the list if it is /* Check each of the symbols, and remove it from the list if it is
a type corresponding to a renaming that is out of the scope of a type corresponding to a renaming that is out of the scope of
the current block. */ the current block. */
i = 0; i = 0;
while (i < nsyms) while (i < syms->size ())
{ {
if (ada_parse_renaming (syms[i].symbol, NULL, NULL, NULL) if (ada_parse_renaming ((*syms)[i].symbol, NULL, NULL, NULL)
== ADA_OBJECT_RENAMING == ADA_OBJECT_RENAMING
&& old_renaming_is_invisible (syms[i].symbol, current_function_name)) && old_renaming_is_invisible ((*syms)[i].symbol,
{ current_function_name))
int j; syms->erase (syms->begin () + i);
for (j = i + 1; j < nsyms; j += 1)
syms[j - 1] = syms[j];
nsyms -= 1;
}
else else
i += 1; i += 1;
} }
return nsyms; return syms->size ();
} }
/* Add to OBSTACKP all symbols from BLOCK (and its super-blocks) /* Add to OBSTACKP all symbols from BLOCK (and its super-blocks)
@ -5779,10 +5764,9 @@ ada_add_all_symbols (struct obstack *obstackp,
/* Find symbols in DOMAIN matching LOOKUP_NAME, in BLOCK and, if FULL_SEARCH /* Find symbols in DOMAIN matching LOOKUP_NAME, in BLOCK and, if FULL_SEARCH
is non-zero, enclosing scope and in global scopes, returning the number of is non-zero, enclosing scope and in global scopes, returning the number of
matches. matches.
Sets *RESULTS to point to a newly allocated vector of (SYM,BLOCK) tuples, Fills *RESULTS with (SYM,BLOCK) tuples, indicating the symbols
indicating the symbols found and the blocks and symbol tables (if found and the blocks and symbol tables (if any) in which they were
any) in which they were found. This vector should be freed when found.
no longer useful.
When full_search is non-zero, any non-function/non-enumeral When full_search is non-zero, any non-function/non-enumeral
symbol match within the nest of blocks whose innermost member is BLOCK, symbol match within the nest of blocks whose innermost member is BLOCK,
@ -5797,7 +5781,7 @@ static int
ada_lookup_symbol_list_worker (const lookup_name_info &lookup_name, ada_lookup_symbol_list_worker (const lookup_name_info &lookup_name,
const struct block *block, const struct block *block,
domain_enum domain, domain_enum domain,
struct block_symbol **results, std::vector<struct block_symbol> *results,
int full_search) int full_search)
{ {
int syms_from_global_search; int syms_from_global_search;
@ -5810,11 +5794,11 @@ ada_lookup_symbol_list_worker (const lookup_name_info &lookup_name,
ndefns = num_defns_collected (&obstack); ndefns = num_defns_collected (&obstack);
results_size = obstack_object_size (&obstack); struct block_symbol *base = defns_collected (&obstack, 1);
*results = (struct block_symbol *) malloc (results_size); for (int i = 0; i < ndefns; ++i)
memcpy (*results, defns_collected (&obstack, 1), results_size); results->push_back (base[i]);
ndefns = remove_extra_symbols (*results, ndefns); ndefns = remove_extra_symbols (results);
if (ndefns == 0 && full_search && syms_from_global_search) if (ndefns == 0 && full_search && syms_from_global_search)
cache_symbol (ada_lookup_name (lookup_name), domain, NULL, NULL); cache_symbol (ada_lookup_name (lookup_name), domain, NULL, NULL);
@ -5823,21 +5807,21 @@ ada_lookup_symbol_list_worker (const lookup_name_info &lookup_name,
cache_symbol (ada_lookup_name (lookup_name), domain, cache_symbol (ada_lookup_name (lookup_name), domain,
(*results)[0].symbol, (*results)[0].block); (*results)[0].symbol, (*results)[0].block);
ndefns = remove_irrelevant_renamings (*results, ndefns, block); ndefns = remove_irrelevant_renamings (results, block);
return ndefns; return ndefns;
} }
/* Find symbols in DOMAIN matching NAME, in BLOCK and enclosing scope and /* Find symbols in DOMAIN matching NAME, in BLOCK and enclosing scope and
in global scopes, returning the number of matches, and setting *RESULTS in global scopes, returning the number of matches, and filling *RESULTS
to a newly-allocated vector of (SYM,BLOCK) tuples. This newly-allocated with (SYM,BLOCK) tuples.
vector should be freed when no longer useful.
See ada_lookup_symbol_list_worker for further details. */ See ada_lookup_symbol_list_worker for further details. */
int int
ada_lookup_symbol_list (const char *name, const struct block *block, ada_lookup_symbol_list (const char *name, const struct block *block,
domain_enum domain, struct block_symbol **results) domain_enum domain,
std::vector<struct block_symbol> *results)
{ {
symbol_name_match_type name_match_type = name_match_type_from_name (name); symbol_name_match_type name_match_type = name_match_type_from_name (name);
lookup_name_info lookup_name (name, name_match_type); lookup_name_info lookup_name (name, name_match_type);
@ -5854,19 +5838,15 @@ ada_iterate_over_symbols
gdb::function_view<symbol_found_callback_ftype> callback) gdb::function_view<symbol_found_callback_ftype> callback)
{ {
int ndefs, i; int ndefs, i;
struct block_symbol *results; std::vector<struct block_symbol> results;
struct cleanup *old_chain;
ndefs = ada_lookup_symbol_list_worker (name, block, domain, &results, 0); ndefs = ada_lookup_symbol_list_worker (name, block, domain, &results, 0);
old_chain = make_cleanup (xfree, results);
for (i = 0; i < ndefs; ++i) for (i = 0; i < ndefs; ++i)
{ {
if (!callback (results[i].symbol)) if (!callback (results[i].symbol))
break; break;
} }
do_cleanups (old_chain);
} }
/* The result is as for ada_lookup_symbol_list with FULL_SEARCH set /* The result is as for ada_lookup_symbol_list with FULL_SEARCH set
@ -5906,24 +5886,16 @@ ada_lookup_symbol (const char *name, const struct block *block0,
if (is_a_field_of_this != NULL) if (is_a_field_of_this != NULL)
*is_a_field_of_this = 0; *is_a_field_of_this = 0;
struct block_symbol *candidates; std::vector<struct block_symbol> candidates;
int n_candidates; int n_candidates;
struct cleanup *old_chain;
n_candidates = ada_lookup_symbol_list (name, block0, domain, &candidates); n_candidates = ada_lookup_symbol_list (name, block0, domain, &candidates);
old_chain = make_cleanup (xfree, candidates);
if (n_candidates == 0) if (n_candidates == 0)
{ return {};
do_cleanups (old_chain);
return {};
}
block_symbol info = candidates[0]; block_symbol info = candidates[0];
info.symbol = fixup_symbol_section (info.symbol, NULL); info.symbol = fixup_symbol_section (info.symbol, NULL);
do_cleanups (old_chain);
return info; return info;
} }
@ -11766,24 +11738,20 @@ get_var_value (const char *name, const char *err_msg)
{ {
lookup_name_info lookup_name (name, symbol_name_match_type::FULL); lookup_name_info lookup_name (name, symbol_name_match_type::FULL);
struct block_symbol *syms; std::vector<struct block_symbol> syms;
int nsyms = ada_lookup_symbol_list_worker (lookup_name, int nsyms = ada_lookup_symbol_list_worker (lookup_name,
get_selected_block (0), get_selected_block (0),
VAR_DOMAIN, &syms, 1); VAR_DOMAIN, &syms, 1);
struct cleanup *old_chain = make_cleanup (xfree, syms);
if (nsyms != 1) if (nsyms != 1)
{ {
do_cleanups (old_chain);
if (err_msg == NULL) if (err_msg == NULL)
return 0; return 0;
else else
error (("%s"), err_msg); error (("%s"), err_msg);
} }
struct value *result = value_of_variable (syms[0].symbol, syms[0].block); return value_of_variable (syms[0].symbol, syms[0].block);
do_cleanups (old_chain);
return result;
} }
/* Value of integer variable named NAME in the current environment. /* Value of integer variable named NAME in the current environment.

View file

@ -232,7 +232,8 @@ extern const char *ada_decode (const char*);
extern enum language ada_update_initial_language (enum language); extern enum language ada_update_initial_language (enum language);
extern int ada_lookup_symbol_list (const char *, const struct block *, extern int ada_lookup_symbol_list (const char *, const struct block *,
domain_enum, struct block_symbol**); domain_enum,
std::vector<struct block_symbol> *);
extern char *ada_fold_name (const char *); extern char *ada_fold_name (const char *);