[PATCHv2,11/18] gdb: Convert language_data::la_range_check to a method

Message ID abda2195bec09a7f82dc9400f4147abac5dade2e.1596638296.git.andrew.burgess@embecosm.com
State New
Headers show
Series
  • Further updates for the language class structure
Related show

Commit Message

Andrew Burgess Aug. 5, 2020, 2:45 p.m.
Convert language_data::la_range_check member variable to a virtual
method language_defn::range_checking_on_by_default.

Where the previous member variable was of type 'enum range_check', the
new member function returns a boolean that selects between range
checking being on or off.  This removes the possibility of a language
having its default be the third enum state, range_check_warn.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* ada-lang.c (ada_language_data): Remove la_range_check
	initializer.
	* c-lang.c (c_language_data): Likewise.
	(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::range_checking_on_by_default): New member function.
	* go-lang.c (go_language_data): Remove la_range_check initializer.
	* language.c (enum range_mode): Moved here from language.h.
	(range_mode): Made static.
	(show_range_command): Update to use
	range_checking_on_by_default.
	(set_range_command): Likewise.
	(set_range_case): Likewise.
	(unknown_language_data): Remove la_range_check initializer.
	(auto_language_data): Likewise.
	* language.h (range_mode): Delete.  Enum definition moved to
	language.c.
	(language_data): Remove la_range_check field.
	(language_defn::range_checking_on_by_default): New member
	function.
	* m2-lang.c (m2_language_data): Remove la_range_check initializer.
	(m2_language::range_checking_on_by_default): New member function.
	* objc-lang.c (objc_language_data): Remove la_range_check
	initializer.
	* opencl-lang.c (opencl_language_data): Likewise.
	* p-lang.c (pascal_language_data): Likewise.
	(pascal_language::range_checking_on_by_default): New member
	function.
	* rust-lang.c (rust_language_data): Remove la_range_check
	initializer.
	(rust_language::range_checking_on_by_default): New member
	function.
---
 gdb/ChangeLog     | 38 ++++++++++++++++++++++++++++++++++++++
 gdb/ada-lang.c    |  1 -
 gdb/c-lang.c      |  4 ----
 gdb/d-lang.c      |  1 -
 gdb/f-lang.c      |  6 +++++-
 gdb/go-lang.c     |  1 -
 gdb/language.c    | 24 ++++++++++++++++++------
 gdb/language.h    | 21 +++++++--------------
 gdb/m2-lang.c     |  6 +++++-
 gdb/objc-lang.c   |  1 -
 gdb/opencl-lang.c |  1 -
 gdb/p-lang.c      |  6 +++++-
 gdb/rust-lang.c   |  6 +++++-
 13 files changed, 83 insertions(+), 33 deletions(-)

-- 
2.25.4

Patch

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 58b3c7b654f..1100742c1f5 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -13708,7 +13708,6 @@  ada_get_symbol_name_matcher (const lookup_name_info &lookup_name)
 
 extern const struct language_data ada_language_data =
 {
-  range_check_off,
   case_sensitive_on,            /* Yes, Ada is case-insensitive, but
                                    that's not quite what this means.  */
   array_row_major,
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index c8fe630c247..88af4585b21 100644
--- a/gdb/c-lang.c
+++ b/gdb/c-lang.c
@@ -875,7 +875,6 @@  const struct exp_descriptor exp_descriptor_c =
 
 extern const struct language_data c_language_data =
 {
-  range_check_off,
   case_sensitive_on,
   array_row_major,
   macro_expansion_c,
@@ -985,7 +984,6 @@  enum cplus_primitive_types {
 
 extern const struct language_data cplus_language_data =
 {
-  range_check_off,
   case_sensitive_on,
   array_row_major,
   macro_expansion_c,
@@ -1193,7 +1191,6 @@  static cplus_language cplus_language_defn;
 
 extern const struct language_data asm_language_data =
 {
-  range_check_off,
   case_sensitive_on,
   array_row_major,
   macro_expansion_c,
@@ -1264,7 +1261,6 @@  static asm_language asm_language_defn;
 
 extern const struct language_data minimal_language_data =
 {
-  range_check_off,
   case_sensitive_on,
   array_row_major,
   macro_expansion_c,
diff --git a/gdb/d-lang.c b/gdb/d-lang.c
index 9d491c7b854..d1dad29945a 100644
--- a/gdb/d-lang.c
+++ b/gdb/d-lang.c
@@ -128,7 +128,6 @@  enum d_primitive_types {
 
 extern const struct language_data d_language_data =
 {
-  range_check_off,
   case_sensitive_on,
   array_row_major,
   macro_expansion_no,
diff --git a/gdb/f-lang.c b/gdb/f-lang.c
index cffdf559cff..5e1f0f79443 100644
--- a/gdb/f-lang.c
+++ b/gdb/f-lang.c
@@ -486,7 +486,6 @@  static const struct exp_descriptor exp_descriptor_f =
 
 extern const struct language_data f_language_data =
 {
-  range_check_on,
   case_sensitive_off,
   array_column_major,
   macro_expansion_no,
@@ -722,6 +721,11 @@  class f_language : public language_defn
   bool c_style_arrays_p () const override
   { return false; }
 
+  /* See language.h.  */
+
+  bool range_checking_on_by_default () const override
+  { return true; }
+
 protected:
 
   /* See language.h.  */
diff --git a/gdb/go-lang.c b/gdb/go-lang.c
index dfc0dddc616..f5abd518e22 100644
--- a/gdb/go-lang.c
+++ b/gdb/go-lang.c
@@ -508,7 +508,6 @@  enum go_primitive_types {
 
 extern const struct language_data go_language_data =
 {
-  range_check_off,
   case_sensitive_on,
   array_row_major,
   macro_expansion_no,
diff --git a/gdb/language.c b/gdb/language.c
index 3503408ad21..56b3b2eb306 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -49,12 +49,21 @@ 
 
 static void set_range_case (void);
 
+/* range_mode ==
+   range_mode_auto:   range_check set automatically to default of language.
+   range_mode_manual: range_check set manually by user.  */
+
+enum range_mode
+  {
+    range_mode_auto, range_mode_manual
+  };
+
 /* 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
    language of the first source file.  */
 
-enum range_mode range_mode = range_mode_auto;
+static enum range_mode range_mode = range_mode_auto;
 enum range_check range_check = range_check_off;
 enum case_mode case_mode = case_mode_auto;
 enum case_sensitivity case_sensitivity = case_sensitive_on;
@@ -209,7 +218,9 @@  show_range_command (struct ui_file *file, int from_tty,
     fprintf_filtered (gdb_stdout, _("Range checking is \"%s\".\n"),
 		      value);
 
-  if (range_check != current_language->la_range_check)
+  if (range_check == range_check_warn
+      || ((range_check == range_check_on)
+	  != current_language->range_checking_on_by_default ()))
     warning (_("the current range check setting "
 	       "does not match the language.\n"));
 }
@@ -245,7 +256,9 @@  set_range_command (const char *ignore,
       internal_error (__FILE__, __LINE__,
 		      _("Unrecognized range check setting: \"%s\""), range);
     }
-  if (range_check != current_language->la_range_check)
+  if (range_check == range_check_warn
+      || ((range_check == range_check_on)
+	  != current_language->range_checking_on_by_default ()))
     warning (_("the current range check setting "
 	       "does not match the language.\n"));
 }
@@ -329,7 +342,8 @@  static void
 set_range_case (void)
 {
   if (range_mode == range_mode_auto)
-    range_check = current_language->la_range_check;
+    range_check = (current_language->range_checking_on_by_default ()
+		   ? range_check_on : range_check_off);
 
   if (case_mode == case_mode_auto)
     case_sensitivity = current_language->la_case_sensitivity;
@@ -775,7 +789,6 @@  unknown_language_arch_info (struct gdbarch *gdbarch,
 
 extern const struct language_data unknown_language_data =
 {
-  range_check_off,
   case_sensitive_on,
   array_row_major,
   macro_expansion_no,
@@ -912,7 +925,6 @@  static unknown_language unknown_language_defn;
 
 extern const struct language_data auto_language_data =
 {
-  range_check_off,
   case_sensitive_on,
   array_row_major,
   macro_expansion_no,
diff --git a/gdb/language.h b/gdb/language.h
index 10a9e707320..ffdcdbc21f8 100644
--- a/gdb/language.h
+++ b/gdb/language.h
@@ -42,16 +42,6 @@  class innermost_block_tracker;
 
 #define MAX_FORTRAN_DIMS  7	/* Maximum number of F77 array dims.  */
 
-/* range_mode ==
-   range_mode_auto:   range_check set automatically to default of language.
-   range_mode_manual: range_check set manually by user.  */
-
-extern enum range_mode
-  {
-    range_mode_auto, range_mode_manual
-  }
-range_mode;
-
 /* range_check ==
    range_check_on:    Ranges are checked in GDB expressions, producing errors.
    range_check_warn:  Ranges are checked, producing warnings.
@@ -188,10 +178,6 @@  extern const char *default_word_break_characters (void);
 
 struct language_data
   {
-    /* Default range checking.  */
-
-    enum range_check la_range_check;
-
     /* Default case sensitivity.  */
     enum case_sensitivity la_case_sensitivity;
 
@@ -572,6 +558,13 @@  struct language_defn : language_data
   virtual bool store_sym_names_in_linkage_form_p () const
   { return false; }
 
+  /* Default range checking preference.  The return value from this
+     function provides the automatic setting for 'set check range'.  As a
+     consequence a user is free to override this setting if they want.  */
+
+  virtual bool range_checking_on_by_default () const
+  { return false; }
+
 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 577d8192114..785436c4f22 100644
--- a/gdb/m2-lang.c
+++ b/gdb/m2-lang.c
@@ -199,7 +199,6 @@  const struct exp_descriptor exp_descriptor_modula2 =
 
 extern const struct language_data m2_language_data =
 {
-  range_check_on,
   case_sensitive_on,
   array_row_major,
   macro_expansion_no,
@@ -444,6 +443,11 @@  class m2_language : public language_defn
 
   char string_lower_bound () const override
   { return 0; }
+
+  /* See language.h.  */
+
+  bool range_checking_on_by_default () const override
+  { return true; }
 };
 
 /* Single instance of the M2 language.  */
diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c
index 7b2dbd8bfa2..1788910c8d5 100644
--- a/gdb/objc-lang.c
+++ b/gdb/objc-lang.c
@@ -323,7 +323,6 @@  static const struct op_print objc_op_print_tab[] =
 
 extern const struct language_data objc_language_data =
 {
-  range_check_off,
   case_sensitive_on,
   array_row_major,
   macro_expansion_c,
diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c
index 1e4c28ba230..98486b1af59 100644
--- a/gdb/opencl-lang.c
+++ b/gdb/opencl-lang.c
@@ -1007,7 +1007,6 @@  const struct exp_descriptor exp_descriptor_opencl =
 /* Constant data representing the OpenCL language.  */
 extern const struct language_data opencl_language_data =
 {
-  range_check_off,
   case_sensitive_on,
   array_row_major,
   macro_expansion_c,
diff --git a/gdb/p-lang.c b/gdb/p-lang.c
index 9ca1427098e..2325aca96b5 100644
--- a/gdb/p-lang.c
+++ b/gdb/p-lang.c
@@ -252,7 +252,6 @@  enum pascal_primitive_types {
 
 extern const struct language_data pascal_language_data =
 {
-  range_check_on,
   case_sensitive_on,
   array_row_major,
   macro_expansion_no,
@@ -508,6 +507,11 @@  class pascal_language : public language_defn
 
   const char *name_of_this () const override
   { return "this"; }
+
+  /* See language.h.  */
+
+  bool range_checking_on_by_default () const override
+  { return true; }
 };
 
 /* Single instance of the Pascal language class.  */
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index e2d011acde1..b952d26d720 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -1906,7 +1906,6 @@  static const struct exp_descriptor exp_descriptor_rust =
 
 extern const struct language_data rust_language_data =
 {
-  range_check_on,
   case_sensitive_on,
   array_row_major,
   macro_expansion_no,
@@ -2154,6 +2153,11 @@  class rust_language : public language_defn
 		&& rust_slice_type_p (type)
 		&& strcmp (type->name (), "&str") == 0));
   }
+
+  /* See language.h.  */
+
+  bool range_checking_on_by_default () const override
+  { return true; }
 };
 
 /* Single instance of the Rust language class.  */