]>
Commit | Line | Data |
---|---|---|
5bab03fc | 1 | /* Keeping a unique copy of strings. |
a737b216 | 2 | |
6e30ede8 PE |
3 | Copyright (C) 2002, 2003, 2008, 2009, 2010 Free Software |
4 | Foundation, Inc. | |
5bab03fc PE |
5 | |
6 | This file is part of Bison, the GNU Compiler Compiler. | |
7 | ||
f16b0819 | 8 | This program is free software: you can redistribute it and/or modify |
5bab03fc | 9 | it under the terms of the GNU General Public License as published by |
f16b0819 PE |
10 | the Free Software Foundation, either version 3 of the License, or |
11 | (at your option) any later version. | |
5bab03fc | 12 | |
f16b0819 | 13 | This program is distributed in the hope that it will be useful, |
5bab03fc PE |
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 | |
f16b0819 | 19 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
5bab03fc PE |
20 | |
21 | #ifndef UNIQSTR_H_ | |
22 | # define UNIQSTR_H_ | |
23 | ||
24 | /*-----------------------------------------. | |
25 | | Pointers to unique copies of C strings. | | |
26 | `-----------------------------------------*/ | |
27 | ||
28 | typedef char const *uniqstr; | |
29 | ||
a737b216 PE |
30 | /* Return the uniqstr for STR. */ |
31 | uniqstr uniqstr_new (char const *str); | |
5bab03fc | 32 | |
0ab402b4 JD |
33 | /* Return a uniqstr built by vsprintf. In order to simply concatenate |
34 | strings, use UNIQSTR_CONCAT, which is a convenient wrapper around | |
35 | this function. */ | |
36 | uniqstr uniqstr_vsprintf (char const *format, ...) | |
37 | __attribute__ ((__format__ (__printf__, 1, 2))); | |
38 | ||
a737b216 PE |
39 | /* Two uniqstr values have the same value iff they are the same. */ |
40 | #define UNIQSTR_EQ(USTR1, USTR2) ((USTR1) == (USTR2)) | |
5bab03fc | 41 | |
95d176ff AD |
42 | /* Compare two uniqstr a la strcmp: negative for <, nul for =, and |
43 | positive for >. Undefined order, relies on addresses. */ | |
44 | #define UNIQSTR_CMP(USTR1, USTR2) ((USTR1) - (USTR2)) | |
45 | ||
5bab03fc PE |
46 | /*--------------------------------------. |
47 | | Initializing, destroying, debugging. | | |
48 | `--------------------------------------*/ | |
49 | ||
50 | /* Create the string table. */ | |
51 | void uniqstrs_new (void); | |
52 | ||
a737b216 PE |
53 | /* Die if STR is not a uniqstr. */ |
54 | void uniqstr_assert (char const *str); | |
5bab03fc PE |
55 | |
56 | /* Free all the memory allocated for symbols. */ | |
57 | void uniqstrs_free (void); | |
58 | ||
59 | /* Report them all. */ | |
60 | void uniqstrs_print (void); | |
61 | ||
0ab402b4 JD |
62 | /*----------------. |
63 | | Concatenation. | | |
64 | `----------------*/ | |
65 | ||
66 | /* Concatenate at most 20 strings and return a uniqstr. The goal of | |
67 | this macro is to make the caller's code a little more succinct | |
68 | without a trivial uniqstr_vsprintf format string to maintain | |
69 | (for example, "%s%s%s") while still benefitting from gcc's type | |
70 | checking. Unfortunately, because of the missing format string in the | |
71 | macro invocation, the argument number reported by gcc for a bad | |
72 | argument type is 1 too large. */ | |
73 | #define UNIQSTR_CONCAT(...) \ | |
74 | uniqstr_vsprintf (UNIQSTR_GEN_FORMAT (__VA_ARGS__, \ | |
75 | "%s", "%s", "%s", "%s", "%s", \ | |
76 | "%s", "%s", "%s", "%s", "%s", \ | |
77 | "%s", "%s", "%s", "%s", "%s", \ | |
78 | "%s", "%s", "%s", "%s", "%s"), \ | |
79 | __VA_ARGS__) | |
80 | ||
81 | #define UNIQSTR_GEN_FORMAT(F1, F2, F3, F4, F5, \ | |
82 | F6, F7, F8, F9, F10, \ | |
83 | F11, F12, F13, F14, F15, \ | |
84 | F16, F17, F18, F19, F20, \ | |
85 | ...) \ | |
86 | UNIQSTR_GEN_FORMAT_ (__VA_ARGS__, \ | |
87 | "", "", "", "", "", \ | |
88 | "", "", "", "", "", \ | |
89 | "", "", "", "", "", \ | |
90 | "", "", "", "", "") | |
91 | ||
92 | #define UNIQSTR_GEN_FORMAT_(F1, F2, F3, F4, F5, \ | |
93 | F6, F7, F8, F9, F10, \ | |
94 | F11, F12, F13, F14, F15, \ | |
95 | F16, F17, F18, F19, F20, ...) \ | |
96 | F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 \ | |
97 | F11 F12 F13 F14 F15 F16 F17 F18 F19 F20 | |
98 | ||
5bab03fc | 99 | #endif /* ! defined UNIQSTR_H_ */ |