Introduce unop_cast_type_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_type_operation, which implements
UNOP_CAST_TYPE.

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

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

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

index 8d1bbf028acfa9cfd614e92b5004a814bd904460..609e91f7cd595aedd966d63c1c4425abbfae2dd0 100644 (file)
@@ -1,3 +1,9 @@
+2021-03-08  Tom Tromey  <tom@tromey.com>
+
+       * expop.h (class unop_cast_type_operation): New.
+       * ax-gdb.c (unop_cast_type_operation::do_generate_ax): New
+       method.
+
 2021-03-08  Tom Tromey  <tom@tromey.com>
 
        * expop.h (class unop_cast_operation): New.
index 84887da524f820f0a4f3bb0c7cffc6ee6648b0c0..e0970e87d68207c2aeff4a5c08526c6a42a18d63 100644 (file)
@@ -2661,6 +2661,18 @@ assign_modify_operation::do_generate_ax (struct expression *exp,
             "may not assign to it"), name);
 }
 
+void
+unop_cast_type_operation::do_generate_ax (struct expression *exp,
+                                         struct agent_expr *ax,
+                                         struct axs_value *value,
+                                         struct type *cast_type)
+{
+  struct value *val
+    = std::get<0> (m_storage)->evaluate (nullptr, exp,
+                                        EVAL_AVOID_SIDE_EFFECTS);
+  std::get<1> (m_storage)->generate_ax (exp, ax, value, value_type (val));
+}
+
 }
 
 /* This handles the middle-to-right-side of code generation for binary
index abd5f64fdabb21df99f802d71e2e449dabb57f55..1d1ce0b664a7a4ae4d41a2e06e11deb92d541079 100644 (file)
@@ -1864,6 +1864,37 @@ protected:
     override;
 };
 
+/* A cast, but the type comes from an expression, not a "struct
+   type".  */
+class unop_cast_type_operation
+  : public maybe_constant_operation<operation_up, 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 std::get<1> (m_storage)->evaluate_for_cast (value_type (val),
+                                                      exp, noside);
+  }
+
+  enum exp_opcode opcode () const override
+  { return UNOP_CAST_TYPE; }
+
+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 */