Skip to content

Commit 747c619

Browse files
author
Daniel Kroening
committed
introduce code_havoc_objectt
This documents an existing codet variant.
1 parent bf5f7f7 commit 747c619

File tree

3 files changed

+56
-6
lines changed

3 files changed

+56
-6
lines changed

Diff for: src/goto-programs/builtin_functions.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -809,9 +809,8 @@ void goto_convertt::do_function_call_symbol(
809809
throw 0;
810810
}
811811

812-
codet havoc(ID_havoc_object);
812+
code_havoc_objectt havoc(arguments[0]);
813813
havoc.add_source_location() = function.source_location();
814-
havoc.copy_to_operands(arguments[0]);
815814

816815
dest.add(goto_programt::make_other(havoc, function.source_location()));
817816
}

Diff for: src/goto-symex/symex_other.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,9 @@ void goto_symext::symex_other(
256256
}
257257
else if(statement==ID_havoc_object)
258258
{
259-
DATA_INVARIANT(
260-
code.operands().size() == 1,
261-
"expected havoc_object statement to have one operand");
259+
const auto &havoc_object_statement = to_code_havoc_object(code);
262260

263-
exprt object = clean_expr(code.op0(), state, false);
261+
exprt object = clean_expr(havoc_object_statement.object(), state, false);
264262

265263
process_array_expr(state, object);
266264
havoc_rec(state, guardt(true_exprt(), guard_manager), object);

Diff for: src/util/std_code.h

+53
Original file line numberDiff line numberDiff line change
@@ -2380,6 +2380,59 @@ inline code_try_catcht &to_code_try_catch(codet &code)
23802380
return ret;
23812381
}
23822382

2383+
/// \ref codet representation of a 'havoc_object' statement.
2384+
class code_havoc_objectt : public codet
2385+
{
2386+
public:
2387+
explicit code_havoc_objectt(exprt op)
2388+
: codet(ID_havoc_object, {std::move(op)})
2389+
{
2390+
}
2391+
2392+
const exprt &object() const
2393+
{
2394+
return op0();
2395+
}
2396+
2397+
exprt &object()
2398+
{
2399+
return op0();
2400+
}
2401+
2402+
protected:
2403+
using codet::op0;
2404+
using codet::op1;
2405+
using codet::op2;
2406+
using codet::op3;
2407+
};
2408+
2409+
template <>
2410+
inline bool can_cast_expr<code_havoc_objectt>(const exprt &base)
2411+
{
2412+
return detail::can_cast_code_impl(base, ID_havoc_object);
2413+
}
2414+
2415+
inline void validate_expr(const code_havoc_objectt &x)
2416+
{
2417+
validate_operands(x, 1, "havoc_object must have one operand", true);
2418+
}
2419+
2420+
inline const code_havoc_objectt &to_code_havoc_object(const codet &code)
2421+
{
2422+
PRECONDITION(code.get_statement() == ID_havoc_object);
2423+
const code_havoc_objectt &ret = static_cast<const code_havoc_objectt &>(code);
2424+
validate_expr(ret);
2425+
return ret;
2426+
}
2427+
2428+
inline code_havoc_objectt &to_code_havoc_object(codet &code)
2429+
{
2430+
PRECONDITION(code.get_statement() == ID_try_catch);
2431+
code_havoc_objectt &ret = static_cast<code_havoc_objectt &>(code);
2432+
validate_expr(ret);
2433+
return ret;
2434+
}
2435+
23832436
/// This class is used to interface between a language frontend
23842437
/// and goto-convert -- it communicates the identifiers of the parameters
23852438
/// of a function or method

0 commit comments

Comments
 (0)