[113/203] Introduce unop_alignof_operation

Message ID 20210101214723.1784144-114-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 unop_alignof_operation, which implements UNOP_ALIGNOF.

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

	* expop.h (class unop_alignof_operation): New.
	* eval.c (eval_op_alignof): 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 f07990932b9..526c80de92b 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -1856,7 +1856,7 @@  eval_op_ind (struct type *expect_type, struct expression *exp,
 
 /* A helper function for UNOP_ALIGNOF.  */
 
-static struct value *
+struct value *
 eval_op_alignof (struct type *expect_type, struct expression *exp,
 		 enum noside noside,
 		 struct value *arg1)
diff --git a/gdb/expop.h b/gdb/expop.h
index 22af0c824e2..b5f01550d85 100644
--- a/gdb/expop.h
+++ b/gdb/expop.h
@@ -188,6 +188,10 @@  extern struct value *eval_op_ind (struct type *expect_type,
 extern struct value *eval_op_type (struct type *expect_type,
 				   struct expression *exp,
 				   enum noside noside, struct type *type);
+extern struct value *eval_op_alignof (struct type *expect_type,
+				      struct expression *exp,
+				      enum noside noside,
+				      struct value *arg1);
 
 namespace expr
 {
@@ -1600,6 +1604,27 @@  class unop_sizeof_operation
     override;
 };
 
+/* Implement 'alignof'.  */
+class unop_alignof_operation
+  : public maybe_constant_operation<operation_up>
+{
+public:
+
+  using maybe_constant_operation::maybe_constant_operation;
+
+  value *evaluate (struct type *expect_type,
+		   struct expression *exp,
+		   enum noside noside) override
+  {
+    value *val = std::get<0> (m_storage)->evaluate (nullptr, exp,
+						    EVAL_AVOID_SIDE_EFFECTS);
+    return eval_op_alignof (expect_type, exp, noside, val);
+  }
+
+  enum exp_opcode opcode () const override
+  { return UNOP_ALIGNOF; }
+};
+
 } /* namespace expr */
 
 #endif /* EXPOP_H */