Skip to content

Commit 04f25a1

Browse files
committed
jsil: Replace assert(...) by macros from invariant.h
While new/modified code shouldn't use assert(...) anyway, we had several existing uses of assert. Once we remove nonstd/optional.h, we will no longer implicitly include cassert, implying that a lot of #include <cassert> changes will be necessary. Instead of adding these, go all the way and fix the undesired uses of assert.
1 parent b01b9b7 commit 04f25a1

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

src/jsil/jsil_parse_tree.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ static bool insert_at_label(
3131
if(l.get_label()!=label)
3232
continue;
3333

34-
assert(l.code().get_statement()==ID_skip);
34+
DATA_INVARIANT(l.code().get_statement() == ID_skip, "code should be skip");
3535
l.code()=code;
3636

3737
return false;

src/jsil/jsil_typecheck.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,9 @@ void jsil_typecheckt::typecheck_expr_main(exprt &expr)
167167
}
168168
else
169169
{
170-
// expressions are expected not to have type set just yet
171-
assert(expr.type().is_nil() || expr.type().id().empty());
170+
DATA_INVARIANT(
171+
expr.type().is_nil() || expr.type().id().empty(),
172+
"expressions are expected not to have type set just yet");
172173

173174
if(expr.id()==ID_null ||
174175
expr.id()=="undefined" ||
@@ -273,7 +274,7 @@ void jsil_typecheckt::typecheck_expr_side_effect_throw(
273274
side_effect_expr_throwt &expr)
274275
{
275276
irept &excep_list=expr.add(ID_exception_list);
276-
assert(excep_list.id()==ID_symbol);
277+
PRECONDITION(excep_list.id() == ID_symbol);
277278
symbol_exprt &s=static_cast<symbol_exprt &>(excep_list);
278279
typecheck_symbol_expr(s);
279280
}
@@ -622,7 +623,7 @@ void jsil_typecheckt::typecheck_symbol_expr(symbol_exprt &symbol_expr)
622623
else
623624
{
624625
// symbol already exists
625-
assert(!s_it->second.is_type);
626+
DATA_INVARIANT(!s_it->second.is_type, "non-type symbol expected");
626627

627628
const symbolt &symbol=s_it->second;
628629

@@ -837,7 +838,7 @@ void jsil_typecheckt::typecheck_assign(code_assignt &code)
837838
/// \par parameters: any symbol
838839
void jsil_typecheckt::typecheck_non_type_symbol(symbolt &symbol)
839840
{
840-
assert(!symbol.is_type);
841+
PRECONDITION(!symbol.is_type);
841842

842843
// Using is_extern to check if symbol was already typechecked
843844
if(symbol.is_extern)

src/jsil/jsil_types.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class jsil_builtin_code_typet:public code_typet
4747
inline jsil_builtin_code_typet &to_jsil_builtin_code_type(
4848
code_typet &code)
4949
{
50-
assert(code.get_bool("jsil_builtin_proceduret"));
50+
PRECONDITION(code.get_bool("jsil_builtin_proceduret"));
5151
return static_cast<jsil_builtin_code_typet &>(code);
5252
}
5353

@@ -70,7 +70,7 @@ class jsil_spec_code_typet:public code_typet
7070
inline jsil_spec_code_typet &to_jsil_spec_code_type(
7171
code_typet &code)
7272
{
73-
assert(code.get_bool("jsil_spec_proceduret"));
73+
PRECONDITION(code.get_bool("jsil_spec_proceduret"));
7474
return static_cast<jsil_spec_code_typet &>(code);
7575
}
7676

@@ -101,13 +101,13 @@ class jsil_union_typet:public union_typet
101101

102102
inline jsil_union_typet &to_jsil_union_type(typet &type)
103103
{
104-
assert(type.id()==ID_union);
104+
PRECONDITION(type.id() == ID_union);
105105
return static_cast<jsil_union_typet &>(type);
106106
}
107107

108108
inline const jsil_union_typet &to_jsil_union_type(const typet &type)
109109
{
110-
assert(type.id()==ID_union);
110+
PRECONDITION(type.id() == ID_union);
111111
return static_cast<const jsil_union_typet &>(type);
112112
}
113113

0 commit comments

Comments
 (0)