/* Create a value for an array by allocating space in GDB, copying the
data into that space, and then setting up an array value.
- The array bounds are set from LOWBOUND and HIGHBOUND, and the array
- is populated from the values passed in ELEMVEC.
+ The array bounds are set from LOWBOUND and the size of ELEMVEC, and
+ the array is populated from the values passed in ELEMVEC.
The element type of the array is inherited from the type of the
first element, and all elements must have the same size (though we
don't currently enforce any restriction on their types). */
struct value *
-value_array (int lowbound, int highbound,
- gdb::array_view<struct value *> elemvec)
+value_array (int lowbound, gdb::array_view<struct value *> elemvec)
{
- int nelem;
int idx;
ULONGEST typelength;
struct value *val;
/* Validate that the bounds are reasonable and that each of the
elements have the same size. */
- nelem = highbound - lowbound + 1;
- if (nelem <= 0)
- {
- error (_("bad array bounds (%d, %d)"), lowbound, highbound);
- }
typelength = type_length_units (elemvec[0]->enclosing_type ());
- for (idx = 1; idx < nelem; idx++)
+ for (struct value *other : elemvec.slice (1))
{
- if (type_length_units (elemvec[idx]->enclosing_type ())
- != typelength)
+ if (type_length_units (other->enclosing_type ()) != typelength)
{
error (_("array elements must all be the same size"));
}
}
arraytype = lookup_array_range_type (elemvec[0]->enclosing_type (),
- lowbound, highbound);
+ lowbound,
+ lowbound + elemvec.size () - 1);
if (!current_language->c_style_arrays_p ())
{
val = value::allocate (arraytype);
- for (idx = 0; idx < nelem; idx++)
+ for (idx = 0; idx < elemvec.size (); idx++)
elemvec[idx]->contents_copy (val, idx * typelength, 0, typelength);
return val;
}
copying in each element. */
val = value::allocate (arraytype);
- for (idx = 0; idx < nelem; idx++)
+ for (idx = 0; idx < elemvec.size (); idx++)
elemvec[idx]->contents_copy (val, idx * typelength, 0, typelength);
return val;
}
return value_string ((const gdb_byte *) ptr, count, char_type);
}
-extern struct value *value_array (int lowbound, int highbound,
+extern struct value *value_array (int lowbound,
gdb::array_view<struct value *> elemvec);
extern struct value *value_concat (struct value *arg1, struct value *arg2);