* gdbtypes.c (create_string_type): Receive character type as argument.
[deliverable/binutils-gdb.git] / gdb / valarith.c
index 48f2e95513d7799a4209e7f7700d812cb397c020..6f08705b7577eb8ba388299b67a5186212a3094e 100644 (file)
@@ -233,11 +233,7 @@ value_subscripted_rvalue (struct value *array, struct value *idx, int lowerbound
     memcpy (value_contents_writeable (v),
            value_contents (array) + elt_offs, elt_size);
 
-  if (VALUE_LVAL (array) == lval_internalvar)
-    VALUE_LVAL (v) = lval_internalvar_component;
-  else
-    VALUE_LVAL (v) = VALUE_LVAL (array);
-  VALUE_ADDRESS (v) = VALUE_ADDRESS (array);
+  set_value_component_location (v, array);
   VALUE_REGNUM (v) = VALUE_REGNUM (array);
   VALUE_FRAME_ID (v) = VALUE_FRAME_ID (array);
   set_value_offset (v, value_offset (array) + elt_offs);
@@ -277,11 +273,7 @@ value_bitstring_subscript (struct type *type,
 
   set_value_bitpos (v, bit_index);
   set_value_bitsize (v, 1);
-
-  VALUE_LVAL (v) = VALUE_LVAL (bitstring);
-  if (VALUE_LVAL (bitstring) == lval_internalvar)
-    VALUE_LVAL (v) = lval_internalvar_component;
-  VALUE_ADDRESS (v) = VALUE_ADDRESS (bitstring);
+  set_value_component_location (v, bitstring);
   VALUE_FRAME_ID (v) = VALUE_FRAME_ID (bitstring);
 
   set_value_offset (v, offset + value_offset (bitstring));
@@ -632,6 +624,7 @@ value_concat (struct value *arg1, struct value *arg2)
   char inchar;
   struct type *type1 = check_typedef (value_type (arg1));
   struct type *type2 = check_typedef (value_type (arg2));
+  struct type *char_type;
 
   /* First figure out if we are dealing with two values to be concatenated
      or a repeat count and a value to be repeated.  INVAL1 is set to the
@@ -667,6 +660,7 @@ value_concat (struct value *arg1, struct value *arg2)
          ptr = (char *) alloca (count * inval2len);
          if (TYPE_CODE (type2) == TYPE_CODE_CHAR)
            {
+             char_type = type2;
              inchar = (char) unpack_long (type2,
                                           value_contents (inval2));
              for (idx = 0; idx < count; idx++)
@@ -676,13 +670,14 @@ value_concat (struct value *arg1, struct value *arg2)
            }
          else
            {
+             char_type = TYPE_TARGET_TYPE (type2);
              for (idx = 0; idx < count; idx++)
                {
                  memcpy (ptr + (idx * inval2len), value_contents (inval2),
                          inval2len);
                }
            }
-         outval = value_string (ptr, count * inval2len);
+         outval = value_string (ptr, count * inval2len, char_type);
        }
       else if (TYPE_CODE (type2) == TYPE_CODE_BITSTRING
               || TYPE_CODE (type2) == TYPE_CODE_BOOL)
@@ -708,10 +703,12 @@ value_concat (struct value *arg1, struct value *arg2)
       ptr = (char *) alloca (inval1len + inval2len);
       if (TYPE_CODE (type1) == TYPE_CODE_CHAR)
        {
+         char_type = type1;
          *ptr = (char) unpack_long (type1, value_contents (inval1));
        }
       else
        {
+         char_type = TYPE_TARGET_TYPE (type1);
          memcpy (ptr, value_contents (inval1), inval1len);
        }
       if (TYPE_CODE (type2) == TYPE_CODE_CHAR)
@@ -723,7 +720,7 @@ value_concat (struct value *arg1, struct value *arg2)
        {
          memcpy (ptr + inval1len, value_contents (inval2), inval2len);
        }
-      outval = value_string (ptr, inval1len + inval2len);
+      outval = value_string (ptr, inval1len + inval2len, char_type);
     }
   else if (TYPE_CODE (type1) == TYPE_CODE_BITSTRING
           || TYPE_CODE (type1) == TYPE_CODE_BOOL)
@@ -895,6 +892,19 @@ value_binop (struct value *arg1, struct value *arg2, enum exp_opcode op)
       gdb_byte v1[16], v2[16];
       gdb_byte v[16];
 
+      /* If only one type is decimal float, use its type.
+        Otherwise use the bigger type.  */
+      if (TYPE_CODE (type1) != TYPE_CODE_DECFLOAT)
+       result_type = type2;
+      else if (TYPE_CODE (type2) != TYPE_CODE_DECFLOAT)
+       result_type = type1;
+      else if (TYPE_LENGTH (type2) > TYPE_LENGTH (type1))
+       result_type = type2;
+      else
+       result_type = type1;
+
+      len_v = TYPE_LENGTH (result_type);
+
       value_args_as_decimal (arg1, arg2, v1, &len_v1, v2, &len_v2);
 
       switch (op)
@@ -904,24 +914,13 @@ value_binop (struct value *arg1, struct value *arg2, enum exp_opcode op)
        case BINOP_MUL:
        case BINOP_DIV:
        case BINOP_EXP:
-         decimal_binop (op, v1, len_v1, v2, len_v2, v, &len_v);
+         decimal_binop (op, v1, len_v1, v2, len_v2, v, len_v);
          break;
 
        default:
          error (_("Operation not valid for decimal floating point number."));
        }
 
-      /* If only one type is decimal float, use its type.
-        Otherwise use the bigger type.  */
-      if (TYPE_CODE (type1) != TYPE_CODE_DECFLOAT)
-       result_type = type2;
-      else if (TYPE_CODE (type2) != TYPE_CODE_DECFLOAT)
-       result_type = type1;
-      else if (TYPE_LENGTH (type2) > TYPE_LENGTH (type1))
-       result_type = type2;
-      else
-       result_type = type1;
-
       val = value_from_decfloat (result_type, v);
     }
   else if (TYPE_CODE (type1) == TYPE_CODE_FLT
This page took 0.025154 seconds and 4 git commands to generate.