71 const auto function_name =
id2string(function_symbol.get_identifier());
73 R
"(.*org\.cprover\.CProver\.nondet)"
74 R"((?:Boolean|Byte|Char|Short|Int|Long|Float|Double|With(out)?Null.*))");
75 std::smatch match_results;
76 if(!std::regex_match(function_name, match_results, reg))
92 if(!(instr->is_function_call() && instr->code().id() == ID_code))
96 const auto &code = instr->code();
98 code.get_statement() == ID_function_call,
99 "function_call should have ID_function_call");
110 return expr.
id() == ID_symbol &&
121 if(!(expr.
id() == ID_typecast && expr.
operands().size() == 1))
126 if(!(typecast.op().id() == ID_symbol && !typecast.op().has_operands()))
132 return op_symbol.get_identifier() == identifier;
202 const auto next_instr = std::next(target);
204 instr_info.get_instruction_type() ==
212 const bool remove_returns_not_run = target->call_lhs().is_not_nil();
215 if(remove_returns_not_run)
223 next_instr->is_assign(),
224 "the code_function_callt for a nondet-returning library function should "
225 "either have a variable for the return value in its lhs() or the next "
226 "instruction should be an assignment of the return value to a temporary "
228 const exprt &return_value_assignment = next_instr->assign_lhs();
232 !(return_value_assignment.
id() == ID_symbol &&
246 auto target_instruction = std::find_if(
254 if(target_instruction == end)
256 target_instruction = std::find_if(
265 target_instruction != end,
266 "failed to find return of the temporary return variable or assignment of "
267 "the temporary return variable into a target variable");
274 if(target_instruction->is_set_return_value())
276 const auto &nondet_var = target_instruction->return_value();
279 nondet_var.type(), target_instruction->source_location());
281 instr_info.get_nullable_type() ==
283 target_instruction->code_nonconst() =
code_returnt(inserted_expr);
284 target_instruction->code_nonconst().add_source_location() =
285 target_instruction->source_location();
287 else if(target_instruction->is_assign())
290 const auto &nondet_var = target_instruction->assign_lhs();
293 nondet_var.type(), target_instruction->source_location());
295 instr_info.get_nullable_type() ==
297 target_instruction->assign_rhs_nonconst() = inserted_expr;
302 return std::next(target_instruction);
311 for(
auto instruction_iterator = goto_program.
instructions.begin(),
313 instruction_iterator != end;)
315 instruction_iterator =
goto_instruction_codet representation of a function call statement.
goto_instruction_codet representation of a "return from a function" statement.
dstringt has one field, an unsigned integer no which is an index into a static table of strings.
Base class for all expressions.
bool has_operands() const
Return true if there is at least one operand.
A collection of goto functions.
function_mapt function_map
Interface providing access to a single function in a GOTO model, plus its associated symbol table.
goto_functionst goto_functions
GOTO functions.
This class represents an instruction in the GOTO intermediate representation.
void turn_into_skip()
Transforms an existing instruction into a skip, retaining the source_location.
bool is_set_return_value() const
const exprt & return_value() const
Get the return value of a SET_RETURN_VALUE instruction.
const exprt & assign_rhs() const
Get the rhs of the assignment for ASSIGN.
A generic container class for the GOTO intermediate representation of one function.
instructionst instructions
The list of instructions in the goto program.
void update()
Update all indices.
instructionst::iterator targett
instructionst::const_iterator const_targett
const irep_idt & id() const
Holds information about any discovered nondet methods, with extreme type- safety.
nondet_instruction_infot()
is_nullablet get_nullable_type() const
is_nondett get_instruction_type() const
nondet_instruction_infot(is_nullablet is_nullable)
A side_effect_exprt that returns a non-deterministically chosen value.
void set_nullable(bool nullable)
const irep_idt & get_identifier() const
const code_function_callt & to_code_function_call(const goto_instruction_codet &code)
const std::string & id2string(const irep_idt &d)
void remove_skip(goto_programt &goto_program, goto_programt::targett begin, goto_programt::targett end)
remove unnecessary skip statements
static nondet_instruction_infot is_nondet_returning_object(const code_function_callt &function_call)
Checks whether the function call is one of our nondet library functions.
static void replace_java_nondet(goto_programt &goto_program)
Checks each instruction in the goto program to see whether it is a method returning nondet.
static bool is_symbol_with_id(const exprt &expr, const irep_idt &identifier)
Return whether the expression is a symbol with the specified identifier.
static bool is_return_with_variable(const goto_programt::instructiont &instr, const irep_idt &identifier)
Return whether the instruction is a return, and the rhs is a symbol or typecast expression with the s...
static bool is_assignment_from(const goto_programt::instructiont &instr, const irep_idt &identifier)
Return whether the instruction is an assignment, and the rhs is a symbol or typecast expression with ...
static nondet_instruction_infot get_nondet_instruction_info(const goto_programt::const_targett &instr)
Check whether the instruction is a function call which matches one of the recognised nondet library m...
static goto_programt::targett check_and_replace_target(goto_programt &goto_program, const goto_programt::targett &target)
Given an iterator into a list of instructions, modify the list to replace 'nondet' library functions ...
static bool is_typecast_with_id(const exprt &expr, const irep_idt &identifier)
Return whether the expression is a typecast with the specified identifier.
Replace Java Nondet expressions.
#define DATA_INVARIANT(CONDITION, REASON)
This condition should be used to document that assumptions that are made on goto_functions,...
#define INVARIANT(CONDITION, REASON)
This macro uses the wrapper function 'invariant_violated_string'.
const symbol_exprt & to_symbol_expr(const exprt &expr)
Cast an exprt to a symbol_exprt.
const typecast_exprt & to_typecast_expr(const exprt &expr)
Cast an exprt to a typecast_exprt.