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:
17
src/input.cc
17
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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<KeywordExt_List*>(inputter._head);
|
||||
|
||||
KeywordExt_List *temp;
|
||||
KeywordExt_List *trail = NULL;
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -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<KeywordExt*>(_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<KeywordExt_List*>(_cdr); }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user