]>
Commit | Line | Data |
---|---|---|
08af01c2 | 1 | -*- Autoconf -*- |
cf147260 AD |
2 | |
3 | # C++ skeleton for Bison | |
4 | ||
3209eb1c | 5 | # Copyright (C) 2002-2015 Free Software Foundation, Inc. |
cf147260 | 6 | |
f16b0819 | 7 | # This program is free software: you can redistribute it and/or modify |
cf147260 | 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 |
cf147260 | 10 | # (at your option) any later version. |
f16b0819 | 11 | # |
cf147260 AD |
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 | # |
cf147260 | 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/>. |
cf147260 | 19 | |
827bc59c AD |
20 | # Sanity checks, before defaults installed by c.m4. |
21 | b4_percent_define_ifdef([[api.value.union.name]], | |
22 | [b4_complain_at(b4_percent_define_get_loc([[api.value.union.name]]), | |
23 | [named %union is invalid in C++])]) | |
24 | ||
3953ed88 AD |
25 | m4_include(b4_pkgdatadir/[c.m4]) |
26 | ||
38de4e57 AD |
27 | # b4_comment(TEXT, [PREFIX]) |
28 | # -------------------------- | |
29 | # Put TEXT in comment. Prefix all the output lines with PREFIX. | |
30 | m4_define([b4_comment], | |
31 | [b4_comment_([$1], [$2// ], [$2// ])]) | |
32 | ||
07e65a77 AD |
33 | ## -------- ## |
34 | ## Checks. ## | |
35 | ## -------- ## | |
36 | ||
37 | b4_percent_define_check_kind([api.namespace], [code], [deprecated]) | |
6ce4b4ff | 38 | b4_percent_define_check_kind([parser_class_name], [code], [deprecated]) |
38de4e57 | 39 | |
cf147260 AD |
40 | ## ---------------- ## |
41 | ## Default values. ## | |
42 | ## ---------------- ## | |
43 | ||
a4e25e1d | 44 | b4_percent_define_default([[parser_class_name]], [[parser]]) |
7789b6e3 AD |
45 | |
46 | # Don't do that so that we remember whether we're using a user | |
47 | # request, or the default value. | |
48 | # | |
db8ab2be | 49 | # b4_percent_define_default([[api.location.type]], [[location]]) |
7789b6e3 | 50 | |
a4e25e1d | 51 | b4_percent_define_default([[filename_type]], [[std::string]]) |
07e65a77 | 52 | # Make it a warning for those who used betas of Bison 3.0. |
171ad99d | 53 | b4_percent_define_default([[api.namespace]], m4_defn([b4_prefix])) |
67501061 | 54 | |
c1d19e10 | 55 | b4_percent_define_default([[global_tokens_and_yystype]], [[false]]) |
a4e25e1d JD |
56 | b4_percent_define_default([[define_location_comparison]], |
57 | [m4_if(b4_percent_define_get([[filename_type]]), | |
c1d19e10 | 58 | [std::string], [[true]], [[false]])]) |
cf147260 AD |
59 | |
60 | ||
67501061 | 61 | |
793fbca5 JD |
62 | ## ----------- ## |
63 | ## Namespace. ## | |
64 | ## ----------- ## | |
65 | ||
67501061 AD |
66 | m4_define([b4_namespace_ref], [b4_percent_define_get([[api.namespace]])]) |
67 | ||
793fbca5 | 68 | |
45eebca4 AD |
69 | # Don't permit an empty b4_namespace_ref. Any '::parser::foo' appended to it |
70 | # would compile as an absolute reference with 'parser' in the global namespace. | |
793fbca5 JD |
71 | # b4_namespace_open would open an anonymous namespace and thus establish |
72 | # internal linkage. This would compile. However, it's cryptic, and internal | |
73 | # linkage for the parser would be specified in all translation units that | |
74 | # include the header, which is always generated. If we ever need to permit | |
75 | # internal linkage somehow, surely we can find a cleaner approach. | |
76 | m4_if(m4_bregexp(b4_namespace_ref, [^[ ]*$]), [-1], [], | |
67501061 | 77 | [b4_complain_at(b4_percent_define_get_loc([[api.namespace]]), |
793fbca5 JD |
78 | [[namespace reference is empty]])]) |
79 | ||
80 | # Instead of assuming the C++ compiler will do it, Bison should reject any | |
81 | # invalid b4_namepsace_ref that would be converted to a valid | |
82 | # b4_namespace_open. The problem is that Bison doesn't always output | |
83 | # b4_namespace_ref to uncommented code but should reserve the ability to do so | |
84 | # in future releases without risking breaking any existing user grammars. | |
85 | # Specifically, don't allow empty names as b4_namespace_open would just convert | |
86 | # those into anonymous namespaces, and that might tempt some users. | |
87 | m4_if(m4_bregexp(b4_namespace_ref, [::[ ]*::]), [-1], [], | |
67501061 | 88 | [b4_complain_at(b4_percent_define_get_loc([[api.namespace]]), |
793fbca5 JD |
89 | [[namespace reference has consecutive "::"]])]) |
90 | m4_if(m4_bregexp(b4_namespace_ref, [::[ ]*$]), [-1], [], | |
67501061 | 91 | [b4_complain_at(b4_percent_define_get_loc([[api.namespace]]), |
793fbca5 JD |
92 | [[namespace reference has a trailing "::"]])]) |
93 | ||
94 | m4_define([b4_namespace_open], | |
67501061 | 95 | [b4_user_code([b4_percent_define_get_syncline([[api.namespace]]) |
793fbca5 JD |
96 | [namespace ]m4_bpatsubst(m4_dquote(m4_bpatsubst(m4_dquote(b4_namespace_ref), |
97 | [^\(.\)[ ]*::], [\1])), | |
98 | [::], [ { namespace ])[ {]])]) | |
99 | ||
100 | m4_define([b4_namespace_close], | |
67501061 | 101 | [b4_user_code([b4_percent_define_get_syncline([[api.namespace]]) |
4977e0a7 | 102 | m4_bpatsubst(m4_dquote(m4_bpatsubst(m4_dquote(b4_namespace_ref[ ]), |
b987342b | 103 | [^\(.\)[ ]*\(::\)?\([^][:]\|:[^:]\)*], |
793fbca5 | 104 | [\1])), |
b987342b | 105 | [::\([^][:]\|:[^:]\)*], [} ])[} // ]b4_namespace_ref])]) |
793fbca5 JD |
106 | |
107 | ||
e3990e3c AD |
108 | # b4_token_enums |
109 | # -------------- | |
c095d689 | 110 | # Output the definition of the tokens as enums. |
cf147260 | 111 | m4_define([b4_token_enums], |
e3990e3c AD |
112 | [[enum yytokentype |
113 | { | |
114 | ]m4_join([, | |
115 | ], | |
116 | b4_symbol_map([b4_token_enum]))[ | |
117 | };]dnl | |
c095d689 | 118 | ]) |
cf147260 AD |
119 | |
120 | ||
ef51bfa7 AD |
121 | |
122 | ||
cf147260 AD |
123 | ## ----------------- ## |
124 | ## Semantic Values. ## | |
125 | ## ----------------- ## | |
126 | ||
7601a471 AD |
127 | |
128 | ||
129 | # b4_value_type_declare | |
130 | # --------------------- | |
b9e4eb5b | 131 | # Declare semantic_type. |
7601a471 | 132 | m4_define([b4_value_type_declare], |
6574576c | 133 | [b4_value_type_setup[]dnl |
b9e4eb5b | 134 | [ /// Symbol semantic values. |
435575cb AD |
135 | ]m4_bmatch(b4_percent_define_get_kind([[api.value.type]]), |
136 | [code], | |
137 | [[ typedef ]b4_percent_define_get([[api.value.type]])[ semantic_type;]], | |
138 | [m4_bmatch(b4_percent_define_get([[api.value.type]]), | |
139 | [union\|union-directive], | |
6574576c | 140 | [[ union semantic_type |
d2e3c807 | 141 | { |
435575cb AD |
142 | ]b4_user_union_members[ |
143 | };]])])dnl | |
144 | ]) | |
b9e4eb5b AD |
145 | |
146 | ||
4f84717d AD |
147 | # b4_public_types_declare |
148 | # ----------------------- | |
149 | # Define the public types: token, semantic value, location, and so forth. | |
1d6b689b | 150 | # Depending on %define token_lex, may be output in the header or source file. |
4f84717d | 151 | m4_define([b4_public_types_declare], |
5458913a | 152 | [[#ifndef ]b4_api_PREFIX[STYPE |
7601a471 | 153 | ]b4_value_type_declare[ |
4f84717d | 154 | #else |
5458913a | 155 | typedef ]b4_api_PREFIX[STYPE semantic_type; |
4f84717d AD |
156 | #endif]b4_locations_if([ |
157 | /// Symbol locations. | |
f6b561d9 | 158 | typedef b4_percent_define_get([[api.location.type]], |
7789b6e3 | 159 | [[location]]) location_type;])[ |
1d6b689b | 160 | |
ff601366 AD |
161 | /// Syntax errors thrown from user actions. |
162 | struct syntax_error : std::runtime_error | |
163 | { | |
164 | syntax_error (]b4_locations_if([const location_type& l, ])[const std::string& m);]b4_locations_if([ | |
165 | location_type location;])[ | |
166 | }; | |
167 | ||
4f84717d AD |
168 | /// Tokens. |
169 | struct token | |
170 | { | |
e3990e3c | 171 | ]b4_token_enums[ |
4f84717d | 172 | }; |
1d6b689b | 173 | |
26f95f5f | 174 | /// (External) token type, as returned by yylex. |
4f84717d | 175 | typedef token::yytokentype token_type; |
1d6b689b | 176 | |
5422471c | 177 | /// Symbol type: an internal symbol number. |
26f95f5f AD |
178 | typedef int symbol_number_type; |
179 | ||
5422471c AD |
180 | /// The symbol type number to denote an empty symbol. |
181 | enum { empty_symbol = -2 }; | |
182 | ||
26f95f5f AD |
183 | /// Internal symbol number for tokens (subsumed by symbol_number_type). |
184 | typedef ]b4_int_type_for([b4_translate])[ token_number_type; | |
185 | ||
1dbaf37f TR |
186 | /// A complete symbol. |
187 | /// | |
188 | /// Expects its Base type to provide access to the symbol type | |
189 | /// via type_get(). | |
190 | /// | |
191 | /// Provide access to semantic value]b4_locations_if([ and location])[. | |
192 | template <typename Base> | |
193 | struct basic_symbol : Base | |
1d6b689b | 194 | { |
97ae878e AD |
195 | /// Alias to Base. |
196 | typedef Base super_type; | |
197 | ||
1d6b689b | 198 | /// Default constructor. |
b20e797a | 199 | basic_symbol (); |
1d6b689b | 200 | |
1dbaf37f | 201 | /// Copy constructor. |
b20e797a | 202 | basic_symbol (const basic_symbol& other); |
ee9cf8c4 TR |
203 | ]b4_variant_if([[ |
204 | /// Constructor for valueless symbols, and symbols from each type. | |
205 | ]b4_type_foreach([b4_basic_symbol_constructor_declare])], [[ | |
1dbaf37f | 206 | /// Constructor for valueless symbols. |
7fc7df7a | 207 | basic_symbol (typename Base::kind_type t]b4_locations_if([, |
ee9cf8c4 | 208 | const location_type& l])[);]])[ |
1d6b689b | 209 | |
1dbaf37f | 210 | /// Constructor for symbols with semantic value. |
7fc7df7a | 211 | basic_symbol (typename Base::kind_type t, |
b20e797a TR |
212 | const semantic_type& v]b4_locations_if([, |
213 | const location_type& l])[); | |
1d6b689b | 214 | |
8a4ec359 | 215 | /// Destroy the symbol. |
97ae878e | 216 | ~basic_symbol (); |
04816a6f | 217 | |
ee2f4335 AD |
218 | /// Destroy contents, and record that is empty. |
219 | void clear (); | |
220 | ||
5422471c AD |
221 | /// Whether empty. |
222 | bool empty () const; | |
223 | ||
5f87211c | 224 | /// Destructive move, \a s is emptied into this. |
b20e797a | 225 | void move (basic_symbol& s); |
1d6b689b AD |
226 | |
227 | /// The semantic value. | |
228 | semantic_type value;]b4_locations_if([ | |
229 | ||
230 | /// The location. | |
231 | location_type location;])[ | |
7d1aa2d6 AD |
232 | |
233 | private: | |
234 | /// Assignment operator. | |
235 | basic_symbol& operator= (const basic_symbol& other); | |
1d6b689b AD |
236 | }; |
237 | ||
1dbaf37f TR |
238 | /// Type access provider for token (enum) based symbols. |
239 | struct by_type | |
1d6b689b | 240 | { |
1d6b689b | 241 | /// Default constructor. |
b20e797a | 242 | by_type (); |
1d6b689b | 243 | |
1dbaf37f | 244 | /// Copy constructor. |
b20e797a | 245 | by_type (const by_type& other); |
1d6b689b | 246 | |
26f95f5f AD |
247 | /// The symbol type as needed by the constructor. |
248 | typedef token_type kind_type; | |
1d6b689b | 249 | |
26f95f5f AD |
250 | /// Constructor from (external) token numbers. |
251 | by_type (kind_type t); | |
97ae878e | 252 | |
ee2f4335 AD |
253 | /// Record that this symbol is empty. |
254 | void clear (); | |
255 | ||
26f95f5f AD |
256 | /// Steal the symbol type from \a that. |
257 | void move (by_type& that); | |
1d6b689b | 258 | |
26f95f5f | 259 | /// The (internal) type number (corresponding to \a type). |
8a4ec359 | 260 | /// \a empty when empty. |
26f95f5f | 261 | symbol_number_type type_get () const; |
1d6b689b | 262 | |
2b08bceb | 263 | /// The token. |
b20e797a | 264 | token_type token () const; |
1dbaf37f | 265 | |
26f95f5f | 266 | /// The symbol type. |
5422471c AD |
267 | /// \a empty_symbol when empty. |
268 | /// An int, not token_number_type, to be able to store empty_symbol. | |
269 | int type; | |
1d6b689b | 270 | }; |
1dbaf37f TR |
271 | |
272 | /// "External" symbols: returned by the scanner. | |
273 | typedef basic_symbol<by_type> symbol_type; | |
274 | ||
0623bacc | 275 | ]b4_symbol_constructor_declare]) |
4f84717d AD |
276 | |
277 | ||
1d6b689b AD |
278 | # b4_public_types_define |
279 | # ---------------------- | |
280 | # Provide the implementation needed by the public types. | |
281 | m4_define([b4_public_types_define], | |
403febca | 282 | [[ inline |
ff601366 AD |
283 | ]b4_parser_class_name[::syntax_error::syntax_error (]b4_locations_if([const location_type& l, ])[const std::string& m) |
284 | : std::runtime_error (m)]b4_locations_if([ | |
285 | , location (l)])[ | |
286 | {} | |
287 | ||
1dbaf37f TR |
288 | // basic_symbol. |
289 | template <typename Base> | |
b20e797a | 290 | inline |
1dbaf37f TR |
291 | ]b4_parser_class_name[::basic_symbol<Base>::basic_symbol () |
292 | : value () | |
293 | {} | |
04816a6f | 294 | |
1dbaf37f | 295 | template <typename Base> |
b20e797a | 296 | inline |
1dbaf37f TR |
297 | ]b4_parser_class_name[::basic_symbol<Base>::basic_symbol (const basic_symbol& other) |
298 | : Base (other) | |
299 | , value ()]b4_locations_if([ | |
300 | , location (other.location)])[ | |
1d6b689b | 301 | { |
1dbaf37f TR |
302 | ]b4_variant_if([b4_symbol_variant([other.type_get ()], [value], [copy], |
303 | [other.value])], | |
304 | [value = other.value;])[ | |
1d6b689b AD |
305 | } |
306 | ||
1d6b689b | 307 | |
1dbaf37f | 308 | template <typename Base> |
b20e797a | 309 | inline |
1dbaf37f | 310 | ]b4_parser_class_name[::basic_symbol<Base>::basic_symbol (]b4_join( |
7fc7df7a | 311 | [typename Base::kind_type t], |
1dbaf37f TR |
312 | [const semantic_type& v], |
313 | b4_locations_if([const location_type& l]))[) | |
314 | : Base (t) | |
97ae878e | 315 | , value (]b4_variant_if([], [v])[)]b4_locations_if([ |
1dbaf37f | 316 | , location (l)])[ |
97ae878e | 317 | {]b4_variant_if([[ |
733fb7c5 | 318 | (void) v; |
97ae878e | 319 | ]b4_symbol_variant([this->type_get ()], [value], [copy], [v])])[} |
1d6b689b | 320 | |
ee9cf8c4 TR |
321 | ]b4_variant_if([[ |
322 | // Implementation of basic_symbol constructor for each type. | |
323 | ]b4_type_foreach([b4_basic_symbol_constructor_define])], [[ | |
324 | /// Constructor for valueless symbols. | |
1dbaf37f | 325 | template <typename Base> |
b20e797a | 326 | inline |
1dbaf37f | 327 | ]b4_parser_class_name[::basic_symbol<Base>::basic_symbol (]b4_join( |
7fc7df7a | 328 | [typename Base::kind_type t], |
1dbaf37f | 329 | b4_locations_if([const location_type& l]))[) |
97ae878e AD |
330 | : Base (t) |
331 | , value ()]b4_locations_if([ | |
1dbaf37f | 332 | , location (l)])[ |
ee9cf8c4 | 333 | {}]])[ |
1d6b689b | 334 | |
97ae878e AD |
335 | template <typename Base> |
336 | inline | |
337 | ]b4_parser_class_name[::basic_symbol<Base>::~basic_symbol () | |
ee2f4335 AD |
338 | { |
339 | clear (); | |
340 | } | |
341 | ||
342 | template <typename Base> | |
343 | inline | |
344 | void | |
345 | ]b4_parser_class_name[::basic_symbol<Base>::clear () | |
97ae878e AD |
346 | {]b4_variant_if([[ |
347 | // User destructor. | |
26f95f5f | 348 | symbol_number_type yytype = this->type_get (); |
ee028dce | 349 | basic_symbol<Base>& yysym = *this; |
3e82dfaa | 350 | (void) yysym; |
97ae878e AD |
351 | switch (yytype) |
352 | { | |
353 | ]b4_symbol_foreach([b4_symbol_destructor])dnl | |
354 | [ default: | |
355 | break; | |
356 | } | |
357 | ||
358 | // Type destructor. | |
359 | ]b4_symbol_variant([[yytype]], [[value]], [[template destroy]])])[ | |
ee2f4335 | 360 | Base::clear (); |
97ae878e AD |
361 | } |
362 | ||
5422471c AD |
363 | template <typename Base> |
364 | inline | |
365 | bool | |
366 | ]b4_parser_class_name[::basic_symbol<Base>::empty () const | |
367 | { | |
368 | return Base::type_get () == empty_symbol; | |
369 | } | |
370 | ||
1dbaf37f | 371 | template <typename Base> |
b20e797a | 372 | inline |
1dbaf37f TR |
373 | void |
374 | ]b4_parser_class_name[::basic_symbol<Base>::move (basic_symbol& s) | |
1d6b689b | 375 | { |
97ae878e AD |
376 | super_type::move(s); |
377 | ]b4_variant_if([b4_symbol_variant([this->type_get ()], [value], [move], | |
1dbaf37f | 378 | [s.value])], |
97ae878e AD |
379 | [value = s.value;])[]b4_locations_if([ |
380 | location = s.location;])[ | |
1d6b689b AD |
381 | } |
382 | ||
1dbaf37f | 383 | // by_type. |
b20e797a | 384 | inline |
1dbaf37f | 385 | ]b4_parser_class_name[::by_type::by_type () |
5422471c | 386 | : type (empty_symbol) |
1dbaf37f | 387 | {} |
1d6b689b | 388 | |
b20e797a | 389 | inline |
1dbaf37f TR |
390 | ]b4_parser_class_name[::by_type::by_type (const by_type& other) |
391 | : type (other.type) | |
392 | {} | |
1d6b689b | 393 | |
b20e797a | 394 | inline |
1dbaf37f TR |
395 | ]b4_parser_class_name[::by_type::by_type (token_type t) |
396 | : type (yytranslate_ (t)) | |
397 | {} | |
7be08dfb | 398 | |
ee2f4335 AD |
399 | inline |
400 | void | |
401 | ]b4_parser_class_name[::by_type::clear () | |
402 | { | |
403 | type = empty_symbol; | |
404 | } | |
405 | ||
97ae878e AD |
406 | inline |
407 | void | |
408 | ]b4_parser_class_name[::by_type::move (by_type& that) | |
409 | { | |
410 | type = that.type; | |
ee2f4335 | 411 | that.clear (); |
97ae878e AD |
412 | } |
413 | ||
b20e797a | 414 | inline |
1d6b689b | 415 | int |
1dbaf37f | 416 | ]b4_parser_class_name[::by_type::type_get () const |
1d6b689b AD |
417 | { |
418 | return type; | |
419 | } | |
e36ec1f4 | 420 | ]b4_token_ctor_if([[ |
b20e797a | 421 | inline |
1d6b689b | 422 | ]b4_parser_class_name[::token_type |
1dbaf37f | 423 | ]b4_parser_class_name[::by_type::token () const |
1d6b689b AD |
424 | { |
425 | // YYTOKNUM[NUM] -- (External) token number corresponding to the | |
426 | // (internal) symbol number NUM (which must be that of a token). */ | |
427 | static | |
428 | const ]b4_int_type_for([b4_toknum])[ | |
429 | yytoken_number_[] = | |
430 | { | |
431 | ]b4_toknum[ | |
432 | }; | |
433 | return static_cast<token_type> (yytoken_number_[type]); | |
434 | } | |
0623bacc AD |
435 | ]])[]dnl |
436 | b4_symbol_constructor_define]) | |
437 | ||
438 | ||
439 | # b4_symbol_constructor_declare | |
440 | # b4_symbol_constructor_define | |
441 | # ----------------------------- | |
442 | # Declare/define symbol constructors for all the value types. | |
443 | # Use at class-level. Redefined in variant.hh. | |
444 | m4_define([b4_symbol_constructor_declare], []) | |
445 | m4_define([b4_symbol_constructor_define], []) | |
446 | ||
1d6b689b | 447 | |
cbf25ce7 AD |
448 | # b4_yytranslate_define |
449 | # --------------------- | |
450 | # Define yytranslate_. Sometimes used in the header file, | |
451 | # sometimes in the cc file. | |
452 | m4_define([b4_yytranslate_define], | |
453 | [[ // Symbol number corresponding to token number t. | |
b20e797a | 454 | inline |
cbf25ce7 | 455 | ]b4_parser_class_name[::token_number_type |
e36ec1f4 | 456 | ]b4_parser_class_name[::yytranslate_ (]b4_token_ctor_if([token_type], |
cbf25ce7 AD |
457 | [int])[ t) |
458 | { | |
459 | static | |
460 | const token_number_type | |
461 | translate_table[] = | |
462 | { | |
463 | ]b4_translate[ | |
464 | }; | |
465 | const unsigned int user_token_number_max_ = ]b4_user_token_number_max[; | |
466 | const token_number_type undef_token_ = ]b4_undef_token_number[; | |
467 | ||
468 | if (static_cast<int>(t) <= yyeof_) | |
469 | return yyeof_; | |
470 | else if (static_cast<unsigned int> (t) <= user_token_number_max_) | |
471 | return translate_table[t]; | |
472 | else | |
473 | return undef_token_; | |
474 | } | |
475 | ]]) | |
476 | ||
1d6b689b | 477 | |
cf147260 AD |
478 | # b4_lhs_value([TYPE]) |
479 | # -------------------- | |
480 | # Expansion of $<TYPE>$. | |
481 | m4_define([b4_lhs_value], | |
1fa5d8bb | 482 | [b4_symbol_value([yyval], [$1])]) |
cf147260 AD |
483 | |
484 | ||
485 | # b4_rhs_value(RULE-LENGTH, NUM, [TYPE]) | |
486 | # -------------------------------------- | |
487 | # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH | |
488 | # symbols on RHS. | |
489 | m4_define([b4_rhs_value], | |
1fa5d8bb AD |
490 | [b4_symbol_value([yysemantic_stack_@{($1) - ($2)@}], [$3])]) |
491 | ||
cf147260 AD |
492 | |
493 | # b4_lhs_location() | |
494 | # ----------------- | |
495 | # Expansion of @$. | |
496 | m4_define([b4_lhs_location], | |
497 | [(yyloc)]) | |
498 | ||
499 | ||
500 | # b4_rhs_location(RULE-LENGTH, NUM) | |
501 | # --------------------------------- | |
502 | # Expansion of @NUM, where the current rule has RULE-LENGTH symbols | |
503 | # on RHS. | |
504 | m4_define([b4_rhs_location], | |
d1ff7a7c | 505 | [(yylocation_stack_@{($1) - ($2)@})]) |
cf147260 AD |
506 | |
507 | ||
508 | # b4_parse_param_decl | |
509 | # ------------------- | |
510 | # Extra formal arguments of the constructor. | |
511 | # Change the parameter names from "foo" into "foo_yyarg", so that | |
512 | # there is no collision bw the user chosen attribute name, and the | |
513 | # argument name in the constructor. | |
514 | m4_define([b4_parse_param_decl], | |
515 | [m4_ifset([b4_parse_param], | |
516 | [m4_map_sep([b4_parse_param_decl_1], [, ], [b4_parse_param])])]) | |
517 | ||
518 | m4_define([b4_parse_param_decl_1], | |
519 | [$1_yyarg]) | |
520 | ||
521 | ||
522 | ||
523 | # b4_parse_param_cons | |
524 | # ------------------- | |
525 | # Extra initialisations of the constructor. | |
526 | m4_define([b4_parse_param_cons], | |
527 | [m4_ifset([b4_parse_param], | |
e9690142 | 528 | [ |
cf147260 AD |
529 | b4_cc_constructor_calls(b4_parse_param)])]) |
530 | m4_define([b4_cc_constructor_calls], | |
e9690142 | 531 | [m4_map_sep([b4_cc_constructor_call], [, |
cf147260 AD |
532 | ], [$@])]) |
533 | m4_define([b4_cc_constructor_call], | |
e9690142 | 534 | [$2 ($2_yyarg)]) |
cf147260 AD |
535 | |
536 | # b4_parse_param_vars | |
537 | # ------------------- | |
538 | # Extra instance variables. | |
539 | m4_define([b4_parse_param_vars], | |
540 | [m4_ifset([b4_parse_param], | |
e9690142 | 541 | [ |
ac826bc4 | 542 | // User arguments. |
cf147260 AD |
543 | b4_cc_var_decls(b4_parse_param)])]) |
544 | m4_define([b4_cc_var_decls], | |
e9690142 | 545 | [m4_map_sep([b4_cc_var_decl], [ |
cf147260 AD |
546 | ], [$@])]) |
547 | m4_define([b4_cc_var_decl], | |
e9690142 | 548 | [ $1;]) |
426903aa AD |
549 | |
550 | ||
551 | ## ---------## | |
552 | ## Values. ## | |
553 | ## ---------## | |
554 | ||
555 | # b4_yylloc_default_define | |
556 | # ------------------------ | |
557 | # Define YYLLOC_DEFAULT. | |
558 | m4_define([b4_yylloc_default_define], | |
559 | [[/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. | |
560 | If N is 0, then set CURRENT to the empty location which ends | |
561 | the previous symbol: RHS[0] (always defined). */ | |
562 | ||
563 | # ifndef YYLLOC_DEFAULT | |
564 | # define YYLLOC_DEFAULT(Current, Rhs, N) \ | |
565 | do \ | |
566 | if (N) \ | |
567 | { \ | |
568 | (Current).begin = YYRHSLOC (Rhs, 1).begin; \ | |
569 | (Current).end = YYRHSLOC (Rhs, N).end; \ | |
570 | } \ | |
571 | else \ | |
572 | { \ | |
573 | (Current).begin = (Current).end = YYRHSLOC (Rhs, 0).end; \ | |
574 | } \ | |
575 | while (/*CONSTCOND*/ false) | |
576 | # endif | |
577 | ]]) | |
1dce289a AD |
578 | |
579 | ## -------- ## | |
580 | ## Checks. ## | |
581 | ## -------- ## | |
582 | ||
583 | b4_token_ctor_if([b4_variant_if([], | |
584 | [b4_fatal_at(b4_percent_define_get_loc(api.token.constructor), | |
585 | [cannot use '%s' without '%s'], | |
586 | [%define api.token.constructor], | |
587 | [%define api.value.type variant]))])]) |