Skip to content

Commit a13d36d

Browse files
committed
Expand out for_each_comb. Doesn't need to be a template.
for_each_comb doesn't need to be a template - it's only used once, so we know the type of the collection and we know the operation to be performed.
1 parent 9094f89 commit a13d36d

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

src/analyses/variable-sensitivity/abstract_value_object.cpp

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -521,21 +521,27 @@ static exprt rewrite_expression(
521521
/// \param super_con: vector of some containers storing the values
522522
/// \param sub_con: the one combination being currently constructed
523523
/// \param f: callable with side-effects
524-
template <typename Con, typename F>
525524
void apply_comb(
526-
const std::vector<Con> &super_con,
527-
std::vector<typename Con::value_type> &sub_con,
528-
F f)
525+
abstract_object_sett &results,
526+
const std::vector<value_ranget> &super_con,
527+
std::vector<abstract_object_pointert> &sub_con,
528+
const exprt &expr,
529+
const abstract_environmentt &environment,
530+
const namespacet &ns)
529531
{
530532
size_t n = sub_con.size();
531533
if(n == super_con.size())
532-
f(sub_con);
534+
{
535+
auto rewritten_expr = rewrite_expression(expr, sub_con);
536+
auto combination = transform(rewritten_expr, sub_con, environment, ns);
537+
results.insert(combination);
538+
}
533539
else
534540
{
535541
for(const auto &value : super_con[n])
536542
{
537543
sub_con.push_back(value);
538-
apply_comb(super_con, sub_con, f);
544+
apply_comb(results, super_con, sub_con, expr, environment, ns);
539545
sub_con.pop_back();
540546
}
541547
}
@@ -546,11 +552,16 @@ void apply_comb(
546552
/// f(1,1,1), f(1,1,2), f(1,1,3), f(2,1,1), f(2,1,2), f(2,1,3).
547553
/// \param super_con: vector of some containers storing the values
548554
/// \param f: callable with side-effects
549-
template <typename Con, typename F>
550-
void for_each_comb(const std::vector<Con> &super_con, F f)
555+
abstract_object_sett evaluate_each_combination(
556+
const std::vector<value_ranget> &super_con,
557+
const exprt &expr,
558+
const abstract_environmentt &environment,
559+
const namespacet &ns)
551560
{
552-
std::vector<typename Con::value_type> sub_con;
553-
apply_comb(super_con, sub_con, f);
561+
abstract_object_sett results;
562+
std::vector<abstract_object_pointert> sub_con;
563+
apply_comb(results, super_con, sub_con, expr, environment, ns);
564+
return results;
554565
}
555566

556567
static abstract_object_pointert resolve_new_values(
@@ -578,15 +589,8 @@ static abstract_object_pointert value_set_expression_transform(
578589
return value_set_evaluate_conditional(
579590
expr.type(), collective_operands, environment, ns);
580591

581-
abstract_object_sett resulting_objects;
582-
583-
for_each_comb(
584-
collective_operands,
585-
[&resulting_objects, &expr, &environment, &ns](
586-
const std::vector<abstract_object_pointert> &ops) {
587-
auto rewritten_expr = rewrite_expression(expr, ops);
588-
resulting_objects.insert(transform(rewritten_expr, ops, environment, ns));
589-
});
592+
auto resulting_objects =
593+
evaluate_each_combination(collective_operands, expr, environment, ns);
590594

591595
return resolve_new_values(resulting_objects, environment);
592596
}

0 commit comments

Comments
 (0)