cprover
Toggle main menu visibility
Loading...
Searching...
No Matches
abstract_object_set.cpp
Go to the documentation of this file.
1
/*******************************************************************\
2
3
Module: analyses variable-sensitivity
4
5
Author: Jez Higgins, jez@jezuk.co.uk
6
7
\*******************************************************************/
8
9
#include <
analyses/variable-sensitivity/abstract_object_set.h
>
10
11
#include <
util/interval.h
>
12
#include <
util/string_utils.h
>
13
14
#include <algorithm>
15
16
static
bool
by_length
(
const
std::string &lhs,
const
std::string &rhs)
17
{
18
if
(lhs.size() < rhs.size())
19
return
true
;
20
if
(lhs.size() > rhs.size())
21
return
false
;
22
return
lhs < rhs;
23
}
24
25
void
abstract_object_sett::output
(
26
std::ostream &out,
27
const
ai_baset
&ai,
28
const
namespacet
&ns)
const
29
{
30
std::vector<std::string> output_values;
31
for
(
const
auto
&value :
values
)
32
{
33
std::ostringstream ss;
34
value->output(ss, ai, ns);
35
output_values.emplace_back(ss.str());
36
}
37
std::sort(output_values.begin(), output_values.end(),
by_length
);
38
39
join_strings
(out, output_values.begin(), output_values.end(),
", "
);
40
}
41
42
constant_interval_exprt
abstract_object_sett::to_interval
()
const
43
{
44
PRECONDITION
(!
values
.empty());
45
46
auto
initial =
47
std::dynamic_pointer_cast<const abstract_value_objectt>(
first
())
48
->to_interval();
49
50
if
(initial.is_boolean() &&
values
.size() == 2)
// must be both true and false
51
return
constant_interval_exprt
(
false_exprt
(),
true_exprt
());
52
53
exprt
lower_expr = initial.get_lower();
54
exprt
upper_expr = initial.get_upper();
55
56
for
(
const
auto
&value :
values
)
57
{
58
const
auto
&v =
59
std::dynamic_pointer_cast<const abstract_value_objectt>(value);
60
const
auto
&value_expr = v->to_interval();
61
lower_expr =
62
constant_interval_exprt::get_min
(lower_expr, value_expr.get_lower());
63
upper_expr =
64
constant_interval_exprt::get_max
(upper_expr, value_expr.get_upper());
65
}
66
return
constant_interval_exprt
(lower_expr, upper_expr);
67
}
by_length
static bool by_length(const std::string &lhs, const std::string &rhs)
Definition
abstract_object_set.cpp:16
abstract_object_set.h
an unordered set of value objects
abstract_object_sett::output
void output(std::ostream &out, const ai_baset &ai, const namespacet &ns) const
Definition
abstract_object_set.cpp:25
abstract_object_sett::first
abstract_object_pointert first() const
Definition
abstract_object_set.h:53
abstract_object_sett::values
value_sett values
Definition
abstract_object_set.h:94
abstract_object_sett::to_interval
constant_interval_exprt to_interval() const
Calculate the set of values as an interval.
Definition
abstract_object_set.cpp:42
ai_baset
This is the basic interface of the abstract interpreter with default implementations of the core func...
Definition
ai.h:117
constant_interval_exprt
Represents an interval of values.
Definition
interval.h:52
constant_interval_exprt::get_max
static exprt get_max(const exprt &a, const exprt &b)
Definition
interval.cpp:960
constant_interval_exprt::get_min
static exprt get_min(const exprt &a, const exprt &b)
Definition
interval.cpp:965
exprt
Base class for all expressions.
Definition
expr.h:57
false_exprt
The Boolean constant false.
Definition
std_expr.h:3125
namespacet
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition
namespace.h:91
true_exprt
The Boolean constant true.
Definition
std_expr.h:3116
interval.h
PRECONDITION
#define PRECONDITION(CONDITION)
Definition
invariant.h:463
string_utils.h
join_strings
Stream & join_strings(Stream &&os, const It b, const It e, const Delimiter &delimiter, TransformFunc &&transform_func)
Prints items to an stream, separated by a constant delimiter.
Definition
string_utils.h:61
analyses
variable-sensitivity
abstract_object_set.cpp
Generated by
1.17.0