gdb: Convert language la_is_string_type_p field to a method

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.
This commit is contained in:
Andrew Burgess 2020-06-18 22:01:33 +01:00
parent 4ffc13fb0e
commit 39e7eccae6
14 changed files with 156 additions and 97 deletions

View 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

View 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 @@ 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. */

View 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 */
};

View 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 */
};

View 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 @@ 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. */

View 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 @@ 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. */

View 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 @@ 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. */

View 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);

View 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 @@ 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. */

View 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 */
};

View 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 */
};

View 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 @@ 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. */

View 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 @@ 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. */

View 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. */