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
@@ -175,6 +176,9 @@ void c_wranglert::configure_functions(const jsont &config)
175
176
if (!items.is_array ())
176
177
throw deserialization_exceptiont (" function entry must be sequence" );
177
178
179
+ this ->functions .emplace_back (function_name, functiont{});
180
+ functiont &function_config = this ->functions .back ().second ;
181
+
178
182
for (const auto &function_item : to_json_array (items))
179
183
{
180
184
// These need to start with "ensures", "requires", "assigns",
@@ -194,16 +198,14 @@ void c_wranglert::configure_functions(const jsont &config)
194
198
std::ostringstream rest;
195
199
join_strings (rest, split.begin () + 1 , split.end (), ' ' );
196
200
197
- this ->functions [function_name].contract .emplace_back (
198
- split[0 ], rest.str ());
201
+ function_config.contract .emplace_back (split[0 ], rest.str ());
199
202
}
200
203
else if (split[0 ] == " assert" && split.size () >= 3 )
201
204
{
202
205
std::ostringstream rest;
203
206
join_strings (rest, split.begin () + 2 , split.end (), ' ' );
204
207
205
- this ->functions [function_name].assertions .emplace_back (
206
- split[1 ], rest.str ());
208
+ function_config.assertions .emplace_back (split[1 ], rest.str ());
207
209
}
208
210
else if (
209
211
(split[0 ] == " for" && split.size () >= 3 && split[2 ] == " invariant" ) ||
@@ -212,23 +214,23 @@ void c_wranglert::configure_functions(const jsont &config)
212
214
std::ostringstream rest;
213
215
join_strings (rest, split.begin () + 3 , split.end (), ' ' );
214
216
215
- this -> functions [function_name] .loop_invariants .emplace_back (
217
+ function_config .loop_invariants .emplace_back (
216
218
split[0 ], split[1 ], rest.str ());
217
219
}
218
220
else if (split[0 ] == " stub" )
219
221
{
220
222
std::ostringstream rest;
221
223
join_strings (rest, split.begin () + 1 , split.end (), ' ' );
222
224
223
- this -> functions [function_name] .stub = rest.str ();
225
+ function_config .stub = rest.str ();
224
226
}
225
227
else if (split[0 ] == " remove" )
226
228
{
227
229
if (split.size () == 1 )
228
230
throw deserialization_exceptiont (" unexpected remove entry" );
229
231
230
232
if (split[1 ] == " static" )
231
- this -> functions [function_name] .remove_static = true ;
233
+ function_config .remove_static = true ;
232
234
else
233
235
throw deserialization_exceptiont (
234
236
" unexpected remove entry " + split[1 ]);
@@ -405,13 +407,15 @@ static void mangle(
405
407
if (
406
408
declaration.is_function () && name_opt.has_value () && declaration.has_body ())
407
409
{
408
- auto f_it = config.functions .find (name_opt->text );
409
- if (f_it != config.functions .end ())
410
+ for (const auto &entry : config.functions )
410
411
{
411
- // we are to modify this function
412
- mangle_function (declaration, defines, f_it->second , out);
412
+ if (std::regex_match (name_opt->text , entry.first ))
413
+ {
414
+ // we are to modify this function
415
+ mangle_function (declaration, defines, entry.second , out);
413
416
414
- return ;
417
+ return ;
418
+ }
415
419
}
416
420
}
417
421
0 commit comments