1
0
mirror of https://git.savannah.gnu.org/git/gperf.git synced 2025-12-02 13:09:22 +00:00

Don't use 'register' storage-class specifier in C++ output code.

This commit is contained in:
Bruno Haible
2016-11-26 02:03:38 +01:00
parent 658e826478
commit baf89d87f0
2 changed files with 104 additions and 71 deletions

View File

@@ -1,3 +1,14 @@
2016-11-26 Bruno Haible <bruno@clisp.org>
Don't use 'register' storage-class specifier in C++ output code.
* src/output.cc (register_scs): New variable.
(Output::Output): Initialize it.
(output_upperlower_strcmp, output_upperlower_strncmp,
output_upperlower_memcmp, Output::output_hash_function,
Output::output_lookup_function_body, Output::output_lookup_function):
Use it.
Reported at <https://savannah.gnu.org/bugs/?44887>.
2016-11-26 Bruno Haible <bruno@clisp.org> 2016-11-26 Bruno Haible <bruno@clisp.org>
Avoid 'warning: use of old-style cast' in output code. Avoid 'warning: use of old-style cast' in output code.

View File

@@ -52,6 +52,9 @@
/* ========================================================================= */ /* ========================================================================= */
/* The "register " storage-class specifier. */
static const char *register_scs;
/* The "const " qualifier. */ /* The "const " qualifier. */
static const char *const_always; static const char *const_always;
@@ -313,15 +316,16 @@ output_upperlower_strcmp ()
"gperf_case_strcmp "); "gperf_case_strcmp ");
printf (option[KRC] ? printf (option[KRC] ?
"(s1, s2)\n" "(s1, s2)\n"
" register char *s1;\n" " %schar *s1;\n"
" register char *s2;\n" : " %schar *s2;\n" :
option[C] ? option[C] ?
"(s1, s2)\n" "(s1, s2)\n"
" register const char *s1;\n" " %sconst char *s1;\n"
" register const char *s2;\n" : " %sconst char *s2;\n" :
option[ANSIC] | option[CPLUSPLUS] ? option[ANSIC] | option[CPLUSPLUS] ?
"(register const char *s1, register const char *s2)\n" : "(%sconst char *s1, %sconst char *s2)\n" :
""); "",
register_scs, register_scs);
#if USE_DOWNCASE_TABLE #if USE_DOWNCASE_TABLE
printf ("{\n" printf ("{\n"
" for (;;)\n" " for (;;)\n"
@@ -363,17 +367,18 @@ output_upperlower_strncmp ()
"gperf_case_strncmp "); "gperf_case_strncmp ");
printf (option[KRC] ? printf (option[KRC] ?
"(s1, s2, n)\n" "(s1, s2, n)\n"
" register char *s1;\n" " %schar *s1;\n"
" register char *s2;\n" " %schar *s2;\n"
" register unsigned int n;\n" : " %sunsigned int n;\n" :
option[C] ? option[C] ?
"(s1, s2, n)\n" "(s1, s2, n)\n"
" register const char *s1;\n" " %sconst char *s1;\n"
" register const char *s2;\n" " %sconst char *s2;\n"
" register unsigned int n;\n" : " %sunsigned int n;\n" :
option[ANSIC] | option[CPLUSPLUS] ? option[ANSIC] | option[CPLUSPLUS] ?
"(register const char *s1, register const char *s2, register unsigned int n)\n" : "(%sconst char *s1, %sconst char *s2, %sunsigned int n)\n" :
""); "",
register_scs, register_scs, register_scs);
#if USE_DOWNCASE_TABLE #if USE_DOWNCASE_TABLE
printf ("{\n" printf ("{\n"
" for (; n > 0;)\n" " for (; n > 0;)\n"
@@ -423,17 +428,18 @@ output_upperlower_memcmp ()
"gperf_case_memcmp "); "gperf_case_memcmp ");
printf (option[KRC] ? printf (option[KRC] ?
"(s1, s2, n)\n" "(s1, s2, n)\n"
" register char *s1;\n" " %schar *s1;\n"
" register char *s2;\n" " %schar *s2;\n"
" register unsigned int n;\n" : " %sunsigned int n;\n" :
option[C] ? option[C] ?
"(s1, s2, n)\n" "(s1, s2, n)\n"
" register const char *s1;\n" " %sconst char *s1;\n"
" register const char *s2;\n" " %sconst char *s2;\n"
" register unsigned int n;\n" : " %sunsigned int n;\n" :
option[ANSIC] | option[CPLUSPLUS] ? option[ANSIC] | option[CPLUSPLUS] ?
"(register const char *s1, register const char *s2, register unsigned int n)\n" : "(%sconst char *s1, %sconst char *s2, %sunsigned int n)\n" :
""); "",
register_scs, register_scs, register_scs);
#if USE_DOWNCASE_TABLE #if USE_DOWNCASE_TABLE
printf ("{\n" printf ("{\n"
" for (; n > 0;)\n" " for (; n > 0;)\n"
@@ -825,15 +831,16 @@ Output::output_hash_function () const
printf ("%s ", option.get_hash_name ()); printf ("%s ", option.get_hash_name ());
printf (option[KRC] ? printf (option[KRC] ?
"(str, len)\n" "(str, len)\n"
" register char *str;\n" " %schar *str;\n"
" register unsigned int len;\n" : " %sunsigned int len;\n" :
option[C] ? option[C] ?
"(str, len)\n" "(str, len)\n"
" register const char *str;\n" " %sconst char *str;\n"
" register unsigned int len;\n" : " %sunsigned int len;\n" :
option[ANSIC] | option[CPLUSPLUS] ? option[ANSIC] | option[CPLUSPLUS] ?
"(register const char *str, register unsigned int len)\n" : "(%sconst char *str, %sunsigned int len)\n" :
""); "",
register_scs, register_scs);
/* Note that when the hash function is called, it has already been verified /* Note that when the hash function is called, it has already been verified
that min_key_len <= len <= max_key_len. */ that min_key_len <= len <= max_key_len. */
@@ -927,11 +934,11 @@ Output::output_hash_function () const
/* We've got to use the correct, but brute force, technique. */ /* We've got to use the correct, but brute force, technique. */
/* It doesn't really matter whether hval is an 'int' or /* It doesn't really matter whether hval is an 'int' or
'unsigned int', but 'unsigned int' gives fewer warnings. */ 'unsigned int', but 'unsigned int' gives fewer warnings. */
printf (" register unsigned int hval = %s;\n\n" printf (" %sunsigned int hval = %s;\n\n"
" switch (%s)\n" " switch (%s)\n"
" {\n" " {\n"
" default:\n", " default:\n",
_hash_includes_len ? "len" : "0", register_scs, _hash_includes_len ? "len" : "0",
_hash_includes_len ? "hval" : "len"); _hash_includes_len ? "hval" : "len");
while (key_pos != Positions::LASTCHAR && key_pos >= _max_key_len) while (key_pos != Positions::LASTCHAR && key_pos >= _max_key_len)
@@ -1634,9 +1641,9 @@ Output::output_lookup_function_body (const Output_Compare& comparison) const
{ {
printf (" if (len <= %sMAX_WORD_LENGTH && len >= %sMIN_WORD_LENGTH)\n" printf (" if (len <= %sMAX_WORD_LENGTH && len >= %sMIN_WORD_LENGTH)\n"
" {\n" " {\n"
" register unsigned int key = %s (str, len);\n\n", " %sunsigned int key = %s (str, len);\n\n",
option.get_constants_prefix (), option.get_constants_prefix (), option.get_constants_prefix (), option.get_constants_prefix (),
option.get_hash_name ()); register_scs, option.get_hash_name ());
if (option[SWITCH]) if (option[SWITCH])
{ {
@@ -1655,24 +1662,28 @@ Output::output_lookup_function_body (const Output_Compare& comparison) const
if (option[DUP] && _total_duplicates > 0) if (option[DUP] && _total_duplicates > 0)
{ {
if (option[LENTABLE]) if (option[LENTABLE])
printf (" register %s%s *lengthptr;\n", printf (" %s%s%s *lengthptr;\n",
const_always, smallest_integral_type (_max_key_len)); register_scs, const_always,
printf (" register "); smallest_integral_type (_max_key_len));
printf (" %s",
register_scs);
output_const_type (const_readonly_array, _wordlist_eltype); output_const_type (const_readonly_array, _wordlist_eltype);
printf ("*wordptr;\n"); printf ("*wordptr;\n");
printf (" register "); printf (" %s",
register_scs);
output_const_type (const_readonly_array, _wordlist_eltype); output_const_type (const_readonly_array, _wordlist_eltype);
printf ("*wordendptr;\n"); printf ("*wordendptr;\n");
} }
if (option[TYPE]) if (option[TYPE])
{ {
printf (" register "); printf (" %s",
register_scs);
output_const_type (const_readonly_array, _struct_tag); output_const_type (const_readonly_array, _struct_tag);
printf ("*resword;\n\n"); printf ("*resword;\n\n");
} }
else else
printf (" register %sresword;\n\n", printf (" %s%sresword;\n\n",
_struct_tag); register_scs, _struct_tag);
output_switches (_head, num_switches, switch_size, _min_hash_value, _max_hash_value, 10); output_switches (_head, num_switches, switch_size, _min_hash_value, _max_hash_value, 10);
@@ -1691,8 +1702,8 @@ Output::output_lookup_function_body (const Output_Compare& comparison) const
indent, "", indent, ""); indent, "", indent, "");
indent += 4; indent += 4;
} }
printf ("%*s register %schar *s = ", printf ("%*s %s%schar *s = ",
indent, "", const_always); indent, "", register_scs, const_always);
if (option[TYPE]) if (option[TYPE])
printf ("wordptr->%s", option.get_slot_name ()); printf ("wordptr->%s", option.get_slot_name ());
else else
@@ -1726,8 +1737,8 @@ Output::output_lookup_function_body (const Output_Compare& comparison) const
if (option[TYPE]) if (option[TYPE])
{ {
printf (" {\n" printf (" {\n"
" register %schar *s = resword->%s", " %s%schar *s = resword->%s",
const_always, option.get_slot_name ()); register_scs, const_always, option.get_slot_name ());
if (option[SHAREDLIB]) if (option[SHAREDLIB])
printf (" + %s", printf (" + %s",
option.get_stringpool_name ()); option.get_stringpool_name ());
@@ -1756,9 +1767,9 @@ Output::output_lookup_function_body (const Output_Compare& comparison) const
{ {
int indent = 8; int indent = 8;
printf ("%*s{\n" printf ("%*s{\n"
"%*s register int index = lookup[key];\n\n" "%*s %sint index = lookup[key];\n\n"
"%*s if (index >= 0)\n", "%*s if (index >= 0)\n",
indent, "", indent, "", indent, ""); indent, "", indent, "", register_scs, indent, "");
if (option[LENTABLE]) if (option[LENTABLE])
{ {
printf ("%*s {\n" printf ("%*s {\n"
@@ -1767,9 +1778,10 @@ Output::output_lookup_function_body (const Output_Compare& comparison) const
indent += 4; indent += 4;
} }
printf ("%*s {\n" printf ("%*s {\n"
"%*s register %schar *s = %s[index]", "%*s %s%schar *s = %s[index]",
indent, "", indent, "",
indent, "", const_always, option.get_wordlist_name ()); indent, "", register_scs, const_always,
option.get_wordlist_name ());
if (option[TYPE]) if (option[TYPE])
printf (".%s", option.get_slot_name ()); printf (".%s", option.get_slot_name ());
if (option[SHAREDLIB]) if (option[SHAREDLIB])
@@ -1798,20 +1810,20 @@ Output::output_lookup_function_body (const Output_Compare& comparison) const
{ {
printf ("%*s else if (index < -%sTOTAL_KEYWORDS)\n" printf ("%*s else if (index < -%sTOTAL_KEYWORDS)\n"
"%*s {\n" "%*s {\n"
"%*s register int offset = - 1 - %sTOTAL_KEYWORDS - index;\n", "%*s %sint offset = - 1 - %sTOTAL_KEYWORDS - index;\n",
indent, "", option.get_constants_prefix (), indent, "", indent, "", option.get_constants_prefix (), indent, "",
indent, "", option.get_constants_prefix ()); indent, "", register_scs, option.get_constants_prefix ());
if (option[LENTABLE]) if (option[LENTABLE])
printf ("%*s register %s%s *lengthptr = &%s[%sTOTAL_KEYWORDS + lookup[offset]];\n", printf ("%*s %s%s%s *lengthptr = &%s[%sTOTAL_KEYWORDS + lookup[offset]];\n",
indent, "", const_always, smallest_integral_type (_max_key_len), indent, "", register_scs, const_always, smallest_integral_type (_max_key_len),
option.get_lengthtable_name (), option.get_constants_prefix ()); option.get_lengthtable_name (), option.get_constants_prefix ());
printf ("%*s register ", printf ("%*s %s",
indent, ""); indent, "", register_scs);
output_const_type (const_readonly_array, _wordlist_eltype); output_const_type (const_readonly_array, _wordlist_eltype);
printf ("*wordptr = &%s[%sTOTAL_KEYWORDS + lookup[offset]];\n", printf ("*wordptr = &%s[%sTOTAL_KEYWORDS + lookup[offset]];\n",
option.get_wordlist_name (), option.get_constants_prefix ()); option.get_wordlist_name (), option.get_constants_prefix ());
printf ("%*s register ", printf ("%*s %s",
indent, ""); indent, "", register_scs);
output_const_type (const_readonly_array, _wordlist_eltype); output_const_type (const_readonly_array, _wordlist_eltype);
printf ("*wordendptr = wordptr + -lookup[offset + 1];\n\n"); printf ("*wordendptr = wordptr + -lookup[offset + 1];\n\n");
printf ("%*s while (wordptr < wordendptr)\n" printf ("%*s while (wordptr < wordendptr)\n"
@@ -1824,8 +1836,8 @@ Output::output_lookup_function_body (const Output_Compare& comparison) const
indent, "", indent, ""); indent, "", indent, "");
indent += 4; indent += 4;
} }
printf ("%*s register %schar *s = ", printf ("%*s %s%schar *s = ",
indent, "", const_always); indent, "", register_scs, const_always);
if (option[TYPE]) if (option[TYPE])
printf ("wordptr->%s", option.get_slot_name ()); printf ("wordptr->%s", option.get_slot_name ());
else else
@@ -1873,9 +1885,10 @@ Output::output_lookup_function_body (const Output_Compare& comparison) const
if (!option[LENTABLE]) if (!option[LENTABLE])
{ {
printf ("%*s{\n" printf ("%*s{\n"
"%*s register int o = %s[key]", "%*s %sint o = %s[key]",
indent, "", indent, "",
indent, "", option.get_wordlist_name ()); indent, "", register_scs,
option.get_wordlist_name ());
if (option[TYPE]) if (option[TYPE])
printf (".%s", option.get_slot_name ()); printf (".%s", option.get_slot_name ());
printf (";\n" printf (";\n"
@@ -1884,8 +1897,8 @@ Output::output_lookup_function_body (const Output_Compare& comparison) const
indent, "", indent, "",
indent, ""); indent, "");
indent += 4; indent += 4;
printf ("%*s register %schar *s = o", printf ("%*s %s%schar *s = o",
indent, "", const_always); indent, "", register_scs, const_always);
} }
else else
{ {
@@ -1893,9 +1906,9 @@ Output::output_lookup_function_body (const Output_Compare& comparison) const
(len == lengthtable[key]) test already guarantees that (len == lengthtable[key]) test already guarantees that
key points to nonempty table entry. */ key points to nonempty table entry. */
printf ("%*s{\n" printf ("%*s{\n"
"%*s register %schar *s = %s[key]", "%*s %s%schar *s = %s[key]",
indent, "", indent, "",
indent, "", const_always, indent, "", register_scs, const_always,
option.get_wordlist_name ()); option.get_wordlist_name ());
if (option[TYPE]) if (option[TYPE])
printf (".%s", option.get_slot_name ()); printf (".%s", option.get_slot_name ());
@@ -1906,9 +1919,10 @@ Output::output_lookup_function_body (const Output_Compare& comparison) const
else else
{ {
printf ("%*s{\n" printf ("%*s{\n"
"%*s register %schar *s = %s[key]", "%*s %s%schar *s = %s[key]",
indent, "", indent, "",
indent, "", const_always, option.get_wordlist_name ()); indent, "", register_scs, const_always,
option.get_wordlist_name ());
if (option[TYPE]) if (option[TYPE])
printf (".%s", option.get_slot_name ()); printf (".%s", option.get_slot_name ());
} }
@@ -1971,15 +1985,16 @@ Output::output_lookup_function () const
printf ("%s ", option.get_function_name ()); printf ("%s ", option.get_function_name ());
printf (option[KRC] ? printf (option[KRC] ?
"(str, len)\n" "(str, len)\n"
" register char *str;\n" " %schar *str;\n"
" register unsigned int len;\n" : " %sunsigned int len;\n" :
option[C] ? option[C] ?
"(str, len)\n" "(str, len)\n"
" register const char *str;\n" " %sconst char *str;\n"
" register unsigned int len;\n" : " %sunsigned int len;\n" :
option[ANSIC] | option[CPLUSPLUS] ? option[ANSIC] | option[CPLUSPLUS] ?
"(register const char *str, register unsigned int len)\n" : "(%sconst char *str, %sunsigned int len)\n" :
""); "",
register_scs, register_scs);
/* Output the function's body. */ /* Output the function's body. */
printf ("{\n"); printf ("{\n");
@@ -2018,6 +2033,13 @@ Output::output ()
{ {
compute_min_max (); compute_min_max ();
if (option[CPLUSPLUS])
/* The 'register' keyword is removed from C++17.
See http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4340 */
register_scs = "";
else
register_scs = "register ";
if (option[C] | option[ANSIC] | option[CPLUSPLUS]) if (option[C] | option[ANSIC] | option[CPLUSPLUS])
{ {
const_always = "const "; const_always = "const ";