1228060Sbapt/* This may look like C code, but it is really -*- C++ -*- */ 2228060Sbapt 3228060Sbapt/* Output routines. 4228060Sbapt 5228060Sbapt Copyright (C) 1989-1998, 2000, 2002-2003 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 output_h 27228060Sbapt#define output_h 1 28228060Sbapt 29228060Sbapt#include "keyword-list.h" 30228060Sbapt#include "positions.h" 31228060Sbapt 32228060Sbapt/* OSF/1 cxx needs these forward declarations. */ 33228060Sbaptstruct Output_Constants; 34228060Sbaptstruct Output_Compare; 35228060Sbapt 36228060Sbaptclass Output 37228060Sbapt{ 38228060Sbaptpublic: 39228060Sbapt /* Constructor. */ 40228060Sbapt Output (KeywordExt_List *head, 41228060Sbapt const char *struct_decl, 42228060Sbapt unsigned int struct_decl_lineno, 43228060Sbapt const char *return_type, 44228060Sbapt const char *struct_tag, 45228060Sbapt const char *verbatim_declarations, 46228060Sbapt const char *verbatim_declarations_end, 47228060Sbapt unsigned int verbatim_declarations_lineno, 48228060Sbapt const char *verbatim_code, 49228060Sbapt const char *verbatim_code_end, 50228060Sbapt unsigned int verbatim_code_lineno, 51228060Sbapt bool charset_dependent, 52228060Sbapt int total_keys, 53228060Sbapt int max_key_len, int min_key_len, 54228060Sbapt const Positions& positions, 55228060Sbapt const unsigned int *alpha_inc, 56228060Sbapt int total_duplicates, 57228060Sbapt unsigned int alpha_size, 58228060Sbapt const int *asso_values); 59228060Sbapt 60228060Sbapt /* Generates the hash function and the key word recognizer function. */ 61228060Sbapt void output (); 62228060Sbapt 63228060Sbaptprivate: 64228060Sbapt 65228060Sbapt /* Computes the minimum and maximum hash values, and stores them 66228060Sbapt in _min_hash_value and _max_hash_value. */ 67228060Sbapt void compute_min_max (); 68228060Sbapt 69228060Sbapt /* Returns the number of different hash values. */ 70228060Sbapt int num_hash_values () const; 71228060Sbapt 72228060Sbapt /* Outputs the maximum and minimum hash values etc. */ 73228060Sbapt void output_constants (struct Output_Constants&) const; 74228060Sbapt 75228060Sbapt /* Generates a C expression for an asso_values[] reference. */ 76228060Sbapt void output_asso_values_ref (int pos) const; 77228060Sbapt 78228060Sbapt /* Generates C code for the hash function that returns the 79228060Sbapt proper encoding for each keyword. */ 80228060Sbapt void output_hash_function () const; 81228060Sbapt 82228060Sbapt /* Prints out a table of keyword lengths, for use with the 83228060Sbapt comparison code in generated function 'in_word_set'. */ 84228060Sbapt void output_keylength_table () const; 85228060Sbapt 86228060Sbapt /* Prints out the string pool, containing the strings of the keyword table. 87228060Sbapt */ 88228060Sbapt void output_string_pool () const; 89228060Sbapt 90228060Sbapt /* Prints out the array containing the keywords for the hash function. */ 91228060Sbapt void output_keyword_table () const; 92228060Sbapt 93228060Sbapt /* Generates the large, sparse table that maps hash values into 94228060Sbapt the smaller, contiguous range of the keyword table. */ 95228060Sbapt void output_lookup_array () const; 96228060Sbapt 97228060Sbapt /* Generate all pools needed for the lookup function. */ 98228060Sbapt void output_lookup_pools () const; 99228060Sbapt 100228060Sbapt /* Generate all the tables needed for the lookup function. */ 101228060Sbapt void output_lookup_tables () const; 102228060Sbapt 103228060Sbapt /* Generates C code to perform the keyword lookup. */ 104228060Sbapt void output_lookup_function_body (const struct Output_Compare&) const; 105228060Sbapt 106228060Sbapt /* Generates C code for the lookup function. */ 107228060Sbapt void output_lookup_function () const; 108228060Sbapt 109228060Sbapt /* Linked list of keywords. */ 110228060Sbapt KeywordExt_List * _head; 111228060Sbapt 112228060Sbapt /* Declaration of struct type for a keyword and its attributes. */ 113228060Sbapt const char * const _struct_decl; 114228060Sbapt unsigned int const _struct_decl_lineno; 115228060Sbapt /* Pointer to return type for lookup function. */ 116228060Sbapt const char * _return_type; 117228060Sbapt /* Shorthand for user-defined struct tag type. */ 118228060Sbapt const char * _struct_tag; 119228060Sbapt /* Element type of keyword array. */ 120228060Sbapt const char * _wordlist_eltype; 121228060Sbapt /* The C code from the declarations section. */ 122228060Sbapt const char * const _verbatim_declarations; 123228060Sbapt const char * const _verbatim_declarations_end; 124228060Sbapt unsigned int const _verbatim_declarations_lineno; 125228060Sbapt /* The C code from the end of the file. */ 126228060Sbapt const char * const _verbatim_code; 127228060Sbapt const char * const _verbatim_code_end; 128228060Sbapt unsigned int const _verbatim_code_lineno; 129228060Sbapt /* Whether the keyword chars would have different values in a different 130228060Sbapt character set. */ 131228060Sbapt bool _charset_dependent; 132228060Sbapt /* Total number of keys, counting duplicates. */ 133228060Sbapt int const _total_keys; 134228060Sbapt /* Maximum length of the longest keyword. */ 135228060Sbapt int const _max_key_len; 136228060Sbapt /* Minimum length of the shortest keyword. */ 137228060Sbapt int const _min_key_len; 138228060Sbapt /* Key positions. */ 139228060Sbapt Positions const _key_positions; 140228060Sbapt /* Adjustments to add to bytes add specific key positions. */ 141228060Sbapt const unsigned int * const _alpha_inc; 142228060Sbapt /* Total number of duplicate hash values. */ 143228060Sbapt int const _total_duplicates; 144228060Sbapt /* Minimum hash value for all keywords. */ 145228060Sbapt int _min_hash_value; 146228060Sbapt /* Maximum hash value for all keywords. */ 147228060Sbapt int _max_hash_value; 148228060Sbapt /* Size of alphabet. */ 149228060Sbapt unsigned int const _alpha_size; 150228060Sbapt /* Value associated with each character. */ 151228060Sbapt const int * const _asso_values; 152228060Sbapt}; 153228060Sbapt 154228060Sbapt#endif 155