]> git.saurik.com Git - bison.git/blame - data/java.m4
tests: c++: fix a C++03 conformance issue
[bison.git] / data / java.m4
CommitLineData
8405b70c
PB
1 -*- Autoconf -*-
2
3# Java language support for Bison
4
3209eb1c 5# Copyright (C) 2007-2015 Free Software Foundation, Inc.
8405b70c 6
f16b0819 7# This program is free software: you can redistribute it and/or modify
8405b70c 8# it under the terms of the GNU General Public License as published by
f16b0819 9# the Free Software Foundation, either version 3 of the License, or
8405b70c 10# (at your option) any later version.
f16b0819 11#
8405b70c
PB
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.
f16b0819 16#
8405b70c 17# You should have received a copy of the GNU General Public License
f16b0819 18# along with this program. If not, see <http://www.gnu.org/licenses/>.
8405b70c 19
cd735a8c 20m4_include(b4_pkgdatadir/[c-like.m4])
8405b70c 21
8405b70c 22
e254a580 23# b4_list2(LIST1, LIST2)
6f0a6f27 24# ----------------------
e254a580
DJ
25# Join two lists with a comma if necessary.
26m4_define([b4_list2],
11707b2b 27 [$1[]m4_ifval(m4_quote($1), [m4_ifval(m4_quote($2), [[, ]])])[]$2])
e254a580
DJ
28
29
30# b4_percent_define_get3(DEF, PRE, POST, NOT)
31# -------------------------------------------
32# Expand to the value of DEF surrounded by PRE and POST if it's %define'ed,
33# otherwise NOT.
34m4_define([b4_percent_define_get3],
11707b2b
AD
35 [m4_ifval(m4_quote(b4_percent_define_get([$1])),
36 [$2[]b4_percent_define_get([$1])[]$3], [$4])])
e254a580
DJ
37
38
39
8405b70c
PB
40# b4_flag_value(BOOLEAN-FLAG)
41# ---------------------------
42m4_define([b4_flag_value], [b4_flag_if([$1], [true], [false])])
43
44
45# b4_public_if(TRUE, FALSE)
46# -------------------------
c1d19e10 47b4_percent_define_default([[public]], [[false]])
8405b70c
PB
48m4_define([b4_public_if],
49[b4_percent_define_flag_if([public], [$1], [$2])])
50
8405b70c
PB
51
52# b4_abstract_if(TRUE, FALSE)
53# ---------------------------
01b477c6 54b4_percent_define_default([[abstract]], [[false]])
8405b70c 55m4_define([b4_abstract_if],
01b477c6
PB
56[b4_percent_define_flag_if([abstract], [$1], [$2])])
57
58
e254a580
DJ
59# b4_final_if(TRUE, FALSE)
60# ---------------------------
61b4_percent_define_default([[final]], [[false]])
62m4_define([b4_final_if],
63[b4_percent_define_flag_if([final], [$1], [$2])])
64
65
66# b4_strictfp_if(TRUE, FALSE)
67# ---------------------------
68b4_percent_define_default([[strictfp]], [[false]])
69m4_define([b4_strictfp_if],
70[b4_percent_define_flag_if([strictfp], [$1], [$2])])
71
72
01b477c6
PB
73# b4_lexer_if(TRUE, FALSE)
74# ------------------------
75m4_define([b4_lexer_if],
76[b4_percent_code_ifdef([[lexer]], [$1], [$2])])
8405b70c
PB
77
78
79# b4_identification
80# -----------------
81m4_define([b4_identification],
e254a580 82[ /** Version number for the Bison executable that generated this parser. */
8405b70c
PB
83 public static final String bisonVersion = "b4_version";
84
85 /** Name of the skeleton that generated this parser. */
86 public static final String bisonSkeleton = b4_skeleton;
87])
88
89
90## ------------ ##
91## Data types. ##
92## ------------ ##
93
94# b4_int_type(MIN, MAX)
95# ---------------------
96# Return the smallest int type able to handle numbers ranging from
97# MIN to MAX (included).
98m4_define([b4_int_type],
99[m4_if(b4_ints_in($@, [-128], [127]), [1], [byte],
100 b4_ints_in($@, [-32768], [32767]), [1], [short],
11707b2b 101 [int])])
8405b70c
PB
102
103# b4_int_type_for(NAME)
104# ---------------------
105# Return the smallest int type able to handle numbers ranging from
45eebca4 106# 'NAME_min' to 'NAME_max' (included).
8405b70c
PB
107m4_define([b4_int_type_for],
108[b4_int_type($1_min, $1_max)])
109
110# b4_null
111# -------
112m4_define([b4_null], [null])
113
114
2c1bf9bd
AD
115# b4_typed_parser_table_define(TYPE, NAME, DATA, COMMENT)
116# -------------------------------------------------------
117m4_define([b4_typed_parser_table_define],
118[m4_ifval([$4], [b4_comment([$4])
119 ])dnl
120[private static final ]$1[ yy$2_[] = yy$2_init();
121 private static final ]$1[[] yy$2_init()
09ccae9b
DJ
122 {
123 return new ]$1[[]
124 {
125 ]$3[
126 };
127 }]])
128
129
2c1bf9bd
AD
130# b4_integral_parser_table_define(NAME, DATA, COMMENT)
131#-----------------------------------------------------
132m4_define([b4_integral_parser_table_define],
133[b4_typed_parser_table_define([b4_int_type_for([$2])], [$1], [$2], [$3])])
09ccae9b
DJ
134
135
8405b70c
PB
136## ------------------------- ##
137## Assigning token numbers. ##
138## ------------------------- ##
139
e3990e3c
AD
140# b4_token_enum(TOKEN-NUM)
141# ------------------------
8405b70c
PB
142# Output the definition of this token as an enum.
143m4_define([b4_token_enum],
e3990e3c
AD
144[b4_token_format([ /** Token number, to be returned by the scanner. */
145 static final int %s = %s;
146], [$1])])
8405b70c 147
e3990e3c
AD
148# b4_token_enums
149# --------------
8405b70c
PB
150# Output the definition of the tokens (if there are) as enums.
151m4_define([b4_token_enums],
e3990e3c
AD
152[b4_any_token_visible_if([/* Tokens. */
153b4_symbol_foreach([b4_token_enum])])])
8405b70c
PB
154
155# b4-case(ID, CODE)
156# -----------------
157# We need to fool Java's stupid unreachable code detection.
158m4_define([b4_case], [ case $1:
159 if (yyn == $1)
160 $2;
161 break;
162 ])
163
ca2a6d15
PH
164# b4_predicate_case(LABEL, CONDITIONS)
165# ------------------------------------
166m4_define([b4_predicate_case], [ case $1:
167 if (! ($2)) YYERROR;
168 break;
169 ])
170
8405b70c 171
6ce4b4ff
AD
172## -------- ##
173## Checks. ##
174## -------- ##
175
176b4_percent_define_check_kind([[api.value.type]], [code], [deprecated])
177
178b4_percent_define_check_kind([[annotations]], [code], [deprecated])
179b4_percent_define_check_kind([[extends]], [code], [deprecated])
180b4_percent_define_check_kind([[implements]], [code], [deprecated])
181b4_percent_define_check_kind([[init_throws]], [code], [deprecated])
182b4_percent_define_check_kind([[lex_throws]], [code], [deprecated])
183b4_percent_define_check_kind([[parser_class_name]], [code], [deprecated])
184b4_percent_define_check_kind([[throws]], [code], [deprecated])
185
186
187
8405b70c
PB
188## ---------------- ##
189## Default values. ##
190## ---------------- ##
191
4119d1ea
AD
192m4_define([b4_yystype], [b4_percent_define_get([[api.value.type]])])
193b4_percent_define_default([[api.value.type]], [[Object]])
8405b70c 194
e254a580
DJ
195# %name-prefix
196m4_define_default([b4_prefix], [[YY]])
197
1979121c 198b4_percent_define_default([[parser_class_name]], [b4_prefix[]Parser])
8405b70c
PB
199m4_define([b4_parser_class_name], [b4_percent_define_get([[parser_class_name]])])
200
1979121c 201b4_percent_define_default([[lex_throws]], [[java.io.IOException]])
8405b70c
PB
202m4_define([b4_lex_throws], [b4_percent_define_get([[lex_throws]])])
203
1979121c 204b4_percent_define_default([[throws]], [])
8405b70c
PB
205m4_define([b4_throws], [b4_percent_define_get([[throws]])])
206
1979121c
DJ
207b4_percent_define_default([[init_throws]], [])
208m4_define([b4_init_throws], [b4_percent_define_get([[init_throws]])])
209
f6b561d9 210b4_percent_define_default([[api.location.type]], [Location])
db8ab2be 211m4_define([b4_location_type], [b4_percent_define_get([[api.location.type]])])
8405b70c 212
715978d7 213b4_percent_define_default([[api.position.type]], [Position])
7287be84 214m4_define([b4_position_type], [b4_percent_define_get([[api.position.type]])])
8405b70c
PB
215
216
217## ----------------- ##
218## Semantic Values. ##
219## ----------------- ##
220
221
222# b4_lhs_value([TYPE])
223# --------------------
224# Expansion of $<TYPE>$.
225m4_define([b4_lhs_value], [yyval])
226
227
228# b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
229# --------------------------------------
230# Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
231# symbols on RHS.
232#
233# In this simple implementation, %token and %type have class names
234# between the angle brackets.
235m4_define([b4_rhs_value],
01b477c6 236[(m4_ifval($3, [($3)])[](yystack.valueAt ($1-($2))))])
8405b70c
PB
237
238# b4_lhs_location()
239# -----------------
240# Expansion of @$.
241m4_define([b4_lhs_location],
242[(yyloc)])
243
244
245# b4_rhs_location(RULE-LENGTH, NUM)
246# ---------------------------------
247# Expansion of @NUM, where the current rule has RULE-LENGTH symbols
248# on RHS.
249m4_define([b4_rhs_location],
250[yystack.locationAt ($1-($2))])
251
252
253# b4_lex_param
254# b4_parse_param
255# --------------
256# If defined, b4_lex_param arrives double quoted, but below we prefer
257# it to be single quoted. Same for b4_parse_param.
258
259# TODO: should be in bison.m4
1979121c
DJ
260m4_define_default([b4_lex_param], [[]])
261m4_define([b4_lex_param], b4_lex_param)
262m4_define([b4_parse_param], b4_parse_param)
8405b70c
PB
263
264# b4_lex_param_decl
91be6b28 265# -----------------
8405b70c
PB
266# Extra formal arguments of the constructor.
267m4_define([b4_lex_param_decl],
268[m4_ifset([b4_lex_param],
269 [b4_remove_comma([$1],
11707b2b
AD
270 b4_param_decls(b4_lex_param))],
271 [$1])])
8405b70c 272
01b477c6 273m4_define([b4_param_decls],
11707b2b 274 [m4_map([b4_param_decl], [$@])])
01b477c6 275m4_define([b4_param_decl], [, $1])
8405b70c 276
e254a580 277m4_define([b4_remove_comma], [m4_ifval(m4_quote($1), [$1, ], [])m4_shift2($@)])
8405b70c
PB
278
279
280
281# b4_parse_param_decl
282# -------------------
283# Extra formal arguments of the constructor.
284m4_define([b4_parse_param_decl],
285[m4_ifset([b4_parse_param],
286 [b4_remove_comma([$1],
11707b2b
AD
287 b4_param_decls(b4_parse_param))],
288 [$1])])
8405b70c 289
01b477c6
PB
290
291
292# b4_lex_param_call
91be6b28 293# -----------------
01b477c6
PB
294# Delegating the lexer parameters to the lexer constructor.
295m4_define([b4_lex_param_call],
296 [m4_ifset([b4_lex_param],
11707b2b
AD
297 [b4_remove_comma([$1],
298 b4_param_calls(b4_lex_param))],
299 [$1])])
01b477c6 300m4_define([b4_param_calls],
11707b2b 301 [m4_map([b4_param_call], [$@])])
01b477c6 302m4_define([b4_param_call], [, $2])
8405b70c
PB
303
304
305
306# b4_parse_param_cons
307# -------------------
308# Extra initialisations of the constructor.
309m4_define([b4_parse_param_cons],
310 [m4_ifset([b4_parse_param],
11707b2b 311 [b4_constructor_calls(b4_parse_param)])])
01b477c6 312
8405b70c 313m4_define([b4_constructor_calls],
11707b2b 314 [m4_map([b4_constructor_call], [$@])])
8405b70c 315m4_define([b4_constructor_call],
11707b2b
AD
316 [this.$2 = $2;
317 ])
8405b70c 318
01b477c6
PB
319
320
8405b70c
PB
321# b4_parse_param_vars
322# -------------------
323# Extra instance variables.
324m4_define([b4_parse_param_vars],
325 [m4_ifset([b4_parse_param],
11707b2b 326 [
8405b70c
PB
327 /* User arguments. */
328b4_var_decls(b4_parse_param)])])
01b477c6 329
8405b70c 330m4_define([b4_var_decls],
11707b2b 331 [m4_map_sep([b4_var_decl], [
8405b70c
PB
332], [$@])])
333m4_define([b4_var_decl],
11707b2b 334 [ protected final $1;])
8405b70c 335
01b477c6
PB
336
337
8405b70c
PB
338# b4_maybe_throws(THROWS)
339# -----------------------
340# Expand to either an empty string or "throws THROWS".
341m4_define([b4_maybe_throws],
11707b2b 342 [m4_ifval($1, [throws $1])])