public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 0/7] Language Class Hierarchy Conversion (Prt 3)
@ 2020-06-18 22:31 Andrew Burgess
  2020-06-18 22:31 ` [PATCH 1/7] gdb: Convert language la_parser field to a method Andrew Burgess
                   ` (7 more replies)
  0 siblings, 8 replies; 10+ messages in thread
From: Andrew Burgess @ 2020-06-18 22:31 UTC (permalink / raw)
  To: gdb-patches

In this third patch set I convert the last remaining function pointers
in the language_base structure into member function in language_defn.

There wasn't anything particularaly tricky in this batch.

After this set my plans are (in no particular order):

  - Convert at least some of the data members in language_base into
    member function in language_defn.

  - Move some of the language classes into header files so that member
    functions can be defined in different .c files.  This will allow
    me to remove most of the member functions that currently just
    redirect to a function in another file.

  - Possibly restructure the language class hierarchy to increase the
    amount of sharing that exists between similar languages.

  - Make more of the per-language helper functions private functions
    within the language classes.

Thoughts, feedback, or ideas always welcome.

Thanks,
Andrew

---

Andrew Burgess (7):
  gdb: Convert language la_parser field to a method
  gdb: Convert language la_post_parser field to a method
  gdb: Convert language la_emitchar field to a method
  gdb: Convert language la_printchar field to a method
  gdb: Convert language la_printstr field to a method
  gdb: Convert language la_print_typedef field to a method
  gdb: Convert language la_is_string_type_p field to a method

 gdb/ChangeLog     | 271 ++++++++++++++++++++++++++++++++++++++
 gdb/ada-lang.c    | 118 ++++++++++-------
 gdb/c-lang.c      |  28 ----
 gdb/d-lang.c      |  15 +--
 gdb/f-lang.c      | 132 +++++++++----------
 gdb/go-lang.c     |  35 +++--
 gdb/language.c    | 213 ++++++++++++++++++++++--------
 gdb/language.h    | 103 ++++++++-------
 gdb/m2-lang.c     | 324 +++++++++++++++++++++++-----------------------
 gdb/objc-lang.c   |   7 -
 gdb/opencl-lang.c |   7 -
 gdb/p-lang.c      | 274 ++++++++++++++++++++-------------------
 gdb/p-lang.h      |   4 -
 gdb/parse.c       |  13 +-
 gdb/parser-defs.h |   3 -
 gdb/rust-lang.c   | 162 ++++++++++++-----------
 gdb/typeprint.c   |   9 --
 gdb/valprint.c    |   2 +-
 18 files changed, 1033 insertions(+), 687 deletions(-)

-- 
2.25.4


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

* [PATCH 1/7] gdb: Convert language la_parser field to a method
  2020-06-18 22:31 [PATCH 0/7] Language Class Hierarchy Conversion (Prt 3) Andrew Burgess
@ 2020-06-18 22:31 ` Andrew Burgess
  2020-06-18 22:31 ` [PATCH 2/7] gdb: Convert language la_post_parser " Andrew Burgess
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Andrew Burgess @ 2020-06-18 22:31 UTC (permalink / raw)
  To: gdb-patches

This commit changes the language_data::la_parser function pointer
member variable into a member function of language_defn.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* ada-lang.c (parse): Rename to ada_language::parser.
	(ada_language_data): Delete la_parser initializer.
	(ada_language::parser): New member function, implementation from
	parse.
	* c-lang.c (c_language_data): Delete la_parser initializer.
	(cplus_language_data): Likewise.
	(asm_language_data): Likewise.
	(minimal_language_data): Likewise.
	* d-lang.c (d_language_data): Likewise.
	(d_language::parser): New member function.
	* f-lang.c (f_language_data): Delete la_parser initializer.
	(f_language::parser): New member function.
	* go-lang.c (go_language_data): Delete la_parser initializer.
	(go_language::parser): New member function.
	* language.c (unk_lang_parser): Delete.
	(language_defn::parser): Define new member function.
	(unknown_language_data): Delete la_parser initializer.
	(unknown_language::parser): New member function.
	(auto_language_data): Delete la_parser initializer.
	(auto_language::parser): New member function.
	* language.h (language_data): Delete la_parser field.
	(language_defn::parser): Declare new member function.
	* m2-lang.c (m2_language_data): Delete la_parser initializer.
	(m2_language::parser): New member function.
	* objc-lang.c (objc_language_data): Delete la_parser initializer.
	* opencl-lang.c (opencl_language_data): Likewise.
	* p-lang.c (pascal_language_data): Likewise.
	(pascal_language::parser): New member function.
	* parse.c (parse_exp_in_context): Update call to parser.
	* rust-lang.c (rust_language_data): Delete la_parser initializer.
	(rust_language::parser): New member function.
---
 gdb/ChangeLog     | 34 ++++++++++++++++++++++++++++++++++
 gdb/ada-lang.c    | 16 ++++++++--------
 gdb/c-lang.c      |  4 ----
 gdb/d-lang.c      |  8 +++++++-
 gdb/f-lang.c      |  8 +++++++-
 gdb/go-lang.c     |  8 +++++++-
 gdb/language.c    | 34 ++++++++++++++++++++++++----------
 gdb/language.h    |  8 ++++----
 gdb/m2-lang.c     |  8 +++++++-
 gdb/objc-lang.c   |  1 -
 gdb/opencl-lang.c |  1 -
 gdb/p-lang.c      |  8 +++++++-
 gdb/parse.c       |  2 +-
 gdb/rust-lang.c   |  8 +++++++-
 14 files changed, 113 insertions(+), 35 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index d303915ebd7..c4ee79eb8df 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -13534,13 +13534,6 @@ emit_char (int c, struct type *type, struct ui_file *stream, int quoter)
   ada_emit_char (c, type, stream, quoter, 1);
 }
 
-static int
-parse (struct parser_state *ps)
-{
-  warnings_issued = 0;
-  return ada_parse (ps);
-}
-
 static const struct exp_descriptor ada_exp_descriptor = {
   ada_print_subexp,
   ada_operator_length,
@@ -13718,7 +13711,6 @@ extern const struct language_data ada_language_data =
   macro_expansion_no,
   ada_extensions,
   &ada_exp_descriptor,
-  parse,
   resolve,
   ada_printchar,                /* Print a character constant */
   ada_printstr,                 /* Function to print string constant */
@@ -14116,6 +14108,14 @@ class ada_language : public language_defn
     return {};
   }
 
+  /* See language.h.  */
+
+  int parser (struct parser_state *ps) const override
+  {
+    warnings_issued = 0;
+    return ada_parse (ps);
+  }
+
 protected:
   /* See language.h.  */
 
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index 64dfd713991..37e69d433f0 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -889,7 +889,6 @@ extern const struct language_data c_language_data =
   macro_expansion_c,
   c_extensions,
   &exp_descriptor_c,
-  c_parse,
   null_post_parser,
   c_printchar,			/* Print a character constant */
   c_printstr,			/* Function to print string constant */
@@ -997,7 +996,6 @@ extern const struct language_data cplus_language_data =
   macro_expansion_c,
   cplus_extensions,
   &exp_descriptor_c,
-  c_parse,
   null_post_parser,
   c_printchar,			/* Print a character constant */
   c_printstr,			/* Function to print string constant */
@@ -1202,7 +1200,6 @@ extern const struct language_data asm_language_data =
   macro_expansion_c,
   asm_extensions,
   &exp_descriptor_c,
-  c_parse,
   null_post_parser,
   c_printchar,			/* Print a character constant */
   c_printstr,			/* Function to print string constant */
@@ -1265,7 +1262,6 @@ extern const struct language_data minimal_language_data =
   macro_expansion_c,
   NULL,
   &exp_descriptor_c,
-  c_parse,
   null_post_parser,
   c_printchar,			/* Print a character constant */
   c_printstr,			/* Function to print string constant */
diff --git a/gdb/d-lang.c b/gdb/d-lang.c
index 5689b6ceafc..e2765b5671e 100644
--- a/gdb/d-lang.c
+++ b/gdb/d-lang.c
@@ -142,7 +142,6 @@ extern const struct language_data d_language_data =
   macro_expansion_no,
   d_extensions,
   &exp_descriptor_c,
-  d_parse,
   null_post_parser,
   c_printchar,			/* Print a character constant.  */
   c_printstr,			/* Function to print string constant.  */
@@ -273,6 +272,13 @@ class d_language : public language_defn
   {
     return d_lookup_symbol_nonlocal (this, name, block, domain);
   }
+
+  /* See language.h.  */
+
+  int parser (struct parser_state *ps) const override
+  {
+    return d_parse (ps);
+  }
 };
 
 /* Single instance of the D language class.  */
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index db337be26bb..918a8cfd3dc 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -564,7 +564,6 @@ extern const struct language_data f_language_data =
   macro_expansion_no,
   f_extensions,
   &exp_descriptor_f,
-  f_parse,			/* parser */
   null_post_parser,
   f_printchar,			/* Print character constant */
   f_printstr,			/* function to print string constant */
@@ -713,6 +712,13 @@ class f_language : public language_defn
     return cp_lookup_symbol_nonlocal (this, name, block, domain);
   }
 
+  /* See language.h.  */
+
+  int parser (struct parser_state *ps) const override
+  {
+    return f_parse (ps);
+  }
+
 protected:
 
   /* See language.h.  */
diff --git a/gdb/go-lang.c b/gdb/go-lang.c
index 7da9299fddf..f2553bb3992 100644
--- a/gdb/go-lang.c
+++ b/gdb/go-lang.c
@@ -527,7 +527,6 @@ extern const struct language_data go_language_data =
   macro_expansion_no,
   NULL,
   &exp_descriptor_c,
-  go_parse,
   null_post_parser,
   c_printchar,			/* Print a character constant.  */
   c_printstr,			/* Function to print string constant.  */
@@ -638,6 +637,13 @@ class go_language : public language_defn
   {
     return go_value_print_inner (val, stream, recurse, options);
   }
+
+  /* See language.h.  */
+
+  int parser (struct parser_state *ps) const override
+  {
+    return go_parse (ps);
+  }
 };
 
 /* Single instance of the Go language class.  */
diff --git a/gdb/language.c b/gdb/language.c
index 0cbc7f05402..828d21dc7e0 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -47,8 +47,6 @@
 #include <algorithm>
 #include "gdbarch.h"
 
-static int unk_lang_parser (struct parser_state *);
-
 static void set_range_case (void);
 
 static void unk_lang_emit_char (int c, struct type *type,
@@ -643,6 +641,14 @@ language_defn::value_print (struct value *val, struct ui_file *stream,
 
 /* See language.h.  */
 
+int
+language_defn::parser (struct parser_state *ps) const
+{
+  return c_parse (ps);
+}
+
+/* See language.h.  */
+
 void
 language_defn::value_print_inner
 	(struct value *val, struct ui_file *stream, int recurse,
@@ -718,12 +724,6 @@ default_is_string_type_p (struct type *type)
 
 /* Define the language that is no language.  */
 
-static int
-unk_lang_parser (struct parser_state *ps)
-{
-  return 1;
-}
-
 static void
 unk_lang_emit_char (int c, struct type *type, struct ui_file *stream,
 		    int quoter)
@@ -777,7 +777,6 @@ extern const struct language_data unknown_language_data =
   macro_expansion_no,
   NULL,
   &exp_descriptor_standard,
-  unk_lang_parser,
   null_post_parser,
   unk_lang_printchar,		/* Print character constant */
   unk_lang_printstr,
@@ -842,6 +841,14 @@ class unknown_language : public language_defn
   {
     error (_("unimplemented unknown_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;
+  }
 };
 
 /* Single instance of the unknown language class.  */
@@ -861,7 +868,6 @@ extern const struct language_data auto_language_data =
   macro_expansion_no,
   NULL,
   &exp_descriptor_standard,
-  unk_lang_parser,
   null_post_parser,
   unk_lang_printchar,		/* Print character constant */
   unk_lang_printstr,
@@ -926,6 +932,14 @@ class auto_language : public language_defn
   {
     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;
+  }
 };
 
 /* Single instance of the fake "auto" language.  */
diff --git a/gdb/language.h b/gdb/language.h
index 2149487dd74..7434d74523b 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -225,10 +225,6 @@ struct language_data
 
     const struct exp_descriptor *la_exp_desc;
 
-    /* Parser function.  */
-
-    int (*la_parser) (struct parser_state *);
-
     /* Given an expression *EXPP created by prefixifying the result of
        la_parser, perform any remaining processing necessary to complete
        its translation.  *EXPP may change; la_post_parser is responsible 
@@ -540,6 +536,10 @@ struct language_defn : language_data
 	(struct value *val, struct ui_file *stream, int recurse,
 	 const struct value_print_options *options) const;
 
+  /* Parser function.  */
+
+  virtual int parser (struct parser_state *ps) const;
+
 protected:
 
   /* This is the overridable part of the GET_SYMBOL_NAME_MATCHER method.
diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c
index 356ed4c3bfa..189f5136057 100644
--- a/gdb/m2-lang.c
+++ b/gdb/m2-lang.c
@@ -362,7 +362,6 @@ extern const struct language_data m2_language_data =
   macro_expansion_no,
   NULL,
   &exp_descriptor_modula2,
-  m2_parse,			/* parser */
   null_post_parser,
   m2_printchar,			/* Print character constant */
   m2_printstr,			/* function to print string constant */
@@ -430,6 +429,13 @@ class m2_language : public language_defn
   {
     return m2_value_print_inner (val, stream, recurse, options);
   }
+
+  /* See language.h.  */
+
+  int parser (struct parser_state *ps) const override
+  {
+    return m2_parse (ps);
+  }
 };
 
 /* Single instance of the M2 language.  */
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index 1e4862fe3fe..90804acc165 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -337,7 +337,6 @@ extern const struct language_data objc_language_data =
   macro_expansion_c,
   objc_extensions,
   &exp_descriptor_standard,
-  c_parse,
   null_post_parser,
   c_printchar,		       /* Print a character constant */
   c_printstr,		       /* Function to print string constant */
diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
index 2a83f51f5c7..7c9965814ff 100644
--- a/gdb/opencl-lang.c
+++ b/gdb/opencl-lang.c
@@ -1016,7 +1016,6 @@ extern const struct language_data opencl_language_data =
   macro_expansion_c,
   NULL,
   &exp_descriptor_opencl,
-  c_parse,
   null_post_parser,
   c_printchar,			/* Print a character constant */
   c_printstr,			/* Function to print string constant */
diff --git a/gdb/p-lang.c b/gdb/p-lang.c
index 5c1b273e7f5..ce812d1d306 100644
--- a/gdb/p-lang.c
+++ b/gdb/p-lang.c
@@ -393,7 +393,6 @@ extern const struct language_data pascal_language_data =
   macro_expansion_no,
   p_extensions,
   &exp_descriptor_standard,
-  pascal_parse,
   null_post_parser,
   pascal_printchar,		/* Print a character constant */
   pascal_printstr,		/* Function to print string constant */
@@ -492,6 +491,13 @@ class pascal_language : public language_defn
   {
     return pascal_value_print_inner (val, stream, recurse, options);
   }
+
+  /* See language.h.  */
+
+  int parser (struct parser_state *ps) const override
+  {
+    return pascal_parse (ps);
+  }
 };
 
 /* Single instance of the Pascal language class.  */
diff --git a/gdb/parse.c b/gdb/parse.c
index d5efe4ab3d8..f003a30bafa 100644
--- a/gdb/parse.c
+++ b/gdb/parse.c
@@ -1119,7 +1119,7 @@ parse_exp_in_context (const char **stringptr, CORE_ADDR pc,
 
   try
     {
-      lang->la_parser (&ps);
+      lang->parser (&ps);
     }
   catch (const gdb_exception &except)
     {
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index d251dab29fc..2153323cff0 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -1989,7 +1989,6 @@ extern const struct language_data rust_language_data =
   macro_expansion_no,
   rust_extensions,
   &exp_descriptor_rust,
-  rust_parse,
   null_post_parser,
   rust_printchar,		/* Print a character constant */
   rust_printstr,		/* Function to print string constant */
@@ -2142,6 +2141,13 @@ class rust_language : public language_defn
       }
     return result;
   }
+
+  /* See language.h.  */
+
+  int parser (struct parser_state *ps) const override
+  {
+    return rust_parse (ps);
+  }
 };
 
 /* Single instance of the Rust language class.  */
-- 
2.25.4


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

* [PATCH 2/7] gdb: Convert language la_post_parser field to a method
  2020-06-18 22:31 [PATCH 0/7] Language Class Hierarchy Conversion (Prt 3) Andrew Burgess
  2020-06-18 22:31 ` [PATCH 1/7] gdb: Convert language la_parser field to a method Andrew Burgess
@ 2020-06-18 22:31 ` Andrew Burgess
  2020-06-18 22:31 ` [PATCH 3/7] gdb: Convert language la_emitchar " Andrew Burgess
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Andrew Burgess @ 2020-06-18 22:31 UTC (permalink / raw)
  To: gdb-patches

This commit changes the language_data::la_post_parser function pointer
member variable into a member function of language_defn.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* ada-lang.c (resolve): Rename to ada_language::post_parser.
	(ada_language_data): Delete la_post_parser initializer.
	(ada_language::post_parser): New member function.
	* c-lang.c (c_language_data): Delete la_post_parser initializer.
	(cplus_language_data): Likewise.
	(asm_language_data): Likewise.
	(minimal_language_data): Likewise.
	* d-lang.c (d_language_data): Likewise.
	* f-lang.c (f_language_data): Likewise.
	* go-lang.c (go_language_data): Likewise.
	* language.c (unknown_language_data): Likewise.
	(auto_language_data): Likewise.
	* language.h (language_data): Delete la_post_parser field.
	(language_defn::post_parser): New member function.
	* m2-lang.c (m2_language_data): Delete la_post_parser initializer.
	* objc-lang.c (objc_language_data): Likewise.
	* opencl-lang.c (opencl_language_data): Likewise.
	* p-lang.c (pascal_language_data): Likewise.
	* parse.c (parse_exp_in_context): Update call to post_parser.
	(null_post_parser): Delete definition.
	* parser-defs.h (null_post_parser): Delete declaration.
	* rust-lang.c (rust_language_data): Delete la_post_parser
	initializer.
---
 gdb/ChangeLog     | 26 ++++++++++++++++++++++++++
 gdb/ada-lang.c    | 46 +++++++++++++++++++++++-----------------------
 gdb/c-lang.c      |  4 ----
 gdb/d-lang.c      |  1 -
 gdb/f-lang.c      |  1 -
 gdb/go-lang.c     |  1 -
 gdb/language.c    |  2 --
 gdb/language.h    | 26 +++++++++++++++-----------
 gdb/m2-lang.c     |  1 -
 gdb/objc-lang.c   |  1 -
 gdb/opencl-lang.c |  1 -
 gdb/p-lang.c      |  1 -
 gdb/parse.c       | 11 +----------
 gdb/parser-defs.h |  3 ---
 gdb/rust-lang.c   |  1 -
 15 files changed, 65 insertions(+), 61 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index c4ee79eb8df..bb6d011e13e 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -3360,28 +3360,6 @@ See set/show multiple-symbol."));
   return n_chosen;
 }
 
-/* Same as evaluate_type (*EXP), but resolves ambiguous symbol
-   references (marked by OP_VAR_VALUE nodes in which the symbol has an
-   undefined namespace) and converts operators that are
-   user-defined into appropriate function calls.  If CONTEXT_TYPE is
-   non-null, it provides a preferred result type [at the moment, only
-   type void has any effect---causing procedures to be preferred over
-   functions in calls].  A null CONTEXT_TYPE indicates that a non-void
-   return type is preferred.  May change (expand) *EXP.  */
-
-static void
-resolve (expression_up *expp, int void_context_p, int parse_completion,
-	 innermost_block_tracker *tracker)
-{
-  struct type *context_type = NULL;
-  int pc = 0;
-
-  if (void_context_p)
-    context_type = builtin_type ((*expp)->gdbarch)->builtin_void;
-
-  resolve_subexp (expp, &pc, 1, context_type, parse_completion, tracker);
-}
-
 /* Resolve the operator of the subexpression beginning at
    position *POS of *EXPP.  "Resolving" consists of replacing
    the symbols that have undefined namespaces in OP_VAR_VALUE nodes
@@ -13711,7 +13689,6 @@ extern const struct language_data ada_language_data =
   macro_expansion_no,
   ada_extensions,
   &ada_exp_descriptor,
-  resolve,
   ada_printchar,                /* Print a character constant */
   ada_printstr,                 /* Function to print string constant */
   emit_char,                    /* Function to print single char (not used) */
@@ -14116,6 +14093,29 @@ class ada_language : public language_defn
     return ada_parse (ps);
   }
 
+  /* See language.h.
+
+     Same as evaluate_type (*EXP), but resolves ambiguous symbol references
+     (marked by OP_VAR_VALUE nodes in which the symbol has an undefined
+     namespace) and converts operators that are user-defined into
+     appropriate function calls.  If CONTEXT_TYPE is non-null, it provides
+     a preferred result type [at the moment, only type void has any
+     effect---causing procedures to be preferred over functions in calls].
+     A null CONTEXT_TYPE indicates that a non-void return type is
+     preferred.  May change (expand) *EXP.  */
+
+  void post_parser (expression_up *expp, int void_context_p, int completing,
+		    innermost_block_tracker *tracker) const override
+  {
+    struct type *context_type = NULL;
+    int pc = 0;
+
+    if (void_context_p)
+      context_type = builtin_type ((*expp)->gdbarch)->builtin_void;
+
+    resolve_subexp (expp, &pc, 1, context_type, completing, tracker);
+  }
+
 protected:
   /* See language.h.  */
 
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index 37e69d433f0..363c896b7a9 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -889,7 +889,6 @@ extern const struct language_data c_language_data =
   macro_expansion_c,
   c_extensions,
   &exp_descriptor_c,
-  null_post_parser,
   c_printchar,			/* Print a character constant */
   c_printstr,			/* Function to print string constant */
   c_emit_char,			/* Print a single char */
@@ -996,7 +995,6 @@ extern const struct language_data cplus_language_data =
   macro_expansion_c,
   cplus_extensions,
   &exp_descriptor_c,
-  null_post_parser,
   c_printchar,			/* Print a character constant */
   c_printstr,			/* Function to print string constant */
   c_emit_char,			/* Print a single char */
@@ -1200,7 +1198,6 @@ extern const struct language_data asm_language_data =
   macro_expansion_c,
   asm_extensions,
   &exp_descriptor_c,
-  null_post_parser,
   c_printchar,			/* Print a character constant */
   c_printstr,			/* Function to print string constant */
   c_emit_char,			/* Print a single char */
@@ -1262,7 +1259,6 @@ extern const struct language_data minimal_language_data =
   macro_expansion_c,
   NULL,
   &exp_descriptor_c,
-  null_post_parser,
   c_printchar,			/* Print a character constant */
   c_printstr,			/* Function to print string constant */
   c_emit_char,			/* Print a single char */
diff --git a/gdb/d-lang.c b/gdb/d-lang.c
index e2765b5671e..facc82c2019 100644
--- a/gdb/d-lang.c
+++ b/gdb/d-lang.c
@@ -142,7 +142,6 @@ extern const struct language_data d_language_data =
   macro_expansion_no,
   d_extensions,
   &exp_descriptor_c,
-  null_post_parser,
   c_printchar,			/* Print a character constant.  */
   c_printstr,			/* Function to print string constant.  */
   c_emit_char,			/* Print a single char.  */
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index 918a8cfd3dc..1b545b27b3b 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -564,7 +564,6 @@ extern const struct language_data f_language_data =
   macro_expansion_no,
   f_extensions,
   &exp_descriptor_f,
-  null_post_parser,
   f_printchar,			/* Print character constant */
   f_printstr,			/* function to print string constant */
   f_emit_char,			/* Function to print a single character */
diff --git a/gdb/go-lang.c b/gdb/go-lang.c
index f2553bb3992..c26dee9a063 100644
--- a/gdb/go-lang.c
+++ b/gdb/go-lang.c
@@ -527,7 +527,6 @@ extern const struct language_data go_language_data =
   macro_expansion_no,
   NULL,
   &exp_descriptor_c,
-  null_post_parser,
   c_printchar,			/* Print a character constant.  */
   c_printstr,			/* Function to print string constant.  */
   c_emit_char,			/* Print a single char.  */
diff --git a/gdb/language.c b/gdb/language.c
index 828d21dc7e0..72fa1e45134 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -777,7 +777,6 @@ extern const struct language_data unknown_language_data =
   macro_expansion_no,
   NULL,
   &exp_descriptor_standard,
-  null_post_parser,
   unk_lang_printchar,		/* Print character constant */
   unk_lang_printstr,
   unk_lang_emit_char,
@@ -868,7 +867,6 @@ extern const struct language_data auto_language_data =
   macro_expansion_no,
   NULL,
   &exp_descriptor_standard,
-  null_post_parser,
   unk_lang_printchar,		/* Print character constant */
   unk_lang_printstr,
   unk_lang_emit_char,
diff --git a/gdb/language.h b/gdb/language.h
index 7434d74523b..d5b106d84e9 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -225,17 +225,6 @@ struct language_data
 
     const struct exp_descriptor *la_exp_desc;
 
-    /* Given an expression *EXPP created by prefixifying the result of
-       la_parser, perform any remaining processing necessary to complete
-       its translation.  *EXPP may change; la_post_parser is responsible 
-       for releasing its previous contents, if necessary.  If 
-       VOID_CONTEXT_P, then no value is expected from the expression.
-       If COMPLETING is non-zero, then the expression has been parsed
-       for completion, not evaluation.  */
-
-    void (*la_post_parser) (expression_up *expp, int void_context_p,
-			    int completing, innermost_block_tracker *tracker);
-
     void (*la_printchar) (int ch, struct type *chtype,
 			  struct ui_file * stream);
 
@@ -540,6 +529,21 @@ struct language_defn : language_data
 
   virtual int parser (struct parser_state *ps) const;
 
+  /* Given an expression *EXPP created by prefixifying the result of
+     la_parser, perform any remaining processing necessary to complete its
+     translation.  *EXPP may change; la_post_parser is responsible for
+     releasing its previous contents, if necessary.  If VOID_CONTEXT_P,
+     then no value is expected from the expression.  If COMPLETING is
+     non-zero, then the expression has been parsed for completion, not
+     evaluation.  */
+
+  virtual void post_parser (expression_up *expp, int void_context_p,
+			    int completing,
+			    innermost_block_tracker *tracker) const
+  {
+    /* By default the post-parser does nothing.  */
+  }
+
 protected:
 
   /* This is the overridable part of the GET_SYMBOL_NAME_MATCHER method.
diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c
index 189f5136057..5aca8334961 100644
--- a/gdb/m2-lang.c
+++ b/gdb/m2-lang.c
@@ -362,7 +362,6 @@ extern const struct language_data m2_language_data =
   macro_expansion_no,
   NULL,
   &exp_descriptor_modula2,
-  null_post_parser,
   m2_printchar,			/* Print character constant */
   m2_printstr,			/* function to print string constant */
   m2_emit_char,			/* Function to print a single character */
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index 90804acc165..2ec87774f43 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -337,7 +337,6 @@ extern const struct language_data objc_language_data =
   macro_expansion_c,
   objc_extensions,
   &exp_descriptor_standard,
-  null_post_parser,
   c_printchar,		       /* Print a character constant */
   c_printstr,		       /* Function to print string constant */
   c_emit_char,
diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
index 7c9965814ff..f314eff55f3 100644
--- a/gdb/opencl-lang.c
+++ b/gdb/opencl-lang.c
@@ -1016,7 +1016,6 @@ extern const struct language_data opencl_language_data =
   macro_expansion_c,
   NULL,
   &exp_descriptor_opencl,
-  null_post_parser,
   c_printchar,			/* Print a character constant */
   c_printstr,			/* Function to print string constant */
   c_emit_char,			/* Print a single char */
diff --git a/gdb/p-lang.c b/gdb/p-lang.c
index ce812d1d306..14ca5d78338 100644
--- a/gdb/p-lang.c
+++ b/gdb/p-lang.c
@@ -393,7 +393,6 @@ extern const struct language_data pascal_language_data =
   macro_expansion_no,
   p_extensions,
   &exp_descriptor_standard,
-  null_post_parser,
   pascal_printchar,		/* Print a character constant */
   pascal_printstr,		/* Function to print string constant */
   pascal_emit_char,		/* Print a single char */
diff --git a/gdb/parse.c b/gdb/parse.c
index f003a30bafa..2fb474e27f1 100644
--- a/gdb/parse.c
+++ b/gdb/parse.c
@@ -1146,8 +1146,7 @@ parse_exp_in_context (const char **stringptr, CORE_ADDR pc,
   if (out_subexp)
     *out_subexp = subexp;
 
-  lang->la_post_parser (&result, void_context_p, ps.parse_completion,
-			tracker);
+  lang->post_parser (&result, void_context_p, ps.parse_completion, tracker);
 
   if (expressiondebug)
     dump_prefix_expression (result.get (), gdb_stdlog);
@@ -1241,14 +1240,6 @@ parse_expression_for_completion (const char *string,
   return value_type (val);
 }
 
-/* A post-parser that does nothing.  */
-
-void
-null_post_parser (expression_up *exp, int void_context_p, int completin,
-		  innermost_block_tracker *tracker)
-{
-}
-
 /* Parse floating point value P of length LEN.
    Return false if invalid, true if valid.
    The successfully parsed number is stored in DATA in
diff --git a/gdb/parser-defs.h b/gdb/parser-defs.h
index d6c3b068978..a9b8a12959b 100644
--- a/gdb/parser-defs.h
+++ b/gdb/parser-defs.h
@@ -350,9 +350,6 @@ extern int operator_check_standard (struct expression *exp, int pos,
 
 extern const char *op_name_standard (enum exp_opcode);
 
-extern void null_post_parser (expression_up *, int, int,
-			      innermost_block_tracker *);
-
 extern bool parse_float (const char *p, int len,
 			 const struct type *type, gdb_byte *data);
 \f
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index 2153323cff0..846fe1fa40a 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -1989,7 +1989,6 @@ extern const struct language_data rust_language_data =
   macro_expansion_no,
   rust_extensions,
   &exp_descriptor_rust,
-  null_post_parser,
   rust_printchar,		/* Print a character constant */
   rust_printstr,		/* Function to print string constant */
   rust_emitchar,		/* Print a single char */
-- 
2.25.4


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

* [PATCH 3/7] gdb: Convert language la_emitchar field to a method
  2020-06-18 22:31 [PATCH 0/7] Language Class Hierarchy Conversion (Prt 3) Andrew Burgess
  2020-06-18 22:31 ` [PATCH 1/7] gdb: Convert language la_parser field to a method Andrew Burgess
  2020-06-18 22:31 ` [PATCH 2/7] gdb: Convert language la_post_parser " Andrew Burgess
@ 2020-06-18 22:31 ` Andrew Burgess
  2020-06-18 22:31 ` [PATCH 4/7] gdb: Convert language la_printchar " Andrew Burgess
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Andrew Burgess @ 2020-06-18 22:31 UTC (permalink / raw)
  To: gdb-patches

This commit changes the language_data::la_emitchar function pointer
member variable into a member function of language_defn.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* ada-lang.c (emit_char): Renamed to ada_language::emitchar.
	(ada_language_data): Delete la_emitchar initializer.
	(ada_language::emitchar): New member function, implementation from
	emit_char.
	* c-lang.c (c_language_data): Delete la_emitchar initializer.
	(cplus_language_data): Likewise.
	(asm_language_data): Likewise.
	(minimal_language_data): Likewise.
	* d-lang.c (d_language_data): Likewise.
	* f-lang.c (f_emit_char): Rename to f_language::emitchar.
	(f_language_data): Delete la_emitchar initializer.
	(f_language::emitchar): New member function, implementation from
	f_emit_char.
	* go-lang.c (go_language_data): Delete la_emitchar initializer.
	* language.c (unk_lang_emit_char): Delete.
	(language_defn::emitchar): New member function definition.
	(unknown_language_data): Delete la_emitchar initializer.
	(unknown_language::emitchar): New member function.
	(auto_language_data): Delete la_emitchar initializer.
	(auto_language::emitchar): New member function.
	* language.h (language_data): Delete la_emitchar field.
	(language_defn::emitchar): New member field declaration.
	(LA_EMIT_CHAR): Update call to emitchar.
	* m2-lang.c (m2_emit_char): Rename to m2_language::emitchar.
	(m2_language_data): Delete la_emitchar initializer.
	(m2_language::emitchar): New member function, implementation from
	m2_emit_char.
	* objc-lang.c (objc_language_data): Delete la_emitchar
	initializer.
	* opencl-lang.c (opencl_language_data): Likewise.
	* p-lang.c (pascal_emit_char): Rename to pascal_language::emitchar.
	(pascal_language_data): Delete la_emitchar initializer.
	(pascal_language::emitchar): New member function, implementation
	from pascal_emit_char.
	* rust-lang.c (rust_emitchar): Rename to rust_language::emitchar.
	(rust_language_data): Delete la_emitchar initializer.
	(rust_language::emitchar): New member function, implementation
	from rust_emitchar.
---
 gdb/ChangeLog     | 41 ++++++++++++++++++++
 gdb/ada-lang.c    | 17 ++++----
 gdb/c-lang.c      |  4 --
 gdb/d-lang.c      |  1 -
 gdb/f-lang.c      | 26 +++++--------
 gdb/go-lang.c     |  1 -
 gdb/language.c    | 40 ++++++++++++-------
 gdb/language.h    | 11 ++++--
 gdb/m2-lang.c     | 99 +++++++++++++++++++++--------------------------
 gdb/objc-lang.c   |  1 -
 gdb/opencl-lang.c |  1 -
 gdb/p-lang.c      | 30 ++++++--------
 gdb/rust-lang.c   | 53 +++++++++++++------------
 13 files changed, 173 insertions(+), 152 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index bb6d011e13e..7858679f5bc 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -13504,14 +13504,6 @@ enum ada_primitive_types {
 \f
 				/* Language vector */
 
-/* Not really used, but needed in the ada_language_defn.  */
-
-static void
-emit_char (int c, struct type *type, struct ui_file *stream, int quoter)
-{
-  ada_emit_char (c, type, stream, quoter, 1);
-}
-
 static const struct exp_descriptor ada_exp_descriptor = {
   ada_print_subexp,
   ada_operator_length,
@@ -13691,7 +13683,6 @@ extern const struct language_data ada_language_data =
   &ada_exp_descriptor,
   ada_printchar,                /* Print a character constant */
   ada_printstr,                 /* Function to print string constant */
-  emit_char,                    /* Function to print single char (not used) */
   ada_print_typedef,            /* Print a typedef using appropriate syntax */
   NULL,                         /* name_of_this */
   true,                         /* la_store_sym_names_in_linkage_form_p */
@@ -14116,6 +14107,14 @@ class ada_language : public language_defn
     resolve_subexp (expp, &pc, 1, context_type, completing, tracker);
   }
 
+  /* See language.h.  */
+
+  void emitchar (int ch, struct type *chtype,
+		 struct ui_file *stream, int quoter) const override
+  {
+    ada_emit_char (ch, chtype, stream, quoter, 1);
+  }
+
 protected:
   /* See language.h.  */
 
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index 363c896b7a9..fbd564d0415 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -891,7 +891,6 @@ extern const struct language_data c_language_data =
   &exp_descriptor_c,
   c_printchar,			/* Print a character constant */
   c_printstr,			/* Function to print string constant */
-  c_emit_char,			/* Print a single char */
   c_print_typedef,		/* Print a typedef using appropriate syntax */
   NULL,				/* name_of_this */
   true,				/* la_store_sym_names_in_linkage_form_p */
@@ -997,7 +996,6 @@ extern const struct language_data cplus_language_data =
   &exp_descriptor_c,
   c_printchar,			/* Print a character constant */
   c_printstr,			/* Function to print string constant */
-  c_emit_char,			/* Print a single char */
   c_print_typedef,		/* Print a typedef using appropriate syntax */
   "this",                       /* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
@@ -1200,7 +1198,6 @@ extern const struct language_data asm_language_data =
   &exp_descriptor_c,
   c_printchar,			/* Print a character constant */
   c_printstr,			/* Function to print string constant */
-  c_emit_char,			/* Print a single char */
   c_print_typedef,		/* Print a typedef using appropriate syntax */
   NULL,				/* name_of_this */
   true,				/* la_store_sym_names_in_linkage_form_p */
@@ -1261,7 +1258,6 @@ extern const struct language_data minimal_language_data =
   &exp_descriptor_c,
   c_printchar,			/* Print a character constant */
   c_printstr,			/* Function to print string constant */
-  c_emit_char,			/* Print a single char */
   c_print_typedef,		/* Print a typedef using appropriate syntax */
   NULL,				/* name_of_this */
   true,				/* la_store_sym_names_in_linkage_form_p */
diff --git a/gdb/d-lang.c b/gdb/d-lang.c
index facc82c2019..fa6df337389 100644
--- a/gdb/d-lang.c
+++ b/gdb/d-lang.c
@@ -144,7 +144,6 @@ extern const struct language_data d_language_data =
   &exp_descriptor_c,
   c_printchar,			/* Print a character constant.  */
   c_printstr,			/* Function to print string constant.  */
-  c_emit_char,			/* Print a single char.  */
   c_print_typedef,		/* Print a typedef using appropriate
 				   syntax.  */
   "this",
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index 1b545b27b3b..90b2e861286 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -42,8 +42,6 @@
 /* Local functions */
 
 static void f_printchar (int c, struct type *type, struct ui_file * stream);
-static void f_emit_char (int c, struct type *type,
-			 struct ui_file * stream, int quoter);
 
 /* Return the encoding that should be used for the character type
    TYPE.  */
@@ -72,20 +70,6 @@ f_get_encoding (struct type *type)
   return encoding;
 }
 
-/* Print the character C on STREAM as part of the contents of a literal
-   string whose delimiter is QUOTER.  Note that that format for printing
-   characters and strings is language specific.
-   FIXME:  This is a copy of the same function from c-exp.y.  It should
-   be replaced with a true F77 version.  */
-
-static void
-f_emit_char (int c, struct type *type, struct ui_file *stream, int quoter)
-{
-  const char *encoding = f_get_encoding (type);
-
-  generic_emit_char (c, type, stream, quoter, encoding);
-}
-
 /* Implementation of la_printchar.  */
 
 static void
@@ -566,7 +550,6 @@ extern const struct language_data f_language_data =
   &exp_descriptor_f,
   f_printchar,			/* Print character constant */
   f_printstr,			/* function to print string constant */
-  f_emit_char,			/* Function to print a single character */
   f_print_typedef,		/* Print a typedef using appropriate syntax */
   NULL,                    	/* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
@@ -718,6 +701,15 @@ class f_language : public language_defn
     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);
+  }
+
 protected:
 
   /* See language.h.  */
diff --git a/gdb/go-lang.c b/gdb/go-lang.c
index c26dee9a063..f167543278a 100644
--- a/gdb/go-lang.c
+++ b/gdb/go-lang.c
@@ -529,7 +529,6 @@ extern const struct language_data go_language_data =
   &exp_descriptor_c,
   c_printchar,			/* Print a character constant.  */
   c_printstr,			/* Function to print string constant.  */
-  c_emit_char,			/* Print a single char.  */
   c_print_typedef,		/* Print a typedef using appropriate
 				   syntax.  */
   NULL,				/* name_of_this */
diff --git a/gdb/language.c b/gdb/language.c
index 72fa1e45134..6778646becd 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -49,9 +49,6 @@
 
 static void set_range_case (void);
 
-static void unk_lang_emit_char (int c, struct type *type,
-				struct ui_file *stream, int quoter);
-
 static void unk_lang_printchar (int c, struct type *type,
 				struct ui_file *stream);
 
@@ -657,6 +654,15 @@ language_defn::value_print_inner
   return c_value_print_inner (val, stream, recurse, options);
 }
 
+/* See language.h.  */
+
+void
+language_defn::emitchar (int ch, struct type *chtype,
+			 struct ui_file * stream, int quoter) const
+{
+  c_emit_char (ch, chtype, stream, quoter);
+}
+
 /* The default implementation of the get_symbol_name_matcher_inner method
    from the language_defn class.  Matches with strncmp_iw.  */
 
@@ -722,16 +728,6 @@ default_is_string_type_p (struct type *type)
   return (type->code ()  == TYPE_CODE_STRING);
 }
 
-/* Define the language that is no language.  */
-
-static void
-unk_lang_emit_char (int c, struct type *type, struct ui_file *stream,
-		    int quoter)
-{
-  error (_("internal error - unimplemented "
-	   "function unk_lang_emit_char called."));
-}
-
 static void
 unk_lang_printchar (int c, struct type *type, struct ui_file *stream)
 {
@@ -779,7 +775,6 @@ extern const struct language_data unknown_language_data =
   &exp_descriptor_standard,
   unk_lang_printchar,		/* Print character constant */
   unk_lang_printstr,
-  unk_lang_emit_char,
   default_print_typedef,	/* Print a typedef using appropriate syntax */
   "this",        	    	/* name_of_this */
   true,				/* store_sym_names_in_linkage_form_p */
@@ -848,6 +843,14 @@ class unknown_language : public language_defn
     /* 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 unknown_language::emitchar called"));
+  }
 };
 
 /* Single instance of the unknown language class.  */
@@ -869,7 +872,6 @@ extern const struct language_data auto_language_data =
   &exp_descriptor_standard,
   unk_lang_printchar,		/* Print character constant */
   unk_lang_printstr,
-  unk_lang_emit_char,
   default_print_typedef,	/* Print a typedef using appropriate syntax */
   "this",		        /* name_of_this */
   false,			/* store_sym_names_in_linkage_form_p */
@@ -938,6 +940,14 @@ class auto_language : public language_defn
     /* 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"));
+  }
 };
 
 /* Single instance of the fake "auto" language.  */
diff --git a/gdb/language.h b/gdb/language.h
index d5b106d84e9..612afb3c5f1 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -233,9 +233,6 @@ struct language_data
 			 const char *encoding, int force_ellipses,
 			 const struct value_print_options *);
 
-    void (*la_emitchar) (int ch, struct type *chtype,
-			 struct ui_file * stream, int quoter);
-
     /* Print a typedef using syntax appropriate for this language.
        TYPE is the underlying type.  NEW_SYMBOL is the symbol naming
        the type.  STREAM is the output stream on which to print.  */
@@ -544,6 +541,12 @@ struct language_defn : language_data
     /* By default the post-parser does nothing.  */
   }
 
+  /* Print the character CH (of type CHTYPE) on STREAM as part of the
+     contents of a literal string whose delimiter is QUOTER.  */
+
+  virtual void emitchar (int ch, struct type *chtype,
+			 struct ui_file *stream, int quoter) const;
+
 protected:
 
   /* This is the overridable part of the GET_SYMBOL_NAME_MATCHER method.
@@ -651,7 +654,7 @@ extern enum language set_language (enum language);
   (current_language->la_printstr(stream, elttype, string, length, \
 				 encoding, force_ellipses,options))
 #define LA_EMIT_CHAR(ch, type, stream, quoter) \
-  (current_language->la_emitchar(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, \
diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c
index 5aca8334961..d8f7f005280 100644
--- a/gdb/m2-lang.c
+++ b/gdb/m2-lang.c
@@ -30,59 +30,6 @@
 #include "gdbarch.h"
 
 static void m2_printchar (int, struct type *, struct ui_file *);
-static void m2_emit_char (int, struct type *, struct ui_file *, int);
-
-/* Print the character C on STREAM as part of the contents of a literal
-   string whose delimiter is QUOTER.  Note that that format for printing
-   characters and strings is language specific.
-   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_emit_char (int c, struct type *type, struct ui_file *stream, int quoter)
-{
-
-  c &= 0xFF;			/* Avoid sign bit follies.  */
-
-  if (PRINT_LITERAL_FORM (c))
-    {
-      if (c == '\\' || c == quoter)
-	{
-	  fputs_filtered ("\\", stream);
-	}
-      fprintf_filtered (stream, "%c", c);
-    }
-  else
-    {
-      switch (c)
-	{
-	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) c);
-	  break;
-	}
-    }
-}
 
 /* FIXME:  This is a copy of the same function from c-exp.y.  It should
    be replaced with a true Modula version.  */
@@ -364,7 +311,6 @@ extern const struct language_data m2_language_data =
   &exp_descriptor_modula2,
   m2_printchar,			/* Print character constant */
   m2_printstr,			/* function to print string constant */
-  m2_emit_char,			/* Function to print a single character */
   m2_print_typedef,		/* Print a typedef using appropriate syntax */
   NULL,		                /* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
@@ -435,6 +381,51 @@ class m2_language : public language_defn
   {
     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;
+	  }
+      }
+  }
 };
 
 /* Single instance of the M2 language.  */
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index 2ec87774f43..ffde14a97aa 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -339,7 +339,6 @@ extern const struct language_data objc_language_data =
   &exp_descriptor_standard,
   c_printchar,		       /* Print a character constant */
   c_printstr,		       /* Function to print string constant */
-  c_emit_char,
   c_print_typedef,		/* Print a typedef using appropriate syntax */
   "self",		        /* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
index f314eff55f3..3789c211ca0 100644
--- a/gdb/opencl-lang.c
+++ b/gdb/opencl-lang.c
@@ -1018,7 +1018,6 @@ extern const struct language_data opencl_language_data =
   &exp_descriptor_opencl,
   c_printchar,			/* Print a character constant */
   c_printstr,			/* Function to print string constant */
-  c_emit_char,			/* Print a single char */
   c_print_typedef,		/* Print a typedef using appropriate syntax */
   NULL,                         /* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
diff --git a/gdb/p-lang.c b/gdb/p-lang.c
index 14ca5d78338..b0465f4a355 100644
--- a/gdb/p-lang.c
+++ b/gdb/p-lang.c
@@ -192,23 +192,6 @@ pascal_one_char (int c, struct ui_file *stream, int *in_quotes)
     }
 }
 
-static void pascal_emit_char (int c, struct type *type,
-			      struct ui_file *stream, int quoter);
-
-/* Print the character C on STREAM as part of the contents of a literal
-   string whose delimiter is QUOTER.  Note that that format for printing
-   characters and strings is language specific.  */
-
-static void
-pascal_emit_char (int c, struct type *type, struct ui_file *stream, int quoter)
-{
-  int in_quotes = 0;
-
-  pascal_one_char (c, stream, &in_quotes);
-  if (in_quotes)
-    fputs_filtered ("'", stream);
-}
-
 void
 pascal_printchar (int c, struct type *type, struct ui_file *stream)
 {
@@ -395,7 +378,6 @@ extern const struct language_data pascal_language_data =
   &exp_descriptor_standard,
   pascal_printchar,		/* Print a character constant */
   pascal_printstr,		/* Function to print string constant */
-  pascal_emit_char,		/* Print a single char */
   pascal_print_typedef,		/* Print a typedef using appropriate syntax */
   "this",		        /* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
@@ -497,6 +479,18 @@ class pascal_language : public language_defn
   {
     return pascal_parse (ps);
   }
+
+  /* See language.h.  */
+
+  void emitchar (int ch, struct type *chtype,
+		 struct ui_file *stream, int quoter) const override
+  {
+    int in_quotes = 0;
+
+    pascal_one_char (ch, stream, &in_quotes);
+    if (in_quotes)
+      fputs_filtered ("'", stream);
+  }
 };
 
 /* Single instance of the Pascal language class.  */
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index 846fe1fa40a..2d6cb8bf0b1 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -281,32 +281,6 @@ rust_get_trait_object_pointer (struct value *value)
 
 \f
 
-/* la_emitchar implementation for Rust.  */
-
-static void
-rust_emitchar (int c, struct type *type, struct ui_file *stream, int quoter)
-{
-  if (!rust_chartype_p (type))
-    generic_emit_char (c, type, stream, quoter,
-		       target_charset (get_type_arch (type)));
-  else if (c == '\\' || c == quoter)
-    fprintf_filtered (stream, "\\%c", c);
-  else if (c == '\n')
-    fputs_filtered ("\\n", stream);
-  else if (c == '\r')
-    fputs_filtered ("\\r", stream);
-  else if (c == '\t')
-    fputs_filtered ("\\t", stream);
-  else if (c == '\0')
-    fputs_filtered ("\\0", stream);
-  else if (c >= 32 && c <= 127 && isprint (c))
-    fputc_filtered (c, stream);
-  else if (c <= 255)
-    fprintf_filtered (stream, "\\x%02x", c);
-  else
-    fprintf_filtered (stream, "\\u{%06x}", c);
-}
-
 /* la_printchar implementation for Rust.  */
 
 static void
@@ -1991,7 +1965,6 @@ extern const struct language_data rust_language_data =
   &exp_descriptor_rust,
   rust_printchar,		/* Print a character constant */
   rust_printstr,		/* Function to print string constant */
-  rust_emitchar,		/* Print a single char */
   rust_print_typedef,		/* Print a typedef using appropriate syntax */
   NULL,				/* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
@@ -2147,6 +2120,32 @@ class rust_language : public language_defn
   {
     return rust_parse (ps);
   }
+
+  /* See language.h.  */
+
+  void emitchar (int ch, struct type *chtype,
+		 struct ui_file *stream, int quoter) const override
+  {
+    if (!rust_chartype_p (chtype))
+      generic_emit_char (ch, chtype, stream, quoter,
+			 target_charset (get_type_arch (chtype)));
+    else if (ch == '\\' || ch == quoter)
+      fprintf_filtered (stream, "\\%c", ch);
+    else if (ch == '\n')
+      fputs_filtered ("\\n", stream);
+    else if (ch == '\r')
+      fputs_filtered ("\\r", stream);
+    else if (ch == '\t')
+      fputs_filtered ("\\t", stream);
+    else if (ch == '\0')
+      fputs_filtered ("\\0", stream);
+    else if (ch >= 32 && ch <= 127 && isprint (ch))
+      fputc_filtered (ch, stream);
+    else if (ch <= 255)
+      fprintf_filtered (stream, "\\x%02x", ch);
+    else
+      fprintf_filtered (stream, "\\u{%06x}", ch);
+  }
 };
 
 /* Single instance of the Rust language class.  */
-- 
2.25.4


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

* [PATCH 4/7] gdb: Convert language la_printchar field to a method
  2020-06-18 22:31 [PATCH 0/7] Language Class Hierarchy Conversion (Prt 3) Andrew Burgess
                   ` (2 preceding siblings ...)
  2020-06-18 22:31 ` [PATCH 3/7] gdb: Convert language la_emitchar " Andrew Burgess
@ 2020-06-18 22:31 ` Andrew Burgess
  2020-06-18 22:31 ` [PATCH 5/7] gdb: Convert language la_printstr " Andrew Burgess
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Andrew Burgess @ 2020-06-18 22:31 UTC (permalink / raw)
  To: gdb-patches

This commit changes the language_data::la_printchar function pointer
member variable into a member function of language_defn.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* ada-lang.c (ada_language_data): Delete la_printchar initializer.
	(ada_language::printchar): New member function.
	* c-lang.c (c_language_data): Delete la_printchar initializer.
	(cplus_language_data): Likewise.
	(asm_language_data): Likewise.
	(minimal_language_data): Likewise.
	* d-lang.c (d_language_data): Likewise.
	* f-lang.c (f_printchar): Rename to f_language::printchar.
	(f_language_data): Delete la_printchar initializer.
	(f_language::printchar): New member function, implementation from
	f_printchar.
	* go-lang.c (go_language_data): Delete la_printchar initializer.
	* language.c (unk_lang_printchar): Delete.
	(language_defn::printchar): Define new member function.
	(unknown_language_data): Delete la_printchar initializer.
	(unknown_language::printchar): New member function.
	(auto_language_data): Delete la_printchar initializer.
	(auto_language::printchar): New member function.
	* language.h (language_data): Delete la_printchar field.
	(language_defn::printchar): Declare new member function.
	(LA_PRINT_CHAR): Update call to printchar.
	* m2-lang.c (m2_language_data): Delete la_printchar initializer.
	(m2_language::printchar): New member function.
	* objc-lang.c (objc_language_data): Delete la_printchar
	initializer.
	* opencl-lang.c (opencl_language_data): Likewise.
	* p-lang.c (pascal_language_data): Delete la_printchar
	initializer.
	(pascal_language::printchar): New member function.
	* rust-lang.c (rust_printchar): Rename to
	rust_language::printchar.
	(rust_language_data): Delete la_printchar initializer.
	(rust_language::printchar): New member function, implementation
	from rust_printchar.
---
 gdb/ChangeLog     | 37 +++++++++++++++++++++++++++++++++++++
 gdb/ada-lang.c    |  9 ++++++++-
 gdb/c-lang.c      |  4 ----
 gdb/d-lang.c      |  1 -
 gdb/f-lang.c      | 23 ++++++++++-------------
 gdb/go-lang.c     |  1 -
 gdb/language.c    | 37 +++++++++++++++++++++++++------------
 gdb/language.h    |  8 ++++----
 gdb/m2-lang.c     |  9 ++++++++-
 gdb/objc-lang.c   |  1 -
 gdb/opencl-lang.c |  1 -
 gdb/p-lang.c      | 10 +++++++++-
 gdb/rust-lang.c   | 21 ++++++++++-----------
 13 files changed, 111 insertions(+), 51 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 7858679f5bc..e69c3cbf50c 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -13681,7 +13681,6 @@ extern const struct language_data ada_language_data =
   macro_expansion_no,
   ada_extensions,
   &ada_exp_descriptor,
-  ada_printchar,                /* Print a character constant */
   ada_printstr,                 /* Function to print string constant */
   ada_print_typedef,            /* Print a typedef using appropriate syntax */
   NULL,                         /* name_of_this */
@@ -14115,6 +14114,14 @@ class ada_language : public language_defn
     ada_emit_char (ch, chtype, stream, quoter, 1);
   }
 
+  /* See language.h.  */
+
+  void printchar (int ch, struct type *chtype,
+		  struct ui_file *stream) const override
+  {
+    ada_printchar (ch, chtype, stream);
+  }
+
 protected:
   /* See language.h.  */
 
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index fbd564d0415..f7b1b80cd56 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -889,7 +889,6 @@ extern const struct language_data c_language_data =
   macro_expansion_c,
   c_extensions,
   &exp_descriptor_c,
-  c_printchar,			/* Print a character constant */
   c_printstr,			/* Function to print string constant */
   c_print_typedef,		/* Print a typedef using appropriate syntax */
   NULL,				/* name_of_this */
@@ -994,7 +993,6 @@ extern const struct language_data cplus_language_data =
   macro_expansion_c,
   cplus_extensions,
   &exp_descriptor_c,
-  c_printchar,			/* Print a character constant */
   c_printstr,			/* Function to print string constant */
   c_print_typedef,		/* Print a typedef using appropriate syntax */
   "this",                       /* name_of_this */
@@ -1196,7 +1194,6 @@ extern const struct language_data asm_language_data =
   macro_expansion_c,
   asm_extensions,
   &exp_descriptor_c,
-  c_printchar,			/* Print a character constant */
   c_printstr,			/* Function to print string constant */
   c_print_typedef,		/* Print a typedef using appropriate syntax */
   NULL,				/* name_of_this */
@@ -1256,7 +1253,6 @@ extern const struct language_data minimal_language_data =
   macro_expansion_c,
   NULL,
   &exp_descriptor_c,
-  c_printchar,			/* Print a character constant */
   c_printstr,			/* Function to print string constant */
   c_print_typedef,		/* Print a typedef using appropriate syntax */
   NULL,				/* name_of_this */
diff --git a/gdb/d-lang.c b/gdb/d-lang.c
index fa6df337389..f76b74f18b4 100644
--- a/gdb/d-lang.c
+++ b/gdb/d-lang.c
@@ -142,7 +142,6 @@ extern const struct language_data d_language_data =
   macro_expansion_no,
   d_extensions,
   &exp_descriptor_c,
-  c_printchar,			/* Print a character constant.  */
   c_printstr,			/* Function to print string constant.  */
   c_print_typedef,		/* Print a typedef using appropriate
 				   syntax.  */
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index 90b2e861286..68d0a4e6d0c 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -41,8 +41,6 @@
 
 /* Local functions */
 
-static void f_printchar (int c, struct type *type, struct ui_file * stream);
-
 /* Return the encoding that should be used for the character type
    TYPE.  */
 
@@ -70,16 +68,6 @@ f_get_encoding (struct type *type)
   return encoding;
 }
 
-/* Implementation of la_printchar.  */
-
-static void
-f_printchar (int c, struct type *type, struct ui_file *stream)
-{
-  fputs_filtered ("'", stream);
-  LA_EMIT_CHAR (c, type, stream, '\'');
-  fputs_filtered ("'", stream);
-}
-
 /* Print the character string STRING, printing at most LENGTH characters.
    Printing stops early if the number hits print_max; repeat counts
    are printed as appropriate.  Print ellipses at the end if we
@@ -548,7 +536,6 @@ extern const struct language_data f_language_data =
   macro_expansion_no,
   f_extensions,
   &exp_descriptor_f,
-  f_printchar,			/* Print character constant */
   f_printstr,			/* function to print string constant */
   f_print_typedef,		/* Print a typedef using appropriate syntax */
   NULL,                    	/* name_of_this */
@@ -710,6 +697,16 @@ class f_language : public language_defn
     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);
+  }
+
 protected:
 
   /* See language.h.  */
diff --git a/gdb/go-lang.c b/gdb/go-lang.c
index f167543278a..819780bc30e 100644
--- a/gdb/go-lang.c
+++ b/gdb/go-lang.c
@@ -527,7 +527,6 @@ extern const struct language_data go_language_data =
   macro_expansion_no,
   NULL,
   &exp_descriptor_c,
-  c_printchar,			/* Print a character constant.  */
   c_printstr,			/* Function to print string constant.  */
   c_print_typedef,		/* Print a typedef using appropriate
 				   syntax.  */
diff --git a/gdb/language.c b/gdb/language.c
index 6778646becd..34990e040cd 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -49,9 +49,6 @@
 
 static void set_range_case (void);
 
-static void unk_lang_printchar (int c, struct type *type,
-				struct ui_file *stream);
-
 /* The current (default at startup) state of type and range checking.
    (If the modes are set to "auto", though, these are changed based
    on the default language at startup, and then again based on the
@@ -663,6 +660,15 @@ language_defn::emitchar (int ch, struct type *chtype,
   c_emit_char (ch, chtype, stream, quoter);
 }
 
+/* See language.h.  */
+
+void
+language_defn::printchar (int ch, struct type *chtype,
+			  struct ui_file * stream) const
+{
+  c_printchar (ch, chtype, stream);
+}
+
 /* The default implementation of the get_symbol_name_matcher_inner method
    from the language_defn class.  Matches with strncmp_iw.  */
 
@@ -728,13 +734,6 @@ default_is_string_type_p (struct type *type)
   return (type->code ()  == TYPE_CODE_STRING);
 }
 
-static void
-unk_lang_printchar (int c, struct type *type, struct ui_file *stream)
-{
-  error (_("internal error - unimplemented "
-	   "function unk_lang_printchar called."));
-}
-
 static void
 unk_lang_printstr (struct ui_file *stream, struct type *type,
 		   const gdb_byte *string, unsigned int length,
@@ -773,7 +772,6 @@ extern const struct language_data unknown_language_data =
   macro_expansion_no,
   NULL,
   &exp_descriptor_standard,
-  unk_lang_printchar,		/* Print character constant */
   unk_lang_printstr,
   default_print_typedef,	/* Print a typedef using appropriate syntax */
   "this",        	    	/* name_of_this */
@@ -851,6 +849,14 @@ class unknown_language : public language_defn
   {
     error (_("unimplemented unknown_language::emitchar called"));
   }
+
+  /* See language.h.  */
+
+  void printchar (int ch, struct type *chtype,
+		  struct ui_file *stream) const override
+  {
+    error (_("unimplemented unknown_language::printchar called"));
+  }
 };
 
 /* Single instance of the unknown language class.  */
@@ -870,7 +876,6 @@ extern const struct language_data auto_language_data =
   macro_expansion_no,
   NULL,
   &exp_descriptor_standard,
-  unk_lang_printchar,		/* Print character constant */
   unk_lang_printstr,
   default_print_typedef,	/* Print a typedef using appropriate syntax */
   "this",		        /* name_of_this */
@@ -948,6 +953,14 @@ class auto_language : public language_defn
   {
     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"));
+  }
 };
 
 /* Single instance of the fake "auto" language.  */
diff --git a/gdb/language.h b/gdb/language.h
index 612afb3c5f1..fc9efd89939 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -225,9 +225,6 @@ struct language_data
 
     const struct exp_descriptor *la_exp_desc;
 
-    void (*la_printchar) (int ch, struct type *chtype,
-			  struct ui_file * stream);
-
     void (*la_printstr) (struct ui_file * stream, struct type *elttype,
 			 const gdb_byte *string, unsigned int length,
 			 const char *encoding, int force_ellipses,
@@ -547,6 +544,9 @@ struct language_defn : language_data
   virtual void emitchar (int ch, struct type *chtype,
 			 struct ui_file *stream, int quoter) const;
 
+  virtual void printchar (int ch, struct type *chtype,
+			  struct ui_file * stream) const;
+
 protected:
 
   /* This is the overridable part of the GET_SYMBOL_NAME_MATCHER method.
@@ -649,7 +649,7 @@ extern enum language set_language (enum language);
   (current_language->value_print (val,stream,options))
 
 #define LA_PRINT_CHAR(ch, type, stream) \
-  (current_language->la_printchar(ch, type, stream))
+  (current_language->printchar (ch, type, stream))
 #define LA_PRINT_STRING(stream, elttype, string, length, encoding, force_ellipses, options) \
   (current_language->la_printstr(stream, elttype, string, length, \
 				 encoding, force_ellipses,options))
diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c
index d8f7f005280..bdb1a460aea 100644
--- a/gdb/m2-lang.c
+++ b/gdb/m2-lang.c
@@ -309,7 +309,6 @@ extern const struct language_data m2_language_data =
   macro_expansion_no,
   NULL,
   &exp_descriptor_modula2,
-  m2_printchar,			/* Print character constant */
   m2_printstr,			/* function to print string constant */
   m2_print_typedef,		/* Print a typedef using appropriate syntax */
   NULL,		                /* name_of_this */
@@ -426,6 +425,14 @@ class m2_language : public language_defn
 	  }
       }
   }
+
+  /* See language.h.  */
+
+  void printchar (int ch, struct type *chtype,
+		  struct ui_file *stream) const override
+  {
+    m2_printchar (ch, chtype, stream);
+  }
 };
 
 /* Single instance of the M2 language.  */
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index ffde14a97aa..736c8684523 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -337,7 +337,6 @@ extern const struct language_data objc_language_data =
   macro_expansion_c,
   objc_extensions,
   &exp_descriptor_standard,
-  c_printchar,		       /* Print a character constant */
   c_printstr,		       /* Function to print string constant */
   c_print_typedef,		/* Print a typedef using appropriate syntax */
   "self",		        /* name_of_this */
diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
index 3789c211ca0..d66f3f8aec3 100644
--- a/gdb/opencl-lang.c
+++ b/gdb/opencl-lang.c
@@ -1016,7 +1016,6 @@ extern const struct language_data opencl_language_data =
   macro_expansion_c,
   NULL,
   &exp_descriptor_opencl,
-  c_printchar,			/* Print a character constant */
   c_printstr,			/* Function to print string constant */
   c_print_typedef,		/* Print a typedef using appropriate syntax */
   NULL,                         /* name_of_this */
diff --git a/gdb/p-lang.c b/gdb/p-lang.c
index b0465f4a355..b8c99c4650f 100644
--- a/gdb/p-lang.c
+++ b/gdb/p-lang.c
@@ -376,7 +376,6 @@ extern const struct language_data pascal_language_data =
   macro_expansion_no,
   p_extensions,
   &exp_descriptor_standard,
-  pascal_printchar,		/* Print a character constant */
   pascal_printstr,		/* Function to print string constant */
   pascal_print_typedef,		/* Print a typedef using appropriate syntax */
   "this",		        /* name_of_this */
@@ -491,6 +490,15 @@ class pascal_language : public language_defn
     if (in_quotes)
       fputs_filtered ("'", stream);
   }
+
+  /* See language.h.  */
+
+  void printchar (int ch, struct type *chtype,
+		  struct ui_file *stream) const override
+  {
+    pascal_printchar (ch, chtype, stream);
+  }
+
 };
 
 /* Single instance of the Pascal language class.  */
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index 2d6cb8bf0b1..36e26179f34 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -281,16 +281,6 @@ rust_get_trait_object_pointer (struct value *value)
 
 \f
 
-/* la_printchar implementation for Rust.  */
-
-static void
-rust_printchar (int c, struct type *type, struct ui_file *stream)
-{
-  fputs_filtered ("'", stream);
-  LA_EMIT_CHAR (c, type, stream, '\'');
-  fputs_filtered ("'", stream);
-}
-
 /* la_printstr implementation for Rust.  */
 
 static void
@@ -1963,7 +1953,6 @@ extern const struct language_data rust_language_data =
   macro_expansion_no,
   rust_extensions,
   &exp_descriptor_rust,
-  rust_printchar,		/* Print a character constant */
   rust_printstr,		/* Function to print string constant */
   rust_print_typedef,		/* Print a typedef using appropriate syntax */
   NULL,				/* name_of_this */
@@ -2146,6 +2135,16 @@ class rust_language : public language_defn
     else
       fprintf_filtered (stream, "\\u{%06x}", ch);
   }
+
+  /* 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);
+  }
 };
 
 /* Single instance of the Rust language class.  */
-- 
2.25.4


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

* [PATCH 5/7] gdb: Convert language la_printstr field to a method
  2020-06-18 22:31 [PATCH 0/7] Language Class Hierarchy Conversion (Prt 3) Andrew Burgess
                   ` (3 preceding siblings ...)
  2020-06-18 22:31 ` [PATCH 4/7] gdb: Convert language la_printchar " Andrew Burgess
@ 2020-06-18 22:31 ` Andrew Burgess
  2020-06-18 22:31 ` [PATCH 6/7] gdb: Convert language la_print_typedef " Andrew Burgess
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Andrew Burgess @ 2020-06-18 22:31 UTC (permalink / raw)
  To: gdb-patches

This commit changes the language_data::la_printstr function pointer
member variable into a member function of language_defn.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* ada-lang.c (ada_language_data): Delete la_printstr initializer.
	(ada_language::printstr): New member function.
	* c-lang.c (c_language_data): Delete la_printstr initializer.
	(cplus_language_data): Likewise.
	(asm_language_data): Likewise.
	(minimal_language_data): Likewise.
	* d-lang.c (d_language_data): Likewise.
	* f-lang.c (f_printstr): Rename to f_language::printstr.
	(f_language_data): Delete la_printstr initializer.
	(f_language::printstr): New member function, implementation from
	f_printstr.
	* go-lang.c (go_language_data): Delete la_printstr initializer.
	* language.c (language_defn::printstr): Define new member
	function.
	(unk_lang_printstr): Delete.
	(unknown_language_data): Delete la_printstr initializer.
	(unknown_language::printstr): New member function.
	(auto_language_data): Delete la_printstr initializer.
	(auto_language::printstr): New member function.
	* language.h (language_data): Delete la_printstr field.
	(language_defn::printstr): Declare new member function.
	(LA_PRINT_STRING): Update call to printstr.
	* m2-lang.c (m2_printstr): Rename to m2_language::printstr.
	(m2_language_data): Delete la_printstr initializer.
	(m2_language::printstr): New member function, implementation from
	m2_printstr.
	* objc-lang.c (objc_language_data): Delete la_printstr
	initializer.
	* opencl-lang.c (opencl_language_data): Likewise.
	* p-lang.c (pascal_printstr): Rename to pascal_language::printstr.
	(pascal_language_data): Delete la_printstr initializer.
	(pascal_language::printstr): New member function, implementation
	from pascal_printstr.
	* p-lang.h (pascal_printstr): Delete declaration.
	* rust-lang.c (rust_printstr): Update header comment.
	(rust_language_data): Delete la_printstr initializer.
	(rust_language::printstr): New member function.
---
 gdb/ChangeLog     |  40 ++++++++++
 gdb/ada-lang.c    |  12 ++-
 gdb/c-lang.c      |   4 -
 gdb/d-lang.c      |   1 -
 gdb/f-lang.c      |  43 +++++-----
 gdb/go-lang.c     |   1 -
 gdb/language.c    |  44 ++++++++---
 gdb/language.h    |  19 +++--
 gdb/m2-lang.c     | 156 ++++++++++++++++++------------------
 gdb/objc-lang.c   |   1 -
 gdb/opencl-lang.c |   1 -
 gdb/p-lang.c      | 197 ++++++++++++++++++++++------------------------
 gdb/p-lang.h      |   4 -
 gdb/rust-lang.c   |  14 +++-
 14 files changed, 297 insertions(+), 240 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index e69c3cbf50c..62ea21a3857 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -13681,7 +13681,6 @@ extern const struct language_data ada_language_data =
   macro_expansion_no,
   ada_extensions,
   &ada_exp_descriptor,
-  ada_printstr,                 /* Function to print string constant */
   ada_print_typedef,            /* Print a typedef using appropriate syntax */
   NULL,                         /* name_of_this */
   true,                         /* la_store_sym_names_in_linkage_form_p */
@@ -14122,6 +14121,17 @@ class ada_language : public language_defn
     ada_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
+  {
+    ada_printstr (stream, elttype, string, length, encoding,
+		  force_ellipses, options);
+  }
+
 protected:
   /* See language.h.  */
 
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index f7b1b80cd56..d6bbc025bc7 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -889,7 +889,6 @@ extern const struct language_data c_language_data =
   macro_expansion_c,
   c_extensions,
   &exp_descriptor_c,
-  c_printstr,			/* Function to print string constant */
   c_print_typedef,		/* Print a typedef using appropriate syntax */
   NULL,				/* name_of_this */
   true,				/* la_store_sym_names_in_linkage_form_p */
@@ -993,7 +992,6 @@ extern const struct language_data cplus_language_data =
   macro_expansion_c,
   cplus_extensions,
   &exp_descriptor_c,
-  c_printstr,			/* Function to print string constant */
   c_print_typedef,		/* Print a typedef using appropriate syntax */
   "this",                       /* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
@@ -1194,7 +1192,6 @@ extern const struct language_data asm_language_data =
   macro_expansion_c,
   asm_extensions,
   &exp_descriptor_c,
-  c_printstr,			/* Function to print string constant */
   c_print_typedef,		/* Print a typedef using appropriate syntax */
   NULL,				/* name_of_this */
   true,				/* la_store_sym_names_in_linkage_form_p */
@@ -1253,7 +1250,6 @@ extern const struct language_data minimal_language_data =
   macro_expansion_c,
   NULL,
   &exp_descriptor_c,
-  c_printstr,			/* Function to print string constant */
   c_print_typedef,		/* Print a typedef using appropriate syntax */
   NULL,				/* name_of_this */
   true,				/* la_store_sym_names_in_linkage_form_p */
diff --git a/gdb/d-lang.c b/gdb/d-lang.c
index f76b74f18b4..17ab38ee511 100644
--- a/gdb/d-lang.c
+++ b/gdb/d-lang.c
@@ -142,7 +142,6 @@ extern const struct language_data d_language_data =
   macro_expansion_no,
   d_extensions,
   &exp_descriptor_c,
-  c_printstr,			/* Function to print string constant.  */
   c_print_typedef,		/* Print a typedef using appropriate
 				   syntax.  */
   "this",
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index 68d0a4e6d0c..67c2ea34b64 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -68,29 +68,6 @@ f_get_encoding (struct type *type)
   return encoding;
 }
 
-/* Print the character string STRING, printing at most LENGTH characters.
-   Printing stops early if the number hits print_max; repeat counts
-   are printed as appropriate.  Print ellipses at the end if we
-   had to stop before printing LENGTH characters, or if FORCE_ELLIPSES.
-   FIXME:  This is a copy of the same function from c-exp.y.  It should
-   be replaced with a true F77 version.  */
-
-static void
-f_printstr (struct ui_file *stream, struct type *type, const gdb_byte *string,
-	    unsigned int length, const char *encoding, int force_ellipses,
-	    const struct value_print_options *options)
-{
-  const char *type_encoding = f_get_encoding (type);
-
-  if (TYPE_LENGTH (type) == 4)
-    fputs_filtered ("4_", stream);
-
-  if (!encoding || !*encoding)
-    encoding = type_encoding;
-
-  generic_printstr (stream, type, string, length, encoding,
-		    force_ellipses, '\'', 0, options);
-}
 \f
 
 /* Table of operators and their precedences for printing expressions.  */
@@ -536,7 +513,6 @@ extern const struct language_data f_language_data =
   macro_expansion_no,
   f_extensions,
   &exp_descriptor_f,
-  f_printstr,			/* function to print string constant */
   f_print_typedef,		/* Print a typedef using appropriate syntax */
   NULL,                    	/* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
@@ -707,6 +683,25 @@ class f_language : public language_defn
     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);
+  }
+
 protected:
 
   /* See language.h.  */
diff --git a/gdb/go-lang.c b/gdb/go-lang.c
index 819780bc30e..69f14b8c56c 100644
--- a/gdb/go-lang.c
+++ b/gdb/go-lang.c
@@ -527,7 +527,6 @@ extern const struct language_data go_language_data =
   macro_expansion_no,
   NULL,
   &exp_descriptor_c,
-  c_printstr,			/* Function to print string constant.  */
   c_print_typedef,		/* Print a typedef using appropriate
 				   syntax.  */
   NULL,				/* name_of_this */
diff --git a/gdb/language.c b/gdb/language.c
index 34990e040cd..9867ac4b4b5 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -669,6 +669,18 @@ language_defn::printchar (int ch, struct type *chtype,
   c_printchar (ch, chtype, stream);
 }
 
+/* See language.h.  */
+
+void
+language_defn::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
+{
+  c_printstr (stream, elttype, string, length, encoding, force_ellipses,
+	      options);
+}
+
 /* The default implementation of the get_symbol_name_matcher_inner method
    from the language_defn class.  Matches with strncmp_iw.  */
 
@@ -734,16 +746,6 @@ default_is_string_type_p (struct type *type)
   return (type->code ()  == TYPE_CODE_STRING);
 }
 
-static void
-unk_lang_printstr (struct ui_file *stream, struct type *type,
-		   const gdb_byte *string, unsigned int length,
-		   const char *encoding, int force_ellipses,
-		   const struct value_print_options *options)
-{
-  error (_("internal error - unimplemented "
-	   "function unk_lang_printstr called."));
-}
-
 static const struct op_print unk_op_print_tab[] =
 {
   {NULL, OP_NULL, PREC_NULL, 0}
@@ -772,7 +774,6 @@ extern const struct language_data unknown_language_data =
   macro_expansion_no,
   NULL,
   &exp_descriptor_standard,
-  unk_lang_printstr,
   default_print_typedef,	/* Print a typedef using appropriate syntax */
   "this",        	    	/* name_of_this */
   true,				/* store_sym_names_in_linkage_form_p */
@@ -857,6 +858,16 @@ class unknown_language : public language_defn
   {
     error (_("unimplemented unknown_language::printchar called"));
   }
+
+  /* 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
+  {
+    error (_("unimplemented unknown_language::printstr called"));
+  }
 };
 
 /* Single instance of the unknown language class.  */
@@ -876,7 +887,6 @@ extern const struct language_data auto_language_data =
   macro_expansion_no,
   NULL,
   &exp_descriptor_standard,
-  unk_lang_printstr,
   default_print_typedef,	/* Print a typedef using appropriate syntax */
   "this",		        /* name_of_this */
   false,			/* store_sym_names_in_linkage_form_p */
@@ -961,6 +971,16 @@ class auto_language : public language_defn
   {
     error (_("unimplemented auto_language::printchar called"));
   }
+
+  /* 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
+  {
+    error (_("unimplemented auto_language::printstr called"));
+  }
 };
 
 /* Single instance of the fake "auto" language.  */
diff --git a/gdb/language.h b/gdb/language.h
index fc9efd89939..a68b6dfdcae 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -225,11 +225,6 @@ struct language_data
 
     const struct exp_descriptor *la_exp_desc;
 
-    void (*la_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 *);
-
     /* Print a typedef using syntax appropriate for this language.
        TYPE is the underlying type.  NEW_SYMBOL is the symbol naming
        the type.  STREAM is the output stream on which to print.  */
@@ -547,6 +542,16 @@ struct language_defn : language_data
   virtual void printchar (int ch, struct type *chtype,
 			  struct ui_file * stream) const;
 
+/* Print the character string STRING, printing at most LENGTH characters.
+   Printing stops early if the number hits print_max; repeat counts
+   are printed as appropriate.  Print ellipses at the end if we
+   had to stop before printing LENGTH characters, or if FORCE_ELLIPSES.  */
+
+  virtual 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;
+
 protected:
 
   /* This is the overridable part of the GET_SYMBOL_NAME_MATCHER method.
@@ -651,8 +656,8 @@ extern enum language set_language (enum language);
 #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) \
-  (current_language->la_printstr(stream, elttype, string, length, \
-				 encoding, force_ellipses,options))
+  (current_language->printstr (stream, elttype, string, length, \
+			       encoding, force_ellipses,options))
 #define LA_EMIT_CHAR(ch, type, stream, quoter) \
   (current_language->emitchar (ch, type, stream, quoter))
 
diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c
index bdb1a460aea..b84a9a49f84 100644
--- a/gdb/m2-lang.c
+++ b/gdb/m2-lang.c
@@ -42,86 +42,6 @@ m2_printchar (int c, struct type *type, struct ui_file *stream)
   fputs_filtered ("'", stream);
 }
 
-/* Print the character string STRING, printing at most LENGTH characters.
-   Printing stops early if the number hits print_max; repeat counts
-   are printed as appropriate.  Print ellipses at the end if we
-   had to stop before printing LENGTH characters, or if FORCE_ELLIPSES.
-   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_printstr (struct ui_file *stream, struct type *type, const gdb_byte *string,
-	     unsigned int length, const char *encoding, int force_ellipses,
-	     const struct value_print_options *options)
-{
-  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], type, 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], type, stream, '"');
-	  ++things_printed;
-	}
-    }
-
-  /* Terminate the quotes if necessary.  */
-  if (in_quotes)
-    fputs_filtered ("\"", stream);
-
-  if (force_ellipses || i < length)
-    fputs_filtered ("...", stream);
-}
-
 /* Return true if TYPE is a string.  */
 
 static bool
@@ -309,7 +229,6 @@ extern const struct language_data m2_language_data =
   macro_expansion_no,
   NULL,
   &exp_descriptor_modula2,
-  m2_printstr,			/* function to print string constant */
   m2_print_typedef,		/* Print a typedef using appropriate syntax */
   NULL,		                /* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
@@ -433,6 +352,81 @@ class m2_language : public language_defn
   {
     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);
+
+    if (force_ellipses || i < length)
+      fputs_filtered ("...", stream);
+  }
 };
 
 /* Single instance of the M2 language.  */
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index 736c8684523..95c6c0a1fc5 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -337,7 +337,6 @@ extern const struct language_data objc_language_data =
   macro_expansion_c,
   objc_extensions,
   &exp_descriptor_standard,
-  c_printstr,		       /* Function to print string constant */
   c_print_typedef,		/* Print a typedef using appropriate syntax */
   "self",		        /* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
index d66f3f8aec3..765202aac0a 100644
--- a/gdb/opencl-lang.c
+++ b/gdb/opencl-lang.c
@@ -1016,7 +1016,6 @@ extern const struct language_data opencl_language_data =
   macro_expansion_c,
   NULL,
   &exp_descriptor_opencl,
-  c_printstr,			/* Function to print string constant */
   c_print_typedef,		/* Print a typedef using appropriate syntax */
   NULL,                         /* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
diff --git a/gdb/p-lang.c b/gdb/p-lang.c
index b8c99c4650f..1c6aea90b6c 100644
--- a/gdb/p-lang.c
+++ b/gdb/p-lang.c
@@ -202,106 +202,6 @@ pascal_printchar (int c, struct type *type, struct ui_file *stream)
     fputs_filtered ("'", stream);
 }
 
-/* Print the character string STRING, printing at most LENGTH characters.
-   Printing stops early if the number hits print_max; repeat counts
-   are printed as appropriate.  Print ellipses at the end if we
-   had to stop before printing LENGTH characters, or if FORCE_ELLIPSES.  */
-
-void
-pascal_printstr (struct ui_file *stream, struct type *type,
-		 const gdb_byte *string, unsigned int length,
-		 const char *encoding, int force_ellipses,
-		 const struct value_print_options *options)
-{
-  enum bfd_endian byte_order = type_byte_order (type);
-  unsigned int i;
-  unsigned int things_printed = 0;
-  int in_quotes = 0;
-  int need_comma = 0;
-  int width;
-
-  /* Preserve TYPE's original type, just set its LENGTH.  */
-  check_typedef (type);
-  width = TYPE_LENGTH (type);
-
-  /* If the string was not truncated due to `set print elements', and
-     the last byte of it is a null, we don't print that, in traditional C
-     style.  */
-  if ((!force_ellipses) && length > 0
-	&& extract_unsigned_integer (string + (length - 1) * width, width,
-				     byte_order) == 0)
-    length--;
-
-  if (length == 0)
-    {
-      fputs_filtered ("''", stream);
-      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;
-      unsigned long int current_char;
-
-      QUIT;
-
-      if (need_comma)
-	{
-	  fputs_filtered (", ", stream);
-	  need_comma = 0;
-	}
-
-      current_char = extract_unsigned_integer (string + i * width, width,
-					       byte_order);
-
-      rep1 = i + 1;
-      reps = 1;
-      while (rep1 < length
-	     && extract_unsigned_integer (string + rep1 * width, width,
-					  byte_order) == current_char)
-	{
-	  ++rep1;
-	  ++reps;
-	}
-
-      if (reps > options->repeat_count_threshold)
-	{
-	  if (in_quotes)
-	    {
-	      fputs_filtered ("', ", stream);
-	      in_quotes = 0;
-	    }
-	  pascal_printchar (current_char, type, stream);
-	  fprintf_filtered (stream, " %p[<repeats %u times>%p]",
-			    metadata_style.style ().ptr (),
-			    reps, nullptr);
-	  i = rep1 - 1;
-	  things_printed += options->repeat_count_threshold;
-	  need_comma = 1;
-	}
-      else
-	{
-	  if ((!in_quotes) && (PRINT_LITERAL_FORM (current_char)))
-	    {
-	      fputs_filtered ("'", stream);
-	      in_quotes = 1;
-	    }
-	  pascal_one_char (current_char, stream, &in_quotes);
-	  ++things_printed;
-	}
-    }
-
-  /* Terminate the quotes if necessary.  */
-  if (in_quotes)
-    fputs_filtered ("'", stream);
-
-  if (force_ellipses || i < length)
-    fputs_filtered ("...", stream);
-}
 \f
 
 /* Table mapping opcodes into strings for printing operators
@@ -376,7 +276,6 @@ extern const struct language_data pascal_language_data =
   macro_expansion_no,
   p_extensions,
   &exp_descriptor_standard,
-  pascal_printstr,		/* Function to print string constant */
   pascal_print_typedef,		/* Print a typedef using appropriate syntax */
   "this",		        /* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
@@ -499,6 +398,102 @@ class pascal_language : public language_defn
     pascal_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
+  {
+    enum bfd_endian byte_order = type_byte_order (elttype);
+    unsigned int i;
+    unsigned int things_printed = 0;
+    int in_quotes = 0;
+    int need_comma = 0;
+    int width;
+
+    /* Preserve ELTTYPE's original type, just set its LENGTH.  */
+    check_typedef (elttype);
+    width = TYPE_LENGTH (elttype);
+
+    /* If the string was not truncated due to `set print elements', and
+       the last byte of it is a null, we don't print that, in traditional C
+       style.  */
+    if ((!force_ellipses) && length > 0
+	&& extract_unsigned_integer (string + (length - 1) * width, width,
+				     byte_order) == 0)
+      length--;
+
+    if (length == 0)
+      {
+	fputs_filtered ("''", stream);
+	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;
+	unsigned long int current_char;
+
+	QUIT;
+
+	if (need_comma)
+	  {
+	    fputs_filtered (", ", stream);
+	    need_comma = 0;
+	  }
+
+	current_char = extract_unsigned_integer (string + i * width, width,
+						 byte_order);
+
+	rep1 = i + 1;
+	reps = 1;
+	while (rep1 < length
+	       && extract_unsigned_integer (string + rep1 * width, width,
+					    byte_order) == current_char)
+	  {
+	    ++rep1;
+	    ++reps;
+	  }
+
+	if (reps > options->repeat_count_threshold)
+	  {
+	    if (in_quotes)
+	      {
+		fputs_filtered ("', ", stream);
+		in_quotes = 0;
+	      }
+	    pascal_printchar (current_char, elttype, stream);
+	    fprintf_filtered (stream, " %p[<repeats %u times>%p]",
+			      metadata_style.style ().ptr (),
+			      reps, nullptr);
+	    i = rep1 - 1;
+	    things_printed += options->repeat_count_threshold;
+	    need_comma = 1;
+	  }
+	else
+	  {
+	    if ((!in_quotes) && (PRINT_LITERAL_FORM (current_char)))
+	      {
+		fputs_filtered ("'", stream);
+		in_quotes = 1;
+	      }
+	    pascal_one_char (current_char, stream, &in_quotes);
+	    ++things_printed;
+	  }
+      }
+
+    /* Terminate the quotes if necessary.  */
+    if (in_quotes)
+      fputs_filtered ("'", stream);
+
+    if (force_ellipses || i < length)
+      fputs_filtered ("...", stream);
+  }
 };
 
 /* Single instance of the Pascal language class.  */
diff --git a/gdb/p-lang.h b/gdb/p-lang.h
index 9ce61318761..3eaad015a6e 100644
--- a/gdb/p-lang.h
+++ b/gdb/p-lang.h
@@ -56,10 +56,6 @@ extern int
 
 extern void pascal_printchar (int, struct type *, struct ui_file *);
 
-extern void pascal_printstr (struct ui_file *, struct type *, const gdb_byte *,
-			     unsigned int, const char *, int,
-			     const struct value_print_options *);
-
 extern struct type **const pascal_builtin_types[];
 
 /* These are in p-typeprint.c: */
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index 36e26179f34..b13623fe619 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -281,7 +281,7 @@ rust_get_trait_object_pointer (struct value *value)
 
 \f
 
-/* la_printstr implementation for Rust.  */
+/* language_defn::printstr implementation for Rust.  */
 
 static void
 rust_printstr (struct ui_file *stream, struct type *type,
@@ -1953,7 +1953,6 @@ extern const struct language_data rust_language_data =
   macro_expansion_no,
   rust_extensions,
   &exp_descriptor_rust,
-  rust_printstr,		/* Function to print string constant */
   rust_print_typedef,		/* Print a typedef using appropriate syntax */
   NULL,				/* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
@@ -2145,6 +2144,17 @@ class rust_language : public language_defn
     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
+  {
+    rust_printstr (stream, elttype, string, length, encoding,
+		   force_ellipses, options);
+  }
 };
 
 /* Single instance of the Rust language class.  */
-- 
2.25.4


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

* [PATCH 6/7] gdb: Convert language la_print_typedef field to a method
  2020-06-18 22:31 [PATCH 0/7] Language Class Hierarchy Conversion (Prt 3) Andrew Burgess
                   ` (4 preceding siblings ...)
  2020-06-18 22:31 ` [PATCH 5/7] gdb: Convert language la_printstr " Andrew Burgess
@ 2020-06-18 22:31 ` Andrew Burgess
  2020-06-18 22:31 ` [PATCH 7/7] gdb: Convert language la_is_string_type_p " Andrew Burgess
  2020-06-19 14:25 ` [PATCH 0/7] Language Class Hierarchy Conversion (Prt 3) Tom Tromey
  7 siblings, 0 replies; 10+ messages in thread
From: Andrew Burgess @ 2020-06-18 22:31 UTC (permalink / raw)
  To: gdb-patches

This commit changes the language_data::la_print_typedef function
pointer member variable into a member function of language_defn.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* ada-lang.c (ada_language_data): Delete la_print_typedef
	initializer.
	(ada_language::print_typedef): New member function.
	* c-lang.c (c_language_data): Delete la_print_typedef initializer.
	(cplus_language_data): Likewise.
	(asm_language_data): Likewise.
	(minimal_language_data): Likewise.
	* d-lang.c (d_language_data): Likewise.
	* f-lang.c (f_language_data): Likewise.
	(f_language::print_typedef): New member function.
	* go-lang.c (go_language_data): Delete la_print_typedef
	initializer.
	* language.c (language_defn::print_typedef): Define member
	function.
	(unknown_language_data): Delete la_print_typedef initializer.
	(unknown_language::print_typedef): New member function.
	(auto_language_data): Delete la_print_typedef initializer.
	(auto_language::print_typedef): New member function.
	* language.h (language_data): Delete la_print_typedef field.
	(language_defn::print_typedef): Declare new member function.
	(LA_PRINT_TYPEDEF): Update call to print_typedef.
	(default_print_typedef): Delete declaration.
	* m2-lang.c (m2_language_data): Delete la_print_typedef
	initializer.
	(m2_language::print_typedef): New member function.
	* objc-lang.c (objc_language_data): Delete la_print_typedef
	initializer.
	* opencl-lang.c (opencl_language_data): Likewise.
	* p-lang.c (pascal_language_data): Likewise.
	(pascal_language::print_typedef): New member function.
	* rust-lang.c (rust_print_typedef): Delete function,
	implementation moved to rust_language::print_typedef.
	(rust_language): Delete la_print_typedef initializer.
	(rust_language::print_typedef): New member function,
	implementation from rust_print_typedef.
	* typeprint.c (default_print_typedef): Delete.
---
 gdb/ChangeLog     | 39 +++++++++++++++++++++++++++++++++++++++
 gdb/ada-lang.c    |  9 ++++++++-
 gdb/c-lang.c      |  4 ----
 gdb/d-lang.c      |  2 --
 gdb/f-lang.c      |  9 ++++++++-
 gdb/go-lang.c     |  2 --
 gdb/language.c    | 27 +++++++++++++++++++++++++--
 gdb/language.h    | 21 +++++++++------------
 gdb/m2-lang.c     | 10 +++++++++-
 gdb/objc-lang.c   |  1 -
 gdb/opencl-lang.c |  1 -
 gdb/p-lang.c      | 10 +++++++++-
 gdb/rust-lang.c   | 25 +++++++++++--------------
 gdb/typeprint.c   |  9 ---------
 14 files changed, 118 insertions(+), 51 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 62ea21a3857..752bf44cef0 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -13681,7 +13681,6 @@ extern const struct language_data ada_language_data =
   macro_expansion_no,
   ada_extensions,
   &ada_exp_descriptor,
-  ada_print_typedef,            /* Print a typedef using appropriate syntax */
   NULL,                         /* name_of_this */
   true,                         /* la_store_sym_names_in_linkage_form_p */
   ada_op_print_tab,             /* expression operators for printing */
@@ -14132,6 +14131,14 @@ class ada_language : public language_defn
 		  force_ellipses, options);
   }
 
+  /* See language.h.  */
+
+  void print_typedef (struct type *type, struct symbol *new_symbol,
+		      struct ui_file *stream) const override
+  {
+    ada_print_typedef (type, new_symbol, stream);
+  }
+
 protected:
   /* See language.h.  */
 
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index d6bbc025bc7..aca0d7a6bc9 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -889,7 +889,6 @@ extern const struct language_data c_language_data =
   macro_expansion_c,
   c_extensions,
   &exp_descriptor_c,
-  c_print_typedef,		/* Print a typedef using appropriate syntax */
   NULL,				/* name_of_this */
   true,				/* la_store_sym_names_in_linkage_form_p */
   c_op_print_tab,		/* expression operators for printing */
@@ -992,7 +991,6 @@ extern const struct language_data cplus_language_data =
   macro_expansion_c,
   cplus_extensions,
   &exp_descriptor_c,
-  c_print_typedef,		/* Print a typedef using appropriate syntax */
   "this",                       /* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
   c_op_print_tab,		/* expression operators for printing */
@@ -1192,7 +1190,6 @@ extern const struct language_data asm_language_data =
   macro_expansion_c,
   asm_extensions,
   &exp_descriptor_c,
-  c_print_typedef,		/* Print a typedef using appropriate syntax */
   NULL,				/* name_of_this */
   true,				/* la_store_sym_names_in_linkage_form_p */
   c_op_print_tab,		/* expression operators for printing */
@@ -1250,7 +1247,6 @@ extern const struct language_data minimal_language_data =
   macro_expansion_c,
   NULL,
   &exp_descriptor_c,
-  c_print_typedef,		/* Print a typedef using appropriate syntax */
   NULL,				/* name_of_this */
   true,				/* la_store_sym_names_in_linkage_form_p */
   c_op_print_tab,		/* expression operators for printing */
diff --git a/gdb/d-lang.c b/gdb/d-lang.c
index 17ab38ee511..b907dd750e0 100644
--- a/gdb/d-lang.c
+++ b/gdb/d-lang.c
@@ -142,8 +142,6 @@ extern const struct language_data d_language_data =
   macro_expansion_no,
   d_extensions,
   &exp_descriptor_c,
-  c_print_typedef,		/* Print a typedef using appropriate
-				   syntax.  */
   "this",
   false,			/* la_store_sym_names_in_linkage_form_p */
   d_op_print_tab,		/* Expression operators for printing.  */
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index 67c2ea34b64..946d5bc25af 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -513,7 +513,6 @@ extern const struct language_data f_language_data =
   macro_expansion_no,
   f_extensions,
   &exp_descriptor_f,
-  f_print_typedef,		/* Print a typedef using appropriate syntax */
   NULL,                    	/* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
   f_op_print_tab,		/* expression operators for printing */
@@ -702,6 +701,14 @@ class f_language : public language_defn
 		      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);
+  }
+
 protected:
 
   /* See language.h.  */
diff --git a/gdb/go-lang.c b/gdb/go-lang.c
index 69f14b8c56c..fa263997b12 100644
--- a/gdb/go-lang.c
+++ b/gdb/go-lang.c
@@ -527,8 +527,6 @@ extern const struct language_data go_language_data =
   macro_expansion_no,
   NULL,
   &exp_descriptor_c,
-  c_print_typedef,		/* Print a typedef using appropriate
-				   syntax.  */
   NULL,				/* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
   go_op_print_tab,		/* Expression operators for printing.  */
diff --git a/gdb/language.c b/gdb/language.c
index 9867ac4b4b5..5ae8c46879c 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -681,6 +681,15 @@ language_defn::printstr (struct ui_file *stream, struct type *elttype,
 	      options);
 }
 
+/* See language.h.  */
+
+void
+language_defn::print_typedef (struct type *type, struct symbol *new_symbol,
+			      struct ui_file *stream) const
+{
+  c_print_typedef (type, new_symbol, stream);
+}
+
 /* The default implementation of the get_symbol_name_matcher_inner method
    from the language_defn class.  Matches with strncmp_iw.  */
 
@@ -774,7 +783,6 @@ extern const struct language_data unknown_language_data =
   macro_expansion_no,
   NULL,
   &exp_descriptor_standard,
-  default_print_typedef,	/* Print a typedef using appropriate syntax */
   "this",        	    	/* name_of_this */
   true,				/* store_sym_names_in_linkage_form_p */
   unk_op_print_tab,		/* expression operators for printing */
@@ -868,6 +876,14 @@ class unknown_language : public language_defn
   {
     error (_("unimplemented unknown_language::printstr called"));
   }
+
+  /* See language.h.  */
+
+  void print_typedef (struct type *type, struct symbol *new_symbol,
+		      struct ui_file *stream) const override
+  {
+    error (_("unimplemented unknown_language::print_typedef called"));
+  }
 };
 
 /* Single instance of the unknown language class.  */
@@ -887,7 +903,6 @@ extern const struct language_data auto_language_data =
   macro_expansion_no,
   NULL,
   &exp_descriptor_standard,
-  default_print_typedef,	/* Print a typedef using appropriate syntax */
   "this",		        /* name_of_this */
   false,			/* store_sym_names_in_linkage_form_p */
   unk_op_print_tab,		/* expression operators for printing */
@@ -981,6 +996,14 @@ class auto_language : public language_defn
   {
     error (_("unimplemented auto_language::printstr called"));
   }
+
+  /* See language.h.  */
+
+  void print_typedef (struct type *type, struct symbol *new_symbol,
+		      struct ui_file *stream) const override
+  {
+    error (_("unimplemented auto_language::print_typedef called"));
+  }
 };
 
 /* Single instance of the fake "auto" language.  */
diff --git a/gdb/language.h b/gdb/language.h
index a68b6dfdcae..19cd8205718 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -225,13 +225,6 @@ struct language_data
 
     const struct exp_descriptor *la_exp_desc;
 
-    /* Print a typedef using syntax appropriate for this language.
-       TYPE is the underlying type.  NEW_SYMBOL is the symbol naming
-       the type.  STREAM is the output stream on which to print.  */
-
-    void (*la_print_typedef) (struct type *type, struct symbol *new_symbol,
-			      struct ui_file *stream);
-
     /* Now come some hooks for lookup_symbol.  */
 
     /* If this is non-NULL, specifies the name that of the implicit
@@ -552,6 +545,14 @@ struct language_defn : language_data
 			 const char *encoding, int force_ellipses,
 			 const struct value_print_options *options) const;
 
+
+  /* Print a typedef using syntax appropriate for this language.
+     TYPE is the underlying type.  NEW_SYMBOL is the symbol naming
+     the type.  STREAM is the output stream on which to print.  */
+
+  virtual void print_typedef (struct type *type, struct symbol *new_symbol,
+			      struct ui_file *stream) const;
+
 protected:
 
   /* This is the overridable part of the GET_SYMBOL_NAME_MATCHER method.
@@ -648,7 +649,7 @@ extern enum language set_language (enum language);
   (current_language->print_type(type,varstring,stream,show,level,flags))
 
 #define LA_PRINT_TYPEDEF(type,new_symbol,stream) \
-  (current_language->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))
@@ -715,10 +716,6 @@ extern char *language_demangle (const struct language_defn *current_language,
    (and returned) by reference at the language level.  */
 struct language_pass_by_ref_info language_pass_by_reference (struct type *type);
 
-/* The default implementation of la_print_typedef.  */
-void default_print_typedef (struct type *type, struct symbol *new_symbol,
-			    struct ui_file *stream);
-
 void c_get_string (struct value *value,
 		   gdb::unique_xmalloc_ptr<gdb_byte> *buffer,
 		   int *length, struct type **char_type,
diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c
index b84a9a49f84..f0f7c22fb5d 100644
--- a/gdb/m2-lang.c
+++ b/gdb/m2-lang.c
@@ -229,7 +229,6 @@ extern const struct language_data m2_language_data =
   macro_expansion_no,
   NULL,
   &exp_descriptor_modula2,
-  m2_print_typedef,		/* Print a typedef using appropriate syntax */
   NULL,		                /* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
   m2_op_print_tab,		/* expression operators for printing */
@@ -427,6 +426,15 @@ class m2_language : public language_defn
     if (force_ellipses || i < length)
       fputs_filtered ("...", stream);
   }
+
+  /* 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);
+  }
+
 };
 
 /* Single instance of the M2 language.  */
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index 95c6c0a1fc5..0c952730a96 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -337,7 +337,6 @@ extern const struct language_data objc_language_data =
   macro_expansion_c,
   objc_extensions,
   &exp_descriptor_standard,
-  c_print_typedef,		/* Print a typedef using appropriate syntax */
   "self",		        /* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
   objc_op_print_tab,		/* Expression operators for printing */
diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
index 765202aac0a..2431faed00e 100644
--- a/gdb/opencl-lang.c
+++ b/gdb/opencl-lang.c
@@ -1016,7 +1016,6 @@ extern const struct language_data opencl_language_data =
   macro_expansion_c,
   NULL,
   &exp_descriptor_opencl,
-  c_print_typedef,		/* Print a typedef using appropriate syntax */
   NULL,                         /* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
   c_op_print_tab,		/* expression operators for printing */
diff --git a/gdb/p-lang.c b/gdb/p-lang.c
index 1c6aea90b6c..9fd823185b1 100644
--- a/gdb/p-lang.c
+++ b/gdb/p-lang.c
@@ -276,7 +276,6 @@ extern const struct language_data pascal_language_data =
   macro_expansion_no,
   p_extensions,
   &exp_descriptor_standard,
-  pascal_print_typedef,		/* Print a typedef using appropriate syntax */
   "this",		        /* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
   pascal_op_print_tab,		/* expression operators for printing */
@@ -494,6 +493,15 @@ class pascal_language : public language_defn
     if (force_ellipses || i < length)
       fputs_filtered ("...", stream);
   }
+
+  /* See language.h.  */
+
+  void print_typedef (struct type *type, struct symbol *new_symbol,
+		      struct ui_file *stream) const override
+  {
+    pascal_print_typedef (type, new_symbol, stream);
+  }
+
 };
 
 /* Single instance of the Pascal language class.  */
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index b13623fe619..083b3f73277 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -765,19 +765,6 @@ rust_print_struct_def (struct type *type, const char *varstring,
   fputs_filtered (is_tuple_struct ? ")" : "}", stream);
 }
 
-/* la_print_typedef implementation for Rust.  */
-
-static void
-rust_print_typedef (struct type *type,
-		    struct symbol *new_symbol,
-		    struct ui_file *stream)
-{
-  type = check_typedef (type);
-  fprintf_filtered (stream, "type %s = ", new_symbol->print_name ());
-  type_print (type, "", stream, 0);
-  fprintf_filtered (stream, ";");
-}
-
 /* la_print_type implementation for Rust.  */
 
 static void
@@ -1953,7 +1940,6 @@ extern const struct language_data rust_language_data =
   macro_expansion_no,
   rust_extensions,
   &exp_descriptor_rust,
-  rust_print_typedef,		/* Print a typedef using appropriate syntax */
   NULL,				/* name_of_this */
   false,			/* la_store_sym_names_in_linkage_form_p */
   c_op_print_tab,		/* expression operators for printing */
@@ -2155,6 +2141,17 @@ class rust_language : public language_defn
     rust_printstr (stream, elttype, string, length, encoding,
 		   force_ellipses, options);
   }
+
+  /* See language.h.  */
+
+  void print_typedef (struct type *type, struct symbol *new_symbol,
+		      struct ui_file *stream) const override
+  {
+    type = check_typedef (type);
+    fprintf_filtered (stream, "type %s = ", new_symbol->print_name ());
+    type_print (type, "", stream, 0);
+    fprintf_filtered (stream, ";");
+  }
 };
 
 /* Single instance of the Rust language class.  */
diff --git a/gdb/typeprint.c b/gdb/typeprint.c
index 37409d9a210..08b9a426eac 100644
--- a/gdb/typeprint.c
+++ b/gdb/typeprint.c
@@ -368,15 +368,6 @@ typedef_print (struct type *type, struct symbol *newobj, struct ui_file *stream)
   LA_PRINT_TYPEDEF (type, newobj, stream);
 }
 
-/* The default way to print a typedef.  */
-
-void
-default_print_typedef (struct type *type, struct symbol *new_symbol,
-		       struct ui_file *stream)
-{
-  error (_("Language not supported."));
-}
-
 /* Print a description of a type TYPE in the form of a declaration of a
    variable named VARSTRING.  (VARSTRING is demangled if necessary.)
    Output goes to STREAM (via stdio).
-- 
2.25.4


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

* [PATCH 7/7] gdb: Convert language la_is_string_type_p field to a method
  2020-06-18 22:31 [PATCH 0/7] Language Class Hierarchy Conversion (Prt 3) Andrew Burgess
                   ` (5 preceding siblings ...)
  2020-06-18 22:31 ` [PATCH 6/7] gdb: Convert language la_print_typedef " Andrew Burgess
@ 2020-06-18 22:31 ` Andrew Burgess
  2020-06-19 14:25 ` [PATCH 0/7] Language Class Hierarchy Conversion (Prt 3) Tom Tromey
  7 siblings, 0 replies; 10+ messages in thread
From: Andrew Burgess @ 2020-06-18 22:31 UTC (permalink / raw)
  To: gdb-patches

This commit changes the language_data::la_is_string_type_p function
pointer member variable into a member function of language_defn.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* ada-lang.c (ada_language_data): Delete la_is_string_type_p
	initializer.
	(ada_language::is_string_type_p): New member function.
	* c-lang.c (c_language_data): Delete la_is_string_type_p
	initializer.
	(cplus_language_data): Likewise.
	(asm_language_data): Likewise.
	(minimal_language_data): Likewise.
	* d-lang.c (d_language_data): Likewise.
	* f-lang.c (f_is_string_type_p): Delete function, implementation
	moved to f_language::is_string_type_p.
	(f_language_data): Delete la_is_string_type_p initializer.
	(f_language::is_string_type_p): New member function,
	implementation from f_is_string_type_p.
	* go-lang.c (go_is_string_type_p): Delete function, implementation
	moved to go_language::is_string_type_p.
	(go_language_data): Delete la_is_string_type_p initializer.
	(go_language::is_string_type_p): New member function,
	implementation from go_is_string_type_p.
	* language.c (language_defn::is_string_type_p): Define new member
	function.
	(default_is_string_type_p): Make static, add comment copied from
	header file.
	(unknown_language_data): Delete la_is_string_type_p initializer.
	(unknown_language::is_string_type_p): New member function.
	(auto_language_data): Delete la_is_string_type_p initializer.
	(auto_language::is_string_type_p): New member function.
	* language.h (language_data): Delete la_is_string_type_p field.
	(language_defn::is_string_type_p): Declare new function.
	(default_is_string_type_p): Delete desclaration, move comment to
	definition.
	* m2-lang.c (m2_is_string_type_p): Delete function, implementation
	moved to m2_language::is_string_type_p.
	(m2_language_data): Delete la_is_string_type_p initializer.
	(m2_language::is_string_type_p): New member function,
	implementation from m2_is_string_type_p.
	* objc-lang.c (objc_language_data): Delete la_is_string_type_p
	initializer.
	* opencl-lang.c (opencl_language_data): Likewise.
	* p-lang.c (pascal_is_string_type_p): Delete function,
	implementation moved to pascal_language::is_string_type_p.
	(pascal_language_data): Delete la_is_string_type_p initializer.
	(pascal_language::is_string_type_p): New member function,
	implementation from pascal_is_string_type_p.
	* rust-lang.c (rust_is_string_type_p): Delete function,
	implementation moved to rust_language::is_string_type_p.
	(rust_language_data): Delete la_is_string_type_p initializer.
	(rust_language::is_string_type_p): New member function,
	implementation from rust_is_string_type_p.
	* valprint.c (val_print_scalar_or_string_type_p): Update call to
	is_string_type_p.
---
 gdb/ChangeLog     | 54 +++++++++++++++++++++++++++++++++++++++++++++++
 gdb/ada-lang.c    |  9 +++++++-
 gdb/c-lang.c      |  4 ----
 gdb/d-lang.c      |  1 -
 gdb/f-lang.c      | 22 +++++++++----------
 gdb/go-lang.c     | 21 +++++++++---------
 gdb/language.c    | 29 +++++++++++++++++++++----
 gdb/language.h    | 10 +++------
 gdb/m2-lang.c     | 41 +++++++++++++++++------------------
 gdb/objc-lang.c   |  1 -
 gdb/opencl-lang.c |  1 -
 gdb/p-lang.c      | 18 ++++++----------
 gdb/rust-lang.c   | 40 +++++++++++++++++------------------
 gdb/valprint.c    |  2 +-
 14 files changed, 156 insertions(+), 97 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 752bf44cef0..9b0c2efbfe2 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -13687,7 +13687,6 @@ extern const struct language_data ada_language_data =
   0,                            /* c-style arrays */
   1,                            /* String lower bound */
   &ada_varobj_ops,
-  ada_is_string_type,
   "(...)"			/* la_struct_too_deep_ellipsis */
 };
 
@@ -14139,6 +14138,14 @@ class ada_language : public language_defn
     ada_print_typedef (type, new_symbol, stream);
   }
 
+  /* See language.h.  */
+
+  bool is_string_type_p (struct type *type) const override
+  {
+    return ada_is_string_type (type);
+  }
+
+
 protected:
   /* See language.h.  */
 
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index aca0d7a6bc9..f29f2cef610 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -895,7 +895,6 @@ extern const struct language_data c_language_data =
   1,				/* c-style arrays */
   0,				/* String lower bound */
   &c_varobj_ops,
-  c_is_string_type_p,
   "{...}"			/* la_struct_too_deep_ellipsis */
 };
 
@@ -997,7 +996,6 @@ extern const struct language_data cplus_language_data =
   1,				/* c-style arrays */
   0,				/* String lower bound */
   &cplus_varobj_ops,
-  c_is_string_type_p,
   "{...}"			/* la_struct_too_deep_ellipsis */
 };
 
@@ -1196,7 +1194,6 @@ extern const struct language_data asm_language_data =
   1,				/* c-style arrays */
   0,				/* String lower bound */
   &default_varobj_ops,
-  c_is_string_type_p,
   "{...}"			/* la_struct_too_deep_ellipsis */
 };
 
@@ -1253,7 +1250,6 @@ extern const struct language_data minimal_language_data =
   1,				/* c-style arrays */
   0,				/* String lower bound */
   &default_varobj_ops,
-  c_is_string_type_p,
   "{...}"			/* la_struct_too_deep_ellipsis */
 };
 
diff --git a/gdb/d-lang.c b/gdb/d-lang.c
index b907dd750e0..4ebb011ee9b 100644
--- a/gdb/d-lang.c
+++ b/gdb/d-lang.c
@@ -148,7 +148,6 @@ extern const struct language_data d_language_data =
   1,				/* C-style arrays.  */
   0,				/* String lower bound.  */
   &default_varobj_ops,
-  c_is_string_type_p,
   "{...}"			/* la_struct_too_deep_ellipsis */
 };
 
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index 946d5bc25af..58b41d11d11 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -291,17 +291,6 @@ evaluate_subexp_f (struct type *expect_type, struct expression *exp,
   return nullptr;
 }
 
-/* Return true if TYPE is a string.  */
-
-static bool
-f_is_string_type_p (struct type *type)
-{
-  type = check_typedef (type);
-  return (type->code () == TYPE_CODE_STRING
-	  || (type->code () == TYPE_CODE_ARRAY
-	      && TYPE_TARGET_TYPE (type)->code () == TYPE_CODE_CHAR));
-}
-
 /* Special expression lengths for Fortran.  */
 
 static void
@@ -519,7 +508,6 @@ extern const struct language_data f_language_data =
   0,				/* arrays are first-class (not c-style) */
   1,				/* String lower bound */
   &default_varobj_ops,
-  f_is_string_type_p,
   "(...)"			/* la_struct_too_deep_ellipsis */
 };
 
@@ -709,6 +697,16 @@ class f_language : public language_defn
     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));
+  }
+
 protected:
 
   /* See language.h.  */
diff --git a/gdb/go-lang.c b/gdb/go-lang.c
index fa263997b12..cb42ef1b7cf 100644
--- a/gdb/go-lang.c
+++ b/gdb/go-lang.c
@@ -131,16 +131,6 @@ go_classify_struct_type (struct type *type)
   return GO_TYPE_NONE;
 }
 
-/* Return true if TYPE is a string.  */
-
-static bool
-go_is_string_type_p (struct type *type)
-{
-  type = check_typedef (type);
-  return (type->code () == TYPE_CODE_STRUCT
-	  && go_classify_struct_type (type) == GO_TYPE_STRING);
-}
-
 /* Subroutine of unpack_mangled_go_symbol to simplify it.
    Given "[foo.]bar.baz", store "bar" in *PACKAGEP and "baz" in *OBJECTP.
    We stomp on the last '.' to nul-terminate "bar".
@@ -533,7 +523,6 @@ extern const struct language_data go_language_data =
   1,				/* C-style arrays.  */
   0,				/* String lower bound.  */
   &default_varobj_ops,
-  go_is_string_type_p,
   "{...}"			/* la_struct_too_deep_ellipsis */
 };
 
@@ -638,6 +627,16 @@ class go_language : public language_defn
   {
     return go_parse (ps);
   }
+
+  /* See language.h.  */
+
+  bool is_string_type_p (struct type *type) const override
+  {
+    type = check_typedef (type);
+    return (type->code () == TYPE_CODE_STRUCT
+	    && go_classify_struct_type (type) == GO_TYPE_STRING);
+  }
+
 };
 
 /* Single instance of the Go language class.  */
diff --git a/gdb/language.c b/gdb/language.c
index 5ae8c46879c..c993cfc57a6 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -690,6 +690,14 @@ language_defn::print_typedef (struct type *type, struct symbol *new_symbol,
   c_print_typedef (type, new_symbol, stream);
 }
 
+/* See language.h.  */
+
+bool
+language_defn::is_string_type_p (struct type *type) const
+{
+  return c_is_string_type_p (type);
+}
+
 /* The default implementation of the get_symbol_name_matcher_inner method
    from the language_defn class.  Matches with strncmp_iw.  */
 
@@ -741,9 +749,10 @@ language_defn::get_symbol_name_matcher_inner
   return default_symbol_name_matcher;
 }
 
-/* See language.h.  */
+/* Return true if TYPE is a string type, otherwise return false.  This
+   default implementation only detects TYPE_CODE_STRING.  */
 
-bool
+static bool
 default_is_string_type_p (struct type *type)
 {
   type = check_typedef (type);
@@ -789,7 +798,6 @@ extern const struct language_data unknown_language_data =
   1,				/* c-style arrays */
   0,				/* String lower bound */
   &default_varobj_ops,
-  default_is_string_type_p,
   "{...}"			/* la_struct_too_deep_ellipsis */
 };
 
@@ -884,6 +892,13 @@ class unknown_language : public language_defn
   {
     error (_("unimplemented unknown_language::print_typedef called"));
   }
+
+  /* See language.h.  */
+
+  bool is_string_type_p (struct type *type) const override
+  {
+    return default_is_string_type_p (type);
+  }
 };
 
 /* Single instance of the unknown language class.  */
@@ -909,7 +924,6 @@ extern const struct language_data auto_language_data =
   1,				/* c-style arrays */
   0,				/* String lower bound */
   &default_varobj_ops,
-  default_is_string_type_p,
   "{...}"			/* la_struct_too_deep_ellipsis */
 };
 
@@ -1004,6 +1018,13 @@ class auto_language : public language_defn
   {
     error (_("unimplemented auto_language::print_typedef called"));
   }
+
+  /* See language.h.  */
+
+  bool is_string_type_p (struct type *type) const override
+  {
+    return default_is_string_type_p (type);
+  }
 };
 
 /* Single instance of the fake "auto" language.  */
diff --git a/gdb/language.h b/gdb/language.h
index 19cd8205718..d2e5b733077 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -267,9 +267,6 @@ struct language_data
     /* Various operations on varobj.  */
     const struct lang_varobj_ops *la_varobj_ops;
 
-    /* Return true if TYPE is a string type.  */
-    bool (*la_is_string_type_p) (struct type *type);
-
     /* This string is used by the 'set print max-depth' setting.  When GDB
        replaces a struct or union (during value printing) that is "too
        deep" this string is displayed instead.  */
@@ -553,6 +550,9 @@ struct language_defn : language_data
   virtual void print_typedef (struct type *type, struct symbol *new_symbol,
 			      struct ui_file *stream) const;
 
+  /* Return true if TYPE is a string type.  */
+  virtual bool is_string_type_p (struct type *type) const;
+
 protected:
 
   /* This is the overridable part of the GET_SYMBOL_NAME_MATCHER method.
@@ -684,10 +684,6 @@ extern enum language set_language (enum language);
 
 extern int pointer_type (struct type *);
 
-/* Return true if TYPE is a string type, otherwise return false.  This
-   default implementation only detects TYPE_CODE_STRING.  */
-extern bool default_is_string_type_p (struct type *type);
-
 /* Error messages */
 
 extern void range_error (const char *, ...) ATTRIBUTE_PRINTF (1, 2);
diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c
index f0f7c22fb5d..2c39359d289 100644
--- a/gdb/m2-lang.c
+++ b/gdb/m2-lang.c
@@ -42,27 +42,6 @@ m2_printchar (int c, struct type *type, struct ui_file *stream)
   fputs_filtered ("'", stream);
 }
 
-/* Return true if TYPE is a string.  */
-
-static bool
-m2_is_string_type_p (struct type *type)
-{
-  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;
-}
-
 static struct value *
 evaluate_subexp_modula2 (struct type *expect_type, struct expression *exp,
 			 int *pos, enum noside noside)
@@ -235,7 +214,6 @@ extern const struct language_data m2_language_data =
   0,				/* arrays are first-class (not c-style) */
   0,				/* String lower bound */
   &default_varobj_ops,
-  m2_is_string_type_p,
   "{...}"			/* la_struct_too_deep_ellipsis */
 };
 
@@ -435,6 +413,25 @@ class m2_language : public language_defn
     m2_print_typedef (type, new_symbol, stream);
   }
 
+  /* 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;
+  }
 };
 
 /* Single instance of the M2 language.  */
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index 0c952730a96..63cdac1b035 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -343,7 +343,6 @@ extern const struct language_data objc_language_data =
   1,				/* C-style arrays */
   0,				/* String lower bound */
   &default_varobj_ops,
-  c_is_string_type_p,
   "{...}"			/* la_struct_too_deep_ellipsis */
 };
 
diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
index 2431faed00e..eccf1df9621 100644
--- a/gdb/opencl-lang.c
+++ b/gdb/opencl-lang.c
@@ -1022,7 +1022,6 @@ extern const struct language_data opencl_language_data =
   1,				/* c-style arrays */
   0,				/* String lower bound */
   &default_varobj_ops,
-  c_is_string_type_p,
   "{...}"			/* la_struct_too_deep_ellipsis */
 };
 
diff --git a/gdb/p-lang.c b/gdb/p-lang.c
index 9fd823185b1..07afbdda5bb 100644
--- a/gdb/p-lang.c
+++ b/gdb/p-lang.c
@@ -152,16 +152,6 @@ is_pascal_string_type (struct type *type,int *length_pos,
   return 0;
 }
 
-/* This is a wrapper around IS_PASCAL_STRING_TYPE that returns true if TYPE
-   is a string.  */
-
-static bool
-pascal_is_string_type_p (struct type *type)
-{
-  return is_pascal_string_type (type, nullptr, nullptr, nullptr,
-				nullptr, nullptr) > 0;
-}
-
 static void pascal_one_char (int, struct ui_file *, int *);
 
 /* Print the character C on STREAM as part of the contents of a literal
@@ -282,7 +272,6 @@ extern const struct language_data pascal_language_data =
   1,				/* c-style arrays */
   0,				/* String lower bound */
   &default_varobj_ops,
-  pascal_is_string_type_p,
   "{...}"			/* la_struct_too_deep_ellipsis */
 };
 
@@ -502,6 +491,13 @@ class pascal_language : public language_defn
     pascal_print_typedef (type, new_symbol, stream);
   }
 
+  /* See language.h.  */
+
+  bool is_string_type_p (struct type *type) const override
+  {
+    return is_pascal_string_type (type, nullptr, nullptr, nullptr,
+				  nullptr, nullptr) > 0;
+  }
 };
 
 /* Single instance of the Pascal language class.  */
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index 083b3f73277..d1efea19e91 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -226,26 +226,6 @@ rust_chartype_p (struct type *type)
 	  && TYPE_UNSIGNED (type));
 }
 
-/* Return true if TYPE is a string type.  */
-
-static bool
-rust_is_string_type_p (struct type *type)
-{
-  LONGEST low_bound, high_bound;
-
-  type = check_typedef (type);
-  return ((type->code () == TYPE_CODE_STRING)
-	  || (type->code () == TYPE_CODE_PTR
-	      && (TYPE_TARGET_TYPE (type)->code () == TYPE_CODE_ARRAY
-		  && rust_u8_type_p (TYPE_TARGET_TYPE (TYPE_TARGET_TYPE (type)))
-		  && get_array_bounds (TYPE_TARGET_TYPE (type), &low_bound,
-				       &high_bound)))
-	  || (type->code () == TYPE_CODE_STRUCT
-	      && !rust_enum_p (type)
-	      && rust_slice_type_p (type)
-	      && strcmp (type->name (), "&str") == 0));
-}
-
 /* If VALUE represents a trait object pointer, return the underlying
    pointer with the correct (i.e., runtime) type.  Otherwise, return
    NULL.  */
@@ -1946,7 +1926,6 @@ extern const struct language_data rust_language_data =
   1,				/* c-style arrays */
   0,				/* String lower bound */
   &default_varobj_ops,
-  rust_is_string_type_p,
   "{...}"			/* la_struct_too_deep_ellipsis */
 };
 
@@ -2152,6 +2131,25 @@ class rust_language : public language_defn
     type_print (type, "", stream, 0);
     fprintf_filtered (stream, ";");
   }
+
+  /* See language.h.  */
+
+  bool is_string_type_p (struct type *type) const override
+  {
+    LONGEST low_bound, high_bound;
+
+    type = check_typedef (type);
+    return ((type->code () == TYPE_CODE_STRING)
+	    || (type->code () == TYPE_CODE_PTR
+		&& (TYPE_TARGET_TYPE (type)->code () == TYPE_CODE_ARRAY
+		    && rust_u8_type_p (TYPE_TARGET_TYPE (TYPE_TARGET_TYPE (type)))
+		    && get_array_bounds (TYPE_TARGET_TYPE (type), &low_bound,
+					 &high_bound)))
+	    || (type->code () == TYPE_CODE_STRUCT
+		&& !rust_enum_p (type)
+		&& rust_slice_type_p (type)
+		&& strcmp (type->name (), "&str") == 0));
+  }
 };
 
 /* Single instance of the Rust language class.  */
diff --git a/gdb/valprint.c b/gdb/valprint.c
index 51c77c3e6d2..db98ca2abc9 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -298,7 +298,7 @@ val_print_scalar_or_string_type_p (struct type *type,
 				   const struct language_defn *language)
 {
   return (val_print_scalar_type_p (type)
-	  || language->la_is_string_type_p (type));
+	  || language->is_string_type_p (type));
 }
 
 /* See its definition in value.h.  */
-- 
2.25.4


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

* Re: [PATCH 0/7] Language Class Hierarchy Conversion (Prt 3)
  2020-06-18 22:31 [PATCH 0/7] Language Class Hierarchy Conversion (Prt 3) Andrew Burgess
                   ` (6 preceding siblings ...)
  2020-06-18 22:31 ` [PATCH 7/7] gdb: Convert language la_is_string_type_p " Andrew Burgess
@ 2020-06-19 14:25 ` Tom Tromey
  2020-06-19 16:18   ` Andrew Burgess
  7 siblings, 1 reply; 10+ messages in thread
From: Tom Tromey @ 2020-06-19 14:25 UTC (permalink / raw)
  To: Andrew Burgess; +Cc: gdb-patches

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

Andrew> In this third patch set I convert the last remaining function pointers
Andrew> in the language_base structure into member function in language_defn.

Andrew> There wasn't anything particularaly tricky in this batch.

I skimmed these and it all seems fine to me.

Andrew> After this set my plans are (in no particular order):

Andrew>   - Convert at least some of the data members in language_base into
Andrew>     member function in language_defn.

Andrew>   - Move some of the language classes into header files so that member
Andrew>     functions can be defined in different .c files.  This will allow
Andrew>     me to remove most of the member functions that currently just
Andrew>     redirect to a function in another file.

Andrew>   - Possibly restructure the language class hierarchy to increase the
Andrew>     amount of sharing that exists between similar languages.

Andrew>   - Make more of the per-language helper functions private functions
Andrew>     within the language classes.

Andrew> Thoughts, feedback, or ideas always welcome.

I wouldn't mind getting rid of the LA_* macros.  Especially after this
series, I don't think they add much.

Tom

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

* Re: [PATCH 0/7] Language Class Hierarchy Conversion (Prt 3)
  2020-06-19 14:25 ` [PATCH 0/7] Language Class Hierarchy Conversion (Prt 3) Tom Tromey
@ 2020-06-19 16:18   ` Andrew Burgess
  0 siblings, 0 replies; 10+ messages in thread
From: Andrew Burgess @ 2020-06-19 16:18 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

* Tom Tromey <tom@tromey.com> [2020-06-19 08:25:56 -0600]:

> >>>>> "Andrew" == Andrew Burgess <andrew.burgess@embecosm.com> writes:
> 
> Andrew> In this third patch set I convert the last remaining function pointers
> Andrew> in the language_base structure into member function in language_defn.
> 
> Andrew> There wasn't anything particularaly tricky in this batch.
> 
> I skimmed these and it all seems fine to me.
> 
> Andrew> After this set my plans are (in no particular order):
> 
> Andrew>   - Convert at least some of the data members in language_base into
> Andrew>     member function in language_defn.
> 
> Andrew>   - Move some of the language classes into header files so that member
> Andrew>     functions can be defined in different .c files.  This will allow
> Andrew>     me to remove most of the member functions that currently just
> Andrew>     redirect to a function in another file.
> 
> Andrew>   - Possibly restructure the language class hierarchy to increase the
> Andrew>     amount of sharing that exists between similar languages.
> 
> Andrew>   - Make more of the per-language helper functions private functions
> Andrew>     within the language classes.
> 
> Andrew> Thoughts, feedback, or ideas always welcome.
> 
> I wouldn't mind getting rid of the LA_* macros.  Especially after this
> series, I don't think they add much.

In many cases they hide an access of current_language.  In my mind,
ideally, I like to use current_language less.  So, when you parse an
expression at the prompt at some point this would trigger some kind of
current_language->entry_point_function (....), but after that we
should remain within the language class as much as possible to parse
the expression, and not be using current_language at all.

But yes, I'd also like to see those macros gone :)

Thanks,
Andrew

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

end of thread, other threads:[~2020-06-19 16:18 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-18 22:31 [PATCH 0/7] Language Class Hierarchy Conversion (Prt 3) Andrew Burgess
2020-06-18 22:31 ` [PATCH 1/7] gdb: Convert language la_parser field to a method Andrew Burgess
2020-06-18 22:31 ` [PATCH 2/7] gdb: Convert language la_post_parser " Andrew Burgess
2020-06-18 22:31 ` [PATCH 3/7] gdb: Convert language la_emitchar " Andrew Burgess
2020-06-18 22:31 ` [PATCH 4/7] gdb: Convert language la_printchar " Andrew Burgess
2020-06-18 22:31 ` [PATCH 5/7] gdb: Convert language la_printstr " Andrew Burgess
2020-06-18 22:31 ` [PATCH 6/7] gdb: Convert language la_print_typedef " Andrew Burgess
2020-06-18 22:31 ` [PATCH 7/7] gdb: Convert language la_is_string_type_p " Andrew Burgess
2020-06-19 14:25 ` [PATCH 0/7] Language Class Hierarchy Conversion (Prt 3) Tom Tromey
2020-06-19 16:18   ` Andrew Burgess

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