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:32 -0700
commit73796c73263da16cedbefd5a43ab7e1887836115 (patch)
treec6d74fd8ea50be3c5f5643c26dc518d802c2f511 /gdb
parentcd9a314824b2b87207a8ba7a8003639989d2406b (diff)
downloadbinutils-73796c73263da16cedbefd5a43ab7e1887836115.zip
binutils-73796c73263da16cedbefd5a43ab7e1887836115.tar.gz
binutils-73796c73263da16cedbefd5a43ab7e1887836115.tar.bz2
Introduce ada_binop_addsub_operation
This adds class ada_binop_addsub_operation, which implements the Ada + and - operators. gdb/ChangeLog 2021-03-08 Tom Tromey <tom@tromey.com> * ada-lang.c (ada_binop_addsub_operation::evaluate): New method. * ada-exp.h (class ada_binop_addsub_operation): New.
Diffstat (limited to 'gdb')
-rw-r--r--gdb/ChangeLog5
-rw-r--r--gdb/ada-exp.h16
-rw-r--r--gdb/ada-lang.c40
3 files changed, 61 insertions, 0 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index af13b9a..597513a 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,10 @@
2021-03-08 Tom Tromey <tom@tromey.com>
+ * ada-lang.c (ada_binop_addsub_operation::evaluate): New method.
+ * ada-exp.h (class ada_binop_addsub_operation): New.
+
+2021-03-08 Tom Tromey <tom@tromey.com>
+
* ada-lang.h (ada_find_operator_symbol, ada_resolve_funcall)
(ada_resolve_variable): Declare.
* ada-lang.c (ada_find_operator_symbol, ada_resolve_funcall)
diff --git a/gdb/ada-exp.h b/gdb/ada-exp.h
index de69210..ad69d93 100644
--- a/gdb/ada-exp.h
+++ b/gdb/ada-exp.h
@@ -134,6 +134,22 @@ public:
{ return UNOP_IN_RANGE; }
};
+/* The Ada + and - operators. */
+class ada_binop_addsub_operation
+ : public tuple_holding_operation<enum exp_opcode, operation_up, operation_up>
+{
+public:
+
+ using tuple_holding_operation::tuple_holding_operation;
+
+ value *evaluate (struct type *expect_type,
+ struct expression *exp,
+ enum noside noside) override;
+
+ enum exp_opcode opcode () const override
+ { return std::get<0> (m_storage); }
+};
+
} /* namespace expr */
#endif /* ADA_EXP_H */
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 098a5a6..86ccc57 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -10492,6 +10492,46 @@ ada_ternop_range_operation::evaluate (struct type *expect_type,
return eval_ternop_in_range (expect_type, exp, noside, arg0, arg1, arg2);
}
+value *
+ada_binop_addsub_operation::evaluate (struct type *expect_type,
+ struct expression *exp,
+ enum noside noside)
+{
+ value *arg1 = std::get<1> (m_storage)->evaluate_with_coercion (exp, noside);
+ value *arg2 = std::get<2> (m_storage)->evaluate_with_coercion (exp, noside);
+
+ auto do_op = [=] (LONGEST x, LONGEST y)
+ {
+ if (std::get<0> (m_storage) == BINOP_ADD)
+ return x + y;
+ return x - y;
+ };
+
+ if (value_type (arg1)->code () == TYPE_CODE_PTR)
+ return (value_from_longest
+ (value_type (arg1),
+ do_op (value_as_long (arg1), value_as_long (arg2))));
+ if (value_type (arg2)->code () == TYPE_CODE_PTR)
+ return (value_from_longest
+ (value_type (arg2),
+ do_op (value_as_long (arg1), value_as_long (arg2))));
+ /* Preserve the original type for use by the range case below.
+ We cannot cast the result to a reference type, so if ARG1 is
+ a reference type, find its underlying type. */
+ struct type *type = value_type (arg1);
+ while (type->code () == TYPE_CODE_REF)
+ type = TYPE_TARGET_TYPE (type);
+ binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
+ arg1 = value_binop (arg1, arg2, std::get<0> (m_storage));
+ /* We need to special-case the result with a range.
+ This is done for the benefit of "ptype". gdb's Ada support
+ historically used the LHS to set the result type here, so
+ preserve this behavior. */
+ if (type->code () == TYPE_CODE_RANGE)
+ arg1 = value_cast (type, arg1);
+ return arg1;
+}
+
}
/* Implement the evaluate_exp routine in the exp_descriptor structure