Blame src/output.h

Packit b27855
/* This may look like C code, but it is really -*- C++ -*- */
Packit b27855
Packit b27855
/* Output routines.
Packit b27855
Packit b27855
   Copyright (C) 1989-1998, 2000, 2002-2003, 2009, 2016 Free Software Foundation, Inc.
Packit b27855
   Written by Douglas C. Schmidt <schmidt@ics.uci.edu>
Packit b27855
   and Bruno Haible <bruno@clisp.org>.
Packit b27855
Packit b27855
   This file is part of GNU GPERF.
Packit b27855
Packit b27855
   This program is free software: you can redistribute it and/or modify
Packit b27855
   it under the terms of the GNU General Public License as published by
Packit b27855
   the Free Software Foundation; either version 3 of the License, or
Packit b27855
   (at your option) any later version.
Packit b27855
Packit b27855
   This program is distributed in the hope that it will be useful,
Packit b27855
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit b27855
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit b27855
   GNU General Public License for more details.
Packit b27855
Packit b27855
   You should have received a copy of the GNU General Public License
Packit b27855
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
Packit b27855
Packit b27855
#ifndef output_h
Packit b27855
#define output_h 1
Packit b27855
Packit b27855
#include "keyword-list.h"
Packit b27855
#include "positions.h"
Packit b27855
Packit b27855
/* OSF/1 cxx needs these forward declarations. */
Packit b27855
struct Output_Constants;
Packit b27855
struct Output_Compare;
Packit b27855
Packit b27855
class Output
Packit b27855
{
Packit b27855
public:
Packit b27855
  /* Constructor.  */
Packit b27855
                        Output (KeywordExt_List *head,
Packit b27855
                                const char *struct_decl,
Packit b27855
                                unsigned int struct_decl_lineno,
Packit b27855
                                const char *return_type,
Packit b27855
                                const char *struct_tag,
Packit b27855
                                const char *verbatim_declarations,
Packit b27855
                                const char *verbatim_declarations_end,
Packit b27855
                                unsigned int verbatim_declarations_lineno,
Packit b27855
                                const char *verbatim_code,
Packit b27855
                                const char *verbatim_code_end,
Packit b27855
                                unsigned int verbatim_code_lineno,
Packit b27855
                                bool charset_dependent,
Packit b27855
                                int total_keys,
Packit b27855
                                int max_key_len, int min_key_len,
Packit b27855
                                bool hash_includes_len,
Packit b27855
                                const Positions& positions,
Packit b27855
                                const unsigned int *alpha_inc,
Packit b27855
                                int total_duplicates,
Packit b27855
                                unsigned int alpha_size,
Packit b27855
                                const int *asso_values);
Packit b27855
Packit b27855
  /* Generates the hash function and the key word recognizer function.  */
Packit b27855
  void                  output ();
Packit b27855
Packit b27855
private:
Packit b27855
Packit b27855
  /* Computes the minimum and maximum hash values, and stores them
Packit b27855
     in _min_hash_value and _max_hash_value.  */
Packit b27855
  void                  compute_min_max ();
Packit b27855
Packit b27855
  /* Returns the number of different hash values.  */
Packit b27855
  int                   num_hash_values () const;
Packit b27855
Packit b27855
  /* Outputs the maximum and minimum hash values etc.  */
Packit b27855
  void                  output_constants (struct Output_Constants&) const;
Packit b27855
Packit b27855
  /* Generates a C expression for an asso_values[] index.  */
Packit b27855
  void                  output_asso_values_index (int pos) const;
Packit b27855
Packit b27855
  /* Generates a C expression for an asso_values[] reference.  */
Packit b27855
  void                  output_asso_values_ref (int pos) const;
Packit b27855
Packit b27855
  /* Generates C code for the hash function that returns the
Packit b27855
     proper encoding for each keyword.  */
Packit b27855
  void                  output_hash_function () const;
Packit b27855
Packit b27855
  /* Prints out a table of keyword lengths, for use with the
Packit b27855
     comparison code in generated function 'in_word_set'.  */
Packit b27855
  void                  output_keylength_table () const;
Packit b27855
Packit b27855
  /* Prints out the string pool, containing the strings of the keyword table.
Packit b27855
   */
Packit b27855
  void                  output_string_pool () const;
Packit b27855
Packit b27855
  /* Prints out the array containing the keywords for the hash function.  */
Packit b27855
  void                  output_keyword_table () const;
Packit b27855
Packit b27855
  /* Generates the large, sparse table that maps hash values into
Packit b27855
     the smaller, contiguous range of the keyword table.  */
Packit b27855
  void                  output_lookup_array () const;
Packit b27855
Packit b27855
  /* Generate all pools needed for the lookup function.  */
Packit b27855
  void                  output_lookup_pools () const;
Packit b27855
Packit b27855
  /* Generate all the tables needed for the lookup function.  */
Packit b27855
  void                  output_lookup_tables () const;
Packit b27855
Packit b27855
  /* Generates C code to perform the keyword lookup.  */
Packit b27855
  void                  output_lookup_function_body (const struct Output_Compare&) const;
Packit b27855
Packit b27855
  /* Generates C code for the lookup function.  */
Packit b27855
  void                  output_lookup_function () const;
Packit b27855
Packit b27855
  /* Linked list of keywords.  */
Packit b27855
  KeywordExt_List *     _head;
Packit b27855
Packit b27855
  /* Declaration of struct type for a keyword and its attributes.  */
Packit b27855
  const char * const    _struct_decl;
Packit b27855
  unsigned int const    _struct_decl_lineno;
Packit b27855
  /* Pointer to return type for lookup function. */
Packit b27855
  const char *          _return_type;
Packit b27855
  /* Shorthand for user-defined struct tag type. */
Packit b27855
  const char *          _struct_tag;
Packit b27855
  /* Element type of keyword array.  */
Packit b27855
  const char *          _wordlist_eltype;
Packit b27855
  /* The C code from the declarations section.  */
Packit b27855
  const char * const    _verbatim_declarations;
Packit b27855
  const char * const    _verbatim_declarations_end;
Packit b27855
  unsigned int const    _verbatim_declarations_lineno;
Packit b27855
  /* The C code from the end of the file.  */
Packit b27855
  const char * const    _verbatim_code;
Packit b27855
  const char * const    _verbatim_code_end;
Packit b27855
  unsigned int const    _verbatim_code_lineno;
Packit b27855
  /* Whether the keyword chars would have different values in a different
Packit b27855
     character set.  */
Packit b27855
  bool                  _charset_dependent;
Packit b27855
  /* Total number of keys, counting duplicates. */
Packit b27855
  int const             _total_keys;
Packit b27855
  /* Maximum length of the longest keyword. */
Packit b27855
  int const             _max_key_len;
Packit b27855
  /* Minimum length of the shortest keyword. */
Packit b27855
  int const             _min_key_len;
Packit b27855
  /* Whether the hash function includes the length.  */
Packit b27855
  bool                  _hash_includes_len;
Packit b27855
  /* Key positions.  */
Packit b27855
  Positions const       _key_positions;
Packit b27855
  /* Adjustments to add to bytes add specific key positions.  */
Packit b27855
  const unsigned int * const _alpha_inc;
Packit b27855
  /* Total number of duplicate hash values. */
Packit b27855
  int const             _total_duplicates;
Packit b27855
  /* Minimum hash value for all keywords. */
Packit b27855
  int                   _min_hash_value;
Packit b27855
  /* Maximum hash value for all keywords. */
Packit b27855
  int                   _max_hash_value;
Packit b27855
  /* Size of alphabet. */
Packit b27855
  unsigned int const    _alpha_size;
Packit b27855
  /* Value associated with each character. */
Packit b27855
  const int * const     _asso_values;
Packit b27855
};
Packit b27855
Packit b27855
#endif