]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Change {lookup,make}_reference_type API
authorArtemiy Volkov <artemiyv@acm.org>
Mon, 20 Mar 2017 20:47:39 +0000 (13:47 -0700)
committerKeith Seitz <keiths@redhat.com>
Mon, 20 Mar 2017 20:47:39 +0000 (13:47 -0700)
Parameterize lookup_reference_type() and make_reference_type() by the kind of
reference type we want to look up. Create two wrapper functions
lookup_{lvalue,rvalue}_reference_type() for lookup_reference_type() to simplify
the API. Change all callers to use the new API.

gdb/Changelog

PR gdb/14441
* dwarf2read.c (read_tag_reference_type): Use
lookup_lvalue_reference_type() instead of lookup_reference_type().
* eval.c (evaluate_subexp_standard): Likewise.
* f-exp.y: Likewise.
* gdbtypes.c (make_reference_type, lookup_reference_type):
Generalize with rvalue reference types.
(lookup_lvalue_reference_type, lookup_rvalue_reference_type): New
convenience wrappers for lookup_reference_type().
* gdbtypes.h (make_reference_type, lookup_reference_type): Add a
reference kind parameter.
(lookup_lvalue_reference_type, lookup_rvalue_reference_type): Add
wrappers for lookup_reference_type().
* guile/scm-type.c (gdbscm_type_reference): Use
lookup_lvalue_reference_type() instead of lookup_reference_type().
* guile/scm-value.c (gdbscm_value_dynamic_type): Likewise.
* parse.c (follow_types): Likewise.
* python/py-type.c (typy_reference, typy_lookup_type): Likewise.
* python/py-value.c (valpy_get_dynamic_type, valpy_getitem):
Likewise.
* python/py-xmethods.c (gdbpy_get_xmethod_result_type)
(gdbpy_invoke_xmethod): Likewise.
* stabsread.c: Provide extra argument to make_reference_type()
call.
* valops.c (value_ref, value_rtti_indirect_type): Use
lookup_lvalue_reference_type() instead of lookup_reference_type().

14 files changed:
gdb/ChangeLog
gdb/dwarf2read.c
gdb/eval.c
gdb/f-exp.y
gdb/gdbtypes.c
gdb/gdbtypes.h
gdb/guile/scm-type.c
gdb/guile/scm-value.c
gdb/parse.c
gdb/python/py-type.c
gdb/python/py-value.c
gdb/python/py-xmethods.c
gdb/stabsread.c
gdb/valops.c

index ff09df0f55f60c9f56e7125a4667bc69bbd18cac..872f661dc53d6093471ff24bd5ed77557f171ab1 100644 (file)
@@ -1,3 +1,32 @@
+2017-03-20  Artemiy Volkov  <artemiyv@acm.org>
+
+       PR gdb/14441
+       * dwarf2read.c (read_tag_reference_type): Use
+       lookup_lvalue_reference_type() instead of lookup_reference_type().
+       * eval.c (evaluate_subexp_standard): Likewise.
+       * f-exp.y: Likewise.
+       * gdbtypes.c (make_reference_type, lookup_reference_type):
+       Generalize with rvalue reference types.
+       (lookup_lvalue_reference_type, lookup_rvalue_reference_type): New
+       convenience wrappers for lookup_reference_type().
+       * gdbtypes.h (make_reference_type, lookup_reference_type): Add a
+       reference kind parameter.
+       (lookup_lvalue_reference_type, lookup_rvalue_reference_type): Add
+       wrappers for lookup_reference_type().
+       * guile/scm-type.c (gdbscm_type_reference): Use
+       lookup_lvalue_reference_type() instead of lookup_reference_type().
+       * guile/scm-value.c (gdbscm_value_dynamic_type): Likewise.
+       * parse.c (follow_types): Likewise.
+       * python/py-type.c (typy_reference, typy_lookup_type): Likewise.
+       * python/py-value.c (valpy_get_dynamic_type, valpy_getitem):
+       Likewise.
+       * python/py-xmethods.c (gdbpy_get_xmethod_result_type)
+       (gdbpy_invoke_xmethod): Likewise.
+       * stabsread.c: Provide extra argument to make_reference_type()
+       call.
+       * valops.c (value_ref, value_rtti_indirect_type): Use
+       lookup_lvalue_reference_type() instead of lookup_reference_type().
+
 2017-03-20  Artemiy Volkov  <artemiyv@acm.org>
 
        PR gdb/14441
index da70884c48496053536109da8754b2c32cd36a05..3fb843ac9ef009255989a2f2ca4d0874c6b5d727 100644 (file)
@@ -14584,7 +14584,7 @@ read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu)
   if (type)
     return type;
 
-  type = lookup_reference_type (target_type);
+  type = lookup_lvalue_reference_type (target_type);
   attr = dwarf2_attr (die, DW_AT_byte_size, cu);
   if (attr)
     {
index 76d7f731a72723521303ac8aaeda3f0935676c59..61d8d195b18452642620b1db27f8740f05125bc3 100644 (file)
@@ -2771,7 +2771,7 @@ evaluate_subexp_standard (struct type *expect_type,
 
              if (TYPE_CODE (check_typedef (type)) != TYPE_CODE_REF)
                {
-                 type = lookup_reference_type (type);
+                 type = lookup_lvalue_reference_type (type);
                  result = allocate_value (type);
                }
            }
index a791d2caf9fdacd6e4269c1e72b3a7ec8e402237..49d797d7d45ed6458ad4993ec201141985dffcd7 100644 (file)
@@ -513,7 +513,7 @@ ptype       :       typebase
                        follow_type = lookup_pointer_type (follow_type);
                        break;
                      case tp_reference:
-                       follow_type = lookup_reference_type (follow_type);
+                       follow_type = lookup_lvalue_reference_type (follow_type);
                        break;
                      case tp_array:
                        array_size = pop_type_int ();
index 5e5db2776b16424491da44427a104239d64fea9a..60cef682aa4127cb82a93b59be9a86c97fe6bf61 100644 (file)
@@ -384,15 +384,21 @@ lookup_pointer_type (struct type *type)
 /* Lookup a C++ `reference' to a type TYPE.  TYPEPTR, if nonzero,
    points to a pointer to memory where the reference type should be
    stored.  If *TYPEPTR is zero, update it to point to the reference
-   type we return.  We allocate new memory if needed.  */
+   type we return.  We allocate new memory if needed. REFCODE denotes
+   the kind of reference type to lookup (lvalue or rvalue reference).  */
 
 struct type *
-make_reference_type (struct type *type, struct type **typeptr)
+make_reference_type (struct type *type, struct type **typeptr,
+                      enum type_code refcode)
 {
   struct type *ntype;  /* New type */
+  struct type **reftype;
   struct type *chain;
 
-  ntype = TYPE_REFERENCE_TYPE (type);
+  gdb_assert (refcode == TYPE_CODE_REF || refcode == TYPE_CODE_RVALUE_REF);
+
+  ntype = (refcode == TYPE_CODE_REF ? TYPE_REFERENCE_TYPE (type)
+           : TYPE_RVALUE_REFERENCE_TYPE (type));
 
   if (ntype)
     {
@@ -421,7 +427,10 @@ make_reference_type (struct type *type, struct type **typeptr)
     }
 
   TYPE_TARGET_TYPE (ntype) = type;
-  TYPE_REFERENCE_TYPE (type) = ntype;
+  reftype = (refcode == TYPE_CODE_REF ? &TYPE_REFERENCE_TYPE (type)
+             : &TYPE_RVALUE_REFERENCE_TYPE (type));
+
+  *reftype = ntype;
 
   /* FIXME!  Assume the machine has only one representation for
      references, and that it matches the (only) representation for
@@ -429,10 +438,9 @@ make_reference_type (struct type *type, struct type **typeptr)
 
   TYPE_LENGTH (ntype) =
     gdbarch_ptr_bit (get_type_arch (type)) / TARGET_CHAR_BIT;
-  TYPE_CODE (ntype) = TYPE_CODE_REF;
+  TYPE_CODE (ntype) = refcode;
 
-  if (!TYPE_REFERENCE_TYPE (type))     /* Remember it, if don't have one.  */
-    TYPE_REFERENCE_TYPE (type) = ntype;
+  *reftype = ntype;
 
   /* Update the length of all the other variants of this type.  */
   chain = TYPE_CHAIN (ntype);
@@ -449,9 +457,25 @@ make_reference_type (struct type *type, struct type **typeptr)
    details.  */
 
 struct type *
-lookup_reference_type (struct type *type)
+lookup_reference_type (struct type *type, enum type_code refcode)
+{
+  return make_reference_type (type, (struct type **) 0, refcode);
+}
+
+/* Lookup the lvalue reference type for the type TYPE.  */
+
+struct type *
+lookup_lvalue_reference_type (struct type *type)
+{
+  return lookup_reference_type (type, TYPE_CODE_REF);
+}
+
+/* Lookup the rvalue reference type for the type TYPE.  */
+
+struct type *
+lookup_rvalue_reference_type (struct type *type)
 {
-  return make_reference_type (type, (struct type **) 0);
+  return lookup_reference_type (type, TYPE_CODE_RVALUE_REF);
 }
 
 /* Lookup a function type that returns type TYPE.  TYPEPTR, if
index 7d107fae8236374e7f3b7f28583bbb9f3972b7fd..4abeaf3286d699f11a1e0d0629789e96692dc44e 100644 (file)
@@ -1714,9 +1714,13 @@ extern void append_flags_type_flag (struct type *type, int bitpos,
 extern void make_vector_type (struct type *array_type);
 extern struct type *init_vector_type (struct type *elt_type, int n);
 
-extern struct type *lookup_reference_type (struct type *);
+extern struct type *lookup_reference_type (struct type *, enum type_code);
+extern struct type *lookup_lvalue_reference_type (struct type *);
+extern struct type *lookup_rvalue_reference_type (struct type *);
 
-extern struct type *make_reference_type (struct type *, struct type **);
+
+extern struct type *make_reference_type (struct type *, struct type **,
+                                         enum type_code);
 
 extern struct type *make_cv_type (int, int, struct type *, struct type **);
 
index b3036adec94d85063dc3e7aaa3e726f202dfa811..704be886d6a06a52b0e8f6eb38d057547ad15e1c 100644 (file)
@@ -845,7 +845,7 @@ gdbscm_type_reference (SCM self)
 
   TRY
     {
-      type = lookup_reference_type (type);
+      type = lookup_lvalue_reference_type (type);
     }
   CATCH (except, RETURN_MASK_ALL)
     {
index f81a90cb0d9d91a7306ecc7213ff968a3299c065..f63103227cef7b35d1c9813708925f945b59d2fd 100644 (file)
@@ -591,7 +591,7 @@ gdbscm_value_dynamic_type (SCM self)
              if (was_pointer)
                type = lookup_pointer_type (type);
              else
-               type = lookup_reference_type (type);
+               type = lookup_lvalue_reference_type (type);
            }
        }
       else if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
index e6f6805bfa10fbe2dd2371c80ace86818cb3ef4e..23c636f6c7e7db6427dbf246939ce5095efc2a89 100644 (file)
@@ -1686,7 +1686,7 @@ follow_types (struct type *follow_type)
        make_addr_space = 0;
        break;
       case tp_reference:
-       follow_type = lookup_reference_type (follow_type);
+       follow_type = lookup_lvalue_reference_type (follow_type);
        if (make_const)
          follow_type = make_cv_type (make_const, 
                                      TYPE_VOLATILE (follow_type), 
index d3506ca21d87d66873c18dd1a7d11d13c3ce3700..c4d5917d84bafef8e385b4ee1974d390acc1a133 100644 (file)
@@ -626,7 +626,7 @@ typy_reference (PyObject *self, PyObject *args)
 
   TRY
     {
-      type = lookup_reference_type (type);
+      type = lookup_lvalue_reference_type (type);
     }
   CATCH (except, RETURN_MASK_ALL)
     {
@@ -786,7 +786,7 @@ typy_lookup_type (struct demangle_component *demangled,
          switch (demangled_type)
            {
            case DEMANGLE_COMPONENT_REFERENCE:
-             rtype =  lookup_reference_type (type);
+             rtype = lookup_lvalue_reference_type (type);
              break;
            case DEMANGLE_COMPONENT_POINTER:
              rtype = lookup_pointer_type (type);
index 124d398013926ce3bd9e9dfbf0cf2fc54a3709a8..a56e555d47f479b1b5419551118b4974dc18def5 100644 (file)
@@ -369,7 +369,7 @@ valpy_get_dynamic_type (PyObject *self, void *closure)
              if (was_pointer)
                type = lookup_pointer_type (type);
              else
-               type = lookup_reference_type (type);
+               type = lookup_lvalue_reference_type (type);
            }
        }
       else if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
@@ -801,7 +801,8 @@ valpy_getitem (PyObject *self, PyObject *key)
          if (TYPE_CODE (val_type) == TYPE_CODE_PTR)
            res_val = value_cast (lookup_pointer_type (base_class_type), tmp);
          else if (TYPE_CODE (val_type) == TYPE_CODE_REF)
-           res_val = value_cast (lookup_reference_type (base_class_type), tmp);
+           res_val = value_cast (lookup_lvalue_reference_type (base_class_type),
+                                 tmp);
          else
            res_val = value_cast (base_class_type, tmp);
        }
index d293c71b8cb40292a133add383327b68748df46e..8a9bb9b1c96d0b34991a3e911bdaf8603459cc1c 100644 (file)
@@ -466,7 +466,7 @@ gdbpy_get_xmethod_result_type (const struct extension_language_defn *extlang,
     }
   else if (TYPE_CODE (obj_type) == TYPE_CODE_REF)
     {
-      struct type *this_ref = lookup_reference_type (this_type);
+      struct type *this_ref = lookup_lvalue_reference_type (this_type);
 
       if (!types_equal (obj_type, this_ref))
        obj = value_cast (this_ref, obj);
@@ -554,7 +554,7 @@ gdbpy_invoke_xmethod (const struct extension_language_defn *extlang,
     }
   else if (TYPE_CODE (obj_type) == TYPE_CODE_REF)
     {
-      struct type *this_ref = lookup_reference_type (this_type);
+      struct type *this_ref = lookup_lvalue_reference_type (this_type);
 
       if (!types_equal (obj_type, this_ref))
        obj = value_cast (this_ref, obj);
index da7241a64288a2a2d7bd2ff0d15d17f7c124bc3d..14122021c63863ad3b096a0c823f3cfd0e21d161 100644 (file)
@@ -1794,7 +1794,8 @@ again:
 
     case '&':                  /* Reference to another type */
       type1 = read_type (pp, objfile);
-      type = make_reference_type (type1, dbx_lookup_type (typenums, objfile));
+      type = make_reference_type (type1, dbx_lookup_type (typenums, objfile),
+                                  TYPE_CODE_REF);
       break;
 
     case 'f':                  /* Function returning another type */
index fa25ff97382c99d92a12e3293be2faefedcd7bfe..d218c923d2f46925a873b25292c6cf50a53e1b07 100644 (file)
@@ -1536,7 +1536,7 @@ value_ref (struct value *arg1)
     return arg1;
 
   arg2 = value_addr (arg1);
-  deprecated_set_value_type (arg2, lookup_reference_type (type));
+  deprecated_set_value_type (arg2, lookup_lvalue_reference_type (type));
   return arg2;
 }
 
@@ -3639,7 +3639,7 @@ value_rtti_indirect_type (struct value *v, int *full,
       real_type = make_cv_type (TYPE_CONST (target_type),
                                TYPE_VOLATILE (target_type), real_type, NULL);
       if (TYPE_CODE (type) == TYPE_CODE_REF)
-        real_type = lookup_reference_type (real_type);
+        real_type = lookup_lvalue_reference_type (real_type);
       else if (TYPE_CODE (type) == TYPE_CODE_PTR)
         real_type = lookup_pointer_type (real_type);
       else