From 9fa6cbdde51fb80315b527d54ab14e112ab18adf Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Fri, 22 Nov 2002 14:19:08 +0000 Subject: [PATCH] Let the input module see only Keyword, not KeywordExt. --- ChangeLog | 15 +++++++++++++++ src/input.cc | 17 +++++++++++------ src/input.h | 6 +++++- src/key-list.cc | 17 +++++++++++++++-- src/keyword-list.cc | 8 +++++++- src/keyword-list.h | 28 +++++++++++++++++++++------- 6 files changed, 74 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8987435..6bbf327 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,20 @@ 2002-11-02 Bruno Haible + * 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. * src/bool-array.icc: Use new-style casts. * src/gen-perf.cc: Likewise. diff --git a/src/input.cc b/src/input.cc index 1f48d54..2d9ddfc 100644 --- a/src/input.cc +++ b/src/input.cc @@ -26,6 +26,11 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ #include "options.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: 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. */ -static KeywordExt_List * -parse_line (const char *line, const char *delimiters) +Keyword_List * +Input::parse_line (const char *line, const char *delimiters) { if (*line == '"') { @@ -299,7 +304,7 @@ parse_line (const char *line, const char *delimiters) } 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 { @@ -312,7 +317,7 @@ parse_line (const char *line, const char *delimiters) else /* Skip the first delimiter. */ 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); - for (KeywordExt_List *temp = _head; + for (Keyword_List *temp = _head; (ptr = Read_Line::read_next_line ()) && strcmp (ptr, "%%"); temp = temp->rest()) temp->rest() = parse_line (ptr, delimiter); diff --git a/src/input.h b/src/input.h index 583bcb8..61534c9 100644 --- a/src/input.h +++ b/src/input.h @@ -31,6 +31,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ class Input : private Read_Line { public: + Input (Keyword_Factory *keyword_factory); void read_keys (); private: #ifndef strcspn @@ -46,7 +47,10 @@ public: const char * _struct_tag; /* Shorthand for user-defined struct tag type. */ const char * _include_src; /* C source code to be included verbatim. */ 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 diff --git a/src/key-list.cc b/src/key-list.cc index cb16327..ad18c52 100644 --- a/src/key-list.cc +++ b/src/key-list.cc @@ -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 to by _head. This list is then quickly checked for "links", i.e., unhashable elements possessing identical key sets and lengths. */ @@ -55,14 +67,15 @@ Key_List::~Key_List () void Key_List::read_keys () { - Input inputter; + KeywordExt_Factory factory; + Input inputter (&factory); inputter.read_keys (); _array_type = inputter._array_type; _return_type = inputter._return_type; _struct_tag = inputter._struct_tag; _include_src = inputter._include_src; _additional_code = inputter._additional_code; - _head = inputter._head; + _head = static_cast(inputter._head); KeywordExt_List *temp; KeywordExt_List *trail = NULL; diff --git a/src/keyword-list.cc b/src/keyword-list.cc index 7776b5c..5900dcc 100644 --- a/src/keyword-list.cc +++ b/src/keyword-list.cc @@ -23,7 +23,13 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ #include "keyword-list.h" /* Constructor. */ -KeywordExt_List::KeywordExt_List (KeywordExt *car) +Keyword_List::Keyword_List (Keyword *car) : _cdr (NULL), _car (car) { } + +/* Unused constructor. */ +KeywordExt_List::KeywordExt_List (KeywordExt *car) + : Keyword_List (car) +{ +} diff --git a/src/keyword-list.h b/src/keyword-list.h index 0a3f5d3..18a7158 100644 --- a/src/keyword-list.h +++ b/src/keyword-list.h @@ -27,19 +27,33 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ #include "keyword.h" /* List node of a linear list of Keyword. */ -class KeywordExt_List { +class Keyword_List +{ public: /* 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); /* Access to first element of list. */ - KeywordExt * first () { return _car; } + KeywordExt * first () { return static_cast(_car); } /* Access to next element of list. */ - KeywordExt_List *& rest () { return _cdr; } - -private: - KeywordExt_List * _cdr; - KeywordExt * const _car; + KeywordExt_List *& rest () { return static_cast(_cdr); } }; #endif