]>
git.saurik.com Git - bison.git/blob - src/system.h
1 /* System-dependent definitions for Bison.
3 Copyright (C) 2000-2007, 2009-2012 Free Software Foundation, Inc.
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
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.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 #ifndef BISON_SYSTEM_H
19 #define BISON_SYSTEM_H
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
42 #define ARRAY_CARDINALITY(Array) (sizeof (Array) / sizeof *(Array))
43 #define STREQ(L, R) (strcmp(L, R) == 0)
44 #define STRNEQ(L, R) (!STREQ(L, R))
46 /* Just like strncmp, but the second argument must be a literal string
47 and you don't specify the length. */
48 #define STRNCMP_LIT(S, Literal) \
49 strncmp (S, "" Literal "", sizeof (Literal) - 1)
51 /* Whether Literal is a prefix of S. */
52 #define STRPREFIX_LIT(Literal, S) \
53 (STRNCMP_LIT (S, Literal) == 0)
56 # include <sys/types.h>
63 /* This isn't perfect, but it's good enough for Bison, which needs
64 only to hash pointers. */
65 typedef size_t uintptr_t;
69 #define EX_MISMATCH 63
75 #include <unlocked-io.h>
84 /* Use PACIFY_CC to indicate that Code is unimportant to the logic of Bison
85 but that it is necessary for suppressing compiler warnings. For example,
86 Code might be a variable initializer that's always overwritten before the
89 PACIFY_CC is intended to be useful only as a comment as it does not alter
90 Code. It is tempting to redefine PACIFY_CC so that it will suppress Code
91 when configuring without --enable-gcc-warnings. However, that would mean
92 that, for maintainers, Bison would compile with potentially less warnings
93 and safer logic than it would for users. Due to the overhead of M4,
94 suppressing Code is unlikely to offer any significant improvement in
95 Bison's performance anyway. */
96 #define PACIFY_CC(Code) Code
99 /* This feature is available in gcc versions 2.5 and later. */
100 # if (! defined __GNUC__ || __GNUC__ < 2 \
101 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5))
102 # define __attribute__(Spec) /* empty */
106 /* The __-protected variants of `format' and `printf' attributes
107 are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
108 #if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
109 # define __format__ format
110 # define __printf__ printf
113 #ifndef ATTRIBUTE_NORETURN
114 # define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
117 #ifndef ATTRIBUTE_UNUSED
118 # define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
121 #define FUNCTION_PRINT() fprintf (stderr, "%s: ", __func__)
130 #define _(Msgid) gettext (Msgid)
131 #define N_(Msgid) (Msgid)
146 /* In the past, Bison defined aver to simply invoke abort in the case of
147 a failed assertion. The rationale was that <assert.h>'s assertions
148 were too heavyweight and could be disabled too easily. See
150 <http://lists.gnu.org/archive/html/bison-patches/2006-01/msg00080.html>
151 <http://lists.gnu.org/archive/html/bison-patches/2006-09/msg00111.html>.
153 However, normal assert output can be helpful during development and
154 in bug reports from users. Moreover, it's not clear now that
155 <assert.h>'s assertions are significantly heavyweight. Finally, if
156 users want to experiment with disabling assertions, it's debatable
157 whether it's our responsibility to stop them. See discussion
159 <http://lists.gnu.org/archive/html/bison-patches/2009-09/msg00013.html>.
161 For now, we use assert but we call it aver throughout Bison in case
162 we later wish to try another scheme.
172 #define obstack_chunk_alloc xmalloc
173 #define obstack_chunk_free free
176 #define obstack_sgrow(Obs, Str) \
177 obstack_grow (Obs, Str, strlen (Str))
179 #define obstack_fgrow1(Obs, Format, Arg1) \
182 sprintf (buf, Format, Arg1); \
183 obstack_grow (Obs, buf, strlen (buf)); \
186 #define obstack_fgrow2(Obs, Format, Arg1, Arg2) \
189 sprintf (buf, Format, Arg1, Arg2); \
190 obstack_grow (Obs, buf, strlen (buf)); \
193 #define obstack_fgrow3(Obs, Format, Arg1, Arg2, Arg3) \
196 sprintf (buf, Format, Arg1, Arg2, Arg3); \
197 obstack_grow (Obs, buf, strlen (buf)); \
200 #define obstack_fgrow4(Obs, Format, Arg1, Arg2, Arg3, Arg4) \
203 sprintf (buf, Format, Arg1, Arg2, Arg3, Arg4); \
204 obstack_grow (Obs, buf, strlen (buf)); \
209 /*-----------------------------------------.
210 | Extensions to use for the output files. |
211 `-----------------------------------------*/
214 # define OUTPUT_EXT ".output"
218 # define TAB_EXT ".tab"
221 #ifndef DEFAULT_TMPDIR
222 # define DEFAULT_TMPDIR "/tmp"
227 /*---------------------.
228 | Free a linked list. |
229 `---------------------*/
231 #define LIST_FREE(Type, List) \
233 Type *_node, *_next; \
234 for (_node = List; _node; _node = _next) \
236 _next = _node->next; \
242 /*---------------------------------------------.
243 | Debugging memory allocation (must be last). |
244 `---------------------------------------------*/
247 # define DMALLOC_FUNC_CHECK
248 # include <dmalloc.h>
249 # endif /* WITH_DMALLOC */
251 #endif /* ! BISON_SYSTEM_H */