CBMC
ai_domain.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module: Abstract Interpretation
4 
5 Author: Daniel Kroening, kroening@kroening.com
6 
7 \*******************************************************************/
8 
11 
12 #include "ai_domain.h"
13 
14 #include <util/pointer_expr.h>
15 #include <util/simplify_expr.h>
16 
18  const
19 {
20  std::ostringstream out;
21  output(out, ai, ns);
22  json_stringt json(out.str());
23  return std::move(json);
24 }
25 
27 {
28  std::ostringstream out;
29  output(out, ai, ns);
30  xmlt xml("abstract_state");
31  xml.data = out.str();
32  return xml;
33 }
34 
44  const
45 {
46  // Care must be taken here to give something that is still writable
47  if(condition.id() == ID_index)
48  {
49  index_exprt ie = to_index_expr(condition);
50  bool no_simplification = ai_simplify(ie.index(), ns);
51  if(!no_simplification)
52  condition = simplify_expr(std::move(ie), ns);
53 
54  return no_simplification;
55  }
56  else if(condition.id() == ID_dereference)
57  {
58  dereference_exprt de = to_dereference_expr(condition);
59  bool no_simplification = ai_simplify(de.pointer(), ns);
60  if(!no_simplification)
61  condition = simplify_expr(std::move(de), ns); // So *(&x) -> x
62 
63  return no_simplification;
64  }
65  else if(condition.id() == ID_member)
66  {
67  member_exprt me = to_member_expr(condition);
68  // Since simplify_ai_lhs is required to return an addressable object
69  // (so remains a valid left hand side), to simplify
70  // `(something_simplifiable).b` we require that `something_simplifiable`
71  // must also be addressable
72  bool no_simplification = ai_simplify_lhs(me.compound(), ns);
73  if(!no_simplification)
74  condition = simplify_expr(std::move(me), ns);
75 
76  return no_simplification;
77  }
78  else
79  return true;
80 }
Abstract Interpretation Domain.
This is the basic interface of the abstract interpreter with default implementations of the core func...
Definition: ai.h:117
virtual xmlt output_xml(const ai_baset &ai, const namespacet &ns) const
Definition: ai_domain.cpp:26
virtual jsont output_json(const ai_baset &ai, const namespacet &ns) const
Definition: ai_domain.cpp:17
virtual bool ai_simplify_lhs(exprt &condition, const namespacet &ns) const
Simplifies the expression but keeps it as an l-value.
Definition: ai_domain.cpp:43
virtual void output(std::ostream &, const ai_baset &, const namespacet &) const
Definition: ai_domain.h:104
virtual bool ai_simplify(exprt &condition, const namespacet &) const
also add
Definition: ai_domain.h:149
Operator to dereference a pointer.
Definition: pointer_expr.h:834
Base class for all expressions.
Definition: expr.h:56
Array index operator.
Definition: std_expr.h:1470
exprt & index()
Definition: std_expr.h:1510
const irep_idt & id() const
Definition: irep.h:388
Definition: json.h:27
Extract member of struct or union.
Definition: std_expr.h:2849
const exprt & compound() const
Definition: std_expr.h:2898
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
Definition: namespace.h:94
Definition: xml.h:21
std::string data
Definition: xml.h:39
API to expression classes for Pointers.
const dereference_exprt & to_dereference_expr(const exprt &expr)
Cast an exprt to a dereference_exprt.
Definition: pointer_expr.h:890
static void json(json_objectT &result, const irep_idt &property_id, const property_infot &property_info)
Definition: properties.cpp:120
xmlt xml(const irep_idt &property_id, const property_infot &property_info)
Definition: properties.cpp:110
exprt simplify_expr(exprt src, const namespacet &ns)
const member_exprt & to_member_expr(const exprt &expr)
Cast an exprt to a member_exprt.
Definition: std_expr.h:2941
const index_exprt & to_index_expr(const exprt &expr)
Cast an exprt to an index_exprt.
Definition: std_expr.h:1538