]> git.saurik.com Git - bison.git/blob - src/system.h
Port to GCC 2.95. First two problems reported by Michael Deutschmann in
[bison.git] / src / system.h
1 /* System-dependent definitions for Bison.
2
3 Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free
4 Software Foundation, Inc.
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,
18 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
19
20 #ifndef BISON_SYSTEM_H
21 #define BISON_SYSTEM_H
22
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
39 #include <limits.h>
40 #include <stddef.h>
41 #include <stdlib.h>
42 #include <string.h>
43
44 #if HAVE_SYS_TYPES_H
45 # include <sys/types.h>
46 #endif
47
48 #if HAVE_UNISTD_H
49 # include <unistd.h>
50 #endif
51
52 #if HAVE_INTTYPES_H
53 # include <inttypes.h>
54 #endif
55
56 #include <stdint.h>
57
58 #ifndef UINTPTR_MAX
59 /* This isn't perfect, but it's good enough for Bison, which needs
60 only to hash pointers. */
61 typedef size_t uintptr_t;
62 #endif
63
64
65 /*---------.
66 | Gnulib. |
67 `---------*/
68
69 #include <stpcpy.h>
70 #include <unlocked-io.h>
71 #include <verify.h>
72 #include <xalloc.h>
73
74
75 /*-----------------.
76 | GCC extensions. |
77 `-----------------*/
78
79 /* Use this to suppress gcc's `...may be used before initialized'
80 warnings. */
81 #ifdef lint
82 # define IF_LINT(Code) Code
83 #else
84 # define IF_LINT(Code) /* empty */
85 #endif
86
87 #ifndef __attribute__
88 /* This feature is available in gcc versions 2.5 and later. */
89 # if (! defined __GNUC__ || __GNUC__ < 2 \
90 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__)
91 # define __attribute__(Spec) /* empty */
92 # endif
93 #endif
94
95 /* The __-protected variants of `format' and `printf' attributes
96 are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
97 #if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
98 # define __format__ format
99 # define __printf__ printf
100 #endif
101
102 #ifndef ATTRIBUTE_NORETURN
103 # define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
104 #endif
105
106 #ifndef ATTRIBUTE_UNUSED
107 # define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
108 #endif
109
110 #define FUNCTION_PRINT() fprintf (stderr, "%s: ", __func__)
111
112 /*------.
113 | NLS. |
114 `------*/
115
116 #include <locale.h>
117
118 #include <gettext.h>
119 #define _(Msgid) gettext (Msgid)
120 #define N_(Msgid) (Msgid)
121
122
123 /*-------------------------------.
124 | Fix broken compilation flags. |
125 `-------------------------------*/
126
127 #ifndef LOCALEDIR
128 # define LOCALEDIR "/usr/local/share/locale"
129 #endif
130
131
132 /*-----------.
133 | Booleans. |
134 `-----------*/
135
136 #include <stdbool.h>
137
138
139
140 /*-------------.
141 | Assertions. |
142 `-------------*/
143
144 /* <assert.h>'s assertions are too heavyweight, and can be disabled
145 too easily, so use aver rather than assert. */
146 static inline void
147 aver (bool assertion)
148 {
149 if (! assertion)
150 abort ();
151 }
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 */