summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2003-04-08 10:55:59 +0000
committerBruno Haible <bruno@clisp.org>2003-04-08 10:55:59 +0000
commit3bdad49e79619a0de67bb9ea112829417f4eabcd (patch)
tree3939d9557bead444385d274592cf42c751126ee6
parent2535f34494011d57d9603d6e44604d357f83a4b0 (diff)
downloadgperf-3bdad49e79619a0de67bb9ea112829417f4eabcd.tar.gz
Small simplifications.
-rw-r--r--ChangeLog6
-rw-r--r--src/output.cc53
-rw-r--r--src/output.h3
3 files changed, 41 insertions, 21 deletions
diff --git a/ChangeLog b/ChangeLog
index ffed0de..c69b0b0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
2002-12-12 Bruno Haible <bruno@clisp.org>
+ * src/output.h (Output::output_asso_values_ref): New declaration.
+ * src/output.cc (char_to_index): Remove variable.
+ (Output::output_asso_values_ref): New function.
+ (Output::output_hash_function): Use it.
+ (Output::output): Update.
+
* src/positions.h (Positions::is_useall, Positions::set_useall,
Positions::iterator, Positions::reviterator): New method declarations.
(Positions::_useall): New field.
diff --git a/src/output.cc b/src/output.cc
index 94e5952..f1bd0d0 100644
--- a/src/output.cc
+++ b/src/output.cc
@@ -63,9 +63,6 @@ smallest_integral_type (int min, int max)
return "int";
}
-/* A cast from `char' to a valid array index. */
-static const char *char_to_index;
-
/* ------------------------------------------------------------------------- */
/* Constructor.
@@ -561,6 +558,26 @@ void Output_Compare_Memcmp::output_comparison (const Output_Expr& expr1,
/* ------------------------------------------------------------------------- */
+/* Generates a C expression for an asso_values[] reference. */
+
+void
+Output::output_asso_values_ref (int pos) const
+{
+ printf ("asso_values[");
+ /* Always cast to unsigned char. This is necessary when the alpha_inc
+ is nonzero, and also avoids a gcc warning "subscript has type 'char'". */
+ printf ("(unsigned char)");
+ if (pos == Positions::LASTCHAR)
+ printf ("str[len - 1]");
+ else
+ {
+ printf ("str[%d]", pos);
+ if (_alpha_inc[pos])
+ printf ("+%u", _alpha_inc[pos]);
+ }
+ printf ("]");
+}
+
/* Generates C code for the hash function that returns the
proper encoding for each keyword.
The hash function has the signature
@@ -665,20 +682,15 @@ Output::output_hash_function () const
&& _key_positions[1] == Positions::LASTCHAR)
/* Optimize special case of "-k 1,$". */
{
- printf ("asso_values[%sstr[len - 1]] + asso_values[%sstr[0]",
- char_to_index, char_to_index);
- if (_alpha_inc[0])
- printf ("+%u", _alpha_inc[0]);
- printf ("]");
+ output_asso_values_ref (Positions::LASTCHAR);
+ printf (" + ");
+ output_asso_values_ref (0);
}
else
{
for (; key_pos != Positions::LASTCHAR; )
{
- printf ("asso_values[%sstr[%d]", char_to_index, key_pos);
- if (_alpha_inc[key_pos])
- printf ("+%u", _alpha_inc[key_pos]);
- printf ("]");
+ output_asso_values_ref (key_pos);
if ((key_pos = iter.next ()) != PositionIterator::EOS)
printf (" + ");
else
@@ -686,7 +698,7 @@ Output::output_hash_function () const
}
if (key_pos == Positions::LASTCHAR)
- printf ("asso_values[%sstr[len - 1]]", char_to_index);
+ output_asso_values_ref (Positions::LASTCHAR);
}
printf (";\n");
@@ -713,11 +725,9 @@ Output::output_hash_function () const
for ( ; i > key_pos; i--)
printf (" case %d:\n", i);
- printf (" hval += asso_values[%sstr[%d]",
- char_to_index, key_pos);
- if (_alpha_inc[key_pos])
- printf ("+%u", _alpha_inc[key_pos]);
- printf ("];\n");
+ printf (" hval += ");
+ output_asso_values_ref (key_pos);
+ printf (";\n");
key_pos = iter.next ();
}
@@ -731,7 +741,10 @@ Output::output_hash_function () const
" }\n"
" return hval");
if (key_pos == Positions::LASTCHAR)
- printf (" + asso_values[%sstr[len - 1]]", char_to_index);
+ {
+ printf (" + ");
+ output_asso_values_ref (Positions::LASTCHAR);
+ }
printf (";\n");
}
}
@@ -1577,8 +1590,6 @@ Output::output ()
_struct_tag = (const_always[0] ? "const char *" : "char *");
}
- char_to_index = "(unsigned char)";
-
printf ("/* ");
if (option[KRC])
printf ("KR-C");
diff --git a/src/output.h b/src/output.h
index 780b4f1..7631110 100644
--- a/src/output.h
+++ b/src/output.h
@@ -71,6 +71,9 @@ private:
/* Outputs the maximum and minimum hash values etc. */
void output_constants (struct Output_Constants&) const;
+ /* Generates a C expression for an asso_values[] reference. */
+ void output_asso_values_ref (int pos) const;
+
/* Generates C code for the hash function that returns the
proper encoding for each keyword. */
void output_hash_function () const;