26std::optional<code_with_contract_typet>
40 return get_contract(function_identifier, ns).has_value();
45 auto text =
expr2c(src, ns);
47 return std::string(text, 0,
MAX_TEXT - 3) +
"...";
157 for(
auto &target : targets.operands())
193 return symbol_expr.get_identifier().starts_with(
205 return symbol_expr.get_identifier().starts_with(
"old::");
213 const std::string &prefix,
214 std::vector<std::pair<symbol_exprt, exprt>> &
old_exprs)
216 for(std::size_t i = 0; i <
old_exprs.size(); i++)
223 irep_idt identifier = prefix + std::to_string(index);
231 const std::string &prefix,
232 std::vector<std::pair<symbol_exprt, exprt>> &
old_exprs)
249 const std::vector<std::pair<symbol_exprt, exprt>> &
old_exprs,
267 goto_functionst::function_mapt::value_type &f,
278 auto &body = f.second.body;
280 if(body.instructions.empty())
291 for(
auto &assumption :
contract.c_requires())
301 std::vector<std::pair<symbol_exprt, exprt>>
old_exprs;
308 auto last = body.instructions.end();
309 if(std::prev(last)->is_end_function())
310 last = std::prev(last);
312 for(
auto &assertion :
contract.c_ensures())
316 std::string
comment =
"postcondition";
317 if(
contract.c_ensures().size() >= 2)
320 auto location = assertion.source_location();
321 location.set_function(f.first);
342 for(
auto &instruction : body.instructions)
343 instruction.transform(
363 for(
auto it = body.instructions.begin(); it != body.instructions.end();
368 const auto &lhs = it->assign_lhs();
380 auto location = it->source_location();
381 location.set_property_class(
"assigns");
382 location.set_comment(
"assigns clause");
393 goto_functionst::function_mapt::value_type &f,
396 auto &body = f.second.body;
401 for(
auto it = body.instructions.begin(); it != body.instructions.end(); it++)
403 if(it->is_function_call())
405 const auto &function = it->call_function();
418 std::vector<std::pair<symbol_exprt, exprt>>
old_exprs;
430 const auto ¶meters =
to_code_type(symbol.type).parameters();
431 const auto &arguments = it->call_arguments();
433 for(std::size_t p = 0; p <
f_it->second.parameter_identifiers.size();
437 f_it->second.parameter_identifiers[p], parameters[p].type());
442 const auto &call_lhs = it->call_lhs();
455 auto location = it->source_location();
457 location.set_comment(
458 id2string(symbol.display_name()) +
" precondition " +
471 auto location = it->source_location();
482 const auto &targets =
486 for(
auto &target : targets)
493 auto goto_instruction =
522 auto &location = it->source_location();
543 it->turn_into_skip();
546 body.destructive_insert(std::next(it), dest);
const code_with_contract_typet & to_code_with_contract_type(const typet &type)
Cast a typet to a code_with_contract_typet.
Operator to return the address of an object.
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Boolean AND All operands must be boolean, and the result is always boolean.
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Base class for all expressions.
std::vector< exprt > operandst
typet & type()
Return the type of the expression.
const source_locationt & source_location() const
source_locationt & add_source_location()
function_mapt function_map
symbol_tablet symbol_table
Symbol table.
goto_functionst goto_functions
GOTO functions.
A generic container class for the GOTO intermediate representation of one function.
static instructiont make_assumption(const exprt &g, const source_locationt &l=source_locationt::nil())
instructionst instructions
The list of instructions in the goto program.
void destructive_insert(const_targett target, goto_programt &p)
Inserts the given program p before target.
static instructiont make_assignment(const code_assignt &_code, const source_locationt &l=source_locationt::nil())
Create an assignment instruction.
static instructiont make_skip(const source_locationt &l=source_locationt::nil())
targett add(instructiont &&instruction)
Adds a given instruction at the end.
static instructiont make_assertion(const exprt &g, const source_locationt &l=source_locationt::nil())
static instructiont make_incomplete_goto(const exprt &_cond, const source_locationt &l=source_locationt::nil())
const irep_idt & id() const
A namespacet is essentially one or two symbol tables bound together, to allow for symbol lookups in t...
bool lookup(const irep_idt &name, const symbolt *&symbol) const override
See documentation for namespace_baset::lookup().
Replace a symbol expression by a given expression.
void insert(const class symbol_exprt &old_expr, const exprt &new_expr)
Sets old_expr to be replaced by new_expr if we don't already have a replacement; otherwise does nothi...
A side_effect_exprt that returns a non-deterministically chosen value.
const irep_idt & get_file() const
void set_function(const irep_idt &function)
Expression to hold a symbol (variable)
The Boolean constant true.
static exprt conditional_cast(const exprt &expr, const typet &type)
std::string expr2c(const exprt &expr, const namespacet &ns, const expr2c_configurationt &configuration)
static std::string expr2text(const exprt &src, const namespacet &ns)
static bool is_symbol_member(const exprt &expr)
static bool is_procedure_local(const irep_idt &function_identifier, const exprt &lhs)
void replace_function_calls_by_contracts(goto_functionst::function_mapt::value_type &f, const goto_modelt &goto_model)
goto_programt old_assignments(const std::vector< std::pair< symbol_exprt, exprt > > &old_exprs, const source_locationt &source_location)
static bool is_old(const exprt &lhs)
static exprt make_address(exprt src)
exprt replace_old(exprt src, const std::string &prefix, std::vector< std::pair< symbol_exprt, exprt > > &old_exprs)
static exprt instantiate_contract_lambda(exprt src)
std::optional< code_with_contract_typet > get_contract(const irep_idt &function_identifier, const namespacet &ns)
source_locationt add_function(irep_idt function_identifier, source_locationt src)
exprt assigns_match(const exprt &assigns, const exprt &lhs)
void instrument_contracts(goto_modelt &goto_model)
static exprt make_assigns_assertion(irep_idt function_identifier, const exprt::operandst &assigns, const exprt &lhs)
void instrument_contract_checks(goto_functionst::function_mapt::value_type &f, const namespacet &ns)
symbol_exprt find_old_expr(const exprt &src, const std::string &prefix, std::vector< std::pair< symbol_exprt, exprt > > &old_exprs)
bool has_contract(const irep_idt &function_identifier, const namespacet &ns)
exprt replace_source_location(exprt src, const source_locationt &source_location)
Instrument Given Invariants.
const std::string & id2string(const irep_idt &d)
API to expression classes for 'mathematical' expressions.
const lambda_exprt & to_lambda_expr(const exprt &expr)
Cast an exprt to a lambda_exprt.
const dereference_exprt & to_dereference_expr(const exprt &expr)
Cast an exprt to a dereference_exprt.
exprt same_object(const exprt &p1, const exprt &p2)
Various predicates over pointers in programs.
void postcondition(const namespacet &ns, const value_sett &value_set, const symex_target_equationt &equation, const goto_symex_statet &s, exprt &dest)
void precondition(const namespacet &ns, value_setst &value_sets, const goto_programt::const_targett target, const symex_target_equationt &equation, const goto_symex_statet &s, exprt &dest, message_handlert &message_handler)
static std::string comment(const rw_set_baset::entryt &entry, bool write)
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
exprt disjunction(const exprt::operandst &op)
1) generates a disjunction for two or more operands 2) for one operand, returns the operand 3) return...
const index_exprt & to_index_expr(const exprt &expr)
Cast an exprt to an index_exprt.
const binary_exprt & to_binary_expr(const exprt &expr)
Cast an exprt to a binary_exprt.
const unary_exprt & to_unary_expr(const exprt &expr)
Cast an exprt to a unary_exprt.
const multi_ary_exprt & to_multi_ary_expr(const exprt &expr)
Cast an exprt to a multi_ary_exprt.
const member_exprt & to_member_expr(const exprt &expr)
Cast an exprt to a member_exprt.
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
const code_typet & to_code_type(const typet &type)
Cast a typet to a code_typet.