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

Let the input module see only Keyword, not KeywordExt.

This commit is contained in:
Bruno Haible
2002-11-22 14:19:08 +00:00
parent 32f5ea88cf
commit 9fa6cbdde5
6 changed files with 74 additions and 17 deletions

View File

@@ -1,5 +1,20 @@
2002-11-02 Bruno Haible <bruno@clisp.org> 2002-11-02 Bruno Haible <bruno@clisp.org>
* src/keyword-list.h (Keyword_List): New class.
(KeywordExt_List): Inherit from it.
* src/keyword-list.cc (Keyword_List::Keyword_List): New constructor.
(KeywordExt_List::KeywordExt_List): Update.
* src/input.h (Input::Input): Add Keyword_Factory argument.
(Input::_factory): New field.
(Input::_head): Change type to Keyword_List*.
(Input::parse_line): New declaration.
* src/input.cc (Input::Input): New constructor.
(Input::parse_line): Renamed from parse_line. Use the _factory.
(Input::read_keys): Update.
* src/key-list.cc (KeywordExt_Factory): New class.
(Key_List::read_keys): Pass a KeywordExt_Factory as Input constructor
argument.
Avoid g++ -Wold-style-cast warnings. Avoid g++ -Wold-style-cast warnings.
* src/bool-array.icc: Use new-style casts. * src/bool-array.icc: Use new-style casts.
* src/gen-perf.cc: Likewise. * src/gen-perf.cc: Likewise.

View File

@@ -26,6 +26,11 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. */
#include "options.h" #include "options.h"
#include "input.h" #include "input.h"
Input::Input (Keyword_Factory *keyword_factory)
: _factory (keyword_factory)
{
}
/* Gathers the input stream into a buffer until one of two things occur: /* Gathers the input stream into a buffer until one of two things occur:
1. We read a '%' followed by a '%' 1. We read a '%' followed by a '%'
@@ -177,11 +182,11 @@ Input::set_output_types ()
} }
} }
/* Extracts a key from an input line and creates a new KeywordExt_List for /* Extracts a key from an input line and creates a new Keyword_List for
it. */ it. */
static KeywordExt_List * Keyword_List *
parse_line (const char *line, const char *delimiters) Input::parse_line (const char *line, const char *delimiters)
{ {
if (*line == '"') if (*line == '"')
{ {
@@ -299,7 +304,7 @@ parse_line (const char *line, const char *delimiters)
} }
lp++; lp++;
} }
return new KeywordExt_List (new KeywordExt (key, kp - key, option[TYPE] ? lp : "")); return new Keyword_List (_factory->create_keyword (key, kp - key, option[TYPE] ? lp : ""));
} }
else else
{ {
@@ -312,7 +317,7 @@ parse_line (const char *line, const char *delimiters)
else else
/* Skip the first delimiter. */ /* Skip the first delimiter. */
rest = &line[len + 1]; rest = &line[len + 1];
return new KeywordExt_List (new KeywordExt (line, len, option[TYPE] ? rest : "")); return new Keyword_List (_factory->create_keyword (line, len, option[TYPE] ? rest : ""));
} }
} }
@@ -336,7 +341,7 @@ Input::read_keys ()
_head = parse_line (ptr, delimiter); _head = parse_line (ptr, delimiter);
for (KeywordExt_List *temp = _head; for (Keyword_List *temp = _head;
(ptr = Read_Line::read_next_line ()) && strcmp (ptr, "%%"); (ptr = Read_Line::read_next_line ()) && strcmp (ptr, "%%");
temp = temp->rest()) temp = temp->rest())
temp->rest() = parse_line (ptr, delimiter); temp->rest() = parse_line (ptr, delimiter);

View File

@@ -31,6 +31,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. */
class Input : private Read_Line class Input : private Read_Line
{ {
public: public:
Input (Keyword_Factory *keyword_factory);
void read_keys (); void read_keys ();
private: private:
#ifndef strcspn #ifndef strcspn
@@ -46,7 +47,10 @@ public:
const char * _struct_tag; /* Shorthand for user-defined struct tag type. */ const char * _struct_tag; /* Shorthand for user-defined struct tag type. */
const char * _include_src; /* C source code to be included verbatim. */ const char * _include_src; /* C source code to be included verbatim. */
bool _additional_code; /* True if any additional C code is included. */ bool _additional_code; /* True if any additional C code is included. */
KeywordExt_List * _head; /* Points to the head of the linked list. */ Keyword_Factory * _factory; /* Creates the keywords. */
Keyword_List * _head; /* Points to the head of the linked list. */
private:
Keyword_List * parse_line (const char *line, const char *delimiters);
}; };
#endif #endif

View File

@@ -48,6 +48,18 @@ Key_List::~Key_List ()
} }
} }
class KeywordExt_Factory : public Keyword_Factory
{
virtual Keyword * create_keyword (const char *allchars, int allchars_length,
const char *rest);
};
Keyword *
KeywordExt_Factory::create_keyword (const char *allchars, int allchars_length, const char *rest)
{
return new KeywordExt (allchars, allchars_length, rest);
}
/* Reads in all keys from standard input and creates a linked list pointed /* Reads in all keys from standard input and creates a linked list pointed
to by _head. This list is then quickly checked for "links", i.e., to by _head. This list is then quickly checked for "links", i.e.,
unhashable elements possessing identical key sets and lengths. */ unhashable elements possessing identical key sets and lengths. */
@@ -55,14 +67,15 @@ Key_List::~Key_List ()
void void
Key_List::read_keys () Key_List::read_keys ()
{ {
Input inputter; KeywordExt_Factory factory;
Input inputter (&factory);
inputter.read_keys (); inputter.read_keys ();
_array_type = inputter._array_type; _array_type = inputter._array_type;
_return_type = inputter._return_type; _return_type = inputter._return_type;
_struct_tag = inputter._struct_tag; _struct_tag = inputter._struct_tag;
_include_src = inputter._include_src; _include_src = inputter._include_src;
_additional_code = inputter._additional_code; _additional_code = inputter._additional_code;
_head = inputter._head; _head = static_cast<KeywordExt_List*>(inputter._head);
KeywordExt_List *temp; KeywordExt_List *temp;
KeywordExt_List *trail = NULL; KeywordExt_List *trail = NULL;

View File

@@ -23,7 +23,13 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. */
#include "keyword-list.h" #include "keyword-list.h"
/* Constructor. */ /* Constructor. */
KeywordExt_List::KeywordExt_List (KeywordExt *car) Keyword_List::Keyword_List (Keyword *car)
: _cdr (NULL), _car (car) : _cdr (NULL), _car (car)
{ {
} }
/* Unused constructor. */
KeywordExt_List::KeywordExt_List (KeywordExt *car)
: Keyword_List (car)
{
}

View File

@@ -27,19 +27,33 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. */
#include "keyword.h" #include "keyword.h"
/* List node of a linear list of Keyword. */ /* List node of a linear list of Keyword. */
class KeywordExt_List { class Keyword_List
{
public: public:
/* Constructor. */ /* Constructor. */
Keyword_List (Keyword *car);
/* Access to first element of list. */
Keyword * first () { return _car; }
/* Access to next element of list. */
Keyword_List *& rest () { return _cdr; }
protected:
Keyword_List * _cdr;
Keyword * const _car;
};
/* List node of a linear list of KeywordExt. */
class KeywordExt_List : public Keyword_List
{
public:
/* Unused constructor. */
KeywordExt_List (KeywordExt *car); KeywordExt_List (KeywordExt *car);
/* Access to first element of list. */ /* Access to first element of list. */
KeywordExt * first () { return _car; } KeywordExt * first () { return static_cast<KeywordExt*>(_car); }
/* Access to next element of list. */ /* Access to next element of list. */
KeywordExt_List *& rest () { return _cdr; } KeywordExt_List *& rest () { return static_cast<KeywordExt_List*>(_cdr); }
private:
KeywordExt_List * _cdr;
KeywordExt * const _car;
}; };
#endif #endif