]> git.saurik.com Git - bison.git/blame - src/system.h
Split the default %destructor/%printer into two kinds: <*> and <!>.
[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
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. */
54typedef size_t uintptr_t;
55#endif
56
a4b36db4 57
cb48f191
PE
58/*---------.
59| Gnulib. |
60`---------*/
b77b9ee0 61
1f65350a 62#include <stpcpy.h>
cb48f191
PE
63#include <unlocked-io.h>
64#include <verify.h>
65#include <xalloc.h>
7625ec2c 66
b77b9ee0 67
a0f6b076
AD
68/*-----------------.
69| GCC extensions. |
70`-----------------*/
71
48e28efa
PE
72/* Use this to suppress gcc's `...may be used before initialized'
73 warnings. */
74#ifdef lint
75# define IF_LINT(Code) Code
76#else
77# define IF_LINT(Code) /* empty */
78#endif
79
a0f6b076
AD
80#ifndef __attribute__
81/* This feature is available in gcc versions 2.5 and later. */
02650b7f
PE
82# if (! defined __GNUC__ || __GNUC__ < 2 \
83 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__)
a0f6b076
AD
84# define __attribute__(Spec) /* empty */
85# endif
e9955c83
AD
86#endif
87
a0f6b076
AD
88/* The __-protected variants of `format' and `printf' attributes
89 are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
e9955c83
AD
90#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
91# define __format__ format
92# define __printf__ printf
a0f6b076
AD
93#endif
94
e9955c83
AD
95#ifndef ATTRIBUTE_NORETURN
96# define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
97#endif
98
99#ifndef ATTRIBUTE_UNUSED
100# define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
101#endif
a0f6b076 102
e9071366
AD
103#define FUNCTION_PRINT() fprintf (stderr, "%s: ", __func__)
104
a0f6b076
AD
105/*------.
106| NLS. |
107`------*/
108
6e26ca8c 109#include <locale.h>
f2d78a99 110
982cc302 111#include <gettext.h>
e0327bc8
AD
112#define _(Msgid) gettext (Msgid)
113#define N_(Msgid) (Msgid)
f2d78a99 114
a0f6b076 115
015acc48
AD
116/*-----------.
117| Booleans. |
118`-----------*/
119
f61aad93 120#include <stdbool.h>
8c7ebe49
AD
121
122
4f82b42a
PE
123
124/*-------------.
125| Assertions. |
126`-------------*/
127
128/* <assert.h>'s assertions are too heavyweight, and can be disabled
129 too easily, so use aver rather than assert. */
130static inline void
131aver (bool assertion)
132{
133 if (! assertion)
134 abort ();
135}
136
137
8c7ebe49
AD
138/*-----------.
139| Obstacks. |
140`-----------*/
141
04098407
PE
142#define obstack_chunk_alloc xmalloc
143#define obstack_chunk_free free
144#include <obstack.h>
8c7ebe49 145
ff4423cc
AD
146#define obstack_sgrow(Obs, Str) \
147 obstack_grow (Obs, Str, strlen (Str))
8c7ebe49
AD
148
149#define obstack_fgrow1(Obs, Format, Arg1) \
150do { \
151 char buf[4096]; \
152 sprintf (buf, Format, Arg1); \
153 obstack_grow (Obs, buf, strlen (buf)); \
154} while (0)
dd60faec
AD
155
156#define obstack_fgrow2(Obs, Format, Arg1, Arg2) \
157do { \
158 char buf[4096]; \
159 sprintf (buf, Format, Arg1, Arg2); \
160 obstack_grow (Obs, buf, strlen (buf)); \
161} while (0)
896fe5c1
AD
162
163#define obstack_fgrow3(Obs, Format, Arg1, Arg2, Arg3) \
164do { \
165 char buf[4096]; \
166 sprintf (buf, Format, Arg1, Arg2, Arg3); \
167 obstack_grow (Obs, buf, strlen (buf)); \
168} while (0)
7de3329e 169
ff4423cc
AD
170#define obstack_fgrow4(Obs, Format, Arg1, Arg2, Arg3, Arg4) \
171do { \
172 char buf[4096]; \
173 sprintf (buf, Format, Arg1, Arg2, Arg3, Arg4); \
174 obstack_grow (Obs, buf, strlen (buf)); \
175} while (0)
176
7de3329e 177
7de3329e 178
381fb12e
AD
179/*-----------------------------------------.
180| Extensions to use for the output files. |
181`-----------------------------------------*/
7de3329e 182
deb63d81
PE
183#ifndef OUTPUT_EXT
184# define OUTPUT_EXT ".output"
185#endif
186
187#ifndef TAB_EXT
188# define TAB_EXT ".tab"
189#endif
55b96341 190
381fb12e
AD
191#ifndef DEFAULT_TMPDIR
192# define DEFAULT_TMPDIR "/tmp"
193#endif
194
195
196
381fb12e
AD
197/*---------------------.
198| Free a linked list. |
199`---------------------*/
200
300f275f
AD
201#define LIST_FREE(Type, List) \
202do { \
203 Type *_node, *_next; \
204 for (_node = List; _node; _node = _next) \
205 { \
206 _next = _node->next; \
afbb696d 207 free (_node); \
300f275f
AD
208 } \
209} while (0)
210
381fb12e
AD
211
212/*---------------------------------------------.
213| Debugging memory allocation (must be last). |
214`---------------------------------------------*/
342b8b6e
AD
215
216# if WITH_DMALLOC
217# define DMALLOC_FUNC_CHECK
218# include <dmalloc.h>
219# endif /* WITH_DMALLOC */
220
a4b36db4 221#endif /* ! BISON_SYSTEM_H */