[2/6] Convert long_const_operation to use gdb_mpz

Message ID 20230328-expr-128-bit-v1-2-f9eeb0143318@adacore.com
State New
Headers
Series Add 128-bit integers to Ada and Rust parsers |

Commit Message

Tom Tromey March 28, 2023, 3:49 p.m. UTC
  This changes long_const_operation to use gdb_mpz for its storage.
---
 gdb/ada-lang.c |  4 ++--
 gdb/ax-gdb.c   |  4 ++--
 gdb/expop.h    | 26 +++++++++++++++++++++++---
 gdb/expprint.c |  6 ++++++
 4 files changed, 33 insertions(+), 7 deletions(-)
  

Patch

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 5301c72d514..e51fd082d73 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -10612,10 +10612,10 @@  ada_char_operation::replace (operation_up &&owner,
 
   if (context_type != nullptr && context_type->code () == TYPE_CODE_ENUM)
     {
+      LONGEST val = as_longest ();
       gdb_assert (result.get () == this);
       std::get<0> (m_storage) = context_type;
-      std::get<1> (m_storage)
-	= convert_char_literal (context_type, std::get<1> (m_storage));
+      std::get<1> (m_storage) = convert_char_literal (context_type, val);
     }
 
   return result;
diff --git a/gdb/ax-gdb.c b/gdb/ax-gdb.c
index 1ed648ce002..9dda7fe524d 100644
--- a/gdb/ax-gdb.c
+++ b/gdb/ax-gdb.c
@@ -1630,8 +1630,8 @@  long_const_operation::do_generate_ax (struct expression *exp,
 				      struct axs_value *value,
 				      struct type *cast_type)
 {
-  gen_int_literal (ax, value, std::get<1> (m_storage),
-		   std::get<0> (m_storage));
+  LONGEST val = as_longest ();
+  gen_int_literal (ax, value, val, std::get<0> (m_storage));
 }
 
 void
diff --git a/gdb/expop.h b/gdb/expop.h
index d973d2314bb..854945c8688 100644
--- a/gdb/expop.h
+++ b/gdb/expop.h
@@ -274,6 +274,12 @@  check_objfile (ULONGEST val, struct objfile *objfile)
   return false;
 }
 
+static inline bool
+check_objfile (const gdb_mpz &val, struct objfile *objfile)
+{
+  return false;
+}
+
 template<typename T>
 static inline bool
 check_objfile (enum_flags<T> val, struct objfile *objfile)
@@ -319,6 +325,8 @@  extern void dump_for_expression (struct ui_file *stream, int depth,
 				 struct type *type);
 extern void dump_for_expression (struct ui_file *stream, int depth,
 				 CORE_ADDR addr);
+extern void dump_for_expression (struct ui_file *stream, int depth,
+				 const gdb_mpz &addr);
 extern void dump_for_expression (struct ui_file *stream, int depth,
 				 internalvar *ivar);
 extern void dump_for_expression (struct ui_file *stream, int depth,
@@ -468,6 +476,12 @@  check_constant (ULONGEST cst)
   return true;
 }
 
+static inline bool
+check_constant (const gdb_mpz &cst)
+{
+  return true;
+}
+
 static inline bool
 check_constant (struct symbol *sym)
 {
@@ -665,18 +679,21 @@  class var_value_operation
 };
 
 class long_const_operation
-  : public tuple_holding_operation<struct type *, LONGEST>
+  : public tuple_holding_operation<struct type *, gdb_mpz>
 {
 public:
 
   using tuple_holding_operation::tuple_holding_operation;
 
+  long_const_operation (struct type *type, LONGEST val)
+    : long_const_operation (type, gdb_mpz (val))
+  { }
+
   value *evaluate (struct type *expect_type,
 		   struct expression *exp,
 		   enum noside noside) override
   {
-    return value_from_longest (std::get<0> (m_storage),
-			       std::get<1> (m_storage));
+    return value_from_mpz (std::get<0> (m_storage), std::get<1> (m_storage));
   }
 
   enum exp_opcode opcode () const override
@@ -687,6 +704,9 @@  class long_const_operation
 
 protected:
 
+  LONGEST as_longest () const
+  { return std::get<1> (m_storage).as_integer_truncate<LONGEST> (); }
+
   void do_generate_ax (struct expression *exp,
 		       struct agent_expr *ax,
 		       struct axs_value *value,
diff --git a/gdb/expprint.c b/gdb/expprint.c
index 0c7cc754179..e0ec25573c2 100644
--- a/gdb/expprint.c
+++ b/gdb/expprint.c
@@ -108,6 +108,12 @@  dump_for_expression (struct ui_file *stream, int depth, CORE_ADDR addr)
 	      core_addr_to_string (addr));
 }
 
+void
+dump_for_expression (struct ui_file *stream, int depth, const gdb_mpz &val)
+{
+  gdb_printf (stream, _("%*sConstant: %s\n"), depth, "", val.str ().c_str ());
+}
+
 void
 dump_for_expression (struct ui_file *stream, int depth, internalvar *ivar)
 {