]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - contrib/gperf/src/keyword.h
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / contrib / gperf / src / keyword.h
1 /* This may look like C code, but it is really -*- C++ -*- */
2
3 /* Keyword data.
4
5    Copyright (C) 1989-1998, 2000, 2002 Free Software Foundation, Inc.
6    Written by Douglas C. Schmidt <schmidt@ics.uci.edu>
7    and Bruno Haible <bruno@clisp.org>.
8
9    This file is part of GNU GPERF.
10
11    GNU GPERF is free software; you can redistribute it and/or modify
12    it under the terms of the GNU General Public License as published by
13    the Free Software Foundation; either version 2, or (at your option)
14    any later version.
15
16    GNU GPERF is distributed in the hope that it will be useful,
17    but WITHOUT ANY WARRANTY; without even the implied warranty of
18    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19    GNU General Public License for more details.
20
21    You should have received a copy of the GNU General Public License
22    along with this program; see the file COPYING.
23    If not, write to the Free Software Foundation, Inc.,
24    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
25
26 #ifndef keyword_h
27 #define keyword_h 1
28
29 /* Class defined in "positions.h".  */
30 class Positions;
31
32 /* An instance of this class is a keyword, as specified in the input file.  */
33
34 struct Keyword
35 {
36   /* Constructor.  */
37                         Keyword (const char *allchars, int allchars_length,
38                                  const char *rest);
39
40   /* Data members defined immediately by the input file.  */
41   /* The keyword as a string, possibly containing NUL bytes.  */
42   const char *const     _allchars;
43   int const             _allchars_length;
44   /* Additional stuff seen on the same line of the input file.  */
45   const char *const     _rest;
46   /* Line number of this keyword in the input file.  */
47   unsigned int          _lineno;
48 };
49
50 /* A keyword, in the context of a given keyposition list.  */
51
52 struct KeywordExt : public Keyword
53 {
54   /* Constructor.  */
55                         KeywordExt (const char *allchars, int allchars_length,
56                                     const char *rest);
57
58   /* Data members depending on the keyposition list.  */
59   /* The selected characters that participate for the hash function,
60      selected according to the keyposition list, as a canonically reordered
61      multiset.  */
62   const unsigned int *  _selchars;
63   int                   _selchars_length;
64   /* Chained list of keywords having the same _selchars and
65      - if !option[NOLENGTH] - also the same _allchars_length.
66      Note that these duplicates are not members of the main keyword list.  */
67   KeywordExt *          _duplicate_link;
68
69   /* Methods depending on the keyposition list.  */
70   /* Initializes selchars and selchars_length, without reordering.  */
71   void                  init_selchars_tuple (const Positions& positions, const unsigned int *alpha_unify);
72   /* Initializes selchars and selchars_length, with reordering.  */
73   void                  init_selchars_multiset (const Positions& positions, const unsigned int *alpha_unify, const unsigned int *alpha_inc);
74   /* Deletes selchars.  */
75   void                  delete_selchars ();
76
77   /* Data members used by the algorithm.  */
78   int                   _hash_value; /* Hash value for the keyword.  */
79
80   /* Data members used by the output routines.  */
81   int                   _final_index;
82
83 private:
84   unsigned int *        init_selchars_low (const Positions& positions, const unsigned int *alpha_unify, const unsigned int *alpha_inc);
85 };
86
87 /* An abstract factory for creating Keyword instances.
88    This factory is used to make the Input class independent of the concrete
89    class KeywordExt.  */
90
91 class Keyword_Factory
92 {
93 public:
94   /* Constructor.  */
95                         Keyword_Factory ();
96   /* Destructor.  */
97   virtual               ~Keyword_Factory ();
98
99   /* Creates a new Keyword.  */
100   virtual /*abstract*/ Keyword *
101                         create_keyword (const char *allchars, int allchars_length,
102                                         const char *rest) = 0;
103 };
104
105 /* A statically allocated empty string.  */
106 extern char empty_string[1];
107
108 #ifdef __OPTIMIZE__
109
110 #define INLINE inline
111 #include "keyword.icc"
112 #undef INLINE
113
114 #endif
115
116 #endif