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