public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Andrew Burgess <andrew.burgess@embecosm.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 1/9] gdb: Merge auto and unknown language implementations
Date: Mon, 12 Oct 2020 15:46:29 +0100	[thread overview]
Message-ID: <06603e2359d85c1791c89167b5909bfa11166de3.1602508908.git.andrew.burgess@embecosm.com> (raw)
In-Reply-To: <cover.1602508908.git.andrew.burgess@embecosm.com>

The auto_language and unknown_language classes are basically the same
except for the language names and store_sym_names_in_linkage_form_p
which the unknown_language overrides to return true, while
auto_language returns the default false.

This commit creates a new parent class from which both of these
languages can inherit.  The two base classes are now greatly reduced.

Some of the static helper functions which previously were called from
both of these languages are now only called from one place, and so
I've inlined them into the new class.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* language.c (default_is_string_type_p): Delete, implementation
	moved into auto_or_unknown_language::is_string_type_p.
	(unk_op_print_tab): Moved into
	auto_or_unknown_language::opcode_print_table.
	(unknown_language_arch_info): Delete, implementation moved into
	auto_or_unknown_language::language_arch_info.
	(class auto_or_unknown_language): New class, member functions
	copied from unknown_language class, with some updates.
	(class unknown_language): Most member functions moved into
	auto_or_unknown_language class.  Inherit from
	auto_or_unknown_language class.
	(class auto_language): Inherit from auto_or_unknown_language.
	Delete most member functions.
---
 gdb/ChangeLog  |  16 ++++
 gdb/language.c | 215 ++++++++++++++-----------------------------------
 2 files changed, 76 insertions(+), 155 deletions(-)

diff --git a/gdb/language.c b/gdb/language.c
index 761f4966979..ffc1e85503a 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -782,60 +782,25 @@ language_defn::expression_ops () const
   return &exp_descriptor_standard;
 }
 
-/* Return true if TYPE is a string type, otherwise return false.  This
-   default implementation only detects TYPE_CODE_STRING.  */
+/* Parent class for both the "auto" and "unknown" languages.  These two
+   pseudo-languages are very similar so merging their implementations like
+   this makes sense.  */
 
-static bool
-default_is_string_type_p (struct type *type)
-{
-  type = check_typedef (type);
-  while (type->code () == TYPE_CODE_REF)
-    {
-      type = TYPE_TARGET_TYPE (type);
-      type = check_typedef (type);
-    }
-  return (type->code ()  == TYPE_CODE_STRING);
-}
-
-static const struct op_print unk_op_print_tab[] =
-{
-  {NULL, OP_NULL, PREC_NULL, 0}
-};
-
-static void
-unknown_language_arch_info (struct gdbarch *gdbarch,
-			    struct language_arch_info *lai)
-{
-  lai->string_char_type = builtin_type (gdbarch)->builtin_char;
-  lai->bool_type_default = builtin_type (gdbarch)->builtin_int;
-  lai->primitive_type_vector = GDBARCH_OBSTACK_CALLOC (gdbarch, 1,
-						       struct type *);
-}
-
-/* Class representing the unknown language.  */
-
-class unknown_language : public language_defn
+class auto_or_unknown_language : public language_defn
 {
 public:
-  unknown_language ()
-    : language_defn (language_unknown)
+  auto_or_unknown_language (enum language lang)
+    : language_defn (lang)
   { /* Nothing.  */ }
 
-  /* See language.h.  */
-
-  const char *name () const override
-  { return "unknown"; }
-
-  /* See language.h.  */
-
-  const char *natural_name () const override
-  { return "Unknown"; }
-
   /* See language.h.  */
   void language_arch_info (struct gdbarch *gdbarch,
 			   struct language_arch_info *lai) const override
   {
-    unknown_language_arch_info (gdbarch, lai);
+    lai->string_char_type = builtin_type (gdbarch)->builtin_char;
+    lai->bool_type_default = builtin_type (gdbarch)->builtin_int;
+    lai->primitive_type_vector = GDBARCH_OBSTACK_CALLOC (gdbarch, 1,
+						       struct type *);
   }
 
   /* See language.h.  */
@@ -844,14 +809,15 @@ class unknown_language : public language_defn
 		   struct ui_file *stream, int show, int level,
 		   const struct type_print_options *flags) const override
   {
-    error (_("unimplemented unknown_language::print_type called"));
+    error (_("type printing not implemented for language \"%s\""),
+	   natural_name ());
   }
 
   /* See language.h.  */
 
   char *demangle (const char *mangled, int options) const override
   {
-    /* The unknown language just uses the C++ demangler.  */
+    /* The auto language just uses the C++ demangler.  */
     return gdb_demangle (mangled, options);
   }
 
@@ -860,7 +826,8 @@ class unknown_language : public language_defn
   void value_print (struct value *val, struct ui_file *stream,
 		    const struct value_print_options *options) const override
   {
-    error (_("unimplemented unknown_language::value_print called"));
+    error (_("value printing not implemented for language \"%s\""),
+	   natural_name ());
   }
 
   /* See language.h.  */
@@ -869,7 +836,8 @@ class unknown_language : public language_defn
 	(struct value *val, struct ui_file *stream, int recurse,
 	 const struct value_print_options *options) const override
   {
-    error (_("unimplemented unknown_language::value_print_inner called"));
+    error (_("inner value printing not implemented for language \"%s\""),
+	   natural_name ());
   }
 
   /* See language.h.  */
@@ -885,7 +853,8 @@ class unknown_language : public language_defn
   void emitchar (int ch, struct type *chtype,
 		 struct ui_file *stream, int quoter) const override
   {
-    error (_("unimplemented unknown_language::emitchar called"));
+    error (_("emit character not implemented for language \"%s\""),
+	   natural_name ());
   }
 
   /* See language.h.  */
@@ -893,7 +862,8 @@ class unknown_language : public language_defn
   void printchar (int ch, struct type *chtype,
 		  struct ui_file *stream) const override
   {
-    error (_("unimplemented unknown_language::printchar called"));
+    error (_("print character not implemented for language \"%s\""),
+	   natural_name ());
   }
 
   /* See language.h.  */
@@ -903,7 +873,8 @@ class unknown_language : public language_defn
 		 const char *encoding, int force_ellipses,
 		 const struct value_print_options *options) const override
   {
-    error (_("unimplemented unknown_language::printstr called"));
+    error (_("print string not implemented for language \"%s\""),
+	   natural_name ());
   }
 
   /* See language.h.  */
@@ -911,14 +882,21 @@ class unknown_language : public language_defn
   void print_typedef (struct type *type, struct symbol *new_symbol,
 		      struct ui_file *stream) const override
   {
-    error (_("unimplemented unknown_language::print_typedef called"));
+    error (_("print typedef not implemented for language \"%s\""),
+	   natural_name ());
   }
 
   /* See language.h.  */
 
   bool is_string_type_p (struct type *type) const override
   {
-    return default_is_string_type_p (type);
+    type = check_typedef (type);
+    while (type->code () == TYPE_CODE_REF)
+      {
+	type = TYPE_TARGET_TYPE (type);
+	type = check_typedef (type);
+      }
+    return (type->code () == TYPE_CODE_STRING);
   }
 
   /* See language.h.  */
@@ -928,26 +906,24 @@ class unknown_language : public language_defn
 
   /* See language.h.  */
 
-  bool store_sym_names_in_linkage_form_p () const override
-  { return true; }
-
-  /* See language.h.  */
-
   const struct op_print *opcode_print_table () const override
-  { return unk_op_print_tab; }
-};
-
-/* Single instance of the unknown language class.  */
+  {
+    static const struct op_print unk_op_print_tab[] =
+      {
+	{NULL, OP_NULL, PREC_NULL, 0}
+      };
 
-static unknown_language unknown_language_defn;
+    return unk_op_print_tab;
+  }
+};
 
 /* Class representing the fake "auto" language.  */
 
-class auto_language : public language_defn
+class auto_language : public auto_or_unknown_language
 {
 public:
   auto_language ()
-    : language_defn (language_auto)
+    : auto_or_unknown_language (language_auto)
   { /* Nothing.  */ }
 
   /* See language.h.  */
@@ -959,111 +935,40 @@ class auto_language : public language_defn
 
   const char *natural_name () const override
   { return "Auto"; }
+};
 
-  /* See language.h.  */
-  void language_arch_info (struct gdbarch *gdbarch,
-			   struct language_arch_info *lai) const override
-  {
-    unknown_language_arch_info (gdbarch, lai);
-  }
-
-  /* See language.h.  */
-
-  void print_type (struct type *type, const char *varstring,
-		   struct ui_file *stream, int show, int level,
-		   const struct type_print_options *flags) const override
-  {
-    error (_("unimplemented auto_language::print_type called"));
-  }
-
-  /* See language.h.  */
-
-  char *demangle (const char *mangled, int options) const override
-  {
-    /* The auto language just uses the C++ demangler.  */
-    return gdb_demangle (mangled, options);
-  }
-
-  /* See language.h.  */
-
-  void value_print (struct value *val, struct ui_file *stream,
-		    const struct value_print_options *options) const override
-  {
-    error (_("unimplemented auto_language::value_print called"));
-  }
-
-  /* See language.h.  */
-
-  void value_print_inner
-	(struct value *val, struct ui_file *stream, int recurse,
-	 const struct value_print_options *options) const override
-  {
-    error (_("unimplemented auto_language::value_print_inner called"));
-  }
-
-  /* See language.h.  */
-
-  int parser (struct parser_state *ps) const override
-  {
-    /* No parsing is done, just claim success.  */
-    return 1;
-  }
-
-  /* See language.h.  */
-
-  void emitchar (int ch, struct type *chtype,
-		 struct ui_file *stream, int quoter) const override
-  {
-    error (_("unimplemented auto_language::emitchar called"));
-  }
-
-  /* See language.h.  */
-
-  void printchar (int ch, struct type *chtype,
-		  struct ui_file *stream) const override
-  {
-    error (_("unimplemented auto_language::printchar called"));
-  }
-
-  /* See language.h.  */
+/* Single instance of the fake "auto" language.  */
 
-  void printstr (struct ui_file *stream, struct type *elttype,
-		 const gdb_byte *string, unsigned int length,
-		 const char *encoding, int force_ellipses,
-		 const struct value_print_options *options) const override
-  {
-    error (_("unimplemented auto_language::printstr called"));
-  }
+static auto_language auto_language_defn;
 
-  /* See language.h.  */
+/* Class representing the unknown language.  */
 
-  void print_typedef (struct type *type, struct symbol *new_symbol,
-		      struct ui_file *stream) const override
-  {
-    error (_("unimplemented auto_language::print_typedef called"));
-  }
+class unknown_language : public auto_or_unknown_language
+{
+public:
+  unknown_language ()
+    : auto_or_unknown_language (language_unknown)
+  { /* Nothing.  */ }
 
   /* See language.h.  */
 
-  bool is_string_type_p (struct type *type) const override
-  {
-    return default_is_string_type_p (type);
-  }
+  const char *name () const override
+  { return "unknown"; }
 
   /* See language.h.  */
 
-  const char *name_of_this () const override
-  { return "this"; }
+  const char *natural_name () const override
+  { return "Unknown"; }
 
   /* See language.h.  */
 
-  const struct op_print *opcode_print_table () const override
-  { return unk_op_print_tab; }
+  bool store_sym_names_in_linkage_form_p () const override
+  { return true; }
 };
 
-/* Single instance of the fake "auto" language.  */
+/* Single instance of the unknown language class.  */
 
-static auto_language auto_language_defn;
+static unknown_language unknown_language_defn;
 
 \f
 /* Per-architecture language information.  */
-- 
2.25.4


  reply	other threads:[~2020-10-12 14:46 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-12 14:46 [PATCH 0/9] Continuing Changes to Language Classes Andrew Burgess
2020-10-12 14:46 ` Andrew Burgess [this message]
2020-10-12 14:46 ` [PATCH 2/9] gdb: move Modula2 language class into a header file Andrew Burgess
2020-10-13  9:58   ` Gaius Mulley
2020-10-12 14:46 ` [PATCH 3/9] gdb: remove LA_PRINT_TYPEDEF macro Andrew Burgess
2020-10-12 14:46 ` [PATCH 4/9] gdb: remove LA_VALUE_PRINT macro Andrew Burgess
2020-10-20 20:06   ` Tom Tromey
2020-10-12 14:46 ` [PATCH 5/9] gdb: remove LA_PRINT_ARRAY_INDEX macro Andrew Burgess
2020-10-12 14:46 ` [PATCH 6/9] gdb: remove LA_ITERATE_OVER_SYMBOLS macro Andrew Burgess
2020-10-12 14:46 ` [PATCH 7/9] gdb: Rename language_defn::demangle Andrew Burgess
2020-10-12 14:46 ` [PATCH 8/9] gdb: Improve documentation comment on language_defn::print_type Andrew Burgess
2020-10-12 14:46 ` [PATCH 9/9] gdb: move f_language class into a header file Andrew Burgess
2020-10-20 20:07 ` [PATCH 0/9] Continuing Changes to Language Classes Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=06603e2359d85c1791c89167b5909bfa11166de3.1602508908.git.andrew.burgess@embecosm.com \
    --to=andrew.burgess@embecosm.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).