[v3,167/206] Introduce ada_atr_val_operation

Message ID 20210220201609.838264-168-tom@tromey.com
State New
Headers show
Series
  • Refactor expressions
Related show

Commit Message

Tom Tromey Feb. 20, 2021, 8:15 p.m.
This adds class ada_atr_val_operation, which implements OP_ATR_VAL.

gdb/ChangeLog
2021-02-20  Tom Tromey  <tom@tromey.com>

	* ada-lang.c (ada_val_atr): No longer static.
	(ada_atr_val_operation::evaluate): New method.
	* ada-exp.h (class ada_atr_val_operation): New.
---
 gdb/ChangeLog  |  6 ++++++
 gdb/ada-exp.h  | 19 +++++++++++++++++++
 gdb/ada-lang.c | 11 ++++++++++-
 3 files changed, 35 insertions(+), 1 deletion(-)

-- 
2.26.2

Patch

diff --git a/gdb/ada-exp.h b/gdb/ada-exp.h
index 07744c1c8ea..c86b0548947 100644
--- a/gdb/ada-exp.h
+++ b/gdb/ada-exp.h
@@ -69,6 +69,9 @@  extern struct value *ada_pos_atr (struct type *expect_type,
 				  struct expression *exp,
 				  enum noside noside, enum exp_opcode op,
 				  struct value *arg);
+extern struct value *ada_val_atr (enum noside noside, struct type *type,
+				  struct value *arg);
+
 
 namespace expr
 {
@@ -334,6 +337,22 @@  class ada_var_msym_value_operation
   using operation::do_generate_ax;
 };
 
+/* Implement the Ada 'val attribute.  */
+class ada_atr_val_operation
+  : public tuple_holding_operation<struct type *, 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 OP_ATR_VAL; }
+};
+
 } /* namespace expr */
 
 #endif /* ADA_EXP_H */
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 283568f3e27..e1630af3b75 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -9008,7 +9008,7 @@  val_atr (struct type *type, LONGEST val)
   return value_from_longest (type, val);
 }
 
-static struct value *
+struct value *
 ada_val_atr (enum noside noside, struct type *type, struct value *arg)
 {
   if (noside == EVAL_AVOID_SIDE_EFFECTS)
@@ -10865,6 +10865,15 @@  ada_var_value_operation::evaluate (struct type *expect_type,
   return ada_to_fixed_value (arg1);
 }
 
+value *
+ada_atr_val_operation::evaluate (struct type *expect_type,
+				 struct expression *exp,
+				 enum noside noside)
+{
+  value *arg = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
+  return ada_val_atr (noside, std::get<0> (m_storage), arg);
+}
+
 }
 
 /* Implement the evaluate_exp routine in the exp_descriptor structure