]>
Commit | Line | Data |
---|---|---|
87aabbff | 1 | /* System-dependent definitions for Bison. |
45aa0550 | 2 | |
38609c34 JD |
3 | Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009 |
4 | Free Software Foundation, Inc. | |
a0f6b076 | 5 | |
f16b0819 | 6 | This program is free software: you can redistribute it and/or modify |
a0f6b076 | 7 | it under the terms of the GNU General Public License as published by |
f16b0819 PE |
8 | the Free Software Foundation, either version 3 of the License, or |
9 | (at your option) any later version. | |
a0f6b076 AD |
10 | |
11 | This program is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
f16b0819 | 17 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
a0f6b076 | 18 | |
d968a24b JT |
19 | #ifndef BISON_SYSTEM_H |
20 | #define BISON_SYSTEM_H | |
21 | ||
c21493b8 PE |
22 | /* flex 2.5.31 gratutiously defines macros like INT8_MIN. But this |
23 | runs afoul of pre-C99 compilers that have <inttypes.h> or | |
24 | <stdint.h>, which are included below if available. It also runs | |
25 | afoul of pre-C99 compilers that define these macros in <limits.h>. */ | |
26 | #if ! defined __STDC_VERSION__ || __STDC_VERSION__ < 199901 | |
27 | # undef INT8_MIN | |
28 | # undef INT16_MIN | |
29 | # undef INT32_MIN | |
30 | # undef INT8_MAX | |
31 | # undef INT16_MAX | |
32 | # undef UINT8_MAX | |
33 | # undef INT32_MAX | |
34 | # undef UINT16_MAX | |
35 | # undef UINT32_MAX | |
36 | #endif | |
37 | ||
6e26ca8c | 38 | #include <limits.h> |
deedb0b7 | 39 | #include <stddef.h> |
6e26ca8c PE |
40 | #include <stdlib.h> |
41 | #include <string.h> | |
ceed8467 | 42 | |
27b0ffea AD |
43 | #if HAVE_SYS_TYPES_H |
44 | # include <sys/types.h> | |
45 | #endif | |
46 | ||
3b2942e6 PE |
47 | #include <unistd.h> |
48 | #include <inttypes.h> | |
cb48f191 PE |
49 | |
50 | #ifndef UINTPTR_MAX | |
deedb0b7 PE |
51 | /* This isn't perfect, but it's good enough for Bison, which needs |
52 | only to hash pointers. */ | |
53 | typedef size_t uintptr_t; | |
54 | #endif | |
55 | ||
a4b36db4 | 56 | |
cb48f191 PE |
57 | /*---------. |
58 | | Gnulib. | | |
59 | `---------*/ | |
b77b9ee0 | 60 | |
cb48f191 PE |
61 | #include <unlocked-io.h> |
62 | #include <verify.h> | |
63 | #include <xalloc.h> | |
7625ec2c | 64 | |
b77b9ee0 | 65 | |
a0f6b076 AD |
66 | /*-----------------. |
67 | | GCC extensions. | | |
68 | `-----------------*/ | |
69 | ||
48e28efa PE |
70 | /* Use this to suppress gcc's `...may be used before initialized' |
71 | warnings. */ | |
72 | #ifdef lint | |
73 | # define IF_LINT(Code) Code | |
74 | #else | |
75 | # define IF_LINT(Code) /* empty */ | |
76 | #endif | |
77 | ||
a0f6b076 AD |
78 | #ifndef __attribute__ |
79 | /* This feature is available in gcc versions 2.5 and later. */ | |
02650b7f PE |
80 | # if (! defined __GNUC__ || __GNUC__ < 2 \ |
81 | || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__) | |
a0f6b076 AD |
82 | # define __attribute__(Spec) /* empty */ |
83 | # endif | |
e9955c83 AD |
84 | #endif |
85 | ||
a0f6b076 AD |
86 | /* The __-protected variants of `format' and `printf' attributes |
87 | are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */ | |
e9955c83 AD |
88 | #if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) |
89 | # define __format__ format | |
90 | # define __printf__ printf | |
a0f6b076 AD |
91 | #endif |
92 | ||
e9955c83 AD |
93 | #ifndef ATTRIBUTE_NORETURN |
94 | # define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__)) | |
95 | #endif | |
96 | ||
97 | #ifndef ATTRIBUTE_UNUSED | |
98 | # define ATTRIBUTE_UNUSED __attribute__ ((__unused__)) | |
99 | #endif | |
a0f6b076 | 100 | |
e9071366 AD |
101 | #define FUNCTION_PRINT() fprintf (stderr, "%s: ", __func__) |
102 | ||
a0f6b076 AD |
103 | /*------. |
104 | | NLS. | | |
105 | `------*/ | |
106 | ||
6e26ca8c | 107 | #include <locale.h> |
f2d78a99 | 108 | |
982cc302 | 109 | #include <gettext.h> |
e0327bc8 AD |
110 | #define _(Msgid) gettext (Msgid) |
111 | #define N_(Msgid) (Msgid) | |
f2d78a99 | 112 | |
a0f6b076 | 113 | |
015acc48 AD |
114 | /*-----------. |
115 | | Booleans. | | |
116 | `-----------*/ | |
117 | ||
f61aad93 | 118 | #include <stdbool.h> |
8c7ebe49 AD |
119 | |
120 | ||
4f82b42a PE |
121 | |
122 | /*-------------. | |
123 | | Assertions. | | |
124 | `-------------*/ | |
125 | ||
f1fb412c JD |
126 | /* In the past, Bison defined aver to simply invoke abort in the case of |
127 | a failed assertion. The rationale was that <assert.h>'s assertions | |
128 | were too heavyweight and could be disabled too easily. See | |
129 | discussions at | |
c842365a JD |
130 | <http://lists.gnu.org/archive/html/bison-patches/2006-01/msg00080.html> |
131 | <http://lists.gnu.org/archive/html/bison-patches/2006-09/msg00111.html>. | |
f1fb412c JD |
132 | |
133 | However, normal assert output can be helpful during development and | |
134 | in bug reports from users. Moreover, it's not clear now that | |
135 | <assert.h>'s assertions are significantly heavyweight. Finally, if | |
136 | users want to experiment with disabling assertions, it's debatable | |
137 | whether it's our responsibility to stop them. See discussion | |
138 | starting at | |
139 | <http://lists.gnu.org/archive/html/bison-patches/2009-09/msg00013.html>. | |
140 | ||
141 | For now, we use assert but we call it aver throughout Bison in case | |
142 | we later wish to try another scheme. | |
c842365a | 143 | */ |
f1fb412c JD |
144 | #include <assert.h> |
145 | #define aver assert | |
4f82b42a PE |
146 | |
147 | ||
8c7ebe49 AD |
148 | /*-----------. |
149 | | Obstacks. | | |
150 | `-----------*/ | |
151 | ||
04098407 PE |
152 | #define obstack_chunk_alloc xmalloc |
153 | #define obstack_chunk_free free | |
154 | #include <obstack.h> | |
8c7ebe49 | 155 | |
ff4423cc AD |
156 | #define obstack_sgrow(Obs, Str) \ |
157 | obstack_grow (Obs, Str, strlen (Str)) | |
8c7ebe49 AD |
158 | |
159 | #define obstack_fgrow1(Obs, Format, Arg1) \ | |
160 | do { \ | |
161 | char buf[4096]; \ | |
162 | sprintf (buf, Format, Arg1); \ | |
163 | obstack_grow (Obs, buf, strlen (buf)); \ | |
164 | } while (0) | |
dd60faec AD |
165 | |
166 | #define obstack_fgrow2(Obs, Format, Arg1, Arg2) \ | |
167 | do { \ | |
168 | char buf[4096]; \ | |
169 | sprintf (buf, Format, Arg1, Arg2); \ | |
170 | obstack_grow (Obs, buf, strlen (buf)); \ | |
171 | } while (0) | |
896fe5c1 AD |
172 | |
173 | #define obstack_fgrow3(Obs, Format, Arg1, Arg2, Arg3) \ | |
174 | do { \ | |
175 | char buf[4096]; \ | |
176 | sprintf (buf, Format, Arg1, Arg2, Arg3); \ | |
177 | obstack_grow (Obs, buf, strlen (buf)); \ | |
178 | } while (0) | |
7de3329e | 179 | |
ff4423cc AD |
180 | #define obstack_fgrow4(Obs, Format, Arg1, Arg2, Arg3, Arg4) \ |
181 | do { \ | |
182 | char buf[4096]; \ | |
183 | sprintf (buf, Format, Arg1, Arg2, Arg3, Arg4); \ | |
184 | obstack_grow (Obs, buf, strlen (buf)); \ | |
185 | } while (0) | |
186 | ||
7de3329e | 187 | |
7de3329e | 188 | |
381fb12e AD |
189 | /*-----------------------------------------. |
190 | | Extensions to use for the output files. | | |
191 | `-----------------------------------------*/ | |
7de3329e | 192 | |
deb63d81 PE |
193 | #ifndef OUTPUT_EXT |
194 | # define OUTPUT_EXT ".output" | |
195 | #endif | |
196 | ||
197 | #ifndef TAB_EXT | |
198 | # define TAB_EXT ".tab" | |
199 | #endif | |
55b96341 | 200 | |
381fb12e AD |
201 | #ifndef DEFAULT_TMPDIR |
202 | # define DEFAULT_TMPDIR "/tmp" | |
203 | #endif | |
204 | ||
205 | ||
206 | ||
381fb12e AD |
207 | /*---------------------. |
208 | | Free a linked list. | | |
209 | `---------------------*/ | |
210 | ||
300f275f AD |
211 | #define LIST_FREE(Type, List) \ |
212 | do { \ | |
213 | Type *_node, *_next; \ | |
214 | for (_node = List; _node; _node = _next) \ | |
215 | { \ | |
216 | _next = _node->next; \ | |
afbb696d | 217 | free (_node); \ |
300f275f AD |
218 | } \ |
219 | } while (0) | |
220 | ||
381fb12e AD |
221 | |
222 | /*---------------------------------------------. | |
223 | | Debugging memory allocation (must be last). | | |
224 | `---------------------------------------------*/ | |
342b8b6e AD |
225 | |
226 | # if WITH_DMALLOC | |
227 | # define DMALLOC_FUNC_CHECK | |
228 | # include <dmalloc.h> | |
229 | # endif /* WITH_DMALLOC */ | |
230 | ||
a4b36db4 | 231 | #endif /* ! BISON_SYSTEM_H */ |