Skip to content

Commit db07f93

Browse files
authored
Merge pull request #7409 from tautschnig/cleanup/assert-to-invariant2
Replace remaining uses of assert(...) by macros from invariant.h
2 parents 6d2e501 + 0da93f3 commit db07f93

File tree

10 files changed

+36
-30
lines changed

10 files changed

+36
-30
lines changed

src/goto-cc/as86_cmdline.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ Author: Michael Tautschnig
1111

1212
#include "as86_cmdline.h"
1313

14-
#include <iostream>
15-
14+
#include <util/invariant.h>
1615
#include <util/prefix.h>
1716

17+
#include <iostream>
18+
1819
// non-as86 options
1920
const char *goto_as86_options_with_argument[]=
2021
{
@@ -56,7 +57,7 @@ const char *as86_options_with_argument[]=
5657

5758
bool as86_cmdlinet::parse(int argc, const char **argv)
5859
{
59-
assert(argc>0);
60+
PRECONDITION(argc > 0);
6061
add_arg(argv[0]);
6162

6263
for(int i=1; i<argc; i++)

src/goto-cc/as_cmdline.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ Author: Michael Tautschnig
1111

1212
#include "as_cmdline.h"
1313

14-
#include <iostream>
15-
14+
#include <util/invariant.h>
1615
#include <util/prefix.h>
1716

17+
#include <iostream>
18+
1819
// non-as options
1920
const char *goto_as_options_with_argument[]=
2021
{
@@ -78,7 +79,7 @@ const char *as_options_with_argument[]=
7879

7980
bool as_cmdlinet::parse(int argc, const char **argv)
8081
{
81-
assert(argc>0);
82+
PRECONDITION(argc > 0);
8283
add_arg(argv[0]);
8384

8485
for(int i=1; i<argc; i++)

src/goto-cc/as_mode.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ int as_modet::doit()
201201
{
202202
if(outputs>0)
203203
{
204-
assert(!dest.empty());
204+
PRECONDITION(!dest.empty());
205205
compiler.add_input_file(dest);
206206
os.close();
207207
}
@@ -230,7 +230,7 @@ int as_modet::doit()
230230

231231
if(outputs>0)
232232
{
233-
assert(!dest.empty());
233+
PRECONDITION(!dest.empty());
234234
compiler.add_input_file(dest);
235235
}
236236
else
@@ -260,7 +260,7 @@ int as_modet::doit()
260260
/// run as or as86 with original command line
261261
int as_modet::run_as()
262262
{
263-
assert(!cmdline.parsed_argv.empty());
263+
PRECONDITION(!cmdline.parsed_argv.empty());
264264

265265
// build new argv
266266
std::vector<std::string> new_argv;

src/goto-cc/bcc_cmdline.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ Author: Michael Tautschnig
1111

1212
#include "bcc_cmdline.h"
1313

14-
#include <iostream>
15-
14+
#include <util/invariant.h>
1615
#include <util/prefix.h>
1716

17+
#include <iostream>
18+
1819
// non-bcc options
1920
const char *goto_bcc_options_with_argument[]=
2021
{
@@ -68,7 +69,7 @@ const char *bcc_options_with_argument[]=
6869

6970
bool bcc_cmdlinet::parse(int argc, const char **argv)
7071
{
71-
assert(argc>0);
72+
PRECONDITION(argc > 0);
7273
add_arg(argv[0]);
7374

7475
for(int i=1; i<argc; i++)

src/goto-cc/gcc_cmdline.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Author: CM Wintersteiger, 2006
1111

1212
#include "gcc_cmdline.h"
1313

14+
#include <util/invariant.h>
1415
#include <util/prefix.h>
1516

1617
#include <cstring>
@@ -228,7 +229,7 @@ const char *gcc_options_without_argument[]=
228229
/// \return none
229230
bool gcc_cmdlinet::parse(int argc, const char **argv)
230231
{
231-
assert(argc>0);
232+
PRECONDITION(argc > 0);
232233
add_arg(argv[0]);
233234

234235
argst current_args;
@@ -447,8 +448,8 @@ bool gcc_cmdlinet::parse_arguments(
447448
void gcc_cmdlinet::parse_specs_line(const std::string &line, bool in_spec_file)
448449
{
449450
// initial whitespace has been stripped
450-
assert(!line.empty());
451-
assert(line[0]!=' ' && line[0]!='\t');
451+
PRECONDITION(!line.empty());
452+
PRECONDITION(line[0] != ' ' && line[0] != '\t');
452453

453454
argst args_from_specs;
454455

src/goto-cc/ld_cmdline.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ Author: Daniel Kroening, 2013
1111

1212
#include "ld_cmdline.h"
1313

14-
#include <iostream>
15-
14+
#include <util/invariant.h>
1615
#include <util/prefix.h>
1716

17+
#include <iostream>
18+
1819
// clang-format off
1920
const char *goto_ld_options_with_argument[]=
2021
{
@@ -253,7 +254,7 @@ const char *ld_options_without_argument[]=
253254
/// \return none
254255
bool ld_cmdlinet::parse(int argc, const char **argv)
255256
{
256-
assert(argc>0);
257+
PRECONDITION(argc > 0);
257258
add_arg(argv[0]);
258259

259260
for(int i=1; i<argc; i++)

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

src/linking/linking.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,7 +1215,7 @@ void linkingt::duplicate_type_symbol(
12151215
symbolt &old_symbol,
12161216
const symbolt &new_symbol)
12171217
{
1218-
assert(new_symbol.is_type);
1218+
PRECONDITION(new_symbol.is_type);
12191219

12201220
if(!old_symbol.is_type)
12211221
{
@@ -1310,7 +1310,7 @@ bool linkingt::needs_renaming_type(
13101310
const symbolt &old_symbol,
13111311
const symbolt &new_symbol)
13121312
{
1313-
assert(new_symbol.is_type);
1313+
PRECONDITION(new_symbol.is_type);
13141314

13151315
if(!old_symbol.is_type)
13161316
return true;

0 commit comments

Comments
 (0)