gdb: Convert language_data::string_lower_bound to a method
authorAndrew Burgess <andrew.burgess@embecosm.com>
Sun, 5 Jul 2020 08:29:34 +0000 (09:29 +0100)
committerAndrew Burgess <andrew.burgess@embecosm.com>
Wed, 16 Sep 2020 09:16:48 +0000 (10:16 +0100)
Convert language_data::string_lower_bound member variable to a virtual
method language_defn::string_lower_bound.

Over all of the languages we currently support there are currently
only two values for the lower bound, 0 or 1.  I noticed that in all
cases, if a language has C style arrays then the lower bound is 0,
otherwise the lower bound is 1.  So the default for the virtual method
in language.h makes use of this, which means languages don't have to
worry about providing a string_lower_bound method at all.

Except for Modula2.  This language is defined to not have C style
arrays, but has a string_lower_bound index of 0, this behaviour is
maintained after this commit by having Modula2 be the only language
that overrides the string_lower_bound method.

There should be no user visible changes after this commit.

gdb/ChangeLog:

* ada-lang.c (ada_language_data): Remove string_lower_bound
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.
* go-lang.c (go_language_data): Likewise.
* language.c (unknown_language_data): Likewise.
(auto_language_data): Likewise.
* language.h (language_data): Remove string_lower_bound field.
(language_defn::string_lower_bound): New member function.
* m2-lang.c (m2_language_data): Remove string_lower_bound
initializer.
(m2_language::string_lower_bound): New member function.
* objc-lang.c (objc_language_data): Remove string_lower_bound
initializer.
* opencl-lang.c (opencl_language_data): Likewise.
* p-lang.c (pascal_language_data): Likewise.
* rust-lang.c (rust_language_data): Likewise.
* valops.c (value_cstring): Update call to string_lower_bound.
(value_string): Likewise.
* value.c (allocate_repeated_value): Likewise.

15 files changed:
gdb/ChangeLog
gdb/ada-lang.c
gdb/c-lang.c
gdb/d-lang.c
gdb/f-lang.c
gdb/go-lang.c
gdb/language.c
gdb/language.h
gdb/m2-lang.c
gdb/objc-lang.c
gdb/opencl-lang.c
gdb/p-lang.c
gdb/rust-lang.c
gdb/valops.c
gdb/value.c

index 741e9bffd033b58a5551fdeaddfd7fb6159fc693..a337c605fc0e3c0ef815e3da9bf5965b0d82d62e 100644 (file)
@@ -1,3 +1,30 @@
+2020-09-16  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+       * ada-lang.c (ada_language_data): Remove string_lower_bound
+       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.
+       * go-lang.c (go_language_data): Likewise.
+       * language.c (unknown_language_data): Likewise.
+       (auto_language_data): Likewise.
+       * language.h (language_data): Remove string_lower_bound field.
+       (language_defn::string_lower_bound): New member function.
+       * m2-lang.c (m2_language_data): Remove string_lower_bound
+       initializer.
+       (m2_language::string_lower_bound): New member function.
+       * objc-lang.c (objc_language_data): Remove string_lower_bound
+       initializer.
+       * opencl-lang.c (opencl_language_data): Likewise.
+       * p-lang.c (pascal_language_data): Likewise.
+       * rust-lang.c (rust_language_data): Likewise.
+       * valops.c (value_cstring): Update call to string_lower_bound.
+       (value_string): Likewise.
+       * value.c (allocate_repeated_value): Likewise.
+
 2020-09-16  Andrew Burgess  <andrew.burgess@embecosm.com>
 
        * valops.c (value_repeat): Fix incorrect argument name in comment.
index 859dcec84ba792e8b724ffc5ddc466700b7c50ae..b90e7a05bcdf295c45a2e148db1fd0c6fe02c526 100644 (file)
@@ -13716,7 +13716,6 @@ extern const struct language_data ada_language_data =
   &ada_exp_descriptor,
   true,                         /* la_store_sym_names_in_linkage_form_p */
   ada_op_print_tab,             /* expression operators for printing */
-  1,                            /* String lower bound */
   &ada_varobj_ops,
 };
 
index 41eac2d43a3c83bdd77aa79346ef1931e13c6bc4..ecb339c3f87665b592b2a8b5fc16b4518e145f17 100644 (file)
@@ -882,7 +882,6 @@ extern const struct language_data c_language_data =
   &exp_descriptor_c,
   true,                                /* la_store_sym_names_in_linkage_form_p */
   c_op_print_tab,              /* expression operators for printing */
-  0,                           /* String lower bound */
   &c_varobj_ops,
 };
 
@@ -989,7 +988,6 @@ extern const struct language_data cplus_language_data =
   &exp_descriptor_c,
   false,                       /* la_store_sym_names_in_linkage_form_p */
   c_op_print_tab,              /* expression operators for printing */
-  0,                           /* String lower bound */
   &cplus_varobj_ops,
 };
 
@@ -1199,7 +1197,6 @@ extern const struct language_data asm_language_data =
   &exp_descriptor_c,
   true,                                /* la_store_sym_names_in_linkage_form_p */
   c_op_print_tab,              /* expression operators for printing */
-  0,                           /* String lower bound */
   &default_varobj_ops,
 };
 
@@ -1267,7 +1264,6 @@ extern const struct language_data minimal_language_data =
   &exp_descriptor_c,
   true,                                /* la_store_sym_names_in_linkage_form_p */
   c_op_print_tab,              /* expression operators for printing */
-  0,                           /* String lower bound */
   &default_varobj_ops,
 };
 
index 679120899891ecf51ae5621270dc0c8e3278b6e9..f75a973fbfb1007d15bff5052b03c391f56fe732 100644 (file)
@@ -135,7 +135,6 @@ extern const struct language_data d_language_data =
   &exp_descriptor_c,
   false,                       /* la_store_sym_names_in_linkage_form_p */
   d_op_print_tab,              /* Expression operators for printing.  */
-  0,                           /* String lower bound.  */
   &default_varobj_ops,
 };
 
index 649716ba1060ceb728ae1a9eff7c13f4a2931b16..344bdb8f0c8beb745a92bf34008baad3880a5906 100644 (file)
@@ -493,7 +493,6 @@ extern const struct language_data f_language_data =
   &exp_descriptor_f,
   false,                       /* la_store_sym_names_in_linkage_form_p */
   f_op_print_tab,              /* expression operators for printing */
-  1,                           /* String lower bound */
   &default_varobj_ops,
 };
 
index c2724e3d7cc06e5c8867283d302b0b324b552efd..c0ad0be13628fa830f5b4277f4b37d786fc5df0a 100644 (file)
@@ -515,7 +515,6 @@ extern const struct language_data go_language_data =
   &exp_descriptor_c,
   false,                       /* la_store_sym_names_in_linkage_form_p */
   go_op_print_tab,             /* Expression operators for printing.  */
-  0,                           /* String lower bound.  */
   &default_varobj_ops,
 };
 
index 9a496ae8548bec0af71188c3dce12f83494d6187..1866a964599c61f0dfd9600ec41c48959fe9d8bc 100644 (file)
@@ -782,7 +782,6 @@ extern const struct language_data unknown_language_data =
   &exp_descriptor_standard,
   true,                                /* store_sym_names_in_linkage_form_p */
   unk_op_print_tab,            /* expression operators for printing */
-  0,                           /* String lower bound */
   &default_varobj_ops,
 };
 
@@ -916,7 +915,6 @@ extern const struct language_data auto_language_data =
   &exp_descriptor_standard,
   false,                       /* store_sym_names_in_linkage_form_p */
   unk_op_print_tab,            /* expression operators for printing */
-  0,                           /* String lower bound */
   &default_varobj_ops,
 };
 
index 83014e47789d1586de855c454e0b12fdb26441e2..d83ea132a91d2e37c5a3c02e3d873033261b88b5 100644 (file)
@@ -232,9 +232,6 @@ struct language_data
 
     const struct op_print *la_op_print_tab;
 
-    /* Index to use for extracting the first element of a string.  */
-    char string_lower_bound;
-
     /* Various operations on varobj.  */
     const struct lang_varobj_ops *la_varobj_ops;
   };
@@ -568,6 +565,14 @@ struct language_defn : language_data
   virtual bool c_style_arrays_p () const
   { return true; }
 
+  /* Return the index to use for extracting the first element of a string,
+     or as the lower bound when creating a new string.  The default of
+     choosing 0 or 1 based on C_STYLE_ARRAYS_P works for all currently
+     supported languages except Modula-2.  */
+
+  virtual char string_lower_bound () const
+  { return c_style_arrays_p () ? 0 : 1; }
+
 protected:
 
   /* This is the overridable part of the GET_SYMBOL_NAME_MATCHER method.
index 9dd557777c0a2473e755cfa3f20f0dcd16060519..7bd9e710377acc43b94be52169f5c613595f1ebc 100644 (file)
@@ -206,7 +206,6 @@ extern const struct language_data m2_language_data =
   &exp_descriptor_modula2,
   false,                       /* la_store_sym_names_in_linkage_form_p */
   m2_op_print_tab,             /* expression operators for printing */
-  0,                           /* String lower bound */
   &default_varobj_ops,
 };
 
@@ -440,6 +439,12 @@ public:
 
   bool c_style_arrays_p () const override
   { return false; }
+
+  /* See language.h.  Despite not having C-style arrays, Modula-2 uses 0
+     for its string lower bounds.  */
+
+  char string_lower_bound () const override
+  { return 0; }
 };
 
 /* Single instance of the M2 language.  */
index 66b7b50144b3b934ed539f9479e70ac1bc5c6bd9..337b7a49f3c5c57380f03a0975eaffbaead01e17 100644 (file)
@@ -330,7 +330,6 @@ extern const struct language_data objc_language_data =
   &exp_descriptor_standard,
   false,                       /* la_store_sym_names_in_linkage_form_p */
   objc_op_print_tab,           /* Expression operators for printing */
-  0,                           /* String lower bound */
   &default_varobj_ops,
 };
 
index 1ac3aa42a8ebd05da6c3058dbe36b935b976bee0..2e3e54a2233fdd384487a45ffb67203af65eed81 100644 (file)
@@ -1013,7 +1013,6 @@ extern const struct language_data opencl_language_data =
   &exp_descriptor_opencl,
   false,                       /* la_store_sym_names_in_linkage_form_p */
   c_op_print_tab,              /* expression operators for printing */
-  0,                           /* String lower bound */
   &default_varobj_ops,
 };
 
index 66ba51ac8eb420092bd37705c0b29e691fb83f31..b07557151dbbcb3c020436e392574d773df09d43 100644 (file)
@@ -259,7 +259,6 @@ extern const struct language_data pascal_language_data =
   &exp_descriptor_standard,
   false,                       /* la_store_sym_names_in_linkage_form_p */
   pascal_op_print_tab,         /* expression operators for printing */
-  0,                           /* String lower bound */
   &default_varobj_ops,
 };
 
index de971e6255a1c48d1de41395ddb7008d67ee51a1..12fc138785d3379872e9eb46d0edef6e84b708ec 100644 (file)
@@ -1908,7 +1908,6 @@ extern const struct language_data rust_language_data =
   &exp_descriptor_rust,
   false,                       /* la_store_sym_names_in_linkage_form_p */
   c_op_print_tab,              /* expression operators for printing */
-  0,                           /* String lower bound */
   &default_varobj_ops,
 };
 
index cf4cbaba02b7ca9b7d65f821fee72e6fabc0f921..0995a76c02f818b67e80e39a90e91146416aca3f 100644 (file)
@@ -1644,7 +1644,7 @@ struct value *
 value_cstring (const char *ptr, ssize_t len, struct type *char_type)
 {
   struct value *val;
-  int lowbound = current_language->string_lower_bound;
+  int lowbound = current_language->string_lower_bound ();
   ssize_t highbound = len / TYPE_LENGTH (char_type);
   struct type *stringtype
     = lookup_array_range_type (char_type, lowbound, highbound + lowbound - 1);
@@ -1667,7 +1667,7 @@ struct value *
 value_string (const char *ptr, ssize_t len, struct type *char_type)
 {
   struct value *val;
-  int lowbound = current_language->string_lower_bound;
+  int lowbound = current_language->string_lower_bound ();
   ssize_t highbound = len / TYPE_LENGTH (char_type);
   struct type *stringtype
     = lookup_string_range_type (char_type, lowbound, highbound + lowbound - 1);
index c72b2fd6cead66dcc53bd936d8b945a6ce2d2cb5..c8d94149bb8cece2cde7c2c2d9c39ad384ce4ecc 100644 (file)
@@ -1041,7 +1041,10 @@ allocate_value (struct type *type)
 struct value *
 allocate_repeat_value (struct type *type, int count)
 {
-  int low_bound = current_language->string_lower_bound;                /* ??? */
+  /* Despite the fact that we are really creating an array of TYPE here, we
+     use the string lower bound as the array lower bound.  This seems to
+     work fine for now.  */
+  int low_bound = current_language->string_lower_bound ();
   /* FIXME-type-allocation: need a way to free this type when we are
      done with it.  */
   struct type *array_type