1228060Sbapt/* This may look like C code, but it is really -*- C++ -*- */
2228060Sbapt
3228060Sbapt/* Keyword data.
4228060Sbapt
5228060Sbapt   Copyright (C) 1989-1998, 2000, 2002 Free Software Foundation, Inc.
6228060Sbapt   Written by Douglas C. Schmidt <schmidt@ics.uci.edu>
7228060Sbapt   and Bruno Haible <bruno@clisp.org>.
8228060Sbapt
9228060Sbapt   This file is part of GNU GPERF.
10228060Sbapt
11228060Sbapt   GNU GPERF is free software; you can redistribute it and/or modify
12228060Sbapt   it under the terms of the GNU General Public License as published by
13228060Sbapt   the Free Software Foundation; either version 2, or (at your option)
14228060Sbapt   any later version.
15228060Sbapt
16228060Sbapt   GNU GPERF is distributed in the hope that it will be useful,
17228060Sbapt   but WITHOUT ANY WARRANTY; without even the implied warranty of
18228060Sbapt   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19228060Sbapt   GNU General Public License for more details.
20228060Sbapt
21228060Sbapt   You should have received a copy of the GNU General Public License
22228060Sbapt   along with this program; see the file COPYING.
23228060Sbapt   If not, write to the Free Software Foundation, Inc.,
24228060Sbapt   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
25228060Sbapt
26228060Sbapt#ifndef keyword_h
27228060Sbapt#define keyword_h 1
28228060Sbapt
29228060Sbapt/* Class defined in "positions.h".  */
30228060Sbaptclass Positions;
31228060Sbapt
32228060Sbapt/* An instance of this class is a keyword, as specified in the input file.  */
33228060Sbapt
34228060Sbaptstruct Keyword
35228060Sbapt{
36228060Sbapt  /* Constructor.  */
37228060Sbapt                        Keyword (const char *allchars, int allchars_length,
38228060Sbapt                                 const char *rest);
39228060Sbapt
40228060Sbapt  /* Data members defined immediately by the input file.  */
41228060Sbapt  /* The keyword as a string, possibly containing NUL bytes.  */
42228060Sbapt  const char *const     _allchars;
43228060Sbapt  int const             _allchars_length;
44228060Sbapt  /* Additional stuff seen on the same line of the input file.  */
45228060Sbapt  const char *const     _rest;
46228060Sbapt  /* Line number of this keyword in the input file.  */
47228060Sbapt  unsigned int          _lineno;
48228060Sbapt};
49228060Sbapt
50228060Sbapt/* A keyword, in the context of a given keyposition list.  */
51228060Sbapt
52228060Sbaptstruct KeywordExt : public Keyword
53228060Sbapt{
54228060Sbapt  /* Constructor.  */
55228060Sbapt                        KeywordExt (const char *allchars, int allchars_length,
56228060Sbapt                                    const char *rest);
57228060Sbapt
58228060Sbapt  /* Data members depending on the keyposition list.  */
59228060Sbapt  /* The selected characters that participate for the hash function,
60228060Sbapt     selected according to the keyposition list, as a canonically reordered
61228060Sbapt     multiset.  */
62228060Sbapt  const unsigned int *  _selchars;
63228060Sbapt  int                   _selchars_length;
64228060Sbapt  /* Chained list of keywords having the same _selchars and
65228060Sbapt     - if !option[NOLENGTH] - also the same _allchars_length.
66228060Sbapt     Note that these duplicates are not members of the main keyword list.  */
67228060Sbapt  KeywordExt *          _duplicate_link;
68228060Sbapt
69228060Sbapt  /* Methods depending on the keyposition list.  */
70228060Sbapt  /* Initializes selchars and selchars_length, without reordering.  */
71228060Sbapt  void                  init_selchars_tuple (const Positions& positions, const unsigned int *alpha_unify);
72228060Sbapt  /* Initializes selchars and selchars_length, with reordering.  */
73228060Sbapt  void                  init_selchars_multiset (const Positions& positions, const unsigned int *alpha_unify, const unsigned int *alpha_inc);
74228060Sbapt  /* Deletes selchars.  */
75228060Sbapt  void                  delete_selchars ();
76228060Sbapt
77228060Sbapt  /* Data members used by the algorithm.  */
78228060Sbapt  int                   _hash_value; /* Hash value for the keyword.  */
79228060Sbapt
80228060Sbapt  /* Data members used by the output routines.  */
81228060Sbapt  int                   _final_index;
82228060Sbapt
83228060Sbaptprivate:
84228060Sbapt  unsigned int *        init_selchars_low (const Positions& positions, const unsigned int *alpha_unify, const unsigned int *alpha_inc);
85228060Sbapt};
86228060Sbapt
87228060Sbapt/* An abstract factory for creating Keyword instances.
88228060Sbapt   This factory is used to make the Input class independent of the concrete
89228060Sbapt   class KeywordExt.  */
90228060Sbapt
91228060Sbaptclass Keyword_Factory
92228060Sbapt{
93228060Sbaptpublic:
94228060Sbapt  /* Constructor.  */
95228060Sbapt                        Keyword_Factory ();
96228060Sbapt  /* Destructor.  */
97228060Sbapt  virtual               ~Keyword_Factory ();
98228060Sbapt
99228060Sbapt  /* Creates a new Keyword.  */
100228060Sbapt  virtual /*abstract*/ Keyword *
101228060Sbapt                        create_keyword (const char *allchars, int allchars_length,
102228060Sbapt                                        const char *rest) = 0;
103228060Sbapt};
104228060Sbapt
105228060Sbapt/* A statically allocated empty string.  */
106228060Sbaptextern char empty_string[1];
107228060Sbapt
108228060Sbapt#ifdef __OPTIMIZE__
109228060Sbapt
110228060Sbapt#define INLINE inline
111228060Sbapt#include "keyword.icc"
112228060Sbapt#undef INLINE
113228060Sbapt
114228060Sbapt#endif
115228060Sbapt
116228060Sbapt#endif
117