/* Perform arithmetic and other operations on values, for GDB.
- Copyright (C) 1986-2018 Free Software Foundation, Inc.
+ Copyright (C) 1986-2019 Free Software Foundation, Inc.
This file is part of GDB.
#include "language.h"
#include "target-float.h"
#include "infcall.h"
-#include "common/byte-vector.h"
+#include "gdbsupport/byte-vector.h"
+#include "gdbarch.h"
/* Define whether or not the C operator '/' truncates towards zero for
differently signed operands (truncation direction is undefined in C). */
to doubles, but no longer does. */
struct value *
-value_subscripted_rvalue (struct value *array, LONGEST index, int lowerbound)
+value_subscripted_rvalue (struct value *array, LONGEST index, LONGEST lowerbound)
{
struct type *array_type = check_typedef (value_type (array));
struct type *elt_type = check_typedef (TYPE_TARGET_TYPE (array_type));
ULONGEST elt_size = type_length_units (elt_type);
+
+ /* Fetch the bit stride and convert it to a byte stride, assuming 8 bits
+ in a byte. */
+ LONGEST stride = TYPE_ARRAY_BIT_STRIDE (array_type);
+ if (stride != 0)
+ {
+ struct gdbarch *arch = get_type_arch (elt_type);
+ int unit_size = gdbarch_addressable_memory_unit_size (arch);
+ elt_size = stride / (unit_size * 8);
+ }
+
ULONGEST elt_offs = elt_size * (index - lowerbound);
if (index < lowerbound
situations or combinations thereof. */
static struct value *
-value_user_defined_cpp_op (struct value **args, int nargs, char *oper,
+value_user_defined_cpp_op (gdb::array_view<value *> args, char *oper,
int *static_memfuncp, enum noside noside)
{
struct symbol *symp = NULL;
struct value *valp = NULL;
- find_overload_match (args, nargs, oper, BOTH /* could be method */,
+ find_overload_match (args, oper, BOTH /* could be method */,
&args[0] /* objp */,
NULL /* pass NULL symbol since symbol is unknown */,
&valp, &symp, static_memfuncp, 0, noside);
function, otherwise return NULL. */
static struct value *
-value_user_defined_op (struct value **argp, struct value **args, char *name,
- int *static_memfuncp, int nargs, enum noside noside)
+value_user_defined_op (struct value **argp, gdb::array_view<value *> args,
+ char *name, int *static_memfuncp, enum noside noside)
{
struct value *result = NULL;
if (current_language->la_language == language_cplus)
{
- result = value_user_defined_cpp_op (args, nargs, name, static_memfuncp,
+ result = value_user_defined_cpp_op (args, name, static_memfuncp,
noside);
}
else
- result = value_struct_elt (argp, args, name, static_memfuncp,
- "structure");
+ result = value_struct_elt (argp, args.data (), name, static_memfuncp,
+ "structure");
return result;
}
arg1.operator @ (arg1,arg2) and return that value (where '@' is any
binary operator which is legal for GNU C++).
- OP is the operatore, and if it is BINOP_ASSIGN_MODIFY, then OTHEROP
+ OP is the operator, and if it is BINOP_ASSIGN_MODIFY, then OTHEROP
is the opcode saying how to modify it. Otherwise, OTHEROP is
unused. */
value_x_binop (struct value *arg1, struct value *arg2, enum exp_opcode op,
enum exp_opcode otherop, enum noside noside)
{
- struct value **argvec;
char *ptr;
char tstr[13];
int static_memfuncp;
if (TYPE_CODE (check_typedef (value_type (arg1))) != TYPE_CODE_STRUCT)
error (_("Can't do that binary op on that type")); /* FIXME be explicit */
- argvec = (struct value **) alloca (sizeof (struct value *) * 4);
+ value *argvec_storage[3];
+ gdb::array_view<value *> argvec = argvec_storage;
+
argvec[1] = value_addr (arg1);
argvec[2] = arg2;
- argvec[3] = 0;
/* Make the right function name up. */
strcpy (tstr, "operator__");
error (_("Invalid binary operation specified."));
}
- argvec[0] = value_user_defined_op (&arg1, argvec + 1, tstr,
- &static_memfuncp, 2, noside);
+ argvec[0] = value_user_defined_op (&arg1, argvec.slice (1), tstr,
+ &static_memfuncp, noside);
if (argvec[0])
{
if (static_memfuncp)
{
argvec[1] = argvec[0];
- argvec++;
+ argvec = argvec.slice (1);
}
if (TYPE_CODE (value_type (argvec[0])) == TYPE_CODE_XMETHOD)
{
if (noside == EVAL_AVOID_SIDE_EFFECTS)
{
struct type *return_type
- = result_type_of_xmethod (argvec[0], 2, argvec + 1);
+ = result_type_of_xmethod (argvec[0], argvec.slice (1));
if (return_type == NULL)
error (_("Xmethod is missing return type."));
return value_zero (return_type, VALUE_LVAL (arg1));
}
- return call_xmethod (argvec[0], 2, argvec + 1);
+ return call_xmethod (argvec[0], argvec.slice (1));
}
if (noside == EVAL_AVOID_SIDE_EFFECTS)
{
return value_zero (return_type, VALUE_LVAL (arg1));
}
return call_function_by_hand (argvec[0], NULL,
- {argvec + 1, 2u - static_memfuncp});
+ argvec.slice (1, 2 - static_memfuncp));
}
throw_error (NOT_FOUND_ERROR,
_("member function %s not found"), tstr);
value_x_unop (struct value *arg1, enum exp_opcode op, enum noside noside)
{
struct gdbarch *gdbarch = get_type_arch (value_type (arg1));
- struct value **argvec;
char *ptr;
char tstr[13], mangle_tstr[13];
int static_memfuncp, nargs;
if (TYPE_CODE (check_typedef (value_type (arg1))) != TYPE_CODE_STRUCT)
error (_("Can't do that unary op on that type")); /* FIXME be explicit */
- argvec = (struct value **) alloca (sizeof (struct value *) * 4);
+ value *argvec_storage[3];
+ gdb::array_view<value *> argvec = argvec_storage;
+
argvec[1] = value_addr (arg1);
argvec[2] = 0;
case UNOP_POSTINCREMENT:
strcpy (ptr, "++");
argvec[2] = value_from_longest (builtin_type (gdbarch)->builtin_int, 0);
- argvec[3] = 0;
nargs ++;
break;
case UNOP_POSTDECREMENT:
strcpy (ptr, "--");
argvec[2] = value_from_longest (builtin_type (gdbarch)->builtin_int, 0);
- argvec[3] = 0;
nargs ++;
break;
case UNOP_LOGICAL_NOT:
error (_("Invalid unary operation specified."));
}
- argvec[0] = value_user_defined_op (&arg1, argvec + 1, tstr,
- &static_memfuncp, nargs, noside);
+ argvec[0] = value_user_defined_op (&arg1, argvec.slice (1, nargs), tstr,
+ &static_memfuncp, noside);
if (argvec[0])
{
if (static_memfuncp)
{
argvec[1] = argvec[0];
- nargs --;
- argvec++;
+ argvec = argvec.slice (1);
}
if (TYPE_CODE (value_type (argvec[0])) == TYPE_CODE_XMETHOD)
{
if (noside == EVAL_AVOID_SIDE_EFFECTS)
{
struct type *return_type
- = result_type_of_xmethod (argvec[0], 1, argvec + 1);
+ = result_type_of_xmethod (argvec[0], argvec[1]);
if (return_type == NULL)
error (_("Xmethod is missing return type."));
return value_zero (return_type, VALUE_LVAL (arg1));
}
- return call_xmethod (argvec[0], 1, argvec + 1);
+ return call_xmethod (argvec[0], argvec[1]);
}
if (noside == EVAL_AVOID_SIDE_EFFECTS)
{
return value_zero (return_type, VALUE_LVAL (arg1));
}
return call_function_by_hand (argvec[0], NULL,
- gdb::make_array_view (argvec + 1, nargs));
+ argvec.slice (1, nargs));
}
throw_error (NOT_FOUND_ERROR,
_("member function %s not found"), tstr);
val = allocate_value (result_type);
store_signed_integer (value_contents_raw (val),
TYPE_LENGTH (result_type),
- gdbarch_byte_order (get_type_arch (result_type)),
+ type_byte_order (result_type),
v);
}
else
val = allocate_value (result_type);
store_unsigned_integer (value_contents_raw (val),
TYPE_LENGTH (value_type (val)),
- gdbarch_byte_order
- (get_type_arch (result_type)),
+ type_byte_order (result_type),
v);
}
else
val = allocate_value (result_type);
store_signed_integer (value_contents_raw (val),
TYPE_LENGTH (value_type (val)),
- gdbarch_byte_order
- (get_type_arch (result_type)),
+ type_byte_order (result_type),
v);
}
}
return -1;
rel_index = index - low_bound;
word = extract_unsigned_integer (valaddr + (rel_index / TARGET_CHAR_BIT), 1,
- gdbarch_byte_order (gdbarch));
+ type_byte_order (type));
rel_index %= TARGET_CHAR_BIT;
- if (gdbarch_bits_big_endian (gdbarch))
+ if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
rel_index = TARGET_CHAR_BIT - 1 - rel_index;
return (word >> rel_index) & 1;
}
error (_("First argument of 'IN' not in range"));
return member;
}
-
-void
-_initialize_valarith (void)
-{
-}