Skip to content

Commit 7c6507f

Browse files
committed
Pass command line option to parse_function_pointer_restriction()
1 parent 237b400 commit 7c6507f

File tree

3 files changed

+23
-17
lines changed

3 files changed

+23
-17
lines changed

src/goto-programs/restrict_function_pointers.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ parse_function_pointer_restrictions_from_command_line(
260260
for(const std::string &restriction_opt : restriction_opts)
261261
{
262262
const auto restriction =
263-
parse_function_pointer_restriction(restriction_opt);
263+
parse_function_pointer_restriction(restriction_opt, "--" + option_name);
264264

265265
const bool inserted = function_pointer_restrictions
266266
.emplace(restriction.first, restriction.second)
@@ -298,7 +298,8 @@ function_pointer_restrictionst::parse_function_pointer_restrictions_from_file(
298298

299299
function_pointer_restrictionst::restrictiont
300300
function_pointer_restrictionst::parse_function_pointer_restriction(
301-
const std::string &restriction_opt)
301+
const std::string &restriction_opt,
302+
const std::string &option)
302303
{
303304
// the format for restrictions is <pointer_name>/<target[,more_targets]*>
304305
// exactly one pointer and at least one target
@@ -311,23 +312,23 @@ function_pointer_restrictionst::parse_function_pointer_restriction(
311312
{
312313
throw invalid_command_line_argument_exceptiont{
313314
"couldn't find '/' in `" + restriction_opt + "'",
314-
"--" RESTRICT_FUNCTION_POINTER_OPT,
315+
option,
315316
restriction_format_message};
316317
}
317318

318319
if(pointer_name_end == restriction_opt.size())
319320
{
320321
throw invalid_command_line_argument_exceptiont{
321322
"couldn't find names of targets after '/' in `" + restriction_opt + "'",
322-
"--" RESTRICT_FUNCTION_POINTER_OPT,
323+
option,
323324
restriction_format_message};
324325
}
325326

326327
if(pointer_name_end == 0)
327328
{
328329
throw invalid_command_line_argument_exceptiont{
329330
"couldn't find target name before '/' in `" + restriction_opt + "'",
330-
"--" RESTRICT_FUNCTION_POINTER_OPT};
331+
option};
331332
}
332333

333334
auto const pointer_name = restriction_opt.substr(0, pointer_name_end);
@@ -339,7 +340,7 @@ function_pointer_restrictionst::parse_function_pointer_restriction(
339340
{
340341
throw invalid_command_line_argument_exceptiont{
341342
"missing target list for function pointer restriction " + pointer_name,
342-
"--" RESTRICT_FUNCTION_POINTER_OPT,
343+
option,
343344
restriction_format_message};
344345
}
345346

@@ -352,7 +353,7 @@ function_pointer_restrictionst::parse_function_pointer_restriction(
352353
{
353354
throw invalid_command_line_argument_exceptiont(
354355
"leading or trailing comma in restrictions for `" + pointer_name + "'",
355-
"--" RESTRICT_FUNCTION_POINTER_OPT,
356+
option,
356357
restriction_format_message);
357358
}
358359
}

src/goto-programs/restrict_function_pointers.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,9 @@ class function_pointer_restrictionst
9898
const std::list<std::string> &filenames,
9999
message_handlert &message_handler);
100100

101-
static restrictiont
102-
parse_function_pointer_restriction(const std::string &restriction_opt);
101+
static restrictiont parse_function_pointer_restriction(
102+
const std::string &restriction_opt,
103+
const std::string &option);
103104
};
104105

105106
function_pointer_restrictionst get_function_pointer_by_name_restrictions(

unit/goto-programs/restrict_function_pointers.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,43 +23,47 @@ void restriction_parsing_test()
2323
{
2424
{
2525
const auto res =
26-
fp_restrictionst::parse_function_pointer_restriction("func1/func2");
26+
fp_restrictionst::parse_function_pointer_restriction(
27+
"func1/func2", "test");
2728
REQUIRE(res.first == "func1");
2829
REQUIRE(res.second.size() == 1);
2930
REQUIRE(res.second.find("func2") != res.second.end());
3031
}
3132

3233
{
3334
const auto res =
34-
fp_restrictionst::parse_function_pointer_restriction("func1/func2,func3");
35+
fp_restrictionst::parse_function_pointer_restriction(
36+
"func1/func2,func3", "test");
3537
REQUIRE(res.first == "func1");
3638
REQUIRE(res.second.size() == 2);
3739
REQUIRE(res.second.find("func2") != res.second.end());
3840
REQUIRE(res.second.find("func3") != res.second.end());
3941
}
4042

4143
REQUIRE_THROWS_AS(
42-
fp_restrictionst::parse_function_pointer_restriction("func"),
44+
fp_restrictionst::parse_function_pointer_restriction("func", "test"),
4345
invalid_command_line_argument_exceptiont);
4446

4547
REQUIRE_THROWS_AS(
46-
fp_restrictionst::parse_function_pointer_restriction("/func"),
48+
fp_restrictionst::parse_function_pointer_restriction("/func", "test"),
4749
invalid_command_line_argument_exceptiont);
4850

4951
REQUIRE_THROWS_AS(
50-
fp_restrictionst::parse_function_pointer_restriction("func/"),
52+
fp_restrictionst::parse_function_pointer_restriction("func/", "test"),
5153
invalid_command_line_argument_exceptiont);
5254

5355
REQUIRE_THROWS_AS(
54-
fp_restrictionst::parse_function_pointer_restriction("func/,"),
56+
fp_restrictionst::parse_function_pointer_restriction("func/,", "test"),
5557
invalid_command_line_argument_exceptiont);
5658

5759
REQUIRE_THROWS_AS(
58-
fp_restrictionst::parse_function_pointer_restriction("func1/func2,"),
60+
fp_restrictionst::parse_function_pointer_restriction(
61+
"func1/func2,", "test"),
5962
invalid_command_line_argument_exceptiont);
6063

6164
REQUIRE_THROWS_AS(
62-
fp_restrictionst::parse_function_pointer_restriction("func1/,func2"),
65+
fp_restrictionst::parse_function_pointer_restriction(
66+
"func1/,func2", "test"),
6367
invalid_command_line_argument_exceptiont);
6468
}
6569

0 commit comments

Comments
 (0)