uniqstr.h 2.2 KB

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