[v3,163/206] Introduce ada_var_msym_value_operation

Message ID 20210220201609.838264-164-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_var_msym_value_operation, which implements
OP_VAR_MSYM_VALUE for Ada.

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

	* ada-lang.c (ada_var_msym_value_operation::evaluate_for_cast):
	New method.
	* ada-exp.h (class ada_var_msym_value_operation): New.
---
 gdb/ChangeLog  |  6 ++++++
 gdb/ada-exp.h  | 17 +++++++++++++++++
 gdb/ada-lang.c | 25 +++++++++++++++++++++++++
 3 files changed, 48 insertions(+)

-- 
2.26.2

Patch

diff --git a/gdb/ada-exp.h b/gdb/ada-exp.h
index 0f2f62f5978..0fe6ecf7e93 100644
--- a/gdb/ada-exp.h
+++ b/gdb/ada-exp.h
@@ -304,6 +304,23 @@  class ada_var_value_operation
   using operation::do_generate_ax;
 };
 
+/* Variant of var_msym_value_operation for Ada.  */
+class ada_var_msym_value_operation
+  : public var_msym_value_operation
+{
+public:
+
+  using var_msym_value_operation::var_msym_value_operation;
+
+  value *evaluate_for_cast (struct type *expect_type,
+			    struct expression *exp,
+			    enum noside noside) override;
+
+protected:
+
+  using operation::do_generate_ax;
+};
+
 } /* namespace expr */
 
 #endif /* ADA_EXP_H */
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index b05a8ab275e..79cc04a762c 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -10724,6 +10724,31 @@  ada_unop_atr_operation::evaluate (struct type *expect_type,
 		       val, type_arg, std::get<2> (m_storage));
 }
 
+value *
+ada_var_msym_value_operation::evaluate_for_cast (struct type *expect_type,
+						 struct expression *exp,
+						 enum noside noside)
+{
+  if (noside == EVAL_AVOID_SIDE_EFFECTS)
+    return value_zero (expect_type, not_lval);
+
+  value *val = evaluate_var_msym_value (noside,
+					std::get<1> (m_storage),
+					std::get<0> (m_storage));
+
+  val = ada_value_cast (expect_type, val);
+
+  /* Follow the Ada language semantics that do not allow taking
+     an address of the result of a cast (view conversion in Ada).  */
+  if (VALUE_LVAL (val) == lval_memory)
+    {
+      if (value_lazy (val))
+	value_fetch_lazy (val);
+      VALUE_LVAL (val) = not_lval;
+    }
+  return val;
+}
+
 value *
 ada_var_value_operation::evaluate_for_cast (struct type *expect_type,
 					    struct expression *exp,