Introduce unop_ind_operation
This adds class unop_ind_operation, which implements UNOP_IND. gdb/ChangeLog 2021-03-08 Tom Tromey <tom@tromey.com> * expop.h (class unop_ind_base_operation) (class unop_ind_operation): New. * eval.c (eval_op_ind): No longer static. Remove "op" parameter. (unop_ind_base_operation::evaluate_for_address) (unop_ind_base_operation::evaluate_for_sizeof): New method. * ax-gdb.c (gen_expr_unop) <case UNOP_IND>: New.
This commit is contained in:
parent
6d89e2962a
commit
876469ffa1
4 changed files with 111 additions and 5 deletions
|
@ -1,3 +1,12 @@
|
||||||
|
2021-03-08 Tom Tromey <tom@tromey.com>
|
||||||
|
|
||||||
|
* expop.h (class unop_ind_base_operation)
|
||||||
|
(class unop_ind_operation): New.
|
||||||
|
* eval.c (eval_op_ind): No longer static. Remove "op" parameter.
|
||||||
|
(unop_ind_base_operation::evaluate_for_address)
|
||||||
|
(unop_ind_base_operation::evaluate_for_sizeof): New method.
|
||||||
|
* ax-gdb.c (gen_expr_unop) <case UNOP_IND>: New.
|
||||||
|
|
||||||
2021-03-08 Tom Tromey <tom@tromey.com>
|
2021-03-08 Tom Tromey <tom@tromey.com>
|
||||||
|
|
||||||
* expop.h (unop_incr_operation): New template.
|
* expop.h (unop_incr_operation): New template.
|
||||||
|
|
|
@ -2736,6 +2736,14 @@ gen_expr_unop (struct expression *exp,
|
||||||
gen_complement (ax, value);
|
gen_complement (ax, value);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case UNOP_IND:
|
||||||
|
lhs->generate_ax (exp, ax, value);
|
||||||
|
gen_usual_unary (ax, value);
|
||||||
|
if (!pointer_type (value->type))
|
||||||
|
error (_("Argument of unary `*' is not a pointer."));
|
||||||
|
gen_deref (value);
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
gdb_assert_not_reached ("invalid case in gen_expr_unop");
|
gdb_assert_not_reached ("invalid case in gen_expr_unop");
|
||||||
}
|
}
|
||||||
|
|
45
gdb/eval.c
45
gdb/eval.c
|
@ -1827,9 +1827,9 @@ eval_op_lognot (struct type *expect_type, struct expression *exp,
|
||||||
|
|
||||||
/* A helper function for UNOP_IND. */
|
/* A helper function for UNOP_IND. */
|
||||||
|
|
||||||
static struct value *
|
struct value *
|
||||||
eval_op_ind (struct type *expect_type, struct expression *exp,
|
eval_op_ind (struct type *expect_type, struct expression *exp,
|
||||||
enum noside noside, enum exp_opcode op,
|
enum noside noside,
|
||||||
struct value *arg1)
|
struct value *arg1)
|
||||||
{
|
{
|
||||||
struct type *type = check_typedef (value_type (arg1));
|
struct type *type = check_typedef (value_type (arg1));
|
||||||
|
@ -1839,8 +1839,8 @@ eval_op_ind (struct type *expect_type, struct expression *exp,
|
||||||
"to member without an object"));
|
"to member without an object"));
|
||||||
if (noside == EVAL_SKIP)
|
if (noside == EVAL_SKIP)
|
||||||
return eval_skip_value (exp);
|
return eval_skip_value (exp);
|
||||||
if (unop_user_defined_p (op, arg1))
|
if (unop_user_defined_p (UNOP_IND, arg1))
|
||||||
return value_x_unop (arg1, op, noside);
|
return value_x_unop (arg1, UNOP_IND, noside);
|
||||||
else if (noside == EVAL_AVOID_SIDE_EFFECTS)
|
else if (noside == EVAL_AVOID_SIDE_EFFECTS)
|
||||||
{
|
{
|
||||||
type = check_typedef (value_type (arg1));
|
type = check_typedef (value_type (arg1));
|
||||||
|
@ -2974,7 +2974,7 @@ evaluate_subexp_standard (struct type *expect_type,
|
||||||
if (expect_type && expect_type->code () == TYPE_CODE_PTR)
|
if (expect_type && expect_type->code () == TYPE_CODE_PTR)
|
||||||
expect_type = TYPE_TARGET_TYPE (check_typedef (expect_type));
|
expect_type = TYPE_TARGET_TYPE (check_typedef (expect_type));
|
||||||
arg1 = evaluate_subexp (expect_type, exp, pos, noside);
|
arg1 = evaluate_subexp (expect_type, exp, pos, noside);
|
||||||
return eval_op_ind (expect_type, exp, noside, op, arg1);
|
return eval_op_ind (expect_type, exp, noside, arg1);
|
||||||
|
|
||||||
case UNOP_ADDR:
|
case UNOP_ADDR:
|
||||||
/* C++: check for and handle pointer to members. */
|
/* C++: check for and handle pointer to members. */
|
||||||
|
@ -3301,6 +3301,22 @@ scope_operation::evaluate_for_address (struct expression *exp,
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
value *
|
||||||
|
unop_ind_base_operation::evaluate_for_address (struct expression *exp,
|
||||||
|
enum noside noside)
|
||||||
|
{
|
||||||
|
value *x = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
|
||||||
|
|
||||||
|
/* We can't optimize out "&*" if there's a user-defined operator*. */
|
||||||
|
if (unop_user_defined_p (UNOP_IND, x))
|
||||||
|
{
|
||||||
|
x = value_x_unop (x, UNOP_IND, noside);
|
||||||
|
return evaluate_subexp_for_address_base (exp, noside, x);
|
||||||
|
}
|
||||||
|
|
||||||
|
return coerce_array (x);
|
||||||
|
}
|
||||||
|
|
||||||
value *
|
value *
|
||||||
var_msym_value_operation::evaluate_for_address (struct expression *exp,
|
var_msym_value_operation::evaluate_for_address (struct expression *exp,
|
||||||
enum noside noside)
|
enum noside noside)
|
||||||
|
@ -3569,6 +3585,25 @@ subscript_operation::evaluate_for_sizeof (struct expression *exp,
|
||||||
return operation::evaluate_for_sizeof (exp, noside);
|
return operation::evaluate_for_sizeof (exp, noside);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
value *
|
||||||
|
unop_ind_base_operation::evaluate_for_sizeof (struct expression *exp,
|
||||||
|
enum noside noside)
|
||||||
|
{
|
||||||
|
value *val = std::get<0> (m_storage)->evaluate (nullptr, exp,
|
||||||
|
EVAL_AVOID_SIDE_EFFECTS);
|
||||||
|
struct type *type = check_typedef (value_type (val));
|
||||||
|
if (type->code () != TYPE_CODE_PTR
|
||||||
|
&& !TYPE_IS_REFERENCE (type)
|
||||||
|
&& type->code () != TYPE_CODE_ARRAY)
|
||||||
|
error (_("Attempt to take contents of a non-pointer value."));
|
||||||
|
type = TYPE_TARGET_TYPE (type);
|
||||||
|
if (is_dynamic_type (type))
|
||||||
|
type = value_type (value_ind (val));
|
||||||
|
/* FIXME: This should be size_t. */
|
||||||
|
struct type *size_type = builtin_type (exp->gdbarch)->builtin_int;
|
||||||
|
return value_from_longest (size_type, (LONGEST) TYPE_LENGTH (type));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Evaluate a subexpression of EXP, at index *POS, and return a value
|
/* Evaluate a subexpression of EXP, at index *POS, and return a value
|
||||||
|
|
54
gdb/expop.h
54
gdb/expop.h
|
@ -182,6 +182,10 @@ extern struct value *eval_op_postdec (struct type *expect_type,
|
||||||
enum noside noside,
|
enum noside noside,
|
||||||
enum exp_opcode op,
|
enum exp_opcode op,
|
||||||
struct value *arg1);
|
struct value *arg1);
|
||||||
|
extern struct value *eval_op_ind (struct type *expect_type,
|
||||||
|
struct expression *exp,
|
||||||
|
enum noside noside,
|
||||||
|
struct value *arg1);
|
||||||
|
|
||||||
namespace expr
|
namespace expr
|
||||||
{
|
{
|
||||||
|
@ -1366,6 +1370,56 @@ using postinc_operation
|
||||||
using postdec_operation
|
using postdec_operation
|
||||||
= unop_incr_operation<UNOP_POSTDECREMENT, eval_op_postdec>;
|
= unop_incr_operation<UNOP_POSTDECREMENT, eval_op_postdec>;
|
||||||
|
|
||||||
|
/* Base class for implementations of UNOP_IND. */
|
||||||
|
class unop_ind_base_operation
|
||||||
|
: public tuple_holding_operation<operation_up>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
using tuple_holding_operation::tuple_holding_operation;
|
||||||
|
|
||||||
|
value *evaluate (struct type *expect_type,
|
||||||
|
struct expression *exp,
|
||||||
|
enum noside noside) override
|
||||||
|
{
|
||||||
|
if (expect_type != nullptr && expect_type->code () == TYPE_CODE_PTR)
|
||||||
|
expect_type = TYPE_TARGET_TYPE (check_typedef (expect_type));
|
||||||
|
value *val = std::get<0> (m_storage)->evaluate (expect_type, exp, noside);
|
||||||
|
return eval_op_ind (expect_type, exp, noside, val);
|
||||||
|
}
|
||||||
|
|
||||||
|
value *evaluate_for_address (struct expression *exp,
|
||||||
|
enum noside noside) override;
|
||||||
|
|
||||||
|
value *evaluate_for_sizeof (struct expression *exp,
|
||||||
|
enum noside noside) override;
|
||||||
|
|
||||||
|
enum exp_opcode opcode () const override
|
||||||
|
{ return UNOP_IND; }
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Ordinary UNOP_IND implementation. */
|
||||||
|
class unop_ind_operation
|
||||||
|
: public unop_ind_base_operation
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
using unop_ind_base_operation::unop_ind_base_operation;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
void do_generate_ax (struct expression *exp,
|
||||||
|
struct agent_expr *ax,
|
||||||
|
struct axs_value *value,
|
||||||
|
struct type *cast_type)
|
||||||
|
override
|
||||||
|
{
|
||||||
|
gen_expr_unop (exp, UNOP_IND,
|
||||||
|
std::get<0> (this->m_storage).get (),
|
||||||
|
ax, value);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
} /* namespace expr */
|
} /* namespace expr */
|
||||||
|
|
||||||
#endif /* EXPOP_H */
|
#endif /* EXPOP_H */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue