+2009-06-29 Ulrich Weigand <uweigand@de.ibm.com>
+
+ * value.h (value_subscript, value_subscripted_rvalue,
+ value_bitstring_subscript, value_ptradd): Use LONGEST instead
+ of value as type of the index argument.
+ (value_ptrsub): Remove.
+ * valarith.c (value_subscript, value_subscripted_rvalue,
+ value_bitstring_subscript, value_ptradd): Use LONGEST instead
+ of value as type of the index argument.
+ (value_ptrsub): Remove.
+
+ * wrapper.h (gdb_value_subscript): Use LONGEST instead of
+ value as type of the index argument.
+ * wrapper.c (gdb_value_subscript): Likewise.
+
+ Update calls to gdb_value_subscript, value_subscript,
+ value_subscripted_rvalue, value_bitstring_subscript and
+ value_ptradd to use LONGEST instead of value as index
+ argument type. Use value_ptradd instead of value_ptrsub.
+ * ada-lang.c (ada_value_subscript, ada_value_ptr_subscript,
+ ada_tag_name_2): Update.
+ * ada-tasks.c (read_atcb): Update.
+ * eval.c (evaluate_subexp_standard): Update.
+ * valarith.c (value_subscript): Update.
+ * gnu-v2-abi.c (gnuv2_virtual_fn_field): Update.
+ * gnu-v3-abi.c (gnuv3_get_virtual_fn, gnuv3_baseclass_offset,
+ gnuv3_method_ptr_to_value): Update.
+ * jv-lang.c (evaluate_subexp_java): Update.
+ * m2-lang.c (evaluate_subexp_modula2): Update.
+ * python/python-value.c (valpy_getitem, valpy_binop): Update.
+ * wrapper.c (gdb_value_subscript): Update.
+ * varobj.c (c_describe_child): Update.
+
2009-06-29 Ulrich Weigand <uweigand@de.ibm.com>
* gdbtypes.h (make_function_type): Remove OBJFILE parameter.
{
if (TYPE_CODE (elt_type) != TYPE_CODE_ARRAY)
error (_("too many subscripts (%d expected)"), k);
- elt = value_subscript (elt, value_pos_atr (builtin_type_int32, ind[k]));
+ elt = value_subscript (elt, pos_atr (ind[k]));
}
return elt;
}
for (k = 0; k < arity; k += 1)
{
LONGEST lwb, upb;
- struct value *idx;
if (TYPE_CODE (type) != TYPE_CODE_ARRAY)
error (_("too many subscripts (%d expected)"), k);
arr = value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (type)),
value_copy (arr));
get_discrete_bounds (TYPE_INDEX_TYPE (type), &lwb, &upb);
- idx = value_pos_atr (builtin_type_int32, ind[k]);
- if (lwb != 0)
- idx = value_binop (idx, value_from_longest (value_type (idx), lwb),
- BINOP_SUB);
-
- arr = value_ptradd (arr, idx);
+ arr = value_ptradd (arr, pos_atr (ind[k]) - lwb);
type = TYPE_TARGET_TYPE (type);
}
valp = value_cast (info_type, args->tag);
if (valp == NULL)
return 0;
- val = value_ind (value_ptradd (valp,
- value_from_longest (builtin_type_int8, -1)));
+ val = value_ind (value_ptradd (valp, -1));
if (val == NULL)
return 0;
val = ada_value_struct_elt (val, "expanded_name", 1);
ada_coerce_to_simple_array_ptr (value_field (tcb_value,
fieldno.entry_calls));
entry_calls_value_element =
- value_subscript (entry_calls_value, atc_nesting_level_value);
+ value_subscript (entry_calls_value,
+ value_as_long (atc_nesting_level_value));
called_task_fieldno =
ada_get_field_index (value_type (entry_calls_value_element),
"called_task", 0);
else
{
arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
- return value_subscript (arg1, arg2);
+ return value_subscript (arg1, value_as_long (arg2));
}
case TYPE_CODE_PTR:
op = exp->elts[pc + 1].opcode;
if (binop_user_defined_p (op, arg1, arg2))
return value_x_binop (arg1, arg2, BINOP_ASSIGN_MODIFY, op, noside);
- else if (op == BINOP_ADD && ptrmath_type_p (value_type (arg1)))
- arg2 = value_ptradd (arg1, arg2);
- else if (op == BINOP_SUB && ptrmath_type_p (value_type (arg1)))
- arg2 = value_ptrsub (arg1, arg2);
+ else if (op == BINOP_ADD && ptrmath_type_p (value_type (arg1))
+ && is_integral_type (value_type (arg2)))
+ arg2 = value_ptradd (arg1, value_as_long (arg2));
+ else if (op == BINOP_SUB && ptrmath_type_p (value_type (arg1))
+ && is_integral_type (value_type (arg2)))
+ arg2 = value_ptradd (arg1, - value_as_long (arg2));
else
{
struct value *tmp = arg1;
goto nosideret;
if (binop_user_defined_p (op, arg1, arg2))
return value_x_binop (arg1, arg2, op, OP_NULL, noside);
- else if (ptrmath_type_p (value_type (arg1)))
- return value_ptradd (arg1, arg2);
- else if (ptrmath_type_p (value_type (arg2)))
- return value_ptradd (arg2, arg1);
+ else if (ptrmath_type_p (value_type (arg1))
+ && is_integral_type (value_type (arg2)))
+ return value_ptradd (arg1, value_as_long (arg2));
+ else if (ptrmath_type_p (value_type (arg2))
+ && is_integral_type (value_type (arg1)))
+ return value_ptradd (arg2, value_as_long (arg1));
else
{
binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
goto nosideret;
if (binop_user_defined_p (op, arg1, arg2))
return value_x_binop (arg1, arg2, op, OP_NULL, noside);
- else if (ptrmath_type_p (value_type (arg1)))
+ else if (ptrmath_type_p (value_type (arg1))
+ && ptrmath_type_p (value_type (arg2)))
{
- if (ptrmath_type_p (value_type (arg2)))
- {
- /* FIXME -- should be ptrdiff_t */
- type = builtin_type (exp->gdbarch)->builtin_long;
- return value_from_longest (type, value_ptrdiff (arg1, arg2));
- }
- else
- return value_ptrsub (arg1, arg2);
+ /* FIXME -- should be ptrdiff_t */
+ type = builtin_type (exp->gdbarch)->builtin_long;
+ return value_from_longest (type, value_ptrdiff (arg1, arg2));
}
+ else if (ptrmath_type_p (value_type (arg1))
+ && is_integral_type (value_type (arg2)))
+ return value_ptradd (arg1, - value_as_long (arg2));
else
{
binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
if (noside == EVAL_AVOID_SIDE_EFFECTS)
return value_zero (TYPE_TARGET_TYPE (type), VALUE_LVAL (arg1));
else
- return value_subscript (arg1, arg2);
+ return value_subscript (arg1, value_as_long (arg2));
}
case BINOP_IN:
case TYPE_CODE_PTR:
case TYPE_CODE_ARRAY:
case TYPE_CODE_STRING:
- arg1 = value_subscript (arg1, arg2);
+ arg1 = value_subscript (arg1, value_as_long (arg2));
break;
case TYPE_CODE_BITSTRING:
type = language_bool_type (exp->language_defn, exp->gdbarch);
- arg1 = value_bitstring_subscript (type, arg1, arg2);
+ arg1 = value_bitstring_subscript (type, arg1,
+ value_as_long (arg2));
break;
default:
offset_item =
array_size_array[i - 1] * offset_item + subscript_array[i - 1];
- /* Construct a value node with the value of the offset */
-
- arg2 = value_from_longest (builtin_type_int32, offset_item);
-
/* Let us now play a dirty trick: we will take arg1
which is a value node pointing to the topmost level
of the multidimensional array-set and pretend
returns the correct type value */
deprecated_set_value_type (arg1, tmp_type);
- return value_subscripted_rvalue (arg1, arg2, 0);
+ return value_subscripted_rvalue (arg1, offset_item, 0);
}
case BINOP_LOGICAL_AND:
}
else
{
- arg2 = value_from_longest (builtin_type_uint8, (LONGEST) 1);
if (ptrmath_type_p (value_type (arg1)))
- arg2 = value_ptradd (arg1, arg2);
+ arg2 = value_ptradd (arg1, 1);
else
{
struct value *tmp = arg1;
+ arg2 = value_one (value_type (arg1), not_lval);
binop_promote (exp->language_defn, exp->gdbarch, &tmp, &arg2);
arg2 = value_binop (tmp, arg2, BINOP_ADD);
}
}
else
{
- arg2 = value_from_longest (builtin_type_uint8, (LONGEST) 1);
if (ptrmath_type_p (value_type (arg1)))
- arg2 = value_ptrsub (arg1, arg2);
+ arg2 = value_ptradd (arg1, -1);
else
{
struct value *tmp = arg1;
+ arg2 = value_one (value_type (arg1), not_lval);
binop_promote (exp->language_defn, exp->gdbarch, &tmp, &arg2);
arg2 = value_binop (tmp, arg2, BINOP_SUB);
}
}
else
{
- arg2 = value_from_longest (builtin_type_uint8, (LONGEST) 1);
if (ptrmath_type_p (value_type (arg1)))
- arg2 = value_ptradd (arg1, arg2);
+ arg2 = value_ptradd (arg1, 1);
else
{
struct value *tmp = arg1;
+ arg2 = value_one (value_type (arg1), not_lval);
binop_promote (exp->language_defn, exp->gdbarch, &tmp, &arg2);
arg2 = value_binop (tmp, arg2, BINOP_ADD);
}
}
else
{
- arg2 = value_from_longest (builtin_type_uint8, (LONGEST) 1);
if (ptrmath_type_p (value_type (arg1)))
- arg2 = value_ptrsub (arg1, arg2);
+ arg2 = value_ptradd (arg1, -1);
else
{
struct value *tmp = arg1;
+ arg2 = value_one (value_type (arg1), not_lval);
binop_promote (exp->language_defn, exp->gdbarch, &tmp, &arg2);
arg2 = value_binop (tmp, arg2, BINOP_SUB);
}
struct value *entry;
struct value *vfn;
struct value *vtbl;
- struct value *vi = value_from_longest (builtin_type_int32,
- (LONGEST) TYPE_FN_FIELD_VOFFSET (f, j));
+ LONGEST vi = (LONGEST) TYPE_FN_FIELD_VOFFSET (f, j);
struct type *fcontext = TYPE_FN_FIELD_FCONTEXT (f, j);
struct type *context;
struct type *context_vptr_basetype;
/* Fetch the appropriate function pointer from the vtable. */
vfn = value_subscript (value_field (vtable, vtable_field_virtual_functions),
- value_from_longest (builtin_type_int32, vtable_index));
+ vtable_index);
/* If this architecture uses function descriptors directly in the vtable,
then the address of the vtable entry is actually a "function pointer"
struct type *ptr_type;
struct value *vtable;
struct type *vbasetype;
- struct value *offset_val, *vbase_array;
+ struct value *vbase_array;
CORE_ADDR vtable_address;
long int cur_base_offset, base_offset;
int vbasetype_vptr_fieldno;
vtable
= value_at_lazy (vtable_type,
vtable_address - vtable_address_point_offset (gdbarch));
- offset_val = value_from_longest (builtin_type_int32, cur_base_offset);
vbase_array = value_field (vtable, vtable_field_vcall_and_vbase_offsets);
- base_offset = value_as_long (value_subscript (vbase_array, offset_val));
+ base_offset = value_as_long (value_subscript (vbase_array, cur_base_offset));
return base_offset;
}
CORE_ADDR ptr_value;
struct type *domain_type, *final_type, *method_type;
LONGEST adjustment;
- struct value *adjval;
int vbit;
domain_type = TYPE_DOMAIN_TYPE (check_typedef (value_type (method_ptr)));
You can provoke this case by casting a Base::* to a Derived::*, for
instance. */
*this_p = value_cast (builtin_type (gdbarch)->builtin_data_ptr, *this_p);
- adjval = value_from_longest (builtin_type (gdbarch)->builtin_long,
- adjustment);
- *this_p = value_ptradd (*this_p, adjval);
+ *this_p = value_ptradd (*this_p, adjustment);
*this_p = value_cast (final_type, *this_p);
if (vbit)
if (noside == EVAL_AVOID_SIDE_EFFECTS)
return value_zero (TYPE_TARGET_TYPE (type), VALUE_LVAL (arg1));
else
- return value_subscript (arg1, arg2);
+ return value_subscript (arg1, value_as_long (arg2));
}
if (name)
error (_("cannot subscript something of type `%s'"), name);
arg1 = value_cast (type, arg1);
type = check_typedef (value_type (arg1));
- return value_ind (value_ptradd (arg1, arg2));
+ return value_ind (value_ptradd (arg1, value_as_long (arg2)));
}
else
if (TYPE_CODE (type) != TYPE_CODE_ARRAY)
if (noside == EVAL_AVOID_SIDE_EFFECTS)
return value_zero (TYPE_TARGET_TYPE (type), VALUE_LVAL (arg1));
else
- return value_subscript (arg1, arg2);
+ return value_subscript (arg1, value_as_long (arg2));
default:
return evaluate_subexp_standard (expect_type, exp, pos, noside);
if (idx == NULL)
return NULL;
- res_val = value_subscript (tmp, idx);
+ res_val = value_subscript (tmp, value_as_long (idx));
}
}
if (field)
CHECK_TYPEDEF (rtype);
rtype = STRIP_REFERENCE (rtype);
- if (TYPE_CODE (ltype) == TYPE_CODE_PTR)
- res_val = value_ptradd (arg1, arg2);
- else if (TYPE_CODE (rtype) == TYPE_CODE_PTR)
- res_val = value_ptradd (arg2, arg1);
+ if (TYPE_CODE (ltype) == TYPE_CODE_PTR
+ && is_integral_type (rtype))
+ res_val = value_ptradd (arg1, value_as_long (arg2));
+ else if (TYPE_CODE (rtype) == TYPE_CODE_PTR
+ && is_integral_type (ltype))
+ res_val = value_ptradd (arg2, value_as_long (arg1));
else
res_val = value_binop (arg1, arg2, BINOP_ADD);
}
CHECK_TYPEDEF (rtype);
rtype = STRIP_REFERENCE (rtype);
- if (TYPE_CODE (ltype) == TYPE_CODE_PTR)
- {
- if (TYPE_CODE (rtype) == TYPE_CODE_PTR)
- /* A ptrdiff_t for the target would be preferable
- here. */
- res_val = value_from_longest (builtin_type_pyint,
- value_ptrdiff (arg1, arg2));
- else
- res_val = value_ptrsub (arg1, arg2);
- }
+ if (TYPE_CODE (ltype) == TYPE_CODE_PTR
+ && TYPE_CODE (rtype) == TYPE_CODE_PTR)
+ /* A ptrdiff_t for the target would be preferable here. */
+ res_val = value_from_longest (builtin_type_pyint,
+ value_ptrdiff (arg1, arg2));
+ else if (TYPE_CODE (ltype) == TYPE_CODE_PTR
+ && is_integral_type (rtype))
+ res_val = value_ptradd (arg1, - value_as_long (arg2));
else
res_val = value_binop (arg1, arg2, BINOP_SUB);
}
If the pointer type is void *, then return 1.
If the target type is incomplete, then error out.
This isn't a general purpose function, but just a
- helper for value_ptrsub & value_ptradd.
+ helper for value_ptradd.
*/
static LONGEST
result of C-style pointer arithmetic ARG1 + ARG2. */
struct value *
-value_ptradd (struct value *arg1, struct value *arg2)
+value_ptradd (struct value *arg1, LONGEST arg2)
{
struct type *valptrtype;
LONGEST sz;
valptrtype = check_typedef (value_type (arg1));
sz = find_size_for_pointer_math (valptrtype);
- if (!is_integral_type (value_type (arg2)))
- error (_("Argument to arithmetic operation not a number or boolean."));
-
- return value_from_pointer (valptrtype,
- value_as_address (arg1)
- + (sz * value_as_long (arg2)));
-}
-
-/* Given a pointer ARG1 and an integral value ARG2, return the
- result of C-style pointer arithmetic ARG1 - ARG2. */
-
-struct value *
-value_ptrsub (struct value *arg1, struct value *arg2)
-{
- struct type *valptrtype;
- LONGEST sz;
-
- arg1 = coerce_array (arg1);
- valptrtype = check_typedef (value_type (arg1));
- sz = find_size_for_pointer_math (valptrtype);
-
- if (!is_integral_type (value_type (arg2)))
- error (_("Argument to arithmetic operation not a number or boolean."));
-
return value_from_pointer (valptrtype,
- value_as_address (arg1)
- - (sz * value_as_long (arg2)));
+ value_as_address (arg1) + sz * arg2);
}
/* Given two compatible pointer values ARG1 and ARG2, return the
verbosity is set, warn about invalid indices (but still use them). */
struct value *
-value_subscript (struct value *array, struct value *idx)
+value_subscript (struct value *array, LONGEST index)
{
struct value *bound;
int c_style = current_language->c_style_arrays;
get_discrete_bounds (range_type, &lowerbound, &upperbound);
if (VALUE_LVAL (array) != lval_memory)
- return value_subscripted_rvalue (array, idx, lowerbound);
+ return value_subscripted_rvalue (array, index, lowerbound);
if (c_style == 0)
{
- LONGEST index = value_as_long (idx);
if (index >= lowerbound && index <= upperbound)
- return value_subscripted_rvalue (array, idx, lowerbound);
+ return value_subscripted_rvalue (array, index, lowerbound);
/* Emit warning unless we have an array of unknown size.
An array of unknown size has lowerbound 0 and upperbound -1. */
if (upperbound > -1)
c_style = 1;
}
- if (lowerbound != 0)
- {
- bound = value_from_longest (value_type (idx), (LONGEST) lowerbound);
- idx = value_binop (idx, bound, BINOP_SUB);
- }
-
+ index -= lowerbound;
array = value_coerce_array (array);
}
if (c_style)
- return value_ind (value_ptradd (array, idx));
+ return value_ind (value_ptradd (array, index));
else
error (_("not an array or string"));
}
to doubles, but no longer does. */
struct value *
-value_subscripted_rvalue (struct value *array, struct value *idx, int lowerbound)
+value_subscripted_rvalue (struct value *array, LONGEST index, int lowerbound)
{
struct type *array_type = check_typedef (value_type (array));
struct type *elt_type = check_typedef (TYPE_TARGET_TYPE (array_type));
unsigned int elt_size = TYPE_LENGTH (elt_type);
- LONGEST index = value_as_long (idx);
unsigned int elt_offs = elt_size * longest_to_int (index - lowerbound);
struct value *v;
struct value *
value_bitstring_subscript (struct type *type,
- struct value *bitstring, struct value *idx)
+ struct value *bitstring, LONGEST index)
{
struct type *bitstring_type, *range_type;
- LONGEST index = value_as_long (idx);
struct value *v;
int offset, byte, bit_index;
LONGEST lowerbound, upperbound;
extern struct value *value_binop (struct value *arg1, struct value *arg2,
enum exp_opcode op);
-extern struct value *value_ptradd (struct value *arg1, struct value *arg2);
-
-extern struct value *value_ptrsub (struct value *arg1, struct value *arg2);
+extern struct value *value_ptradd (struct value *arg1, LONGEST arg2);
extern LONGEST value_ptrdiff (struct value *arg1, struct value *arg2);
extern struct value *value_repeat (struct value *arg1, int count);
-extern struct value *value_subscript (struct value *array, struct value *idx);
+extern struct value *value_subscript (struct value *array, LONGEST index);
extern struct value *value_bitstring_subscript (struct type *type,
struct value *bitstring,
- struct value *idx);
+ LONGEST index);
extern struct value *register_value_being_returned (struct type *valtype,
struct regcache *retbuf);
extern struct value *value_of_local (const char *name, int complain);
-extern struct value * value_subscripted_rvalue (struct value *array, struct value *idx, int lowerbound);
+extern struct value *value_subscripted_rvalue (struct value *array,
+ LONGEST index, int lowerbound);
/* User function handler. */
if (cvalue && value)
{
int real_index = index + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type));
- struct value *indval =
- value_from_longest (builtin_type_int32, (LONGEST) real_index);
- gdb_value_subscript (value, indval, cvalue);
+ gdb_value_subscript (value, real_index, cvalue);
}
if (ctype)
}
int
-gdb_value_subscript (struct value *val1, struct value *val2,
+gdb_value_subscript (struct value *val, LONGEST index,
struct value **result)
{
volatile struct gdb_exception except;
TRY_CATCH (except, RETURN_MASK_ERROR)
{
- *result = value_subscript (val1, val2);
+ *result = value_subscript (val, index);
}
if (except.reason < 0)
extern int gdb_value_assign (struct value *, struct value *, struct value **);
-extern int gdb_value_subscript (struct value *, struct value *,
- struct value **);
+extern int gdb_value_subscript (struct value *, LONGEST, struct value **);
extern enum gdb_rc gdb_value_struct_elt (struct ui_out *uiout,
struct value **result_ptr,