-
Notifications
You must be signed in to change notification settings - Fork 273
/
Copy pathai_domain.cpp
80 lines (68 loc) · 2.42 KB
/
ai_domain.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*******************************************************************\
Module: Abstract Interpretation
Author: Daniel Kroening, [email protected]
\*******************************************************************/
/// \file
/// Abstract Interpretation Domain
#include "ai_domain.h"
#include <util/pointer_expr.h>
#include <util/simplify_expr.h>
jsont ai_domain_baset::output_json(const ai_baset &ai, const namespacet &ns)
const
{
std::ostringstream out;
output(out, ai, ns);
json_stringt json(out.str());
return std::move(json);
}
xmlt ai_domain_baset::output_xml(const ai_baset &ai, const namespacet &ns) const
{
std::ostringstream out;
output(out, ai, ns);
xmlt xml("abstract_state");
xml.data = out.str();
return xml;
}
/// Use the information in the domain to simplify the expression on the LHS of
/// an assignment. This for example won't simplify symbols to their values, but
/// does simplify indices in arrays, members of structs and dereferencing of
/// pointers
/// \param condition: The expression to simplify
/// \param ns: The namespace
/// \return True if condition did not change. False otherwise. condition will be
/// updated with the simplified condition if it has worked
bool ai_domain_baset::ai_simplify_lhs(exprt &condition, const namespacet &ns)
const
{
// Care must be taken here to give something that is still writable
if(condition.id() == ID_index)
{
index_exprt ie = to_index_expr(condition);
bool no_simplification = ai_simplify(ie.index(), ns);
if(!no_simplification)
condition = simplify_expr(std::move(ie), ns);
return no_simplification;
}
else if(condition.id() == ID_dereference)
{
dereference_exprt de = to_dereference_expr(condition);
bool no_simplification = ai_simplify(de.pointer(), ns);
if(!no_simplification)
condition = simplify_expr(std::move(de), ns); // So *(&x) -> x
return no_simplification;
}
else if(condition.id() == ID_member)
{
member_exprt me = to_member_expr(condition);
// Since simplify_ai_lhs is required to return an addressable object
// (so remains a valid left hand side), to simplify
// `(something_simplifiable).b` we require that `something_simplifiable`
// must also be addressable
bool no_simplification = ai_simplify_lhs(me.compound(), ns);
if(!no_simplification)
condition = simplify_expr(std::move(me), ns);
return no_simplification;
}
else
return true;
}