Introduce unop_alignof_operation
authorTom Tromey <tom@tromey.com>
Mon, 8 Mar 2021 14:27:57 +0000 (07:27 -0700)
committerTom Tromey <tom@tromey.com>
Mon, 8 Mar 2021 14:28:22 +0000 (07:28 -0700)
This adds class unop_alignof_operation, which implements UNOP_ALIGNOF.

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

* expop.h (class unop_alignof_operation): New.
* eval.c (eval_op_alignof): No longer static.

gdb/ChangeLog
gdb/eval.c
gdb/expop.h

index cf5d7839f6a86a1fbacbcddd41c40d6ba6a4dabc..94bcb64fa0330e8a675d18f2601297c55ec44cc2 100644 (file)
@@ -1,3 +1,8 @@
+2021-03-08  Tom Tromey  <tom@tromey.com>
+
+       * expop.h (class unop_alignof_operation): New.
+       * eval.c (eval_op_alignof): No longer static.
+
 2021-03-08  Tom Tromey  <tom@tromey.com>
 
        * expop.h (class unop_sizeof_operation): New.
index f5a5a2050803d831d5d727fb3d7c91fa5ebe5bd1..3cf8bf1d5a92c6ccaf12f178ab1a198e1858e23a 100644 (file)
@@ -1881,7 +1881,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)
index 8cb7281830bec8522fadb0dc1da00d0a15ce658f..87e52acb6bf9bc70ea5209b1e465e3917de8fc2c 100644 (file)
@@ -189,6 +189,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
 {
@@ -1611,6 +1615,27 @@ protected:
     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 */