mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-06-21 02:24:17 +08:00
Split helper functions
This splits a couple of address-of and sizeof functions, so that the body can be reused by the (coming) new expression code. gdb/ChangeLog 2021-03-08 Tom Tromey <tom@tromey.com> * eval.c (evaluate_subexp_for_address_base): New function. (evaluate_subexp_for_address): Use it. (evaluate_subexp_for_sizeof_base): New function. (evaluate_subexp_for_sizeof): Use it.
This commit is contained in:
@ -1,3 +1,10 @@
|
|||||||
|
2021-03-08 Tom Tromey <tom@tromey.com>
|
||||||
|
|
||||||
|
* eval.c (evaluate_subexp_for_address_base): New function.
|
||||||
|
(evaluate_subexp_for_address): Use it.
|
||||||
|
(evaluate_subexp_for_sizeof_base): New function.
|
||||||
|
(evaluate_subexp_for_sizeof): Use it.
|
||||||
|
|
||||||
2021-03-08 Tom Tromey <tom@tromey.com>
|
2021-03-08 Tom Tromey <tom@tromey.com>
|
||||||
|
|
||||||
* rust-lang.c (eval_op_rust_structop): New function.
|
* rust-lang.c (eval_op_rust_structop): New function.
|
||||||
|
65
gdb/eval.c
65
gdb/eval.c
@ -3081,6 +3081,29 @@ evaluate_subexp_standard (struct type *expect_type,
|
|||||||
gdb_assert_not_reached ("missed return?");
|
gdb_assert_not_reached ("missed return?");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Helper for evaluate_subexp_for_address. */
|
||||||
|
|
||||||
|
static value *
|
||||||
|
evaluate_subexp_for_address_base (struct expression *exp, enum noside noside,
|
||||||
|
value *x)
|
||||||
|
{
|
||||||
|
if (noside == EVAL_AVOID_SIDE_EFFECTS)
|
||||||
|
{
|
||||||
|
struct type *type = check_typedef (value_type (x));
|
||||||
|
|
||||||
|
if (TYPE_IS_REFERENCE (type))
|
||||||
|
return value_zero (lookup_pointer_type (TYPE_TARGET_TYPE (type)),
|
||||||
|
not_lval);
|
||||||
|
else if (VALUE_LVAL (x) == lval_memory || value_must_coerce_to_target (x))
|
||||||
|
return value_zero (lookup_pointer_type (value_type (x)),
|
||||||
|
not_lval);
|
||||||
|
else
|
||||||
|
error (_("Attempt to take address of "
|
||||||
|
"value not located in memory."));
|
||||||
|
}
|
||||||
|
return value_addr (x);
|
||||||
|
}
|
||||||
|
|
||||||
/* Evaluate a subexpression of EXP, at index *POS,
|
/* Evaluate a subexpression of EXP, at index *POS,
|
||||||
and return the address of that subexpression.
|
and return the address of that subexpression.
|
||||||
Advance *POS over the subexpression.
|
Advance *POS over the subexpression.
|
||||||
@ -3188,21 +3211,7 @@ evaluate_subexp_for_address (struct expression *exp, int *pos,
|
|||||||
default_case:
|
default_case:
|
||||||
x = evaluate_subexp (nullptr, exp, pos, noside);
|
x = evaluate_subexp (nullptr, exp, pos, noside);
|
||||||
default_case_after_eval:
|
default_case_after_eval:
|
||||||
if (noside == EVAL_AVOID_SIDE_EFFECTS)
|
return evaluate_subexp_for_address_base (exp, noside, x);
|
||||||
{
|
|
||||||
struct type *type = check_typedef (value_type (x));
|
|
||||||
|
|
||||||
if (TYPE_IS_REFERENCE (type))
|
|
||||||
return value_zero (lookup_pointer_type (TYPE_TARGET_TYPE (type)),
|
|
||||||
not_lval);
|
|
||||||
else if (VALUE_LVAL (x) == lval_memory || value_must_coerce_to_target (x))
|
|
||||||
return value_zero (lookup_pointer_type (value_type (x)),
|
|
||||||
not_lval);
|
|
||||||
else
|
|
||||||
error (_("Attempt to take address of "
|
|
||||||
"value not located in memory."));
|
|
||||||
}
|
|
||||||
return value_addr (x);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3251,6 +3260,23 @@ evaluate_subexp_with_coercion (struct expression *exp,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Helper function for evaluating the size of a type. */
|
||||||
|
|
||||||
|
static value *
|
||||||
|
evaluate_subexp_for_sizeof_base (struct expression *exp, struct type *type)
|
||||||
|
{
|
||||||
|
/* FIXME: This should be size_t. */
|
||||||
|
struct type *size_type = builtin_type (exp->gdbarch)->builtin_int;
|
||||||
|
/* $5.3.3/2 of the C++ Standard (n3290 draft) says of sizeof:
|
||||||
|
"When applied to a reference or a reference type, the result is
|
||||||
|
the size of the referenced type." */
|
||||||
|
type = check_typedef (type);
|
||||||
|
if (exp->language_defn->la_language == language_cplus
|
||||||
|
&& (TYPE_IS_REFERENCE (type)))
|
||||||
|
type = check_typedef (TYPE_TARGET_TYPE (type));
|
||||||
|
return value_from_longest (size_type, (LONGEST) TYPE_LENGTH (type));
|
||||||
|
}
|
||||||
|
|
||||||
/* Evaluate a subexpression of EXP, at index *POS,
|
/* Evaluate a subexpression of EXP, at index *POS,
|
||||||
and return a value for the size of that subexpression.
|
and return a value for the size of that subexpression.
|
||||||
Advance *POS over the subexpression. If NOSIDE is EVAL_NORMAL
|
Advance *POS over the subexpression. If NOSIDE is EVAL_NORMAL
|
||||||
@ -3374,14 +3400,7 @@ evaluate_subexp_for_sizeof (struct expression *exp, int *pos,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* $5.3.3/2 of the C++ Standard (n3290 draft) says of sizeof:
|
return evaluate_subexp_for_sizeof_base (exp, type);
|
||||||
"When applied to a reference or a reference type, the result is
|
|
||||||
the size of the referenced type." */
|
|
||||||
type = check_typedef (type);
|
|
||||||
if (exp->language_defn->la_language == language_cplus
|
|
||||||
&& (TYPE_IS_REFERENCE (type)))
|
|
||||||
type = check_typedef (TYPE_TARGET_TYPE (type));
|
|
||||||
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
|
||||||
|
Reference in New Issue
Block a user