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:
11
ChangeLog
11
ChangeLog
@@ -1,5 +1,16 @@
|
|||||||
2002-11-10 Bruno Haible <bruno@clisp.org>
|
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.
|
Fix memory leaks.
|
||||||
* src/keyword.h (empty_string): New declaration.
|
* src/keyword.h (empty_string): New declaration.
|
||||||
* src/keyword.cc (empty_string): New variable.
|
* src/keyword.cc (empty_string): New variable.
|
||||||
|
|||||||
25
src/input.cc
25
src/input.cc
@@ -187,11 +187,14 @@ Input::read_input ()
|
|||||||
_verbatim_declarations_end = NULL;
|
_verbatim_declarations_end = NULL;
|
||||||
_verbatim_declarations_lineno = 0;
|
_verbatim_declarations_lineno = 0;
|
||||||
_struct_decl = NULL;
|
_struct_decl = NULL;
|
||||||
|
_struct_decl_lineno = 0;
|
||||||
_return_type = NULL;
|
_return_type = NULL;
|
||||||
_struct_tag = NULL;
|
_struct_tag = NULL;
|
||||||
{
|
{
|
||||||
unsigned int lineno = 1;
|
unsigned int lineno = 1;
|
||||||
char *struct_decl = NULL;
|
char *struct_decl = NULL;
|
||||||
|
unsigned int *struct_decl_linenos = NULL;
|
||||||
|
unsigned int struct_decl_linecount = 0;
|
||||||
for (const char *p = declarations; p < declarations_end; )
|
for (const char *p = declarations; p < declarations_end; )
|
||||||
{
|
{
|
||||||
const char *line_end;
|
const char *line_end;
|
||||||
@@ -282,6 +285,18 @@ Input::read_input ()
|
|||||||
if (struct_decl)
|
if (struct_decl)
|
||||||
delete[] struct_decl;
|
delete[] struct_decl;
|
||||||
struct_decl = new_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++;
|
lineno++;
|
||||||
p = line_end;
|
p = line_end;
|
||||||
@@ -301,8 +316,13 @@ Input::read_input ()
|
|||||||
/* Drop leading whitespace. */
|
/* Drop leading whitespace. */
|
||||||
{
|
{
|
||||||
char *p = struct_decl;
|
char *p = struct_decl;
|
||||||
|
unsigned int *l = struct_decl_linenos;
|
||||||
while (p[0] == '\n' || p[0] == ' ' || p[0] == '\t')
|
while (p[0] == '\n' || p[0] == ' ' || p[0] == '\t')
|
||||||
|
{
|
||||||
|
if (p[0] == '\n')
|
||||||
|
l++;
|
||||||
p++;
|
p++;
|
||||||
|
}
|
||||||
if (p != struct_decl)
|
if (p != struct_decl)
|
||||||
{
|
{
|
||||||
size_t len = strlen (p);
|
size_t len = strlen (p);
|
||||||
@@ -311,6 +331,7 @@ Input::read_input ()
|
|||||||
delete[] struct_decl;
|
delete[] struct_decl;
|
||||||
struct_decl = new_struct_decl;
|
struct_decl = new_struct_decl;
|
||||||
}
|
}
|
||||||
|
_struct_decl_lineno = *l;
|
||||||
}
|
}
|
||||||
/* Drop trailing whitespace. */
|
/* Drop trailing whitespace. */
|
||||||
for (char *p = struct_decl + strlen (struct_decl); p > struct_decl;)
|
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[struct_tag_length + 2] = '\0';
|
||||||
_return_type = return_type;
|
_return_type = return_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (struct_decl_linenos)
|
||||||
|
delete[] struct_decl_linenos;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Parse the keywords section. */
|
/* Parse the keywords section. */
|
||||||
@@ -579,6 +603,7 @@ Input::read_input ()
|
|||||||
/* Allocate Keyword and add it to the list. */
|
/* Allocate Keyword and add it to the list. */
|
||||||
Keyword *new_kw = _factory->create_keyword (keyword, keyword_length,
|
Keyword *new_kw = _factory->create_keyword (keyword, keyword_length,
|
||||||
rest);
|
rest);
|
||||||
|
new_kw->_lineno = lineno;
|
||||||
*list_tail = new Keyword_List (new_kw);
|
*list_tail = new Keyword_List (new_kw);
|
||||||
list_tail = &(*list_tail)->rest();
|
list_tail = &(*list_tail)->rest();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ public:
|
|||||||
unsigned int _verbatim_code_lineno;
|
unsigned int _verbatim_code_lineno;
|
||||||
/* Declaration of struct type for a keyword and its attributes. */
|
/* Declaration of struct type for a keyword and its attributes. */
|
||||||
const char * _struct_decl;
|
const char * _struct_decl;
|
||||||
|
unsigned int _struct_decl_lineno;
|
||||||
/* Return type of the lookup function. */
|
/* Return type of the lookup function. */
|
||||||
const char * _return_type;
|
const char * _return_type;
|
||||||
/* Shorthand for user-defined struct tag type. */
|
/* Shorthand for user-defined struct tag type. */
|
||||||
|
|||||||
@@ -40,6 +40,8 @@ struct Keyword
|
|||||||
int const _allchars_length;
|
int const _allchars_length;
|
||||||
/* Additional stuff seen on the same line of the input file. */
|
/* Additional stuff seen on the same line of the input file. */
|
||||||
const char *const _rest;
|
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. */
|
/* A keyword, in the context of a given keyposition list. */
|
||||||
|
|||||||
@@ -82,6 +82,7 @@ main (int argc, char *argv[])
|
|||||||
/* Output the hash function code. */
|
/* Output the hash function code. */
|
||||||
Output outputter (searcher._head,
|
Output outputter (searcher._head,
|
||||||
inputter._struct_decl,
|
inputter._struct_decl,
|
||||||
|
inputter._struct_decl_lineno,
|
||||||
inputter._return_type,
|
inputter._return_type,
|
||||||
inputter._struct_tag,
|
inputter._struct_tag,
|
||||||
inputter._verbatim_declarations,
|
inputter._verbatim_declarations,
|
||||||
|
|||||||
@@ -81,8 +81,8 @@ static const char *char_to_index;
|
|||||||
consecutive list elements.
|
consecutive list elements.
|
||||||
*/
|
*/
|
||||||
Output::Output (KeywordExt_List *head, const char *struct_decl,
|
Output::Output (KeywordExt_List *head, const char *struct_decl,
|
||||||
const char *return_type, const char *struct_tag,
|
unsigned int struct_decl_lineno, const char *return_type,
|
||||||
const char *verbatim_declarations,
|
const char *struct_tag, const char *verbatim_declarations,
|
||||||
const char *verbatim_declarations_end,
|
const char *verbatim_declarations_end,
|
||||||
unsigned int verbatim_declarations_lineno,
|
unsigned int verbatim_declarations_lineno,
|
||||||
const char *verbatim_code, const char *verbatim_code_end,
|
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 total_keys, int total_duplicates, int max_key_len,
|
||||||
int min_key_len, int alpha_size, const int *occurrences,
|
int min_key_len, int alpha_size, const int *occurrences,
|
||||||
const int *asso_values)
|
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),
|
_struct_tag (struct_tag),
|
||||||
_verbatim_declarations (verbatim_declarations),
|
_verbatim_declarations (verbatim_declarations),
|
||||||
_verbatim_declarations_end (verbatim_declarations_end),
|
_verbatim_declarations_end (verbatim_declarations_end),
|
||||||
@@ -688,6 +689,9 @@ Output::output_keylength_table () const
|
|||||||
static void
|
static void
|
||||||
output_keyword_entry (KeywordExt *temp, const char *indent)
|
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);
|
printf ("%s ", indent);
|
||||||
if (option[TYPE])
|
if (option[TYPE])
|
||||||
printf ("{");
|
printf ("{");
|
||||||
@@ -1499,7 +1503,12 @@ Output::output ()
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (option[TYPE] && !option[NOTYPE]) /* Output type declaration now, reference it later on.... */
|
if (option[TYPE] && !option[NOTYPE]) /* Output type declaration now, reference it later on.... */
|
||||||
|
{
|
||||||
|
if (option.get_input_file_name ())
|
||||||
|
printf ("#line %u \"%s\"\n",
|
||||||
|
_struct_decl_lineno, option.get_input_file_name ());
|
||||||
printf ("%s\n", _struct_decl);
|
printf ("%s\n", _struct_decl);
|
||||||
|
}
|
||||||
|
|
||||||
if (option[INCLUDE])
|
if (option[INCLUDE])
|
||||||
printf ("#include <string.h>\n"); /* Declare strlen(), strcmp(), strncmp(). */
|
printf ("#include <string.h>\n"); /* Declare strlen(), strcmp(), strncmp(). */
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ public:
|
|||||||
/* Constructor. */
|
/* Constructor. */
|
||||||
Output (KeywordExt_List *head,
|
Output (KeywordExt_List *head,
|
||||||
const char *struct_decl,
|
const char *struct_decl,
|
||||||
|
unsigned int struct_decl_lineno,
|
||||||
const char *return_type,
|
const char *return_type,
|
||||||
const char *struct_tag,
|
const char *struct_tag,
|
||||||
const char *verbatim_declarations,
|
const char *verbatim_declarations,
|
||||||
@@ -97,6 +98,7 @@ private:
|
|||||||
|
|
||||||
/* Declaration of struct type for a keyword and its attributes. */
|
/* Declaration of struct type for a keyword and its attributes. */
|
||||||
const char * const _struct_decl;
|
const char * const _struct_decl;
|
||||||
|
unsigned int const _struct_decl_lineno;
|
||||||
/* Pointer to return type for lookup function. */
|
/* Pointer to return type for lookup function. */
|
||||||
const char * _return_type;
|
const char * _return_type;
|
||||||
/* Shorthand for user-defined struct tag type. */
|
/* Shorthand for user-defined struct tag type. */
|
||||||
|
|||||||
Reference in New Issue
Block a user