source: EcnlProtoTool/trunk/tools/share/bison/c.m4@ 270

Last change on this file since 270 was 270, checked in by coas-nagasima, 7 years ago

mruby版ECNLプロトタイピング・ツールを追加

File size: 12.6 KB
Line 
1 -*- Autoconf -*-
2
3# C M4 Macros for Bison.
4# Copyright (C) 2002, 2004, 2005, 2006, 2007, 2008 Free Software
5# Foundation, Inc.
6
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation, either version 3 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20## ---------------- ##
21## Identification. ##
22## ---------------- ##
23
24# b4_comment(TEXT)
25# ----------------
26m4_define([b4_comment], [/* m4_bpatsubst([$1], [
27], [
28 ]) */])
29
30# b4_identification
31# -----------------
32# Depends on individual skeletons to define b4_pure_flag, b4_push_flag, or
33# b4_pull_flag if they use the values of the %define variables api.pure or
34# api.push_pull.
35m4_define([b4_identification],
36[[/* Identify Bison output. */
37#define YYBISON 1
38
39/* Bison version. */
40#define YYBISON_VERSION "]b4_version["
41
42/* Skeleton name. */
43#define YYSKELETON_NAME ]b4_skeleton[]m4_ifdef([b4_pure_flag], [[
44
45/* Pure parsers. */
46#define YYPURE ]b4_pure_flag])[]m4_ifdef([b4_push_flag], [[
47
48/* Push parsers. */
49#define YYPUSH ]b4_push_flag])[]m4_ifdef([b4_pull_flag], [[
50
51/* Pull parsers. */
52#define YYPULL ]b4_pull_flag])[
53
54/* Using locations. */
55#define YYLSP_NEEDED ]b4_locations_flag[
56]])
57
58
59## ---------------- ##
60## Default values. ##
61## ---------------- ##
62
63# If the %union is not named, its name is YYSTYPE.
64m4_define_default([b4_union_name], [YYSTYPE])
65
66# If the %name-prefix is not given, it is yy.
67m4_define_default([b4_prefix], [yy])
68
69## ------------------------ ##
70## Pure/impure interfaces. ##
71## ------------------------ ##
72
73# b4_user_args
74# ------------
75m4_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.
83m4_define([b4_parse_param],
84b4_parse_param)
85
86
87# b4_parse_param_for(DECL, FORMAL, BODY)
88# ---------------------------------------
89# Iterate over the user parameters, binding the declaration to DECL,
90# the formal name to FORMAL, and evaluating the BODY.
91m4_define([b4_parse_param_for],
92[m4_foreach([$1_$2], m4_defn([b4_parse_param]),
93[m4_pushdef([$1], m4_unquote(m4_car($1_$2)))dnl
94m4_pushdef([$2], m4_shift($1_$2))dnl
95$3[]dnl
96m4_popdef([$2])dnl
97m4_popdef([$1])dnl
98])])
99
100# b4_parse_param_use
101# ------------------
102# `YYUSE' all the parse-params.
103m4_define([b4_parse_param_use],
104[b4_parse_param_for([Decl], [Formal], [ YYUSE (Formal);
105])dnl
106])
107
108
109## ------------ ##
110## Data Types. ##
111## ------------ ##
112
113# b4_int_type(MIN, MAX)
114# ---------------------
115# Return the smallest int type able to handle numbers ranging from
116# MIN to MAX (included).
117m4_define([b4_int_type],
118[m4_if(b4_ints_in($@, [0], [255]), [1], [unsigned char],
119 b4_ints_in($@, [-128], [127]), [1], [signed char],
120
121 b4_ints_in($@, [0], [65535]), [1], [unsigned short int],
122 b4_ints_in($@, [-32768], [32767]), [1], [short int],
123
124 m4_eval([0 <= $1]), [1], [unsigned int],
125
126 [int])])
127
128
129# b4_int_type_for(NAME)
130# ---------------------
131# Return the smallest int type able to handle numbers ranging from
132# `NAME_min' to `NAME_max' (included).
133m4_define([b4_int_type_for],
134[b4_int_type($1_min, $1_max)])
135
136
137
138## ---------##
139## Values. ##
140## ---------##
141
142# b4_null
143---------
144# Return a null pointer constant. NULL infringes on the user name
145# space in C, so use 0 rather than NULL.
146m4_define([b4_null], [0])
147
148
149
150
151## ------------------------- ##
152## Assigning token numbers. ##
153## ------------------------- ##
154
155# b4_token_define(TOKEN-NAME, TOKEN-NUMBER)
156# -----------------------------------------
157# Output the definition of this token as #define.
158m4_define([b4_token_define],
159[#define $1 $2
160])
161
162
163# b4_token_defines(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER)
164# -------------------------------------------------------
165# Output the definition of the tokens (if there are) as #defines.
166m4_define([b4_token_defines],
167[m4_if([$#$1], [1], [],
168[/* Tokens. */
169m4_map([b4_token_define], [$@])])
170])
171
172
173# b4_token_enum(TOKEN-NAME, TOKEN-NUMBER)
174# ---------------------------------------
175# Output the definition of this token as an enum.
176m4_define([b4_token_enum],
177[$1 = $2])
178
179
180# b4_token_enums(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER)
181# -----------------------------------------------------
182# Output the definition of the tokens (if there are) as enums.
183m4_define([b4_token_enums],
184[m4_if([$#$1], [1], [],
185[/* Tokens. */
186#ifndef YYTOKENTYPE
187# define YYTOKENTYPE
188 /* Put the tokens into the symbol table, so that GDB and other debuggers
189 know about them. */
190 enum yytokentype {
191m4_map_sep([ b4_token_enum], [,
192],
193 [$@])
194 };
195#endif
196])])
197
198
199# b4_token_enums_defines(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER)
200# -------------------------------------------------------------
201# Output the definition of the tokens (if there are any) as enums and, if POSIX
202# Yacc is enabled, as #defines.
203m4_define([b4_token_enums_defines],
204[b4_token_enums($@)b4_yacc_if([b4_token_defines($@)], [])
205])
206
207
208
209## --------------------------------------------- ##
210## Defining C functions in both K&R and ANSI-C. ##
211## --------------------------------------------- ##
212
213
214# b4_modern_c
215# -----------
216# A predicate useful in #if to determine whether C is ancient or modern.
217#
218# If __STDC__ is defined, the compiler is modern. IBM xlc 7.0 when run
219# as 'cc' doesn't define __STDC__ (or __STDC_VERSION__) for pedantic
220# reasons, but it defines __C99__FUNC__ so check that as well.
221# Microsoft C normally doesn't define these macros, but it defines _MSC_VER.
222# Consider a C++ compiler to be modern if it defines __cplusplus.
223#
224m4_define([b4_c_modern],
225 [[(defined __STDC__ || defined __C99__FUNC__ \
226 || defined __cplusplus || defined _MSC_VER)]])
227
228# b4_c_function_def(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
229# ----------------------------------------------------------
230# Declare the function NAME.
231m4_define([b4_c_function_def],
232[#if b4_c_modern
233b4_c_ansi_function_def($@)
234#else
235$2
236$1 (b4_c_knr_formal_names(m4_shift2($@)))
237b4_c_knr_formal_decls(m4_shift2($@))
238#endif[]dnl
239])
240
241
242# b4_c_ansi_function_def(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
243# ---------------------------------------------------------------
244# Declare the function NAME in ANSI.
245m4_define([b4_c_ansi_function_def],
246[$2
247$1 (b4_c_ansi_formals(m4_shift2($@)))[]dnl
248])
249
250
251# b4_c_ansi_formals([DECL1, NAME1], ...)
252# --------------------------------------
253# Output the arguments ANSI-C definition.
254m4_define([b4_c_ansi_formals],
255[m4_if([$#], [0], [void],
256 [$#$1], [1], [void],
257 [m4_map_sep([b4_c_ansi_formal], [, ], [$@])])])
258
259m4_define([b4_c_ansi_formal],
260[$1])
261
262
263# b4_c_knr_formal_names([DECL1, NAME1], ...)
264# ------------------------------------------
265# Output the argument names.
266m4_define([b4_c_knr_formal_names],
267[m4_map_sep([b4_c_knr_formal_name], [, ], [$@])])
268
269m4_define([b4_c_knr_formal_name],
270[$2])
271
272
273# b4_c_knr_formal_decls([DECL1, NAME1], ...)
274# ------------------------------------------
275# Output the K&R argument declarations.
276m4_define([b4_c_knr_formal_decls],
277[m4_map_sep([b4_c_knr_formal_decl],
278 [
279],
280 [$@])])
281
282m4_define([b4_c_knr_formal_decl],
283[ $1;])
284
285
286
287## ------------------------------------------------------------ ##
288## Declaring (prototyping) C functions in both K&R and ANSI-C. ##
289## ------------------------------------------------------------ ##
290
291
292# b4_c_function_decl(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
293# -----------------------------------------------------------
294# Declare the function NAME.
295m4_define([b4_c_function_decl],
296[#if defined __STDC__ || defined __cplusplus
297b4_c_ansi_function_decl($@)
298#else
299$2 $1 ();
300#endif[]dnl
301])
302
303
304# b4_c_ansi_function_decl(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
305# ----------------------------------------------------------------
306# Declare the function NAME.
307m4_define([b4_c_ansi_function_decl],
308[$2 $1 (b4_c_ansi_formals(m4_shift2($@)));[]dnl
309])
310
311
312
313
314## --------------------- ##
315## Calling C functions. ##
316## --------------------- ##
317
318
319# b4_c_function_call(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
320# -----------------------------------------------------------
321# Call the function NAME with arguments NAME1, NAME2 etc.
322m4_define([b4_c_function_call],
323[$1 (b4_c_args(m4_shift2($@)))[]dnl
324])
325
326
327# b4_c_args([DECL1, NAME1], ...)
328# ------------------------------
329# Output the arguments NAME1, NAME2...
330m4_define([b4_c_args],
331[m4_map_sep([b4_c_arg], [, ], [$@])])
332
333m4_define([b4_c_arg],
334[$2])
335
336
337## ----------- ##
338## Synclines. ##
339## ----------- ##
340
341# b4_sync_start(LINE, FILE)
342# -----------------------
343m4_define([b4_sync_start], [[#]line $1 $2])
344
345
346## -------------- ##
347## User actions. ##
348## -------------- ##
349
350# b4_case(LABEL, STATEMENTS)
351# --------------------------
352m4_define([b4_case],
353[ case $1:
354$2
355 break;])
356
357# b4_symbol_actions(FILENAME, LINENO,
358# SYMBOL-TAG, SYMBOL-NUM,
359# SYMBOL-ACTION, SYMBOL-TYPENAME)
360# -------------------------------------------------
361m4_define([b4_symbol_actions],
362[m4_pushdef([b4_dollar_dollar],
363 [m4_ifval([$6], [(yyvaluep->$6)], [(*yyvaluep)])])dnl
364m4_pushdef([b4_at_dollar], [(*yylocationp)])dnl
365 case $4: /* $3 */
366b4_syncline([$2], [$1])
367 $5;
368b4_syncline([@oline@], [@ofile@])
369 break;
370m4_popdef([b4_at_dollar])dnl
371m4_popdef([b4_dollar_dollar])dnl
372])
373
374
375# b4_yydestruct_generate(FUNCTION-DECLARATOR)
376# -------------------------------------------
377# Generate the "yydestruct" function, which declaration is issued using
378# FUNCTION-DECLARATOR, which may be "b4_c_ansi_function_def" for ISO C
379# or "b4_c_function_def" for K&R.
380m4_define_default([b4_yydestruct_generate],
381[[/*-----------------------------------------------.
382| Release the memory associated to this symbol. |
383`-----------------------------------------------*/
384
385/*ARGSUSED*/
386]$1([yydestruct],
387 [static void],
388 [[const char *yymsg], [yymsg]],
389 [[int yytype], [yytype]],
390 [[YYSTYPE *yyvaluep], [yyvaluep]][]dnl
391b4_locations_if( [, [[YYLTYPE *yylocationp], [yylocationp]]])[]dnl
392m4_ifset([b4_parse_param], [, b4_parse_param]))[
393{
394 YYUSE (yyvaluep);
395]b4_locations_if([ YYUSE (yylocationp);
396])dnl
397b4_parse_param_use[]dnl
398[
399 if (!yymsg)
400 yymsg = "Deleting";
401 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
402
403 switch (yytype)
404 {
405]m4_map([b4_symbol_actions], m4_defn([b4_symbol_destructors]))[
406 default:
407 break;
408 }
409}]dnl
410])
411
412
413# b4_yy_symbol_print_generate(FUNCTION-DECLARATOR)
414# ------------------------------------------------
415# Generate the "yy_symbol_print" function, which declaration is issued using
416# FUNCTION-DECLARATOR, which may be "b4_c_ansi_function_def" for ISO C
417# or "b4_c_function_def" for K&R.
418m4_define_default([b4_yy_symbol_print_generate],
419[[
420/*--------------------------------.
421| Print this symbol on YYOUTPUT. |
422`--------------------------------*/
423
424/*ARGSUSED*/
425]$1([yy_symbol_value_print],
426 [static void],
427 [[FILE *yyoutput], [yyoutput]],
428 [[int yytype], [yytype]],
429 [[YYSTYPE const * const yyvaluep], [yyvaluep]][]dnl
430b4_locations_if([, [[YYLTYPE const * const yylocationp], [yylocationp]]])[]dnl
431m4_ifset([b4_parse_param], [, b4_parse_param]))[
432{
433 if (!yyvaluep)
434 return;
435]b4_locations_if([ YYUSE (yylocationp);
436])dnl
437b4_parse_param_use[]dnl
438[# ifdef YYPRINT
439 if (yytype < YYNTOKENS)
440 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
441# else
442 YYUSE (yyoutput);
443# endif
444 switch (yytype)
445 {
446]m4_map([b4_symbol_actions], m4_defn([b4_symbol_printers]))dnl
447[ default:
448 break;
449 }
450}
451
452
453/*--------------------------------.
454| Print this symbol on YYOUTPUT. |
455`--------------------------------*/
456
457]$1([yy_symbol_print],
458 [static void],
459 [[FILE *yyoutput], [yyoutput]],
460 [[int yytype], [yytype]],
461 [[YYSTYPE const * const yyvaluep], [yyvaluep]][]dnl
462b4_locations_if([, [[YYLTYPE const * const yylocationp], [yylocationp]]])[]dnl
463m4_ifset([b4_parse_param], [, b4_parse_param]))[
464{
465 if (yytype < YYNTOKENS)
466 YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
467 else
468 YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
469
470]b4_locations_if([ YY_LOCATION_PRINT (yyoutput, *yylocationp);
471 YYFPRINTF (yyoutput, ": ");
472])dnl
473[ yy_symbol_value_print (yyoutput, yytype, yyvaluep]dnl
474b4_locations_if([, yylocationp])[]b4_user_args[);
475 YYFPRINTF (yyoutput, ")");
476}]dnl
477])
Note: See TracBrowser for help on using the repository browser.