c++.m4 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  1. -*- Autoconf -*-
  2. # C++ skeleton for Bison
  3. # Copyright (C) 2002-2021 Free Software Foundation, Inc.
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation, either version 3 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. # Sanity checks, before defaults installed by c.m4.
  17. b4_percent_define_ifdef([[api.value.union.name]],
  18. [b4_complain_at(b4_percent_define_get_loc([[api.value.union.name]]),
  19. [named %union is invalid in C++])])
  20. b4_percent_define_default([[api.symbol.prefix]], [[S_]])
  21. m4_include(b4_skeletonsdir/[c.m4])
  22. b4_percent_define_check_kind([api.namespace], [code], [deprecated])
  23. b4_percent_define_check_kind([api.parser.class], [code], [deprecated])
  24. ## ----- ##
  25. ## C++. ##
  26. ## ----- ##
  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. # b4_inline(hh|cc)
  33. # ----------------
  34. # Expand to `inline\n ` if $1 is hh.
  35. m4_define([b4_inline],
  36. [m4_case([$1],
  37. [cc], [],
  38. [hh], [[inline
  39. ]],
  40. [m4_fatal([$0: invalid argument: $1])])])
  41. # b4_cxx_portability
  42. # ------------------
  43. m4_define([b4_cxx_portability],
  44. [#if defined __cplusplus
  45. # define YY_CPLUSPLUS __cplusplus
  46. #else
  47. # define YY_CPLUSPLUS 199711L
  48. #endif
  49. // Support move semantics when possible.
  50. #if 201103L <= YY_CPLUSPLUS
  51. # define YY_MOVE std::move
  52. # define YY_MOVE_OR_COPY move
  53. # define YY_MOVE_REF(Type) Type&&
  54. # define YY_RVREF(Type) Type&&
  55. # define YY_COPY(Type) Type
  56. #else
  57. # define YY_MOVE
  58. # define YY_MOVE_OR_COPY copy
  59. # define YY_MOVE_REF(Type) Type&
  60. # define YY_RVREF(Type) const Type&
  61. # define YY_COPY(Type) const Type&
  62. #endif
  63. // Support noexcept when possible.
  64. #if 201103L <= YY_CPLUSPLUS
  65. # define YY_NOEXCEPT noexcept
  66. # define YY_NOTHROW
  67. #else
  68. # define YY_NOEXCEPT
  69. # define YY_NOTHROW throw ()
  70. #endif
  71. // Support constexpr when possible.
  72. #if 201703 <= YY_CPLUSPLUS
  73. # define YY_CONSTEXPR constexpr
  74. #else
  75. # define YY_CONSTEXPR
  76. #endif[]dnl
  77. ])
  78. ## ---------------- ##
  79. ## Default values. ##
  80. ## ---------------- ##
  81. b4_percent_define_default([[api.parser.class]], [[parser]])
  82. # Don't do that so that we remember whether we're using a user
  83. # request, or the default value.
  84. #
  85. # b4_percent_define_default([[api.location.type]], [[location]])
  86. b4_percent_define_default([[api.filename.type]], [[const std::string]])
  87. # Make it a warning for those who used betas of Bison 3.0.
  88. b4_percent_define_default([[api.namespace]], m4_defn([b4_prefix]))
  89. b4_percent_define_default([[global_tokens_and_yystype]], [[false]])
  90. b4_percent_define_default([[define_location_comparison]],
  91. [m4_if(b4_percent_define_get([[filename_type]]),
  92. [std::string], [[true]], [[false]])])
  93. ## ----------- ##
  94. ## Namespace. ##
  95. ## ----------- ##
  96. m4_define([b4_namespace_ref], [b4_percent_define_get([[api.namespace]])])
  97. # Don't permit an empty b4_namespace_ref. Any '::parser::foo' appended to it
  98. # would compile as an absolute reference with 'parser' in the global namespace.
  99. # b4_namespace_open would open an anonymous namespace and thus establish
  100. # internal linkage. This would compile. However, it's cryptic, and internal
  101. # linkage for the parser would be specified in all translation units that
  102. # include the header, which is always generated. If we ever need to permit
  103. # internal linkage somehow, surely we can find a cleaner approach.
  104. m4_if(m4_bregexp(b4_namespace_ref, [^[ ]*$]), [-1], [],
  105. [b4_complain_at(b4_percent_define_get_loc([[api.namespace]]),
  106. [[namespace reference is empty]])])
  107. # Instead of assuming the C++ compiler will do it, Bison should reject any
  108. # invalid b4_namespace_ref that would be converted to a valid
  109. # b4_namespace_open. The problem is that Bison doesn't always output
  110. # b4_namespace_ref to uncommented code but should reserve the ability to do so
  111. # in future releases without risking breaking any existing user grammars.
  112. # Specifically, don't allow empty names as b4_namespace_open would just convert
  113. # those into anonymous namespaces, and that might tempt some users.
  114. m4_if(m4_bregexp(b4_namespace_ref, [::[ ]*::]), [-1], [],
  115. [b4_complain_at(b4_percent_define_get_loc([[api.namespace]]),
  116. [[namespace reference has consecutive "::"]])])
  117. m4_if(m4_bregexp(b4_namespace_ref, [::[ ]*$]), [-1], [],
  118. [b4_complain_at(b4_percent_define_get_loc([[api.namespace]]),
  119. [[namespace reference has a trailing "::"]])])
  120. m4_define([b4_namespace_open],
  121. [b4_user_code([b4_percent_define_get_syncline([[api.namespace]])dnl
  122. [namespace ]m4_bpatsubst(m4_dquote(m4_bpatsubst(m4_dquote(b4_namespace_ref),
  123. [^\(.\)[ ]*::], [\1])),
  124. [::], [ { namespace ])[ {]])])
  125. m4_define([b4_namespace_close],
  126. [b4_user_code([b4_percent_define_get_syncline([[api.namespace]])dnl
  127. m4_bpatsubst(m4_dquote(m4_bpatsubst(m4_dquote(b4_namespace_ref[ ]),
  128. [^\(.\)[ ]*\(::\)?\([^][:]\|:[^:]\)*],
  129. [\1])),
  130. [::\([^][:]\|:[^:]\)*], [} ])[} // ]b4_namespace_ref])])
  131. ## ------------- ##
  132. ## Token kinds. ##
  133. ## ------------- ##
  134. # b4_token_enums
  135. # --------------
  136. # Output the definition of the token kinds.
  137. m4_define([b4_token_enums],
  138. [[enum token_kind_type
  139. {
  140. ]b4_symbol([-2], [id])[ = -2,
  141. ]b4_symbol_foreach([b4_token_enum])dnl
  142. [ };]dnl
  143. ])
  144. ## -------------- ##
  145. ## Symbol kinds. ##
  146. ## -------------- ##
  147. # b4_declare_symbol_enum
  148. # ----------------------
  149. # The definition of the symbol internal numbers as an enum.
  150. # Defining YYEMPTY here is important: it forces the compiler
  151. # to use a signed type, which matters for yytoken.
  152. m4_define([b4_declare_symbol_enum],
  153. [[enum symbol_kind_type
  154. {
  155. YYNTOKENS = ]b4_tokens_number[, ///< Number of tokens.
  156. ]b4_symbol(-2, kind_base)[ = -2,
  157. ]b4_symbol_foreach([ b4_symbol_enum])dnl
  158. [ };]])
  159. ## ----------------- ##
  160. ## Semantic Values. ##
  161. ## ----------------- ##
  162. # b4_value_type_declare
  163. # ---------------------
  164. # Declare semantic_type.
  165. m4_define([b4_value_type_declare],
  166. [b4_value_type_setup[]dnl
  167. [ /// Symbol semantic values.
  168. ]m4_bmatch(b4_percent_define_get_kind([[api.value.type]]),
  169. [code],
  170. [[ typedef ]b4_percent_define_get([[api.value.type]])[ semantic_type;]],
  171. [m4_bmatch(b4_percent_define_get([[api.value.type]]),
  172. [union\|union-directive],
  173. [[ union semantic_type
  174. {
  175. ]b4_user_union_members[
  176. };]])])dnl
  177. ])
  178. # b4_public_types_declare
  179. # -----------------------
  180. # Define the public types: token, semantic value, location, and so forth.
  181. # Depending on %define token_lex, may be output in the header or source file.
  182. m4_define([b4_public_types_declare],
  183. [[#ifndef ]b4_api_PREFIX[STYPE
  184. ]b4_value_type_declare[
  185. #else
  186. typedef ]b4_api_PREFIX[STYPE semantic_type;
  187. #endif]b4_locations_if([
  188. /// Symbol locations.
  189. typedef b4_percent_define_get([[api.location.type]],
  190. [[location]]) location_type;])[
  191. /// Syntax errors thrown from user actions.
  192. struct syntax_error : std::runtime_error
  193. {
  194. syntax_error (]b4_locations_if([const location_type& l, ])[const std::string& m)
  195. : std::runtime_error (m)]b4_locations_if([
  196. , location (l)])[
  197. {}
  198. syntax_error (const syntax_error& s)
  199. : std::runtime_error (s.what ())]b4_locations_if([
  200. , location (s.location)])[
  201. {}
  202. ~syntax_error () YY_NOEXCEPT YY_NOTHROW;]b4_locations_if([
  203. location_type location;])[
  204. };
  205. /// Token kinds.
  206. struct token
  207. {
  208. ]b4_token_enums[
  209. /// Backward compatibility alias (Bison 3.6).
  210. typedef token_kind_type yytokentype;
  211. };
  212. /// Token kind, as returned by yylex.
  213. typedef token::yytokentype token_kind_type;
  214. /// Backward compatibility alias (Bison 3.6).
  215. typedef token_kind_type token_type;
  216. /// Symbol kinds.
  217. struct symbol_kind
  218. {
  219. ]b4_declare_symbol_enum[
  220. };
  221. /// (Internal) symbol kind.
  222. typedef symbol_kind::symbol_kind_type symbol_kind_type;
  223. /// The number of tokens.
  224. static const symbol_kind_type YYNTOKENS = symbol_kind::YYNTOKENS;
  225. ]])
  226. # b4_symbol_type_define
  227. # ---------------------
  228. # Define symbol_type, the external type for symbols used for symbol
  229. # constructors.
  230. m4_define([b4_symbol_type_define],
  231. [[ /// A complete symbol.
  232. ///
  233. /// Expects its Base type to provide access to the symbol kind
  234. /// via kind ().
  235. ///
  236. /// Provide access to semantic value]b4_locations_if([ and location])[.
  237. template <typename Base>
  238. struct basic_symbol : Base
  239. {
  240. /// Alias to Base.
  241. typedef Base super_type;
  242. /// Default constructor.
  243. basic_symbol ()
  244. : value ()]b4_locations_if([
  245. , location ()])[
  246. {}
  247. #if 201103L <= YY_CPLUSPLUS
  248. /// Move constructor.
  249. basic_symbol (basic_symbol&& that)
  250. : Base (std::move (that))
  251. , value (]b4_variant_if([], [std::move (that.value)]))b4_locations_if([
  252. , location (std::move (that.location))])[
  253. {]b4_variant_if([
  254. b4_symbol_variant([this->kind ()], [value], [move],
  255. [std::move (that.value)])
  256. ])[}
  257. #endif
  258. /// Copy constructor.
  259. basic_symbol (const basic_symbol& that);]b4_variant_if([[
  260. /// Constructors for typed symbols.
  261. ]b4_type_foreach([b4_basic_symbol_constructor_define], [
  262. ])], [[
  263. /// Constructor for valueless symbols.
  264. basic_symbol (typename Base::kind_type t]b4_locations_if([,
  265. YY_MOVE_REF (location_type) l])[);
  266. /// Constructor for symbols with semantic value.
  267. basic_symbol (typename Base::kind_type t,
  268. YY_RVREF (semantic_type) v]b4_locations_if([,
  269. YY_RVREF (location_type) l])[);
  270. ]])[
  271. /// Destroy the symbol.
  272. ~basic_symbol ()
  273. {
  274. clear ();
  275. }
  276. /// Destroy contents, and record that is empty.
  277. void clear () YY_NOEXCEPT
  278. {]b4_variant_if([[
  279. // User destructor.
  280. symbol_kind_type yykind = this->kind ();
  281. basic_symbol<Base>& yysym = *this;
  282. (void) yysym;
  283. switch (yykind)
  284. {
  285. ]b4_symbol_foreach([b4_symbol_destructor])dnl
  286. [ default:
  287. break;
  288. }
  289. // Value type destructor.
  290. ]b4_symbol_variant([[yykind]], [[value]], [[template destroy]])])[
  291. Base::clear ();
  292. }
  293. ]b4_parse_error_bmatch(
  294. [custom\|detailed],
  295. [[ /// The user-facing name of this symbol.
  296. const char *name () const YY_NOEXCEPT
  297. {
  298. return ]b4_parser_class[::symbol_name (this->kind ());
  299. }]],
  300. [simple],
  301. [[#if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
  302. /// The user-facing name of this symbol.
  303. const char *name () const YY_NOEXCEPT
  304. {
  305. return ]b4_parser_class[::symbol_name (this->kind ());
  306. }
  307. #endif // #if ]b4_api_PREFIX[DEBUG || ]b4_token_table_flag[
  308. ]],
  309. [verbose],
  310. [[ /// The user-facing name of this symbol.
  311. std::string name () const YY_NOEXCEPT
  312. {
  313. return ]b4_parser_class[::symbol_name (this->kind ());
  314. }]])[
  315. /// Backward compatibility (Bison 3.6).
  316. symbol_kind_type type_get () const YY_NOEXCEPT;
  317. /// Whether empty.
  318. bool empty () const YY_NOEXCEPT;
  319. /// Destructive move, \a s is emptied into this.
  320. void move (basic_symbol& s);
  321. /// The semantic value.
  322. semantic_type value;]b4_locations_if([
  323. /// The location.
  324. location_type location;])[
  325. private:
  326. #if YY_CPLUSPLUS < 201103L
  327. /// Assignment operator.
  328. basic_symbol& operator= (const basic_symbol& that);
  329. #endif
  330. };
  331. /// Type access provider for token (enum) based symbols.
  332. struct by_kind
  333. {
  334. /// Default constructor.
  335. by_kind ();
  336. #if 201103L <= YY_CPLUSPLUS
  337. /// Move constructor.
  338. by_kind (by_kind&& that);
  339. #endif
  340. /// Copy constructor.
  341. by_kind (const by_kind& that);
  342. /// The symbol kind as needed by the constructor.
  343. typedef token_kind_type kind_type;
  344. /// Constructor from (external) token numbers.
  345. by_kind (kind_type t);
  346. /// Record that this symbol is empty.
  347. void clear () YY_NOEXCEPT;
  348. /// Steal the symbol kind from \a that.
  349. void move (by_kind& that);
  350. /// The (internal) type number (corresponding to \a type).
  351. /// \a empty when empty.
  352. symbol_kind_type kind () const YY_NOEXCEPT;
  353. /// Backward compatibility (Bison 3.6).
  354. symbol_kind_type type_get () const YY_NOEXCEPT;
  355. /// The symbol kind.
  356. /// \a ]b4_symbol_prefix[YYEMPTY when empty.
  357. symbol_kind_type kind_;
  358. };
  359. /// Backward compatibility for a private implementation detail (Bison 3.6).
  360. typedef by_kind by_type;
  361. /// "External" symbols: returned by the scanner.
  362. struct symbol_type : basic_symbol<by_kind>
  363. {]b4_variant_if([[
  364. /// Superclass.
  365. typedef basic_symbol<by_kind> super_type;
  366. /// Empty symbol.
  367. symbol_type () {}
  368. /// Constructor for valueless symbols, and symbols from each type.
  369. ]b4_type_foreach([_b4_token_constructor_define])dnl
  370. ])[};
  371. ]])
  372. # b4_public_types_define(hh|cc)
  373. # -----------------------------
  374. # Provide the implementation needed by the public types.
  375. m4_define([b4_public_types_define],
  376. [[ // basic_symbol.
  377. template <typename Base>
  378. ]b4_parser_class[::basic_symbol<Base>::basic_symbol (const basic_symbol& that)
  379. : Base (that)
  380. , value (]b4_variant_if([], [that.value]))b4_locations_if([
  381. , location (that.location)])[
  382. {]b4_variant_if([
  383. b4_symbol_variant([this->kind ()], [value], [copy],
  384. [YY_MOVE (that.value)])
  385. ])[}
  386. ]b4_variant_if([], [[
  387. /// Constructor for valueless symbols.
  388. template <typename Base>
  389. ]b4_parser_class[::basic_symbol<Base>::basic_symbol (]b4_join(
  390. [typename Base::kind_type t],
  391. b4_locations_if([YY_MOVE_REF (location_type) l]))[)
  392. : Base (t)
  393. , value ()]b4_locations_if([
  394. , location (l)])[
  395. {}
  396. template <typename Base>
  397. ]b4_parser_class[::basic_symbol<Base>::basic_symbol (]b4_join(
  398. [typename Base::kind_type t],
  399. [YY_RVREF (semantic_type) v],
  400. b4_locations_if([YY_RVREF (location_type) l]))[)
  401. : Base (t)
  402. , value (]b4_variant_if([], [YY_MOVE (v)])[)]b4_locations_if([
  403. , location (YY_MOVE (l))])[
  404. {]b4_variant_if([[
  405. (void) v;
  406. ]b4_symbol_variant([this->kind ()], [value], [YY_MOVE_OR_COPY], [YY_MOVE (v)])])[}]])[
  407. template <typename Base>
  408. ]b4_parser_class[::symbol_kind_type
  409. ]b4_parser_class[::basic_symbol<Base>::type_get () const YY_NOEXCEPT
  410. {
  411. return this->kind ();
  412. }
  413. template <typename Base>
  414. bool
  415. ]b4_parser_class[::basic_symbol<Base>::empty () const YY_NOEXCEPT
  416. {
  417. return this->kind () == ]b4_symbol(-2, kind)[;
  418. }
  419. template <typename Base>
  420. void
  421. ]b4_parser_class[::basic_symbol<Base>::move (basic_symbol& s)
  422. {
  423. super_type::move (s);
  424. ]b4_variant_if([b4_symbol_variant([this->kind ()], [value], [move],
  425. [YY_MOVE (s.value)])],
  426. [value = YY_MOVE (s.value);])[]b4_locations_if([
  427. location = YY_MOVE (s.location);])[
  428. }
  429. // by_kind.
  430. ]b4_inline([$1])b4_parser_class[::by_kind::by_kind ()
  431. : kind_ (]b4_symbol(-2, kind)[)
  432. {}
  433. #if 201103L <= YY_CPLUSPLUS
  434. ]b4_inline([$1])b4_parser_class[::by_kind::by_kind (by_kind&& that)
  435. : kind_ (that.kind_)
  436. {
  437. that.clear ();
  438. }
  439. #endif
  440. ]b4_inline([$1])b4_parser_class[::by_kind::by_kind (const by_kind& that)
  441. : kind_ (that.kind_)
  442. {}
  443. ]b4_inline([$1])b4_parser_class[::by_kind::by_kind (token_kind_type t)
  444. : kind_ (yytranslate_ (t))
  445. {}
  446. ]b4_inline([$1])[void
  447. ]b4_parser_class[::by_kind::clear () YY_NOEXCEPT
  448. {
  449. kind_ = ]b4_symbol(-2, kind)[;
  450. }
  451. ]b4_inline([$1])[void
  452. ]b4_parser_class[::by_kind::move (by_kind& that)
  453. {
  454. kind_ = that.kind_;
  455. that.clear ();
  456. }
  457. ]b4_inline([$1])[]b4_parser_class[::symbol_kind_type
  458. ]b4_parser_class[::by_kind::kind () const YY_NOEXCEPT
  459. {
  460. return kind_;
  461. }
  462. ]b4_inline([$1])[]b4_parser_class[::symbol_kind_type
  463. ]b4_parser_class[::by_kind::type_get () const YY_NOEXCEPT
  464. {
  465. return this->kind ();
  466. }
  467. ]])
  468. # b4_token_constructor_define
  469. # ----------------------------
  470. # Define symbol constructors for all the value types.
  471. # Use at class-level. Redefined in variant.hh.
  472. m4_define([b4_token_constructor_define], [])
  473. # b4_yytranslate_define(cc|hh)
  474. # ----------------------------
  475. # Define yytranslate_. Sometimes used in the header file ($1=hh),
  476. # sometimes in the cc file.
  477. m4_define([b4_yytranslate_define],
  478. [ b4_inline([$1])b4_parser_class[::symbol_kind_type
  479. ]b4_parser_class[::yytranslate_ (int t)
  480. {
  481. ]b4_api_token_raw_if(
  482. [[ return static_cast<symbol_kind_type> (t);]],
  483. [[ // YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to
  484. // TOKEN-NUM as returned by yylex.
  485. static
  486. const ]b4_int_type_for([b4_translate])[
  487. translate_table[] =
  488. {
  489. ]b4_translate[
  490. };
  491. // Last valid token kind.
  492. const int code_max = ]b4_code_max[;
  493. if (t <= 0)
  494. return symbol_kind::]b4_symbol_prefix[YYEOF;
  495. else if (t <= code_max)
  496. return YY_CAST (symbol_kind_type, translate_table[t]);
  497. else
  498. return symbol_kind::]b4_symbol_prefix[YYUNDEF;]])[
  499. }
  500. ]])
  501. # b4_lhs_value([TYPE])
  502. # --------------------
  503. m4_define([b4_lhs_value],
  504. [b4_symbol_value([yyval], [$1])])
  505. # b4_rhs_value(RULE-LENGTH, POS, [TYPE])
  506. # --------------------------------------
  507. # FIXME: Dead code.
  508. m4_define([b4_rhs_value],
  509. [b4_symbol_value([yysemantic_stack_@{($1) - ($2)@}], [$3])])
  510. # b4_lhs_location()
  511. # -----------------
  512. # Expansion of @$.
  513. m4_define([b4_lhs_location],
  514. [(yyloc)])
  515. # b4_rhs_location(RULE-LENGTH, POS)
  516. # ---------------------------------
  517. # Expansion of @POS, where the current rule has RULE-LENGTH symbols
  518. # on RHS.
  519. m4_define([b4_rhs_location],
  520. [(yylocation_stack_@{($1) - ($2)@})])
  521. # b4_parse_param_decl
  522. # -------------------
  523. # Extra formal arguments of the constructor.
  524. # Change the parameter names from "foo" into "foo_yyarg", so that
  525. # there is no collision bw the user chosen attribute name, and the
  526. # argument name in the constructor.
  527. m4_define([b4_parse_param_decl],
  528. [m4_ifset([b4_parse_param],
  529. [m4_map_sep([b4_parse_param_decl_1], [, ], [b4_parse_param])])])
  530. m4_define([b4_parse_param_decl_1],
  531. [$1_yyarg])
  532. # b4_parse_param_cons
  533. # -------------------
  534. # Extra initialisations of the constructor.
  535. m4_define([b4_parse_param_cons],
  536. [m4_ifset([b4_parse_param],
  537. [
  538. b4_cc_constructor_calls(b4_parse_param)])])
  539. m4_define([b4_cc_constructor_calls],
  540. [m4_map_sep([b4_cc_constructor_call], [,
  541. ], [$@])])
  542. m4_define([b4_cc_constructor_call],
  543. [$2 ($2_yyarg)])
  544. # b4_parse_param_vars
  545. # -------------------
  546. # Extra instance variables.
  547. m4_define([b4_parse_param_vars],
  548. [m4_ifset([b4_parse_param],
  549. [
  550. // User arguments.
  551. b4_cc_var_decls(b4_parse_param)])])
  552. m4_define([b4_cc_var_decls],
  553. [m4_map_sep([b4_cc_var_decl], [
  554. ], [$@])])
  555. m4_define([b4_cc_var_decl],
  556. [ $1;])
  557. ## ---------##
  558. ## Values. ##
  559. ## ---------##
  560. # b4_yylloc_default_define
  561. # ------------------------
  562. # Define YYLLOC_DEFAULT.
  563. m4_define([b4_yylloc_default_define],
  564. [[/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
  565. If N is 0, then set CURRENT to the empty location which ends
  566. the previous symbol: RHS[0] (always defined). */
  567. # ifndef YYLLOC_DEFAULT
  568. # define YYLLOC_DEFAULT(Current, Rhs, N) \
  569. do \
  570. if (N) \
  571. { \
  572. (Current).begin = YYRHSLOC (Rhs, 1).begin; \
  573. (Current).end = YYRHSLOC (Rhs, N).end; \
  574. } \
  575. else \
  576. { \
  577. (Current).begin = (Current).end = YYRHSLOC (Rhs, 0).end; \
  578. } \
  579. while (false)
  580. # endif
  581. ]])
  582. ## -------- ##
  583. ## Checks. ##
  584. ## -------- ##
  585. b4_token_ctor_if([b4_variant_if([],
  586. [b4_fatal_at(b4_percent_define_get_loc(api.token.constructor),
  587. [cannot use '%s' without '%s'],
  588. [%define api.token.constructor],
  589. [%define api.value.type variant]))])])