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