diff options
author | Joel Brobecker <brobecker@adacore.com> | 2020-11-23 21:50:29 -0500 |
---|---|---|
committer | Joel Brobecker <brobecker@adacore.com> | 2020-11-23 21:50:29 -0500 |
commit | af619ce989a51864b1c2b8c2eef7c46ffe1ff256 (patch) | |
tree | 14035c14f9ebe08254682dc5935bb1a9c0f5c26b | |
parent | e6fcee3a73ddab55e3b35b7705b01035383e5417 (diff) | |
download | gdb-af619ce989a51864b1c2b8c2eef7c46ffe1ff256.zip gdb-af619ce989a51864b1c2b8c2eef7c46ffe1ff256.tar.gz gdb-af619ce989a51864b1c2b8c2eef7c46ffe1ff256.tar.bz2 |
valarith.c: Replace INIT_VAL_WITH_FIXED_POINT_VAL macro by lambda
gdb/ChangeLog (Simon Marchi <simark@simark.ca>):
* valarith.c (fixed_point_binop): Replace the
INIT_VAL_WITH_FIXED_POINT_VAL macro by a lambda. Update all
users accordingly.
-rw-r--r-- | gdb/ChangeLog | 6 | ||||
-rw-r--r-- | gdb/valarith.c | 34 |
2 files changed, 25 insertions, 15 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index d1a1b95..0146874 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,11 @@ 2020-11-24 Joel Brobecker <brobecker@adacore.com> + * valarith.c (fixed_point_binop): Replace the + INIT_VAL_WITH_FIXED_POINT_VAL macro by a lambda. Update all + users accordingly. + +2020-11-24 Joel Brobecker <brobecker@adacore.com> + * gdbtypes.h (struct type) <fixed_point_scaling_factor>: New method, replacing fixed_point_scaling_factor. All callers updated throughout this project. diff --git a/gdb/valarith.c b/gdb/valarith.c index 29ac46b..5b2bf18 100644 --- a/gdb/valarith.c +++ b/gdb/valarith.c @@ -917,44 +917,48 @@ fixed_point_binop (struct value *arg1, struct value *arg2, enum exp_opcode op) type_byte_order (type2), type2->is_unsigned (), type2->fixed_point_scaling_factor ()); -#define INIT_VAL_WITH_FIXED_POINT_VAL(RESULT) \ - do { \ - val = allocate_value (type1); \ - (RESULT).write_fixed_point \ - (gdb::make_array_view (value_contents_raw (val), \ - TYPE_LENGTH (type1)), \ - type_byte_order (type1), type1->is_unsigned (), \ - type1->fixed_point_scaling_factor ()); \ - } while (0) + auto fixed_point_to_value = [type1] (const gdb_mpq &fp) + { + value *fp_val = allocate_value (type1); + + fp.write_fixed_point + (gdb::make_array_view (value_contents_raw (fp_val), + TYPE_LENGTH (type1)), + type_byte_order (type1), + type1->is_unsigned (), + type1->fixed_point_scaling_factor ()); + + return fp_val; + }; switch (op) { case BINOP_ADD: mpq_add (res.val, v1.val, v2.val); - INIT_VAL_WITH_FIXED_POINT_VAL (res); + val = fixed_point_to_value (res); break; case BINOP_SUB: mpq_sub (res.val, v1.val, v2.val); - INIT_VAL_WITH_FIXED_POINT_VAL (res); + val = fixed_point_to_value (res); break; case BINOP_MIN: - INIT_VAL_WITH_FIXED_POINT_VAL (mpq_cmp (v1.val, v2.val) < 0 ? v1 : v2); + val = fixed_point_to_value (mpq_cmp (v1.val, v2.val) < 0 ? v1 : v2); break; case BINOP_MAX: - INIT_VAL_WITH_FIXED_POINT_VAL (mpq_cmp (v1.val, v2.val) > 0 ? v1 : v2); + val = fixed_point_to_value (mpq_cmp (v1.val, v2.val) > 0 ? v1 : v2); break; case BINOP_MUL: mpq_mul (res.val, v1.val, v2.val); - INIT_VAL_WITH_FIXED_POINT_VAL (res); + val = fixed_point_to_value (res); break; case BINOP_DIV: mpq_div (res.val, v1.val, v2.val); - INIT_VAL_WITH_FIXED_POINT_VAL (res); + val = fixed_point_to_value (res); break; case BINOP_EQUAL: |