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

New option --constants-prefix.

This commit is contained in:
Bruno Haible
2011-01-16 16:43:45 +01:00
parent 61edba6dde
commit 5ac5f15a74
8 changed files with 189 additions and 26 deletions

View File

@@ -1,5 +1,5 @@
/* Input routines.
Copyright (C) 1989-1998, 2002-2004 Free Software Foundation, Inc.
Copyright (C) 1989-1998, 2002-2004, 2011 Free Software Foundation, Inc.
Written by Douglas C. Schmidt <schmidt@ics.uci.edu>
and Bruno Haible <bruno@clisp.org>.
@@ -545,6 +545,11 @@ Input::read_input ()
option.set (NULLSTRINGS);
else
if (is_define_declaration (line, line_end, lineno,
"constants-prefix", &arg))
option.set_constants_prefix (arg);
else
if (is_define_declaration (line, line_end, lineno,
"word-array-name", &arg))
option.set_wordlist_name (arg);

View File

@@ -1,5 +1,5 @@
/* Handles parsing the Options provided to the user.
Copyright (C) 1989-1998, 2000, 2002-2004, 2006-2009 Free Software Foundation, Inc.
Copyright (C) 1989-1998, 2000, 2002-2004, 2006-2009, 2011 Free Software Foundation, Inc.
Written by Douglas C. Schmidt <schmidt@ics.uci.edu>
and Bruno Haible <bruno@clisp.org>.
@@ -62,6 +62,9 @@ static const char *const DEFAULT_LENGTHTABLE_NAME = "lengthtable";
/* Default name for string pool. */
static const char *const DEFAULT_STRINGPOOL_NAME = "stringpool";
/* Default prefix for constants. */
static const char *const DEFAULT_CONSTANTS_PREFIX = "";
/* Default delimiters that separate keywords from their attributes. */
static const char *const DEFAULT_DELIMITERS = ",";
@@ -176,6 +179,9 @@ Options::long_usage (FILE * stream)
fprintf (stream,
" --null-strings Use NULL strings instead of empty strings for empty\n"
" keyword table entries.\n");
fprintf (stream,
" --constants-prefix=PREFIX\n"
" Specify prefix for the constants like TOTAL_KEYWORDS.\n");
fprintf (stream,
" -W, --word-array-name=NAME\n"
" Specify name of word list array. Default name is\n"
@@ -465,6 +471,7 @@ Options::Options ()
_wordlist_name (DEFAULT_WORDLIST_NAME),
_lengthtable_name (DEFAULT_LENGTHTABLE_NAME),
_stringpool_name (DEFAULT_STRINGPOOL_NAME),
_constants_prefix (DEFAULT_CONSTANTS_PREFIX),
_delimiters (DEFAULT_DELIMITERS),
_key_positions ()
{
@@ -649,6 +656,14 @@ Options::set_lengthtable_name (const char *name)
_lengthtable_name = name;
}
/* Sets the prefix for the constants, if not already set. */
void
Options::set_constants_prefix (const char *prefix)
{
if (_constants_prefix == DEFAULT_CONSTANTS_PREFIX)
_constants_prefix = prefix;
}
/* Sets the string pool name, if not already set. */
void
Options::set_stringpool_name (const char *name)
@@ -688,6 +703,7 @@ static const struct option long_options[] =
{ "enum", no_argument, NULL, 'E' },
{ "includes", no_argument, NULL, 'I' },
{ "global-table", no_argument, NULL, 'G' },
{ "constants-prefix", required_argument, NULL, CHAR_MAX + 5 },
{ "word-array-name", required_argument, NULL, 'W' },
{ "length-table-name", required_argument, NULL, CHAR_MAX + 4 },
{ "switch", required_argument, NULL, 'S' },
@@ -1044,6 +1060,11 @@ There is NO WARRANTY, to the extent permitted by law.\n\
_lengthtable_name = /*getopt*/optarg;
break;
}
case CHAR_MAX + 5: /* Sets the prefix for the constants. */
{
_constants_prefix = /*getopt*/optarg;
break;
}
default:
short_usage (stderr);
exit (1);

View File

@@ -2,7 +2,7 @@
/* Handles parsing the Options provided to the user.
Copyright (C) 1989-1998, 2000, 2002-2004 Free Software Foundation, Inc.
Copyright (C) 1989-1998, 2000, 2002-2004, 2011 Free Software Foundation, Inc.
Written by Douglas C. Schmidt <schmidt@ics.uci.edu>
and Bruno Haible <bruno@clisp.org>.
@@ -202,6 +202,11 @@ public:
/* Sets the string pool name, if not already set. */
void set_stringpool_name (const char *name);
/* Returns the prefix for the constants. */
const char * get_constants_prefix () const;
/* Sets the prefix for the constants, if not already set. */
void set_constants_prefix (const char *prefix);
/* Returns the string used to delimit keywords from other attributes. */
const char * get_delimiters () const;
/* Sets the delimiters string, if not already set. */
@@ -274,6 +279,9 @@ private:
/* Name used for the string pool. */
const char * _stringpool_name;
/* Prefix for the constants. */
const char * _constants_prefix;
/* Separates keywords from other attributes. */
const char * _delimiters;

View File

@@ -1,6 +1,6 @@
/* Inline Functions for options.{h,cc}.
Copyright (C) 1989-1998, 2000, 2002-2004 Free Software Foundation, Inc.
Copyright (C) 1989-1998, 2000, 2002-2004, 2011 Free Software Foundation, Inc.
Written by Douglas C. Schmidt <schmidt@ics.uci.edu>
and Bruno Haible <bruno@clisp.org>.
@@ -140,6 +140,13 @@ Options::get_stringpool_name () const
return _stringpool_name;
}
/* Returns the prefix for the constants. */
INLINE const char *
Options::get_constants_prefix () const
{
return _constants_prefix;
}
/* Returns the string used to delimit keywords from other attributes. */
INLINE const char *
Options::get_delimiters () const

View File

@@ -1,5 +1,5 @@
/* Output routines.
Copyright (C) 1989-1998, 2000, 2002-2004, 2006-2007, 2009 Free Software Foundation, Inc.
Copyright (C) 1989-1998, 2000, 2002-2004, 2006-2007, 2009, 2011 Free Software Foundation, Inc.
Written by Douglas C. Schmidt <schmidt@ics.uci.edu>
and Bruno Haible <bruno@clisp.org>.
@@ -214,17 +214,29 @@ void Output_Enum::output_end ()
printf ("%s };\n\n", _indentation);
}
/* Outputs a constant in the given style. */
static void
output_constant (struct Output_Constants& style, const char *name, int value)
{
const char *prefix = option.get_constants_prefix ();
char combined_name[strlen (prefix) + strlen (name) + 1];
strcpy (combined_name, prefix);
strcpy (combined_name + strlen (prefix), name);
style.output_item (combined_name, value);
}
/* Outputs the maximum and minimum hash values etc. */
void
Output::output_constants (struct Output_Constants& style) const
{
style.output_start ();
style.output_item ("TOTAL_KEYWORDS", _total_keys);
style.output_item ("MIN_WORD_LENGTH", _min_key_len);
style.output_item ("MAX_WORD_LENGTH", _max_key_len);
style.output_item ("MIN_HASH_VALUE", _min_hash_value);
style.output_item ("MAX_HASH_VALUE", _max_hash_value);
output_constant (style, "TOTAL_KEYWORDS", _total_keys);
output_constant (style, "MIN_WORD_LENGTH", _min_key_len);
output_constant (style, "MAX_WORD_LENGTH", _max_key_len);
output_constant (style, "MIN_HASH_VALUE", _min_hash_value);
output_constant (style, "MAX_HASH_VALUE", _max_hash_value);
style.output_end ();
}
@@ -1575,9 +1587,10 @@ output_switches (KeywordExt_List *list, int num_switches, int size, int min_hash
void
Output::output_lookup_function_body (const Output_Compare& comparison) const
{
printf (" if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)\n"
printf (" if (len <= %sMAX_WORD_LENGTH && len >= %sMIN_WORD_LENGTH)\n"
" {\n"
" register int key = %s (str, len);\n\n",
option.get_constants_prefix (), option.get_constants_prefix (),
option.get_hash_name ());
if (option[SWITCH])
@@ -1587,8 +1600,9 @@ Output::output_lookup_function_body (const Output_Compare& comparison) const
if (num_switches > switch_size)
num_switches = switch_size;
printf (" if (key <= MAX_HASH_VALUE && key >= MIN_HASH_VALUE)\n"
" {\n");
printf (" if (key <= %sMAX_HASH_VALUE && key >= %sMIN_HASH_VALUE)\n"
" {\n",
option.get_constants_prefix (), option.get_constants_prefix ());
if (option[DUP] && _total_duplicates > 0)
{
if (option[LENTABLE])
@@ -1686,7 +1700,8 @@ Output::output_lookup_function_body (const Output_Compare& comparison) const
}
else
{
printf (" if (key <= MAX_HASH_VALUE && key >= 0)\n");
printf (" if (key <= %sMAX_HASH_VALUE && key >= 0)\n",
option.get_constants_prefix ());
if (option[DUP])
{
@@ -1732,19 +1747,20 @@ Output::output_lookup_function_body (const Output_Compare& comparison) const
}
if (_total_duplicates > 0)
{
printf ("%*s else if (index < -TOTAL_KEYWORDS)\n"
printf ("%*s else if (index < -%sTOTAL_KEYWORDS)\n"
"%*s {\n"
"%*s register int offset = - 1 - TOTAL_KEYWORDS - index;\n",
indent, "", indent, "", indent, "");
"%*s register int offset = - 1 - %sTOTAL_KEYWORDS - index;\n",
indent, "", option.get_constants_prefix (), indent, "",
indent, "", option.get_constants_prefix ());
if (option[LENTABLE])
printf ("%*s register %s%s *lengthptr = &%s[TOTAL_KEYWORDS + lookup[offset]];\n",
printf ("%*s register %s%s *lengthptr = &%s[%sTOTAL_KEYWORDS + lookup[offset]];\n",
indent, "", const_always, smallest_integral_type (_max_key_len),
option.get_lengthtable_name ());
option.get_lengthtable_name (), option.get_constants_prefix ());
printf ("%*s register ",
indent, "");
output_const_type (const_readonly_array, _wordlist_eltype);
printf ("*wordptr = &%s[TOTAL_KEYWORDS + lookup[offset]];\n",
option.get_wordlist_name ());
printf ("*wordptr = &%s[%sTOTAL_KEYWORDS + lookup[offset]];\n",
option.get_wordlist_name (), option.get_constants_prefix ());
printf ("%*s register ",
indent, "");
output_const_type (const_readonly_array, _wordlist_eltype);