Skip to content

Commit 773bc86

Browse files
author
martin
committed
Convert various comments, asserts and throws into invariants.
1 parent e65f027 commit 773bc86

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

src/analyses/ai.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ Author: Daniel Kroening, [email protected]
1515
#include <memory>
1616
#include <sstream>
1717

18-
#include <util/std_expr.h>
18+
#include <util/invariant.h>
1919
#include <util/std_code.h>
20+
#include <util/std_expr.h>
2021

2122
#include "is_threaded.h"
2223

@@ -220,7 +221,7 @@ void ai_baset::finalize()
220221
ai_baset::locationt ai_baset::get_next(
221222
working_sett &working_set)
222223
{
223-
assert(!working_set.empty());
224+
PRECONDITION(!working_set.empty());
224225

225226
working_sett::iterator i=working_set.begin();
226227
locationt l=i->second;
@@ -248,6 +249,7 @@ bool ai_baset::fixedpoint(
248249
{
249250
locationt l=get_next(working_set);
250251

252+
// goto_program is really only needed for iterator manipulation
251253
if(visit(l, working_set, goto_program, goto_functions, ns))
252254
new_data=true;
253255
}
@@ -323,6 +325,8 @@ bool ai_baset::do_function_call(
323325
// initialize state, if necessary
324326
get_state(l_return);
325327

328+
PRECONDITION(l_call->is_function_call());
329+
326330
const goto_functionst::goto_functiont &goto_function=
327331
f_it->second;
328332

@@ -388,7 +392,17 @@ bool ai_baset::do_function_call_rec(
388392
const goto_functionst &goto_functions,
389393
const namespacet &ns)
390394
{
391-
assert(!goto_functions.function_map.empty());
395+
PRECONDITION(!goto_functions.function_map.empty());
396+
397+
// We can't really do this here -- we rely on
398+
// these being removed by some previous analysis.
399+
PRECONDITION(function.id() != ID_dereference);
400+
401+
// Can't be a function
402+
DATA_INVARIANT(
403+
function.id() != "NULL-object", "Function cannot be null object");
404+
DATA_INVARIANT(function.id() != ID_member, "Function cannot be struct field");
405+
DATA_INVARIANT(function.id() != ID_index, "Function cannot be array element");
392406

393407
bool new_data=false;
394408

@@ -411,8 +425,7 @@ bool ai_baset::do_function_call_rec(
411425
}
412426
else if(function.id()==ID_if)
413427
{
414-
if(function.operands().size()!=3)
415-
throw "if has three operands";
428+
DATA_INVARIANT(function.operands().size() != 3, "if has three operands");
416429

417430
bool new_data1=
418431
do_function_call_rec(
@@ -433,19 +446,6 @@ bool ai_baset::do_function_call_rec(
433446
if(new_data1 || new_data2)
434447
new_data=true;
435448
}
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-
}
449449
else
450450
{
451451
throw "unexpected function_call argument: "+

0 commit comments

Comments
 (0)