Debian Codegraph @

src/keyword.h

raw
1 /* This may look like C code, but it is really -*- C++ -*- */
2
3 /* Keyword data.
4
5 Copyright (C) 1989-1998, 2000, 2002-2003, 2017, 2025 Free Software Foundation, Inc.
6 Written by Douglas C. Schmidt <[email protected]>
7 and Bruno Haible <[email protected]>.
8
9 This file is part of GNU GPERF.
10
11 This program 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 3 of the License, or
14 (at your option) any later version.
15
16 This program 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. If not, see <https://www.gnu.org/licenses/>. */
23
24 #ifndef keyword_h
25 #define keyword_h 1
26
27 #include <stddef.h> /* defines size_t */
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, unsigned int lineno);
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, unsigned int lineno);
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, specifically compute_partition. */
78 /* The undetermined selected characters for this keyword, as a
79 canonically reordered multiset. */
80 unsigned int * _undetermined_chars;
81 unsigned int _undetermined_chars_length;
82 size_t _undetermined_chars_hashcode;
83
84 /* Data members used by the algorithm. */
85 int _hash_value; /* Hash value for the keyword. */
86
87 /* Data members used by the output routines. */
88 int _final_index;
89
90 private:
91 unsigned int * init_selchars_low (const Positions& positions, const unsigned int *alpha_unify, const unsigned int *alpha_inc);
92 };
93
94 /* A factory for creating Keyword instances.
95 This factory is used to make the Input class independent of the concrete
96 class KeywordExt. */
97
98 template <class KT>
99 class Keyword_Factory
100 {
101 public:
102 /* Constructor. */
103 Keyword_Factory ();
104 /* Destructor. */
105 virtual ~Keyword_Factory ();
106
107 /* Creates a new Keyword. */
108 virtual KT * create_keyword (const char *allchars, int allchars_length,
109 const char *rest, unsigned int lineno);
110 };
111
112 /* A statically allocated empty string. */
113 extern char empty_string[1];
114
115 #ifdef __OPTIMIZE__
116
117 #define INLINE inline
118 #include "keyword.icc"
119 #undef INLINE
120
121 #endif
122
123 #endif