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