]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: Convert language la_is_string_type_p field to a method
authorAndrew Burgess <andrew.burgess@embecosm.com>
Thu, 18 Jun 2020 21:01:33 +0000 (22:01 +0100)
committerAndrew Burgess <andrew.burgess@embecosm.com>
Tue, 23 Jun 2020 12:34:11 +0000 (13:34 +0100)
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.

14 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/valprint.c

index de348bb4770a2a5c1cc90e04c6bf60a3c68b8bd4..af34af84e33f8cc079ee0a577c38abfe0341dfd1 100644 (file)
@@ -1,3 +1,57 @@
+2020-06-23  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+       * 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.
+
 2020-06-23  Andrew Burgess  <andrew.burgess@embecosm.com>
 
        * ada-lang.c (ada_language_data): Delete la_print_typedef
index 752bf44cef03249ea9b85656ee64c1794d38e93e..9b0c2efbfe21a9f347d380cf7e4ed48fe59c62d5 100644 (file)
@@ -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 @@ public:
     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.  */
 
index aca0d7a6bc9d18cb2b3bfccc17f35d2467fc269d..f29f2cef610458974ccc5f83342d6efaaf8ce624 100644 (file)
@@ -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 */
 };
 
index b907dd750e0098de231627b0c453086ed5d2c107..4ebb011ee9b0374251209123a646939a554bc209 100644 (file)
@@ -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 */
 };
 
index 946d5bc25afc523c55f22b91c8449e8d14794e3b..58b41d11d11a5b4d4a328af83a8c74bebe5a01f8 100644 (file)
@@ -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 @@ public:
     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.  */
index fa263997b12a24ec12c537683840140d36259303..cb42ef1b7cfe926d9d713a4d13283700e484668b 100644 (file)
@@ -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 @@ public:
   {
     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.  */
index 5ae8c46879c5c04a8279f8aebc5f5aeda4698546..c993cfc57a6e1d0e96e74be555ea5d8c41111670 100644 (file)
@@ -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 @@ public:
   {
     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 @@ public:
   {
     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.  */
index 19cd8205718b12f35a0de95d2bfde9c44cec0462..d2e5b733077d30c44ec915ad932c5097bb38a5ca 100644 (file)
@@ -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);
index f0f7c22fb5d698457a0416fe554041cecbb45c55..2c39359d2898e38e1c061cef142eb8c977c2f088 100644 (file)
@@ -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 @@ public:
     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.  */
index 0c952730a967f53cc4be88885ebc057a8ca17744..63cdac1b03568653e9a2c080e58717e579eb6f68 100644 (file)
@@ -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 */
 };
 
index 2431faed00e0964cc34d736bf36629137d5fce3c..eccf1df9621b76c04ec46bb9256154a216474e9f 100644 (file)
@@ -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 */
 };
 
index 9fd823185b15b72196979a30d93d117f0c0031e2..07afbdda5bb4866e4026c6632dc98b5f3691152d 100644 (file)
@@ -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 @@ public:
     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.  */
index 083b3f73277573e4a283ece2396dd1a93f644498..d1efea19e91823e7760e0ec25d04e99b1bedffab 100644 (file)
@@ -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 @@ public:
     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.  */
index 51c77c3e6d2cdf0a1eb92b8ee254f296fba08479..db98ca2abc986a84d6bc5ac3468a9f18fbdfe5d6 100644 (file)
@@ -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.  */