]>
Commit | Line | Data |
---|---|---|
55b929ca | 1 | m4_divert(-1) -*- Autoconf -*- |
fb8135fa AD |
2 | |
3 | # C M4 Macros for Bison. | |
4 | # Copyright (C) 2002 Free 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 of the License, or | |
9 | # (at your option) 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 | |
18 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | |
19 | # 02111-1307 USA | |
20 | ||
21 | ||
2a8d363a AD |
22 | ## ---------------- ## |
23 | ## Identification. ## | |
24 | ## ---------------- ## | |
fb8135fa AD |
25 | |
26 | # b4_copyright(TITLE, YEARS) | |
27 | # -------------------------- | |
28 | m4_define([b4_copyright], | |
29 | [/* A Bison parser, made from b4_filename, by GNU bison b4_version. */ | |
30 | ||
31 | /* $1, | |
c76e14da | 32 | Copyright (C) $2 Free Software Foundation, Inc. |
fb8135fa AD |
33 | |
34 | This program is free software; you can redistribute it and/or modify | |
35 | it under the terms of the GNU General Public License as published by | |
36 | the Free Software Foundation; either version 2, or (at your option) | |
37 | any later version. | |
38 | ||
39 | This program is distributed in the hope that it will be useful, | |
40 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
41 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
42 | GNU General Public License for more details. | |
43 | ||
44 | You should have received a copy of the GNU General Public License | |
45 | along with this program; if not, write to the Free Software | |
46 | Foundation, Inc., 59 Temple Place - Suite 330, | |
ad66f664 | 47 | Boston, MA 02111-1307, USA. */]) |
fb8135fa AD |
48 | |
49 | ||
2a8d363a AD |
50 | # b4_identification |
51 | # ----------------- | |
52 | m4_define([b4_identification], | |
53 | [/* Identify Bison output. */ | |
54 | [#]define YYBISON 1 | |
55 | ||
56 | /* Skeleton name. */ | |
57 | [#]define YYSKELETON_NAME "b4_skeleton" | |
58 | ||
59 | /* Pure parsers. */ | |
60 | [#]define YYPURE b4_pure | |
61 | ||
62 | /* Using locations. */ | |
63 | [#]define YYLSP_NEEDED b4_locations_flag | |
64 | ]) | |
65 | ||
66 | ||
67 | ||
68 | ## ------------------------ ## | |
69 | ## Pure/impure interfaces. ## | |
70 | ## ------------------------ ## | |
71 | ||
72 | ||
73 | # b4_user_args | |
74 | # ------------ | |
75 | m4_define([b4_user_args], | |
76 | [m4_ifset([b4_parse_param], [, b4_c_args(b4_parse_param)])]) | |
77 | ||
78 | ||
79 | # b4_parse_param | |
80 | # -------------- | |
81 | # If defined, b4_parse_param arrives double quoted, but below we prefer | |
82 | # it to be single quoted. | |
83 | m4_define_default([b4_parse_param]) | |
84 | m4_define([b4_parse_param], | |
85 | b4_parse_param)) | |
86 | ||
87 | ||
88 | ||
fb8135fa AD |
89 | ## ------------ ## |
90 | ## Data Types. ## | |
91 | ## ------------ ## | |
92 | ||
fb8135fa | 93 | |
a762e609 AD |
94 | # b4_ints_in(INT1, INT2, LOW, HIGH) |
95 | # --------------------------------- | |
96 | # Return 1 iff both INT1 and INT2 are in [LOW, HIGH], 0 otherwise. | |
97 | m4_define([b4_ints_in], | |
98 | [m4_eval([$3 <= $1 && $1 <= $4 && $3 <= $2 && $2 <= $4])]) | |
99 | ||
100 | ||
101 | # b4_int_type(MIN, MAX) | |
102 | # --------------------- | |
103 | # Return the smallest int type able to handle numbers ranging from | |
104 | # MIN to MAX (included). | |
105 | m4_define([b4_int_type], | |
106 | [m4_if(b4_ints_in($@, [0], [255]), [1], [unsigned char], | |
f1886bb2 | 107 | b4_ints_in($@, [-128], [127]), [1], [signed char], |
a762e609 AD |
108 | |
109 | b4_ints_in($@, [0], [65535]), [1], [unsigned short], | |
110 | b4_ints_in($@, [-32768], [32767]), [1], [short], | |
111 | ||
112 | m4_eval([0 <= $1]), [1], [unsigned int], | |
113 | ||
114 | [int])]) | |
115 | ||
f1886bb2 | 116 | |
a762e609 AD |
117 | # b4_int_type_for(NAME) |
118 | # --------------------- | |
119 | # Return the smallest int type able to handle numbers ranging from | |
120 | # `NAME_min' to `NAME_max' (included). | |
121 | m4_define([b4_int_type_for], | |
122 | [b4_int_type($1_min, $1_max)]) | |
fb8135fa AD |
123 | |
124 | ||
0245f82d AD |
125 | ## ------------------ ## |
126 | ## Decoding options. ## | |
127 | ## ------------------ ## | |
128 | ||
129 | ||
130 | # b4_location_if(IF-TRUE, IF-FALSE) | |
131 | # --------------------------------- | |
132 | # Expand IF-TRUE, if locations are used, IF-FALSE otherwise. | |
133 | m4_define([b4_location_if], | |
134 | [m4_if(b4_locations_flag, [1], | |
135 | [$1], | |
136 | [$2])]) | |
137 | ||
138 | ||
139 | # b4_pure_if(IF-TRUE, IF-FALSE) | |
140 | # ----------------------------- | |
141 | # Expand IF-TRUE, if %pure-parser, IF-FALSE otherwise. | |
142 | m4_define([b4_pure_if], | |
143 | [m4_if(b4_pure, [1], | |
144 | [$1], | |
145 | [$2])]) | |
146 | ||
147 | ||
148 | ||
fb8135fa AD |
149 | ## ------------------------- ## |
150 | ## Assigning token numbers. ## | |
151 | ## ------------------------- ## | |
152 | ||
153 | # b4_token_define(TOKEN-NAME, TOKEN-NUMBER) | |
154 | # ----------------------------------------- | |
155 | # Output the definition of this token as #define. | |
156 | m4_define([b4_token_define], | |
157 | [#define $1 $2 | |
158 | ]) | |
159 | ||
160 | ||
161 | # b4_token_enum(TOKEN-NAME, TOKEN-NUMBER) | |
162 | # --------------------------------------- | |
163 | # Output the definition of this token as an enum. | |
164 | m4_define([b4_token_enum], | |
165 | [$1 = $2]) | |
166 | ||
167 | ||
168 | # b4_token_defines(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER) | |
169 | # ------------------------------------------------------- | |
170 | # Output the definition of the tokens (if there are) as enums and #define. | |
171 | m4_define([b4_token_defines], | |
172 | [m4_if([$@], [[]], [], | |
173 | [/* Tokens. */ | |
6b8c3254 PE |
174 | #ifndef YYTOKENTYPE |
175 | # define YYTOKENTYPE | |
fb8135fa AD |
176 | /* Put the tokens into the symbol table, so that GDB and other debuggers |
177 | know about them. */ | |
178 | enum yytokentype { | |
179 | m4_map_sep([ b4_token_enum], [, | |
180 | ], | |
181 | [$@]) | |
182 | }; | |
095b9f05 | 183 | #endif |
fb8135fa AD |
184 | m4_map([b4_token_define], [$@]) |
185 | ]) | |
186 | ]) | |
4a2a22f4 AD |
187 | |
188 | ||
ae7453f2 | 189 | |
0245f82d AD |
190 | ## --------------------------------------------- ## |
191 | ## Defining C functions in both K&R and ANSI-C. ## | |
192 | ## --------------------------------------------- ## | |
4a2a22f4 AD |
193 | |
194 | ||
0245f82d AD |
195 | # b4_c_function_def(NAME, RETURN-VALUE, [DECL1, NAME1], ...) |
196 | # ---------------------------------------------------------- | |
4a2a22f4 | 197 | # Declare the function NAME. |
0245f82d AD |
198 | m4_define([b4_c_function_def], |
199 | [#if defined (__STDC__) || defined (__cplusplus) | |
200 | b4_c_ansi_function_def($@) | |
4a2a22f4 | 201 | #else |
0245f82d AD |
202 | $2 |
203 | $1 (b4_c_knr_formal_names(m4_shiftn(2, $@))) | |
204 | b4_c_knr_formal_decls(m4_shiftn(2, $@)) | |
4a2a22f4 AD |
205 | #endif[]dnl |
206 | ]) | |
207 | ||
208 | ||
0245f82d AD |
209 | # b4_c_ansi_function_def(NAME, RETURN-VALUE, [DECL1, NAME1], ...) |
210 | # --------------------------------------------------------------- | |
211 | # Declare the function NAME in ANSI. | |
212 | m4_define([b4_c_ansi_function_def], | |
213 | [$2 | |
214 | $1 (b4_c_ansi_formals(m4_shiftn(2, $@)))[]dnl | |
215 | ]) | |
216 | ||
217 | ||
218 | # b4_c_ansi_formals([DECL1, NAME1], ...) | |
219 | # -------------------------------------- | |
4a2a22f4 | 220 | # Output the arguments ANSI-C definition. |
0245f82d AD |
221 | m4_define([b4_c_ansi_formals], |
222 | [m4_case([$@], | |
223 | [], [void], | |
224 | [[]], [void], | |
225 | [m4_map_sep([b4_c_ansi_formal], [, ], [$@])])]) | |
4a2a22f4 | 226 | |
0245f82d AD |
227 | m4_define([b4_c_ansi_formal], |
228 | [$1]) | |
4a2a22f4 AD |
229 | |
230 | ||
0245f82d AD |
231 | # b4_c_knr_formal_names([DECL1, NAME1], ...) |
232 | # ------------------------------------------ | |
4a2a22f4 | 233 | # Output the argument names. |
0245f82d AD |
234 | m4_define([b4_c_knr_formal_names], |
235 | [m4_map_sep([b4_c_knr_formal_name], [, ], [$@])]) | |
4a2a22f4 | 236 | |
0245f82d | 237 | m4_define([b4_c_knr_formal_name], |
4a2a22f4 AD |
238 | [$2]) |
239 | ||
240 | ||
0245f82d AD |
241 | # b4_c_knr_formal_decls([DECL1, NAME1], ...) |
242 | # ------------------------------------------ | |
4a2a22f4 | 243 | # Output the K&R argument declarations. |
0245f82d AD |
244 | m4_define([b4_c_knr_formal_decls], |
245 | [m4_map_sep([b4_c_knr_formal_decl], | |
4a2a22f4 AD |
246 | [ |
247 | ], | |
248 | [$@])]) | |
249 | ||
0245f82d AD |
250 | m4_define([b4_c_knr_formal_decl], |
251 | [ $1;]) | |
21964f43 AD |
252 | |
253 | ||
254 | ||
0245f82d AD |
255 | ## ------------------------------------------------------------ ## |
256 | ## Declaring (prototyping) C functions in both K&R and ANSI-C. ## | |
257 | ## ------------------------------------------------------------ ## | |
21964f43 AD |
258 | |
259 | ||
0245f82d AD |
260 | # b4_c_function_decl(NAME, RETURN-VALUE, [DECL1, NAME1], ...) |
261 | # ----------------------------------------------------------- | |
262 | # Declare the function NAME. | |
263 | m4_define([b4_c_function_decl], | |
264 | [#if defined (__STDC__) || defined (__cplusplus) | |
265 | b4_c_ansi_function_decl($@) | |
266 | #else | |
267 | $2 $1 (); | |
268 | #endif[]dnl | |
269 | ]) | |
21964f43 AD |
270 | |
271 | ||
0245f82d AD |
272 | # b4_c_ansi_function_decl(NAME, RETURN-VALUE, [DECL1, NAME1], ...) |
273 | # ---------------------------------------------------------------- | |
274 | # Declare the function NAME. | |
275 | m4_define([b4_c_ansi_function_decl], | |
276 | [$2 $1 (b4_c_ansi_formals(m4_shiftn(2, $@)));[]dnl | |
277 | ]) | |
278 | ||
279 | ||
280 | ||
281 | ||
282 | ## --------------------- ## | |
283 | ## Calling C functions. ## | |
284 | ## --------------------- ## | |
285 | ||
286 | ||
287 | # b4_c_function_call(NAME, RETURN-VALUE, [DECL1, NAME1], ...) | |
288 | # ----------------------------------------------------------- | |
289 | # Call the function NAME with arguments NAME1, NAME2 etc. | |
290 | m4_define([b4_c_function_call], | |
291 | [$1 (b4_c_args(m4_shiftn(2, $@)))[]dnl | |
292 | ]) | |
293 | ||
294 | ||
295 | # b4_c_args([DECL1, NAME1], ...) | |
296 | # ------------------------------ | |
297 | # Output the arguments NAME1, NAME2... | |
298 | m4_define([b4_c_args], | |
299 | [m4_map_sep([b4_c_arg], [, ], [$@])]) | |
300 | ||
301 | m4_define([b4_c_arg], | |
302 | [$2]) | |
437c2d80 AD |
303 | |
304 | ||
305 | ## ----------- ## | |
306 | ## Synclines. ## | |
307 | ## ----------- ## | |
308 | ||
309 | ||
310 | # b4_syncline(LINE, FILE) | |
311 | # ----------------------- | |
312 | m4_define([b4_syncline], | |
313 | [m4_if(b4_synclines_flag, 1, | |
314 | [[#]line $1 "$2"])]) |