]>
Commit | Line | Data |
---|---|---|
87aabbff | 1 | /* System-dependent definitions for Bison. |
45aa0550 | 2 | |
665f0c24 | 3 | Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free |
c21493b8 | 4 | Software Foundation, Inc. |
a0f6b076 AD |
5 | |
6 | This program is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 2, or (at your option) | |
9 | any later version. | |
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 | |
17 | along with this program; if not, write to the Free Software Foundation, | |
0fb669f9 | 18 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ |
a0f6b076 | 19 | |
d968a24b JT |
20 | #ifndef BISON_SYSTEM_H |
21 | #define BISON_SYSTEM_H | |
22 | ||
c21493b8 PE |
23 | /* flex 2.5.31 gratutiously defines macros like INT8_MIN. But this |
24 | runs afoul of pre-C99 compilers that have <inttypes.h> or | |
25 | <stdint.h>, which are included below if available. It also runs | |
26 | afoul of pre-C99 compilers that define these macros in <limits.h>. */ | |
27 | #if ! defined __STDC_VERSION__ || __STDC_VERSION__ < 199901 | |
28 | # undef INT8_MIN | |
29 | # undef INT16_MIN | |
30 | # undef INT32_MIN | |
31 | # undef INT8_MAX | |
32 | # undef INT16_MAX | |
33 | # undef UINT8_MAX | |
34 | # undef INT32_MAX | |
35 | # undef UINT16_MAX | |
36 | # undef UINT32_MAX | |
37 | #endif | |
38 | ||
6e26ca8c | 39 | #include <limits.h> |
deedb0b7 | 40 | #include <stddef.h> |
6e26ca8c PE |
41 | #include <stdlib.h> |
42 | #include <string.h> | |
ceed8467 | 43 | |
27b0ffea AD |
44 | #if HAVE_SYS_TYPES_H |
45 | # include <sys/types.h> | |
46 | #endif | |
47 | ||
3b2942e6 PE |
48 | #include <unistd.h> |
49 | #include <inttypes.h> | |
cb48f191 PE |
50 | |
51 | #ifndef UINTPTR_MAX | |
deedb0b7 PE |
52 | /* This isn't perfect, but it's good enough for Bison, which needs |
53 | only to hash pointers. */ | |
54 | typedef size_t uintptr_t; | |
55 | #endif | |
56 | ||
a4b36db4 | 57 | |
cb48f191 PE |
58 | /*---------. |
59 | | Gnulib. | | |
60 | `---------*/ | |
b77b9ee0 | 61 | |
cb48f191 PE |
62 | #include <unlocked-io.h> |
63 | #include <verify.h> | |
64 | #include <xalloc.h> | |
7625ec2c | 65 | |
b77b9ee0 | 66 | |
a0f6b076 AD |
67 | /*-----------------. |
68 | | GCC extensions. | | |
69 | `-----------------*/ | |
70 | ||
48e28efa PE |
71 | /* Use this to suppress gcc's `...may be used before initialized' |
72 | warnings. */ | |
73 | #ifdef lint | |
74 | # define IF_LINT(Code) Code | |
75 | #else | |
76 | # define IF_LINT(Code) /* empty */ | |
77 | #endif | |
78 | ||
a0f6b076 AD |
79 | #ifndef __attribute__ |
80 | /* This feature is available in gcc versions 2.5 and later. */ | |
02650b7f PE |
81 | # if (! defined __GNUC__ || __GNUC__ < 2 \ |
82 | || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__) | |
a0f6b076 AD |
83 | # define __attribute__(Spec) /* empty */ |
84 | # endif | |
e9955c83 AD |
85 | #endif |
86 | ||
a0f6b076 AD |
87 | /* The __-protected variants of `format' and `printf' attributes |
88 | are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */ | |
e9955c83 AD |
89 | #if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) |
90 | # define __format__ format | |
91 | # define __printf__ printf | |
a0f6b076 AD |
92 | #endif |
93 | ||
e9955c83 AD |
94 | #ifndef ATTRIBUTE_NORETURN |
95 | # define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__)) | |
96 | #endif | |
97 | ||
98 | #ifndef ATTRIBUTE_UNUSED | |
99 | # define ATTRIBUTE_UNUSED __attribute__ ((__unused__)) | |
100 | #endif | |
a0f6b076 | 101 | |
e9071366 AD |
102 | #define FUNCTION_PRINT() fprintf (stderr, "%s: ", __func__) |
103 | ||
a0f6b076 AD |
104 | /*------. |
105 | | NLS. | | |
106 | `------*/ | |
107 | ||
6e26ca8c | 108 | #include <locale.h> |
f2d78a99 | 109 | |
982cc302 | 110 | #include <gettext.h> |
e0327bc8 AD |
111 | #define _(Msgid) gettext (Msgid) |
112 | #define N_(Msgid) (Msgid) | |
f2d78a99 | 113 | |
a0f6b076 | 114 | |
015acc48 AD |
115 | /*-----------. |
116 | | Booleans. | | |
117 | `-----------*/ | |
118 | ||
f61aad93 | 119 | #include <stdbool.h> |
8c7ebe49 AD |
120 | |
121 | ||
4f82b42a PE |
122 | |
123 | /*-------------. | |
124 | | Assertions. | | |
125 | `-------------*/ | |
126 | ||
127 | /* <assert.h>'s assertions are too heavyweight, and can be disabled | |
128 | too easily, so use aver rather than assert. */ | |
129 | static inline void | |
130 | aver (bool assertion) | |
131 | { | |
132 | if (! assertion) | |
133 | abort (); | |
134 | } | |
135 | ||
136 | ||
8c7ebe49 AD |
137 | /*-----------. |
138 | | Obstacks. | | |
139 | `-----------*/ | |
140 | ||
04098407 PE |
141 | #define obstack_chunk_alloc xmalloc |
142 | #define obstack_chunk_free free | |
143 | #include <obstack.h> | |
8c7ebe49 | 144 | |
ff4423cc AD |
145 | #define obstack_sgrow(Obs, Str) \ |
146 | obstack_grow (Obs, Str, strlen (Str)) | |
8c7ebe49 AD |
147 | |
148 | #define obstack_fgrow1(Obs, Format, Arg1) \ | |
149 | do { \ | |
150 | char buf[4096]; \ | |
151 | sprintf (buf, Format, Arg1); \ | |
152 | obstack_grow (Obs, buf, strlen (buf)); \ | |
153 | } while (0) | |
dd60faec AD |
154 | |
155 | #define obstack_fgrow2(Obs, Format, Arg1, Arg2) \ | |
156 | do { \ | |
157 | char buf[4096]; \ | |
158 | sprintf (buf, Format, Arg1, Arg2); \ | |
159 | obstack_grow (Obs, buf, strlen (buf)); \ | |
160 | } while (0) | |
896fe5c1 AD |
161 | |
162 | #define obstack_fgrow3(Obs, Format, Arg1, Arg2, Arg3) \ | |
163 | do { \ | |
164 | char buf[4096]; \ | |
165 | sprintf (buf, Format, Arg1, Arg2, Arg3); \ | |
166 | obstack_grow (Obs, buf, strlen (buf)); \ | |
167 | } while (0) | |
7de3329e | 168 | |
ff4423cc AD |
169 | #define obstack_fgrow4(Obs, Format, Arg1, Arg2, Arg3, Arg4) \ |
170 | do { \ | |
171 | char buf[4096]; \ | |
172 | sprintf (buf, Format, Arg1, Arg2, Arg3, Arg4); \ | |
173 | obstack_grow (Obs, buf, strlen (buf)); \ | |
174 | } while (0) | |
175 | ||
7de3329e | 176 | |
7de3329e | 177 | |
381fb12e AD |
178 | /*-----------------------------------------. |
179 | | Extensions to use for the output files. | | |
180 | `-----------------------------------------*/ | |
7de3329e | 181 | |
deb63d81 PE |
182 | #ifndef OUTPUT_EXT |
183 | # define OUTPUT_EXT ".output" | |
184 | #endif | |
185 | ||
186 | #ifndef TAB_EXT | |
187 | # define TAB_EXT ".tab" | |
188 | #endif | |
55b96341 | 189 | |
381fb12e AD |
190 | #ifndef DEFAULT_TMPDIR |
191 | # define DEFAULT_TMPDIR "/tmp" | |
192 | #endif | |
193 | ||
194 | ||
195 | ||
381fb12e AD |
196 | /*---------------------. |
197 | | Free a linked list. | | |
198 | `---------------------*/ | |
199 | ||
300f275f AD |
200 | #define LIST_FREE(Type, List) \ |
201 | do { \ | |
202 | Type *_node, *_next; \ | |
203 | for (_node = List; _node; _node = _next) \ | |
204 | { \ | |
205 | _next = _node->next; \ | |
afbb696d | 206 | free (_node); \ |
300f275f AD |
207 | } \ |
208 | } while (0) | |
209 | ||
381fb12e AD |
210 | |
211 | /*---------------------------------------------. | |
212 | | Debugging memory allocation (must be last). | | |
213 | `---------------------------------------------*/ | |
342b8b6e AD |
214 | |
215 | # if WITH_DMALLOC | |
216 | # define DMALLOC_FUNC_CHECK | |
217 | # include <dmalloc.h> | |
218 | # endif /* WITH_DMALLOC */ | |
219 | ||
a4b36db4 | 220 | #endif /* ! BISON_SYSTEM_H */ |