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