Skip to content

Commit 9b2a98a

Browse files
author
martin
committed
Convert various comments, asserts and throws into invariants.
1 parent 574f29c commit 9b2a98a

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

src/analyses/ai.cpp

Lines changed: 22 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,14 @@ 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(it!=goto_functions.function_map.end(),
255+
"instruction.function must be a mapped function");
256+
DATA_INVARIANT(it->second.body_available(),
257+
"instruction.function implies instruction is in function");
258+
251259
if(visit(l, working_set, goto_program, goto_functions, ns))
252260
new_data=true;
253261
}
@@ -323,6 +331,8 @@ bool ai_baset::do_function_call(
323331
// initialize state, if necessary
324332
get_state(l_return);
325333

334+
PRECONDITION(l_call->is_function_call());
335+
326336
const goto_functionst::goto_functiont &goto_function=
327337
f_it->second;
328338

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

393412
bool new_data=false;
394413

@@ -411,8 +430,7 @@ bool ai_baset::do_function_call_rec(
411430
}
412431
else if(function.id()==ID_if)
413432
{
414-
if(function.operands().size()!=3)
415-
throw "if has three operands";
433+
DATA_INVARIANT(function.operands().size()!=3, "if has three operands");
416434

417435
bool new_data1=
418436
do_function_call_rec(
@@ -433,19 +451,6 @@ bool ai_baset::do_function_call_rec(
433451
if(new_data1 || new_data2)
434452
new_data=true;
435453
}
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-
}
449454
else
450455
{
451456
throw "unexpected function_call argument: "+

0 commit comments

Comments
 (0)