]> git.saurik.com Git - bison.git/blob - data/c.m4
Update.
[bison.git] / data / c.m4
1 m4_divert(-1) -*- Autoconf -*-
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
22 ## ---------------- ##
23 ## Identification. ##
24 ## ---------------- ##
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,
32 Copyright (C) $2 Free Software Foundation, Inc.
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,
47 Boston, MA 02111-1307, USA. */])
48
49
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
89 ## ------------ ##
90 ## Data Types. ##
91 ## ------------ ##
92
93
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],
107 b4_ints_in($@, [-128], [127]), [1], [signed char],
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
116
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)])
123
124
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
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. */
174 #ifndef YYTOKENTYPE
175 # define YYTOKENTYPE
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 };
183 #endif
184 m4_map([b4_token_define], [$@])
185 ])
186 ])
187
188
189
190 ## --------------------------------------------- ##
191 ## Defining C functions in both K&R and ANSI-C. ##
192 ## --------------------------------------------- ##
193
194
195 # b4_c_function_def(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
196 # ----------------------------------------------------------
197 # Declare the function NAME.
198 m4_define([b4_c_function_def],
199 [#if defined (__STDC__) || defined (__cplusplus)
200 b4_c_ansi_function_def($@)
201 #else
202 $2
203 $1 (b4_c_knr_formal_names(m4_shiftn(2, $@)))
204 b4_c_knr_formal_decls(m4_shiftn(2, $@))
205 #endif[]dnl
206 ])
207
208
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 # --------------------------------------
220 # Output the arguments ANSI-C definition.
221 m4_define([b4_c_ansi_formals],
222 [m4_case([$@],
223 [], [void],
224 [[]], [void],
225 [m4_map_sep([b4_c_ansi_formal], [, ], [$@])])])
226
227 m4_define([b4_c_ansi_formal],
228 [$1])
229
230
231 # b4_c_knr_formal_names([DECL1, NAME1], ...)
232 # ------------------------------------------
233 # Output the argument names.
234 m4_define([b4_c_knr_formal_names],
235 [m4_map_sep([b4_c_knr_formal_name], [, ], [$@])])
236
237 m4_define([b4_c_knr_formal_name],
238 [$2])
239
240
241 # b4_c_knr_formal_decls([DECL1, NAME1], ...)
242 # ------------------------------------------
243 # Output the K&R argument declarations.
244 m4_define([b4_c_knr_formal_decls],
245 [m4_map_sep([b4_c_knr_formal_decl],
246 [
247 ],
248 [$@])])
249
250 m4_define([b4_c_knr_formal_decl],
251 [ $1;])
252
253
254
255 ## ------------------------------------------------------------ ##
256 ## Declaring (prototyping) C functions in both K&R and ANSI-C. ##
257 ## ------------------------------------------------------------ ##
258
259
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 ])
270
271
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])