From 8e9a3f3b1888a63699324e986fe6d821035cafec Mon Sep 17 00:00:00 2001 From: Per Bothner Date: Mon, 30 Dec 1991 19:22:29 +0000 Subject: [PATCH] Mainly stuff to improve handling of TYPE_CODE_REF (C++ reference) values. (See ChangeLog.) --- gdb/ChangeLog | 22 ++++++++++++++++++++++ gdb/valops.c | 27 ++++++++++++++++++--------- gdb/values.c | 2 +- 3 files changed, 41 insertions(+), 10 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index b7d62a7..7a347ab 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,25 @@ +Mon Dec 30 10:57:02 1991 Per Bothner (bothner at cygnus.com) + + Mainly stuff to improve handling of TYPE_CODE_REF values. + * valops.c (value_addr): If taking the addres of a + TYPE_CODE_REF, just cast the object to the corresponding + TYPE_CODE_PTR. This yields correct C++ semantics, and + preserves the location information, which has the nice effect + that &(&R) given the location containing R. + * values.c (value_copy): Make non-static (used by value_addr). + * eval.c (evaluate_subexp_for_address): Use the default + scheme (with value_addr) for a variable if it has TYPE_CODE_REF. + * valops.c (value_addr), eval.c (evaluate_subexp_for_address, + evaluate_subexp_with_coercion): Factor out some common + expressions into variables, for easier reading. + * findvar.c (locate_var_value): Remove code to handle + TYPE_CODE_REF - it should no longer be needed. + * valops.c (value_assign): Do a COERCE_REF on the + destination operand, for correct C++ semantics. + * valarith.c (value_x_binop): Ditto: De-reference C++ + references in the arguments. + * valops.c: ANSI-fy: bcopy->memcpy, bzero->memset. + Sat Dec 28 11:30:26 1991 Per Bothner (bothner at cygnus.com) * dwarfread.c, coffread.c: Use INIT_CPLUS_SPECIFIC. diff --git a/gdb/valops.c b/gdb/valops.c index 0becbf4..0ebc6ef 100644 --- a/gdb/valops.c +++ b/gdb/valops.c @@ -111,7 +111,7 @@ value_zero (type, lv) { register value val = allocate_value (type); - bzero (VALUE_CONTENTS (val), TYPE_LENGTH (type)); + memset (VALUE_CONTENTS (val), 0, TYPE_LENGTH (type)); VALUE_LVAL (val) = lv; return val; @@ -197,6 +197,7 @@ value_assign (toval, fromval) int use_buffer = 0; COERCE_ARRAY (fromval); + COERCE_REF (toval); if (VALUE_LVAL (toval) != lval_internalvar) fromval = value_cast (type, fromval); @@ -212,7 +213,7 @@ value_assign (toval, fromval) int regno = VALUE_REGNO (toval); if (VALUE_TYPE (fromval) != REGISTER_VIRTUAL_TYPE (regno)) fromval = value_cast (REGISTER_VIRTUAL_TYPE (regno), fromval); - bcopy (VALUE_CONTENTS (fromval), virtual_buffer, + memcpy (virtual_buffer, VALUE_CONTENTS (fromval), REGISTER_VIRTUAL_SIZE (regno)); target_convert_from_virtual (regno, virtual_buffer, raw_buffer); use_buffer = REGISTER_RAW_SIZE (regno); @@ -449,18 +450,26 @@ value value_addr (arg1) value arg1; { - - COERCE_REF(arg1); + struct type *type = VALUE_TYPE (arg1); + if (TYPE_CODE (type) == TYPE_CODE_REF) + { + /* Copy the value, but change the type from (T&) to (T*). + We keep the same location information, which is efficient, + and allows &(&X) to get the location containing the reference. */ + value arg2 = value_copy (arg1); + VALUE_TYPE (arg2) = lookup_pointer_type (TYPE_TARGET_TYPE (type)); + return arg2; + } if (VALUE_REPEATED (arg1) - || TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_ARRAY) + || TYPE_CODE (type) == TYPE_CODE_ARRAY) return value_coerce_array (arg1); - if (TYPE_CODE (VALUE_TYPE (arg1)) == TYPE_CODE_FUNC) + if (TYPE_CODE (type) == TYPE_CODE_FUNC) return value_coerce_function (arg1); if (VALUE_LVAL (arg1) != lval_memory) error ("Attempt to take address of value not located in memory."); - return value_from_longest (lookup_pointer_type (VALUE_TYPE (arg1)), + return value_from_longest (lookup_pointer_type (type), (LONGEST) (VALUE_ADDRESS (arg1) + VALUE_OFFSET (arg1))); } @@ -1045,7 +1054,7 @@ search_struct_method (name, arg1, args, offset, static_memfuncp, type) error ("cannot resolve overloaded method `%s'", name); while (j >= 0) { - if (TYPE_FLAGS (TYPE_FN_FIELD_TYPE (f, j)) & TYPE_FLAG_STUB) + if (TYPE_FN_FIELD_STUB (f, j)) check_stub_method (type, i, j); if (!typecmp (TYPE_FN_FIELD_STATIC_P (f, j), TYPE_FN_FIELD_ARGS (f, j), args)) @@ -1380,7 +1389,7 @@ value_struct_elt_for_address (domain, intype, name) else j = 0; - if (TYPE_FLAGS (TYPE_FN_FIELD_TYPE (f, j)) & TYPE_FLAG_STUB) + if (TYPE_FN_FIELD_STUB (f, j)) check_stub_method (t, i, j); if (TYPE_FN_FIELD_VIRTUAL_P (f, j)) { diff --git a/gdb/values.c b/gdb/values.c index afc5f3c..2c8143d 100644 --- a/gdb/values.c +++ b/gdb/values.c @@ -182,7 +182,7 @@ release_value (val) It contains the same contents, for same memory address, but it's a different block of storage. */ -static value +value value_copy (arg) value arg; { -- 2.7.4