• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* System-dependent definitions for Bison.
2 
3    Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free
4    Software Foundation, Inc.
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,
18    Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
19 
20 #ifndef BISON_SYSTEM_H
21 #define BISON_SYSTEM_H
22 
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 
39 #include <limits.h>
40 #include <stddef.h>
41 #include <stdlib.h>
42 #include <string.h>
43 
44 #include "unlocked-io.h"
45 
46 #if HAVE_SYS_TYPES_H
47 # include <sys/types.h>
48 #endif
49 
50 #if HAVE_UNISTD_H
51 # include <unistd.h>
52 #endif
53 
54 #if HAVE_INTTYPES_H
55 # include <inttypes.h>
56 #endif
57 #if HAVE_STDINT_H
58 # include <stdint.h>
59 #endif
60 
61 #if ! HAVE_UINTPTR_T
62 /* This isn't perfect, but it's good enough for Bison, which needs
63    only to hash pointers.  */
64 typedef size_t uintptr_t;
65 #endif
66 
67 #include <verify.h>
68 #include <xalloc.h>
69 
70 
71 /*---------------------.
72 | Missing prototypes.  |
73 `---------------------*/
74 
75 #include <stpcpy.h>
76 
77 /* From lib/basename.c. */
78 char *base_name (char const *name);
79 
80 
81 /*-----------------.
82 | GCC extensions.  |
83 `-----------------*/
84 
85 /* Use this to suppress gcc's `...may be used before initialized'
86    warnings.  */
87 #ifdef lint
88 # define IF_LINT(Code) Code
89 #else
90 # define IF_LINT(Code) /* empty */
91 #endif
92 
93 #ifndef __attribute__
94 /* This feature is available in gcc versions 2.5 and later.  */
95 # if (! defined __GNUC__ || __GNUC__ < 2 \
96       || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__)
97 #  define __attribute__(Spec) /* empty */
98 # endif
99 #endif
100 
101 /* The __-protected variants of `format' and `printf' attributes
102    are accepted by gcc versions 2.6.4 (effectively 2.7) and later.  */
103 #if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
104 # define __format__ format
105 # define __printf__ printf
106 #endif
107 
108 #ifndef ATTRIBUTE_NORETURN
109 # define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
110 #endif
111 
112 #ifndef ATTRIBUTE_UNUSED
113 # define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
114 #endif
115 
116 /*------.
117 | NLS.  |
118 `------*/
119 
120 #include <locale.h>
121 
122 #include <gettext.h>
123 #define _(Msgid)  gettext (Msgid)
124 #define N_(Msgid) (Msgid)
125 
126 
127 /*-------------------------------.
128 | Fix broken compilation flags.  |
129 `-------------------------------*/
130 
131 #ifndef LOCALEDIR
132 # define LOCALEDIR "/usr/local/share/locale"
133 #endif
134 
135 
136 /*-----------.
137 | Booleans.  |
138 `-----------*/
139 
140 #include <stdbool.h>
141 
142 
143 /*-----------.
144 | Obstacks.  |
145 `-----------*/
146 
147 #define obstack_chunk_alloc xmalloc
148 #define obstack_chunk_free  free
149 #include <obstack.h>
150 
151 #define obstack_sgrow(Obs, Str) \
152   obstack_grow (Obs, Str, strlen (Str))
153 
154 #define obstack_fgrow1(Obs, Format, Arg1)	\
155 do {						\
156   char buf[4096];				\
157   sprintf (buf, Format, Arg1);			\
158   obstack_grow (Obs, buf, strlen (buf));	\
159 } while (0)
160 
161 #define obstack_fgrow2(Obs, Format, Arg1, Arg2)	\
162 do {						\
163   char buf[4096];				\
164   sprintf (buf, Format, Arg1, Arg2);		\
165   obstack_grow (Obs, buf, strlen (buf));	\
166 } while (0)
167 
168 #define obstack_fgrow3(Obs, Format, Arg1, Arg2, Arg3)	\
169 do {							\
170   char buf[4096];					\
171   sprintf (buf, Format, Arg1, Arg2, Arg3);		\
172   obstack_grow (Obs, buf, strlen (buf));		\
173 } while (0)
174 
175 #define obstack_fgrow4(Obs, Format, Arg1, Arg2, Arg3, Arg4)	\
176 do {								\
177   char buf[4096];						\
178   sprintf (buf, Format, Arg1, Arg2, Arg3, Arg4);		\
179   obstack_grow (Obs, buf, strlen (buf));			\
180 } while (0)
181 
182 
183 
184 /*-----------------------------------------.
185 | Extensions to use for the output files.  |
186 `-----------------------------------------*/
187 
188 #ifndef OUTPUT_EXT
189 # define OUTPUT_EXT ".output"
190 #endif
191 
192 #ifndef TAB_EXT
193 # define TAB_EXT ".tab"
194 #endif
195 
196 #ifndef DEFAULT_TMPDIR
197 # define DEFAULT_TMPDIR "/tmp"
198 #endif
199 
200 
201 
202 /*---------------------.
203 | Free a linked list.  |
204 `---------------------*/
205 
206 #define LIST_FREE(Type, List)			\
207 do {						\
208   Type *_node, *_next;				\
209   for (_node = List; _node; _node = _next)	\
210     {						\
211       _next = _node->next;			\
212       free (_node);				\
213     }						\
214 } while (0)
215 
216 
217 /* Assertions.  <assert.h>'s assertions are too heavyweight, and can
218    be disabled too easily, so implement it separately here.  */
219 #define assert(x) ((void) ((x) || (abort (), 0)))
220 
221 
222 /*---------------------------------------------.
223 | Debugging memory allocation (must be last).  |
224 `---------------------------------------------*/
225 
226 # if WITH_DMALLOC
227 #  define DMALLOC_FUNC_CHECK
228 #  include <dmalloc.h>
229 # endif /* WITH_DMALLOC */
230 
231 #endif  /* ! BISON_SYSTEM_H */
232