Introduce unop_cast_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:24 +0000 (07:28 -0700)
This adds class unop_cast_operation, which implements UNOP_CAST.

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

* expop.h (class unop_cast_operation): New.
* ax-gdb.c (unop_cast_operation::do_generate_ax): New method.

gdb/ChangeLog
gdb/ax-gdb.c
gdb/expop.h

index c260f04e48c73c988827c5ec9a082daeb5a7d71d..8d1bbf028acfa9cfd614e92b5004a814bd904460 100644 (file)
@@ -1,3 +1,8 @@
+2021-03-08  Tom Tromey  <tom@tromey.com>
+
+       * expop.h (class unop_cast_operation): New.
+       * ax-gdb.c (unop_cast_operation::do_generate_ax): New method.
+
 2021-03-08  Tom Tromey  <tom@tromey.com>
 
        * expop.h (class assign_modify_operation): New.
index f81e5b9ad29ad9b1d5b9e7af041e2a779d0d1b73..84887da524f820f0a4f3bb0c7cffc6ee6648b0c0 100644 (file)
@@ -2514,6 +2514,16 @@ unop_sizeof_operation::do_generate_ax (struct expression *exp,
   value->type = builtin_type (ax->gdbarch)->builtin_int;
 }
 
+void
+unop_cast_operation::do_generate_ax (struct expression *exp,
+                                    struct agent_expr *ax,
+                                    struct axs_value *value,
+                                    struct type *cast_type)
+{
+  std::get<0> (m_storage)->generate_ax (exp, ax, value,
+                                       std::get<1> (m_storage));
+}
+
 void
 unop_memval_operation::do_generate_ax (struct expression *exp,
                                       struct agent_expr *ax,
index 93af40d9591a39a749c49c963c474dbdc350d7d0..abd5f64fdabb21df99f802d71e2e449dabb57f55 100644 (file)
@@ -1836,6 +1836,34 @@ protected:
     override;
 };
 
+/* A type cast.  */
+class unop_cast_operation
+  : public maybe_constant_operation<operation_up, struct type *>
+{
+public:
+
+  using maybe_constant_operation::maybe_constant_operation;
+
+  value *evaluate (struct type *expect_type,
+                  struct expression *exp,
+                  enum noside noside) override
+  {
+    return std::get<0> (m_storage)->evaluate_for_cast (std::get<1> (m_storage),
+                                                      exp, noside);
+  }
+
+  enum exp_opcode opcode () const override
+  { return UNOP_CAST; }
+
+protected:
+
+  void do_generate_ax (struct expression *exp,
+                      struct agent_expr *ax,
+                      struct axs_value *value,
+                      struct type *cast_type)
+    override;
+};
+
 } /* namespace expr */
 
 #endif /* EXPOP_H */