Use block_symbol in var_value_operation

I noticed that var_value_operation takes a block and a symbol, and
most callers destructure a block_symbol to pass in.  It seems better
for this class to simply hold a block_symbol instead.

Tested on x86-64 Fedora 32.

gdb/ChangeLog
2021-04-15  Tom Tromey  <tromey@adacore.com>

	* rust-exp.y (rust_parser::convert_ast_to_expression): Update.
	* parse.c (parser_state::push_symbol, parser_state::push_dollar):
	Update.
	* p-exp.y (variable): Update.
	* m2-exp.y (variable): Update.
	* go-exp.y (variable): Update.
	* expprint.c (dump_for_expression): New overload.
	* expop.h (check_objfile): New overload.
	(check_constant): New overload.
	(class var_value_operation): Use block_symbol.
	<get_symbol>: Rewrite.
	* eval.c (var_value_operation::evaluate)
	(var_value_operation::evaluate_funcall)
	(var_value_operation::evaluate_for_address)
	(var_value_operation::evaluate_for_address)
	(var_value_operation::evaluate_with_coercion)
	(var_value_operation::evaluate_for_sizeof)
	(var_value_operation::evaluate_for_cast): Update.
	* d-exp.y (PrimaryExpression): Update.
	* c-exp.y (variable): Update.
	* ax-gdb.c (var_value_operation::do_generate_ax): Update.
	* ada-lang.c (ada_var_value_operation::evaluate_for_cast)
	(ada_var_value_operation::evaluate)
	(ada_var_value_operation::resolve)
	(ada_funcall_operation::resolve): Update.
	* ada-exp.y (write_var_from_sym, write_object_renaming)
	(write_ambiguous_var, write_var_or_type, write_name_assoc)
	(maybe_overload): Update.
	* ada-exp.h (class ada_var_value_operation) <get_block>: Rewrite.
This commit is contained in:
Tom Tromey 2021-04-15 10:05:00 -06:00
parent 4c79248a46
commit 9e5e03df52
15 changed files with 122 additions and 70 deletions

View File

@ -1,3 +1,35 @@
2021-04-15 Tom Tromey <tromey@adacore.com>
* rust-exp.y (rust_parser::convert_ast_to_expression): Update.
* parse.c (parser_state::push_symbol, parser_state::push_dollar):
Update.
* p-exp.y (variable): Update.
* m2-exp.y (variable): Update.
* go-exp.y (variable): Update.
* expprint.c (dump_for_expression): New overload.
* expop.h (check_objfile): New overload.
(check_constant): New overload.
(class var_value_operation): Use block_symbol.
<get_symbol>: Rewrite.
* eval.c (var_value_operation::evaluate)
(var_value_operation::evaluate_funcall)
(var_value_operation::evaluate_for_address)
(var_value_operation::evaluate_for_address)
(var_value_operation::evaluate_with_coercion)
(var_value_operation::evaluate_for_sizeof)
(var_value_operation::evaluate_for_cast): Update.
* d-exp.y (PrimaryExpression): Update.
* c-exp.y (variable): Update.
* ax-gdb.c (var_value_operation::do_generate_ax): Update.
* ada-lang.c (ada_var_value_operation::evaluate_for_cast)
(ada_var_value_operation::evaluate)
(ada_var_value_operation::resolve)
(ada_funcall_operation::resolve): Update.
* ada-exp.y (write_var_from_sym, write_object_renaming)
(write_ambiguous_var, write_var_or_type, write_name_assoc)
(maybe_overload): Update.
* ada-exp.h (class ada_var_value_operation) <get_block>: Rewrite.
2021-04-15 Tom Tromey <tom@tromey.com>
Andrew Burgess <andrew.burgess@embecosm.com>
@ -5051,7 +5083,7 @@
* top.c (print_gdb_version): Update copyright year.
2021-01-01 Joel Brobecker <brobecker@adacore.com>
2021-01-01, 21 Joel Brobecker <brobecker@adacore.com>
* config/djgpp/fnchange.lst: Add entry for gdb/ChangeLog-2020.

View File

@ -1,6 +1,6 @@
/* Definitions for Ada expressions
Copyright (C) 2020 Free Software Foundation, Inc.
Copyright (C) 2020, 2021 Free Software Foundation, Inc.
This file is part of GDB.
@ -352,7 +352,7 @@ public:
enum noside noside) override;
const block *get_block () const
{ return std::get<1> (m_storage); }
{ return std::get<0> (m_storage).block; }
bool resolve (struct expression *exp,
bool deprocedure_p,

View File

@ -194,8 +194,7 @@ maybe_overload (enum exp_opcode op, operation_up &lhs, operation_up &rhs)
if (symbol_read_needs_frame (fn.symbol))
pstate->block_tracker->update (fn.block, INNERMOST_BLOCK_FOR_SYMBOLS);
operation_up callee
= make_operation<ada_var_value_operation> (fn.symbol, fn.block);
operation_up callee = make_operation<ada_var_value_operation> (fn);
std::vector<operation_up> argvec;
argvec.push_back (std::move (lhs));
@ -1124,14 +1123,12 @@ yyerror (const char *msg)
non-NULL). */
static void
write_var_from_sym (struct parser_state *par_state,
const struct block *block,
struct symbol *sym)
write_var_from_sym (struct parser_state *par_state, block_symbol sym)
{
if (symbol_read_needs_frame (sym))
par_state->block_tracker->update (block, INNERMOST_BLOCK_FOR_SYMBOLS);
if (symbol_read_needs_frame (sym.symbol))
par_state->block_tracker->update (sym.block, INNERMOST_BLOCK_FOR_SYMBOLS);
par_state->push_new<ada_var_value_operation> (sym, block);
par_state->push_new<ada_var_value_operation> (sym);
}
/* Write integer or boolean constant ARG of type TYPE. */
@ -1190,7 +1187,7 @@ write_object_renaming (struct parser_state *par_state,
&inner_renaming_expr))
{
case ADA_NOT_RENAMING:
write_var_from_sym (par_state, sym_info.block, sym_info.symbol);
write_var_from_sym (par_state, sym_info);
break;
case ADA_OBJECT_RENAMING:
write_object_renaming (par_state, sym_info.block,
@ -1247,8 +1244,7 @@ write_object_renaming (struct parser_state *par_state,
else if (SYMBOL_CLASS (index_sym_info.symbol) == LOC_TYPEDEF)
/* Index is an old-style renaming symbol. */
index_sym_info.block = orig_left_context;
write_var_from_sym (par_state, index_sym_info.block,
index_sym_info.symbol);
write_var_from_sym (par_state, index_sym_info);
}
if (slice_state == SIMPLE_INDEX)
ada_funcall (1);
@ -1458,7 +1454,8 @@ write_ambiguous_var (struct parser_state *par_state,
sym->set_linkage_name (obstack_strndup (&temp_parse_space, name, len));
sym->set_language (language_ada, nullptr);
par_state->push_new<ada_var_value_operation> (sym, block);
block_symbol bsym { sym, block };
par_state->push_new<ada_var_value_operation> (bsym);
}
/* A convenient wrapper around ada_get_field_index that takes
@ -1637,7 +1634,7 @@ write_var_or_type (struct parser_state *par_state,
if (syms.size () == 1)
{
write_var_from_sym (par_state, syms[0].block, syms[0].symbol);
write_var_from_sym (par_state, syms[0]);
write_selectors (par_state, encoded_name + tail_index);
return NULL;
}
@ -1711,7 +1708,7 @@ write_name_assoc (struct parser_state *par_state, struct stoken name)
if (syms.size () != 1 || SYMBOL_CLASS (syms[0].symbol) == LOC_TYPEDEF)
pstate->push_new<ada_string_operation> (copy_name (name));
else
write_var_from_sym (par_state, syms[0].block, syms[0].symbol);
write_var_from_sym (par_state, syms[0]);
}
else
if (write_var_or_type (par_state, NULL, name) != NULL)

View File

@ -10248,8 +10248,8 @@ ada_var_value_operation::evaluate_for_cast (struct type *expect_type,
enum noside noside)
{
value *val = evaluate_var_value (noside,
std::get<1> (m_storage),
std::get<0> (m_storage));
std::get<0> (m_storage).block,
std::get<0> (m_storage).symbol);
val = ada_value_cast (expect_type, val);
@ -10269,7 +10269,7 @@ ada_var_value_operation::evaluate (struct type *expect_type,
struct expression *exp,
enum noside noside)
{
symbol *sym = std::get<0> (m_storage);
symbol *sym = std::get<0> (m_storage).symbol;
if (SYMBOL_DOMAIN (sym) == UNDEF_DOMAIN)
/* Only encountered when an unresolved symbol occurs in a
@ -10360,19 +10360,19 @@ ada_var_value_operation::resolve (struct expression *exp,
innermost_block_tracker *tracker,
struct type *context_type)
{
symbol *sym = std::get<0> (m_storage);
symbol *sym = std::get<0> (m_storage).symbol;
if (SYMBOL_DOMAIN (sym) == UNDEF_DOMAIN)
{
block_symbol resolved
= ada_resolve_variable (sym, std::get<1> (m_storage),
= ada_resolve_variable (sym, std::get<0> (m_storage).block,
context_type, parse_completion,
deprocedure_p, tracker);
std::get<0> (m_storage) = resolved.symbol;
std::get<1> (m_storage) = resolved.block;
std::get<0> (m_storage) = resolved;
}
if (deprocedure_p
&& SYMBOL_TYPE (std::get<0> (m_storage))->code () == TYPE_CODE_FUNC)
&& (SYMBOL_TYPE (std::get<0> (m_storage).symbol)->code ()
== TYPE_CODE_FUNC))
return true;
return false;
@ -10694,8 +10694,7 @@ ada_funcall_operation::resolve (struct expression *exp,
tracker);
std::get<0> (m_storage)
= make_operation<ada_var_value_operation> (resolved.symbol,
resolved.block);
= make_operation<ada_var_value_operation> (resolved);
return false;
}

View File

@ -1980,16 +1980,16 @@ var_value_operation::do_generate_ax (struct expression *exp,
struct axs_value *value,
struct type *cast_type)
{
gen_var_ref (ax, value, std::get<0> (m_storage));
gen_var_ref (ax, value, std::get<0> (m_storage).symbol);
if (value->optimized_out)
error (_("`%s' has been optimized out, cannot use"),
std::get<0> (m_storage)->print_name ());
std::get<0> (m_storage).symbol->print_name ());
if (value->type->code () == TYPE_CODE_ERROR)
{
if (cast_type == nullptr)
error_unknown_type (std::get<0> (m_storage)->print_name ());
error_unknown_type (std::get<0> (m_storage).symbol->print_name ());
value->type = cast_type;
}
}

View File

@ -1125,8 +1125,7 @@ variable: block COLONCOLON name
if (symbol_read_needs_frame (sym.symbol))
pstate->block_tracker->update (sym);
pstate->push_new<var_value_operation> (sym.symbol,
sym.block);
pstate->push_new<var_value_operation> (sym);
}
;
@ -1197,8 +1196,7 @@ variable: name_not_typename
pstate->push_new<var_msym_value_operation>
(resolver);
else
pstate->push_new<var_value_operation>
(sym.symbol, sym.block);
pstate->push_new<var_value_operation> (sym);
}
else if ($1.is_a_field_of_this)
{
@ -1239,8 +1237,11 @@ variable: name_not_typename
? find_function_alias_target (msymbol)
: NULL);
if (alias_target != NULL)
pstate->push_new<var_value_operation>
(alias_target, SYMBOL_BLOCK_VALUE (alias_target));
{
block_symbol bsym { alias_target,
SYMBOL_BLOCK_VALUE (alias_target) };
pstate->push_new<var_value_operation> (bsym);
}
else
pstate->push_new<var_msym_value_operation>
(msymbol);

View File

@ -452,8 +452,7 @@ PrimaryExpression:
{
if (symbol_read_needs_frame (sym.symbol))
pstate->block_tracker->update (sym);
pstate->push_new<var_value_operation> (sym.symbol,
sym.block);
pstate->push_new<var_value_operation> (sym);
}
else if (is_a_field_of_this.type != NULL)
{

View File

@ -579,10 +579,10 @@ var_value_operation::evaluate (struct type *expect_type,
struct expression *exp,
enum noside noside)
{
symbol *var = std::get<0> (m_storage);
symbol *var = std::get<0> (m_storage).symbol;
if (SYMBOL_TYPE (var)->code () == TYPE_CODE_ERROR)
error_unknown_type (var->print_name ());
return evaluate_var_value (noside, std::get<1> (m_storage), var);
return evaluate_var_value (noside, std::get<0> (m_storage).block, var);
}
} /* namespace expr */
@ -719,12 +719,13 @@ var_value_operation::evaluate_funcall (struct type *expect_type,
struct symbol *symp;
find_overload_match (argvec, NULL, NON_METHOD,
NULL, std::get<0> (m_storage),
NULL, std::get<0> (m_storage).symbol,
NULL, &symp, NULL, 0, noside);
if (SYMBOL_TYPE (symp)->code () == TYPE_CODE_ERROR)
error_unknown_type (symp->print_name ());
value *callee = evaluate_var_value (noside, std::get<1> (m_storage), symp);
value *callee = evaluate_var_value (noside, std::get<0> (m_storage).block,
symp);
return evaluate_subexp_do_call (exp, noside, callee, argvec,
nullptr, expect_type);
@ -2573,7 +2574,7 @@ value *
var_value_operation::evaluate_for_address (struct expression *exp,
enum noside noside)
{
symbol *var = std::get<0> (m_storage);
symbol *var = std::get<0> (m_storage).symbol;
/* C++: The "address" of a reference should yield the address
* of the object pointed to. Let value_addr() deal with it. */
@ -2593,20 +2594,21 @@ var_value_operation::evaluate_for_address (struct expression *exp,
return value_zero (type, not_lval);
}
else
return address_of_variable (var, std::get<1> (m_storage));
return address_of_variable (var, std::get<0> (m_storage).block);
}
value *
var_value_operation::evaluate_with_coercion (struct expression *exp,
enum noside noside)
{
struct symbol *var = std::get<0> (m_storage);
struct symbol *var = std::get<0> (m_storage).symbol;
struct type *type = check_typedef (SYMBOL_TYPE (var));
if (type->code () == TYPE_CODE_ARRAY
&& !type->is_vector ()
&& CAST_IS_CONVERSION (exp->language_defn))
{
struct value *val = address_of_variable (var, std::get<1> (m_storage));
struct value *val = address_of_variable (var,
std::get<0> (m_storage).block);
return value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (type)), val);
}
return evaluate (nullptr, exp, noside);
@ -2730,7 +2732,7 @@ value *
var_value_operation::evaluate_for_sizeof (struct expression *exp,
enum noside noside)
{
struct type *type = SYMBOL_TYPE (std::get<0> (m_storage));
struct type *type = SYMBOL_TYPE (std::get<0> (m_storage).symbol);
if (is_dynamic_type (type))
{
value *val = evaluate (nullptr, exp, EVAL_NORMAL);
@ -2778,8 +2780,8 @@ var_value_operation::evaluate_for_cast (struct type *to_type,
enum noside noside)
{
value *val = evaluate_var_value (noside,
std::get<1> (m_storage),
std::get<0> (m_storage));
std::get<0> (m_storage).block,
std::get<0> (m_storage).symbol);
val = value_cast (to_type, val);

View File

@ -221,7 +221,7 @@ check_objfile (struct objfile *exp_objfile, struct objfile *objfile)
return exp_objfile == objfile;
}
static inline bool
static inline bool
check_objfile (struct type *type, struct objfile *objfile)
{
struct objfile *ty_objfile = type->objfile_owner ();
@ -230,18 +230,25 @@ check_objfile (struct type *type, struct objfile *objfile)
return false;
}
static inline bool
static inline bool
check_objfile (struct symbol *sym, struct objfile *objfile)
{
return check_objfile (symbol_objfile (sym), objfile);
}
static inline bool
static inline bool
check_objfile (const struct block *block, struct objfile *objfile)
{
return check_objfile (block_objfile (block), objfile);
}
static inline bool
check_objfile (const block_symbol &sym, struct objfile *objfile)
{
return (check_objfile (sym.symbol, objfile)
|| check_objfile (sym.block, objfile));
}
static inline bool
check_objfile (bound_minimal_symbol minsym, struct objfile *objfile)
{
@ -260,7 +267,7 @@ check_objfile (const std::string &str, struct objfile *objfile)
return false;
}
static inline bool
static inline bool
check_objfile (const operation_up &op, struct objfile *objfile)
{
return op->uses_objfile (objfile);
@ -286,7 +293,7 @@ check_objfile (enum_flags<T> val, struct objfile *objfile)
}
template<typename T>
static inline bool
static inline bool
check_objfile (const std::vector<T> &collection, struct objfile *objfile)
{
for (const auto &item : collection)
@ -298,7 +305,7 @@ check_objfile (const std::vector<T> &collection, struct objfile *objfile)
}
template<typename S, typename T>
static inline bool
static inline bool
check_objfile (const std::pair<S, T> &item, struct objfile *objfile)
{
return (check_objfile (item.first, objfile)
@ -327,6 +334,8 @@ extern void dump_for_expression (struct ui_file *stream, int depth,
internalvar *ivar);
extern void dump_for_expression (struct ui_file *stream, int depth,
symbol *sym);
extern void dump_for_expression (struct ui_file *stream, int depth,
const block_symbol &sym);
extern void dump_for_expression (struct ui_file *stream, int depth,
bound_minimal_symbol msym);
extern void dump_for_expression (struct ui_file *stream, int depth,
@ -480,6 +489,14 @@ check_constant (struct symbol *sym)
|| sc == LOC_LABEL);
}
static inline bool
check_constant (const block_symbol &sym)
{
/* We know the block is constant, so we only need to check the
symbol. */
return check_constant (sym.symbol);
}
template<typename T>
static inline bool
check_constant (const std::vector<T> &collection)
@ -612,7 +629,7 @@ protected:
/* Compute the value of a variable. */
class var_value_operation
: public maybe_constant_operation<symbol *, const block *>
: public maybe_constant_operation<block_symbol>
{
public:
@ -646,7 +663,7 @@ public:
/* Return the symbol referenced by this object. */
symbol *get_symbol () const
{
return std::get<0> (m_storage);
return std::get<0> (m_storage).symbol;
}
protected:

View File

@ -123,6 +123,15 @@ dump_for_expression (struct ui_file *stream, int depth, const block *bl)
fprintf_filtered (stream, _("%*sBlock: %p\n"), depth, "", bl);
}
void
dump_for_expression (struct ui_file *stream, int depth,
const block_symbol &sym)
{
fprintf_filtered (stream, _("%*sBlock symbol:\n"), depth, "");
dump_for_expression (stream, depth + 1, sym.symbol);
dump_for_expression (stream, depth + 1, sym.block);
}
void
dump_for_expression (struct ui_file *stream, int depth,
type_instance_flags flags)

View File

@ -563,8 +563,7 @@ variable: name_not_typename
if (symbol_read_needs_frame (sym.symbol))
pstate->block_tracker->update (sym);
pstate->push_new<var_value_operation>
(sym.symbol, sym.block);
pstate->push_new<var_value_operation> (sym);
}
else if ($1.is_a_field_of_this)
{

View File

@ -517,8 +517,8 @@ fblock : block COLONCOLON BLOCKNAME
/* Useful for assigning to PROCEDURE variables */
variable: fblock
{
pstate->push_new<var_value_operation>
($1, nullptr);
block_symbol sym { $1, nullptr };
pstate->push_new<var_value_operation> (sym);
}
;
@ -539,8 +539,7 @@ variable: block COLONCOLON NAME
if (symbol_read_needs_frame (sym.symbol))
pstate->block_tracker->update (sym);
pstate->push_new<var_value_operation>
(sym.symbol, sym.block);
pstate->push_new<var_value_operation> (sym);
}
;

View File

@ -651,8 +651,7 @@ variable: block COLONCOLON name
error (_("No symbol \"%s\" in specified context."),
copy.c_str ());
pstate->push_new<var_value_operation>
(sym.symbol, sym.block);
pstate->push_new<var_value_operation> (sym);
}
;
@ -690,8 +689,7 @@ variable: name_not_typename
if (symbol_read_needs_frame (sym.symbol))
pstate->block_tracker->update (sym);
pstate->push_new<var_value_operation>
(sym.symbol, sym.block);
pstate->push_new<var_value_operation> (sym);
current_type = sym.symbol->type; }
else if ($1.is_a_field_of_this)
{

View File

@ -224,7 +224,7 @@ parser_state::push_symbol (const char *name, block_symbol sym)
{
if (symbol_read_needs_frame (sym.symbol))
block_tracker->update (sym);
push_new<expr::var_value_operation> (sym.symbol, sym.block);
push_new<expr::var_value_operation> (sym);
}
else
{
@ -301,7 +301,7 @@ parser_state::push_dollar (struct stoken str)
sym = lookup_symbol (copy.c_str (), NULL, VAR_DOMAIN, NULL);
if (sym.symbol)
{
push_new<expr::var_value_operation> (sym.symbol, sym.block);
push_new<expr::var_value_operation> (sym);
return;
}
msym = lookup_bound_minimal_symbol (copy.c_str ());

View File

@ -2429,7 +2429,7 @@ rust_parser::convert_ast_to_expression (const struct rust_op *operation,
VAR_DOMAIN);
operation_up result;
if (sym.symbol != NULL && SYMBOL_CLASS (sym.symbol) != LOC_TYPEDEF)
result.reset (new var_value_operation (sym.symbol, sym.block));
result.reset (new var_value_operation (sym));
else
{
struct type *type = NULL;