diff options
author | Bruno Haible <bruno@clisp.org> | 2003-01-24 12:37:00 +0000 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2003-01-24 12:37:00 +0000 |
commit | 2059095a04318a615ef7d4ba7240d02bf9fffe30 (patch) | |
tree | 1ff2cfdc17a484ed08bdd0865875833f27a65708 | |
parent | a9916548fa1098050c0d576c3f8356b439ac0aaf (diff) | |
download | gperf-2059095a04318a615ef7d4ba7240d02bf9fffe30.tar.gz |
Emit #line directives.
-rw-r--r-- | ChangeLog | 11 | ||||
-rw-r--r-- | src/input.cc | 27 | ||||
-rw-r--r-- | src/input.h | 1 | ||||
-rw-r--r-- | src/keyword.h | 2 | ||||
-rw-r--r-- | src/main.cc | 1 | ||||
-rw-r--r-- | src/output.cc | 17 | ||||
-rw-r--r-- | src/output.h | 2 |
7 files changed, 56 insertions, 5 deletions
@@ -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. diff --git a/src/input.cc b/src/input.cc index a04856b..59d09f7 100644 --- a/src/input.cc +++ b/src/input.cc @@ -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(); } diff --git a/src/input.h b/src/input.h index 6d6fd87..01678a2 100644 --- a/src/input.h +++ b/src/input.h @@ -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. */ diff --git a/src/keyword.h b/src/keyword.h index 0d1eec9..79a71df 100644 --- a/src/keyword.h +++ b/src/keyword.h @@ -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. */ diff --git a/src/main.cc b/src/main.cc index 18ee0bf..a688143 100644 --- a/src/main.cc +++ b/src/main.cc @@ -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, diff --git a/src/output.cc b/src/output.cc index 013a3ad..e581f95 100644 --- a/src/output.cc +++ b/src/output.cc @@ -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(). */ diff --git a/src/output.h b/src/output.h index b079155..d9756ab 100644 --- a/src/output.h +++ b/src/output.h @@ -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. */ |