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