This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
[commit] Convert COERCE_* to functions
- From: Andrew Cagney <cagney at gnu dot org>
- To: gdb-patches at sources dot redhat dot com
- Date: Wed, 10 Nov 2004 14:01:37 -0500
- Subject: [commit] Convert COERCE_* to functions
FYI,
Tested on PPC FC3 with no regressions.
Andrew
2004-11-10 Andrew Cagney <cagney@gnu.org>
* value.h (COERCE_REF, COERCE_ARRAY, COERCE_NUMBER, COERCE_ENUM)
(coerce_ref, coerce_array, coerce_number, coerce_enum): Replace
macros with function declarations.
* value.c (coerce_ref, coerce_array, coerce_number)
(coerce_enum): New functions.
(value_as_long, value_as_address): Update.
* ada-lang.c (ada_coerce_ref, ada_value_binop)
(ada_evaluate_subexp, ada_value_assign, ada_value_struct_elt): Update.
* jv-lang.c (evaluate_subexp_java): Update.
* valarith.c (value_less, value_neg, value_complement)
(value_binop, value_add, value_subscript, value_x_binop)
(value_logical_not, value_sub): Update.
* valops.c (check_field, value_struct_elt, value_ind)
(value_find_oload_method_list, value_cast, value_assign): Update.
* eval.c (evaluate_subexp_standard): Update.
Index: ada-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/ada-lang.c,v
retrieving revision 1.61
diff -p -u -r1.61 ada-lang.c
--- ada-lang.c 9 Nov 2004 14:43:24 -0000 1.61
+++ ada-lang.c 10 Nov 2004 18:51:16 -0000
@@ -2006,7 +2006,7 @@ ada_value_assign (struct value *toval, s
if (!toval->modifiable)
error ("Left operand of assignment is not a modifiable lvalue.");
- COERCE_REF (toval);
+ toval = coerce_ref (toval);
if (VALUE_LVAL (toval) == lval_memory
&& bits > 0
@@ -5479,7 +5479,7 @@ ada_value_struct_elt (struct value *arg,
t1 = ada_check_typedef (t1);
if (TYPE_CODE (t1) == TYPE_CODE_PTR)
{
- COERCE_REF (arg);
+ arg = coerce_ref (arg);
t = t1;
}
}
@@ -5766,7 +5766,7 @@ ada_coerce_ref (struct value *val0)
if (TYPE_CODE (VALUE_TYPE (val0)) == TYPE_CODE_REF)
{
struct value *val = val0;
- COERCE_REF (val);
+ val = coerce_ref (val);
val = unwrap_value (val);
return ada_to_fixed_value (val);
}
@@ -7030,8 +7030,8 @@ ada_value_binop (struct value *arg1, str
struct type *type1, *type2;
LONGEST v, v1, v2;
- COERCE_REF (arg1);
- COERCE_REF (arg2);
+ arg1 = coerce_ref (arg1);
+ arg2 = coerce_ref (arg2);
type1 = base_type (ada_check_typedef (VALUE_TYPE (arg1)));
type2 = base_type (ada_check_typedef (VALUE_TYPE (arg2)));
@@ -7406,8 +7406,8 @@ ada_evaluate_subexp (struct type *expect
evaluate_subexp (NULL_TYPE, exp, pos, noside);
LONGEST low_bound;
LONGEST high_bound;
- COERCE_REF (low_bound_val);
- COERCE_REF (high_bound_val);
+ low_bound_val = coerce_ref (low_bound_val);
+ high_bound_val = coerce_ref (high_bound_val);
low_bound = pos_atr (low_bound_val);
high_bound = pos_atr (high_bound_val);
Index: eval.c
===================================================================
RCS file: /cvs/src/src/gdb/eval.c,v
retrieving revision 1.44
diff -p -u -r1.44 eval.c
--- eval.c 9 Nov 2004 14:43:25 -0000 1.44
+++ eval.c 10 Nov 2004 18:51:16 -0000
@@ -1532,7 +1532,7 @@ evaluate_subexp_standard (struct type *e
array or pointer type (like a plain int variable for example),
then report this as an error. */
- COERCE_REF (arg1);
+ arg1 = coerce_ref (arg1);
type = check_typedef (VALUE_TYPE (arg1));
if (TYPE_CODE (type) != TYPE_CODE_ARRAY
&& TYPE_CODE (type) != TYPE_CODE_PTR)
Index: jv-lang.c
===================================================================
RCS file: /cvs/src/src/gdb/jv-lang.c,v
retrieving revision 1.36
diff -p -u -r1.36 jv-lang.c
--- jv-lang.c 9 Nov 2004 14:43:25 -0000 1.36
+++ jv-lang.c 10 Nov 2004 18:51:16 -0000
@@ -867,7 +867,7 @@ evaluate_subexp_java (struct type *expec
array or pointer type (like a plain int variable for example),
then report this as an error. */
- COERCE_REF (arg1);
+ arg1 = coerce_ref (arg1);
type = check_typedef (VALUE_TYPE (arg1));
if (TYPE_CODE (type) == TYPE_CODE_PTR)
type = check_typedef (TYPE_TARGET_TYPE (type));
Index: valarith.c
===================================================================
RCS file: /cvs/src/src/gdb/valarith.c,v
retrieving revision 1.26
diff -p -u -r1.26 valarith.c
--- valarith.c 9 Nov 2004 14:43:26 -0000 1.26
+++ valarith.c 10 Nov 2004 18:51:16 -0000
@@ -91,8 +91,8 @@ value_add (struct value *arg1, struct va
LONGEST sz;
struct type *type1, *type2, *valptrtype;
- COERCE_ARRAY (arg1);
- COERCE_ARRAY (arg2);
+ arg1 = coerce_array (arg1);
+ arg2 = coerce_array (arg2);
type1 = check_typedef (VALUE_TYPE (arg1));
type2 = check_typedef (VALUE_TYPE (arg2));
@@ -132,8 +132,8 @@ struct value *
value_sub (struct value *arg1, struct value *arg2)
{
struct type *type1, *type2;
- COERCE_ARRAY (arg1);
- COERCE_ARRAY (arg2);
+ arg1 = coerce_array (arg1);
+ arg2 = coerce_array (arg2);
type1 = check_typedef (VALUE_TYPE (arg1));
type2 = check_typedef (VALUE_TYPE (arg2));
@@ -182,7 +182,7 @@ value_subscript (struct value *array, st
int c_style = current_language->c_style_arrays;
struct type *tarray;
- COERCE_REF (array);
+ array = coerce_ref (array);
tarray = check_typedef (VALUE_TYPE (array));
if (TYPE_CODE (tarray) == TYPE_CODE_ARRAY
@@ -346,10 +346,10 @@ value_x_binop (struct value *arg1, struc
char tstr[13];
int static_memfuncp;
- COERCE_REF (arg1);
- COERCE_REF (arg2);
- COERCE_ENUM (arg1);
- COERCE_ENUM (arg2);
+ arg1 = coerce_ref (arg1);
+ arg2 = coerce_ref (arg2);
+ arg1 = coerce_enum (arg1);
+ arg2 = coerce_enum (arg2);
/* now we know that what we have to do is construct our
arg vector and find the right function to call it with. */
@@ -508,8 +508,8 @@ value_x_unop (struct value *arg1, enum e
char tstr[13], mangle_tstr[13];
int static_memfuncp, nargs;
- COERCE_REF (arg1);
- COERCE_ENUM (arg1);
+ arg1 = coerce_ref (arg1);
+ arg1 = coerce_enum (arg1);
/* now we know that what we have to do is construct our
arg vector and find the right function to call it with. */
@@ -747,8 +747,8 @@ value_binop (struct value *arg1, struct
struct value *val;
struct type *type1, *type2;
- COERCE_REF (arg1);
- COERCE_REF (arg2);
+ arg1 = coerce_ref (arg1);
+ arg2 = coerce_ref (arg2);
type1 = check_typedef (VALUE_TYPE (arg1));
type2 = check_typedef (VALUE_TYPE (arg2));
@@ -1155,7 +1155,7 @@ value_logical_not (struct value *arg1)
char *p;
struct type *type1;
- COERCE_NUMBER (arg1);
+ arg1 = coerce_number (arg1);
type1 = check_typedef (VALUE_TYPE (arg1));
if (TYPE_CODE (type1) == TYPE_CODE_FLT)
@@ -1216,8 +1216,8 @@ value_equal (struct value *arg1, struct
enum type_code code2;
int is_int1, is_int2;
- COERCE_ARRAY (arg1);
- COERCE_ARRAY (arg2);
+ arg1 = coerce_array (arg1);
+ arg2 = coerce_array (arg2);
type1 = check_typedef (VALUE_TYPE (arg1));
type2 = check_typedef (VALUE_TYPE (arg2));
@@ -1275,8 +1275,8 @@ value_less (struct value *arg1, struct v
struct type *type1, *type2;
int is_int1, is_int2;
- COERCE_ARRAY (arg1);
- COERCE_ARRAY (arg2);
+ arg1 = coerce_array (arg1);
+ arg2 = coerce_array (arg2);
type1 = check_typedef (VALUE_TYPE (arg1));
type2 = check_typedef (VALUE_TYPE (arg2));
@@ -1317,7 +1317,7 @@ value_neg (struct value *arg1)
struct type *type;
struct type *result_type = VALUE_TYPE (arg1);
- COERCE_REF (arg1);
+ arg1 = coerce_ref (arg1);
type = check_typedef (VALUE_TYPE (arg1));
@@ -1345,7 +1345,7 @@ value_complement (struct value *arg1)
struct type *type;
struct type *result_type = VALUE_TYPE (arg1);
- COERCE_REF (arg1);
+ arg1 = coerce_ref (arg1);
type = check_typedef (VALUE_TYPE (arg1));
Index: valops.c
===================================================================
RCS file: /cvs/src/src/gdb/valops.c,v
retrieving revision 1.133
diff -p -u -r1.133 valops.c
--- valops.c 9 Nov 2004 14:43:26 -0000 1.133
+++ valops.c 10 Nov 2004 18:51:16 -0000
@@ -212,7 +212,7 @@ value_cast (struct type *type, struct va
CHECK_TYPEDEF (type);
code1 = TYPE_CODE (type);
- COERCE_REF (arg2);
+ arg2 = coerce_ref (arg2);
type2 = check_typedef (VALUE_TYPE (arg2));
/* A cast to an undetermined-length array_type, such as (TYPE [])OBJECT,
@@ -524,13 +524,13 @@ value_assign (struct value *toval, struc
if (!toval->modifiable)
error ("Left operand of assignment is not a modifiable lvalue.");
- COERCE_REF (toval);
+ toval = coerce_ref (toval);
type = VALUE_TYPE (toval);
if (VALUE_LVAL (toval) != lval_internalvar)
fromval = value_cast (type, fromval);
else
- COERCE_ARRAY (fromval);
+ fromval = coerce_array (fromval);
CHECK_TYPEDEF (type);
/* Since modifying a register can trash the frame chain, and modifying memory
@@ -896,7 +896,7 @@ value_ind (struct value *arg1)
struct type *base_type;
struct value *arg2;
- COERCE_ARRAY (arg1);
+ arg1 = coerce_array (arg1);
base_type = check_typedef (VALUE_TYPE (arg1));
@@ -1589,7 +1589,7 @@ value_struct_elt (struct value **argp, s
struct type *t;
struct value *v;
- COERCE_ARRAY (*argp);
+ *argp = coerce_array (*argp);
t = check_typedef (VALUE_TYPE (*argp));
@@ -1600,7 +1600,7 @@ value_struct_elt (struct value **argp, s
*argp = value_ind (*argp);
/* Don't coerce fn pointer to fn and then back again! */
if (TYPE_CODE (VALUE_TYPE (*argp)) != TYPE_CODE_FUNC)
- COERCE_ARRAY (*argp);
+ *argp = coerce_array (*argp);
t = check_typedef (VALUE_TYPE (*argp));
}
@@ -1799,7 +1799,7 @@ value_find_oload_method_list (struct val
*argp = value_ind (*argp);
/* Don't coerce fn pointer to fn and then back again! */
if (TYPE_CODE (VALUE_TYPE (*argp)) != TYPE_CODE_FUNC)
- COERCE_ARRAY (*argp);
+ *argp = coerce_array (*argp);
t = check_typedef (VALUE_TYPE (*argp));
}
@@ -2320,7 +2320,7 @@ check_field (struct value *arg1, const c
{
struct type *t;
- COERCE_ARRAY (arg1);
+ arg1 = coerce_array (arg1);
t = VALUE_TYPE (arg1);
Index: value.c
===================================================================
RCS file: /cvs/src/src/gdb/value.c,v
retrieving revision 1.1
diff -p -u -r1.1 value.c
--- value.c 9 Nov 2004 20:41:57 -0000 1.1
+++ value.c 10 Nov 2004 18:51:16 -0000
@@ -526,7 +526,7 @@ value_as_long (struct value *val)
/* This coerces arrays and functions, which is necessary (e.g.
in disassemble_command). It also dereferences references, which
I suspect is the most logical thing to do. */
- COERCE_ARRAY (val);
+ val = coerce_array (val);
return unpack_long (VALUE_TYPE (val), VALUE_CONTENTS (val));
}
@@ -597,7 +597,7 @@ value_as_address (struct value *val)
|| TYPE_CODE (VALUE_TYPE (val)) == TYPE_CODE_METHOD)
return VALUE_ADDRESS (val);
- COERCE_ARRAY (val);
+ val = coerce_array (val);
/* Some architectures (e.g. Harvard), map instruction and data
addresses onto a single large unified address space. For
@@ -1197,6 +1197,45 @@ value_from_double (struct type *type, DO
return val;
}
+
+struct value *
+coerce_ref (struct value *arg)
+{
+ struct type *value_type_arg_tmp = check_typedef (VALUE_TYPE (arg));
+ if (TYPE_CODE (value_type_arg_tmp) == TYPE_CODE_REF)
+ arg = value_at_lazy (TYPE_TARGET_TYPE (value_type_arg_tmp),
+ unpack_pointer (VALUE_TYPE (arg),
+ VALUE_CONTENTS (arg)));
+ return arg;
+}
+
+struct value *
+coerce_array (struct value *arg)
+{
+ arg = coerce_ref (arg);
+ if (current_language->c_style_arrays
+ && TYPE_CODE (VALUE_TYPE (arg)) == TYPE_CODE_ARRAY)
+ arg = value_coerce_array (arg);
+ if (TYPE_CODE (VALUE_TYPE (arg)) == TYPE_CODE_FUNC)
+ arg = value_coerce_function (arg);
+ return arg;
+}
+
+struct value *
+coerce_number (struct value *arg)
+{
+ arg = coerce_array (arg);
+ arg = coerce_enum (arg);
+ return arg;
+}
+
+struct value *
+coerce_enum (struct value *arg)
+{
+ if (TYPE_CODE (check_typedef (VALUE_TYPE (arg))) == TYPE_CODE_ENUM)
+ arg = value_cast (builtin_type_unsigned_int, arg);
+ return arg;
+}
/* Should we use DEPRECATED_EXTRACT_STRUCT_VALUE_ADDRESS instead of
Index: value.h
===================================================================
RCS file: /cvs/src/src/gdb/value.h,v
retrieving revision 1.57
diff -p -u -r1.57 value.h
--- value.h 9 Nov 2004 14:43:26 -0000 1.57
+++ value.h 10 Nov 2004 18:51:17 -0000
@@ -226,14 +226,7 @@ extern int value_fetch_lazy (struct valu
/* Convert a REF to the object referenced. */
-#define COERCE_REF(arg) \
- do { \
- struct type *value_type_arg_tmp = check_typedef (VALUE_TYPE (arg)); \
- if (TYPE_CODE (value_type_arg_tmp) == TYPE_CODE_REF) \
- arg = value_at_lazy (TYPE_TARGET_TYPE (value_type_arg_tmp), \
- unpack_pointer (VALUE_TYPE (arg), \
- VALUE_CONTENTS (arg))); \
- } while (0)
+extern struct value *coerce_ref (struct value *value);
/* If ARG is an array, convert it to a pointer.
If ARG is an enum, convert it to an integer.
@@ -241,26 +234,12 @@ extern int value_fetch_lazy (struct valu
References are dereferenced. */
-#define COERCE_ARRAY(arg) \
- do { \
- COERCE_REF(arg); \
- if (current_language->c_style_arrays \
- && TYPE_CODE (VALUE_TYPE (arg)) == TYPE_CODE_ARRAY) \
- arg = value_coerce_array (arg); \
- if (TYPE_CODE (VALUE_TYPE (arg)) == TYPE_CODE_FUNC) \
- arg = value_coerce_function (arg); \
- } while (0)
-
-#define COERCE_NUMBER(arg) \
- do { COERCE_ARRAY(arg); COERCE_ENUM(arg); } while (0)
+extern struct value *coerce_array (struct value *value);
+extern struct value *coerce_number (struct value *value);
/* If ARG is an enum, convert it to an integer. */
-#define COERCE_ENUM(arg) \
- do { \
- if (TYPE_CODE (check_typedef (VALUE_TYPE (arg))) == TYPE_CODE_ENUM) \
- arg = value_cast (builtin_type_unsigned_int, arg); \
- } while (0)
+extern struct value *coerce_enum (struct value *value);
/* Internal variables (variables for convenience of use of debugger)
are recorded as a chain of these structures. */