]>
Commit | Line | Data |
---|---|---|
87aabbff | 1 | /* System-dependent definitions for Bison. |
45aa0550 | 2 | |
3209eb1c | 3 | Copyright (C) 2000-2007, 2009-2015 Free Software Foundation, Inc. |
a0f6b076 | 4 | |
f16b0819 | 5 | This program is free software: you can redistribute it and/or modify |
a0f6b076 | 6 | it under the terms of the GNU General Public License as published by |
f16b0819 PE |
7 | the Free Software Foundation, either version 3 of the License, or |
8 | (at your option) any later version. | |
a0f6b076 AD |
9 | |
10 | This program is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | GNU General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU General Public License | |
f16b0819 | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
a0f6b076 | 17 | |
d968a24b | 18 | #ifndef BISON_SYSTEM_H |
a99ec53e | 19 | # define BISON_SYSTEM_H |
d968a24b | 20 | |
c21493b8 PE |
21 | /* flex 2.5.31 gratutiously defines macros like INT8_MIN. But this |
22 | runs afoul of pre-C99 compilers that have <inttypes.h> or | |
23 | <stdint.h>, which are included below if available. It also runs | |
24 | afoul of pre-C99 compilers that define these macros in <limits.h>. */ | |
a99ec53e AD |
25 | # if ! defined __STDC_VERSION__ || __STDC_VERSION__ < 199901 |
26 | # undef INT8_MIN | |
27 | # undef INT16_MIN | |
28 | # undef INT32_MIN | |
29 | # undef INT8_MAX | |
30 | # undef INT16_MAX | |
31 | # undef UINT8_MAX | |
32 | # undef INT32_MAX | |
33 | # undef UINT16_MAX | |
34 | # undef UINT32_MAX | |
35 | # endif | |
36 | ||
37 | # include <limits.h> | |
38 | # include <stddef.h> | |
39 | # include <stdlib.h> | |
40 | # include <string.h> | |
41 | ||
42 | # define ARRAY_CARDINALITY(Array) (sizeof (Array) / sizeof *(Array)) | |
43 | # define STREQ(L, R) (strcmp(L, R) == 0) | |
44 | # define STRNEQ(L, R) (!STREQ(L, R)) | |
f518dbaf | 45 | |
4663cb4d AD |
46 | /* Just like strncmp, but the second argument must be a literal string |
47 | and you don't specify the length. */ | |
a99ec53e | 48 | # define STRNCMP_LIT(S, Literal) \ |
4663cb4d AD |
49 | strncmp (S, "" Literal "", sizeof (Literal) - 1) |
50 | ||
51 | /* Whether Literal is a prefix of S. */ | |
a99ec53e | 52 | # define STRPREFIX_LIT(Literal, S) \ |
4663cb4d AD |
53 | (STRNCMP_LIT (S, Literal) == 0) |
54 | ||
a99ec53e AD |
55 | # include <unistd.h> |
56 | # include <inttypes.h> | |
cb48f191 | 57 | |
a99ec53e | 58 | # ifndef UINTPTR_MAX |
deedb0b7 PE |
59 | /* This isn't perfect, but it's good enough for Bison, which needs |
60 | only to hash pointers. */ | |
61 | typedef size_t uintptr_t; | |
a99ec53e | 62 | # endif |
deedb0b7 | 63 | |
1127a75a | 64 | /* Version mismatch. */ |
a99ec53e | 65 | # define EX_MISMATCH 63 |
a4b36db4 | 66 | |
cb48f191 PE |
67 | /*---------. |
68 | | Gnulib. | | |
69 | `---------*/ | |
b77b9ee0 | 70 | |
a99ec53e AD |
71 | # include <unlocked-io.h> |
72 | # include <verify.h> | |
73 | # include <xalloc.h> | |
7625ec2c | 74 | |
b77b9ee0 | 75 | |
a0f6b076 AD |
76 | /*-----------------. |
77 | | GCC extensions. | | |
78 | `-----------------*/ | |
79 | ||
84f6a6ca JD |
80 | /* Use PACIFY_CC to indicate that Code is unimportant to the logic of Bison |
81 | but that it is necessary for suppressing compiler warnings. For example, | |
82 | Code might be a variable initializer that's always overwritten before the | |
83 | variable is used. | |
84 | ||
85 | PACIFY_CC is intended to be useful only as a comment as it does not alter | |
86 | Code. It is tempting to redefine PACIFY_CC so that it will suppress Code | |
87 | when configuring without --enable-gcc-warnings. However, that would mean | |
88 | that, for maintainers, Bison would compile with potentially less warnings | |
89 | and safer logic than it would for users. Due to the overhead of M4, | |
90 | suppressing Code is unlikely to offer any significant improvement in | |
91 | Bison's performance anyway. */ | |
a99ec53e | 92 | # define PACIFY_CC(Code) Code |
48e28efa | 93 | |
a99ec53e | 94 | # ifndef __attribute__ |
a0f6b076 | 95 | /* This feature is available in gcc versions 2.5 and later. */ |
a99ec53e | 96 | # if (! defined __GNUC__ || __GNUC__ < 2 \ |
ef51bfa7 | 97 | || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)) |
a99ec53e AD |
98 | # define __attribute__(Spec) /* empty */ |
99 | # endif | |
a0f6b076 | 100 | # endif |
e9955c83 | 101 | |
45eebca4 | 102 | /* The __-protected variants of 'format' and 'printf' attributes |
a0f6b076 | 103 | are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */ |
a99ec53e AD |
104 | # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) |
105 | # define __format__ format | |
106 | # define __printf__ printf | |
107 | # endif | |
a0f6b076 | 108 | |
a99ec53e AD |
109 | # ifndef ATTRIBUTE_NORETURN |
110 | # define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__)) | |
111 | # endif | |
e9955c83 | 112 | |
a99ec53e AD |
113 | # ifndef ATTRIBUTE_UNUSED |
114 | # define ATTRIBUTE_UNUSED __attribute__ ((__unused__)) | |
115 | # endif | |
a0f6b076 | 116 | |
e9071366 | 117 | |
a0f6b076 AD |
118 | /*------. |
119 | | NLS. | | |
120 | `------*/ | |
121 | ||
a99ec53e | 122 | # include <locale.h> |
f2d78a99 | 123 | |
a99ec53e AD |
124 | # include <gettext.h> |
125 | # define _(Msgid) gettext (Msgid) | |
126 | # define N_(Msgid) (Msgid) | |
f2d78a99 | 127 | |
a0f6b076 | 128 | |
015acc48 AD |
129 | /*-----------. |
130 | | Booleans. | | |
131 | `-----------*/ | |
132 | ||
a99ec53e | 133 | # include <stdbool.h> |
8c7ebe49 AD |
134 | |
135 | ||
4f82b42a PE |
136 | |
137 | /*-------------. | |
138 | | Assertions. | | |
139 | `-------------*/ | |
140 | ||
ca01f454 JD |
141 | /* In the past, Bison defined aver to simply invoke abort in the case of |
142 | a failed assertion. The rationale was that <assert.h>'s assertions | |
143 | were too heavyweight and could be disabled too easily. See | |
144 | discussions at | |
9789acf0 JD |
145 | <http://lists.gnu.org/archive/html/bison-patches/2006-01/msg00080.html> |
146 | <http://lists.gnu.org/archive/html/bison-patches/2006-09/msg00111.html>. | |
ca01f454 JD |
147 | |
148 | However, normal assert output can be helpful during development and | |
149 | in bug reports from users. Moreover, it's not clear now that | |
150 | <assert.h>'s assertions are significantly heavyweight. Finally, if | |
151 | users want to experiment with disabling assertions, it's debatable | |
152 | whether it's our responsibility to stop them. See discussion | |
153 | starting at | |
154 | <http://lists.gnu.org/archive/html/bison-patches/2009-09/msg00013.html>. | |
155 | ||
156 | For now, we use assert but we call it aver throughout Bison in case | |
157 | we later wish to try another scheme. | |
9789acf0 | 158 | */ |
a99ec53e AD |
159 | # include <assert.h> |
160 | # define aver assert | |
4f82b42a PE |
161 | |
162 | ||
8c7ebe49 AD |
163 | /*-----------. |
164 | | Obstacks. | | |
165 | `-----------*/ | |
166 | ||
a99ec53e AD |
167 | # define obstack_chunk_alloc xmalloc |
168 | # define obstack_chunk_free free | |
169 | # include <obstack.h> | |
8c7ebe49 | 170 | |
6fbe73b6 AD |
171 | /* String-grow: append Str to Obs. */ |
172 | ||
a99ec53e | 173 | # define obstack_sgrow(Obs, Str) \ |
ff4423cc | 174 | obstack_grow (Obs, Str, strlen (Str)) |
8c7ebe49 | 175 | |
13b712d7 AD |
176 | /* Output Str escaped for our postprocessing (i.e., escape M4 special |
177 | characters). | |
178 | ||
179 | For instance "[foo]" -> "@{foo@}", "$$" -> "$][$][". */ | |
180 | ||
181 | # define obstack_escape(Obs, Str) \ | |
182 | do { \ | |
4323e0da AD |
183 | char const *p__; \ |
184 | for (p__ = Str; *p__; p__++) \ | |
185 | switch (*p__) \ | |
13b712d7 AD |
186 | { \ |
187 | case '$': obstack_sgrow (Obs, "$]["); break; \ | |
188 | case '@': obstack_sgrow (Obs, "@@" ); break; \ | |
189 | case '[': obstack_sgrow (Obs, "@{" ); break; \ | |
190 | case ']': obstack_sgrow (Obs, "@}" ); break; \ | |
4323e0da | 191 | default: obstack_1grow (Obs, *p__ ); break; \ |
13b712d7 AD |
192 | } \ |
193 | } while (0) | |
194 | ||
195 | ||
0601c3bf AD |
196 | /* Output Str both quoted for M4 (i.e., embed in [[...]]), and escaped |
197 | for our postprocessing (i.e., escape M4 special characters). If | |
198 | Str is empty (or NULL), output "[]" instead of "[[]]" as it make M4 | |
199 | programming easier (m4_ifval can be used). | |
200 | ||
201 | For instance "[foo]" -> "[[@{foo@}]]", "$$" -> "[[$][$][]]". */ | |
202 | ||
203 | # define obstack_quote(Obs, Str) \ | |
204 | do { \ | |
205 | char const* obstack_quote_p = Str; \ | |
206 | if (obstack_quote_p && obstack_quote_p[0]) \ | |
207 | { \ | |
208 | obstack_sgrow (Obs, "[["); \ | |
209 | obstack_escape (Obs, obstack_quote_p); \ | |
210 | obstack_sgrow (Obs, "]]"); \ | |
211 | } \ | |
212 | else \ | |
213 | obstack_sgrow (Obs, "[]"); \ | |
214 | } while (0) | |
215 | ||
216 | ||
6fbe73b6 AD |
217 | /* Append the ending 0, finish Obs, and return the string. */ |
218 | ||
a99ec53e | 219 | # define obstack_finish0(Obs) \ |
6fbe73b6 AD |
220 | (obstack_1grow (Obs, '\0'), (char *) obstack_finish (Obs)) |
221 | ||
ff4423cc | 222 | |
381fb12e AD |
223 | /*-----------------------------------------. |
224 | | Extensions to use for the output files. | | |
225 | `-----------------------------------------*/ | |
7de3329e | 226 | |
a99ec53e AD |
227 | # ifndef OUTPUT_EXT |
228 | # define OUTPUT_EXT ".output" | |
229 | # endif | |
deb63d81 | 230 | |
a99ec53e AD |
231 | # ifndef TAB_EXT |
232 | # define TAB_EXT ".tab" | |
233 | # endif | |
55b96341 | 234 | |
381fb12e AD |
235 | |
236 | ||
381fb12e AD |
237 | /*---------------------. |
238 | | Free a linked list. | | |
239 | `---------------------*/ | |
240 | ||
a99ec53e AD |
241 | # define LIST_FREE(Type, List) \ |
242 | do { \ | |
243 | Type *_node, *_next; \ | |
244 | for (_node = List; _node; _node = _next) \ | |
245 | { \ | |
246 | _next = _node->next; \ | |
247 | free (_node); \ | |
248 | } \ | |
249 | } while (0) | |
300f275f | 250 | |
381fb12e AD |
251 | |
252 | /*---------------------------------------------. | |
253 | | Debugging memory allocation (must be last). | | |
254 | `---------------------------------------------*/ | |
342b8b6e AD |
255 | |
256 | # if WITH_DMALLOC | |
257 | # define DMALLOC_FUNC_CHECK | |
258 | # include <dmalloc.h> | |
259 | # endif /* WITH_DMALLOC */ | |
260 | ||
a4b36db4 | 261 | #endif /* ! BISON_SYSTEM_H */ |