aboutsummaryrefslogtreecommitdiff
path: root/gdb/valops.c
diff options
context:
space:
mode:
authorArtemiy Volkov <artemiyv@acm.org>2017-03-20 13:47:54 -0700
committerKeith Seitz <keiths@redhat.com>2017-03-20 13:47:54 -0700
commitaa0061181ab00081e9907447561e589d6edee9f2 (patch)
treeed4d550dc5a47158d2582c25dd51fd6658f61fcc /gdb/valops.c
parent3fcf899da106890f3948093c2424f9dff67d6fe0 (diff)
Convert lvalue reference type check to general reference type check
In almost all contexts (except for overload resolution rules and expression semantics), lvalue and rvalue references are equivalent. That means that in all but these cases we can replace a TYPE_CODE_REF check to a TYPE_IS_REFERENCE check and, for switch statements, add a case label for a rvalue reference type next to a case label for an lvalue reference type. This patch does exactly that. gdb/ChangeLog PR gdb/14441 * aarch64-tdep.c (aarch64_type_align) (aarch64_extract_return_value, aarch64_store_return_value): Change lvalue reference type checks to general reference type checks. * amd64-tdep.c (amd64_classify): Likewise. * amd64-windows-tdep.c (amd64_windows_passed_by_integer_register): Likewise. * arm-tdep.c (arm_type_align, arm_extract_return_value) (arm_store_return_value): Likewise. * ax-gdb.c (gen_fetch, gen_cast): Likewise. * c-typeprint.c (c_print_type): Likewise. * c-varobj.c (adjust_value_for_child_access, c_value_of_variable) (cplus_number_of_children, cplus_describe_child): Likewise. * compile/compile-c-symbols.c (generate_vla_size): Likewise. * completer.c (expression_completer): Likewise. * cp-support.c (make_symbol_overload_list_adl_namespace): Likewise. * darwin-nat-info.c (info_mach_region_command): Likewise. * dwarf2loc.c (entry_data_value_coerce_ref) (value_of_dwarf_reg_entry): Likewise. * eval.c (ptrmath_type_p, evaluate_subexp_standard) (evaluate_subexp_for_address, evaluate_subexp_for_sizeof): Likewise. * findvar.c (extract_typed_address, store_typed_address): Likewise. * gdbtypes.c (rank_one_type): Likewise. * hppa-tdep.c (hppa64_integral_or_pointer_p): Likewise. * infcall.c (value_arg_coerce): Likewise. * language.c (pointer_type): Likewise. * m32c-tdep.c (m32c_reg_arg_type, m32c_m16c_address_to_pointer): Likewise. * m88k-tdep.c (m88k_integral_or_pointer_p): Likewise. * mn10300-tdep.c (mn10300_type_align): Likewise. * msp430-tdep.c (msp430_push_dummy_call): Likewise. * ppc-sysv-tdep.c (do_ppc_sysv_return_value) (ppc64_sysv_abi_push_param, ppc64_sysv_abi_return_value): Likewise. * printcmd.c (print_formatted, x_command): Likewise. * python/py-type.c (typy_get_composite, typy_template_argument): Likewise. * python/py-value.c (valpy_referenced_value) (valpy_get_dynamic_type, value_has_field): Likewise. * s390-linux-tdep.c (s390_function_arg_integer): Likewise. * sparc-tdep.c (sparc_integral_or_pointer_p): Likewise. * sparc64-tdep.c (sparc64_integral_or_pointer_p): Likewise. * spu-tdep.c (spu_scalar_value_p): Likewise. * symtab.c (lookup_symbol_aux): Likewise. * typeprint.c (whatis_exp, print_type_scalar): Likewise. * valarith.c (binop_types_user_defined_p, unop_user_defined_p): Likewise. * valops.c (value_cast_pointers, value_cast) (value_reinterpret_cast, value_dynamic_cast, value_addr, typecmp) (value_struct_elt, value_struct_elt_bitpos) (value_find_oload_method_list, find_overload_match) (value_rtti_indirect_type): Likewise. * valprint.c (val_print_scalar_type_p, generic_val_print): Likewise. * value.c (value_actual_type, value_as_address, unpack_long) (pack_long, pack_unsigned_long, coerce_ref_if_computed) (coerce_ref): Likewise. * varobj.c (varobj_get_value_type): Likewise.
Diffstat (limited to 'gdb/valops.c')
-rw-r--r--gdb/valops.c45
1 files changed, 20 insertions, 25 deletions
diff --git a/gdb/valops.c b/gdb/valops.c
index 21f4008b90..93ae6cf807 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -318,7 +318,7 @@ value_cast_pointers (struct type *type, struct value *arg2,
{
struct value *v2;
- if (TYPE_CODE (type2) == TYPE_CODE_REF)
+ if (TYPE_IS_REFERENCE (type2))
v2 = coerce_ref (arg2);
else
v2 = value_ind (arg2);
@@ -361,24 +361,20 @@ value_cast (struct type *type, struct value *arg2)
if (value_type (arg2) == type)
return arg2;
- code1 = TYPE_CODE (check_typedef (type));
-
/* Check if we are casting struct reference to struct reference. */
- if (code1 == TYPE_CODE_REF)
+ if (TYPE_IS_REFERENCE (check_typedef (type)))
{
/* We dereference type; then we recurse and finally
we generate value of the given reference. Nothing wrong with
that. */
struct type *t1 = check_typedef (type);
struct type *dereftype = check_typedef (TYPE_TARGET_TYPE (t1));
- struct value *val = value_cast (dereftype, arg2);
+ struct value *val = value_cast (dereftype, arg2);
return value_ref (val, TYPE_CODE (t1));
}
- code2 = TYPE_CODE (check_typedef (value_type (arg2)));
-
- if (code2 == TYPE_CODE_REF)
+ if (TYPE_IS_REFERENCE (check_typedef (value_type (arg2))))
/* We deref the value and then do the cast. */
return value_cast (type, coerce_ref (arg2));
@@ -389,7 +385,7 @@ value_cast (struct type *type, struct value *arg2)
/* You can't cast to a reference type. See value_cast_pointers
instead. */
- gdb_assert (code1 != TYPE_CODE_REF);
+ gdb_assert (!TYPE_IS_REFERENCE (type));
/* A cast to an undetermined-length array_type, such as
(TYPE [])OBJECT, is treated like a cast to (TYPE [N])OBJECT,
@@ -592,8 +588,8 @@ value_reinterpret_cast (struct type *type, struct value *arg)
dest_type = type;
/* If we are casting to a reference type, transform
- reinterpret_cast<T&>(V) to *reinterpret_cast<T*>(&V). */
- if (TYPE_CODE (real_type) == TYPE_CODE_REF)
+ reinterpret_cast<T&[&]>(V) to *reinterpret_cast<T*>(&V). */
+ if (TYPE_IS_REFERENCE (real_type))
{
is_ref = 1;
arg = value_addr (arg);
@@ -733,10 +729,10 @@ value_dynamic_cast (struct type *type, struct value *arg)
struct type *class_type, *rtti_type;
struct value *result, *tem, *original_arg = arg;
CORE_ADDR addr;
- int is_ref = TYPE_CODE (resolved_type) == TYPE_CODE_REF;
+ int is_ref = TYPE_IS_REFERENCE (resolved_type);
if (TYPE_CODE (resolved_type) != TYPE_CODE_PTR
- && TYPE_CODE (resolved_type) != TYPE_CODE_REF)
+ && !TYPE_IS_REFERENCE (resolved_type))
error (_("Argument to dynamic_cast must be a pointer or reference type"));
if (TYPE_CODE (TYPE_TARGET_TYPE (resolved_type)) != TYPE_CODE_VOID
&& TYPE_CODE (TYPE_TARGET_TYPE (resolved_type)) != TYPE_CODE_STRUCT)
@@ -1478,7 +1474,7 @@ value_addr (struct value *arg1)
struct value *arg2;
struct type *type = check_typedef (value_type (arg1));
- if (TYPE_CODE (type) == TYPE_CODE_REF)
+ if (TYPE_IS_REFERENCE (type))
{
if (value_bits_synthetic_pointer (arg1, value_embedded_offset (arg1),
TARGET_CHAR_BIT * TYPE_LENGTH (type)))
@@ -1744,7 +1740,7 @@ typecmp (int staticp, int varargs, int nargs,
tt1 = check_typedef (t1[i].type);
tt2 = check_typedef (value_type (t2[i]));
- if (TYPE_CODE (tt1) == TYPE_CODE_REF
+ if (TYPE_IS_REFERENCE (tt1)
/* We should be doing hairy argument matching, as below. */
&& (TYPE_CODE (check_typedef (TYPE_TARGET_TYPE (tt1)))
== TYPE_CODE (tt2)))
@@ -1762,14 +1758,13 @@ typecmp (int staticp, int varargs, int nargs,
char *>, and properly access map["hello"], because the
argument to [] will be a reference to a pointer to a char,
and the argument will be a pointer to a char. */
- while (TYPE_CODE(tt1) == TYPE_CODE_REF
- || TYPE_CODE (tt1) == TYPE_CODE_PTR)
+ while (TYPE_IS_REFERENCE (tt1) || TYPE_CODE (tt1) == TYPE_CODE_PTR)
{
tt1 = check_typedef( TYPE_TARGET_TYPE(tt1) );
}
while (TYPE_CODE(tt2) == TYPE_CODE_ARRAY
|| TYPE_CODE(tt2) == TYPE_CODE_PTR
- || TYPE_CODE(tt2) == TYPE_CODE_REF)
+ || TYPE_IS_REFERENCE (tt2))
{
tt2 = check_typedef (TYPE_TARGET_TYPE(tt2));
}
@@ -2161,7 +2156,7 @@ value_struct_elt (struct value **argp, struct value **args,
/* Follow pointers until we get to a non-pointer. */
- while (TYPE_CODE (t) == TYPE_CODE_PTR || TYPE_CODE (t) == TYPE_CODE_REF)
+ while (TYPE_CODE (t) == TYPE_CODE_PTR || TYPE_IS_REFERENCE (t))
{
*argp = value_ind (*argp);
/* Don't coerce fn pointer to fn and then back again! */
@@ -2248,7 +2243,7 @@ value_struct_elt_bitpos (struct value **argp, int bitpos, struct type *ftype,
t = check_typedef (value_type (*argp));
- while (TYPE_CODE (t) == TYPE_CODE_PTR || TYPE_CODE (t) == TYPE_CODE_REF)
+ while (TYPE_CODE (t) == TYPE_CODE_PTR || TYPE_IS_REFERENCE (t))
{
*argp = value_ind (*argp);
if (TYPE_CODE (check_typedef (value_type (*argp))) != TYPE_CODE_FUNC)
@@ -2409,7 +2404,7 @@ value_find_oload_method_list (struct value **argp, const char *method,
t = check_typedef (value_type (*argp));
/* Code snarfed from value_struct_elt. */
- while (TYPE_CODE (t) == TYPE_CODE_PTR || TYPE_CODE (t) == TYPE_CODE_REF)
+ while (TYPE_CODE (t) == TYPE_CODE_PTR || TYPE_IS_REFERENCE (t))
{
*argp = value_ind (*argp);
/* Don't coerce fn pointer to fn and then back again! */
@@ -2818,7 +2813,7 @@ find_overload_match (struct value **args, int nargs,
if (TYPE_CODE (temp_type) != TYPE_CODE_PTR
&& (TYPE_CODE (objtype) == TYPE_CODE_PTR
- || TYPE_CODE (objtype) == TYPE_CODE_REF))
+ || TYPE_IS_REFERENCE (objtype)))
{
temp = value_addr (temp);
}
@@ -3614,7 +3609,7 @@ value_rtti_indirect_type (struct value *v, int *full,
type = value_type (v);
type = check_typedef (type);
- if (TYPE_CODE (type) == TYPE_CODE_REF)
+ if (TYPE_IS_REFERENCE (type))
target = coerce_ref (v);
else if (TYPE_CODE (type) == TYPE_CODE_PTR)
{
@@ -3647,8 +3642,8 @@ value_rtti_indirect_type (struct value *v, int *full,
target_type = value_type (target);
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_lvalue_reference_type (real_type);
+ if (TYPE_IS_REFERENCE (type))
+ real_type = lookup_reference_type (real_type, TYPE_CODE (type));
else if (TYPE_CODE (type) == TYPE_CODE_PTR)
real_type = lookup_pointer_type (real_type);
else