1
0
mirror of https://git.savannah.gnu.org/git/gperf.git synced 2025-12-02 21:19:24 +00:00

Emit #line directives.

This commit is contained in:
Bruno Haible
2003-01-24 12:37:00 +00:00
parent a9916548fa
commit 2059095a04
7 changed files with 56 additions and 5 deletions

View File

@@ -1,5 +1,16 @@
2002-11-10 Bruno Haible <bruno@clisp.org>
* src/keyword.h (Keyword::_lineno): New field.
* src/input.h (Input::_struct_decl_lineno): New field.
* src/input.cc (Input::read_input): Set _struct_decl_lineno. Fill
each keyword's _lineno field.
* src/main.cc (main): Pass _struct_decl_lineno from Input to Output.
* src/output.h (Output::Output) Add struct_decl_lineno argument.
(Output::_struct_decl_lineno): New field.
* src/output.cc (Output::Output) Add struct_decl_lineno argument.
(output_keyword_entry): Emit #line directive before table entry.
(Output::output): Emit #line directive before _struct_decl.
Fix memory leaks.
* src/keyword.h (empty_string): New declaration.
* src/keyword.cc (empty_string): New variable.

View File

@@ -187,11 +187,14 @@ Input::read_input ()
_verbatim_declarations_end = NULL;
_verbatim_declarations_lineno = 0;
_struct_decl = NULL;
_struct_decl_lineno = 0;
_return_type = NULL;
_struct_tag = NULL;
{
unsigned int lineno = 1;
char *struct_decl = NULL;
unsigned int *struct_decl_linenos = NULL;
unsigned int struct_decl_linecount = 0;
for (const char *p = declarations; p < declarations_end; )
{
const char *line_end;
@@ -282,6 +285,18 @@ Input::read_input ()
if (struct_decl)
delete[] struct_decl;
struct_decl = new_struct_decl;
/* Append the lineno to struct_decl_linenos. */
unsigned int *new_struct_decl_linenos =
new unsigned int[struct_decl_linecount + 1];
if (struct_decl_linecount > 0)
memcpy (new_struct_decl_linenos, struct_decl_linenos,
struct_decl_linecount * sizeof (unsigned int));
new_struct_decl_linenos[struct_decl_linecount] = lineno;
if (struct_decl_linenos)
delete[] struct_decl_linenos;
struct_decl_linenos = new_struct_decl_linenos;
/* Increment struct_decl_linecount. */
struct_decl_linecount++;
}
lineno++;
p = line_end;
@@ -301,8 +316,13 @@ Input::read_input ()
/* Drop leading whitespace. */
{
char *p = struct_decl;
unsigned int *l = struct_decl_linenos;
while (p[0] == '\n' || p[0] == ' ' || p[0] == '\t')
p++;
{
if (p[0] == '\n')
l++;
p++;
}
if (p != struct_decl)
{
size_t len = strlen (p);
@@ -311,6 +331,7 @@ Input::read_input ()
delete[] struct_decl;
struct_decl = new_struct_decl;
}
_struct_decl_lineno = *l;
}
/* Drop trailing whitespace. */
for (char *p = struct_decl + strlen (struct_decl); p > struct_decl;)
@@ -364,6 +385,9 @@ Input::read_input ()
return_type[struct_tag_length + 2] = '\0';
_return_type = return_type;
}
if (struct_decl_linenos)
delete[] struct_decl_linenos;
}
/* Parse the keywords section. */
@@ -579,6 +603,7 @@ Input::read_input ()
/* Allocate Keyword and add it to the list. */
Keyword *new_kw = _factory->create_keyword (keyword, keyword_length,
rest);
new_kw->_lineno = lineno;
*list_tail = new Keyword_List (new_kw);
list_tail = &(*list_tail)->rest();
}

View File

@@ -54,6 +54,7 @@ public:
unsigned int _verbatim_code_lineno;
/* Declaration of struct type for a keyword and its attributes. */
const char * _struct_decl;
unsigned int _struct_decl_lineno;
/* Return type of the lookup function. */
const char * _return_type;
/* Shorthand for user-defined struct tag type. */

View File

@@ -40,6 +40,8 @@ struct Keyword
int const _allchars_length;
/* Additional stuff seen on the same line of the input file. */
const char *const _rest;
/* Line number of this keyword in the input file. */
unsigned int _lineno;
};
/* A keyword, in the context of a given keyposition list. */

View File

@@ -82,6 +82,7 @@ main (int argc, char *argv[])
/* Output the hash function code. */
Output outputter (searcher._head,
inputter._struct_decl,
inputter._struct_decl_lineno,
inputter._return_type,
inputter._struct_tag,
inputter._verbatim_declarations,

View File

@@ -81,8 +81,8 @@ static const char *char_to_index;
consecutive list elements.
*/
Output::Output (KeywordExt_List *head, const char *struct_decl,
const char *return_type, const char *struct_tag,
const char *verbatim_declarations,
unsigned int struct_decl_lineno, const char *return_type,
const char *struct_tag, const char *verbatim_declarations,
const char *verbatim_declarations_end,
unsigned int verbatim_declarations_lineno,
const char *verbatim_code, const char *verbatim_code_end,
@@ -90,7 +90,8 @@ Output::Output (KeywordExt_List *head, const char *struct_decl,
int total_keys, int total_duplicates, int max_key_len,
int min_key_len, int alpha_size, const int *occurrences,
const int *asso_values)
: _head (head), _struct_decl (struct_decl), _return_type (return_type),
: _head (head), _struct_decl (struct_decl),
_struct_decl_lineno (struct_decl_lineno), _return_type (return_type),
_struct_tag (struct_tag),
_verbatim_declarations (verbatim_declarations),
_verbatim_declarations_end (verbatim_declarations_end),
@@ -688,6 +689,9 @@ Output::output_keylength_table () const
static void
output_keyword_entry (KeywordExt *temp, const char *indent)
{
if (option[TYPE] && option.get_input_file_name ())
printf ("#line %u \"%s\"\n",
temp->_lineno, option.get_input_file_name ());
printf ("%s ", indent);
if (option[TYPE])
printf ("{");
@@ -1499,7 +1503,12 @@ Output::output ()
}
if (option[TYPE] && !option[NOTYPE]) /* Output type declaration now, reference it later on.... */
printf ("%s\n", _struct_decl);
{
if (option.get_input_file_name ())
printf ("#line %u \"%s\"\n",
_struct_decl_lineno, option.get_input_file_name ());
printf ("%s\n", _struct_decl);
}
if (option[INCLUDE])
printf ("#include <string.h>\n"); /* Declare strlen(), strcmp(), strncmp(). */

View File

@@ -38,6 +38,7 @@ public:
/* Constructor. */
Output (KeywordExt_List *head,
const char *struct_decl,
unsigned int struct_decl_lineno,
const char *return_type,
const char *struct_tag,
const char *verbatim_declarations,
@@ -97,6 +98,7 @@ private:
/* Declaration of struct type for a keyword and its attributes. */
const char * const _struct_decl;
unsigned int const _struct_decl_lineno;
/* Pointer to return type for lookup function. */
const char * _return_type;
/* Shorthand for user-defined struct tag type. */