/* Perform non-arithmetic operations on values, for GDB.
- Copyright 1986, 1987, 1989, 1991, 1992, 1993, 1994, 1995
+ Copyright 1986, 1987, 1989, 1991, 1992, 1993, 1994, 1995, 1996
Free Software Foundation, Inc.
This file is part of GDB.
#include <errno.h>
#include "gdb_string.h"
+/* Default to coercing float to double in function calls only when there is
+ no prototype. Otherwise on targets where the debug information is incorrect
+ for either the prototype or non-prototype case, we can force it by defining
+ COERCE_FLOAT_TO_DOUBLE in the target configuration file. */
+
+#ifndef COERCE_FLOAT_TO_DOUBLE
+#define COERCE_FLOAT_TO_DOUBLE (param_type == NULL)
+#endif
+
/* Local functions. */
static int typecmp PARAMS ((int staticp, struct type *t1[], value_ptr t2[]));
+#ifdef CALL_DUMMY
static CORE_ADDR find_function_addr PARAMS ((value_ptr, struct type **));
+static value_ptr value_arg_coerce PARAMS ((value_ptr, struct type *));
+#endif
+
+#ifndef PUSH_ARGUMENTS
static CORE_ADDR value_push PARAMS ((CORE_ADDR, value_ptr));
+#endif
static value_ptr search_struct_field PARAMS ((char *, value_ptr, int,
struct type *, int));
/* Flag for whether we want to abandon failed expression evals by default. */
+#if 0
static int auto_abandon = 0;
+#endif
\f
/* Find the address of function name NAME in the inferior. */
low_bound = 0, high_bound = 0;
new_length = val_length / element_length;
if (val_length % element_length != 0)
- warning("array element type size does not divide object size in cast");
+ warning("array element type size does not divide object size in cast");
/* FIXME-type-allocation: need a way to free this type when we are
done with it. */
range_type = create_range_type ((struct type *) NULL,
COERCE_VARYING_ARRAY (arg2, type2);
code2 = TYPE_CODE (type2);
- if (code1 == TYPE_CODE_COMPLEX)
- return cast_into_complex (type, arg2);
- if (code1 == TYPE_CODE_BOOL)
+ if (code1 == TYPE_CODE_COMPLEX)
+ return cast_into_complex (type, arg2);
+ if (code1 == TYPE_CODE_BOOL || code1 == TYPE_CODE_CHAR)
code1 = TYPE_CODE_INT;
- if (code2 == TYPE_CODE_BOOL)
+ if (code2 == TYPE_CODE_BOOL || code2 == TYPE_CODE_CHAR)
code2 = TYPE_CODE_INT;
scalar = (code2 == TYPE_CODE_INT || code2 == TYPE_CODE_FLT
}
else if (VALUE_LVAL (arg2) == lval_memory)
{
- return value_at_lazy (type, VALUE_ADDRESS (arg2) + VALUE_OFFSET (arg2));
+ return value_at_lazy (type, VALUE_ADDRESS (arg2) + VALUE_OFFSET (arg2),
+ VALUE_BFD_SECTION (arg2));
}
else if (code1 == TYPE_CODE_VOID)
{
the contents are actually required. */
value_ptr
-value_at (type, addr)
+value_at (type, addr, sect)
struct type *type;
CORE_ADDR addr;
+ asection *sect;
{
register value_ptr val;
val = allocate_value (type);
- read_memory (addr, VALUE_CONTENTS_RAW (val), TYPE_LENGTH (type));
+#ifdef GDB_TARGET_IS_D10V
+ if (TYPE_TARGET_TYPE(type) && TYPE_CODE(TYPE_TARGET_TYPE(type)) == TYPE_CODE_FUNC)
+ {
+ int num;
+ short snum;
+ read_memory (addr, (char *)&snum, 2);
+ num = D10V_MAKE_IADDR(snum);
+ memcpy( VALUE_CONTENTS_RAW (val), &num, 4);
+ }
+ else
+#endif
+
+ read_memory_section (addr, VALUE_CONTENTS_RAW (val), TYPE_LENGTH (type), sect);
VALUE_LVAL (val) = lval_memory;
VALUE_ADDRESS (val) = addr;
+ VALUE_BFD_SECTION (val) = sect;
return val;
}
/* Return a lazy value with type TYPE located at ADDR (cf. value_at). */
value_ptr
-value_at_lazy (type, addr)
+value_at_lazy (type, addr, sect)
struct type *type;
CORE_ADDR addr;
+ asection *sect;
{
register value_ptr val;
VALUE_LVAL (val) = lval_memory;
VALUE_ADDRESS (val) = addr;
VALUE_LAZY (val) = 1;
+ VALUE_BFD_SECTION (val) = sect;
return val;
}
CORE_ADDR addr = VALUE_ADDRESS (val) + VALUE_OFFSET (val);
int length = TYPE_LENGTH (VALUE_TYPE (val));
+#ifdef GDB_TARGET_IS_D10V
+ struct type *type = VALUE_TYPE(val);
+ if (TYPE_TARGET_TYPE(type) && TYPE_CODE(TYPE_TARGET_TYPE(type)) == TYPE_CODE_FUNC)
+ {
+ int num;
+ short snum;
+ read_memory (addr, (char *)&snum, 2);
+ num = D10V_MAKE_IADDR(snum);
+ memcpy( VALUE_CONTENTS_RAW (val), &num, 4);
+ }
+ else
+#endif
+
if (length)
- read_memory (addr, VALUE_CONTENTS_RAW (val), length);
+ read_memory_section (addr, VALUE_CONTENTS_RAW (val), length,
+ VALUE_BFD_SECTION (val));
VALUE_LAZY (val) = 0;
return 0;
}
if (!toval->modifiable)
error ("Left operand of assignment is not a modifiable lvalue.");
- COERCE_ARRAY (fromval);
COERCE_REF (toval);
type = VALUE_TYPE (toval);
if (VALUE_LVAL (toval) != lval_internalvar)
fromval = value_cast (type, fromval);
+ else
+ COERCE_ARRAY (fromval);
CHECK_TYPEDEF (type);
/* If TOVAL is a special machine register requiring conversion
{
case lval_internalvar:
set_internalvar (VALUE_INTERNALVAR (toval), fromval);
- return VALUE_INTERNALVAR (toval)->value;
+ return value_copy (VALUE_INTERNALVAR (toval)->value);
case lval_internalvar_component:
set_internalvar_component (VALUE_INTERNALVAR (toval),
+ HOST_CHAR_BIT - 1)
/ HOST_CHAR_BIT;
- if (len > sizeof (LONGEST))
+ if (len > (int) sizeof (LONGEST))
error ("Can't handle bitfields which don't fit in a %d bit word.",
sizeof (LONGEST) * HOST_CHAR_BIT);
char buffer[sizeof (LONGEST)];
int len = REGISTER_RAW_SIZE (VALUE_REGNO (toval));
- if (len > sizeof (LONGEST))
+ if (len > (int) sizeof (LONGEST))
error ("Can't handle bitfields in registers larger than %d bits.",
sizeof (LONGEST) * HOST_CHAR_BIT);
/* If the field does not entirely fill a LONGEST, then zero the sign bits.
If the field is signed, and is negative, then sign extend. */
if ((VALUE_BITSIZE (toval) > 0)
- && (VALUE_BITSIZE (toval) < 8 * sizeof (LONGEST)))
+ && (VALUE_BITSIZE (toval) < 8 * (int) sizeof (LONGEST)))
{
LONGEST fieldval = value_as_long (fromval);
- LONGEST valmask = (((unsigned LONGEST) 1) << VALUE_BITSIZE (toval)) - 1;
+ LONGEST valmask = (((ULONGEST) 1) << VALUE_BITSIZE (toval)) - 1;
fieldval &= valmask;
if (!TYPE_UNSIGNED (type) && (fieldval & (valmask ^ (valmask >> 1))))
struct block *b;
{
value_ptr val;
- struct frame_info *frame;
+ struct frame_info *frame = NULL;
- if (b == NULL)
- /* Use selected frame. */
- frame = NULL;
- else
+ if (!b)
+ frame = NULL; /* Use selected frame. */
+ else if (symbol_read_needs_frame (var))
{
frame = block_innermost_frame (b);
- if (frame == NULL && symbol_read_needs_frame (var))
- {
- if (BLOCK_FUNCTION (b) != NULL
- && SYMBOL_NAME (BLOCK_FUNCTION (b)) != NULL)
- error ("No frame is currently executing in block %s.",
- SYMBOL_NAME (BLOCK_FUNCTION (b)));
- else
- error ("No frame is currently executing in specified block");
- }
+ if (!frame)
+ if (BLOCK_FUNCTION (b)
+ && SYMBOL_NAME (BLOCK_FUNCTION (b)))
+ error ("No frame is currently executing in block %s.",
+ SYMBOL_NAME (BLOCK_FUNCTION (b)));
+ else
+ error ("No frame is currently executing in specified block");
}
+
val = read_var_value (var, frame);
- if (val == 0)
+ if (!val)
error ("Address of symbol \"%s\" is unknown.", SYMBOL_SOURCE_NAME (var));
+
return val;
}
value_coerce_function (arg1)
value_ptr arg1;
{
+ value_ptr retval;
if (VALUE_LVAL (arg1) != lval_memory)
error ("Attempt to take address of value not located in memory.");
- return value_from_longest (lookup_pointer_type (VALUE_TYPE (arg1)),
- (LONGEST) (VALUE_ADDRESS (arg1) + VALUE_OFFSET (arg1)));
+ retval = value_from_longest (lookup_pointer_type (VALUE_TYPE (arg1)),
+ (LONGEST) (VALUE_ADDRESS (arg1) + VALUE_OFFSET (arg1)));
+ VALUE_BFD_SECTION (retval) = VALUE_BFD_SECTION (arg1);
+ return retval;
}
/* Return a pointer value for the object for which ARG1 is the contents. */
value_addr (arg1)
value_ptr arg1;
{
+ value_ptr retval;
+
struct type *type = check_typedef (VALUE_TYPE (arg1));
if (TYPE_CODE (type) == TYPE_CODE_REF)
{
if (VALUE_LVAL (arg1) != lval_memory)
error ("Attempt to take address of value not located in memory.");
- return value_from_longest (lookup_pointer_type (VALUE_TYPE (arg1)),
- (LONGEST) (VALUE_ADDRESS (arg1) + VALUE_OFFSET (arg1)));
+ retval = value_from_longest (lookup_pointer_type (VALUE_TYPE (arg1)),
+ (LONGEST) (VALUE_ADDRESS (arg1) + VALUE_OFFSET (arg1)));
+ VALUE_BFD_SECTION (retval) = VALUE_BFD_SECTION (arg1);
+ return retval;
}
/* Given a value of a pointer type, apply the C unary * operator to it. */
BUILTIN_TYPE_LONGEST would seem to be a mistake. */
if (TYPE_CODE (type1) == TYPE_CODE_INT)
return value_at (builtin_type_int,
- (CORE_ADDR) value_as_long (arg1));
+ (CORE_ADDR) value_as_long (arg1),
+ VALUE_BFD_SECTION (arg1));
else if (TYPE_CODE (type1) == TYPE_CODE_PTR)
- return value_at_lazy (TYPE_TARGET_TYPE (type1), value_as_pointer (arg1));
+ return value_at_lazy (TYPE_TARGET_TYPE (type1), value_as_pointer (arg1),
+ VALUE_BFD_SECTION (arg1));
error ("Attempt to take contents of a non-pointer value.");
return 0; /* For lint -- never reached */
}
CORE_ADDR
push_word (sp, word)
CORE_ADDR sp;
- unsigned LONGEST word;
+ ULONGEST word;
{
register int len = REGISTER_SIZE;
char buffer[MAX_REGISTER_RAW_SIZE];
/* Push onto the stack the specified value VALUE. */
+#ifndef PUSH_ARGUMENTS
+
static CORE_ADDR
value_push (sp, arg)
register CORE_ADDR sp;
return sp;
}
+#endif /* !PUSH_ARGUMENTS */
+
+#ifdef CALL_DUMMY
/* Perform the standard coercions that are specified
for arguments to be passed to C functions.
if (TYPE_LENGTH (type) < TYPE_LENGTH (builtin_type_int))
type = builtin_type_int;
break;
- case TYPE_CODE_FLT:
- if (TYPE_LENGTH (type) < TYPE_LENGTH (builtin_type_double))
- type = builtin_type_double;
- break;
+ case TYPE_CODE_FLT:
+ /* coerce float to double, unless the function prototype specifies float */
+ if (COERCE_FLOAT_TO_DOUBLE)
+ {
+ if (TYPE_LENGTH (type) < TYPE_LENGTH (builtin_type_double))
+ type = builtin_type_double;
+ else if (TYPE_LENGTH (type) > TYPE_LENGTH (builtin_type_double))
+ type = builtin_type_long_double;
+ }
+ break;
case TYPE_CODE_FUNC:
type = lookup_pointer_type (type);
break;
return funaddr;
}
-#if defined (CALL_DUMMY)
/* All this stuff with a dummy frame may seem unnecessarily complicated
(why not just save registers in GDB?). The purpose of pushing a dummy
frame which looks just like a real frame is so that if you call a
CORE_ADDR start_sp;
/* CALL_DUMMY is an array of words (REGISTER_SIZE), but each word
is in host byte order. Before calling FIX_CALL_DUMMY, we byteswap it
- and remove any extra bytes which might exist because unsigned LONGEST is
+ and remove any extra bytes which might exist because ULONGEST is
bigger than REGISTER_SIZE. */
- static unsigned LONGEST dummy[] = CALL_DUMMY;
- char dummy1[REGISTER_SIZE * sizeof dummy / sizeof (unsigned LONGEST)];
+ static ULONGEST dummy[] = CALL_DUMMY;
+ char dummy1[REGISTER_SIZE * sizeof dummy / sizeof (ULONGEST)];
CORE_ADDR old_sp;
struct type *value_type;
unsigned char struct_return;
- CORE_ADDR struct_addr;
+ CORE_ADDR struct_addr = 0;
struct inferior_status inf_status;
struct cleanup *old_chain;
CORE_ADDR funaddr;
- int using_gcc;
+ int using_gcc; /* Set to version of gcc in use, or zero if not gcc */
CORE_ADDR real_pc;
struct type *ftype = check_typedef (SYMBOL_TYPE (function));
{
struct block *b = block_for_pc (funaddr);
- /* If compiled without -g, assume GCC. */
- using_gcc = b == NULL ? 0 : BLOCK_GCC_COMPILED (b);
+ /* If compiled without -g, assume GCC 2. */
+ using_gcc = (b == NULL ? 2 : BLOCK_GCC_COMPILED (b));
}
/* Are we returning a value using a structure return or a normal
/* Create a call sequence customized for this function
and the number of arguments for it. */
- for (i = 0; i < sizeof dummy / sizeof (dummy[0]); i++)
+ for (i = 0; i < (int) (sizeof (dummy) / sizeof (dummy[0])); i++)
store_unsigned_integer (&dummy1[i * REGISTER_SIZE],
REGISTER_SIZE,
- (unsigned LONGEST)dummy[i]);
+ (ULONGEST)dummy[i]);
#ifdef GDB_TARGET_IS_HPPA
real_pc = FIX_CALL_DUMMY (dummy1, start_sp, funaddr, nargs, args,
if ((TYPE_CODE (arg_type) == TYPE_CODE_STRUCT
|| TYPE_CODE (arg_type) == TYPE_CODE_UNION
|| TYPE_CODE (arg_type) == TYPE_CODE_ARRAY
- || TYPE_CODE (arg_type) == TYPE_CODE_STRING)
+ || TYPE_CODE (arg_type) == TYPE_CODE_STRING
+ || TYPE_CODE (arg_type) == TYPE_CODE_BITSTRING
+ || TYPE_CODE (arg_type) == TYPE_CODE_SET
+ || (TYPE_CODE (arg_type) == TYPE_CODE_FLT
+ && TYPE_LENGTH (arg_type) > 8)
+ )
&& REG_STRUCT_HAS_ADDR (using_gcc, arg_type))
{
CORE_ADDR addr;
int len = TYPE_LENGTH (arg_type);
#ifdef STACK_ALIGN
+ /* MVS 11/22/96: I think at least some of this stack_align code is
+ really broken. Better to let PUSH_ARGUMENTS adjust the stack in
+ a target-defined manner. */
int aligned_len = STACK_ALIGN (len);
#else
int aligned_len = len;
{
int len = TYPE_LENGTH (value_type);
#ifdef STACK_ALIGN
+ /* MVS 11/22/96: I think at least some of this stack_align code is
+ really broken. Better to let PUSH_ARGUMENTS adjust the stack in
+ a target-defined manner. */
len = STACK_ALIGN (len);
#endif
#if 1 INNER_THAN 2
#endif
}
-#ifdef STACK_ALIGN
- /* If stack grows down, we must leave a hole at the top. */
+#if defined(STACK_ALIGN) && (1 INNER_THAN 2)
+ /* MVS 11/22/96: I think at least some of this stack_align code is
+ really broken. Better to let PUSH_ARGUMENTS adjust the stack in
+ a target-defined manner. */
{
+ /* If stack grows down, we must leave a hole at the top. */
int len = 0;
for (i = nargs - 1; i >= 0; i--)
#ifdef CALL_DUMMY_STACK_ADJUST
len += CALL_DUMMY_STACK_ADJUST;
#endif
-#if 1 INNER_THAN 2
sp -= STACK_ALIGN (len) - len;
-#else
- sp += STACK_ALIGN (len) - len;
-#endif
}
#endif /* STACK_ALIGN */
sp = value_push (sp, args[i]);
#endif /* !PUSH_ARGUMENTS */
+#ifdef PUSH_RETURN_ADDRESS /* for targets that use no CALL_DUMMY */
+ /* There are a number of targets now which actually don't write any
+ CALL_DUMMY instructions into the target, but instead just save the
+ machine state, push the arguments, and jump directly to the callee
+ function. Since this doesn't actually involve executing a JSR/BSR
+ instruction, the return address must be set up by hand, either by
+ pushing onto the stack or copying into a return-address register
+ as appropriate. Formerly this has been done in PUSH_ARGUMENTS,
+ but that's overloading its functionality a bit, so I'm making it
+ explicit to do it here. */
+ sp = PUSH_RETURN_ADDRESS(real_pc, sp);
+#endif /* PUSH_RETURN_ADDRESS */
+
+#if defined(STACK_ALIGN) && !(1 INNER_THAN 2)
+ {
+ /* If stack grows up, we must leave a hole at the bottom, note
+ that sp already has been advanced for the arguments! */
+#ifdef CALL_DUMMY_STACK_ADJUST
+ sp += CALL_DUMMY_STACK_ADJUST;
+#endif
+ sp = STACK_ALIGN (sp);
+ }
+#endif /* STACK_ALIGN */
+
+/* XXX This seems wrong. For stacks that grow down we shouldn't do
+ anything here! */
+ /* MVS 11/22/96: I think at least some of this stack_align code is
+ really broken. Better to let PUSH_ARGUMENTS adjust the stack in
+ a target-defined manner. */
#ifdef CALL_DUMMY_STACK_ADJUST
#if 1 INNER_THAN 2
sp -= CALL_DUMMY_STACK_ADJUST;
-#else
- sp += CALL_DUMMY_STACK_ADJUST;
#endif
#endif /* CALL_DUMMY_STACK_ADJUST */
{
int nelem;
int idx;
- int typelength;
+ unsigned int typelength;
value_ptr val;
struct type *rangetype;
struct type *arraytype;
}
}
+ rangetype = create_range_type ((struct type *) NULL, builtin_type_int,
+ lowbound, highbound);
+ arraytype = create_array_type ((struct type *) NULL,
+ VALUE_TYPE (elemvec[0]), rangetype);
+
+ if (!current_language->c_style_arrays)
+ {
+ val = allocate_value (arraytype);
+ for (idx = 0; idx < nelem; idx++)
+ {
+ memcpy (VALUE_CONTENTS_RAW (val) + (idx * typelength),
+ VALUE_CONTENTS (elemvec[idx]),
+ typelength);
+ }
+ VALUE_BFD_SECTION (val) = VALUE_BFD_SECTION (elemvec[0]);
+ return val;
+ }
+
/* Allocate space to store the array in the inferior, and then initialize
it by copying in each element. FIXME: Is it worth it to create a
local buffer in which to collect each value and then write all the
/* Create the array type and set up an array value to be evaluated lazily. */
- rangetype = create_range_type ((struct type *) NULL, builtin_type_int,
- lowbound, highbound);
- arraytype = create_array_type ((struct type *) NULL,
- VALUE_TYPE (elemvec[0]), rangetype);
- val = value_at_lazy (arraytype, addr);
+ val = value_at_lazy (arraytype, addr, VALUE_BFD_SECTION (elemvec[0]));
return (val);
}
addr = allocate_space_in_inferior (len);
write_memory (addr, ptr, len);
- val = value_at_lazy (stringtype, addr);
+ val = value_at_lazy (stringtype, addr, NULL);
return (val);
}
error ("Internal error: could not find physical static variable named %s",
phys_name);
v = value_at (TYPE_FIELD_TYPE (type, i),
- (CORE_ADDR)SYMBOL_BLOCK_VALUE (sym));
+ SYMBOL_VALUE_ADDRESS (sym), SYMBOL_BFD_SECTION (sym));
}
else
v = value_primitive_field (arg1, offset, i, type);
for (i = TYPE_NFN_FIELDS (type) - 1; i >= 0; i--)
{
char *t_field_name = TYPE_FN_FIELDLIST_NAME (type, i);
+ /* FIXME! May need to check for ARM demangling here */
if (strncmp(t_field_name, "__", 2)==0 ||
strncmp(t_field_name, "op", 2)==0 ||
strncmp(t_field_name, "type", 4)==0 )
{
if (!args[1])
{
- /* destructors are a special case. */
- v = value_fn_field (NULL, TYPE_FN_FIELDLIST1 (t, 0),
- TYPE_FN_FIELDLIST_LENGTH (t, 0), 0, 0);
- if (!v) error("could not find destructor function named %s.", name);
- else return v;
+ /* Destructors are a special case. */
+ int m_index, f_index;
+
+ v = NULL;
+ if (get_destructor_fn_field (t, &m_index, &f_index))
+ {
+ v = value_fn_field (NULL, TYPE_FN_FIELDLIST1 (t, m_index),
+ f_index, NULL, 0);
+ }
+ if (v == NULL)
+ error ("could not find destructor function named %s.", name);
+ else
+ return v;
}
else
{
{
char *dname = type_name_no_tag (type);
char *cp = strchr (dname, '<');
- int len;
+ unsigned int len;
/* Do not compare the template part for template classes. */
if (cp == NULL)
/* Destructors are a special case. */
if (destructor_name_p (name, type))
- return 1;
+ {
+ int m_index, f_index;
+
+ return get_destructor_fn_field (type, &m_index, &f_index);
+ }
for (i = TYPE_NFN_FIELDS (type) - 1; i >= 0; --i)
{
error ("Internal error: could not find physical static variable named %s",
phys_name);
return value_at (SYMBOL_TYPE (sym),
- (CORE_ADDR)SYMBOL_BLOCK_VALUE (sym));
+ SYMBOL_VALUE_ADDRESS (sym),
+ SYMBOL_BFD_SECTION (sym));
}
if (TYPE_FIELD_PACKED (t, i))
error ("pointers to bitfield members not allowed");
value_ptr array;
int lowbound, length;
{
+ struct type *slice_range_type, *slice_type, *range_type;
+ LONGEST lowerbound, upperbound, offset;
+ value_ptr slice;
struct type *array_type;
array_type = check_typedef (VALUE_TYPE (array));
COERCE_VARYING_ARRAY (array, array_type);
- if (TYPE_CODE (array_type) == TYPE_CODE_BITSTRING)
- error ("not implemented - bitstring slice");
if (TYPE_CODE (array_type) != TYPE_CODE_ARRAY
- && TYPE_CODE (array_type) != TYPE_CODE_STRING)
+ && TYPE_CODE (array_type) != TYPE_CODE_STRING
+ && TYPE_CODE (array_type) != TYPE_CODE_BITSTRING)
error ("cannot take slice of non-array");
+ range_type = TYPE_INDEX_TYPE (array_type);
+ if (get_discrete_bounds (range_type, &lowerbound, &upperbound) < 0)
+ error ("slice from bad array or bitstring");
+ if (lowbound < lowerbound || length < 0
+ || lowbound + length - 1 > upperbound
+ /* Chill allows zero-length strings but not arrays. */
+ || (current_language->la_language == language_chill
+ && length == 0 && TYPE_CODE (array_type) == TYPE_CODE_ARRAY))
+ error ("slice out of range");
+ /* FIXME-type-allocation: need a way to free this type when we are
+ done with it. */
+ slice_range_type = create_range_type ((struct type*) NULL,
+ TYPE_TARGET_TYPE (range_type),
+ lowbound, lowbound + length - 1);
+ if (TYPE_CODE (array_type) == TYPE_CODE_BITSTRING)
+ {
+ int i;
+ slice_type = create_set_type ((struct type*) NULL, slice_range_type);
+ TYPE_CODE (slice_type) = TYPE_CODE_BITSTRING;
+ slice = value_zero (slice_type, not_lval);
+ for (i = 0; i < length; i++)
+ {
+ int element = value_bit_index (array_type,
+ VALUE_CONTENTS (array),
+ lowbound + i);
+ if (element < 0)
+ error ("internal error accessing bitstring");
+ else if (element > 0)
+ {
+ int j = i % TARGET_CHAR_BIT;
+ if (BITS_BIG_ENDIAN)
+ j = TARGET_CHAR_BIT - 1 - j;
+ VALUE_CONTENTS_RAW (slice)[i / TARGET_CHAR_BIT] |= (1 << j);
+ }
+ }
+ /* We should set the address, bitssize, and bitspos, so the clice
+ can be used on the LHS, but that may require extensions to
+ value_assign. For now, just leave as a non_lval. FIXME. */
+ }
else
{
- struct type *slice_range_type, *slice_type;
- value_ptr slice;
- struct type *range_type = TYPE_FIELD_TYPE (array_type,0);
struct type *element_type = TYPE_TARGET_TYPE (array_type);
- LONGEST lowerbound, upperbound, offset;
-
- if (get_discrete_bounds (range_type, &lowerbound, &upperbound) < 0)
- error ("slice from bad array");
offset
= (lowbound - lowerbound) * TYPE_LENGTH (check_typedef (element_type));
- if (lowbound < lowerbound || length < 0
- || lowbound + length - 1 > upperbound)
- error ("slice out of range");
- /* FIXME-type-allocation: need a way to free this type when we are
- done with it. */
- slice_range_type = create_range_type ((struct type*) NULL,
- TYPE_TARGET_TYPE (range_type),
- lowerbound,
- lowerbound + length - 1);
slice_type = create_array_type ((struct type*) NULL, element_type,
slice_range_type);
TYPE_CODE (slice_type) = TYPE_CODE (array_type);
VALUE_LVAL (slice) = VALUE_LVAL (array);
VALUE_ADDRESS (slice) = VALUE_ADDRESS (array);
VALUE_OFFSET (slice) = VALUE_OFFSET (array) + offset;
- return slice;
}
+ return slice;
}
/* Assuming chill_varying_type (VARRAY) is true, return an equivalent