]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Add ability to return rvalue reference values from value_ref
authorArtemiy Volkov <artemiyv@acm.org>
Mon, 20 Mar 2017 20:47:41 +0000 (13:47 -0700)
committerKeith Seitz <keiths@redhat.com>
Mon, 20 Mar 2017 20:47:41 +0000 (13:47 -0700)
Parameterize value_ref() by the kind of reference type the value of which
is requested. Change all callers to use the new API.

gdb/ChangeLog

PR gdb/14441
* ada-lang.c (ada_evaluate_subexp): Adhere to the new
value_ref() interface.
* c-valprint.c (c_value_print): Likewise.
* infcall.c (value_arg_coerce): Likewise.
* python/py-value.c (valpy_reference_value): Likewise.
* valops.c (value_cast, value_reinterpret_cast)
(value_dynamic_cast, typecmp): Likewise.
(value_ref): Parameterize by kind of return value reference type.
* value.h (value_ref): Add new parameter "refcode".

gdb/ChangeLog
gdb/ada-lang.c
gdb/c-valprint.c
gdb/infcall.c
gdb/python/py-value.c
gdb/python/py-xmethods.c
gdb/valops.c
gdb/value.h

index 872f661dc53d6093471ff24bd5ed77557f171ab1..0645273ef1ea3886c13c077c010aad2225499ee8 100644 (file)
@@ -1,3 +1,16 @@
+2017-03-20  Artemiy Volkov  <artemiyv@acm.org>
+
+       PR gdb/14441
+       * ada-lang.c (ada_evaluate_subexp): Adhere to the new
+       value_ref() interface.
+       * c-valprint.c (c_value_print): Likewise.
+       * infcall.c (value_arg_coerce): Likewise.
+       * python/py-value.c (valpy_reference_value): Likewise.
+       * valops.c (value_cast, value_reinterpret_cast)
+       (value_dynamic_cast, typecmp): Likewise.
+       (value_ref): Parameterize by kind of return value reference type.
+       * value.h (value_ref): Add new parameter "refcode".
+
 2017-03-20  Artemiy Volkov  <artemiyv@acm.org>
 
        PR gdb/14441
index 753409cdbf582cfdbc66233965bc8fbaac2cf663..9b91e0cc5c1e18097011193e8958946968538d2f 100644 (file)
@@ -10707,7 +10707,7 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
                     should return a ref as it should be valid to ask
                     for its address; so rebuild a ref after coerce.  */
                  arg1 = ada_coerce_ref (arg1);
-                 return value_ref (arg1);
+                 return value_ref (arg1, TYPE_CODE_REF);
                }
            }
 
index 5993195fbe5b4c5b95987b0dd7414d1a94e6f6ed..d29b20ebda9be720e4534550fab1f0239e71c8cd 100644 (file)
@@ -606,10 +606,14 @@ c_value_print (struct value *val, struct ui_file *stream,
       else if (options->objectprint
               && (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_STRUCT))
        {
-         int is_ref = TYPE_CODE (type) == TYPE_CODE_REF;
+         int is_ref = TYPE_IS_REFERENCE (type);
+         enum type_code refcode = TYPE_CODE_UNDEF;
 
          if (is_ref)
-           val = value_addr (val);
+           {
+             val = value_addr (val);
+             refcode = TYPE_CODE (type);
+           }
 
          /* Pointer to class, check real type of object.  */
          fprintf_filtered (stream, "(");
@@ -635,7 +639,7 @@ c_value_print (struct value *val, struct ui_file *stream,
 
          if (is_ref)
            {
-             val = value_ref (value_ind (val));
+             val = value_ref (value_ind (val), refcode);
              type = value_type (val);
            }
 
index f55acb5c27e27a1a625c1114ee86b499a34de0b9..713738ee8b64126e2f7ac7a2aa988b773e05feef 100644 (file)
@@ -168,7 +168,7 @@ value_arg_coerce (struct gdbarch *gdbarch, struct value *arg,
           if the value was not previously in memory - in some cases
           we should clearly be allowing this, but how?  */
        new_value = value_cast (TYPE_TARGET_TYPE (type), arg);
-       new_value = value_ref (new_value);
+       new_value = value_ref (new_value, TYPE_CODE (type));
        return new_value;
       }
     case TYPE_CODE_INT:
index a56e555d47f479b1b5419551118b4974dc18def5..c848f0f65d57220977481c54fc26812f5bcf2721 100644 (file)
@@ -248,7 +248,7 @@ valpy_reference_value (PyObject *self, PyObject *args)
       scoped_value_mark free_values;
 
       self_val = ((value_object *) self)->value;
-      result = value_to_value_object (value_ref (self_val));
+      result = value_to_value_object (value_ref (self_val, TYPE_CODE_REF));
     }
   CATCH (except, RETURN_MASK_ALL)
     {
index 8a9bb9b1c96d0b34991a3e911bdaf8603459cc1c..d01488fc74430c187a2cd49ceca178455fb64841 100644 (file)
@@ -552,9 +552,10 @@ gdbpy_invoke_xmethod (const struct extension_language_defn *extlang,
       if (!types_equal (obj_type, this_ptr))
        obj = value_cast (this_ptr, obj);
     }
-  else if (TYPE_CODE (obj_type) == TYPE_CODE_REF)
+  else if (TYPE_IS_REFERENCE (obj_type))
     {
-      struct type *this_ref = lookup_lvalue_reference_type (this_type);
+      struct type *this_ref
+       = lookup_reference_type (this_type, TYPE_CODE (obj_type));
 
       if (!types_equal (obj_type, this_ref))
        obj = value_cast (this_ref, obj);
index d218c923d2f46925a873b25292c6cf50a53e1b07..21f4008b9017f5fe080aa7b05995d376cbd91fd0 100644 (file)
@@ -373,7 +373,7 @@ value_cast (struct type *type, struct value *arg2)
       struct type *dereftype = check_typedef (TYPE_TARGET_TYPE (t1));
       struct value *val =  value_cast (dereftype, arg2);
 
-      return value_ref (val); 
+      return value_ref (val, TYPE_CODE (t1));
     }
 
   code2 = TYPE_CODE (check_typedef (value_type (arg2)));
@@ -623,7 +623,8 @@ value_reinterpret_cast (struct type *type, struct value *arg)
     error (_("Invalid reinterpret_cast"));
 
   if (is_ref)
-    result = value_cast (type, value_ref (value_ind (result)));
+    result = value_cast (type, value_ref (value_ind (result),
+                                          TYPE_CODE (type)));
 
   return result;
 }
@@ -819,7 +820,9 @@ value_dynamic_cast (struct type *type, struct value *arg)
                                arg_type,
                                &result) == 1)
        return value_cast (type,
-                          is_ref ? value_ref (result) : value_addr (result));
+                          is_ref
+                          ? value_ref (result, TYPE_CODE (resolved_type))
+                          : value_addr (result));
     }
 
   /* The second dynamic check specified in 5.2.7.  */
@@ -831,7 +834,9 @@ value_dynamic_cast (struct type *type, struct value *arg)
                               value_address (tem), tem,
                               rtti_type, &result) == 1)
     return value_cast (type,
-                      is_ref ? value_ref (result) : value_addr (result));
+                      is_ref
+                      ? value_ref (result, TYPE_CODE (resolved_type))
+                      : value_addr (result));
 
   if (TYPE_CODE (resolved_type) == TYPE_CODE_PTR)
     return value_zero (type, not_lval);
@@ -1527,16 +1532,20 @@ value_addr (struct value *arg1)
    contents.  */
 
 struct value *
-value_ref (struct value *arg1)
+value_ref (struct value *arg1, enum type_code refcode)
 {
   struct value *arg2;
   struct type *type = check_typedef (value_type (arg1));
 
-  if (TYPE_CODE (type) == TYPE_CODE_REF)
+  gdb_assert (refcode == TYPE_CODE_REF || refcode == TYPE_CODE_RVALUE_REF);
+
+  if ((TYPE_CODE (type) == TYPE_CODE_REF
+       || TYPE_CODE (type) == TYPE_CODE_RVALUE_REF)
+      && TYPE_CODE (type) == refcode)
     return arg1;
 
   arg2 = value_addr (arg1);
-  deprecated_set_value_type (arg2, lookup_lvalue_reference_type (type));
+  deprecated_set_value_type (arg2, lookup_reference_type (type, refcode));
   return arg2;
 }
 
@@ -1743,7 +1752,7 @@ typecmp (int staticp, int varargs, int nargs,
          if (TYPE_CODE (tt2) == TYPE_CODE_ARRAY)
            t2[i] = value_coerce_array (t2[i]);
          else
-           t2[i] = value_ref (t2[i]);
+           t2[i] = value_ref (t2[i], TYPE_CODE (tt1));
          continue;
        }
 
index c57ea7979e05d6118b5b3478c96602b0ecececee..a1d1609777f0a7a85b2b140c76d068cb791780ef 100644 (file)
@@ -775,7 +775,7 @@ extern struct value *value_ind (struct value *arg1);
 
 extern struct value *value_addr (struct value *arg1);
 
-extern struct value *value_ref (struct value *arg1);
+extern struct value *value_ref (struct value *arg1, enum type_code refcode);
 
 extern struct value *value_assign (struct value *toval,
                                   struct value *fromval);