|
| 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 | +} |
0 commit comments