]> git.saurik.com Git - bison.git/blob - data/c++.m4
tests: fix maintainer-xml-check for recent changes.
[bison.git] / data / c++.m4
1 -*- Autoconf -*-
2
3 # C++ skeleton for Bison
4
5 # Copyright (C) 2002-2010 Free Software 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 m4_include(b4_pkgdatadir/[c.m4])
21
22 ## ---------------- ##
23 ## Default values. ##
24 ## ---------------- ##
25
26 # Default parser class name.
27 b4_percent_define_default([[parser_class_name]], [[parser]])
28 b4_percent_define_default([[location_type]], [[location]])
29 b4_percent_define_default([[filename_type]], [[std::string]])
30 b4_percent_define_default([[namespace]], m4_defn([b4_prefix]))
31 b4_percent_define_default([[global_tokens_and_yystype]], [[false]])
32 b4_percent_define_default([[define_location_comparison]],
33 [m4_if(b4_percent_define_get([[filename_type]]),
34 [std::string], [[true]], [[false]])])
35
36
37 ## ----------- ##
38 ## Namespace. ##
39 ## ----------- ##
40
41 m4_define([b4_namespace_ref], [b4_percent_define_get([[namespace]])])
42
43 # Don't permit an empty b4_namespace_ref. Any `::parser::foo' appended to it
44 # would compile as an absolute reference with `parser' in the global namespace.
45 # b4_namespace_open would open an anonymous namespace and thus establish
46 # internal linkage. This would compile. However, it's cryptic, and internal
47 # linkage for the parser would be specified in all translation units that
48 # include the header, which is always generated. If we ever need to permit
49 # internal linkage somehow, surely we can find a cleaner approach.
50 m4_if(m4_bregexp(b4_namespace_ref, [^[ ]*$]), [-1], [],
51 [b4_complain_at(b4_percent_define_get_loc([[namespace]]),
52 [[namespace reference is empty]])])
53
54 # Instead of assuming the C++ compiler will do it, Bison should reject any
55 # invalid b4_namepsace_ref that would be converted to a valid
56 # b4_namespace_open. The problem is that Bison doesn't always output
57 # b4_namespace_ref to uncommented code but should reserve the ability to do so
58 # in future releases without risking breaking any existing user grammars.
59 # Specifically, don't allow empty names as b4_namespace_open would just convert
60 # those into anonymous namespaces, and that might tempt some users.
61 m4_if(m4_bregexp(b4_namespace_ref, [::[ ]*::]), [-1], [],
62 [b4_complain_at(b4_percent_define_get_loc([[namespace]]),
63 [[namespace reference has consecutive "::"]])])
64 m4_if(m4_bregexp(b4_namespace_ref, [::[ ]*$]), [-1], [],
65 [b4_complain_at(b4_percent_define_get_loc([[namespace]]),
66 [[namespace reference has a trailing "::"]])])
67
68 m4_define([b4_namespace_open],
69 [b4_user_code([b4_percent_define_get_syncline([[namespace]])
70 [namespace ]m4_bpatsubst(m4_dquote(m4_bpatsubst(m4_dquote(b4_namespace_ref),
71 [^\(.\)[ ]*::], [\1])),
72 [::], [ { namespace ])[ {]])])
73
74 m4_define([b4_namespace_close],
75 [b4_user_code([b4_percent_define_get_syncline([[namespace]])
76 m4_bpatsubst(m4_dquote(m4_bpatsubst(m4_dquote(b4_namespace_ref[ ]),
77 [^\(.\)[ ]*\(::\)?\([^][:]\|:[^:]\)*],
78 [\1])),
79 [::\([^][:]\|:[^:]\)*], [} ])[} // ]b4_namespace_ref])])
80
81
82 # b4_token_enums(LIST-OF-PAIRS-TOKEN-NAME-TOKEN-NUMBER)
83 # -----------------------------------------------------
84 # Output the definition of the tokens as enums.
85 m4_define([b4_token_enums],
86 [/* Tokens. */
87 enum yytokentype {
88 m4_map_sep([ b4_token_enum], [,
89 ],
90 [$@])
91 };
92 ])
93
94
95 ## ----------------- ##
96 ## Semantic Values. ##
97 ## ----------------- ##
98
99
100 # b4_lhs_value([TYPE])
101 # --------------------
102 # Expansion of $<TYPE>$.
103 m4_define([b4_lhs_value],
104 [(yyval[]m4_ifval([$1], [.$1]))])
105
106
107 # b4_rhs_value(RULE-LENGTH, NUM, [TYPE])
108 # --------------------------------------
109 # Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
110 # symbols on RHS.
111 m4_define([b4_rhs_value],
112 [(yysemantic_stack_@{($1) - ($2)@}m4_ifval([$3], [.$3]))])
113
114 # b4_lhs_location()
115 # -----------------
116 # Expansion of @$.
117 m4_define([b4_lhs_location],
118 [(yyloc)])
119
120
121 # b4_rhs_location(RULE-LENGTH, NUM)
122 # ---------------------------------
123 # Expansion of @NUM, where the current rule has RULE-LENGTH symbols
124 # on RHS.
125 m4_define([b4_rhs_location],
126 [(yylocation_stack_@{($1) - ($2)@})])
127
128
129 # b4_parse_param_decl
130 # -------------------
131 # Extra formal arguments of the constructor.
132 # Change the parameter names from "foo" into "foo_yyarg", so that
133 # there is no collision bw the user chosen attribute name, and the
134 # argument name in the constructor.
135 m4_define([b4_parse_param_decl],
136 [m4_ifset([b4_parse_param],
137 [m4_map_sep([b4_parse_param_decl_1], [, ], [b4_parse_param])])])
138
139 m4_define([b4_parse_param_decl_1],
140 [$1_yyarg])
141
142
143
144 # b4_parse_param_cons
145 # -------------------
146 # Extra initialisations of the constructor.
147 m4_define([b4_parse_param_cons],
148 [m4_ifset([b4_parse_param],
149 [
150 b4_cc_constructor_calls(b4_parse_param)])])
151 m4_define([b4_cc_constructor_calls],
152 [m4_map_sep([b4_cc_constructor_call], [,
153 ], [$@])])
154 m4_define([b4_cc_constructor_call],
155 [$2 ($2_yyarg)])
156
157 # b4_parse_param_vars
158 # -------------------
159 # Extra instance variables.
160 m4_define([b4_parse_param_vars],
161 [m4_ifset([b4_parse_param],
162 [
163 /* User arguments. */
164 b4_cc_var_decls(b4_parse_param)])])
165 m4_define([b4_cc_var_decls],
166 [m4_map_sep([b4_cc_var_decl], [
167 ], [$@])])
168 m4_define([b4_cc_var_decl],
169 [ $1;])