1/* This may look like C code, but it is really -*- C++ -*- */ 2 3/* Keyword data. 4 5 Copyright (C) 1989-1998, 2000, 2002 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 keyword_h 25#define keyword_h 1 26 27/* Class defined in "positions.h". */ 28class Positions; 29 30/* An instance of this class is a keyword, as specified in the input file. */ 31 32struct Keyword 33{ 34 /* Constructor. */ 35 Keyword (const char *allchars, int allchars_length, 36 const char *rest); 37 38 /* Data members defined immediately by the input file. */ 39 /* The keyword as a string, possibly containing NUL bytes. */ 40 const char *const _allchars; 41 int const _allchars_length; 42 /* Additional stuff seen on the same line of the input file. */ 43 const char *const _rest; 44 /* Line number of this keyword in the input file. */ 45 unsigned int _lineno; 46}; 47 48/* A keyword, in the context of a given keyposition list. */ 49 50struct KeywordExt : public Keyword 51{ 52 /* Constructor. */ 53 KeywordExt (const char *allchars, int allchars_length, 54 const char *rest); 55 56 /* Data members depending on the keyposition list. */ 57 /* The selected characters that participate for the hash function, 58 selected according to the keyposition list, as a canonically reordered 59 multiset. */ 60 const unsigned int * _selchars; 61 int _selchars_length; 62 /* Chained list of keywords having the same _selchars and 63 - if !option[NOLENGTH] - also the same _allchars_length. 64 Note that these duplicates are not members of the main keyword list. */ 65 KeywordExt * _duplicate_link; 66 67 /* Methods depending on the keyposition list. */ 68 /* Initializes selchars and selchars_length, without reordering. */ 69 void init_selchars_tuple (const Positions& positions, const unsigned int *alpha_unify); 70 /* Initializes selchars and selchars_length, with reordering. */ 71 void init_selchars_multiset (const Positions& positions, const unsigned int *alpha_unify, const unsigned int *alpha_inc); 72 /* Deletes selchars. */ 73 void delete_selchars (); 74 75 /* Data members used by the algorithm. */ 76 int _hash_value; /* Hash value for the keyword. */ 77 78 /* Data members used by the output routines. */ 79 int _final_index; 80 81private: 82 unsigned int * init_selchars_low (const Positions& positions, const unsigned int *alpha_unify, const unsigned int *alpha_inc); 83}; 84 85/* An abstract factory for creating Keyword instances. 86 This factory is used to make the Input class independent of the concrete 87 class KeywordExt. */ 88 89class Keyword_Factory 90{ 91public: 92 /* Constructor. */ 93 Keyword_Factory (); 94 /* Destructor. */ 95 virtual ~Keyword_Factory (); 96 97 /* Creates a new Keyword. */ 98 virtual /*abstract*/ Keyword * 99 create_keyword (const char *allchars, int allchars_length, 100 const char *rest) = 0; 101}; 102 103/* A statically allocated empty string. */ 104extern char empty_string[1]; 105 106#ifdef __OPTIMIZE__ 107 108#define INLINE inline 109#include "keyword.icc" 110#undef INLINE 111 112#endif 113 114#endif 115