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