]>
Commit | Line | Data |
---|---|---|
87aabbff | 1 | /* System-dependent definitions for Bison. |
45aa0550 | 2 | |
34136e65 | 3 | Copyright (C) 2000-2007, 2009-2012 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 JT |
18 | #ifndef BISON_SYSTEM_H |
19 | #define BISON_SYSTEM_H | |
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>. */ | |
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 | ||
6e26ca8c | 37 | #include <limits.h> |
deedb0b7 | 38 | #include <stddef.h> |
6e26ca8c PE |
39 | #include <stdlib.h> |
40 | #include <string.h> | |
ceed8467 | 41 | |
b6403170 | 42 | #define ARRAY_CARDINALITY(Array) (sizeof (Array) / sizeof *(Array)) |
f518dbaf AD |
43 | #define STREQ(L, R) (strcmp(L, R) == 0) |
44 | #define STRNEQ(L, R) (!STREQ(L, R)) | |
45 | ||
4663cb4d AD |
46 | /* Just like strncmp, but the second argument must be a literal string |
47 | and you don't specify the length. */ | |
48 | #define STRNCMP_LIT(S, Literal) \ | |
49 | strncmp (S, "" Literal "", sizeof (Literal) - 1) | |
50 | ||
51 | /* Whether Literal is a prefix of S. */ | |
52 | #define STRPREFIX_LIT(Literal, S) \ | |
53 | (STRNCMP_LIT (S, Literal) == 0) | |
54 | ||
27b0ffea AD |
55 | #if HAVE_SYS_TYPES_H |
56 | # include <sys/types.h> | |
57 | #endif | |
58 | ||
3b2942e6 PE |
59 | #include <unistd.h> |
60 | #include <inttypes.h> | |
cb48f191 PE |
61 | |
62 | #ifndef UINTPTR_MAX | |
deedb0b7 PE |
63 | /* This isn't perfect, but it's good enough for Bison, which needs |
64 | only to hash pointers. */ | |
65 | typedef size_t uintptr_t; | |
66 | #endif | |
67 | ||
459a57a9 AD |
68 | // Version mismatch. |
69 | #define EX_MISMATCH 63 | |
a4b36db4 | 70 | |
cb48f191 PE |
71 | /*---------. |
72 | | Gnulib. | | |
73 | `---------*/ | |
b77b9ee0 | 74 | |
cb48f191 PE |
75 | #include <unlocked-io.h> |
76 | #include <verify.h> | |
77 | #include <xalloc.h> | |
7625ec2c | 78 | |
b77b9ee0 | 79 | |
a0f6b076 AD |
80 | /*-----------------. |
81 | | GCC extensions. | | |
82 | `-----------------*/ | |
83 | ||
84f6a6ca JD |
84 | /* Use PACIFY_CC to indicate that Code is unimportant to the logic of Bison |
85 | but that it is necessary for suppressing compiler warnings. For example, | |
86 | Code might be a variable initializer that's always overwritten before the | |
87 | variable is used. | |
88 | ||
89 | PACIFY_CC is intended to be useful only as a comment as it does not alter | |
90 | Code. It is tempting to redefine PACIFY_CC so that it will suppress Code | |
91 | when configuring without --enable-gcc-warnings. However, that would mean | |
92 | that, for maintainers, Bison would compile with potentially less warnings | |
93 | and safer logic than it would for users. Due to the overhead of M4, | |
94 | suppressing Code is unlikely to offer any significant improvement in | |
95 | Bison's performance anyway. */ | |
96 | #define PACIFY_CC(Code) Code | |
48e28efa | 97 | |
a0f6b076 AD |
98 | #ifndef __attribute__ |
99 | /* This feature is available in gcc versions 2.5 and later. */ | |
02650b7f | 100 | # if (! defined __GNUC__ || __GNUC__ < 2 \ |
ef51bfa7 | 101 | || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)) |
a0f6b076 AD |
102 | # define __attribute__(Spec) /* empty */ |
103 | # endif | |
e9955c83 AD |
104 | #endif |
105 | ||
a0f6b076 AD |
106 | /* The __-protected variants of `format' and `printf' attributes |
107 | are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */ | |
e9955c83 AD |
108 | #if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) |
109 | # define __format__ format | |
110 | # define __printf__ printf | |
a0f6b076 AD |
111 | #endif |
112 | ||
e9955c83 AD |
113 | #ifndef ATTRIBUTE_NORETURN |
114 | # define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__)) | |
115 | #endif | |
116 | ||
117 | #ifndef ATTRIBUTE_UNUSED | |
118 | # define ATTRIBUTE_UNUSED __attribute__ ((__unused__)) | |
119 | #endif | |
a0f6b076 | 120 | |
e9071366 AD |
121 | #define FUNCTION_PRINT() fprintf (stderr, "%s: ", __func__) |
122 | ||
a0f6b076 AD |
123 | /*------. |
124 | | NLS. | | |
125 | `------*/ | |
126 | ||
6e26ca8c | 127 | #include <locale.h> |
f2d78a99 | 128 | |
982cc302 | 129 | #include <gettext.h> |
e0327bc8 AD |
130 | #define _(Msgid) gettext (Msgid) |
131 | #define N_(Msgid) (Msgid) | |
f2d78a99 | 132 | |
a0f6b076 | 133 | |
015acc48 AD |
134 | /*-----------. |
135 | | Booleans. | | |
136 | `-----------*/ | |
137 | ||
f61aad93 | 138 | #include <stdbool.h> |
8c7ebe49 AD |
139 | |
140 | ||
4f82b42a PE |
141 | |
142 | /*-------------. | |
143 | | Assertions. | | |
144 | `-------------*/ | |
145 | ||
ca01f454 JD |
146 | /* In the past, Bison defined aver to simply invoke abort in the case of |
147 | a failed assertion. The rationale was that <assert.h>'s assertions | |
148 | were too heavyweight and could be disabled too easily. See | |
149 | discussions at | |
9789acf0 JD |
150 | <http://lists.gnu.org/archive/html/bison-patches/2006-01/msg00080.html> |
151 | <http://lists.gnu.org/archive/html/bison-patches/2006-09/msg00111.html>. | |
ca01f454 JD |
152 | |
153 | However, normal assert output can be helpful during development and | |
154 | in bug reports from users. Moreover, it's not clear now that | |
155 | <assert.h>'s assertions are significantly heavyweight. Finally, if | |
156 | users want to experiment with disabling assertions, it's debatable | |
157 | whether it's our responsibility to stop them. See discussion | |
158 | starting at | |
159 | <http://lists.gnu.org/archive/html/bison-patches/2009-09/msg00013.html>. | |
160 | ||
161 | For now, we use assert but we call it aver throughout Bison in case | |
162 | we later wish to try another scheme. | |
9789acf0 | 163 | */ |
ca01f454 JD |
164 | #include <assert.h> |
165 | #define aver assert | |
4f82b42a PE |
166 | |
167 | ||
8c7ebe49 AD |
168 | /*-----------. |
169 | | Obstacks. | | |
170 | `-----------*/ | |
171 | ||
04098407 PE |
172 | #define obstack_chunk_alloc xmalloc |
173 | #define obstack_chunk_free free | |
174 | #include <obstack.h> | |
8c7ebe49 | 175 | |
ff4423cc AD |
176 | #define obstack_sgrow(Obs, Str) \ |
177 | obstack_grow (Obs, Str, strlen (Str)) | |
8c7ebe49 | 178 | |
13b712d7 AD |
179 | /* Output Str escaped for our postprocessing (i.e., escape M4 special |
180 | characters). | |
181 | ||
182 | For instance "[foo]" -> "@{foo@}", "$$" -> "$][$][". */ | |
183 | ||
184 | # define obstack_escape(Obs, Str) \ | |
185 | do { \ | |
4323e0da AD |
186 | char const *p__; \ |
187 | for (p__ = Str; *p__; p__++) \ | |
188 | switch (*p__) \ | |
13b712d7 AD |
189 | { \ |
190 | case '$': obstack_sgrow (Obs, "$]["); break; \ | |
191 | case '@': obstack_sgrow (Obs, "@@" ); break; \ | |
192 | case '[': obstack_sgrow (Obs, "@{" ); break; \ | |
193 | case ']': obstack_sgrow (Obs, "@}" ); break; \ | |
4323e0da | 194 | default: obstack_1grow (Obs, *p__ ); break; \ |
13b712d7 AD |
195 | } \ |
196 | } while (0) | |
197 | ||
198 | ||
0601c3bf AD |
199 | /* Output Str both quoted for M4 (i.e., embed in [[...]]), and escaped |
200 | for our postprocessing (i.e., escape M4 special characters). If | |
201 | Str is empty (or NULL), output "[]" instead of "[[]]" as it make M4 | |
202 | programming easier (m4_ifval can be used). | |
203 | ||
204 | For instance "[foo]" -> "[[@{foo@}]]", "$$" -> "[[$][$][]]". */ | |
205 | ||
206 | # define obstack_quote(Obs, Str) \ | |
207 | do { \ | |
208 | char const* obstack_quote_p = Str; \ | |
209 | if (obstack_quote_p && obstack_quote_p[0]) \ | |
210 | { \ | |
211 | obstack_sgrow (Obs, "[["); \ | |
212 | obstack_escape (Obs, obstack_quote_p); \ | |
213 | obstack_sgrow (Obs, "]]"); \ | |
214 | } \ | |
215 | else \ | |
216 | obstack_sgrow (Obs, "[]"); \ | |
217 | } while (0) | |
218 | ||
219 | ||
ff4423cc | 220 | |
7de3329e | 221 | |
7de3329e | 222 | |
381fb12e AD |
223 | /*-----------------------------------------. |
224 | | Extensions to use for the output files. | | |
225 | `-----------------------------------------*/ | |
7de3329e | 226 | |
deb63d81 PE |
227 | #ifndef OUTPUT_EXT |
228 | # define OUTPUT_EXT ".output" | |
229 | #endif | |
230 | ||
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 | ||
e9690142 JD |
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 | } \ | |
300f275f AD |
249 | } while (0) |
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 */ |