]> git.saurik.com Git - bison.git/blame - src/system.h
Update POTFILES.
[bison.git] / src / system.h
CommitLineData
87aabbff 1/* System-dependent definitions for Bison.
45aa0550 2
1462fcee 3 Copyright (C) 2000-2007, 2009-2010 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. */
52typedef 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
48e28efa
PE
69/* Use this to suppress gcc's `...may be used before initialized'
70 warnings. */
71#ifdef lint
72# define IF_LINT(Code) Code
73#else
74# define IF_LINT(Code) /* empty */
75#endif
76
a0f6b076
AD
77#ifndef __attribute__
78/* This feature is available in gcc versions 2.5 and later. */
02650b7f
PE
79# if (! defined __GNUC__ || __GNUC__ < 2 \
80 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__)
a0f6b076
AD
81# define __attribute__(Spec) /* empty */
82# endif
e9955c83
AD
83#endif
84
a0f6b076
AD
85/* The __-protected variants of `format' and `printf' attributes
86 are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
e9955c83
AD
87#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
88# define __format__ format
89# define __printf__ printf
a0f6b076
AD
90#endif
91
e9955c83
AD
92#ifndef ATTRIBUTE_NORETURN
93# define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
94#endif
95
96#ifndef ATTRIBUTE_UNUSED
97# define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
98#endif
a0f6b076 99
e9071366
AD
100#define FUNCTION_PRINT() fprintf (stderr, "%s: ", __func__)
101
a0f6b076
AD
102/*------.
103| NLS. |
104`------*/
105
6e26ca8c 106#include <locale.h>
f2d78a99 107
982cc302 108#include <gettext.h>
e0327bc8
AD
109#define _(Msgid) gettext (Msgid)
110#define N_(Msgid) (Msgid)
f2d78a99 111
a0f6b076 112
015acc48
AD
113/*-----------.
114| Booleans. |
115`-----------*/
116
f61aad93 117#include <stdbool.h>
8c7ebe49
AD
118
119
4f82b42a
PE
120
121/*-------------.
122| Assertions. |
123`-------------*/
124
f1fb412c
JD
125/* In the past, Bison defined aver to simply invoke abort in the case of
126 a failed assertion. The rationale was that <assert.h>'s assertions
127 were too heavyweight and could be disabled too easily. See
128 discussions at
c842365a
JD
129 <http://lists.gnu.org/archive/html/bison-patches/2006-01/msg00080.html>
130 <http://lists.gnu.org/archive/html/bison-patches/2006-09/msg00111.html>.
f1fb412c
JD
131
132 However, normal assert output can be helpful during development and
133 in bug reports from users. Moreover, it's not clear now that
134 <assert.h>'s assertions are significantly heavyweight. Finally, if
135 users want to experiment with disabling assertions, it's debatable
136 whether it's our responsibility to stop them. See discussion
137 starting at
138 <http://lists.gnu.org/archive/html/bison-patches/2009-09/msg00013.html>.
139
140 For now, we use assert but we call it aver throughout Bison in case
141 we later wish to try another scheme.
c842365a 142*/
f1fb412c
JD
143#include <assert.h>
144#define aver assert
4f82b42a
PE
145
146
8c7ebe49
AD
147/*-----------.
148| Obstacks. |
149`-----------*/
150
04098407
PE
151#define obstack_chunk_alloc xmalloc
152#define obstack_chunk_free free
153#include <obstack.h>
8c7ebe49 154
ff4423cc
AD
155#define obstack_sgrow(Obs, Str) \
156 obstack_grow (Obs, Str, strlen (Str))
8c7ebe49
AD
157
158#define obstack_fgrow1(Obs, Format, Arg1) \
159do { \
160 char buf[4096]; \
161 sprintf (buf, Format, Arg1); \
162 obstack_grow (Obs, buf, strlen (buf)); \
163} while (0)
dd60faec
AD
164
165#define obstack_fgrow2(Obs, Format, Arg1, Arg2) \
166do { \
167 char buf[4096]; \
168 sprintf (buf, Format, Arg1, Arg2); \
169 obstack_grow (Obs, buf, strlen (buf)); \
170} while (0)
896fe5c1
AD
171
172#define obstack_fgrow3(Obs, Format, Arg1, Arg2, Arg3) \
173do { \
174 char buf[4096]; \
175 sprintf (buf, Format, Arg1, Arg2, Arg3); \
176 obstack_grow (Obs, buf, strlen (buf)); \
177} while (0)
7de3329e 178
ff4423cc
AD
179#define obstack_fgrow4(Obs, Format, Arg1, Arg2, Arg3, Arg4) \
180do { \
181 char buf[4096]; \
182 sprintf (buf, Format, Arg1, Arg2, Arg3, Arg4); \
183 obstack_grow (Obs, buf, strlen (buf)); \
184} while (0)
185
7de3329e 186
7de3329e 187
381fb12e
AD
188/*-----------------------------------------.
189| Extensions to use for the output files. |
190`-----------------------------------------*/
7de3329e 191
deb63d81
PE
192#ifndef OUTPUT_EXT
193# define OUTPUT_EXT ".output"
194#endif
195
196#ifndef TAB_EXT
197# define TAB_EXT ".tab"
198#endif
55b96341 199
381fb12e
AD
200#ifndef DEFAULT_TMPDIR
201# define DEFAULT_TMPDIR "/tmp"
202#endif
203
204
205
381fb12e
AD
206/*---------------------.
207| Free a linked list. |
208`---------------------*/
209
300f275f
AD
210#define LIST_FREE(Type, List) \
211do { \
212 Type *_node, *_next; \
213 for (_node = List; _node; _node = _next) \
214 { \
215 _next = _node->next; \
afbb696d 216 free (_node); \
300f275f
AD
217 } \
218} while (0)
219
381fb12e
AD
220
221/*---------------------------------------------.
222| Debugging memory allocation (must be last). |
223`---------------------------------------------*/
342b8b6e
AD
224
225# if WITH_DMALLOC
226# define DMALLOC_FUNC_CHECK
227# include <dmalloc.h>
228# endif /* WITH_DMALLOC */
229
a4b36db4 230#endif /* ! BISON_SYSTEM_H */