29
29
#include < fstream>
30
30
#include < iostream>
31
31
#include < map>
32
+ #include < regex>
32
33
#include < sstream>
33
34
#include < unordered_map>
34
35
@@ -86,7 +87,7 @@ struct c_wranglert
86
87
bool remove_static = false ;
87
88
};
88
89
89
- using functionst = std::map <std::string , functiont>;
90
+ using functionst = std::list <std::pair<std::regex , functiont> >;
90
91
functionst functions;
91
92
92
93
// output
@@ -171,6 +172,9 @@ void c_wranglert::configure_functions(const jsont &config)
171
172
if (!items.is_array ())
172
173
throw deserialization_exceptiont (" function entry must be sequence" );
173
174
175
+ this ->functions .emplace_back (function_name, functiont{});
176
+ functiont &function_config = this ->functions .back ().second ;
177
+
174
178
for (const auto &function_item : to_json_array (items))
175
179
{
176
180
// These need to start with "ensures", "requires", "assigns",
@@ -190,16 +194,14 @@ void c_wranglert::configure_functions(const jsont &config)
190
194
std::ostringstream rest;
191
195
join_strings (rest, split.begin () + 1 , split.end (), ' ' );
192
196
193
- this ->functions [function_name].contract .emplace_back (
194
- split[0 ], rest.str ());
197
+ function_config.contract .emplace_back (split[0 ], rest.str ());
195
198
}
196
199
else if (split[0 ] == " assert" && split.size () >= 3 )
197
200
{
198
201
std::ostringstream rest;
199
202
join_strings (rest, split.begin () + 2 , split.end (), ' ' );
200
203
201
- this ->functions [function_name].assertions .emplace_back (
202
- split[1 ], rest.str ());
204
+ function_config.assertions .emplace_back (split[1 ], rest.str ());
203
205
}
204
206
else if (
205
207
(split[0 ] == " for" && split.size () >= 3 && split[2 ] == " invariant" ) ||
@@ -208,23 +210,23 @@ void c_wranglert::configure_functions(const jsont &config)
208
210
std::ostringstream rest;
209
211
join_strings (rest, split.begin () + 3 , split.end (), ' ' );
210
212
211
- this -> functions [function_name] .loop_invariants .emplace_back (
213
+ function_config .loop_invariants .emplace_back (
212
214
split[0 ], split[1 ], rest.str ());
213
215
}
214
216
else if (split[0 ] == " stub" )
215
217
{
216
218
std::ostringstream rest;
217
219
join_strings (rest, split.begin () + 1 , split.end (), ' ' );
218
220
219
- this -> functions [function_name] .stub = rest.str ();
221
+ function_config .stub = rest.str ();
220
222
}
221
223
else if (split[0 ] == " remove" )
222
224
{
223
225
if (split.size () == 1 )
224
226
throw deserialization_exceptiont (" unexpected remove entry" );
225
227
226
228
if (split[1 ] == " static" )
227
- this -> functions [function_name] .remove_static = true ;
229
+ function_config .remove_static = true ;
228
230
else
229
231
throw deserialization_exceptiont (
230
232
" unexpected remove entry " + split[1 ]);
@@ -401,13 +403,15 @@ static void mangle(
401
403
if (
402
404
declaration.is_function () && name_opt.has_value () && declaration.has_body ())
403
405
{
404
- auto f_it = config.functions .find (name_opt->text );
405
- if (f_it != config.functions .end ())
406
+ for (const auto &entry : config.functions )
406
407
{
407
- // we are to modify this function
408
- mangle_function (declaration, defines, f_it->second , out);
408
+ if (std::regex_match (name_opt->text , entry.first ))
409
+ {
410
+ // we are to modify this function
411
+ mangle_function (declaration, defines, entry.second , out);
409
412
410
- return ;
413
+ return ;
414
+ }
411
415
}
412
416
}
413
417
0 commit comments