[v3,094/206] Introduce structop_operation

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

Commit Message

Tom Tromey Feb. 20, 2021, 8:14 p.m.
This adds class structop_base_operation and structop_operation, which
implement STRUCTOP_STRUCT.  The base class exists to unify the
completion code between STRUCTOP_STRUCT and STRUCTOP_PTR.

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

	* expop.h (class structop_base_operation)
	(class structop_operation): New.
	* eval.c (eval_op_structop_struct): No longer static.
---
 gdb/ChangeLog |  6 +++++
 gdb/eval.c    |  2 +-
 gdb/expop.h   | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 69 insertions(+), 1 deletion(-)

-- 
2.26.2

Patch

diff --git a/gdb/eval.c b/gdb/eval.c
index dd86e6892fe..5002c25a347 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -1342,7 +1342,7 @@  eval_op_ternop (struct type *expect_type, struct expression *exp,
 
 /* A helper function for STRUCTOP_STRUCT.  */
 
-static struct value *
+struct value *
 eval_op_structop_struct (struct type *expect_type, struct expression *exp,
 			 enum noside noside,
 			 struct value *arg1, const char *string)
diff --git a/gdb/expop.h b/gdb/expop.h
index 9c63f129594..9f1625ca7f7 100644
--- a/gdb/expop.h
+++ b/gdb/expop.h
@@ -70,6 +70,11 @@  extern struct value *eval_op_ternop (struct type *expect_type,
 				     enum noside noside,
 				     struct value *array, struct value *low,
 				     struct value *upper);
+extern struct value *eval_op_structop_struct (struct type *expect_type,
+					      struct expression *exp,
+					      enum noside noside,
+					      struct value *arg1,
+					      const char *string);
 
 namespace expr
 {
@@ -786,6 +791,63 @@  class complex_operation
   { return OP_COMPLEX; }
 };
 
+class structop_base_operation
+  : public tuple_holding_operation<operation_up, std::string>
+{
+public:
+
+  /* Used for completion.  Return the field name.  */
+  const std::string &get_string () const
+  {
+    return std::get<1> (m_storage);
+  }
+
+  /* Used for completion.  Evaluate the LHS for type.  */
+  value *evaluate_lhs (struct expression *exp)
+  {
+    return std::get<0> (m_storage)->evaluate (nullptr, exp,
+					      EVAL_AVOID_SIDE_EFFECTS);
+  }
+
+protected:
+
+  using tuple_holding_operation::tuple_holding_operation;
+};
+
+class structop_operation
+  : public structop_base_operation
+{
+public:
+
+  using structop_base_operation::structop_base_operation;
+
+  value *evaluate (struct type *expect_type,
+		   struct expression *exp,
+		   enum noside noside) override
+  {
+    value *val =std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
+    return eval_op_structop_struct (expect_type, exp, noside, val,
+				    std::get<1> (m_storage).c_str ());
+  }
+
+  enum exp_opcode opcode () const override
+  { return STRUCTOP_STRUCT; }
+
+protected:
+
+  void do_generate_ax (struct expression *exp,
+		       struct agent_expr *ax,
+		       struct axs_value *value,
+		       struct type *cast_type)
+    override
+  {
+    gen_expr_structop (exp, STRUCTOP_STRUCT,
+		       std::get<0> (this->m_storage).get (),
+		       std::get<1> (this->m_storage).c_str (),
+		       ax, value);
+  }
+};
+
 } /* namespace expr */
 
 #endif /* EXPOP_H */