Skip to content

Commit 79edf59

Browse files
author
martin
committed
Convert various comments, asserts and throws into invariants.
1 parent e9e6a1f commit 79edf59

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

src/analyses/ai.cpp

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ void ai_baset::finalize()
220220
ai_baset::locationt ai_baset::get_next(
221221
working_sett &working_set)
222222
{
223-
assert(!working_set.empty());
223+
PRECONDITION(!working_set.empty());
224224

225225
working_sett::iterator i=working_set.begin();
226226
locationt l=i->second;
@@ -248,6 +248,16 @@ bool ai_baset::fixedpoint(
248248
{
249249
locationt l=get_next(working_set);
250250

251+
// goto_program is really only needed for iterator manipulation
252+
auto it = goto_functions.function_map.find(l->function);
253+
254+
DATA_INVARIANT(
255+
it != goto_functions.function_map.end(),
256+
"instruction.function must be a mapped function");
257+
DATA_INVARIANT(
258+
it->second.body_available(),
259+
"instruction.function implies instruction is in function");
260+
251261
if(visit(l, working_set, goto_program, goto_functions, ns))
252262
new_data=true;
253263
}
@@ -323,6 +333,8 @@ bool ai_baset::do_function_call(
323333
// initialize state, if necessary
324334
get_state(l_return);
325335

336+
PRECONDITION(l_call->is_function_call());
337+
326338
const goto_functionst::goto_functiont &goto_function=
327339
f_it->second;
328340

@@ -388,7 +400,17 @@ bool ai_baset::do_function_call_rec(
388400
const goto_functionst &goto_functions,
389401
const namespacet &ns)
390402
{
391-
assert(!goto_functions.function_map.empty());
403+
PRECONDITION(!goto_functions.function_map.empty());
404+
405+
// We can't really do this here -- we rely on
406+
// these being removed by some previous analysis.
407+
PRECONDITION(function.id() != ID_dereference);
408+
409+
// Can't be a function
410+
DATA_INVARIANT(
411+
function.id() != "NULL-object", "Function cannot be null object");
412+
DATA_INVARIANT(function.id() != ID_member, "Function cannot be struct field");
413+
DATA_INVARIANT(function.id() != ID_index, "Function cannot be array element");
392414

393415
bool new_data=false;
394416

@@ -411,8 +433,7 @@ bool ai_baset::do_function_call_rec(
411433
}
412434
else if(function.id()==ID_if)
413435
{
414-
if(function.operands().size()!=3)
415-
throw "if has three operands";
436+
DATA_INVARIANT(function.operands().size() != 3, "if has three operands");
416437

417438
bool new_data1=
418439
do_function_call_rec(
@@ -433,19 +454,6 @@ bool ai_baset::do_function_call_rec(
433454
if(new_data1 || new_data2)
434455
new_data=true;
435456
}
436-
else if(function.id()==ID_dereference)
437-
{
438-
// We can't really do this here -- we rely on
439-
// these being removed by some previous analysis.
440-
}
441-
else if(function.id() == ID_null_object)
442-
{
443-
// ignore, can't be a function
444-
}
445-
else if(function.id()==ID_member || function.id()==ID_index)
446-
{
447-
// ignore, can't be a function
448-
}
449457
else
450458
{
451459
throw "unexpected function_call argument: "+

0 commit comments

Comments
 (0)