|
| 1 | +/*******************************************************************\ |
| 2 | +
|
| 3 | +Module: Abstract Interpretation |
| 4 | +
|
| 5 | +Author: Daniel Kroening, [email protected] |
| 6 | +
|
| 7 | +\*******************************************************************/ |
| 8 | + |
| 9 | +/// \file |
| 10 | +/// Abstract Interpretation Domain |
| 11 | + |
| 12 | +#ifndef CPROVER_ANALYSES_AI_DOMAIN_H |
| 13 | +#define CPROVER_ANALYSES_AI_DOMAIN_H |
| 14 | + |
| 15 | +#include <util/expr.h> |
| 16 | +#include <util/json.h> |
| 17 | +#include <util/make_unique.h> |
| 18 | +#include <util/xml.h> |
| 19 | + |
| 20 | +#include <goto-programs/goto_model.h> |
| 21 | + |
| 22 | +// forward reference the abstract interpreter interface |
| 23 | +class ai_baset; |
| 24 | + |
| 25 | +/// The interface offered by a domain, allows code to manipulate domains without |
| 26 | +/// knowing their exact type. Derive from this to implement domains. |
| 27 | +class ai_domain_baset |
| 28 | +{ |
| 29 | +protected: |
| 30 | + /// The constructor is expected to produce 'false' or 'bottom' |
| 31 | + ai_domain_baset() |
| 32 | + { |
| 33 | + } |
| 34 | + |
| 35 | +public: |
| 36 | + virtual ~ai_domain_baset() |
| 37 | + { |
| 38 | + } |
| 39 | + |
| 40 | + typedef goto_programt::const_targett locationt; |
| 41 | + |
| 42 | + /// how function calls are treated: |
| 43 | + /// a) there is an edge from each call site to the function head |
| 44 | + /// b) there is an edge from the last instruction (END_FUNCTION) |
| 45 | + /// of the function to the instruction _following_ the call site |
| 46 | + /// (this also needs to set the LHS, if applicable) |
| 47 | + /// |
| 48 | + /// "this" is the domain before the instruction "from" |
| 49 | + /// "from" is the instruction to be interpretted |
| 50 | + /// "to" is the next instruction (for GOTO, FUNCTION_CALL, END_FUNCTION) |
| 51 | + /// |
| 52 | + /// PRECONDITION(from.is_dereferenceable(), "Must not be _::end()") |
| 53 | + /// PRECONDITION(to.is_dereferenceable(), "Must not be _::end()") |
| 54 | + /// PRECONDITION(are_comparable(from,to) || |
| 55 | + /// (from->is_function_call() || from->is_end_function()) |
| 56 | + |
| 57 | + virtual void transform( |
| 58 | + locationt from, |
| 59 | + locationt to, |
| 60 | + ai_baset &ai, |
| 61 | + const namespacet &ns) = 0; |
| 62 | + |
| 63 | + virtual void |
| 64 | + output(std::ostream &out, const ai_baset &ai, const namespacet &ns) const |
| 65 | + { |
| 66 | + } |
| 67 | + |
| 68 | + virtual jsont output_json(const ai_baset &ai, const namespacet &ns) const; |
| 69 | + |
| 70 | + virtual xmlt output_xml(const ai_baset &ai, const namespacet &ns) const; |
| 71 | + |
| 72 | + /// no states |
| 73 | + virtual void make_bottom() = 0; |
| 74 | + |
| 75 | + /// all states -- the analysis doesn't use this, |
| 76 | + /// and domains may refuse to implement it. |
| 77 | + virtual void make_top() = 0; |
| 78 | + |
| 79 | + /// a reasonable entry-point state |
| 80 | + virtual void make_entry() = 0; |
| 81 | + |
| 82 | + virtual bool is_bottom() const = 0; |
| 83 | + |
| 84 | + virtual bool is_top() const = 0; |
| 85 | + |
| 86 | + /// also add |
| 87 | + /// |
| 88 | + /// bool merge(const T &b, locationt from, locationt to); |
| 89 | + /// |
| 90 | + /// This computes the join between "this" and "b". |
| 91 | + /// Return true if "this" has changed. |
| 92 | + /// In the usual case, "b" is the updated state after "from" |
| 93 | + /// and "this" is the state before "to". |
| 94 | + /// |
| 95 | + /// PRECONDITION(from.is_dereferenceable(), "Must not be _::end()") |
| 96 | + /// PRECONDITION(to.is_dereferenceable(), "Must not be _::end()") |
| 97 | + |
| 98 | + /// This method allows an expression to be simplified / evaluated using the |
| 99 | + /// current state. It is used to evaluate assertions and in program |
| 100 | + /// simplification |
| 101 | + |
| 102 | + /// return true if unchanged |
| 103 | + virtual bool ai_simplify(exprt &condition, const namespacet &ns) const |
| 104 | + { |
| 105 | + return true; |
| 106 | + } |
| 107 | + |
| 108 | + /// Simplifies the expression but keeps it as an l-value |
| 109 | + virtual bool ai_simplify_lhs(exprt &condition, const namespacet &ns) const; |
| 110 | + |
| 111 | + /// Gives a Boolean condition that is true for all values represented by the |
| 112 | + /// domain. This allows domains to be converted into program invariants. |
| 113 | + virtual exprt to_predicate(void) const |
| 114 | + { |
| 115 | + if(is_bottom()) |
| 116 | + return false_exprt(); |
| 117 | + else |
| 118 | + return true_exprt(); |
| 119 | + } |
| 120 | +}; |
| 121 | + |
| 122 | +#endif |
0 commit comments