From: Andrew Burgess <andrew.burgess@embecosm.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 7/7] gdb: Convert language la_is_string_type_p field to a method
Date: Thu, 18 Jun 2020 23:31:54 +0100 [thread overview]
Message-ID: <9f662c89d08c6f9f83ac5185bf5e3bc26feb3b80.1592519094.git.andrew.burgess@embecosm.com> (raw)
In-Reply-To: <cover.1592519094.git.andrew.burgess@embecosm.com>
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
next prev parent reply other threads:[~2020-06-18 22:32 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Andrew Burgess [this message]
2020-06-19 14:25 ` [PATCH 0/7] Language Class Hierarchy Conversion (Prt 3) Tom Tromey
2020-06-19 16:18 ` Andrew Burgess
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=9f662c89d08c6f9f83ac5185bf5e3bc26feb3b80.1592519094.git.andrew.burgess@embecosm.com \
--to=andrew.burgess@embecosm.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).