|
| 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/json.h> |
| 16 | +#include <util/xml.h> |
| 17 | +#include <util/expr.h> |
| 18 | +#include <util/make_unique.h> |
| 19 | + |
| 20 | +#include <goto-programs/goto_model.h> |
| 21 | + |
| 22 | +// forward reference |
| 23 | +class ai_baset; |
| 24 | + |
| 25 | +// don't use me -- I am just a base class |
| 26 | +// please derive from me |
| 27 | +class ai_domain_baset |
| 28 | +{ |
| 29 | +public: |
| 30 | + // The constructor is expected to produce 'false' |
| 31 | + // or 'bottom' |
| 32 | + ai_domain_baset() |
| 33 | + { |
| 34 | + } |
| 35 | + |
| 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 output( |
| 64 | + std::ostream &out, |
| 65 | + const ai_baset &ai, |
| 66 | + const namespacet &ns) const |
| 67 | + { |
| 68 | + } |
| 69 | + |
| 70 | + virtual jsont output_json( |
| 71 | + const ai_baset &ai, |
| 72 | + const namespacet &ns) const; |
| 73 | + |
| 74 | + virtual xmlt output_xml( |
| 75 | + const ai_baset &ai, |
| 76 | + const namespacet &ns) const; |
| 77 | + |
| 78 | + // no states |
| 79 | + virtual void make_bottom()=0; |
| 80 | + |
| 81 | + // all states -- the analysis doesn't use this, |
| 82 | + // and domains may refuse to implement it. |
| 83 | + virtual void make_top()=0; |
| 84 | + |
| 85 | + // a reasonable entry-point state |
| 86 | + virtual void make_entry()=0; |
| 87 | + |
| 88 | + virtual bool is_bottom() const=0; |
| 89 | + |
| 90 | + virtual bool is_top() const=0; |
| 91 | + |
| 92 | + // also add |
| 93 | + // |
| 94 | + // bool merge(const T &b, locationt from, locationt to); |
| 95 | + // |
| 96 | + // This computes the join between "this" and "b". |
| 97 | + // Return true if "this" has changed. |
| 98 | + // In the usual case, "b" is the updated state after "from" |
| 99 | + // and "this" is the state before "to". |
| 100 | + // |
| 101 | + // PRECONDITION(from.is_dereferenceable(), "Must not be _::end()") |
| 102 | + // PRECONDITION(to.is_dereferenceable(), "Must not be _::end()") |
| 103 | + |
| 104 | + // This method allows an expression to be simplified / evaluated using the |
| 105 | + // current state. It is used to evaluate assertions and in program |
| 106 | + // simplification |
| 107 | + |
| 108 | + // return true if unchanged |
| 109 | + virtual bool ai_simplify( |
| 110 | + exprt &condition, |
| 111 | + const namespacet &ns) const |
| 112 | + { |
| 113 | + return true; |
| 114 | + } |
| 115 | + |
| 116 | + // Simplifies the expression but keeps it as an l-value |
| 117 | + virtual bool ai_simplify_lhs( |
| 118 | + exprt &condition, |
| 119 | + const namespacet &ns) const; |
| 120 | +}; |
| 121 | + |
| 122 | +#endif |
0 commit comments