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 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. */
31struct Output_Constants;
32struct Output_Compare;
33
34class Output
35{
36public:
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
62private:
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[] reference.  */
75  void                  output_asso_values_ref (int pos) const;
76
77  /* Generates C code for the hash function that returns the
78     proper encoding for each keyword.  */
79  void                  output_hash_function () const;
80
81  /* Prints out a table of keyword lengths, for use with the
82     comparison code in generated function 'in_word_set'.  */
83  void                  output_keylength_table () const;
84
85  /* Prints out the string pool, containing the strings of the keyword table.
86   */
87  void                  output_string_pool () const;
88
89  /* Prints out the array containing the keywords for the hash function.  */
90  void                  output_keyword_table () const;
91
92  /* Generates the large, sparse table that maps hash values into
93     the smaller, contiguous range of the keyword table.  */
94  void                  output_lookup_array () const;
95
96  /* Generate all pools needed for the lookup function.  */
97  void                  output_lookup_pools () const;
98
99  /* Generate all the tables needed for the lookup function.  */
100  void                  output_lookup_tables () const;
101
102  /* Generates C code to perform the keyword lookup.  */
103  void                  output_lookup_function_body (const struct Output_Compare&) const;
104
105  /* Generates C code for the lookup function.  */
106  void                  output_lookup_function () const;
107
108  /* Linked list of keywords.  */
109  KeywordExt_List *     _head;
110
111  /* Declaration of struct type for a keyword and its attributes.  */
112  const char * const    _struct_decl;
113  unsigned int const    _struct_decl_lineno;
114  /* Pointer to return type for lookup function. */
115  const char *          _return_type;
116  /* Shorthand for user-defined struct tag type. */
117  const char *          _struct_tag;
118  /* Element type of keyword array.  */
119  const char *          _wordlist_eltype;
120  /* The C code from the declarations section.  */
121  const char * const    _verbatim_declarations;
122  const char * const    _verbatim_declarations_end;
123  unsigned int const    _verbatim_declarations_lineno;
124  /* The C code from the end of the file.  */
125  const char * const    _verbatim_code;
126  const char * const    _verbatim_code_end;
127  unsigned int const    _verbatim_code_lineno;
128  /* Whether the keyword chars would have different values in a different
129     character set.  */
130  bool                  _charset_dependent;
131  /* Total number of keys, counting duplicates. */
132  int const             _total_keys;
133  /* Maximum length of the longest keyword. */
134  int const             _max_key_len;
135  /* Minimum length of the shortest keyword. */
136  int const             _min_key_len;
137  /* Whether the hash function includes the length.  */
138  bool                  _hash_includes_len;
139  /* Key positions.  */
140  Positions const       _key_positions;
141  /* Adjustments to add to bytes add specific key positions.  */
142  const unsigned int * const _alpha_inc;
143  /* Total number of duplicate hash values. */
144  int const             _total_duplicates;
145  /* Minimum hash value for all keywords. */
146  int                   _min_hash_value;
147  /* Maximum hash value for all keywords. */
148  int                   _max_hash_value;
149  /* Size of alphabet. */
150  unsigned int const    _alpha_size;
151  /* Value associated with each character. */
152  const int * const     _asso_values;
153};
154
155#endif
156