]> git.saurik.com Git - bison.git/blob - src/system.h
gnulib: update
[bison.git] / src / system.h
1 /* System-dependent definitions for Bison.
2
3 Copyright (C) 2000-2007, 2009-2012 Free Software Foundation, Inc.
4
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
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
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17
18 #ifndef BISON_SYSTEM_H
19 # define BISON_SYSTEM_H
20
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
37 # include <limits.h>
38 # include <stddef.h>
39 # include <stdlib.h>
40 # include <string.h>
41 # include <unistd.h>
42 # include <inttypes.h>
43
44 # ifndef UINTPTR_MAX
45 /* This isn't perfect, but it's good enough for Bison, which needs
46 only to hash pointers. */
47 typedef size_t uintptr_t;
48 # endif
49
50 // Version mismatch.
51 # define EX_MISMATCH 63
52
53 /*---------.
54 | Gnulib. |
55 `---------*/
56
57 # include <unlocked-io.h>
58 # include <verify.h>
59 # include <xalloc.h>
60
61
62 /*-----------------.
63 | GCC extensions. |
64 `-----------------*/
65
66 /* Use PACIFY_CC to indicate that Code is unimportant to the logic of Bison
67 but that it is necessary for suppressing compiler warnings. For example,
68 Code might be a variable initializer that's always overwritten before the
69 variable is used.
70
71 PACIFY_CC is intended to be useful only as a comment as it does not alter
72 Code. It is tempting to redefine PACIFY_CC so that it will suppress Code
73 when configuring without --enable-gcc-warnings. However, that would mean
74 that, for maintainers, Bison would compile with potentially less warnings
75 and safer logic than it would for users. Due to the overhead of M4,
76 suppressing Code is unlikely to offer any significant improvement in
77 Bison's performance anyway. */
78 # define PACIFY_CC(Code) Code
79
80 # ifndef __attribute__
81 /* This feature is available in gcc versions 2.5 and later. */
82 # if (! defined __GNUC__ || __GNUC__ < 2 \
83 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5))
84 # define __attribute__(Spec) /* empty */
85 # endif
86 # endif
87
88 /* The __-protected variants of `format' and `printf' attributes
89 are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
90 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
91 # define __format__ format
92 # define __printf__ printf
93 # endif
94
95 # ifndef ATTRIBUTE_NORETURN
96 # define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
97 # endif
98
99 # ifndef ATTRIBUTE_UNUSED
100 # define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
101 # endif
102
103
104 /*------.
105 | NLS. |
106 `------*/
107
108 # include <locale.h>
109
110 # include <gettext.h>
111 # define _(Msgid) gettext (Msgid)
112 # define N_(Msgid) (Msgid)
113
114
115 /*-----------.
116 | Booleans. |
117 `-----------*/
118
119 # include <stdbool.h>
120
121
122
123 /*-------------.
124 | Assertions. |
125 `-------------*/
126
127 /* In the past, Bison defined aver to simply invoke abort in the case of
128 a failed assertion. The rationale was that <assert.h>'s assertions
129 were too heavyweight and could be disabled too easily. See
130 discussions at
131 <http://lists.gnu.org/archive/html/bison-patches/2006-01/msg00080.html>
132 <http://lists.gnu.org/archive/html/bison-patches/2006-09/msg00111.html>.
133
134 However, normal assert output can be helpful during development and
135 in bug reports from users. Moreover, it's not clear now that
136 <assert.h>'s assertions are significantly heavyweight. Finally, if
137 users want to experiment with disabling assertions, it's debatable
138 whether it's our responsibility to stop them. See discussion
139 starting at
140 <http://lists.gnu.org/archive/html/bison-patches/2009-09/msg00013.html>.
141
142 For now, we use assert but we call it aver throughout Bison in case
143 we later wish to try another scheme.
144 */
145 # include <assert.h>
146 # define aver assert
147
148
149 /*-----------.
150 | Obstacks. |
151 `-----------*/
152
153 # define obstack_chunk_alloc xmalloc
154 # define obstack_chunk_free free
155 # include <obstack.h>
156
157 # define obstack_sgrow(Obs, Str) \
158 obstack_grow (Obs, Str, strlen (Str))
159
160 /* Output Str escaped for our postprocessing (i.e., escape M4 special
161 characters).
162
163 For instance "[foo]" -> "@{foo@}", "$$" -> "$][$][". */
164
165 # define obstack_escape(Obs, Str) \
166 do { \
167 char const *p; \
168 for (p = Str; *p; p++) \
169 switch (*p) \
170 { \
171 case '$': obstack_sgrow (Obs, "$]["); break; \
172 case '@': obstack_sgrow (Obs, "@@" ); break; \
173 case '[': obstack_sgrow (Obs, "@{" ); break; \
174 case ']': obstack_sgrow (Obs, "@}" ); break; \
175 default: obstack_1grow (Obs, *p ); break; \
176 } \
177 } while (0)
178
179
180 /* Output Str both quoted for M4 (i.e., embed in [[...]]), and escaped
181 for our postprocessing (i.e., escape M4 special characters). If
182 Str is empty (or NULL), output "[]" instead of "[[]]" as it make M4
183 programming easier (m4_ifval can be used).
184
185 For instance "[foo]" -> "[[@{foo@}]]", "$$" -> "[[$][$][]]". */
186
187 # define obstack_quote(Obs, Str) \
188 do { \
189 char const* obstack_quote_p = Str; \
190 if (obstack_quote_p && obstack_quote_p[0]) \
191 { \
192 obstack_sgrow (Obs, "[["); \
193 obstack_escape (Obs, obstack_quote_p); \
194 obstack_sgrow (Obs, "]]"); \
195 } \
196 else \
197 obstack_sgrow (Obs, "[]"); \
198 } while (0)
199
200
201
202
203
204 /*-----------------------------------------.
205 | Extensions to use for the output files. |
206 `-----------------------------------------*/
207
208 # ifndef OUTPUT_EXT
209 # define OUTPUT_EXT ".output"
210 # endif
211
212 # ifndef TAB_EXT
213 # define TAB_EXT ".tab"
214 # endif
215
216
217
218 /*---------------------.
219 | Free a linked list. |
220 `---------------------*/
221
222 # define LIST_FREE(Type, List) \
223 do { \
224 Type *_node, *_next; \
225 for (_node = List; _node; _node = _next) \
226 { \
227 _next = _node->next; \
228 free (_node); \
229 } \
230 } while (0)
231
232
233 /*---------------------------------------------.
234 | Debugging memory allocation (must be last). |
235 `---------------------------------------------*/
236
237 # if WITH_DMALLOC
238 # define DMALLOC_FUNC_CHECK
239 # include <dmalloc.h>
240 # endif /* WITH_DMALLOC */
241
242 #endif /* ! BISON_SYSTEM_H */