Skip to content

Commit 3bd1c87

Browse files
committed
Pull array helpers out of full_array merge unit tests
1 parent c57e6c2 commit 3bd1c87

File tree

7 files changed

+207
-159
lines changed

7 files changed

+207
-159
lines changed

unit/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ SRC += analyses/ai/ai.cpp \
2828
analyses/variable-sensitivity/interval_abstract_value/merge.cpp \
2929
analyses/variable-sensitivity/interval_abstract_value/to_predicate.cpp \
3030
analyses/variable-sensitivity/interval_abstract_value/widening_merge.cpp \
31+
analyses/variable-sensitivity/full_struct_abstract_object/array_builder.cpp \
3132
analyses/variable-sensitivity/full_struct_abstract_object/merge.cpp \
3233
analyses/variable-sensitivity/full_struct_abstract_object/struct_builder.cpp \
3334
analyses/variable-sensitivity/full_struct_abstract_object/to_predicate.cpp \
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*******************************************************************\
2+
3+
Module: Unit tests helpers for arrays
4+
5+
Author: Jez Higgins, [email protected]
6+
7+
\*******************************************************************/
8+
9+
#include <analyses/variable-sensitivity/abstract_environment.h>
10+
#include <analyses/variable-sensitivity/full_array_abstract_object.h>
11+
#include <analyses/variable-sensitivity/full_array_abstract_object/array_builder.h>
12+
#include <arith_tools.h>
13+
#include <util/mathematical_types.h>
14+
15+
full_array_abstract_objectt::full_array_pointert build_array(
16+
const exprt &array_expr,
17+
abstract_environmentt &environment,
18+
const namespacet &ns)
19+
{
20+
return std::make_shared<full_array_abstract_objectt>(
21+
array_expr, environment, ns);
22+
}
23+
24+
full_array_abstract_objectt::full_array_pointert build_array(
25+
const std::vector<int> &array,
26+
abstract_environmentt &environment,
27+
const namespacet &ns)
28+
{
29+
const array_typet array_type(
30+
integer_typet(), from_integer(array.size(), integer_typet()));
31+
32+
exprt::operandst element_ops;
33+
34+
for(auto element : array)
35+
element_ops.push_back(from_integer(element, integer_typet()));
36+
37+
auto array_expr = array_exprt(element_ops, array_type);
38+
return build_array(array_expr, environment, ns);
39+
}
40+
41+
full_array_abstract_objectt::full_array_pointert build_top_array()
42+
{
43+
auto array_type =
44+
array_typet(integer_typet(), from_integer(3, integer_typet()));
45+
return std::make_shared<full_array_abstract_objectt>(array_type, true, false);
46+
}
47+
48+
full_array_abstract_objectt::full_array_pointert build_bottom_array()
49+
{
50+
auto array_type =
51+
array_typet(integer_typet(), from_integer(3, integer_typet()));
52+
return std::make_shared<full_array_abstract_objectt>(array_type, false, true);
53+
}
54+
55+
exprt read_index(
56+
full_array_abstract_objectt::full_array_pointert array_object,
57+
const index_exprt &index,
58+
abstract_environmentt &environment,
59+
const namespacet &ns)
60+
{
61+
return array_object->expression_transform(index, {}, environment, ns)
62+
->to_constant();
63+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*******************************************************************\
2+
3+
Module: Unit tests helpers for arrays
4+
5+
Author: Jez Higgins, [email protected]
6+
7+
\*******************************************************************/
8+
#ifndef CPROVER_ANALYSES_VARIABLE_SENSITIVITY_FULL_ARRAY_ABSTRACT_OBJECT_ARRAY_BUILDER_H
9+
#define CPROVER_ANALYSES_VARIABLE_SENSITIVITY_FULL_ARRAY_ABSTRACT_OBJECT_ARRAY_BUILDER_H
10+
11+
#include <analyses/variable-sensitivity/full_array_abstract_object.h>
12+
13+
full_array_abstract_objectt::full_array_pointert build_array(
14+
const exprt &array_expr,
15+
abstract_environmentt &environment,
16+
const namespacet &ns);
17+
18+
full_array_abstract_objectt::full_array_pointert build_array(
19+
const std::vector<int> &array,
20+
abstract_environmentt &environment,
21+
const namespacet &ns);
22+
23+
full_array_abstract_objectt::full_array_pointert build_top_array();
24+
25+
full_array_abstract_objectt::full_array_pointert build_bottom_array();
26+
27+
exprt read_index(
28+
full_array_abstract_objectt::full_array_pointert array_object,
29+
const index_exprt &index,
30+
abstract_environmentt &environment,
31+
const namespacet &ns);
32+
33+
#endif

0 commit comments

Comments
 (0)