* h8300-tdep.c (h8300_push_dummy_call): Replace unsafe alloca
[deliverable/binutils-gdb.git] / gdb / valarith.c
index 265532cd4f611fb00c32ac5a3ad34b82fc470a6e..6858d2b6c64dddcc4b3681cecd6c07ce5cdc4cbe 100644 (file)
@@ -1,8 +1,7 @@
 /* Perform arithmetic and other operations on values, for GDB.
 
-   Copyright (C) 1986, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996,
-   1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009,
-   2010, 2011 Free Software Foundation, Inc.
+   Copyright (C) 1986, 1988-2005, 2007-2012 Free Software Foundation,
+   Inc.
 
    This file is part of GDB.
 
@@ -65,7 +64,7 @@ find_size_for_pointer_math (struct type *ptr_type)
        sz = 1;
       else
        {
-         char *name;
+         const char *name;
          
          name = TYPE_NAME (ptr_target);
          if (name == NULL)
@@ -140,7 +139,6 @@ value_ptrdiff (struct value *arg1, struct value *arg2)
 
    ARRAY may be of type TYPE_CODE_ARRAY or TYPE_CODE_STRING.  If the
    current language supports C-style arrays, it may also be TYPE_CODE_PTR.
-   To access TYPE_CODE_BITSTRING values, use value_bitstring_subscript.
 
    See comments in value_coerce_array() for rationale for reason for
    doing lower bounds adjustment here rather than there.
@@ -210,8 +208,9 @@ value_subscripted_rvalue (struct value *array, LONGEST index, int lowerbound)
   else
     {
       v = allocate_value (elt_type);
-      memcpy (value_contents_writeable (v),
-             value_contents (array) + elt_offs, elt_size);
+      value_contents_copy (v, value_embedded_offset (v),
+                          array, value_embedded_offset (array) + elt_offs,
+                          elt_size);
     }
 
   set_value_component_location (v, array);
@@ -221,46 +220,6 @@ value_subscripted_rvalue (struct value *array, LONGEST index, int lowerbound)
   return v;
 }
 
-/* Return the value of BITSTRING[IDX] as (boolean) type TYPE.  */
-
-struct value *
-value_bitstring_subscript (struct type *type,
-                          struct value *bitstring, LONGEST index)
-{
-
-  struct type *bitstring_type, *range_type;
-  struct value *v;
-  int offset, byte, bit_index;
-  LONGEST lowerbound, upperbound;
-
-  bitstring_type = check_typedef (value_type (bitstring));
-  gdb_assert (TYPE_CODE (bitstring_type) == TYPE_CODE_BITSTRING);
-
-  range_type = TYPE_INDEX_TYPE (bitstring_type);
-  get_discrete_bounds (range_type, &lowerbound, &upperbound);
-  if (index < lowerbound || index > upperbound)
-    error (_("bitstring index out of range"));
-
-  index -= lowerbound;
-  offset = index / TARGET_CHAR_BIT;
-  byte = *((char *) value_contents (bitstring) + offset);
-
-  bit_index = index % TARGET_CHAR_BIT;
-  byte >>= (gdbarch_bits_big_endian (get_type_arch (bitstring_type)) ?
-           TARGET_CHAR_BIT - 1 - bit_index : bit_index);
-
-  v = value_from_longest (type, byte & 1);
-
-  set_value_bitpos (v, bit_index);
-  set_value_bitsize (v, 1);
-  set_value_component_location (v, bitstring);
-  VALUE_FRAME_ID (v) = VALUE_FRAME_ID (bitstring);
-
-  set_value_offset (v, offset + value_offset (bitstring));
-
-  return v;
-}
-
 \f
 /* Check to see if either argument is a structure, or a reference to
    one.  This is called so we know whether to go ahead with the normal
@@ -279,7 +238,7 @@ binop_types_user_defined_p (enum exp_opcode op,
   if (TYPE_CODE (type1) == TYPE_CODE_REF)
     type1 = check_typedef (TYPE_TARGET_TYPE (type1));
 
-  type2 = check_typedef (type1);
+  type2 = check_typedef (type2);
   if (TYPE_CODE (type2) == TYPE_CODE_REF)
     type2 = check_typedef (TYPE_TARGET_TYPE (type2));
 
@@ -314,15 +273,9 @@ unop_user_defined_p (enum exp_opcode op, struct value *arg1)
   if (op == UNOP_ADDR)
     return 0;
   type1 = check_typedef (value_type (arg1));
-  for (;;)
-    {
-      if (TYPE_CODE (type1) == TYPE_CODE_STRUCT)
-       return 1;
-      else if (TYPE_CODE (type1) == TYPE_CODE_REF)
-       type1 = TYPE_TARGET_TYPE (type1);
-      else
-       return 0;
-    }
+  if (TYPE_CODE (type1) == TYPE_CODE_REF)
+    type1 = check_typedef (TYPE_TARGET_TYPE (type1));
+  return TYPE_CODE (type1) == TYPE_CODE_STRUCT;
 }
 
 /* Try to find an operator named OPERATOR which takes NARGS arguments
@@ -340,15 +293,8 @@ value_user_defined_cpp_op (struct value **args, int nargs, char *operator,
 
   struct symbol *symp = NULL;
   struct value *valp = NULL;
-  struct type **arg_types;
-  int i;
-
-  arg_types = (struct type **) alloca (nargs * (sizeof (struct type *)));
-  /* Prepare list of argument types for overload resolution.  */
-  for (i = 0; i < nargs; i++)
-    arg_types[i] = value_type (args[i]);
 
-  find_overload_match (arg_types, nargs, operator, BOTH /* could be method */,
+  find_overload_match (args, nargs, operator, BOTH /* could be method */,
                        0 /* strict match */, &args[0], /* objp */
                        NULL /* pass NULL symbol since symbol is unknown */,
                        &valp, &symp, static_memfuncp, 0);
@@ -748,10 +694,9 @@ value_concat (struct value *arg1, struct value *arg2)
            }
          outval = value_string (ptr, count * inval2len, char_type);
        }
-      else if (TYPE_CODE (type2) == TYPE_CODE_BITSTRING
-              || TYPE_CODE (type2) == TYPE_CODE_BOOL)
+      else if (TYPE_CODE (type2) == TYPE_CODE_BOOL)
        {
-         error (_("unimplemented support for bitstring/boolean repeats"));
+         error (_("unimplemented support for boolean repeats"));
        }
       else
        {
@@ -793,17 +738,15 @@ value_concat (struct value *arg1, struct value *arg2)
        }
       outval = value_string (ptr, inval1len + inval2len, char_type);
     }
-  else if (TYPE_CODE (type1) == TYPE_CODE_BITSTRING
-          || TYPE_CODE (type1) == TYPE_CODE_BOOL)
+  else if (TYPE_CODE (type1) == TYPE_CODE_BOOL)
     {
       /* We have two bitstrings to concatenate.  */
-      if (TYPE_CODE (type2) != TYPE_CODE_BITSTRING
-         && TYPE_CODE (type2) != TYPE_CODE_BOOL)
+      if (TYPE_CODE (type2) != TYPE_CODE_BOOL)
        {
-         error (_("Bitstrings or booleans can only be concatenated "
+         error (_("Booleans can only be concatenated "
                   "with other bitstrings or booleans."));
        }
-      error (_("unimplemented support for bitstring/boolean concatenation."));
+      error (_("unimplemented support for boolean concatenation."));
     }
   else
     {
@@ -1403,7 +1346,7 @@ static struct value *
 vector_binop (struct value *val1, struct value *val2, enum exp_opcode op)
 {
   struct value *val, *tmp, *mark;
-  struct type *type1, *type2, *eltype1, *eltype2, *result_type;
+  struct type *type1, *type2, *eltype1, *eltype2;
   int t1_is_vec, t2_is_vec, elsize, i;
   LONGEST low_bound1, high_bound1, low_bound2, high_bound2;
 
This page took 0.027357 seconds and 4 git commands to generate.