(root)/
bison-3.8.2/
src/
uniqstr.h
       1  /* Keeping a unique copy of strings.
       2  
       3     Copyright (C) 2002-2003, 2008-2015, 2018-2021 Free Software
       4     Foundation, Inc.
       5  
       6     This file is part of Bison, the GNU Compiler Compiler.
       7  
       8     This program is free software: you can redistribute it and/or modify
       9     it under the terms of the GNU General Public License as published by
      10     the Free Software Foundation, either version 3 of the License, or
      11     (at your option) any later version.
      12  
      13     This program is distributed in the hope that it will be useful,
      14     but WITHOUT ANY WARRANTY; without even the implied warranty of
      15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      16     GNU General Public License for more details.
      17  
      18     You should have received a copy of the GNU General Public License
      19     along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
      20  
      21  #ifndef UNIQSTR_H_
      22  # define UNIQSTR_H_
      23  
      24  # include <stdio.h>
      25  
      26  /*-----------------------------------------.
      27  | Pointers to unique copies of C strings.  |
      28  `-----------------------------------------*/
      29  
      30  typedef char const *uniqstr;
      31  
      32  /* Return the uniqstr for STR.  */
      33  uniqstr uniqstr_new (char const *str);
      34  
      35  /* Two uniqstr values have the same value iff they are the same.  */
      36  # define UNIQSTR_EQ(Ustr1, Ustr2) (!!((Ustr1) == (Ustr2)))
      37  
      38  /* Compare two uniqstr a la strcmp: negative for <, nul for =, and
      39     positive for >.  Undefined order, relies on addresses.  */
      40  int uniqstr_cmp (uniqstr u1, uniqstr u2);
      41  
      42  /* Die if STR is not a uniqstr.  */
      43  void uniqstr_assert (char const *str);
      44  
      45  /*----------------.
      46  | Concatenation.  |
      47  `----------------*/
      48  
      49  /* Concatenate strings and return a uniqstr.  The goal of
      50     this macro is to make the caller's code a little more succinct.  */
      51  # define UNIQSTR_CONCAT(...)                                            \
      52    uniqstr_concat (ARRAY_CARDINALITY (((char const *[]) {__VA_ARGS__})), \
      53                    __VA_ARGS__)
      54  uniqstr uniqstr_concat (int nargs, ...);
      55  
      56  /*--------------------.
      57  | Table of uniqstrs.  |
      58  `--------------------*/
      59  
      60  /* Create the string table.  */
      61  void uniqstrs_new (void);
      62  
      63  /* Free all the memory allocated for symbols.  */
      64  void uniqstrs_free (void);
      65  
      66  /* Report them all.  */
      67  void uniqstrs_print (void);
      68  
      69  #endif /* ! defined UNIQSTR_H_ */