aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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