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