[v3,1/8] Remove language_defn::emitchar

Message ID 20251228-string-printing-2-v3-1-ec5cc9dd0c71@tromey.com
State New
Headers
Series Refactor character printing |

Commit Message

Tom Tromey Dec. 28, 2025, 8:13 p.m. UTC
  Nothing outside of the specific language implementations ever calls
language_defn::emitchar.  This patch removes this method and updates
the rest of the code.  In some spots, the method is entirely removed;
in others, just the 'override' is removed.
---
 gdb/ada-lang.c  |  8 --------
 gdb/c-lang.c    | 19 +++----------------
 gdb/f-lang.h    | 12 ++----------
 gdb/language.c  |  9 ---------
 gdb/language.h  |  6 ------
 gdb/m2-lang.h   |  2 +-
 gdb/p-lang.h    |  2 +-
 gdb/rust-lang.c | 10 ++++++----
 gdb/rust-lang.h | 12 +-----------
 9 files changed, 14 insertions(+), 66 deletions(-)
  

Comments

Simon Marchi Jan. 7, 2026, 8:26 p.m. UTC | #1
On 2025-12-28 15:13, Tom Tromey wrote:
> Nothing outside of the specific language implementations ever calls
> language_defn::emitchar.  This patch removes this method and updates
> the rest of the code.  In some spots, the method is entirely removed;
> in others, just the 'override' is removed.

Seems like a good cleanup on its own.

Approved-By: Simon Marchi <simon.marchi@efficios.com>

Simon
  

Patch

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 87ae5975788415bcd709071153565501e9baaf65..7cee3ac381344022f8598a060f4c09e60be74e50 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -13893,14 +13893,6 @@  class ada_language : public language_defn
 
   /* See language.h.  */
 
-  void emitchar (int ch, struct type *chtype,
-		 struct ui_file *stream, int quoter) const override
-  {
-    ada_emit_char (ch, chtype, stream, quoter, 1);
-  }
-
-  /* See language.h.  */
-
   void printchar (int ch, struct type *chtype,
 		  struct ui_file *stream) const override
   {
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index 59db4c4ab6d52b259ae54f4294508dccd74b54b3..77753eb6c58ac63f6bfa25d541afdb1fcb2ab0f5 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -135,20 +135,6 @@  classify_type (struct type *elttype, struct gdbarch *gdbarch,
   return result;
 }
 
-/* Print the character C on STREAM as part of the contents of a
-   literal string whose delimiter is QUOTER.  Note that that format
-   for printing characters and strings is language specific.  */
-
-void
-language_defn::emitchar (int c, struct type *type,
-			 struct ui_file *stream, int quoter) const
-{
-  const char *encoding;
-
-  classify_type (type, type->arch (), &encoding);
-  generic_emit_char (c, type, stream, quoter, encoding);
-}
-
 /* See language.h.  */
 
 void
@@ -156,8 +142,9 @@  language_defn::printchar (int c, struct type *type,
 			  struct ui_file * stream) const
 {
   c_string_type str_type;
+  const char *encoding;
 
-  str_type = classify_type (type, type->arch (), NULL);
+  str_type = classify_type (type, type->arch (), &encoding);
   switch (str_type)
     {
     case C_CHAR:
@@ -174,7 +161,7 @@  language_defn::printchar (int c, struct type *type,
     }
 
   gdb_putc ('\'', stream);
-  emitchar (c, type, stream, '\'');
+  generic_emit_char (c, type, stream, '\'', encoding);
   gdb_putc ('\'', stream);
 }
 
diff --git a/gdb/f-lang.h b/gdb/f-lang.h
index f60d02a1586e75b52e6858e2436e0e0fe24c6923..7ffaccacce3cddf8d3831680ae887093a0c58308 100644
--- a/gdb/f-lang.h
+++ b/gdb/f-lang.h
@@ -158,20 +158,12 @@  class f_language : public language_defn
 
   /* See language.h.  */
 
-  void emitchar (int ch, struct type *chtype,
-		 struct ui_file *stream, int quoter) const override
-  {
-    const char *encoding = get_encoding (chtype);
-    generic_emit_char (ch, chtype, stream, quoter, encoding);
-  }
-
-  /* See language.h.  */
-
   void printchar (int ch, struct type *chtype,
 		  struct ui_file *stream) const override
   {
     gdb_puts ("'", stream);
-    emitchar (ch, chtype, stream, '\'');
+    const char *encoding = get_encoding (chtype);
+    generic_emit_char (ch, chtype, stream, '\'', encoding);
     gdb_puts ("'", stream);
   }
 
diff --git a/gdb/language.c b/gdb/language.c
index 168b9381bee5f40d524baa89c93e8ad63747c302..a929b53599b5d007b0021e9f7006495c28014062 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -801,15 +801,6 @@  class unknown_language : public language_defn
 
   /* See language.h.  */
 
-  void emitchar (int ch, struct type *chtype,
-		 struct ui_file *stream, int quoter) const override
-  {
-    error (_("emit character not implemented for language \"%s\""),
-	   natural_name ());
-  }
-
-  /* See language.h.  */
-
   void printchar (int ch, struct type *chtype,
 		  struct ui_file *stream) const override
   {
diff --git a/gdb/language.h b/gdb/language.h
index 926d94405ea5db32741a619899bef6df38304a02..92b3e39b79a40b82c37d977712b5e8c614bec712 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -524,12 +524,6 @@  struct language_defn
 
   virtual int parser (struct parser_state *ps) const;
 
-  /* Print the character CH (of type CHTYPE) on STREAM as part of the
-     contents of a literal string whose delimiter is QUOTER.  */
-
-  virtual void emitchar (int ch, struct type *chtype,
-			 struct ui_file *stream, int quoter) const;
-
   virtual void printchar (int ch, struct type *chtype,
 			  struct ui_file * stream) const;
 
diff --git a/gdb/m2-lang.h b/gdb/m2-lang.h
index 753fbbed96aa2f4c169d1092b41de6f6c1b6e674..86421a69af23f1b0885534800a9d7f5ae0701b46 100644
--- a/gdb/m2-lang.h
+++ b/gdb/m2-lang.h
@@ -93,7 +93,7 @@  class m2_language : public language_defn
   /* See language.h.  */
 
   void emitchar (int ch, struct type *chtype,
-		 struct ui_file *stream, int quoter) const override;
+		 struct ui_file *stream, int quoter) const;
 
   /* See language.h.  */
 
diff --git a/gdb/p-lang.h b/gdb/p-lang.h
index f3bb329bc02e5adc18fb28ae90856ebcbd3d1455..ab8e4bfa7f654240646e2b54dec212fc65a638a6 100644
--- a/gdb/p-lang.h
+++ b/gdb/p-lang.h
@@ -110,7 +110,7 @@  class pascal_language : public language_defn
   /* See language.h.  */
 
   void emitchar (int ch, struct type *chtype,
-		 struct ui_file *stream, int quoter) const override
+		 struct ui_file *stream, int quoter) const
   {
     int in_quotes = 0;
 
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index 20dffbe8d206ff11be0ad33e919afda143b77634..2c3f2a37d38615374f7059302f52a6ab04f8fa8f 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -1771,13 +1771,14 @@  rust_language::print_type (struct type *type, const char *varstring,
 /* See language.h.  */
 
 void
-rust_language::emitchar (int ch, struct type *chtype,
-			 struct ui_file *stream, int quoter) const
+rust_language::printchar (int ch, struct type *chtype,
+			  struct ui_file *stream) const
 {
+  fputs_filtered ("'", stream);
   if (!rust_chartype_p (chtype))
-    generic_emit_char (ch, chtype, stream, quoter,
+    generic_emit_char (ch, chtype, stream, '\'',
 		       target_charset (chtype->arch ()));
-  else if (ch == '\\' || ch == quoter)
+  else if (ch == '\\')
     gdb_printf (stream, "\\%c", ch);
   else if (ch == '\n')
     gdb_puts ("\\n", stream);
@@ -1793,6 +1794,7 @@  rust_language::emitchar (int ch, struct type *chtype,
     gdb_printf (stream, "\\x%02x", ch);
   else
     gdb_printf (stream, "\\u{%06x}", ch);
+  gdb_puts ("'", stream);
 }
 
 /* See language.h.  */
diff --git a/gdb/rust-lang.h b/gdb/rust-lang.h
index b35968e6ccdbca2727bb308ef3617d6592b0f36a..34769cd88421a308732df20172236b19e13cf2c9 100644
--- a/gdb/rust-lang.h
+++ b/gdb/rust-lang.h
@@ -156,18 +156,8 @@  class rust_language : public language_defn
 
   /* See language.h.  */
 
-  void emitchar (int ch, struct type *chtype,
-		 struct ui_file *stream, int quoter) const override;
-
-  /* See language.h.  */
-
   void printchar (int ch, struct type *chtype,
-		  struct ui_file *stream) const override
-  {
-    gdb_puts ("'", stream);
-    emitchar (ch, chtype, stream, '\'');
-    gdb_puts ("'", stream);
-  }
+		  struct ui_file *stream) const override;
 
   /* See language.h.  */