@@ -215,15 +215,26 @@ void parse_function_pointer_restriction_options_from_cmdline(
215
215
const cmdlinet &cmdline,
216
216
optionst &options)
217
217
{
218
- options.set_option (
219
- RESTRICT_FUNCTION_POINTER_OPT,
220
- cmdline.get_values (RESTRICT_FUNCTION_POINTER_OPT));
221
- options.set_option (
222
- RESTRICT_FUNCTION_POINTER_FROM_FILE_OPT,
223
- cmdline.get_values (RESTRICT_FUNCTION_POINTER_FROM_FILE_OPT));
224
- options.set_option (
225
- RESTRICT_FUNCTION_POINTER_BY_NAME_OPT,
226
- cmdline.get_values (RESTRICT_FUNCTION_POINTER_BY_NAME_OPT));
218
+ if (cmdline.isset (RESTRICT_FUNCTION_POINTER_OPT))
219
+ {
220
+ options.set_option (
221
+ RESTRICT_FUNCTION_POINTER_OPT,
222
+ cmdline.get_values (RESTRICT_FUNCTION_POINTER_OPT));
223
+ }
224
+
225
+ if (cmdline.isset (RESTRICT_FUNCTION_POINTER_FROM_FILE_OPT))
226
+ {
227
+ options.set_option (
228
+ RESTRICT_FUNCTION_POINTER_FROM_FILE_OPT,
229
+ cmdline.get_values (RESTRICT_FUNCTION_POINTER_FROM_FILE_OPT));
230
+ }
231
+
232
+ if (cmdline.isset (RESTRICT_FUNCTION_POINTER_BY_NAME_OPT))
233
+ {
234
+ options.set_option (
235
+ RESTRICT_FUNCTION_POINTER_BY_NAME_OPT,
236
+ cmdline.get_values (RESTRICT_FUNCTION_POINTER_BY_NAME_OPT));
237
+ }
227
238
}
228
239
229
240
function_pointer_restrictionst::restrictionst
@@ -249,17 +260,17 @@ function_pointer_restrictionst::merge_function_pointer_restrictions(
249
260
}
250
261
251
262
function_pointer_restrictionst::restrictionst
252
- parse_function_pointer_restrictions_from_command_line (
263
+ function_pointer_restrictionst::parse_function_pointer_restrictions (
253
264
const std::list<std::string> &restriction_opts,
254
- const std::string &option_name )
265
+ const std::string &option )
255
266
{
256
267
auto function_pointer_restrictions =
257
268
function_pointer_restrictionst::restrictionst{};
258
269
259
270
for (const std::string &restriction_opt : restriction_opts)
260
271
{
261
272
const auto restriction =
262
- parse_function_pointer_restriction (restriction_opt);
273
+ parse_function_pointer_restriction (restriction_opt, option );
263
274
264
275
const bool inserted = function_pointer_restrictions
265
276
.emplace (restriction.first , restriction.second )
@@ -270,23 +281,34 @@ parse_function_pointer_restrictions_from_command_line(
270
281
throw invalid_command_line_argument_exceptiont{
271
282
" function pointer restriction for `" + id2string (restriction.first ) +
272
283
" ' was specified twice" ,
273
- " -- " RESTRICT_FUNCTION_POINTER_OPT };
284
+ option };
274
285
}
275
286
}
276
287
277
288
return function_pointer_restrictions;
278
289
}
279
290
291
+
292
+ function_pointer_restrictionst::restrictionst
293
+ function_pointer_restrictionst::
294
+ parse_function_pointer_restrictions_from_command_line (
295
+ const std::list<std::string> &restriction_opts)
296
+ {
297
+ return parse_function_pointer_restrictions (
298
+ restriction_opts,
299
+ " --" RESTRICT_FUNCTION_POINTER_OPT);
300
+ }
301
+
280
302
function_pointer_restrictionst::restrictionst
281
303
function_pointer_restrictionst::parse_function_pointer_restrictions_from_file (
282
304
const std::list<std::string> &filenames,
283
305
message_handlert &message_handler)
284
306
{
285
307
auto merged_restrictions = function_pointer_restrictionst::restrictionst{};
308
+
286
309
for (auto const &filename : filenames)
287
310
{
288
- auto const restrictions =
289
- function_pointer_restrictionst::read_from_file (filename, message_handler);
311
+ auto const restrictions = read_from_file (filename, message_handler);
290
312
291
313
merged_restrictions = merge_function_pointer_restrictions (
292
314
std::move (merged_restrictions), restrictions.restrictions );
@@ -297,7 +319,8 @@ function_pointer_restrictionst::parse_function_pointer_restrictions_from_file(
297
319
298
320
function_pointer_restrictionst::restrictiont
299
321
function_pointer_restrictionst::parse_function_pointer_restriction (
300
- const std::string &restriction_opt)
322
+ const std::string &restriction_opt,
323
+ const std::string &option)
301
324
{
302
325
// the format for restrictions is <pointer_name>/<target[,more_targets]*>
303
326
// exactly one pointer and at least one target
@@ -310,23 +333,23 @@ function_pointer_restrictionst::parse_function_pointer_restriction(
310
333
{
311
334
throw invalid_command_line_argument_exceptiont{
312
335
" couldn't find '/' in `" + restriction_opt + " '" ,
313
- " -- " RESTRICT_FUNCTION_POINTER_OPT ,
336
+ option ,
314
337
restriction_format_message};
315
338
}
316
339
317
340
if (pointer_name_end == restriction_opt.size ())
318
341
{
319
342
throw invalid_command_line_argument_exceptiont{
320
343
" couldn't find names of targets after '/' in `" + restriction_opt + " '" ,
321
- " -- " RESTRICT_FUNCTION_POINTER_OPT ,
344
+ option ,
322
345
restriction_format_message};
323
346
}
324
347
325
348
if (pointer_name_end == 0 )
326
349
{
327
350
throw invalid_command_line_argument_exceptiont{
328
351
" couldn't find target name before '/' in `" + restriction_opt + " '" ,
329
- " -- " RESTRICT_FUNCTION_POINTER_OPT };
352
+ option };
330
353
}
331
354
332
355
auto const pointer_name = restriction_opt.substr (0 , pointer_name_end);
@@ -338,7 +361,7 @@ function_pointer_restrictionst::parse_function_pointer_restriction(
338
361
{
339
362
throw invalid_command_line_argument_exceptiont{
340
363
" missing target list for function pointer restriction " + pointer_name,
341
- " -- " RESTRICT_FUNCTION_POINTER_OPT ,
364
+ option ,
342
365
restriction_format_message};
343
366
}
344
367
@@ -351,7 +374,7 @@ function_pointer_restrictionst::parse_function_pointer_restriction(
351
374
{
352
375
throw invalid_command_line_argument_exceptiont (
353
376
" leading or trailing comma in restrictions for `" + pointer_name + " '" ,
354
- " -- " RESTRICT_FUNCTION_POINTER_OPT ,
377
+ option ,
355
378
restriction_format_message);
356
379
}
357
380
}
@@ -361,18 +384,27 @@ function_pointer_restrictionst::parse_function_pointer_restriction(
361
384
362
385
function_pointer_restrictionst function_pointer_restrictionst::from_options (
363
386
const optionst &options,
387
+ const goto_modelt &goto_model,
364
388
message_handlert &message_handler)
365
389
{
366
390
auto const restriction_opts =
367
391
options.get_list_option (RESTRICT_FUNCTION_POINTER_OPT);
368
392
auto const commandline_restrictions =
369
- parse_function_pointer_restrictions_from_command_line (
370
- restriction_opts, RESTRICT_FUNCTION_POINTER_OPT);
393
+ parse_function_pointer_restrictions_from_command_line (restriction_opts);
394
+
395
+ auto const restriction_file_opts =
396
+ options.get_list_option (RESTRICT_FUNCTION_POINTER_FROM_FILE_OPT);
371
397
auto const file_restrictions = parse_function_pointer_restrictions_from_file (
372
- options.get_list_option (RESTRICT_FUNCTION_POINTER_FROM_FILE_OPT),
373
- message_handler);
398
+ restriction_file_opts, message_handler);
399
+
400
+ auto const restriction_name_opts =
401
+ options.get_list_option (RESTRICT_FUNCTION_POINTER_BY_NAME_OPT);
402
+ auto const name_restrictions = get_function_pointer_by_name_restrictions (
403
+ restriction_name_opts, goto_model);
404
+
374
405
return {merge_function_pointer_restrictions (
375
- std::move (file_restrictions), commandline_restrictions)};
406
+ commandline_restrictions,
407
+ merge_function_pointer_restrictions (file_restrictions, name_restrictions))};
376
408
}
377
409
378
410
function_pointer_restrictionst
@@ -465,21 +497,16 @@ void function_pointer_restrictionst::write_to_file(
465
497
466
498
function_pointer_restrictions_json.output (outFile);
467
499
}
468
- function_pointer_restrictionst function_pointer_restrictionst::merge (
469
- const function_pointer_restrictionst &other) const
470
- {
471
- return function_pointer_restrictionst{
472
- merge_function_pointer_restrictions (restrictions, other.restrictions )};
473
- }
474
500
475
- function_pointer_restrictionst get_function_pointer_by_name_restrictions (
476
- const goto_modelt &goto_model,
477
- const optionst &options)
501
+ function_pointer_restrictionst::restrictionst
502
+ function_pointer_restrictionst::get_function_pointer_by_name_restrictions (
503
+ const std::list<std::string> &restriction_name_opts,
504
+ const goto_modelt &goto_model)
478
505
{
479
506
function_pointer_restrictionst::restrictionst by_name_restrictions =
480
- parse_function_pointer_restrictions_from_command_line (
481
- options. get_list_option ( RESTRICT_FUNCTION_POINTER_BY_NAME_OPT),
482
- RESTRICT_FUNCTION_POINTER_BY_NAME_OPT);
507
+ parse_function_pointer_restrictions (
508
+ restriction_name_opts, RESTRICT_FUNCTION_POINTER_BY_NAME_OPT);
509
+
483
510
function_pointer_restrictionst::restrictionst restrictions;
484
511
for (auto const &goto_function : goto_model.goto_functions .function_map )
485
512
{
@@ -520,5 +547,6 @@ function_pointer_restrictionst get_function_pointer_by_name_restrictions(
520
547
}
521
548
});
522
549
}
523
- return function_pointer_restrictionst{restrictions};
550
+
551
+ return restrictions;
524
552
}
0 commit comments