From patchwork Mon Dec 21 01:31:12 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Artemiy Volkov X-Patchwork-Id: 10077 Received: (qmail 93387 invoked by alias); 20 Dec 2015 22:35:18 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 93181 invoked by uid 89); 20 Dec 2015 22:35:16 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=421, 7, 4499, 4217, 6367 X-HELO: mail-lb0-f196.google.com Received: from mail-lb0-f196.google.com (HELO mail-lb0-f196.google.com) (209.85.217.196) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Sun, 20 Dec 2015 22:35:14 +0000 Received: by mail-lb0-f196.google.com with SMTP id ti8so1487641lbb.3 for ; Sun, 20 Dec 2015 14:35:13 -0800 (PST) X-Received: by 10.112.155.167 with SMTP id vx7mr5181963lbb.9.1450650910624; Sun, 20 Dec 2015 14:35:10 -0800 (PST) Received: from localhost.localdomain ([37.204.1.155]) by smtp.gmail.com with ESMTPSA id m75sm4420435lfg.15.2015.12.20.14.35.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 20 Dec 2015 14:35:09 -0800 (PST) From: Artemiy Volkov To: gdb-patches@sourceware.org Cc: Artemiy Volkov Subject: [PATCH 02/11] [PR gdb/14441] gdb: gdbtypes: change {lookup, make}_reference_type() API Date: Mon, 21 Dec 2015 04:31:12 +0300 Message-Id: <1450661481-31178-3-git-send-email-artemiyv@acm.org> In-Reply-To: <1450661481-31178-1-git-send-email-artemiyv@acm.org> References: <1450661481-31178-1-git-send-email-artemiyv@acm.org> X-IsSubscribed: yes 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. ./Changelog: 2015-12-19 Artemiy Volkov * gdb/dwarf2read.c (read_tag_reference_type): Use lookup_lvalue_reference_type() instead of lookup_reference_type(). * gdb/eval.c (evaluate_subexp_standard): Likewise. * gdb/f-exp.y: Likewise. * gdb/gdbtypes.c (make_reference_type): Generalize with rvalue reference types. (lookup_reference_type): Generalize with rvalue reference types. (lookup_lvalue_reference_type): New convenience wrapper for lookup_reference_type(). (lookup_rvalue_reference_type): Likewise. * gdb/gdbtypes.h: Change interface for {make,lookup}_{rvalue,}_reference_type(). * gdb/guile/scm-type.c (gdbscm_type_reference): Use lookup_lvalue_reference_type() instead of lookup_reference_type(). * gdb/guile/scm-value.c (gdbscm_value_dynamic_type): Likewise. * gdb/parse.c (follow_types): Likewise. * gdb/python/py-type.c (typy_reference): Likewise. (typy_lookup_type): Likewise. * gdb/python/py-value.c (valpy_get_dynamic_type): Likewise. (valpy_getitem): Likewise. * gdb/python/py-xmethods.c (gdbpy_get_xmethod_result_type): Likewise. (gdbpy_invoke_xmethod): Likewise. * gdb/stabsread.c: Provide extra argument to make_reference_type() call. * gdb/valops.c (value_ref): Use lookup_lvalue_reference_type() instead of lookup_reference_type(). (value_rtti_indirect_type): Likewise. --- gdb/dwarf2read.c | 2 +- gdb/eval.c | 2 +- gdb/f-exp.y | 2 +- gdb/gdbtypes.c | 45 ++++++++++++++++++++++++++++++++++----------- gdb/gdbtypes.h | 8 ++++++-- gdb/guile/scm-type.c | 2 +- gdb/guile/scm-value.c | 2 +- gdb/parse.c | 2 +- gdb/python/py-type.c | 4 ++-- gdb/python/py-value.c | 4 ++-- gdb/python/py-xmethods.c | 4 ++-- gdb/stabsread.c | 2 +- gdb/valops.c | 4 ++-- 13 files changed, 55 insertions(+), 28 deletions(-) diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index 4881d72..5c3d42c 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -14337,7 +14337,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) { diff --git a/gdb/eval.c b/gdb/eval.c index 84e2e34..3d408e4 100644 --- a/gdb/eval.c +++ b/gdb/eval.c @@ -2789,7 +2789,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); } } diff --git a/gdb/f-exp.y b/gdb/f-exp.y index 56629dc..c57aec1 100644 --- a/gdb/f-exp.y +++ b/gdb/f-exp.y @@ -567,7 +567,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 (); diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c index b9850cf..49e5bf2 100644 --- a/gdb/gdbtypes.c +++ b/gdb/gdbtypes.c @@ -382,17 +382,23 @@ 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. */ + 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. + REFCODE denotes the kind of reference type to lookup (lvalue or rvalue + reference). We allocate new memory if needed. */ 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,11 @@ 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)); + + if(!*reftype) + *reftype = ntype; /* FIXME! Assume the machine has only one representation for references, and that it matches the (only) representation for @@ -429,10 +439,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 +458,23 @@ 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); +} + +/* Separate convenience functions for lvalue and rvalue references. */ + +struct type * +lookup_lvalue_reference_type (struct type *type) +{ + return lookup_reference_type (type, TYPE_CODE_REF); +} + +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 diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h index 2ef38ca..993cceb 100644 --- a/gdb/gdbtypes.h +++ b/gdb/gdbtypes.h @@ -1725,9 +1725,13 @@ extern void append_flags_type_flag (struct type *type, int bitpos, char *name); 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 **); diff --git a/gdb/guile/scm-type.c b/gdb/guile/scm-type.c index 642ce15..0d4aa63 100644 --- a/gdb/guile/scm-type.c +++ b/gdb/guile/scm-type.c @@ -854,7 +854,7 @@ gdbscm_type_reference (SCM self) TRY { - type = lookup_reference_type (type); + type = lookup_lvalue_reference_type (type); } CATCH (except, RETURN_MASK_ALL) { diff --git a/gdb/guile/scm-value.c b/gdb/guile/scm-value.c index 851d8a7..638876f 100644 --- a/gdb/guile/scm-value.c +++ b/gdb/guile/scm-value.c @@ -601,7 +601,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) diff --git a/gdb/parse.c b/gdb/parse.c index a24c52a..ef45fac 100644 --- a/gdb/parse.c +++ b/gdb/parse.c @@ -1695,7 +1695,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), diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c index ef4e719..676ab63 100644 --- a/gdb/python/py-type.c +++ b/gdb/python/py-type.c @@ -667,7 +667,7 @@ typy_reference (PyObject *self, PyObject *args) TRY { - type = lookup_reference_type (type); + type = lookup_lvalue_reference_type (type); } CATCH (except, RETURN_MASK_ALL) { @@ -827,7 +827,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); diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c index 140aaf5..5d30a0f 100644 --- a/gdb/python/py-value.c +++ b/gdb/python/py-value.c @@ -376,7 +376,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) @@ -766,7 +766,7 @@ 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); } diff --git a/gdb/python/py-xmethods.c b/gdb/python/py-xmethods.c index f927fe9..0cda83d 100644 --- a/gdb/python/py-xmethods.c +++ b/gdb/python/py-xmethods.c @@ -550,7 +550,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); @@ -636,7 +636,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); diff --git a/gdb/stabsread.c b/gdb/stabsread.c index bc43566..285394f 100644 --- a/gdb/stabsread.c +++ b/gdb/stabsread.c @@ -1772,7 +1772,7 @@ 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 */ diff --git a/gdb/valops.c b/gdb/valops.c index 5e5f685..1bf1d3d 100644 --- a/gdb/valops.c +++ b/gdb/valops.c @@ -1508,7 +1508,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; } @@ -3616,7 +3616,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