]> git.saurik.com Git - bison.git/blame - src/system.h
xml: match DOT output and xml2dot.xsl processing
[bison.git] / src / system.h
CommitLineData
87aabbff 1/* System-dependent definitions for Bison.
45aa0550 2
c932d613 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 18#ifndef BISON_SYSTEM_H
37e884cd 19# define BISON_SYSTEM_H
d968a24b 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>. */
37e884cd
AD
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
37# include <limits.h>
38# include <stddef.h>
39# include <stdlib.h>
40# include <string.h>
37e884cd
AD
41# include <unistd.h>
42# include <inttypes.h>
43
211c8185
AD
44#define ARRAY_CARDINALITY(Array) (sizeof (Array) / sizeof *(Array))
45#define STREQ(L, R) (strcmp(L, R) == 0)
46#define STRNEQ(L, R) (!STREQ(L, R))
47
37e884cd 48# ifndef UINTPTR_MAX
deedb0b7
PE
49/* This isn't perfect, but it's good enough for Bison, which needs
50 only to hash pointers. */
51typedef size_t uintptr_t;
37e884cd 52# endif
deedb0b7 53
da209f94 54// Version mismatch.
37e884cd 55# define EX_MISMATCH 63
a4b36db4 56
cb48f191
PE
57/*---------.
58| Gnulib. |
59`---------*/
b77b9ee0 60
37e884cd
AD
61# include <unlocked-io.h>
62# include <verify.h>
63# include <xalloc.h>
7625ec2c 64
b77b9ee0 65
a0f6b076
AD
66/*-----------------.
67| GCC extensions. |
68`-----------------*/
69
77bb73e7
JD
70/* Use PACIFY_CC to indicate that Code is unimportant to the logic of Bison
71 but that it is necessary for suppressing compiler warnings. For example,
72 Code might be a variable initializer that's always overwritten before the
73 variable is used.
74
75 PACIFY_CC is intended to be useful only as a comment as it does not alter
76 Code. It is tempting to redefine PACIFY_CC so that it will suppress Code
77 when configuring without --enable-gcc-warnings. However, that would mean
78 that, for maintainers, Bison would compile with potentially less warnings
79 and safer logic than it would for users. Due to the overhead of M4,
80 suppressing Code is unlikely to offer any significant improvement in
81 Bison's performance anyway. */
37e884cd 82# define PACIFY_CC(Code) Code
48e28efa 83
37e884cd 84# ifndef __attribute__
a0f6b076 85/* This feature is available in gcc versions 2.5 and later. */
37e884cd 86# if (! defined __GNUC__ || __GNUC__ < 2 \
ef51bfa7 87 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5))
37e884cd
AD
88# define __attribute__(Spec) /* empty */
89# endif
a0f6b076 90# endif
e9955c83 91
a0f6b076
AD
92/* The __-protected variants of `format' and `printf' attributes
93 are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
37e884cd
AD
94# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
95# define __format__ format
96# define __printf__ printf
97# endif
a0f6b076 98
37e884cd
AD
99# ifndef ATTRIBUTE_NORETURN
100# define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
101# endif
e9955c83 102
37e884cd
AD
103# ifndef ATTRIBUTE_UNUSED
104# define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
105# endif
a0f6b076 106
e9071366 107
a0f6b076
AD
108/*------.
109| NLS. |
110`------*/
111
37e884cd 112# include <locale.h>
f2d78a99 113
37e884cd
AD
114# include <gettext.h>
115# define _(Msgid) gettext (Msgid)
116# define N_(Msgid) (Msgid)
f2d78a99 117
a0f6b076 118
015acc48
AD
119/*-----------.
120| Booleans. |
121`-----------*/
122
37e884cd 123# include <stdbool.h>
8c7ebe49
AD
124
125
4f82b42a
PE
126
127/*-------------.
128| Assertions. |
129`-------------*/
130
f1fb412c
JD
131/* In the past, Bison defined aver to simply invoke abort in the case of
132 a failed assertion. The rationale was that <assert.h>'s assertions
133 were too heavyweight and could be disabled too easily. See
134 discussions at
c842365a
JD
135 <http://lists.gnu.org/archive/html/bison-patches/2006-01/msg00080.html>
136 <http://lists.gnu.org/archive/html/bison-patches/2006-09/msg00111.html>.
f1fb412c
JD
137
138 However, normal assert output can be helpful during development and
139 in bug reports from users. Moreover, it's not clear now that
140 <assert.h>'s assertions are significantly heavyweight. Finally, if
141 users want to experiment with disabling assertions, it's debatable
142 whether it's our responsibility to stop them. See discussion
143 starting at
144 <http://lists.gnu.org/archive/html/bison-patches/2009-09/msg00013.html>.
145
146 For now, we use assert but we call it aver throughout Bison in case
147 we later wish to try another scheme.
c842365a 148*/
37e884cd
AD
149# include <assert.h>
150# define aver assert
4f82b42a
PE
151
152
8c7ebe49
AD
153/*-----------.
154| Obstacks. |
155`-----------*/
156
37e884cd
AD
157# define obstack_chunk_alloc xmalloc
158# define obstack_chunk_free free
159# include <obstack.h>
8c7ebe49 160
9b858541 161# define obstack_sgrow(Obs, Str) \
ff4423cc 162 obstack_grow (Obs, Str, strlen (Str))
8c7ebe49 163
13b712d7
AD
164/* Output Str escaped for our postprocessing (i.e., escape M4 special
165 characters).
166
167 For instance "[foo]" -> "@{foo@}", "$$" -> "$][$][". */
168
169# define obstack_escape(Obs, Str) \
170 do { \
171 char const *p; \
172 for (p = Str; *p; p++) \
173 switch (*p) \
174 { \
175 case '$': obstack_sgrow (Obs, "$]["); break; \
176 case '@': obstack_sgrow (Obs, "@@" ); break; \
177 case '[': obstack_sgrow (Obs, "@{" ); break; \
178 case ']': obstack_sgrow (Obs, "@}" ); break; \
179 default: obstack_1grow (Obs, *p ); break; \
180 } \
181 } while (0)
182
183
0601c3bf
AD
184/* Output Str both quoted for M4 (i.e., embed in [[...]]), and escaped
185 for our postprocessing (i.e., escape M4 special characters). If
186 Str is empty (or NULL), output "[]" instead of "[[]]" as it make M4
187 programming easier (m4_ifval can be used).
188
189 For instance "[foo]" -> "[[@{foo@}]]", "$$" -> "[[$][$][]]". */
190
191# define obstack_quote(Obs, Str) \
192 do { \
193 char const* obstack_quote_p = Str; \
194 if (obstack_quote_p && obstack_quote_p[0]) \
195 { \
196 obstack_sgrow (Obs, "[["); \
197 obstack_escape (Obs, obstack_quote_p); \
198 obstack_sgrow (Obs, "]]"); \
199 } \
200 else \
201 obstack_sgrow (Obs, "[]"); \
202 } while (0)
203
204
47a31596 205/* Append the ending 0, finish Obs, and return the string. */
0601c3bf 206
47a31596
TR
207# define obstack_finish0(Obs) \
208 (obstack_1grow (Obs, '\0'), (char *) obstack_finish (Obs))
13b712d7 209
7de3329e 210
381fb12e
AD
211/*-----------------------------------------.
212| Extensions to use for the output files. |
213`-----------------------------------------*/
7de3329e 214
37e884cd
AD
215# ifndef OUTPUT_EXT
216# define OUTPUT_EXT ".output"
217# endif
deb63d81 218
37e884cd
AD
219# ifndef TAB_EXT
220# define TAB_EXT ".tab"
221# endif
55b96341 222
381fb12e
AD
223
224
381fb12e
AD
225/*---------------------.
226| Free a linked list. |
227`---------------------*/
228
9b858541
AD
229# define LIST_FREE(Type, List) \
230 do { \
231 Type *_node, *_next; \
232 for (_node = List; _node; _node = _next) \
233 { \
234 _next = _node->next; \
235 free (_node); \
236 } \
237 } while (0)
300f275f 238
381fb12e
AD
239
240/*---------------------------------------------.
241| Debugging memory allocation (must be last). |
242`---------------------------------------------*/
342b8b6e
AD
243
244# if WITH_DMALLOC
245# define DMALLOC_FUNC_CHECK
246# include <dmalloc.h>
247# endif /* WITH_DMALLOC */
248
a4b36db4 249#endif /* ! BISON_SYSTEM_H */