public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 0/9] Continuing Changes to Language Classes
@ 2020-10-12 14:46 Andrew Burgess
  2020-10-12 14:46 ` [PATCH 1/9] gdb: Merge auto and unknown language implementations Andrew Burgess
                   ` (9 more replies)
  0 siblings, 10 replies; 13+ messages in thread
From: Andrew Burgess @ 2020-10-12 14:46 UTC (permalink / raw)
  To: gdb-patches

Patches #1, #2, and #9 are all about improving the C++ classes used to
represent languages in GDB.

Patches #3 -> #8 are other language related cleanups.

All feedback welcome.

Thanks,
Andrew


---

Andrew Burgess (9):
  gdb: Merge auto and unknown language implementations
  gdb: move Modula2 language class into a header file
  gdb: remove LA_PRINT_TYPEDEF macro
  gdb: remove LA_VALUE_PRINT macro
  gdb: remove LA_PRINT_ARRAY_INDEX macro
  gdb: remove LA_ITERATE_OVER_SYMBOLS macro
  gdb: Rename language_defn::demangle
  gdb: Improve documentation comment on language_defn::print_type
  gdb: move f_language class into a header file

 gdb/ChangeLog      | 133 +++++++++++++++
 gdb/ada-lang.c     |   4 +-
 gdb/c-lang.c       |   2 +-
 gdb/d-lang.c       |   2 +-
 gdb/f-exp.y        |   2 +-
 gdb/f-lang.c       | 320 +++++++-----------------------------
 gdb/f-lang.h       | 272 ++++++++++++++++++++++++++++--
 gdb/f-typeprint.c  |  82 +++------
 gdb/f-valprint.c   |   5 +-
 gdb/go-lang.c      |   2 +-
 gdb/language.c     | 221 +++++++------------------
 gdb/language.h     |  25 +--
 gdb/linespec.c     |   2 +-
 gdb/m2-exp.y       |   2 +-
 gdb/m2-lang.c      | 402 +++++++++++++++++----------------------------
 gdb/m2-lang.h      | 130 +++++++++++++--
 gdb/m2-typeprint.c |   4 +-
 gdb/m2-valprint.c  |  11 +-
 gdb/objc-lang.c    |   2 +-
 gdb/parse.c        |   1 -
 gdb/rust-lang.c    |   2 +-
 gdb/typeprint.c    |   2 +-
 gdb/valprint.c     |   6 +-
 23 files changed, 848 insertions(+), 786 deletions(-)

-- 
2.25.4


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 1/9] gdb: Merge auto and unknown language implementations
  2020-10-12 14:46 [PATCH 0/9] Continuing Changes to Language Classes Andrew Burgess
@ 2020-10-12 14:46 ` Andrew Burgess
  2020-10-12 14:46 ` [PATCH 2/9] gdb: move Modula2 language class into a header file Andrew Burgess
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Andrew Burgess @ 2020-10-12 14:46 UTC (permalink / raw)
  To: gdb-patches

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


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 2/9] gdb: move Modula2 language class into a header file
  2020-10-12 14:46 [PATCH 0/9] Continuing Changes to Language Classes Andrew Burgess
  2020-10-12 14:46 ` [PATCH 1/9] gdb: Merge auto and unknown language implementations Andrew Burgess
@ 2020-10-12 14:46 ` 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
                   ` (7 subsequent siblings)
  9 siblings, 1 reply; 13+ messages in thread
From: Andrew Burgess @ 2020-10-12 14:46 UTC (permalink / raw)
  To: gdb-patches

Move the m2_language class from m2-lang.c into m2-lang.h.  The benefit
of this move is that we can remove trampoline functions.  Currently
the language implementation is split of different m2-* files with
m2-lang.h including declaration for all the language implementation
functions.

Currently the m2_language class in m2-lang.c has member functions that
then call the global functions declared in m2-lang.h.

After this change the m2_language class is declared in m2-lang.h, and
the member functions are the implementations defined in all the m2-*
files.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* m2-exp.y (m2_parse): Rename to...
	(m2_language::parser): ...this.  Update function signature.
	* m2-lang.c (m2_printchar): Renamed to m2_language::printchar.
	(m2_op_print): Rename to...
	(m2_language::op_print_tab): ...this, and make const.
	(exp_descriptor_modula2): Rename to...
	(m2_language::exp_descriptor_modula2): ...this.
	(class m2_language): Move to m2-lang.h.
	(m2_language::language_arch_info): New function, moved out of
	class declaration.
	(m2_language::printchar): New function, body from m2_printchar.
	(m2_language::printstr): New function, moved out of class
	declaration.
	(m2_language::emitchar): Likewise.
	* m2-lang.h (m2_parse): Delete declaration.
	(m2_print_typedef): Delete declaration.
	(m2_value_print_inner): Delete declaration.
	(class m2_language): Class declaration moved from m2-lang.c,
	larger functions are left in m2-lang.c.
	* m2-typeprint.c (m2_print_typedef): Rename to...
	(m2_language::print_typedef): ...this, and update function
	signature.
	* m2-valprint.c (m2_value_print_inner): Rename to...
	(m2_language::value_print_inner): ...this, replace use of
	LA_PRINT_STRING with a direct call to printstr member function,
	and update recursive call.
---
 gdb/ChangeLog      |  29 ++++
 gdb/m2-exp.y       |   2 +-
 gdb/m2-lang.c      | 402 +++++++++++++++++----------------------------
 gdb/m2-lang.h      | 130 +++++++++++++--
 gdb/m2-typeprint.c |   4 +-
 gdb/m2-valprint.c  |  11 +-
 6 files changed, 308 insertions(+), 270 deletions(-)

diff --git a/gdb/m2-exp.y b/gdb/m2-exp.y
index c79c1f25828..5924e895c70 100644
--- a/gdb/m2-exp.y
+++ b/gdb/m2-exp.y
@@ -1031,7 +1031,7 @@ yylex (void)
 }
 
 int
-m2_parse (struct parser_state *par_state)
+m2_language::parser (struct parser_state *par_state) const
 {
   /* Setting up the parser state.  */
   scoped_restore pstate_restore = make_scoped_restore (&pstate);
diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c
index 3cc0364b4a1..2f671eff08f 100644
--- a/gdb/m2-lang.c
+++ b/gdb/m2-lang.c
@@ -29,19 +29,6 @@
 #include "valprint.h"
 #include "gdbarch.h"
 
-static void m2_printchar (int, struct type *, struct ui_file *);
-
-/* FIXME:  This is a copy of the same function from c-exp.y.  It should
-   be replaced with a true Modula version.  */
-
-static void
-m2_printchar (int c, struct type *type, struct ui_file *stream)
-{
-  fputs_filtered ("'", stream);
-  LA_EMIT_CHAR (c, type, stream, '\'');
-  fputs_filtered ("'", stream);
-}
-
 static struct value *
 evaluate_subexp_modula2 (struct type *expect_type, struct expression *exp,
 			 int *pos, enum noside noside)
@@ -140,7 +127,7 @@ evaluate_subexp_modula2 (struct type *expect_type, struct expression *exp,
 
 /* Table of operators and their precedences for printing expressions.  */
 
-static const struct op_print m2_op_print_tab[] =
+const struct op_print m2_language::op_print_tab[] =
 {
   {"+", BINOP_ADD, PREC_ADD, 0},
   {"+", UNOP_PLUS, PREC_PREFIX, 0},
@@ -185,7 +172,7 @@ enum m2_primitive_types {
   nr_m2_primitive_types
 };
 
-const struct exp_descriptor exp_descriptor_modula2 = 
+const struct exp_descriptor m2_language::exp_descriptor_modula2 =
 {
   print_subexp_standard,
   operator_length_standard,
@@ -195,262 +182,173 @@ const struct exp_descriptor exp_descriptor_modula2 =
   evaluate_subexp_modula2
 };
 
-/* Class representing the M2 language.  */
-
-class m2_language : public language_defn
-{
-public:
-  m2_language ()
-    : language_defn (language_m2)
-  { /* Nothing.  */ }
-
-  /* See language.h.  */
-
-  const char *name () const override
-  { return "modula-2"; }
-
-  /* See language.h.  */
-
-  const char *natural_name () const override
-  { return "Modula-2"; }
-
-  /* See language.h.  */
-  void language_arch_info (struct gdbarch *gdbarch,
-			   struct language_arch_info *lai) const override
-  {
-    const struct builtin_m2_type *builtin = builtin_m2_type (gdbarch);
-
-    lai->string_char_type = builtin->builtin_char;
-    lai->primitive_type_vector
-      = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_m2_primitive_types + 1,
-				struct type *);
-
-    lai->primitive_type_vector [m2_primitive_type_char]
-      = builtin->builtin_char;
-    lai->primitive_type_vector [m2_primitive_type_int]
-      = builtin->builtin_int;
-    lai->primitive_type_vector [m2_primitive_type_card]
-      = builtin->builtin_card;
-    lai->primitive_type_vector [m2_primitive_type_real]
-      = builtin->builtin_real;
-    lai->primitive_type_vector [m2_primitive_type_bool]
-      = builtin->builtin_bool;
-
-    lai->bool_type_symbol = "BOOLEAN";
-    lai->bool_type_default = builtin->builtin_bool;
-  }
-
-  /* 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
-  {
-    m2_print_type (type, varstring, stream, show, level, flags);
-  }
-
-  /* See language.h.  */
-
-  void value_print_inner
-	(struct value *val, struct ui_file *stream, int recurse,
-	 const struct value_print_options *options) const override
-  {
-    return m2_value_print_inner (val, stream, recurse, options);
-  }
-
-  /* See language.h.  */
-
-  int parser (struct parser_state *ps) const override
-  {
-    return m2_parse (ps);
-  }
-
-  /* See language.h.  */
-
-  void emitchar (int ch, struct type *chtype,
-		 struct ui_file *stream, int quoter) const override
-  {
-    ch &= 0xFF;			/* Avoid sign bit follies.  */
-
-    if (PRINT_LITERAL_FORM (ch))
-      {
-	if (ch == '\\' || ch == quoter)
-	  fputs_filtered ("\\", stream);
-	fprintf_filtered (stream, "%c", ch);
-      }
-    else
-      {
-	switch (ch)
-	  {
-	  case '\n':
-	    fputs_filtered ("\\n", stream);
-	    break;
-	  case '\b':
-	    fputs_filtered ("\\b", stream);
-	    break;
-	  case '\t':
-	    fputs_filtered ("\\t", stream);
-	    break;
-	  case '\f':
-	    fputs_filtered ("\\f", stream);
-	    break;
-	  case '\r':
-	    fputs_filtered ("\\r", stream);
-	    break;
-	  case '\033':
-	    fputs_filtered ("\\e", stream);
-	    break;
-	  case '\007':
-	    fputs_filtered ("\\a", stream);
-	    break;
-	  default:
-	    fprintf_filtered (stream, "\\%.3o", (unsigned int) ch);
-	    break;
-	  }
-      }
-  }
-
-  /* See language.h.  */
-
-  void printchar (int ch, struct type *chtype,
-		  struct ui_file *stream) const override
-  {
-    m2_printchar (ch, chtype, stream);
-  }
-
-  /* See language.h.  */
-
-  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
-  {
-    unsigned int i;
-    unsigned int things_printed = 0;
-    int in_quotes = 0;
-    int need_comma = 0;
-
-    if (length == 0)
-      {
-	fputs_filtered ("\"\"", gdb_stdout);
-	return;
-      }
-
-    for (i = 0; i < length && things_printed < options->print_max; ++i)
-      {
-	/* Position of the character we are examining
-	   to see whether it is repeated.  */
-	unsigned int rep1;
-	/* Number of repetitions we have detected so far.  */
-	unsigned int reps;
-
-	QUIT;
-
-	if (need_comma)
-	  {
-	    fputs_filtered (", ", stream);
-	    need_comma = 0;
-	  }
-
-	rep1 = i + 1;
-	reps = 1;
-	while (rep1 < length && string[rep1] == string[i])
-	  {
-	    ++rep1;
-	    ++reps;
-	  }
-
-	if (reps > options->repeat_count_threshold)
-	  {
-	    if (in_quotes)
-	      {
-		fputs_filtered ("\", ", stream);
-		in_quotes = 0;
-	      }
-	    m2_printchar (string[i], elttype, stream);
-	    fprintf_filtered (stream, " <repeats %u times>", reps);
-	    i = rep1 - 1;
-	    things_printed += options->repeat_count_threshold;
-	    need_comma = 1;
-	  }
-	else
-	  {
-	    if (!in_quotes)
-	      {
-		fputs_filtered ("\"", stream);
-		in_quotes = 1;
-	      }
-	    LA_EMIT_CHAR (string[i], elttype, stream, '"');
-	    ++things_printed;
-	  }
-      }
-
-    /* Terminate the quotes if necessary.  */
-    if (in_quotes)
-      fputs_filtered ("\"", stream);
+/* Single instance of the M2 language.  */
 
-    if (force_ellipses || i < length)
-      fputs_filtered ("...", stream);
-  }
+static m2_language m2_language_defn;
 
-  /* See language.h.  */
+/* See language.h.  */
 
-  void print_typedef (struct type *type, struct symbol *new_symbol,
-		      struct ui_file *stream) const override
-  {
-    m2_print_typedef (type, new_symbol, stream);
-  }
+void
+m2_language::language_arch_info (struct gdbarch *gdbarch,
+				 struct language_arch_info *lai) const
+{
+  const struct builtin_m2_type *builtin = builtin_m2_type (gdbarch);
+
+  lai->string_char_type = builtin->builtin_char;
+  lai->primitive_type_vector
+    = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_m2_primitive_types + 1,
+			      struct type *);
+
+  lai->primitive_type_vector [m2_primitive_type_char]
+    = builtin->builtin_char;
+  lai->primitive_type_vector [m2_primitive_type_int]
+    = builtin->builtin_int;
+  lai->primitive_type_vector [m2_primitive_type_card]
+    = builtin->builtin_card;
+  lai->primitive_type_vector [m2_primitive_type_real]
+    = builtin->builtin_real;
+  lai->primitive_type_vector [m2_primitive_type_bool]
+    = builtin->builtin_bool;
+
+  lai->bool_type_symbol = "BOOLEAN";
+  lai->bool_type_default = builtin->builtin_bool;
+}
 
-  /* See language.h.  */
+/* See languge.h.  */
 
-  bool is_string_type_p (struct type *type) const override
-  {
-    type = check_typedef (type);
-    if (type->code () == TYPE_CODE_ARRAY
-	&& TYPE_LENGTH (type) > 0
-	&& TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0)
-      {
-	struct type *elttype = check_typedef (TYPE_TARGET_TYPE (type));
+void
+m2_language::printchar (int c, struct type *type,
+			struct ui_file *stream) const
+{
+  fputs_filtered ("'", stream);
+  emitchar (c, type, stream, '\'');
+  fputs_filtered ("'", stream);
+}
 
-	if (TYPE_LENGTH (elttype) == 1
-	    && (elttype->code () == TYPE_CODE_INT
-		|| elttype->code () == TYPE_CODE_CHAR))
-	  return true;
-      }
+/* See language.h.  */
 
-    return false;
-  }
+void
+m2_language::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
+{
+  unsigned int i;
+  unsigned int things_printed = 0;
+  int in_quotes = 0;
+  int need_comma = 0;
 
-  /* See language.h.  */
+  if (length == 0)
+    {
+      fputs_filtered ("\"\"", gdb_stdout);
+      return;
+    }
 
-  bool c_style_arrays_p () const override
-  { return false; }
+  for (i = 0; i < length && things_printed < options->print_max; ++i)
+    {
+      /* Position of the character we are examining
+	 to see whether it is repeated.  */
+      unsigned int rep1;
+      /* Number of repetitions we have detected so far.  */
+      unsigned int reps;
 
-  /* See language.h.  Despite not having C-style arrays, Modula-2 uses 0
-     for its string lower bounds.  */
+      QUIT;
 
-  char string_lower_bound () const override
-  { return 0; }
+      if (need_comma)
+	{
+	  fputs_filtered (", ", stream);
+	  need_comma = 0;
+	}
 
-  /* See language.h.  */
+      rep1 = i + 1;
+      reps = 1;
+      while (rep1 < length && string[rep1] == string[i])
+	{
+	  ++rep1;
+	  ++reps;
+	}
 
-  bool range_checking_on_by_default () const override
-  { return true; }
+      if (reps > options->repeat_count_threshold)
+	{
+	  if (in_quotes)
+	    {
+	      fputs_filtered ("\", ", stream);
+	      in_quotes = 0;
+	    }
+	  printchar (string[i], elttype, stream);
+	  fprintf_filtered (stream, " <repeats %u times>", reps);
+	  i = rep1 - 1;
+	  things_printed += options->repeat_count_threshold;
+	  need_comma = 1;
+	}
+      else
+	{
+	  if (!in_quotes)
+	    {
+	      fputs_filtered ("\"", stream);
+	      in_quotes = 1;
+	    }
+	  emitchar (string[i], elttype, stream, '"');
+	  ++things_printed;
+	}
+    }
 
-  /* See language.h.  */
+  /* Terminate the quotes if necessary.  */
+  if (in_quotes)
+    fputs_filtered ("\"", stream);
 
-  const struct exp_descriptor *expression_ops () const override
-  { return &exp_descriptor_modula2; }
+  if (force_ellipses || i < length)
+    fputs_filtered ("...", stream);
+}
 
-  /* See language.h.  */
+/* See language.h.  */
 
-  const struct op_print *opcode_print_table () const override
-  { return m2_op_print_tab; }
-};
+void
+m2_language::emitchar (int ch, struct type *chtype,
+		       struct ui_file *stream, int quoter) const
+{
+  ch &= 0xFF;			/* Avoid sign bit follies.  */
 
-/* Single instance of the M2 language.  */
+  if (PRINT_LITERAL_FORM (ch))
+    {
+      if (ch == '\\' || ch == quoter)
+	fputs_filtered ("\\", stream);
+      fprintf_filtered (stream, "%c", ch);
+    }
+  else
+    {
+      switch (ch)
+	{
+	case '\n':
+	  fputs_filtered ("\\n", stream);
+	  break;
+	case '\b':
+	  fputs_filtered ("\\b", stream);
+	  break;
+	case '\t':
+	  fputs_filtered ("\\t", stream);
+	  break;
+	case '\f':
+	  fputs_filtered ("\\f", stream);
+	  break;
+	case '\r':
+	  fputs_filtered ("\\r", stream);
+	  break;
+	case '\033':
+	  fputs_filtered ("\\e", stream);
+	  break;
+	case '\007':
+	  fputs_filtered ("\\a", stream);
+	  break;
+	default:
+	  fprintf_filtered (stream, "\\%.3o", (unsigned int) ch);
+	  break;
+	}
+    }
+}
 
-static m2_language m2_language_defn;
+/* Called during architecture gdbarch initialisation to create language
+   specific types.  */
 
 static void *
 build_m2_types (struct gdbarch *gdbarch)
diff --git a/gdb/m2-lang.h b/gdb/m2-lang.h
index de477e58d5a..3cf32587030 100644
--- a/gdb/m2-lang.h
+++ b/gdb/m2-lang.h
@@ -23,23 +23,13 @@
 struct type_print_options;
 struct parser_state;
 
-extern int m2_parse (struct parser_state *); /* Defined in m2-exp.y */
-
 /* Defined in m2-typeprint.c */
 extern void m2_print_type (struct type *, const char *, struct ui_file *, int,
 			   int, const struct type_print_options *);
 
-extern void m2_print_typedef (struct type *, struct symbol *,
-			      struct ui_file *);
-
 extern int m2_is_long_set (struct type *type);
 extern int m2_is_unbounded_array (struct type *type);
 
-/* Implement la_value_print_inner for Modula-2.  */
-
-extern void m2_value_print_inner (struct value *, struct ui_file *, int,
-				  const struct value_print_options *);
-
 extern int get_long_set_bounds (struct type *type, LONGEST *low,
 				LONGEST *high);
 
@@ -57,4 +47,124 @@ struct builtin_m2_type
 /* Return the Modula-2 type table for the specified architecture.  */
 extern const struct builtin_m2_type *builtin_m2_type (struct gdbarch *gdbarch);
 
+/* Class representing the M2 language.  */
+
+class m2_language : public language_defn
+{
+public:
+  m2_language ()
+    : language_defn (language_m2)
+  { /* Nothing.  */ }
+
+  /* See language.h.  */
+
+  const char *name () const override
+  { return "modula-2"; }
+
+  /* See language.h.  */
+
+  const char *natural_name () const override
+  { return "Modula-2"; }
+
+  /* See language.h.  */
+
+  void language_arch_info (struct gdbarch *gdbarch,
+			   struct language_arch_info *lai) const override;
+
+  /* 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
+  {
+    m2_print_type (type, varstring, stream, show, level, flags);
+  }
+
+  /* See language.h.  */
+
+  void value_print_inner (struct value *val, struct ui_file *stream,
+			  int recurse,
+			  const struct value_print_options *options) const override;
+
+  /* See language.h.  */
+
+  int parser (struct parser_state *ps) const override;
+
+  /* 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;
+
+  /* See language.h.  */
+
+  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;
+
+  /* See language.h.  */
+
+  void print_typedef (struct type *type, struct symbol *new_symbol,
+		      struct ui_file *stream) const override;
+
+  /* See language.h.  */
+
+  bool is_string_type_p (struct type *type) const override
+  {
+    type = check_typedef (type);
+    if (type->code () == TYPE_CODE_ARRAY
+	&& TYPE_LENGTH (type) > 0
+	&& TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0)
+      {
+	struct type *elttype = check_typedef (TYPE_TARGET_TYPE (type));
+
+	if (TYPE_LENGTH (elttype) == 1
+	    && (elttype->code () == TYPE_CODE_INT
+		|| elttype->code () == TYPE_CODE_CHAR))
+	  return true;
+      }
+
+    return false;
+  }
+
+  /* See language.h.  */
+
+  bool c_style_arrays_p () const override
+  { return false; }
+
+  /* See language.h.  Despite not having C-style arrays, Modula-2 uses 0
+     for its string lower bounds.  */
+
+  char string_lower_bound () const override
+  { return 0; }
+
+  /* See language.h.  */
+
+  bool range_checking_on_by_default () const override
+  { return true; }
+
+  /* See language.h.  */
+
+  const struct exp_descriptor *expression_ops () const override
+  { return &exp_descriptor_modula2; }
+
+  /* See language.h.  */
+
+  const struct op_print *opcode_print_table () const override
+  { return op_print_tab; }
+
+private:
+  /* Table of expression handling functions for use by EXPRESSION_OPS
+     member function.  */
+  static const struct exp_descriptor exp_descriptor_modula2;
+
+  /* Table of opcode data for use by OPCODE_PRINT_TABLE member function.  */
+  static const struct op_print op_print_tab[];
+};
+
 #endif /* M2_LANG_H */
diff --git a/gdb/m2-typeprint.c b/gdb/m2-typeprint.c
index 963d12596be..dbe112c4fcc 100644
--- a/gdb/m2-typeprint.c
+++ b/gdb/m2-typeprint.c
@@ -158,8 +158,8 @@ m2_print_type (struct type *type, const char *varstring,
    which to print.  */
 
 void
-m2_print_typedef (struct type *type, struct symbol *new_symbol,
-		  struct ui_file *stream)
+m2_language::print_typedef (struct type *type, struct symbol *new_symbol,
+			    struct ui_file *stream) const
 {
   type = check_typedef (type);
   fprintf_filtered (stream, "TYPE ");
diff --git a/gdb/m2-valprint.c b/gdb/m2-valprint.c
index 9f5ce7e9a27..64461d7c592 100644
--- a/gdb/m2-valprint.c
+++ b/gdb/m2-valprint.c
@@ -298,8 +298,9 @@ static const struct generic_val_print_decorations m2_decorations =
 /* See m2-lang.h.  */
 
 void
-m2_value_print_inner (struct value *val, struct ui_file *stream, int recurse,
-		      const struct value_print_options *options)
+m2_language::value_print_inner (struct value *val, struct ui_file *stream,
+				int recurse,
+				const struct value_print_options *options) const
 {
   unsigned len;
   struct type *elttype;
@@ -336,8 +337,8 @@ m2_value_print_inner (struct value *val, struct ui_file *stream, int recurse,
 		  len = temp_len;
 		}
 
-	      LA_PRINT_STRING (stream, TYPE_TARGET_TYPE (type),
-			       valaddr, len, NULL, 0, options);
+	      printstr (stream, TYPE_TARGET_TYPE (type), valaddr, len,
+			NULL, 0, options);
 	    }
 	  else
 	    {
@@ -445,7 +446,7 @@ m2_value_print_inner (struct value *val, struct ui_file *stream, int recurse,
       if (TYPE_LENGTH (type) == TYPE_LENGTH (TYPE_TARGET_TYPE (type)))
 	{
 	  struct value *v = value_cast (TYPE_TARGET_TYPE (type), val);
-	  m2_value_print_inner (v, stream, recurse, options);
+	  value_print_inner (v, stream, recurse, options);
 	  break;
 	}
       /* FIXME: create_static_range_type does not set the unsigned bit in a
-- 
2.25.4


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 3/9] gdb: remove LA_PRINT_TYPEDEF macro
  2020-10-12 14:46 [PATCH 0/9] Continuing Changes to Language Classes Andrew Burgess
  2020-10-12 14:46 ` [PATCH 1/9] gdb: Merge auto and unknown language implementations Andrew Burgess
  2020-10-12 14:46 ` [PATCH 2/9] gdb: move Modula2 language class into a header file Andrew Burgess
@ 2020-10-12 14:46 ` Andrew Burgess
  2020-10-12 14:46 ` [PATCH 4/9] gdb: remove LA_VALUE_PRINT macro Andrew Burgess
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Andrew Burgess @ 2020-10-12 14:46 UTC (permalink / raw)
  To: gdb-patches

Remove the LA_PRINT_TYPEDEF macro, replace the single use with the
macros definition.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* language.h (LA_PRINT_TYPEDEF): Delete.
	* typeprint.c (typedef_print): Call print_typedef directly on the
	current_language object.
---
 gdb/ChangeLog   | 6 ++++++
 gdb/language.h  | 3 ---
 gdb/typeprint.c | 2 +-
 3 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/gdb/language.h b/gdb/language.h
index 3ee6476cbbb..3452149c9ca 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -644,9 +644,6 @@ extern enum language set_language (enum language);
 #define LA_PRINT_TYPE(type,varstring,stream,show,level,flags)		\
   (current_language->print_type(type,varstring,stream,show,level,flags))
 
-#define LA_PRINT_TYPEDEF(type,new_symbol,stream) \
-  (current_language->print_typedef (type,new_symbol,stream))
-
 #define LA_VALUE_PRINT(val,stream,options) \
   (current_language->value_print (val,stream,options))
 
diff --git a/gdb/typeprint.c b/gdb/typeprint.c
index 82ca4257962..40ad239eaef 100644
--- a/gdb/typeprint.c
+++ b/gdb/typeprint.c
@@ -358,7 +358,7 @@ typedef_hash_table::find_typedef (const struct type_print_options *flags,
 void
 typedef_print (struct type *type, struct symbol *newobj, struct ui_file *stream)
 {
-  LA_PRINT_TYPEDEF (type, newobj, stream);
+  current_language->print_typedef (type, newobj, stream);
 }
 
 /* Print a description of a type TYPE in the form of a declaration of a
-- 
2.25.4


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 4/9] gdb: remove LA_VALUE_PRINT macro
  2020-10-12 14:46 [PATCH 0/9] Continuing Changes to Language Classes Andrew Burgess
                   ` (2 preceding siblings ...)
  2020-10-12 14:46 ` [PATCH 3/9] gdb: remove LA_PRINT_TYPEDEF macro Andrew Burgess
@ 2020-10-12 14:46 ` 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
                   ` (5 subsequent siblings)
  9 siblings, 1 reply; 13+ messages in thread
From: Andrew Burgess @ 2020-10-12 14:46 UTC (permalink / raw)
  To: gdb-patches

Remove the LA_VALUE_PRINT macro, and replace its uses with direct
calls to the value_print member function on an appropriate language.

In the global 'value_print' function, we call the value_print method
on the current_language, this is a direct inline replacement of the
old LA_VALUE_PRINT macro.

However, in ada-lang.c, and language.c the macro was being used
within the print_array_index member function of a language class.  In
these cases we now call the value_print member function of the current
language class.

In theory, when we are inside (for example) the
ada_language::print_array_index function the current_language should
always be set to Ada, so this change should have no effect.  However,
if we ever could get into ada_language::print_array_index with the
current language set to something else (which I think would have been
a bug) then we would now see a change in behaviour.  I couldn't find
any cases where this happened though.

There should be no user visible changes after this commit, but it is
not impossible in some edge cases.

gdb/ChangeLog:

	* ada-lang.c (ada_language::print_array_index): Call value_print
	directly.
	* language.c (language_defn::print_array_index): Likewise.
	* language.h (LA_VALUE_PRINT): Delete.
	* valprint.c (value_print): Call value_print on the
	current_language directly.
---
 gdb/ChangeLog  | 9 +++++++++
 gdb/ada-lang.c | 2 +-
 gdb/language.c | 2 +-
 gdb/language.h | 3 ---
 gdb/valprint.c | 2 +-
 5 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index be6d0e1d019..3a74de15bf6 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -13721,7 +13721,7 @@ class ada_language : public language_defn
   {
     struct value *index_value = val_atr (index_type, index);
 
-    LA_VALUE_PRINT (index_value, stream, options);
+    value_print (index_value, stream, options);
     fprintf_filtered (stream, " => ");
   }
 
diff --git a/gdb/language.c b/gdb/language.c
index ffc1e85503a..4053cb76885 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -622,7 +622,7 @@ language_defn::print_array_index (struct type *index_type, LONGEST index,
   struct value *index_value = value_from_longest (index_type, index);
 
   fprintf_filtered (stream, "[");
-  LA_VALUE_PRINT (index_value, stream, options);
+  value_print (index_value, stream, options);
   fprintf_filtered (stream, "] = ");
 }
 
diff --git a/gdb/language.h b/gdb/language.h
index 3452149c9ca..c85f90f8b4b 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -644,9 +644,6 @@ extern enum language set_language (enum language);
 #define LA_PRINT_TYPE(type,varstring,stream,show,level,flags)		\
   (current_language->print_type(type,varstring,stream,show,level,flags))
 
-#define LA_VALUE_PRINT(val,stream,options) \
-  (current_language->value_print (val,stream,options))
-
 #define LA_PRINT_CHAR(ch, type, stream) \
   (current_language->printchar (ch, type, stream))
 #define LA_PRINT_STRING(stream, elttype, string, length, encoding, force_ellipses, options) \
diff --git a/gdb/valprint.c b/gdb/valprint.c
index 0749f38983e..5d43a4cc6b1 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -1148,7 +1148,7 @@ value_print (struct value *val, struct ui_file *stream,
 	return;
     }
 
-  LA_VALUE_PRINT (val, stream, options);
+  current_language->value_print (val, stream, options);
 }
 
 static void
-- 
2.25.4


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 5/9] gdb: remove LA_PRINT_ARRAY_INDEX macro
  2020-10-12 14:46 [PATCH 0/9] Continuing Changes to Language Classes Andrew Burgess
                   ` (3 preceding siblings ...)
  2020-10-12 14:46 ` [PATCH 4/9] gdb: remove LA_VALUE_PRINT macro Andrew Burgess
@ 2020-10-12 14:46 ` Andrew Burgess
  2020-10-12 14:46 ` [PATCH 6/9] gdb: remove LA_ITERATE_OVER_SYMBOLS macro Andrew Burgess
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Andrew Burgess @ 2020-10-12 14:46 UTC (permalink / raw)
  To: gdb-patches

Replace the single use of the LA_PRINT_ARRAY_INDEX macro with the
macro's definition, and delete the macro.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* language.h (LA_PRINT_ARRAY_INDEX): Delete.
	* valprint.c (maybe_print_array_index): Replace use of macro with
	the macros definition.
---
 gdb/ChangeLog  | 6 ++++++
 gdb/language.h | 4 ----
 gdb/valprint.c | 4 ++--
 3 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/gdb/language.h b/gdb/language.h
index c85f90f8b4b..bffa9fddfee 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -652,10 +652,6 @@ extern enum language set_language (enum language);
 #define LA_EMIT_CHAR(ch, type, stream, quoter) \
   (current_language->emitchar (ch, type, stream, quoter))
 
-#define LA_PRINT_ARRAY_INDEX(index_type, index_value, stream, options)	\
-  (current_language->print_array_index(index_type, index_value, stream, \
-				       options))
-
 #define LA_ITERATE_OVER_SYMBOLS(BLOCK, NAME, DOMAIN, CALLBACK) \
   (current_language->iterate_over_symbols (BLOCK, NAME, DOMAIN, CALLBACK))
 
diff --git a/gdb/valprint.c b/gdb/valprint.c
index 5d43a4cc6b1..7c991e109d7 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -1876,8 +1876,8 @@ maybe_print_array_index (struct type *index_type, LONGEST index,
 {
   if (!options->print_array_indexes)
     return; 
-    
-  LA_PRINT_ARRAY_INDEX (index_type, index, stream, options);
+
+  current_language->print_array_index (index_type, index, stream, options);
 }
 
 /* See valprint.h.  */
-- 
2.25.4


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 6/9] gdb: remove LA_ITERATE_OVER_SYMBOLS macro
  2020-10-12 14:46 [PATCH 0/9] Continuing Changes to Language Classes Andrew Burgess
                   ` (4 preceding siblings ...)
  2020-10-12 14:46 ` [PATCH 5/9] gdb: remove LA_PRINT_ARRAY_INDEX macro Andrew Burgess
@ 2020-10-12 14:46 ` Andrew Burgess
  2020-10-12 14:46 ` [PATCH 7/9] gdb: Rename language_defn::demangle Andrew Burgess
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Andrew Burgess @ 2020-10-12 14:46 UTC (permalink / raw)
  To: gdb-patches

Replace the single use of the LA_ITERATE_OVER_SYMBOLS macro with the
macro's definition, and delete the macro.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* language.h (LA_ITERATE_OVER_SYMBOLS): Delete.
	(iterate_over_file_blocks): Replace use of macro with the macros
	definition.
---
 gdb/ChangeLog  | 6 ++++++
 gdb/language.h | 3 ---
 gdb/linespec.c | 2 +-
 3 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/gdb/language.h b/gdb/language.h
index bffa9fddfee..9d64a4ae8e9 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -652,9 +652,6 @@ extern enum language set_language (enum language);
 #define LA_EMIT_CHAR(ch, type, stream, quoter) \
   (current_language->emitchar (ch, type, stream, quoter))
 
-#define LA_ITERATE_OVER_SYMBOLS(BLOCK, NAME, DOMAIN, CALLBACK) \
-  (current_language->iterate_over_symbols (BLOCK, NAME, DOMAIN, CALLBACK))
-
 /* Test a character to decide whether it can be printed in literal form
    or needs to be printed in another representation.  For example,
    in C the literal form of the character with octal value 141 is 'a'
diff --git a/gdb/linespec.c b/gdb/linespec.c
index b05b8ad89a8..a5fd3af1e30 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -1209,7 +1209,7 @@ iterate_over_file_blocks
   for (block = BLOCKVECTOR_BLOCK (SYMTAB_BLOCKVECTOR (symtab), STATIC_BLOCK);
        block != NULL;
        block = BLOCK_SUPERBLOCK (block))
-    LA_ITERATE_OVER_SYMBOLS (block, name, domain, callback);
+    current_language->iterate_over_symbols (block, name, domain, callback);
 }
 
 /* A helper for find_method.  This finds all methods in type T of
-- 
2.25.4


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 7/9] gdb: Rename language_defn::demangle
  2020-10-12 14:46 [PATCH 0/9] Continuing Changes to Language Classes Andrew Burgess
                   ` (5 preceding siblings ...)
  2020-10-12 14:46 ` [PATCH 6/9] gdb: remove LA_ITERATE_OVER_SYMBOLS macro Andrew Burgess
@ 2020-10-12 14:46 ` Andrew Burgess
  2020-10-12 14:46 ` [PATCH 8/9] gdb: Improve documentation comment on language_defn::print_type Andrew Burgess
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Andrew Burgess @ 2020-10-12 14:46 UTC (permalink / raw)
  To: gdb-patches

GDB already has a global symbol `demangle` (a boolean), having a
language method called `demangle` is not a good idea as we often want
to reference `demangle` the control variable inside `demangle` the
member function.

This commit renames `demangle` the member function to
`demangle_symbol`.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* ada-lang.c (ada_language::demangle): Rename to...
	(ada_language::demangle_symbol): ...this.
	* c-lang.c (cplus_language::demangle): Rename to...
	(cplus_language::demangle_symbol): ...this.
	* d-lang.c (d_language::demangle): Rename to...
	(d_language::demangle_symbol): ...this.
	* f-lang.c (f_language::demangle): Rename to...
	(f_language::demangle_symbol): ...this.
	* go-lang.c (go_language::demangle): Rename to...
	(go_language::demangle_symbol): ...this.
	* language.c (language_demangle): Update call to demangle_symbol.
	(auto_or_unknown_language::demangle): Rename to...
	(auto_or_unknown_language::demangle_symbol): ...this.
	* language.h (language_defn::demangle): Rename to...
	(language_defn::demangle_symbol): ...this.
	* objc-lang.c (objc_language::demangle): Rename to...
	(objc_language::demangle_symbol): ...this.
	* rust-lang.c (rust_language::demangle): Rename to...
	(rust_language::demangle_symbol): ...this.
---
 gdb/ChangeLog   | 22 ++++++++++++++++++++++
 gdb/ada-lang.c  |  2 +-
 gdb/c-lang.c    |  2 +-
 gdb/d-lang.c    |  2 +-
 gdb/f-lang.c    |  2 +-
 gdb/go-lang.c   |  2 +-
 gdb/language.c  |  4 ++--
 gdb/language.h  |  2 +-
 gdb/objc-lang.c |  2 +-
 gdb/rust-lang.c |  2 +-
 10 files changed, 32 insertions(+), 10 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 3a74de15bf6..0a5b93f5e29 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -13869,7 +13869,7 @@ class ada_language : public language_defn
 
   /* See language.h.  */
 
-  char *demangle (const char *mangled, int options) const override
+  char *demangle_symbol (const char *mangled, int options) const override
   {
     return ada_la_decode (mangled, options);
   }
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index 4e942435177..329986ce88c 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -1120,7 +1120,7 @@ class cplus_language : public language_defn
 
   /* See language.h.  */
 
-  char *demangle (const char *mangled, int options) const override
+  char *demangle_symbol (const char *mangled, int options) const override
   {
     return gdb_demangle (mangled, options);
   }
diff --git a/gdb/d-lang.c b/gdb/d-lang.c
index f9f1a66c3c2..2537f046c16 100644
--- a/gdb/d-lang.c
+++ b/gdb/d-lang.c
@@ -225,7 +225,7 @@ class d_language : public language_defn
 
   /* See language.h.  */
 
-  char *demangle (const char *mangled, int options) const override
+  char *demangle_symbol (const char *mangled, int options) const override
   {
     return d_demangle (mangled, options);
   }
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index e13097baee4..12fe561afe4 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -779,7 +779,7 @@ class f_language : public language_defn
 
   /* See language.h.  */
 
-  char *demangle (const char *mangled, int options) const override
+  char *demangle_symbol (const char *mangled, int options) const override
   {
       /* We could support demangling here to provide module namespaces
 	 also for inferiors with only minimal symbol table (ELF symbols).
diff --git a/gdb/go-lang.c b/gdb/go-lang.c
index 0322961179f..01cd3a47690 100644
--- a/gdb/go-lang.c
+++ b/gdb/go-lang.c
@@ -586,7 +586,7 @@ class go_language : public language_defn
 
   /* See language.h.  */
 
-  char *demangle (const char *mangled, int options) const override
+  char *demangle_symbol (const char *mangled, int options) const override
   {
     return go_demangle (mangled, options);
   }
diff --git a/gdb/language.c b/gdb/language.c
index 4053cb76885..fe093789af8 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -589,7 +589,7 @@ language_demangle (const struct language_defn *current_language,
 				const char *mangled, int options)
 {
   if (current_language != NULL)
-    return current_language->demangle (mangled, options);
+    return current_language->demangle_symbol (mangled, options);
   return NULL;
 }
 
@@ -815,7 +815,7 @@ class auto_or_unknown_language : public language_defn
 
   /* See language.h.  */
 
-  char *demangle (const char *mangled, int options) const override
+  char *demangle_symbol (const char *mangled, int options) const override
   {
     /* The auto language just uses the C++ demangler.  */
     return gdb_demangle (mangled, options);
diff --git a/gdb/language.h b/gdb/language.h
index 9d64a4ae8e9..106d7667527 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -328,7 +328,7 @@ struct language_defn
   }
 
   /* Return demangled language symbol version of MANGLED, or NULL.  */
-  virtual char *demangle (const char *mangled, int options) const
+  virtual char *demangle_symbol (const char *mangled, int options) const
   {
     return nullptr;
   }
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index 009b7a7331e..16751464c67 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -363,7 +363,7 @@ class objc_language : public language_defn
 
   /* See language.h.  */
 
-  char *demangle (const char *mangled, int options) const override
+  char *demangle_symbol (const char *mangled, int options) const override
   {
     return objc_demangle (mangled, options);
   }
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index f7c762eb640..828d434d465 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -1975,7 +1975,7 @@ class rust_language : public language_defn
 
   /* See language.h.  */
 
-  char *demangle (const char *mangled, int options) const override
+  char *demangle_symbol (const char *mangled, int options) const override
   {
     return gdb_demangle (mangled, options);
   }
-- 
2.25.4


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 8/9] gdb: Improve documentation comment on language_defn::print_type
  2020-10-12 14:46 [PATCH 0/9] Continuing Changes to Language Classes Andrew Burgess
                   ` (6 preceding siblings ...)
  2020-10-12 14:46 ` [PATCH 7/9] gdb: Rename language_defn::demangle Andrew Burgess
@ 2020-10-12 14:46 ` 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
  9 siblings, 0 replies; 13+ messages in thread
From: Andrew Burgess @ 2020-10-12 14:46 UTC (permalink / raw)
  To: gdb-patches

Improves the comment at the declaration of language_defn::print_type.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* language.h (language_defn::print_type): Add variable names in
	declaration, and update header comment.
---
 gdb/ChangeLog  |  5 +++++
 gdb/language.h | 12 ++++++++----
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/gdb/language.h b/gdb/language.h
index 106d7667527..951343fd9a3 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -333,10 +333,14 @@ struct language_defn
     return nullptr;
   }
 
-  /* Print a type using syntax appropriate for this language.  */
-
-  virtual void print_type (struct type *, const char *, struct ui_file *, int,
-			   int, const struct type_print_options *) const = 0;
+  /* Print TYPE to STREAM using syntax appropriate for this language.
+     LEVEL is the depth to indent lines by.  VARSTRING, if not NULL or the
+     empty string, is the name of a variable and TYPE should be printed in
+     the form of a declaration of a variable named VARSTRING.  */
+
+  virtual void print_type (struct type *type, const char *varstring,
+			   struct ui_file *stream, int show, int level,
+			   const struct type_print_options *flags) const = 0;
 
   /* PC is possibly an unknown languages trampoline.
      If that PC falls in a trampoline belonging to this language, return
-- 
2.25.4


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 9/9] gdb: move f_language class into a header file
  2020-10-12 14:46 [PATCH 0/9] Continuing Changes to Language Classes Andrew Burgess
                   ` (7 preceding siblings ...)
  2020-10-12 14:46 ` [PATCH 8/9] gdb: Improve documentation comment on language_defn::print_type Andrew Burgess
@ 2020-10-12 14:46 ` Andrew Burgess
  2020-10-20 20:07 ` [PATCH 0/9] Continuing Changes to Language Classes Tom Tromey
  9 siblings, 0 replies; 13+ messages in thread
From: Andrew Burgess @ 2020-10-12 14:46 UTC (permalink / raw)
  To: gdb-patches

Moves the f_language class from f-lang.c into f-lang.h.  The benefit
of this is that functions declared in other f-*.c files can become
member functions without having to go through a level of indirection.

Some additional support functions have now become private member
functions of the f_language class, these are mostly functions that
then called some other function that was itself a member of the
language_defn class hierarchy.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* f-exp.y (f_parse): Rename to...
	(f_language::parser): ...this.
	* f-lang.c (f_get_encoding): Rename to...
	(f_language::get_encoding): ...this.
	(f_op_print_tab): Rename to...
	(f_language::op_print_tab): ...this.
	(exp_descriptor_f): Rename to...
	(f_language::exp_descriptor_tab): ...this.
	(class f_language): Moved to f-lang.h.
	(f_language::language_arch_info): New function, moved out of class
	declaration.
	(f_language::search_name_hash): Likewise.
	(f_language::lookup_symbol_nonlocal): Likewise.
	(f_language::get_symbol_name_matcher_inner): Likewise.
	* f-lang.h: Add 'valprint.h' include.
	(class f_language): Moved here from f-lang.c.
	* f-typeprint.c (f_type_print_args): Delete commented out
	declaration.
	(f_print_typedef): Rename to...
	(f_language::print_typedef): ...this.
	(f_print_type): Rename to...
	(f_language::print_type): ...this.
	(f_type_print_varspec_prefix): Delete declaration and rename to...
	(f_language::f_type_print_varspec_prefix): ...this.
	(f_type_print_varspec_suffix): Delete declaration and rename to...
	(f_language::f_type_print_varspec_suffix): ...this.
	(f_type_print_base): Delete declaration and rename to...
	(f_language::f_type_print_base): ...this.
	* f-valprint.c (f_value_print_inner): Rename to...
	(f_language::value_print_inner): ...this.
	* parse.c: Delete 'f-lang.h' include.
---
 gdb/ChangeLog     |  34 +++++
 gdb/f-exp.y       |   2 +-
 gdb/f-lang.c      | 320 +++++++++-------------------------------------
 gdb/f-lang.h      | 272 +++++++++++++++++++++++++++++++++++++--
 gdb/f-typeprint.c |  82 ++++--------
 gdb/f-valprint.c  |   5 +-
 gdb/parse.c       |   1 -
 7 files changed, 387 insertions(+), 329 deletions(-)

diff --git a/gdb/f-exp.y b/gdb/f-exp.y
index 0ccb3c68d3e..88f622cf8ec 100644
--- a/gdb/f-exp.y
+++ b/gdb/f-exp.y
@@ -1343,7 +1343,7 @@ yylex (void)
 }
 
 int
-f_parse (struct parser_state *par_state)
+f_language::parser (struct parser_state *par_state) const
 {
   /* Setting up the parser state.  */
   scoped_restore pstate_restore = make_scoped_restore (&pstate);
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index 12fe561afe4..c70b2bcaebe 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -44,8 +44,8 @@
 /* Return the encoding that should be used for the character type
    TYPE.  */
 
-static const char *
-f_get_encoding (struct type *type)
+const char *
+f_language::get_encoding (struct type *type)
 {
   const char *encoding;
 
@@ -72,7 +72,7 @@ f_get_encoding (struct type *type)
 
 /* Table of operators and their precedences for printing expressions.  */
 
-static const struct op_print f_op_print_tab[] =
+const struct op_print f_language::op_print_tab[] =
 {
   {"+", BINOP_ADD, PREC_ADD, 0},
   {"+", UNOP_PLUS, PREC_PREFIX, 0},
@@ -693,7 +693,7 @@ operator_check_f (struct expression *exp, int pos,
 }
 
 /* Expression processing for Fortran.  */
-static const struct exp_descriptor exp_descriptor_f =
+const struct exp_descriptor f_language::exp_descriptor_tab =
 {
   print_subexp_f,
   operator_length_f,
@@ -703,268 +703,72 @@ static const struct exp_descriptor exp_descriptor_f =
   evaluate_subexp_f
 };
 
-/* Class representing the Fortran language.  */
+/* See language.h.  */
 
-class f_language : public language_defn
+void
+f_language::language_arch_info (struct gdbarch *gdbarch,
+				struct language_arch_info *lai) const
 {
-public:
-  f_language ()
-    : language_defn (language_fortran)
-  { /* Nothing.  */ }
-
-  /* See language.h.  */
-
-  const char *name () const override
-  { return "fortran"; }
-
-  /* See language.h.  */
-
-  const char *natural_name () const override
-  { return "Fortran"; }
-
-  /* See language.h.  */
-
-  const std::vector<const char *> &filename_extensions () const override
-  {
-    static const std::vector<const char *> extensions = {
-      ".f", ".F", ".for", ".FOR", ".ftn", ".FTN", ".fpp", ".FPP",
-      ".f90", ".F90", ".f95", ".F95", ".f03", ".F03", ".f08", ".F08"
-    };
-    return extensions;
-  }
-
-  /* See language.h.  */
-  void language_arch_info (struct gdbarch *gdbarch,
-			   struct language_arch_info *lai) const override
-  {
-    const struct builtin_f_type *builtin = builtin_f_type (gdbarch);
-
-    lai->string_char_type = builtin->builtin_character;
-    lai->primitive_type_vector
-      = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_f_primitive_types + 1,
-				struct type *);
-
-    lai->primitive_type_vector [f_primitive_type_character]
-      = builtin->builtin_character;
-    lai->primitive_type_vector [f_primitive_type_logical]
-      = builtin->builtin_logical;
-    lai->primitive_type_vector [f_primitive_type_logical_s1]
-      = builtin->builtin_logical_s1;
-    lai->primitive_type_vector [f_primitive_type_logical_s2]
-      = builtin->builtin_logical_s2;
-    lai->primitive_type_vector [f_primitive_type_logical_s8]
-      = builtin->builtin_logical_s8;
-    lai->primitive_type_vector [f_primitive_type_real]
-      = builtin->builtin_real;
-    lai->primitive_type_vector [f_primitive_type_real_s8]
-      = builtin->builtin_real_s8;
-    lai->primitive_type_vector [f_primitive_type_real_s16]
-      = builtin->builtin_real_s16;
-    lai->primitive_type_vector [f_primitive_type_complex_s8]
-      = builtin->builtin_complex_s8;
-    lai->primitive_type_vector [f_primitive_type_complex_s16]
-      = builtin->builtin_complex_s16;
-    lai->primitive_type_vector [f_primitive_type_void]
-      = builtin->builtin_void;
-
-    lai->bool_type_symbol = "logical";
-    lai->bool_type_default = builtin->builtin_logical_s2;
-  }
-
-  /* See language.h.  */
-  unsigned int search_name_hash (const char *name) const override
-  {
-    return cp_search_name_hash (name);
-  }
-
-  /* See language.h.  */
-
-  char *demangle_symbol (const char *mangled, int options) const override
-  {
-      /* We could support demangling here to provide module namespaces
-	 also for inferiors with only minimal symbol table (ELF symbols).
-	 Just the mangling standard is not standardized across compilers
-	 and there is no DW_AT_producer available for inferiors with only
-	 the ELF symbols to check the mangling kind.  */
-    return nullptr;
-  }
-
-  /* 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
-  {
-    f_print_type (type, varstring, stream, show, level, flags);
-  }
-
-  /* See language.h.  This just returns default set of word break
-     characters but with the modules separator `::' removed.  */
-
-  const char *word_break_characters (void) const override
-  {
-    static char *retval;
-
-    if (!retval)
-      {
-	char *s;
-
-	retval = xstrdup (language_defn::word_break_characters ());
-	s = strchr (retval, ':');
-	if (s)
-	  {
-	    char *last_char = &s[strlen (s) - 1];
-
-	    *s = *last_char;
-	    *last_char = 0;
-	  }
-      }
-    return retval;
-  }
-
-
-  /* See language.h.  */
-
-  void collect_symbol_completion_matches (completion_tracker &tracker,
-					  complete_symbol_mode mode,
-					  symbol_name_match_type name_match_type,
-					  const char *text, const char *word,
-					  enum type_code code) const override
-  {
-    /* Consider the modules separator :: as a valid symbol name character
-       class.  */
-    default_collect_symbol_completion_matches_break_on (tracker, mode,
-							name_match_type,
-							text, word, ":",
-							code);
-  }
-
-  /* See language.h.  */
-
-  void value_print_inner
-	(struct value *val, struct ui_file *stream, int recurse,
-	 const struct value_print_options *options) const override
-  {
-    return f_value_print_inner (val, stream, recurse, options);
-  }
-
-  /* See language.h.  */
-
-  struct block_symbol lookup_symbol_nonlocal
-	(const char *name, const struct block *block,
-	 const domain_enum domain) const override
-  {
-    return cp_lookup_symbol_nonlocal (this, name, block, domain);
-  }
-
-  /* See language.h.  */
-
-  int parser (struct parser_state *ps) const override
-  {
-    return f_parse (ps);
-  }
-
-  /* See language.h.  */
-
-  void emitchar (int ch, struct type *chtype,
-		 struct ui_file *stream, int quoter) const override
-  {
-    const char *encoding = f_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
-  {
-    fputs_filtered ("'", stream);
-    LA_EMIT_CHAR (ch, chtype, stream, '\'');
-    fputs_filtered ("'", stream);
-  }
-
-  /* See language.h.  */
-
-  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
-  {
-    const char *type_encoding = f_get_encoding (elttype);
-
-    if (TYPE_LENGTH (elttype) == 4)
-      fputs_filtered ("4_", stream);
-
-    if (!encoding || !*encoding)
-      encoding = type_encoding;
-
-    generic_printstr (stream, elttype, string, length, encoding,
-		      force_ellipses, '\'', 0, options);
-  }
-
-  /* See language.h.  */
-
-  void print_typedef (struct type *type, struct symbol *new_symbol,
-		      struct ui_file *stream) const override
-  {
-    f_print_typedef (type, new_symbol, stream);
-  }
-
-  /* See language.h.  */
-
-  bool is_string_type_p (struct type *type) const override
-  {
-    type = check_typedef (type);
-    return (type->code () == TYPE_CODE_STRING
-	    || (type->code () == TYPE_CODE_ARRAY
-		&& TYPE_TARGET_TYPE (type)->code () == TYPE_CODE_CHAR));
-  }
-
-  /* See language.h.  */
-
-  const char *struct_too_deep_ellipsis () const override
-  { return "(...)"; }
-
-  /* See language.h.  */
-
-  bool c_style_arrays_p () const override
-  { return false; }
-
-  /* See language.h.  */
-
-  bool range_checking_on_by_default () const override
-  { return true; }
-
-  /* See language.h.  */
-
-  enum case_sensitivity case_sensitivity () const override
-  { return case_sensitive_off; }
-
-  /* See language.h.  */
-
-  enum array_ordering array_ordering () const override
-  { return array_column_major; }
-
-  /* See language.h.  */
+  const struct builtin_f_type *builtin = builtin_f_type (gdbarch);
+
+  lai->string_char_type = builtin->builtin_character;
+  lai->primitive_type_vector
+    = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_f_primitive_types + 1,
+			      struct type *);
+
+  lai->primitive_type_vector [f_primitive_type_character]
+    = builtin->builtin_character;
+  lai->primitive_type_vector [f_primitive_type_logical]
+    = builtin->builtin_logical;
+  lai->primitive_type_vector [f_primitive_type_logical_s1]
+    = builtin->builtin_logical_s1;
+  lai->primitive_type_vector [f_primitive_type_logical_s2]
+    = builtin->builtin_logical_s2;
+  lai->primitive_type_vector [f_primitive_type_logical_s8]
+    = builtin->builtin_logical_s8;
+  lai->primitive_type_vector [f_primitive_type_real]
+    = builtin->builtin_real;
+  lai->primitive_type_vector [f_primitive_type_real_s8]
+    = builtin->builtin_real_s8;
+  lai->primitive_type_vector [f_primitive_type_real_s16]
+    = builtin->builtin_real_s16;
+  lai->primitive_type_vector [f_primitive_type_complex_s8]
+    = builtin->builtin_complex_s8;
+  lai->primitive_type_vector [f_primitive_type_complex_s16]
+    = builtin->builtin_complex_s16;
+  lai->primitive_type_vector [f_primitive_type_void]
+    = builtin->builtin_void;
+
+  lai->bool_type_symbol = "logical";
+  lai->bool_type_default = builtin->builtin_logical_s2;
+}
 
-  const struct exp_descriptor *expression_ops () const override
-  { return &exp_descriptor_f; }
+/* See language.h.  */
 
-  /* See language.h.  */
+unsigned int
+f_language::search_name_hash (const char *name) const
+{
+  return cp_search_name_hash (name);
+}
 
-  const struct op_print *opcode_print_table () const override
-  { return f_op_print_tab; }
+/* See language.h.  */
 
-protected:
+struct block_symbol
+f_language::lookup_symbol_nonlocal (const char *name,
+				    const struct block *block,
+				    const domain_enum domain) const
+{
+  return cp_lookup_symbol_nonlocal (this, name, block, domain);
+}
 
-  /* See language.h.  */
+/* See language.h.  */
 
-  symbol_name_matcher_ftype *get_symbol_name_matcher_inner
-	(const lookup_name_info &lookup_name) const override
-  {
-    return cp_get_symbol_name_matcher (lookup_name);
-  }
-};
+symbol_name_matcher_ftype *
+f_language::get_symbol_name_matcher_inner
+	(const lookup_name_info &lookup_name) const
+{
+  return cp_get_symbol_name_matcher (lookup_name);
+}
 
 /* Single instance of the Fortran language class.  */
 
diff --git a/gdb/f-lang.h b/gdb/f-lang.h
index 4710b14aa62..e59fdef1b19 100644
--- a/gdb/f-lang.h
+++ b/gdb/f-lang.h
@@ -23,24 +23,276 @@
 #ifndef F_LANG_H
 #define F_LANG_H
 
+#include "valprint.h"
+
 struct type_print_options;
 struct parser_state;
 
-extern int f_parse (struct parser_state *);
+/* Class representing the Fortran language.  */
+
+class f_language : public language_defn
+{
+public:
+  f_language ()
+    : language_defn (language_fortran)
+  { /* Nothing.  */ }
+
+  /* See language.h.  */
+
+  const char *name () const override
+  { return "fortran"; }
+
+  /* See language.h.  */
+
+  const char *natural_name () const override
+  { return "Fortran"; }
+
+  /* See language.h.  */
+
+  const std::vector<const char *> &filename_extensions () const override
+  {
+    static const std::vector<const char *> extensions = {
+      ".f", ".F", ".for", ".FOR", ".ftn", ".FTN", ".fpp", ".FPP",
+      ".f90", ".F90", ".f95", ".F95", ".f03", ".F03", ".f08", ".F08"
+    };
+    return extensions;
+  }
+
+  /* See language.h.  */
+  void language_arch_info (struct gdbarch *gdbarch,
+			   struct language_arch_info *lai) const override;
+
+  /* See language.h.  */
+  unsigned int search_name_hash (const char *name) const override;
+
+  /* See language.h.  */
+
+  char *demangle_symbol (const char *mangled, int options) const override
+  {
+      /* We could support demangling here to provide module namespaces
+	 also for inferiors with only minimal symbol table (ELF symbols).
+	 Just the mangling standard is not standardized across compilers
+	 and there is no DW_AT_producer available for inferiors with only
+	 the ELF symbols to check the mangling kind.  */
+    return nullptr;
+  }
+
+  /* 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;
+
+  /* See language.h.  This just returns default set of word break
+     characters but with the modules separator `::' removed.  */
+
+  const char *word_break_characters (void) const override
+  {
+    static char *retval;
+
+    if (!retval)
+      {
+	char *s;
+
+	retval = xstrdup (language_defn::word_break_characters ());
+	s = strchr (retval, ':');
+	if (s)
+	  {
+	    char *last_char = &s[strlen (s) - 1];
+
+	    *s = *last_char;
+	    *last_char = 0;
+	  }
+      }
+    return retval;
+  }
+
+
+  /* See language.h.  */
+
+  void collect_symbol_completion_matches (completion_tracker &tracker,
+					  complete_symbol_mode mode,
+					  symbol_name_match_type name_match_type,
+					  const char *text, const char *word,
+					  enum type_code code) const override
+  {
+    /* Consider the modules separator :: as a valid symbol name character
+       class.  */
+    default_collect_symbol_completion_matches_break_on (tracker, mode,
+							name_match_type,
+							text, word, ":",
+							code);
+  }
+
+  /* See language.h.  */
+
+  void value_print_inner
+	(struct value *val, struct ui_file *stream, int recurse,
+	 const struct value_print_options *options) const override;
+
+  /* See language.h.  */
+
+  struct block_symbol lookup_symbol_nonlocal
+	(const char *name, const struct block *block,
+	 const domain_enum domain) const override;
+
+  /* See language.h.  */
+
+  int parser (struct parser_state *ps) const override;
+
+  /* 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
+  {
+    fputs_filtered ("'", stream);
+    LA_EMIT_CHAR (ch, chtype, stream, '\'');
+    fputs_filtered ("'", stream);
+  }
+
+  /* See language.h.  */
+
+  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
+  {
+    const char *type_encoding = get_encoding (elttype);
+
+    if (TYPE_LENGTH (elttype) == 4)
+      fputs_filtered ("4_", stream);
+
+    if (!encoding || !*encoding)
+      encoding = type_encoding;
+
+    generic_printstr (stream, elttype, string, length, encoding,
+		      force_ellipses, '\'', 0, options);
+  }
 
-/* Implement the la_print_typedef language method for Fortran.  */
+  /* See language.h.  */
 
-extern void f_print_typedef (struct type *type, struct symbol *new_symbol,
-			     struct ui_file *stream);
+  void print_typedef (struct type *type, struct symbol *new_symbol,
+		      struct ui_file *stream) const override;
 
-extern void f_print_type (struct type *, const char *, struct ui_file *, int,
-			  int, const struct type_print_options *);
+  /* See language.h.  */
 
-/* Implement la_value_print_inner for Fortran.  */
+  bool is_string_type_p (struct type *type) const override
+  {
+    type = check_typedef (type);
+    return (type->code () == TYPE_CODE_STRING
+	    || (type->code () == TYPE_CODE_ARRAY
+		&& TYPE_TARGET_TYPE (type)->code () == TYPE_CODE_CHAR));
+  }
 
-extern void f_value_print_inner (struct value *val, struct ui_file *stream,
-				  int recurse,
-				  const struct value_print_options *options);
+  /* See language.h.  */
+
+  const char *struct_too_deep_ellipsis () const override
+  { return "(...)"; }
+
+  /* See language.h.  */
+
+  bool c_style_arrays_p () const override
+  { return false; }
+
+  /* See language.h.  */
+
+  bool range_checking_on_by_default () const override
+  { return true; }
+
+  /* See language.h.  */
+
+  enum case_sensitivity case_sensitivity () const override
+  { return case_sensitive_off; }
+
+  /* See language.h.  */
+
+  enum array_ordering array_ordering () const override
+  { return array_column_major; }
+
+  /* See language.h.  */
+
+  const struct exp_descriptor *expression_ops () const override
+  { return &exp_descriptor_tab; }
+
+  /* See language.h.  */
+
+  const struct op_print *opcode_print_table () const override
+  { return op_print_tab; }
+
+protected:
+
+  /* See language.h.  */
+
+  symbol_name_matcher_ftype *get_symbol_name_matcher_inner
+	(const lookup_name_info &lookup_name) const override;
+
+private:
+  /* Table of expression handling functions for use by EXPRESSION_OPS
+     member function.  */
+
+  static const struct exp_descriptor exp_descriptor_tab;
+
+  /* Table of opcode data for use by OPCODE_PRINT_TABLE member function.  */
+
+  static const struct op_print op_print_tab[];
+
+  /* Return the encoding that should be used for the character type
+     TYPE.  */
+
+  static const char *get_encoding (struct type *type);
+
+  /* Print any asterisks or open-parentheses needed before the variable
+     name (to describe its type).
+
+     On outermost call, pass 0 for PASSED_A_PTR.
+     On outermost call, SHOW > 0 means should ignore
+     any typename for TYPE and show its details.
+     SHOW is always zero on recursive calls.  */
+
+  void f_type_print_varspec_prefix (struct type *type,
+				    struct ui_file * stream,
+				    int show, int passed_a_ptr) const;
+
+  /* Print any array sizes, function arguments or close parentheses needed
+     after the variable name (to describe its type).  Args work like
+     c_type_print_varspec_prefix.
+
+     PRINT_RANK_ONLY is true when TYPE is an array which should be printed
+     without the upper and lower bounds being specified, this will occur
+     when the array is not allocated or not associated and so there are no
+     known upper or lower bounds.  */
+
+  void f_type_print_varspec_suffix (struct type *type,
+				    struct ui_file *stream,
+				    int show, int passed_a_ptr,
+				    int demangled_args,
+				    int arrayprint_recurse_level,
+				    bool print_rank_only) const;
+
+  /* Print the name of the type (or the ultimate pointer target, function
+     value or array element), or the description of a structure or union.
+
+     SHOW nonzero means don't print this type as just its name;
+     show its real definition even if it has a name.
+     SHOW zero means print just typename or struct tag if there is one
+     SHOW negative means abbreviate structure elements.
+     SHOW is decremented for printing of structure elements.
+
+     LEVEL is the depth to indent by.  We increase it for some recursive
+     calls.  */
+
+  void f_type_print_base (struct type *type, struct ui_file *stream, int show,
+			  int level) const;
+};
 
 /* Language-specific data structures */
 
diff --git a/gdb/f-typeprint.c b/gdb/f-typeprint.c
index 577ed3b9d24..0e8bbd61498 100644
--- a/gdb/f-typeprint.c
+++ b/gdb/f-typeprint.c
@@ -33,34 +33,22 @@
 #include "typeprint.h"
 #include "cli/cli-style.h"
 
-#if 0				/* Currently unused.  */
-static void f_type_print_args (struct type *, struct ui_file *);
-#endif
-
-static void f_type_print_varspec_suffix (struct type *, struct ui_file *, int,
-					 int, int, int, bool);
-
-void f_type_print_varspec_prefix (struct type *, struct ui_file *,
-				  int, int);
-
-void f_type_print_base (struct type *, struct ui_file *, int, int);
-\f
-
-/* See documentation in f-lang.h.  */
+/* See f-lang.h.  */
 
 void
-f_print_typedef (struct type *type, struct symbol *new_symbol,
-		 struct ui_file *stream)
+f_language::print_typedef (struct type *type, struct symbol *new_symbol,
+			   struct ui_file *stream) const
 {
   type = check_typedef (type);
-  f_print_type (type, "", stream, 0, 0, &type_print_raw_options);
+  print_type (type, "", stream, 0, 0, &type_print_raw_options);
 }
 
-/* LEVEL is the depth to indent lines by.  */
+/* See f-lang.h.  */
 
 void
-f_print_type (struct type *type, const char *varstring, struct ui_file *stream,
-	      int show, int level, const struct type_print_options *flags)
+f_language::print_type (struct type *type, const char *varstring,
+			struct ui_file *stream, int show, int level,
+			const struct type_print_options *flags) const
 {
   enum type_code code;
 
@@ -99,17 +87,12 @@ f_print_type (struct type *type, const char *varstring, struct ui_file *stream,
    }
 }
 
-/* Print any asterisks or open-parentheses needed before the
-   variable name (to describe its type).
-
-   On outermost call, pass 0 for PASSED_A_PTR.
-   On outermost call, SHOW > 0 means should ignore
-   any typename for TYPE and show its details.
-   SHOW is always zero on recursive calls.  */
+/* See f-lang.h.  */
 
 void
-f_type_print_varspec_prefix (struct type *type, struct ui_file *stream,
-			     int show, int passed_a_ptr)
+f_language::f_type_print_varspec_prefix (struct type *type,
+					 struct ui_file *stream,
+					 int show, int passed_a_ptr) const
 {
   if (type == 0)
     return;
@@ -158,19 +141,15 @@ f_type_print_varspec_prefix (struct type *type, struct ui_file *stream,
     }
 }
 
-/* Print any array sizes, function arguments or close parentheses
-   needed after the variable name (to describe its type).
-   Args work like c_type_print_varspec_prefix.
+/* See f-lang.h.  */
 
-   PRINT_RANK_ONLY is true when TYPE is an array which should be printed
-   without the upper and lower bounds being specified, this will occur
-   when the array is not allocated or not associated and so there are no
-   known upper or lower bounds.  */
-
-static void
-f_type_print_varspec_suffix (struct type *type, struct ui_file *stream,
-			     int show, int passed_a_ptr, int demangled_args,
-			     int arrayprint_recurse_level, bool print_rank_only)
+void
+f_language::f_type_print_varspec_suffix (struct type *type,
+					 struct ui_file *stream,
+					 int show, int passed_a_ptr,
+					 int demangled_args,
+					 int arrayprint_recurse_level,
+					 bool print_rank_only) const
 {
   /* No static variables are permitted as an error call may occur during
      execution of this function.  */
@@ -263,7 +242,7 @@ f_type_print_varspec_suffix (struct type *type, struct ui_file *stream,
 	  fprintf_filtered (stream, ") ");
 	fprintf_filtered (stream, "(");
 	if (nfields == 0 && type->is_prototyped ())
-	  f_print_type (builtin_f_type (get_type_arch (type))->builtin_void,
+	  print_type (builtin_f_type (get_type_arch (type))->builtin_void,
 			"", stream, -1, 0, 0);
 	else
 	  for (i = 0; i < nfields; i++)
@@ -273,7 +252,7 @@ f_type_print_varspec_suffix (struct type *type, struct ui_file *stream,
 		  fputs_filtered (", ", stream);
 		  wrap_here ("    ");
 		}
-	      f_print_type (type->field (i).type (), "", stream, -1, 0, 0);
+	      print_type (type->field (i).type (), "", stream, -1, 0, 0);
 	    }
 	fprintf_filtered (stream, ")");
       }
@@ -301,22 +280,11 @@ f_type_print_varspec_suffix (struct type *type, struct ui_file *stream,
     }
 }
 
-/* Print the name of the type (or the ultimate pointer target,
-   function value or array element), or the description of a
-   structure or union.
-
-   SHOW nonzero means don't print this type as just its name;
-   show its real definition even if it has a name.
-   SHOW zero means print just typename or struct tag if there is one
-   SHOW negative means abbreviate structure elements.
-   SHOW is decremented for printing of structure elements.
-
-   LEVEL is the depth to indent by.
-   We increase it for some recursive calls.  */
+/* See f-lang.h.  */
 
 void
-f_type_print_base (struct type *type, struct ui_file *stream, int show,
-		   int level)
+f_language::f_type_print_base (struct type *type, struct ui_file *stream,
+			       int show, int level) const
 {
   int index;
 
diff --git a/gdb/f-valprint.c b/gdb/f-valprint.c
index e7dc20d0ea5..95630a76d7d 100644
--- a/gdb/f-valprint.c
+++ b/gdb/f-valprint.c
@@ -214,8 +214,9 @@ static const struct generic_val_print_decorations f_decorations =
 /* See f-lang.h.  */
 
 void
-f_value_print_inner (struct value *val, struct ui_file *stream, int recurse,
-		      const struct value_print_options *options)
+f_language::value_print_inner (struct value *val, struct ui_file *stream,
+			       int recurse,
+			       const struct value_print_options *options) const
 {
   struct type *type = check_typedef (value_type (val));
   struct gdbarch *gdbarch = get_type_arch (type);
diff --git a/gdb/parse.c b/gdb/parse.c
index 6b9541bfdc2..932b7f6e3db 100644
--- a/gdb/parse.c
+++ b/gdb/parse.c
@@ -39,7 +39,6 @@
 #include "value.h"
 #include "command.h"
 #include "language.h"
-#include "f-lang.h"
 #include "parser-defs.h"
 #include "gdbcmd.h"
 #include "symfile.h"		/* for overlay functions */
-- 
2.25.4


^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 2/9] gdb: move Modula2 language class into a header file
  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
  0 siblings, 0 replies; 13+ messages in thread
From: Gaius Mulley @ 2020-10-13  9:58 UTC (permalink / raw)
  To: Andrew Burgess; +Cc: gdb-patches

Andrew Burgess <andrew.burgess@embecosm.com> writes:

> Move the m2_language class from m2-lang.c into m2-lang.h.  The benefit
> of this move is that we can remove trampoline functions.  Currently
> the language implementation is split of different m2-* files with
> m2-lang.h including declaration for all the language implementation
> functions.
>
> Currently the m2_language class in m2-lang.c has member functions that
> then call the global functions declared in m2-lang.h.
>
> After this change the m2_language class is declared in m2-lang.h, and
> the member functions are the implementations defined in all the m2-*
> files.
>
> There should be no user visible changes after this commit.
>
> gdb/ChangeLog:
>
>         * m2-exp.y (m2_parse): Rename to...
>         (m2_language::parser): ...this.  Update function signature.
>         * m2-lang.c (m2_printchar): Renamed to m2_language::printchar.
>         (m2_op_print): Rename to...
>         (m2_language::op_print_tab): ...this, and make const.
>         (exp_descriptor_modula2): Rename to...
>         (m2_language::exp_descriptor_modula2): ...this.
>         (class m2_language): Move to m2-lang.h.
>         (m2_language::language_arch_info): New function, moved out of
>         class declaration.
>         (m2_language::printchar): New function, body from m2_printchar.
>         (m2_language::printstr): New function, moved out of class
>         declaration.
>         (m2_language::emitchar): Likewise.
>         * m2-lang.h (m2_parse): Delete declaration.
>         (m2_print_typedef): Delete declaration.
>         (m2_value_print_inner): Delete declaration.
>         (class m2_language): Class declaration moved from m2-lang.c,
>         larger functions are left in m2-lang.c.
>         * m2-typeprint.c (m2_print_typedef): Rename to...
>         (m2_language::print_typedef): ...this, and update function
>         signature.
>         * m2-valprint.c (m2_value_print_inner): Rename to...
>         (m2_language::value_print_inner): ...this, replace use of
>         LA_PRINT_STRING with a direct call to printstr member function,
>         and update recursive call.

Hi Andrew,

all looks good to me - thanks for tidying up the code and rationalising
the method names,


regards,
Gaius

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 4/9] gdb: remove LA_VALUE_PRINT macro
  2020-10-12 14:46 ` [PATCH 4/9] gdb: remove LA_VALUE_PRINT macro Andrew Burgess
@ 2020-10-20 20:06   ` Tom Tromey
  0 siblings, 0 replies; 13+ messages in thread
From: Tom Tromey @ 2020-10-20 20:06 UTC (permalink / raw)
  To: Andrew Burgess; +Cc: gdb-patches

Andrew> In theory, when we are inside (for example) the
Andrew> ada_language::print_array_index function the current_language should
Andrew> always be set to Ada, so this change should have no effect.  However,
Andrew> if we ever could get into ada_language::print_array_index with the
Andrew> current language set to something else (which I think would have been
Andrew> a bug) then we would now see a change in behaviour.  I couldn't find
Andrew> any cases where this happened though.

I suspect this particular case was just for uniformity.

In the C value-printing code, though, sometimes calls are indirected via
the current language because other languages call into the C
implementation.

There's nothing sacred about that, though, and it's always been a bit ugly.
Cleaning it up as is done in this patch seems like a plus to me.

Tom

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 0/9] Continuing Changes to Language Classes
  2020-10-12 14:46 [PATCH 0/9] Continuing Changes to Language Classes Andrew Burgess
                   ` (8 preceding siblings ...)
  2020-10-12 14:46 ` [PATCH 9/9] gdb: move f_language class into a header file Andrew Burgess
@ 2020-10-20 20:07 ` Tom Tromey
  9 siblings, 0 replies; 13+ messages in thread
From: Tom Tromey @ 2020-10-20 20:07 UTC (permalink / raw)
  To: Andrew Burgess; +Cc: gdb-patches

>>>>> "Andrew" == Andrew Burgess <andrew.burgess@embecosm.com> writes:

Andrew> Patches #1, #2, and #9 are all about improving the C++ classes used to
Andrew> represent languages in GDB.

Andrew> Patches #3 -> #8 are other language related cleanups.

I read through these and they all seem fine to me.  Thank you for doing
this.  I'm particularly glad to see LA_ macros removed.

Tom

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2020-10-20 20:07 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-12 14:46 [PATCH 0/9] Continuing Changes to Language Classes Andrew Burgess
2020-10-12 14:46 ` [PATCH 1/9] gdb: Merge auto and unknown language implementations Andrew Burgess
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

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).