@@ -8,7 +8,117 @@ Author: Daniel Poetzl
8
8
9
9
#include " c_object_factory_parameters.h"
10
10
11
+ #include < util/cmdline.h>
12
+ #include < util/exception_utils.h>
13
+ #include < util/optional_utils.h>
14
+ #include < util/string_utils.h>
15
+
16
+ #include < algorithm>
17
+ #include < string>
18
+
11
19
void parse_c_object_factory_options (const cmdlinet &cmdline, optionst &options)
12
20
{
13
21
parse_object_factory_options (cmdline, options);
22
+ if (cmdline.isset (" pointers-to-treat-as-arrays" ))
23
+ {
24
+ options.set_option (
25
+ " pointers-to-treat-as-arrays" ,
26
+ cmdline.get_comma_separated_values (" pointers-to-treat-as-arrays" ));
27
+ }
28
+ if (cmdline.isset (" associated-array-sizes" ))
29
+ {
30
+ options.set_option (
31
+ " associated-array-sizes" ,
32
+ cmdline.get_comma_separated_values (" associated-array-sizes" ));
33
+ }
34
+ if (cmdline.isset (" max-dynamic-array-size" ))
35
+ {
36
+ options.set_option (
37
+ " max-dynamic-array-size" , cmdline.get_value (" max-dynamic-array-size" ));
38
+ }
39
+ }
40
+
41
+ void c_object_factory_parameterst::set (const optionst &options)
42
+ {
43
+ object_factory_parameterst::set (options);
44
+ auto const &pointers_to_treat_as_array =
45
+ options.get_list_option (" pointers-to-treat-as-arrays" );
46
+ std::transform (
47
+ std::begin (pointers_to_treat_as_array),
48
+ std::end (pointers_to_treat_as_array),
49
+ std::inserter (
50
+ this ->pointers_to_treat_as_array , this ->pointers_to_treat_as_array .end ()),
51
+ id2string);
52
+
53
+ if (options.is_set (" max-dynamic-array-size" ))
54
+ {
55
+ max_dynamic_array_size =
56
+ options.get_unsigned_int_option (" max-dynamic-array-size" );
57
+ if (max_dynamic_array_size == 0 )
58
+ {
59
+ throw invalid_command_line_argument_exceptiont (
60
+ " Max dynamic array size must be >= 1" , " --max-dynamic-array-size" );
61
+ }
62
+ }
63
+ if (options.is_set (" associated-array-sizes" ))
64
+ {
65
+ array_name_to_associated_array_size_variable.clear ();
66
+ variables_that_hold_array_sizes.clear ();
67
+ auto const &array_size_pairs =
68
+ options.get_list_option (" associated-array-sizes" );
69
+ for (auto const &array_size_pair : array_size_pairs)
70
+ {
71
+ std::string array_name;
72
+ std::string size_name;
73
+ try
74
+ {
75
+ split_string (array_size_pair, ' :' , array_name, size_name);
76
+ }
77
+ catch (const deserialization_exceptiont &e)
78
+ {
79
+ throw invalid_command_line_argument_exceptiont{
80
+ " can't parse parameter value" ,
81
+ " --associated-array-sizes" ,
82
+ " pairs of array/size parameter names, separated by a ':' colon" };
83
+ }
84
+ auto const mapping_insert_result =
85
+ array_name_to_associated_array_size_variable.insert (
86
+ {irep_idt{array_name}, irep_idt{size_name}});
87
+ if (!mapping_insert_result.second )
88
+ {
89
+ throw invalid_command_line_argument_exceptiont{
90
+ " duplicate associated size entries for array `" + array_name +
91
+ " ', existing: `" + id2string (mapping_insert_result.first ->second ) +
92
+ " ', tried to insert: `" + size_name + " '" ,
93
+ " --associated-array-sizes" };
94
+ }
95
+ auto const size_name_insert_result =
96
+ variables_that_hold_array_sizes.insert (irep_idt{size_name});
97
+ if (!size_name_insert_result.second )
98
+ {
99
+ throw invalid_command_line_argument_exceptiont{
100
+ " using size parameter `" + size_name + " ' more than once" ,
101
+ " --associated-array-sizes" };
102
+ }
103
+ }
104
+ }
105
+ }
106
+
107
+ bool c_object_factory_parameterst::is_array_size_parameter (irep_idt id) const
108
+ {
109
+ return variables_that_hold_array_sizes.find (id) !=
110
+ end (variables_that_hold_array_sizes);
111
+ }
112
+
113
+ optionalt<irep_idt> c_object_factory_parameterst::get_associated_size_variable (
114
+ irep_idt array_id) const
115
+ {
116
+ return optional_lookup (
117
+ array_name_to_associated_array_size_variable, array_id);
118
+ }
119
+
120
+ bool c_object_factory_parameterst::should_be_treated_as_array (irep_idt id) const
121
+ {
122
+ return pointers_to_treat_as_array.find (id) !=
123
+ pointers_to_treat_as_array.end ();
14
124
}
0 commit comments