29#include "gdbsupport/byte-vector.h"
49 struct type *ptr_target;
51 gdb_assert (ptr_type->
code () == TYPE_CODE_PTR);
57 if (ptr_type->
code () == TYPE_CODE_VOID)
65 error (_(
"Cannot perform pointer math on incomplete types, "
66 "try casting to a known type, or void *."));
68 error (_(
"Cannot perform pointer math on incomplete type \"%s\", "
69 "try casting to a known type, or void *."),
name);
81 struct type *valptrtype;
102 struct type *type1, *type2;
110 gdb_assert (type1->
code () == TYPE_CODE_PTR);
111 gdb_assert (type2->
code () == TYPE_CODE_PTR);
115 error (_(
"First argument of `-' is a pointer and "
116 "second argument is neither\n"
117 "an integer nor a pointer of the same type."));
122 warning (_(
"Type size unknown, assuming 1. "
123 "Try casting to a known type, or void *."));
149 if (tarray->
code () == TYPE_CODE_ARRAY
150 || tarray->
code () == TYPE_CODE_STRING)
154 if (!lowerbound.has_value ())
160 gdb::optional<LONGEST> upperbound
163 if (!upperbound.has_value ())
166 if (index >= *lowerbound && index <= *upperbound)
173 if (*upperbound > -1)
174 warning (_(
"array or string index out of range"));
179 index -= *lowerbound;
201 error (_(
"not an array or string"));
223 elt_size = stride / (unit_size * 8);
226 LONGEST elt_offs = elt_size * (index - lowerbound);
227 bool array_upper_bound_undefined
230 if (index < lowerbound
231 || (!array_upper_bound_undefined
236 error (_(
"no such vector element (vector not associated)"));
238 error (_(
"no such vector element (vector not allocated)"));
240 error (_(
"no such vector element"));
247 address = array->
address () + elt_offs;
260 if (
type->
code () == TYPE_CODE_ARRAY)
280 struct type *type1,
struct type *type2)
282 if (op == BINOP_ASSIGN)
293 return (type1->
code () == TYPE_CODE_STRUCT
294 || type2->
code () == TYPE_CODE_STRUCT);
326 return type1->
code () == TYPE_CODE_STRUCT;
342 struct symbol *symp = NULL;
343 struct value *valp = NULL;
348 &valp, &symp, static_memfuncp, 0,
noside);
362 error (_(
"Could not find %s."), oper);
372 struct value *result = NULL;
410 error (_(
"Can't do that binary op on that type"));
412 value *argvec_storage[3];
413 gdb::array_view<value *> argvec = argvec_storage;
419 strcpy (tstr,
"operator__");
444 case BINOP_BITWISE_AND:
447 case BINOP_BITWISE_IOR:
450 case BINOP_BITWISE_XOR:
453 case BINOP_LOGICAL_AND:
456 case BINOP_LOGICAL_OR:
468 case BINOP_ASSIGN_MODIFY:
486 case BINOP_BITWISE_AND:
489 case BINOP_BITWISE_IOR:
492 case BINOP_BITWISE_XOR:
497 error (_(
"Invalid binary operation specified."));
500 case BINOP_SUBSCRIPT:
523 error (_(
"Invalid binary operation specified."));
527 &static_memfuncp,
noside);
533 argvec[1] = argvec[0];
534 argvec = argvec.slice (1);
536 if (argvec[0]->
type ()->
code () == TYPE_CODE_XMETHOD)
539 gdb_assert (static_memfuncp == 0);
542 struct type *return_type
543 = argvec[0]->result_type_of_xmethod (argvec.slice (1));
545 if (return_type == NULL)
546 error (_(
"Xmethod is missing return type."));
549 return argvec[0]->call_xmethod (argvec.slice (1));
553 struct type *return_type;
559 argvec.slice (1, 2 - static_memfuncp));
561 throw_error (NOT_FOUND_ERROR,
562 _(
"member function %s not found"), tstr);
576 char tstr[13], mangle_tstr[13];
577 int static_memfuncp, nargs;
585 error (_(
"Can't do that unary op on that type"));
587 value *argvec_storage[3];
588 gdb::array_view<value *> argvec = argvec_storage;
596 strcpy (tstr,
"operator__");
598 strcpy (mangle_tstr,
"__");
601 case UNOP_PREINCREMENT:
604 case UNOP_PREDECREMENT:
607 case UNOP_POSTINCREMENT:
612 case UNOP_POSTDECREMENT:
617 case UNOP_LOGICAL_NOT:
620 case UNOP_COMPLEMENT:
636 error (_(
"Invalid unary operation specified."));
640 &static_memfuncp,
noside);
646 argvec[1] = argvec[0];
647 argvec = argvec.slice (1);
649 if (argvec[0]->
type ()->
code () == TYPE_CODE_XMETHOD)
652 gdb_assert (static_memfuncp == 0);
655 struct type *return_type
656 = argvec[0]->result_type_of_xmethod (argvec[1]);
658 if (return_type == NULL)
659 error (_(
"Xmethod is missing return type."));
662 return argvec[0]->call_xmethod (argvec[1]);
666 struct type *return_type;
672 argvec.slice (1, nargs));
674 throw_error (NOT_FOUND_ERROR,
675 _(
"member function %s not found"), tstr);
689 if (type1->
code () != TYPE_CODE_ARRAY && type2->
code () != TYPE_CODE_ARRAY)
690 error (
"no array provided to concatenation");
693 struct type *elttype1 = type1;
694 if (elttype1->
code () == TYPE_CODE_ARRAY)
698 error (_(
"could not determine array bounds on left-hand-side of "
699 "array concatenation"));
708 struct type *elttype2 = type2;
709 if (elttype2->
code () == TYPE_CODE_ARRAY)
713 error (_(
"could not determine array bounds on right-hand-side of "
714 "array concatenation"));
723 error (_(
"concatenation with different element types"));
726 LONGEST n_elts = (high1 - low1 + 1) + (high2 - low2 + 1);
729 lowbound + n_elts - 1);
733 gdb::array_view<const gdb_byte> lhs_contents = arg1->
contents ();
734 gdb::array_view<const gdb_byte> rhs_contents = arg2->
contents ();
735 gdb::copy (lhs_contents,
contents.slice (0, lhs_contents.size ()));
736 gdb::copy (rhs_contents,
contents.slice (lhs_contents.size ()));
746 gdb_byte *x,
struct type **eff_type_x,
747 gdb_byte *y,
struct type **eff_type_y)
749 struct type *type1, *type2;
758 && type1->
code () != type2->
code ())
762 error (_(
"Mixing decimal floating types with "
763 "other floating types is not allowed."));
781 error (_(
"Don't know how to convert from %s to %s."), type1->
name (),
800 error (_(
"Don't know how to convert from %s to %s."), type1->
name (),
821 if (op == BINOP_MUL || op == BINOP_DIV)
852 auto fixed_point_to_value = [type1] (
const gdb_mpq &fp)
869 val = fixed_point_to_value (res);
874 val = fixed_point_to_value (res);
878 val = fixed_point_to_value (std::min (v1, v2));
882 val = fixed_point_to_value (std::max (v1, v2));
887 val = fixed_point_to_value (res);
892 error (_(
"Division by zero"));
894 val = fixed_point_to_value (res);
908 error (_(
"Integer-only operation on fixed point number."));
920 struct type *result_type;
964 struct value *arg1_real, *arg1_imag, *arg2_real, *arg2_imag;
965 if (arg1_type->
code () == TYPE_CODE_COMPLEX)
975 if (arg2_type->
code () == TYPE_CODE_COMPLEX)
989 error (_(
"Argument to complex arithmetic operation not supported."));
991 arg1_real =
value_cast (comp_type, arg1_real);
992 arg1_imag =
value_cast (comp_type, arg1_imag);
993 arg2_real =
value_cast (comp_type, arg2_real);
994 arg2_imag =
value_cast (comp_type, arg2_imag);
998 struct value *result_real, *result_imag;
1021 if (arg2_type->
code () == TYPE_CODE_COMPLEX)
1044 case BINOP_NOTEQUAL:
1052 if (op == BINOP_EQUAL)
1062 error (_(
"Invalid binary operation on numbers."));
1088 type *shift_count_type,
const gdb_mpz &shift_count,
1089 unsigned long &nbits)
1093 LONGEST count = shift_count.
as_integer<LONGEST> ();
1096 auto error_or_warning = [] (
const char *msg)
1102 error ((
"%s"), msg);
1104 warning ((
"%s"), msg);
1107 if (op == BINOP_RSH)
1108 error_or_warning (_(
"right shift count is negative"));
1110 error_or_warning (_(
"left shift count is negative"));
1115 nbits = shift_count.
as_integer<
unsigned long> ();
1123 if (op == BINOP_RSH)
1124 warning (_(
"right shift count >= width of type"));
1126 warning (_(
"left shift count >= width of type"));
1140static struct value *
1144 struct type *type1, *type2, *result_type;
1152 if (type1->
code () == TYPE_CODE_COMPLEX
1153 || type2->
code () == TYPE_CODE_COMPLEX)
1162 error (_(
"Argument to arithmetic operation not a number or boolean."));
1172 struct type *eff_type_v1, *eff_type_v2;
1173 gdb::byte_vector v1, v2;
1174 v1.resize (result_type->
length ());
1175 v2.resize (result_type->
length ());
1178 v1.data (), &eff_type_v1,
1179 v2.data (), &eff_type_v2);
1181 v2.data (), eff_type_v2,
1184 else if (type1->
code () == TYPE_CODE_BOOL
1185 || type2->
code () == TYPE_CODE_BOOL)
1187 LONGEST v1, v2, v = 0;
1194 case BINOP_BITWISE_AND:
1198 case BINOP_BITWISE_IOR:
1202 case BINOP_BITWISE_XOR:
1210 case BINOP_NOTEQUAL:
1215 error (_(
"Invalid operation on booleans."));
1218 result_type = type1;
1235 if (op == BINOP_RSH || op == BINOP_LSH || op == BINOP_EXP)
1236 result_type = type1;
1263 error (_(
"Division by zero"));
1267 v = v1.
pow (v2.as_integer<
unsigned long> ());
1274 error (_(
"Division by zero"));
1294 unsigned long nbits;
1304 unsigned long nbits;
1312 case BINOP_BITWISE_AND:
1316 case BINOP_BITWISE_IOR:
1320 case BINOP_BITWISE_XOR:
1325 v = v1 < v2 ? v1 : v2;
1329 v = v1 > v2 ? v1 : v2;
1336 case BINOP_NOTEQUAL:
1357 error (_(
"Invalid binary operation on numbers."));
1376 struct type *eltype, *scalar_type;
1377 struct value *elval;
1378 LONGEST low_bound, high_bound;
1383 gdb_assert (vector_type->
code () == TYPE_CODE_ARRAY
1387 error (_(
"Could not determine the vector bounds"));
1398 error (_(
"conversion of scalar to vector involves truncation"));
1402 int elt_len = eltype->
length ();
1404 for (i = 0; i < high_bound - low_bound + 1; i++)
1407 val_contents.slice (i * elt_len, elt_len));
1415static struct value *
1418 struct type *type1, *type2, *eltype1, *eltype2;
1419 int t1_is_vec, t2_is_vec, elsize, i;
1420 LONGEST low_bound1, high_bound1, low_bound2, high_bound2;
1425 t1_is_vec = (type1->
code () == TYPE_CODE_ARRAY
1427 t2_is_vec = (type2->
code () == TYPE_CODE_ARRAY
1430 if (!t1_is_vec || !t2_is_vec)
1431 error (_(
"Vector operations are only supported among vectors"));
1435 error (_(
"Could not determine the vector bounds"));
1439 elsize = eltype1->
length ();
1441 if (eltype1->
code () != eltype2->
code ()
1442 || elsize != eltype2->
length ()
1444 || low_bound1 != low_bound2 || high_bound1 != high_bound2)
1445 error (_(
"Cannot perform operation on vectors with different types"));
1450 for (i = 0; i < high_bound1 - low_bound1 + 1; i++)
1455 val_contents.slice (i * elsize, elsize));
1469 int t1_is_vec = (type1->
code () == TYPE_CODE_ARRAY
1471 int t2_is_vec = (type2->
code () == TYPE_CODE_ARRAY
1474 if (!t1_is_vec && !t2_is_vec)
1476 else if (t1_is_vec && t2_is_vec)
1481 struct value **v = t1_is_vec ? &arg2 : &arg1;
1482 struct type *t = t1_is_vec ? type2 : type1;
1484 if (t->
code () != TYPE_CODE_FLT
1485 && t->
code () != TYPE_CODE_DECFLOAT
1487 error (_(
"Argument to operation not a number or boolean."));
1533 const gdb_byte *
s1 = arg1->
contents ().data ();
1534 const gdb_byte *
s2 = arg2->
contents ().data ();
1535 int i, len = len1 < len2 ? len1 : len2;
1537 for (i = 0; i < len; i++)
1541 else if (
s1[i] >
s2[i])
1549 else if (len1 > len2)
1564 struct type *type1, *type2;
1567 int is_int1, is_int2;
1574 code1 = type1->
code ();
1575 code2 = type2->
code ();
1579 if (is_int1 && is_int2)
1584 struct type *eff_type_v1, *eff_type_v2;
1585 gdb::byte_vector v1, v2;
1586 v1.resize (std::max (type1->
length (), type2->
length ()));
1587 v2.resize (std::max (type1->
length (), type2->
length ()));
1590 v1.data (), &eff_type_v1,
1591 v2.data (), &eff_type_v2);
1594 v2.data (), eff_type_v2) == 0;
1599 else if (code1 == TYPE_CODE_PTR && is_int2)
1601 else if (code2 == TYPE_CODE_PTR && is_int1)
1604 else if (code1 == code2
1605 && ((len = (
int) type1->
length ())
1606 == (
int) type2->
length ()))
1617 else if (code1 == TYPE_CODE_STRING && code2 == TYPE_CODE_STRING)
1622 error (_(
"Invalid type combination in equality test."));
1632 struct type *type1, *type2;
1637 return (type1->
code () == type2->
code ()
1639 && memcmp (arg1->
contents ().data (),
1652 struct type *type1, *type2;
1653 int is_int1, is_int2;
1660 code1 = type1->
code ();
1661 code2 = type2->
code ();
1665 if ((is_int1 && is_int2)
1671 struct type *eff_type_v1, *eff_type_v2;
1672 gdb::byte_vector v1, v2;
1673 v1.resize (std::max (type1->
length (), type2->
length ()));
1674 v2.resize (std::max (type1->
length (), type2->
length ()));
1677 v1.data (), &eff_type_v1,
1678 v2.data (), &eff_type_v2);
1681 v2.data (), eff_type_v2) == -1;
1683 else if (code1 == TYPE_CODE_PTR && code2 == TYPE_CODE_PTR)
1688 else if (code1 == TYPE_CODE_PTR && is_int2)
1690 else if (code2 == TYPE_CODE_PTR && is_int1)
1692 else if (code1 == TYPE_CODE_STRING && code2 == TYPE_CODE_STRING)
1696 error (_(
"Invalid type combination in ordering comparison."));
1713 ||
type->
code () == TYPE_CODE_COMPLEX)
1716 error (_(
"Argument to positive operation not a number."));
1738 LONGEST low_bound, high_bound;
1741 error (_(
"Could not determine the vector bounds"));
1744 int elt_len = eltype->
length ();
1746 for (i = 0; i < high_bound - low_bound + 1; i++)
1750 val_contents.slice (i * elt_len, elt_len));
1754 else if (
type->
code () == TYPE_CODE_COMPLEX)
1764 error (_(
"Argument to negate operation not a number."));
1788 LONGEST low_bound, high_bound;
1791 error (_(
"Could not determine the vector bounds"));
1795 int elt_len = eltype->
length ();
1797 for (i = 0; i < high_bound - low_bound + 1; i++)
1801 val_contents.slice (i * elt_len, elt_len));
1804 else if (
type->
code () == TYPE_CODE_COMPLEX)
1815 error (_(
"Argument to complement operation not an integer, boolean."));
1828 LONGEST low_bound, high_bound;
1835 if (index < low_bound || index > high_bound)
1837 rel_index = index - low_bound;
1840 rel_index %= TARGET_CHAR_BIT;
1842 rel_index = TARGET_CHAR_BIT - 1 - rel_index;
1843 return (word >> rel_index) & 1;
constexpr std::string_view s1
constexpr std::string_view s2
static void store_signed_integer(gdb_byte *addr, int len, enum bfd_endian byte_order, LONGEST val)
static ULONGEST extract_unsigned_integer(gdb::array_view< const gdb_byte > buf, enum bfd_endian byte_order)
@ EVAL_AVOID_SIDE_EFFECTS
enum bfd_endian gdbarch_byte_order(struct gdbarch *gdbarch)
int gdbarch_addressable_memory_unit_size(struct gdbarch *gdbarch)
enum bfd_endian type_byte_order(const struct type *type)
int is_integral_type(struct type *t)
int is_floating_type(struct type *t)
int is_dynamic_type(struct type *type)
struct type * lookup_array_range_type(struct type *element_type, LONGEST low_bound, LONGEST high_bound)
bool get_discrete_bounds(struct type *type, LONGEST *lowp, LONGEST *highp)
gdb::optional< LONGEST > get_discrete_high_bound(struct type *type)
gdb::optional< LONGEST > get_discrete_low_bound(struct type *type)
struct type * resolve_dynamic_type(struct type *type, gdb::array_view< const gdb_byte > valaddr, CORE_ADDR addr, const frame_info_ptr *in_frame)
bool get_array_bounds(struct type *type, LONGEST *low_bound, LONGEST *high_bound)
int type_not_associated(const struct type *type)
unsigned int type_length_units(struct type *type)
bool types_equal(struct type *a, struct type *b)
struct type * init_complex_type(const char *name, struct type *target_type)
bool is_fixed_point_type(struct type *type)
int type_not_allocated(const struct type *type)
struct type * check_typedef(struct type *type)
bool can_create_complex_type(struct type *target_type)
#define TYPE_IS_REFERENCE(t)
struct value * call_function_by_hand(struct value *function, type *default_return_type, gdb::array_view< value * > args)
const struct language_defn * language_def(enum language lang)
const struct language_defn * current_language
struct type * language_bool_type(const struct language_defn *la, struct gdbarch *gdbarch)
dynamic_prop_kind kind() const
void read_fixed_point(gdb::array_view< const gdb_byte > buf, enum bfd_endian byte_order, bool unsigned_p, const gdb_mpq &scaling_factor)
static gdb_mpz pow(unsigned long base, unsigned long exp)
enum language la_language
virtual struct value * to_array(struct value *val) const
virtual bool c_style_arrays_p() const
struct type * target_type() const
enum language language() const
ULONGEST bit_stride() const
const gdb_mpq & fixed_point_scaling_factor()
range_bounds * bounds() const
const char * name() const
type * index_type() const
static struct value * zero(struct type *type, enum lval_type lv)
gdb::array_view< const gdb_byte > contents_all()
gdb::array_view< gdb_byte > contents_writeable()
static struct value * allocate(struct type *type)
bool bytes_available(LONGEST offset, ULONGEST length) const
void set_lval(lval_type val)
void mark_bytes_unavailable(LONGEST offset, ULONGEST length)
gdb::array_view< const gdb_byte > contents()
void set_address(CORE_ADDR)
void set_component_location(const struct value *whole)
gdb::array_view< gdb_byte > contents_raw()
struct type * type() const
enum lval_type lval() const
int target_float_compare(const gdb_byte *x, const struct type *type_x, const gdb_byte *y, const struct type *type_y)
bool target_float_is_zero(const gdb_byte *addr, const struct type *type)
void target_float_binop(enum exp_opcode opcode, const gdb_byte *x, const struct type *type_x, const gdb_byte *y, const struct type *type_y, gdb_byte *res, const struct type *type_res)
void target_float_from_longest(gdb_byte *addr, const struct type *type, LONGEST val)
void target_float_from_ulongest(gdb_byte *addr, const struct type *type, ULONGEST val)
static LONGEST find_size_for_pointer_math(struct type *ptr_type)
int value_equal_contents(struct value *arg1, struct value *arg2)
bool value_logical_not(struct value *arg1)
struct value * value_subscript(struct value *array, LONGEST index)
struct value * value_x_binop(struct value *arg1, struct value *arg2, enum exp_opcode op, enum exp_opcode otherop, enum noside noside)
struct value * value_neg(struct value *arg1)
static struct value * complex_binop(struct value *arg1, struct value *arg2, enum exp_opcode op)
static int type_length_bits(type *type)
static struct type * promotion_type(struct type *type1, struct type *type2)
static struct value * scalar_binop(struct value *arg1, struct value *arg2, enum exp_opcode op)
struct value * value_x_unop(struct value *arg1, enum exp_opcode op, enum noside noside)
static struct value * value_user_defined_op(struct value **argp, gdb::array_view< value * > args, char *name, int *static_memfuncp, enum noside noside)
static struct value * value_subscripted_rvalue(struct value *array, LONGEST index, LONGEST lowerbound)
struct value * value_complement(struct value *arg1)
struct value * value_to_array(struct value *val)
struct value * value_pos(struct value *arg1)
static struct value * value_user_defined_cpp_op(gdb::array_view< value * > args, char *oper, int *static_memfuncp, enum noside noside)
static int value_strcmp(struct value *arg1, struct value *arg2)
struct value * value_vector_widen(struct value *scalar_value, struct type *vector_type)
int binop_user_defined_p(enum exp_opcode op, struct value *arg1, struct value *arg2)
static struct value * fixed_point_binop(struct value *arg1, struct value *arg2, enum exp_opcode op)
static struct value * vector_binop(struct value *val1, struct value *val2, enum exp_opcode op)
static bool check_valid_shift_count(enum exp_opcode op, type *result_type, type *shift_count_type, const gdb_mpz &shift_count, unsigned long &nbits)
int value_equal(struct value *arg1, struct value *arg2)
int binop_types_user_defined_p(enum exp_opcode op, struct type *type1, struct type *type2)
int value_less(struct value *arg1, struct value *arg2)
struct value * value_concat(struct value *arg1, struct value *arg2)
struct value * value_ptradd(struct value *arg1, LONGEST arg2)
LONGEST value_ptrdiff(struct value *arg1, struct value *arg2)
int value_bit_index(struct type *type, const gdb_byte *valaddr, int index)
static void value_args_as_target_float(struct value *arg1, struct value *arg2, gdb_byte *x, struct type **eff_type_x, gdb_byte *y, struct type **eff_type_y)
struct value * value_binop(struct value *arg1, struct value *arg2, enum exp_opcode op)
int unop_user_defined_p(enum exp_opcode op, struct value *arg1)
struct value * value_coerce_array(struct value *arg1)
struct value * value_struct_elt(struct value **argp, gdb::optional< gdb::array_view< value * > > args, const char *name, int *static_memfuncp, const char *err)
struct value * value_of_variable(struct symbol *var, const struct block *b)
struct value * value_addr(struct value *arg1)
struct value * value_cast(struct type *type, struct value *arg2)
struct value * value_real_part(struct value *value)
struct value * value_ind(struct value *arg1)
struct value * value_literal_complex(struct value *arg1, struct value *arg2, struct type *type)
gdb_mpq value_to_gdb_mpq(struct value *value)
struct value * value_imaginary_part(struct value *value)
int find_overload_match(gdb::array_view< value * > args, const char *name, enum oload_search_type method, struct value **objp, struct symbol *fsym, struct value **valp, struct symbol **symp, int *staticp, const int no_adl, const enum noside noside)
struct value * value_from_component(struct value *whole, struct type *type, LONGEST offset)
bool is_floating_value(struct value *val)
CORE_ADDR value_as_address(struct value *val)
struct value * value_from_ulongest(struct type *type, ULONGEST num)
struct value * value_from_longest(struct type *type, LONGEST num)
struct value * coerce_ref(struct value *arg)
struct value * value_from_contents(struct type *type, const gdb_byte *contents)
struct value * coerce_array(struct value *arg)
LONGEST value_as_long(struct value *val)
gdb_mpz value_as_mpz(struct value *val)
struct value * value_from_mpz(struct type *type, const gdb_mpz &v)
struct value * value_from_pointer(struct type *type, CORE_ADDR addr)
static bool value_true(struct value *val)