block_lookup (const struct block *context, const char *raw_name)
{
const char *name;
- struct block_symbol *syms;
+ std::vector<struct block_symbol> syms;
int nsyms;
struct symtab *symtab;
- struct cleanup *old_chain;
const struct block *result = NULL;
if (raw_name[0] == '\'')
name = ada_encode (raw_name);
nsyms = ada_lookup_symbol_list (name, context, VAR_DOMAIN, &syms);
- old_chain = make_cleanup (xfree, syms);
if (context == NULL
&& (nsyms == 0 || SYMBOL_CLASS (syms[0].symbol) != LOC_BLOCK))
result = SYMBOL_BLOCK_VALUE (syms[0].symbol);
}
- do_cleanups (old_chain);
return result;
}
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 preferred_index;
struct type *preferred_type;
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))
{
case LOC_TYPEDEF:
int depth;
char *encoded_name;
int name_len;
- struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
if (block == NULL)
block = expression_context_block;
while (tail_index > 0)
{
int nsyms;
- struct block_symbol *syms;
+ std::vector<struct block_symbol> syms;
struct symbol *type_sym;
struct symbol *renaming_sym;
const char* renaming;
encoded_name[tail_index] = '\0';
nsyms = ada_lookup_symbol_list (encoded_name, block,
VAR_DOMAIN, &syms);
- make_cleanup (xfree, syms);
encoded_name[tail_index] = terminator;
/* A single symbol may rename a package or object. */
syms[0].symbol = ren_sym;
}
- type_sym = select_possible_type_sym (syms, nsyms);
+ type_sym = select_possible_type_sym (syms);
if (type_sym != NULL)
renaming_sym = type_sym;
write_object_renaming (par_state, block, renaming, renaming_len,
renaming_expr, MAX_RENAMING_CHAIN_LENGTH);
write_selectors (par_state, encoded_name + tail_index);
- do_cleanups (old_chain);
return NULL;
default:
internal_error (__FILE__, __LINE__,
struct type *field_type;
if (tail_index == name_len)
- {
- do_cleanups (old_chain);
- return SYMBOL_TYPE (type_sym);
- }
+ return SYMBOL_TYPE (type_sym);
/* We have some extraneous characters after the type name.
If this is an expression "TYPE_NAME.FIELD0.[...].FIELDN",
field_type
= get_symbol_field_type (type_sym, encoded_name + tail_index);
if (field_type != NULL)
- {
- do_cleanups (old_chain);
- return field_type;
- }
+ return field_type;
else
error (_("Invalid attempt to select from type: \"%s\"."),
name0.ptr);
encoded_name);
if (type != NULL)
- {
- do_cleanups (old_chain);
- return type;
- }
+ return type;
}
if (nsyms == 1)
{
write_var_from_sym (par_state, syms[0].block, syms[0].symbol);
write_selectors (par_state, encoded_name + tail_index);
- do_cleanups (old_chain);
return NULL;
}
else if (nsyms == 0)
write_exp_msymbol (par_state, msym);
/* Maybe cause error here rather than later? FIXME? */
write_selectors (par_state, encoded_name + tail_index);
- do_cleanups (old_chain);
return NULL;
}
write_ambiguous_var (par_state, block, encoded_name,
tail_index);
write_selectors (par_state, encoded_name + tail_index);
- do_cleanups (old_chain);
return 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,
VAR_DOMAIN, &syms);
- struct cleanup *old_chain = make_cleanup (xfree, syms);
if (nsyms != 1 || SYMBOL_CLASS (syms[0].symbol) == LOC_TYPEDEF)
write_exp_op_with_string (par_state, OP_NAME, name);
else
write_var_from_sym (par_state, syms[0].block, syms[0].symbol);
-
- do_cleanups (old_chain);
}
else
if (write_var_or_type (par_state, NULL, name) != NULL)
struct value **argvec; /* Vector of operand types (alloca'ed). */
int nargs; /* Number of operands. */
int oplen;
- struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
argvec = NULL;
nargs = 0;
case OP_VAR_VALUE:
if (SYMBOL_DOMAIN (exp->elts[pc + 2].symbol) == UNDEF_DOMAIN)
{
- struct block_symbol *candidates;
+ std::vector<struct block_symbol> candidates;
int n_candidates;
n_candidates =
(exp->elts[pc + 2].symbol),
exp->elts[pc + 1].block, VAR_DOMAIN,
&candidates);
- make_cleanup (xfree, candidates);
if (n_candidates > 1)
{
else if (n_candidates == 1)
i = 0;
else if (deprocedure_p
- && !is_nonfunction (candidates, n_candidates))
+ && !is_nonfunction (candidates.data (), n_candidates))
{
i = ada_resolve_function
- (candidates, n_candidates, NULL, 0,
+ (candidates.data (), n_candidates, NULL, 0,
SYMBOL_LINKAGE_NAME (exp->elts[pc + 2].symbol),
context_type);
if (i < 0)
{
printf_filtered (_("Multiple matches for %s\n"),
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;
}
if (exp->elts[pc + 3].opcode == OP_VAR_VALUE
&& SYMBOL_DOMAIN (exp->elts[pc + 5].symbol) == UNDEF_DOMAIN)
{
- struct block_symbol *candidates;
+ std::vector<struct block_symbol> candidates;
int n_candidates;
n_candidates =
(exp->elts[pc + 5].symbol),
exp->elts[pc + 4].block, VAR_DOMAIN,
&candidates);
- make_cleanup (xfree, candidates);
if (n_candidates == 1)
i = 0;
else
{
i = ada_resolve_function
- (candidates, n_candidates,
+ (candidates.data (), n_candidates,
argvec, nargs,
SYMBOL_LINKAGE_NAME (exp->elts[pc + 5].symbol),
context_type);
case UNOP_ABS:
if (possible_user_operator_p (op, argvec))
{
- struct block_symbol *candidates;
+ std::vector<struct block_symbol> candidates;
int n_candidates;
n_candidates =
ada_lookup_symbol_list (ada_decoded_op_name (op),
(struct block *) NULL, VAR_DOMAIN,
&candidates);
- make_cleanup (xfree, candidates);
- i = ada_resolve_function (candidates, n_candidates, argvec, nargs,
- ada_decoded_op_name (op), NULL);
+ i = ada_resolve_function (candidates.data (), n_candidates, argvec,
+ nargs, ada_decoded_op_name (op), NULL);
if (i < 0)
break;
case OP_TYPE:
case OP_REGISTER:
- do_cleanups (old_chain);
return NULL;
}
*pos = pc;
- do_cleanups (old_chain);
if (exp->elts[pc].opcode == OP_VAR_MSYM_VALUE)
return evaluate_var_msym_value (EVAL_AVOID_SIDE_EFFECTS,
exp->elts[pc + 1].objfile,
So, for practical purposes, we consider them as the same. */
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;
(see ada_identical_enum_types_p). */
/* 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)
return 0;
/* 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))
return 0;
/* 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))
!= TYPE_NFIELDS (SYMBOL_TYPE (syms[0].symbol)))
return 0;
/* All the sanity checks passed, so we might have a set of
identical enumeration types. Perform a more complete
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),
SYMBOL_TYPE (syms[0].symbol)))
return 0;
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
this happens is when object files containing stabs-in-ecoff are
linked with files containing ordinary ecoff debugging symbols (or no
Returns the number of items in the modified list. */
static int
-remove_extra_symbols (struct block_symbol *syms, int nsyms)
+remove_extra_symbols (std::vector<struct block_symbol> *syms)
{
int i, j;
/* 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
handle, since we have nothing to do in that case. */
- if (nsyms < 2)
- return nsyms;
+ if (syms->size () < 2)
+ return syms->size ();
i = 0;
- while (i < nsyms)
+ while (i < syms->size ())
{
int remove_p = 0;
/* If two symbols have the same name and one of them is a stub type,
the get rid of the stub. */
- if (TYPE_STUB (SYMBOL_TYPE (syms[i].symbol))
- && SYMBOL_LINKAGE_NAME (syms[i].symbol) != NULL)
+ if (TYPE_STUB (SYMBOL_TYPE ((*syms)[i].symbol))
+ && SYMBOL_LINKAGE_NAME ((*syms)[i].symbol) != NULL)
{
- for (j = 0; j < nsyms; j++)
+ for (j = 0; j < syms->size (); j++)
{
if (j != i
- && !TYPE_STUB (SYMBOL_TYPE (syms[j].symbol))
- && SYMBOL_LINKAGE_NAME (syms[j].symbol) != NULL
- && strcmp (SYMBOL_LINKAGE_NAME (syms[i].symbol),
- SYMBOL_LINKAGE_NAME (syms[j].symbol)) == 0)
+ && !TYPE_STUB (SYMBOL_TYPE ((*syms)[j].symbol))
+ && SYMBOL_LINKAGE_NAME ((*syms)[j].symbol) != NULL
+ && strcmp (SYMBOL_LINKAGE_NAME ((*syms)[i].symbol),
+ SYMBOL_LINKAGE_NAME ((*syms)[j].symbol)) == 0)
remove_p = 1;
}
}
/* Two symbols with the same name, same class and same address
should be identical. */
- else if (SYMBOL_LINKAGE_NAME (syms[i].symbol) != NULL
- && SYMBOL_CLASS (syms[i].symbol) == LOC_STATIC
- && is_nondebugging_type (SYMBOL_TYPE (syms[i].symbol)))
+ else if (SYMBOL_LINKAGE_NAME ((*syms)[i].symbol) != NULL
+ && SYMBOL_CLASS ((*syms)[i].symbol) == LOC_STATIC
+ && 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
- && SYMBOL_LINKAGE_NAME (syms[j].symbol) != NULL
- && strcmp (SYMBOL_LINKAGE_NAME (syms[i].symbol),
- SYMBOL_LINKAGE_NAME (syms[j].symbol)) == 0
- && SYMBOL_CLASS (syms[i].symbol)
- == SYMBOL_CLASS (syms[j].symbol)
- && SYMBOL_VALUE_ADDRESS (syms[i].symbol)
- == SYMBOL_VALUE_ADDRESS (syms[j].symbol))
+ && SYMBOL_LINKAGE_NAME ((*syms)[j].symbol) != NULL
+ && strcmp (SYMBOL_LINKAGE_NAME ((*syms)[i].symbol),
+ SYMBOL_LINKAGE_NAME ((*syms)[j].symbol)) == 0
+ && SYMBOL_CLASS ((*syms)[i].symbol)
+ == SYMBOL_CLASS ((*syms)[j].symbol)
+ && SYMBOL_VALUE_ADDRESS ((*syms)[i].symbol)
+ == SYMBOL_VALUE_ADDRESS ((*syms)[j].symbol))
remove_p = 1;
}
}
if (remove_p)
- {
- for (j = i + 1; j < nsyms; j += 1)
- syms[j - 1] = syms[j];
- nsyms -= 1;
- }
+ syms->erase (syms->begin () + i);
i += 1;
}
to ask the user to disambiguate anyways. And if we have to
present a multiple-choice menu, it's less confusing if the list
isn't missing some choices that were identical and yet distinct. */
- if (symbols_are_identical_enums (syms, nsyms))
- nsyms = 1;
+ if (symbols_are_identical_enums (*syms))
+ syms->resize (1);
- return nsyms;
+ return syms->size ();
}
/* Given a type that corresponds to a renaming entity, use the type name
the user will be unable to print such rename entities. */
static int
-remove_irrelevant_renamings (struct block_symbol *syms,
- int nsyms, const struct block *current_block)
+remove_irrelevant_renamings (std::vector<struct block_symbol> *syms,
+ const struct block *current_block)
{
struct symbol *current_function;
const char *current_function_name;
a simple variable foo in the same block, discard the latter.
First, zero out such symbols, then compress. */
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;
- const struct block *block = syms[i].block;
+ struct symbol *sym = (*syms)[i].symbol;
+ const struct block *block = (*syms)[i].block;
const char *name;
const char *suffix;
int j;
is_new_style_renaming = 1;
- for (j = 0; j < nsyms; j += 1)
- if (i != j && syms[j].symbol != NULL
- && strncmp (name, SYMBOL_LINKAGE_NAME (syms[j].symbol),
+ for (j = 0; j < syms->size (); j += 1)
+ if (i != j && (*syms)[j].symbol != NULL
+ && strncmp (name, SYMBOL_LINKAGE_NAME ((*syms)[j].symbol),
name_len) == 0
- && block == syms[j].block)
- syms[j].symbol = NULL;
+ && block == (*syms)[j].block)
+ (*syms)[j].symbol = NULL;
}
}
if (is_new_style_renaming)
{
int j, k;
- for (j = k = 0; j < nsyms; j += 1)
- if (syms[j].symbol != NULL)
+ for (j = k = 0; j < syms->size (); j += 1)
+ if ((*syms)[j].symbol != NULL)
{
- syms[k] = syms[j];
+ (*syms)[k] = (*syms)[j];
k += 1;
}
return k;
Abort if unable to do so. */
if (current_block == NULL)
- return nsyms;
+ return syms->size ();
current_function = block_linkage_function (current_block);
if (current_function == NULL)
- return nsyms;
+ return syms->size ();
current_function_name = SYMBOL_LINKAGE_NAME (current_function);
if (current_function_name == NULL)
- return nsyms;
+ return syms->size ();
/* 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
the current block. */
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
- && old_renaming_is_invisible (syms[i].symbol, current_function_name))
- {
- int j;
-
- for (j = i + 1; j < nsyms; j += 1)
- syms[j - 1] = syms[j];
- nsyms -= 1;
- }
+ && old_renaming_is_invisible ((*syms)[i].symbol,
+ current_function_name))
+ syms->erase (syms->begin () + i);
else
i += 1;
}
- return nsyms;
+ return syms->size ();
}
/* Add to OBSTACKP all symbols from BLOCK (and its super-blocks)
/* 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
matches.
- Sets *RESULTS to point to a newly allocated vector of (SYM,BLOCK) tuples,
- indicating the symbols found and the blocks and symbol tables (if
- any) in which they were found. This vector should be freed when
- no longer useful.
+ Fills *RESULTS with (SYM,BLOCK) tuples, indicating the symbols
+ found and the blocks and symbol tables (if any) in which they were
+ found.
When full_search is non-zero, any non-function/non-enumeral
symbol match within the nest of blocks whose innermost member is BLOCK,
ada_lookup_symbol_list_worker (const lookup_name_info &lookup_name,
const struct block *block,
domain_enum domain,
- struct block_symbol **results,
+ std::vector<struct block_symbol> *results,
int full_search)
{
int syms_from_global_search;
ndefns = num_defns_collected (&obstack);
- results_size = obstack_object_size (&obstack);
- *results = (struct block_symbol *) malloc (results_size);
- memcpy (*results, defns_collected (&obstack, 1), results_size);
+ struct block_symbol *base = defns_collected (&obstack, 1);
+ for (int i = 0; i < ndefns; ++i)
+ 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)
cache_symbol (ada_lookup_name (lookup_name), domain, NULL, NULL);
cache_symbol (ada_lookup_name (lookup_name), domain,
(*results)[0].symbol, (*results)[0].block);
- ndefns = remove_irrelevant_renamings (*results, ndefns, block);
+ ndefns = remove_irrelevant_renamings (results, block);
return ndefns;
}
/* Find symbols in DOMAIN matching NAME, in BLOCK and enclosing scope and
- in global scopes, returning the number of matches, and setting *RESULTS
- to a newly-allocated vector of (SYM,BLOCK) tuples. This newly-allocated
- vector should be freed when no longer useful.
+ in global scopes, returning the number of matches, and filling *RESULTS
+ with (SYM,BLOCK) tuples.
See ada_lookup_symbol_list_worker for further details. */
int
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);
lookup_name_info lookup_name (name, name_match_type);
gdb::function_view<symbol_found_callback_ftype> callback)
{
int ndefs, i;
- struct block_symbol *results;
- struct cleanup *old_chain;
+ std::vector<struct block_symbol> results;
ndefs = ada_lookup_symbol_list_worker (name, block, domain, &results, 0);
- old_chain = make_cleanup (xfree, results);
for (i = 0; i < ndefs; ++i)
{
if (!callback (results[i].symbol))
break;
}
-
- do_cleanups (old_chain);
}
/* The result is as for ada_lookup_symbol_list with FULL_SEARCH set
if (is_a_field_of_this != NULL)
*is_a_field_of_this = 0;
- struct block_symbol *candidates;
+ std::vector<struct block_symbol> candidates;
int n_candidates;
- struct cleanup *old_chain;
n_candidates = ada_lookup_symbol_list (name, block0, domain, &candidates);
- old_chain = make_cleanup (xfree, candidates);
if (n_candidates == 0)
- {
- do_cleanups (old_chain);
- return {};
- }
+ return {};
block_symbol info = candidates[0];
info.symbol = fixup_symbol_section (info.symbol, NULL);
-
- do_cleanups (old_chain);
-
return info;
}
{
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,
get_selected_block (0),
VAR_DOMAIN, &syms, 1);
- struct cleanup *old_chain = make_cleanup (xfree, syms);
if (nsyms != 1)
{
- do_cleanups (old_chain);
if (err_msg == NULL)
return 0;
else
error (("%s"), err_msg);
}
- struct value *result = value_of_variable (syms[0].symbol, syms[0].block);
- do_cleanups (old_chain);
- return result;
+ return value_of_variable (syms[0].symbol, syms[0].block);
}
/* Value of integer variable named NAME in the current environment.