aboutsummaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2021-03-08 07:27:57 -0700
committerTom Tromey <tom@tromey.com>2021-03-08 07:28:10 -0700
commit7efc87ffcb6cf97592821741a48c373d7e82eb0b (patch)
tree1ef7f07c0962295873cbe47eef6ae2b5abeea2f8 /gdb
parent82390ab88ce41c4fcc26584de895bb2fc24c697e (diff)
downloadbinutils-7efc87ffcb6cf97592821741a48c373d7e82eb0b.zip
binutils-7efc87ffcb6cf97592821741a48c373d7e82eb0b.tar.gz
binutils-7efc87ffcb6cf97592821741a48c373d7e82eb0b.tar.bz2
Split out ada_unop_in_range
This splits UNOP_IN_RANGE into a new function for future use. gdb/ChangeLog 2021-03-08 Tom Tromey <tom@tromey.com> * ada-lang.c (ada_unop_in_range): New function. (ada_evaluate_subexp): Use it.
Diffstat (limited to 'gdb')
-rw-r--r--gdb/ChangeLog5
-rw-r--r--gdb/ada-lang.c65
2 files changed, 43 insertions, 27 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 7d959f2..d81a876 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
2021-03-08 Tom Tromey <tom@tromey.com>
+ * ada-lang.c (ada_unop_in_range): New function.
+ (ada_evaluate_subexp): Use it.
+
+2021-03-08 Tom Tromey <tom@tromey.com>
+
* ada-lang.c (ada_unop_neg): New function.
(ada_evaluate_subexp): Use it.
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index c171e03..ac080fe 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -9974,6 +9974,43 @@ ada_unop_neg (struct type *expect_type,
return value_neg (arg1);
}
+/* A helper function for UNOP_IN_RANGE. */
+
+static value *
+ada_unop_in_range (struct type *expect_type,
+ struct expression *exp,
+ enum noside noside, enum exp_opcode op,
+ struct value *arg1, struct type *type)
+{
+ if (noside == EVAL_SKIP)
+ return eval_skip_value (exp);
+
+ struct value *arg2, *arg3;
+ switch (type->code ())
+ {
+ default:
+ lim_warning (_("Membership test incompletely implemented; "
+ "always returns true"));
+ type = language_bool_type (exp->language_defn, exp->gdbarch);
+ return value_from_longest (type, (LONGEST) 1);
+
+ case TYPE_CODE_RANGE:
+ arg2 = value_from_longest (type,
+ type->bounds ()->low.const_val ());
+ arg3 = value_from_longest (type,
+ type->bounds ()->high.const_val ());
+ binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
+ binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg3);
+ type = language_bool_type (exp->language_defn, exp->gdbarch);
+ return
+ value_from_longest (type,
+ (value_less (arg1, arg3)
+ || value_equal (arg1, arg3))
+ && (value_less (arg2, arg1)
+ || value_equal (arg2, arg1)));
+ }
+}
+
/* Implement the evaluate_exp routine in the exp_descriptor structure
for the Ada language. */
@@ -10514,33 +10551,7 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
(*pos) += 2;
arg1 = evaluate_subexp (nullptr, exp, pos, noside);
type = check_typedef (exp->elts[pc + 1].type);
-
- if (noside == EVAL_SKIP)
- goto nosideret;
-
- switch (type->code ())
- {
- default:
- lim_warning (_("Membership test incompletely implemented; "
- "always returns true"));
- type = language_bool_type (exp->language_defn, exp->gdbarch);
- return value_from_longest (type, (LONGEST) 1);
-
- case TYPE_CODE_RANGE:
- arg2 = value_from_longest (type,
- type->bounds ()->low.const_val ());
- arg3 = value_from_longest (type,
- type->bounds ()->high.const_val ());
- binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
- binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg3);
- type = language_bool_type (exp->language_defn, exp->gdbarch);
- return
- value_from_longest (type,
- (value_less (arg1, arg3)
- || value_equal (arg1, arg3))
- && (value_less (arg2, arg1)
- || value_equal (arg2, arg1)));
- }
+ return ada_unop_in_range (expect_type, exp, noside, op, arg1, type);
case BINOP_IN_BOUNDS:
(*pos) += 2;