Introduce unop_addr_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_addr_operation, which implements UNOP_ADDR.

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

* expop.h (class unop_addr_operation): New.
* ax-gdb.c (gen_expr_unop) <case UNOP_ADDR>: New.

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

index fb0eea2ee86c72a7330e093c7926d042b94f41f6..1998e486b7d41f22ea10101affccfca09ab5505f 100644 (file)
@@ -1,3 +1,8 @@
+2021-03-08  Tom Tromey  <tom@tromey.com>
+
+       * expop.h (class unop_addr_operation): New.
+       * ax-gdb.c (gen_expr_unop) <case UNOP_ADDR>: New.
+
 2021-03-08  Tom Tromey  <tom@tromey.com>
 
        * expop.h (class typeid_operation): New.
index f7ab50f8cde11e639c7be69c326523b33be4fa7b..64710887534440e640d9f39ade722ace92301e89 100644 (file)
@@ -2744,6 +2744,11 @@ gen_expr_unop (struct expression *exp,
       gen_deref (value);
       break;
 
+    case UNOP_ADDR:
+      lhs->generate_ax (exp, ax, value);
+      gen_address_of (value);
+      break;
+
     default:
       gdb_assert_not_reached ("invalid case in gen_expr_unop");
     }
index 804f51654b21a5e36656ea2401f32cf33a953deb..a09be969a087cde0281a530b4133941c18c7bc8b 100644 (file)
@@ -1546,6 +1546,42 @@ public:
   { return OP_TYPEID; }
 };
 
+/* Implement the address-of operation.  */
+class unop_addr_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
+  {
+    /* C++: check for and handle pointer to members.  */
+    if (noside == EVAL_SKIP)
+      return eval_skip_value (exp);
+    else
+      return std::get<0> (m_storage)->evaluate_for_address (exp, noside);
+  }
+
+  enum exp_opcode opcode () const override
+  { return UNOP_ADDR; }
+
+protected:
+
+  void do_generate_ax (struct expression *exp,
+                      struct agent_expr *ax,
+                      struct axs_value *value,
+                      struct type *cast_type)
+    override
+  {
+    gen_expr_unop (exp, UNOP_ADDR,
+                  std::get<0> (this->m_storage).get (),
+                  ax, value);
+  }
+};
+
 } /* namespace expr */
 
 #endif /* EXPOP_H */