Skip to content

Commit d96545d

Browse files
committed
Handle the config specific options in-house
via a member method handle_option. That is recursive_initialization_config now implements its own handle_option that parses the user options specific to the recursive initialization. These are: minimal null tree depth, maximal nondeterministic tree depth, maximal array size and minimal array size. To that end, the config inherits from the harness_option_parser, e.g. to have access to require_exactly_one_value, etc.
1 parent 31fc42c commit d96545d

File tree

2 files changed

+67
-1
lines changed

2 files changed

+67
-1
lines changed

src/goto-harness/recursive_initialization.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,63 @@ Author: Diffblue Ltd.
1616
#include <util/optional_utils.h>
1717
#include <util/std_code.h>
1818
#include <util/std_expr.h>
19+
#include <util/string2int.h>
1920

2021
#include <functional>
2122

23+
bool recursive_initialization_configt::handle_option(
24+
const std::string &option,
25+
const std::list<std::string> &values)
26+
{
27+
if(option == COMMON_HARNESS_GENERATOR_MIN_NULL_TREE_DEPTH_OPT)
28+
{
29+
auto const value = require_exactly_one_value(option, values);
30+
auto const user_min_null_tree_depth =
31+
string2optional<std::size_t>(value, 10);
32+
if(user_min_null_tree_depth.has_value())
33+
{
34+
min_null_tree_depth = user_min_null_tree_depth.value();
35+
}
36+
else
37+
{
38+
throw invalid_command_line_argument_exceptiont{
39+
"failed to convert `" + value + "' to integer",
40+
"--" COMMON_HARNESS_GENERATOR_MIN_NULL_TREE_DEPTH_OPT};
41+
}
42+
return true;
43+
}
44+
else if(option == COMMON_HARNESS_GENERATOR_MAX_NONDET_TREE_DEPTH_OPT)
45+
{
46+
auto const value = require_exactly_one_value(option, values);
47+
auto const user_max_nondet_tree_depth =
48+
string2optional<std::size_t>(value, 10);
49+
if(user_max_nondet_tree_depth.has_value())
50+
{
51+
max_nondet_tree_depth = user_max_nondet_tree_depth.value();
52+
}
53+
else
54+
{
55+
throw invalid_command_line_argument_exceptiont{
56+
"failed to convert `" + value + "' to integer",
57+
"--" COMMON_HARNESS_GENERATOR_MAX_NONDET_TREE_DEPTH_OPT};
58+
}
59+
return true;
60+
}
61+
else if(option == COMMON_HARNESS_GENERATOR_MAX_ARRAY_SIZE_OPT)
62+
{
63+
max_dynamic_array_size = require_one_size_value(
64+
COMMON_HARNESS_GENERATOR_MAX_ARRAY_SIZE_OPT, values);
65+
return true;
66+
}
67+
else if(option == COMMON_HARNESS_GENERATOR_MIN_ARRAY_SIZE_OPT)
68+
{
69+
min_dynamic_array_size = require_one_size_value(
70+
COMMON_HARNESS_GENERATOR_MIN_ARRAY_SIZE_OPT, values);
71+
return true;
72+
}
73+
return false;
74+
}
75+
2276
recursive_initializationt::recursive_initializationt(
2377
recursive_initialization_configt initialization_config,
2478
goto_modelt &goto_model)

src/goto-harness/recursive_initialization.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ Author: Diffblue Ltd.
1818
#include <util/optional.h>
1919
#include <util/std_types.h>
2020

21-
struct recursive_initialization_configt
21+
#include "function_harness_generator_options.h"
22+
#include "goto_harness_generator.h"
23+
24+
struct recursive_initialization_configt : harness_options_parsert
2225
{
2326
std::size_t min_null_tree_depth = 1;
2427
std::size_t max_nondet_tree_depth = 2;
@@ -35,6 +38,15 @@ struct recursive_initialization_configt
3538
std::set<irep_idt> pointers_to_treat_as_cstrings;
3639

3740
std::string to_string() const; // for debugging purposes
41+
42+
/// Parse the options specific for recursive initialisation
43+
/// \param option: the user option name
44+
/// \param values: the (one-or-more) values for this option
45+
/// \return true if the option belonged to recursive initialisation and was
46+
/// successfully parsed here
47+
bool handle_option(
48+
const std::string &option,
49+
const std::list<std::string> &values);
3850
};
3951

4052
/// Class for generating initialisation code

0 commit comments

Comments
 (0)