]> git.saurik.com Git - bison.git/blame - src/system.h
src/location.h: #include "system.h" rather than <stdbool.h>.
[bison.git] / src / system.h
CommitLineData
87aabbff 1/* System-dependent definitions for Bison.
45aa0550 2
c21493b8
PE
3 Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free
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
fb9c0b33
PE
44#include "unlocked-io.h"
45
27b0ffea
AD
46#if HAVE_SYS_TYPES_H
47# include <sys/types.h>
48#endif
49
499daa50 50#if HAVE_UNISTD_H
a0f6b076 51# include <unistd.h>
7bb4d914
JT
52#endif
53
6e26ca8c
PE
54#if HAVE_INTTYPES_H
55# include <inttypes.h>
56#endif
57#if HAVE_STDINT_H
58# include <stdint.h>
59#endif
62a3e4f0 60
6e26ca8c 61#if ! HAVE_UINTPTR_T
deedb0b7
PE
62/* This isn't perfect, but it's good enough for Bison, which needs
63 only to hash pointers. */
64typedef size_t uintptr_t;
65#endif
66
8a6f72f3 67#include <verify.h>
982cc302 68#include <xalloc.h>
a4b36db4 69
273a74fa 70
b77b9ee0
AD
71/*---------------------.
72| Missing prototypes. |
73`---------------------*/
74
1f65350a 75#include <stpcpy.h>
b77b9ee0 76
7625ec2c
AD
77/* From lib/basename.c. */
78char *base_name (char const *name);
79
b77b9ee0 80
a0f6b076
AD
81/*-----------------.
82| GCC extensions. |
83`-----------------*/
84
48e28efa
PE
85/* Use this to suppress gcc's `...may be used before initialized'
86 warnings. */
87#ifdef lint
88# define IF_LINT(Code) Code
89#else
90# define IF_LINT(Code) /* empty */
91#endif
92
a0f6b076
AD
93#ifndef __attribute__
94/* This feature is available in gcc versions 2.5 and later. */
02650b7f
PE
95# if (! defined __GNUC__ || __GNUC__ < 2 \
96 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__)
a0f6b076
AD
97# define __attribute__(Spec) /* empty */
98# endif
e9955c83
AD
99#endif
100
a0f6b076
AD
101/* The __-protected variants of `format' and `printf' attributes
102 are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
e9955c83
AD
103#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
104# define __format__ format
105# define __printf__ printf
a0f6b076
AD
106#endif
107
e9955c83
AD
108#ifndef ATTRIBUTE_NORETURN
109# define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
110#endif
111
112#ifndef ATTRIBUTE_UNUSED
113# define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
114#endif
a0f6b076 115
e9071366
AD
116#define FUNCTION_PRINT() fprintf (stderr, "%s: ", __func__)
117
a0f6b076
AD
118/*------.
119| NLS. |
120`------*/
121
6e26ca8c 122#include <locale.h>
f2d78a99 123
982cc302 124#include <gettext.h>
e0327bc8
AD
125#define _(Msgid) gettext (Msgid)
126#define N_(Msgid) (Msgid)
f2d78a99 127
a0f6b076
AD
128
129/*-------------------------------.
130| Fix broken compilation flags. |
131`-------------------------------*/
132
8a278a04 133#ifndef LOCALEDIR
a0f6b076 134# define LOCALEDIR "/usr/local/share/locale"
8a278a04 135#endif
d968a24b 136
ceed8467 137
015acc48
AD
138/*-----------.
139| Booleans. |
140`-----------*/
141
f61aad93 142#include <stdbool.h>
8c7ebe49
AD
143
144
145/*-----------.
146| Obstacks. |
147`-----------*/
148
04098407
PE
149#define obstack_chunk_alloc xmalloc
150#define obstack_chunk_free free
151#include <obstack.h>
8c7ebe49 152
ff4423cc
AD
153#define obstack_sgrow(Obs, Str) \
154 obstack_grow (Obs, Str, strlen (Str))
8c7ebe49
AD
155
156#define obstack_fgrow1(Obs, Format, Arg1) \
157do { \
158 char buf[4096]; \
159 sprintf (buf, Format, Arg1); \
160 obstack_grow (Obs, buf, strlen (buf)); \
161} while (0)
dd60faec
AD
162
163#define obstack_fgrow2(Obs, Format, Arg1, Arg2) \
164do { \
165 char buf[4096]; \
166 sprintf (buf, Format, Arg1, Arg2); \
167 obstack_grow (Obs, buf, strlen (buf)); \
168} while (0)
896fe5c1
AD
169
170#define obstack_fgrow3(Obs, Format, Arg1, Arg2, Arg3) \
171do { \
172 char buf[4096]; \
173 sprintf (buf, Format, Arg1, Arg2, Arg3); \
174 obstack_grow (Obs, buf, strlen (buf)); \
175} while (0)
7de3329e 176
ff4423cc
AD
177#define obstack_fgrow4(Obs, Format, Arg1, Arg2, Arg3, Arg4) \
178do { \
179 char buf[4096]; \
180 sprintf (buf, Format, Arg1, Arg2, Arg3, Arg4); \
181 obstack_grow (Obs, buf, strlen (buf)); \
182} while (0)
183
7de3329e 184
7de3329e 185
381fb12e
AD
186/*-----------------------------------------.
187| Extensions to use for the output files. |
188`-----------------------------------------*/
7de3329e 189
deb63d81
PE
190#ifndef OUTPUT_EXT
191# define OUTPUT_EXT ".output"
192#endif
193
194#ifndef TAB_EXT
195# define TAB_EXT ".tab"
196#endif
55b96341 197
381fb12e
AD
198#ifndef DEFAULT_TMPDIR
199# define DEFAULT_TMPDIR "/tmp"
200#endif
201
202
203
381fb12e
AD
204/*---------------------.
205| Free a linked list. |
206`---------------------*/
207
300f275f
AD
208#define LIST_FREE(Type, List) \
209do { \
210 Type *_node, *_next; \
211 for (_node = List; _node; _node = _next) \
212 { \
213 _next = _node->next; \
afbb696d 214 free (_node); \
300f275f
AD
215 } \
216} while (0)
217
381fb12e 218
68cae94e
PE
219/* Assertions. <assert.h>'s assertions are too heavyweight, and can
220 be disabled too easily, so implement it separately here. */
221#define assert(x) ((void) ((x) || (abort (), 0)))
222
223
381fb12e
AD
224/*---------------------------------------------.
225| Debugging memory allocation (must be last). |
226`---------------------------------------------*/
342b8b6e
AD
227
228# if WITH_DMALLOC
229# define DMALLOC_FUNC_CHECK
230# include <dmalloc.h>
231# endif /* WITH_DMALLOC */
232
a4b36db4 233#endif /* ! BISON_SYSTEM_H */