mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2025-01-30 12:44:10 +08:00
gdb: Convert language_data::string_lower_bound to a method
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.
This commit is contained in:
parent
1c236ddd45
commit
22c12a6c70
@ -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.
|
||||
|
@ -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,
|
||||
};
|
||||
|
||||
|
@ -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,
|
||||
};
|
||||
|
||||
|
@ -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,
|
||||
};
|
||||
|
||||
|
@ -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,
|
||||
};
|
||||
|
||||
|
@ -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,
|
||||
};
|
||||
|
||||
|
@ -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,
|
||||
};
|
||||
|
||||
|
@ -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.
|
||||
|
@ -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 @@ class m2_language : public language_defn
|
||||
|
||||
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. */
|
||||
|
@ -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,
|
||||
};
|
||||
|
||||
|
@ -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,
|
||||
};
|
||||
|
||||
|
@ -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,
|
||||
};
|
||||
|
||||
|
@ -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,
|
||||
};
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user