[107/203] Introduce type_operation

Message ID 20210101214723.1784144-108-tom@tromey.com
State Superseded
Headers show
Series
  • Refactor expressions
Related show

Commit Message

Tom Tromey Jan. 1, 2021, 9:45 p.m.
This adds class type_operation, which implements OP_TYPE.

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

	* expop.h (class type_operation): New.
	* eval.c (eval_op_type): No longer static.
---
 gdb/ChangeLog |  5 +++++
 gdb/eval.c    |  2 +-
 gdb/expop.h   | 25 +++++++++++++++++++++++++
 3 files changed, 31 insertions(+), 1 deletion(-)

-- 
2.26.2

Patch

diff --git a/gdb/eval.c b/gdb/eval.c
index cca88d49230..f07990932b9 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -2017,7 +2017,7 @@  eval_op_postdec (struct type *expect_type, struct expression *exp,
 
 /* A helper function for OP_TYPE.  */
 
-static struct value *
+struct value *
 eval_op_type (struct type *expect_type, struct expression *exp,
 	      enum noside noside, struct type *type)
 {
diff --git a/gdb/expop.h b/gdb/expop.h
index caac155295a..aac3e729de9 100644
--- a/gdb/expop.h
+++ b/gdb/expop.h
@@ -185,6 +185,9 @@  extern struct value *eval_op_ind (struct type *expect_type,
 				  struct expression *exp,
 				  enum noside noside,
 				  struct value *arg1);
+extern struct value *eval_op_type (struct type *expect_type,
+				   struct expression *exp,
+				   enum noside noside, struct type *type);
 
 namespace expr
 {
@@ -1409,6 +1412,28 @@  class unop_ind_operation
   }
 };
 
+/* Implement OP_TYPE.  */
+class type_operation
+  : public tuple_holding_operation<struct type *>
+{
+public:
+
+  using tuple_holding_operation::tuple_holding_operation;
+
+  value *evaluate (struct type *expect_type,
+		   struct expression *exp,
+		   enum noside noside) override
+  {
+    return eval_op_type (expect_type, exp, noside, std::get<0> (m_storage));
+  }
+
+  enum exp_opcode opcode () const override
+  { return OP_TYPE; }
+
+  bool constant_p () const override
+  { return true; }
+};
+
 } /* namespace expr */
 
 #endif /* EXPOP_H */