1 | /* This may look like C code, but it is really -*- C++ -*- */ |
2 | |
3 | /* Output routines. |
4 | |
5 | Copyright (C) 1989-1998, 2000, 2002-2003, 2009, 2016 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 | 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 <http://www.gnu.org/licenses/>. */ |
23 | |
24 | #ifndef output_h |
25 | #define output_h 1 |
26 | |
27 | #include "keyword-list.h" |
28 | #include "positions.h" |
29 | |
30 | /* OSF/1 cxx needs these forward declarations. */ |
31 | struct Output_Constants; |
32 | struct Output_Compare; |
33 | |
34 | class Output |
35 | { |
36 | public: |
37 | /* Constructor. */ |
38 | Output (KeywordExt_List *head, |
39 | const char *struct_decl, |
40 | unsigned int struct_decl_lineno, |
41 | const char *return_type, |
42 | const char *struct_tag, |
43 | const char *verbatim_declarations, |
44 | const char *verbatim_declarations_end, |
45 | unsigned int verbatim_declarations_lineno, |
46 | const char *verbatim_code, |
47 | const char *verbatim_code_end, |
48 | unsigned int verbatim_code_lineno, |
49 | bool charset_dependent, |
50 | int total_keys, |
51 | int max_key_len, int min_key_len, |
52 | bool hash_includes_len, |
53 | const Positions& positions, |
54 | const unsigned int *alpha_inc, |
55 | int total_duplicates, |
56 | unsigned int alpha_size, |
57 | const int *asso_values); |
58 | |
59 | /* Generates the hash function and the key word recognizer function. */ |
60 | void output (); |
61 | |
62 | private: |
63 | |
64 | /* Computes the minimum and maximum hash values, and stores them |
65 | in _min_hash_value and _max_hash_value. */ |
66 | void compute_min_max (); |
67 | |
68 | /* Returns the number of different hash values. */ |
69 | int num_hash_values () const; |
70 | |
71 | /* Outputs the maximum and minimum hash values etc. */ |
72 | void output_constants (struct Output_Constants&) const; |
73 | |
74 | /* Generates a C expression for an asso_values[] index. */ |
75 | void output_asso_values_index (int pos) const; |
76 | |
77 | /* Generates a C expression for an asso_values[] reference. */ |
78 | void output_asso_values_ref (int pos) const; |
79 | |
80 | /* Generates C code for the hash function that returns the |
81 | proper encoding for each keyword. */ |
82 | void output_hash_function () const; |
83 | |
84 | /* Prints out a table of keyword lengths, for use with the |
85 | comparison code in generated function 'in_word_set'. */ |
86 | void output_keylength_table () const; |
87 | |
88 | /* Prints out the string pool, containing the strings of the keyword table. |
89 | */ |
90 | void output_string_pool () const; |
91 | |
92 | /* Prints out the array containing the keywords for the hash function. */ |
93 | void output_keyword_table () const; |
94 | |
95 | /* Generates the large, sparse table that maps hash values into |
96 | the smaller, contiguous range of the keyword table. */ |
97 | void output_lookup_array () const; |
98 | |
99 | /* Generate all pools needed for the lookup function. */ |
100 | void output_lookup_pools () const; |
101 | |
102 | /* Generate all the tables needed for the lookup function. */ |
103 | void output_lookup_tables () const; |
104 | |
105 | /* Generates C code to perform the keyword lookup. */ |
106 | void output_lookup_function_body (const struct Output_Compare&) const; |
107 | |
108 | /* Generates C code for the lookup function. */ |
109 | void output_lookup_function () const; |
110 | |
111 | /* Linked list of keywords. */ |
112 | KeywordExt_List * _head; |
113 | |
114 | /* Declaration of struct type for a keyword and its attributes. */ |
115 | const char * const _struct_decl; |
116 | unsigned int const _struct_decl_lineno; |
117 | /* Pointer to return type for lookup function. */ |
118 | const char * _return_type; |
119 | /* Shorthand for user-defined struct tag type. */ |
120 | const char * _struct_tag; |
121 | /* Element type of keyword array. */ |
122 | const char * _wordlist_eltype; |
123 | /* The C code from the declarations section. */ |
124 | const char * const _verbatim_declarations; |
125 | const char * const _verbatim_declarations_end; |
126 | unsigned int const _verbatim_declarations_lineno; |
127 | /* The C code from the end of the file. */ |
128 | const char * const _verbatim_code; |
129 | const char * const _verbatim_code_end; |
130 | unsigned int const _verbatim_code_lineno; |
131 | /* Whether the keyword chars would have different values in a different |
132 | character set. */ |
133 | bool _charset_dependent; |
134 | /* Total number of keys, counting duplicates. */ |
135 | int const _total_keys; |
136 | /* Maximum length of the longest keyword. */ |
137 | int const _max_key_len; |
138 | /* Minimum length of the shortest keyword. */ |
139 | int const _min_key_len; |
140 | /* Whether the hash function includes the length. */ |
141 | bool _hash_includes_len; |
142 | /* Key positions. */ |
143 | Positions const _key_positions; |
144 | /* Adjustments to add to bytes add specific key positions. */ |
145 | const unsigned int * const _alpha_inc; |
146 | /* Total number of duplicate hash values. */ |
147 | int const _total_duplicates; |
148 | /* Minimum hash value for all keywords. */ |
149 | int _min_hash_value; |
150 | /* Maximum hash value for all keywords. */ |
151 | int _max_hash_value; |
152 | /* Size of alphabet. */ |
153 | unsigned int const _alpha_size; |
154 | /* Value associated with each character. */ |
155 | const int * const _asso_values; |
156 | }; |
157 | |
158 | #endif |
159 | |