Skip to content

Commit 99755fe

Browse files
committed
Move asserts to invariants (and provide suitable includes)
1 parent 3af3d72 commit 99755fe

7 files changed

+23
-14
lines changed

src/cpp/cpp_exception_id.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ Author: Daniel Kroening, [email protected]
1111

1212
#include "cpp_exception_id.h"
1313

14+
#include <util/invariant.h>
15+
1416
/// turns a type into a list of relevant exception IDs
1517
void cpp_exception_list_rec(
1618
const typet &src,
@@ -91,6 +93,6 @@ irep_idt cpp_exception_id(
9193
{
9294
std::vector<irep_idt> ids;
9395
cpp_exception_list_rec(src, ns, "", ids);
94-
assert(!ids.empty());
96+
CHECK_RETURN(!ids.empty());
9597
return ids.front();
9698
}

src/cpp/cpp_name.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Author: Daniel Kroening, [email protected]
1111
#define CPROVER_CPP_CPP_NAME_H
1212

1313
#include <util/expr.h>
14+
#include <util/invariant.h>
1415

1516
class cpp_namet:public irept
1617
{
@@ -142,13 +143,13 @@ class cpp_namet:public irept
142143

143144
inline cpp_namet &to_cpp_name(irept &cpp_name)
144145
{
145-
assert(cpp_name.id() == ID_cpp_name);
146+
PRECONDITION(cpp_name.id() == ID_cpp_name);
146147
return static_cast<cpp_namet &>(cpp_name);
147148
}
148149

149150
inline const cpp_namet &to_cpp_name(const irept &cpp_name)
150151
{
151-
assert(cpp_name.id() == ID_cpp_name);
152+
PRECONDITION(cpp_name.id() == ID_cpp_name);
152153
return static_cast<const cpp_namet &>(cpp_name);
153154
}
154155

src/cpp/cpp_template_args.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Author: Daniel Kroening, [email protected]
1313
#define CPROVER_CPP_CPP_TEMPLATE_ARGS_H
1414

1515
#include <util/expr.h>
16+
#include <util/invariant.h>
1617

1718
// A data structures for template arguments, i.e.,
1819
// a sequence of types/expressions of the form <E1, T2, ...>.
@@ -47,14 +48,14 @@ class cpp_template_args_non_tct:public cpp_template_args_baset
4748
inline cpp_template_args_non_tct &to_cpp_template_args_non_tc(
4849
irept &irep)
4950
{
50-
assert(irep.id()==ID_template_args);
51+
PRECONDITION(irep.id() == ID_template_args);
5152
return static_cast<cpp_template_args_non_tct &>(irep);
5253
}
5354

5455
inline const cpp_template_args_non_tct &to_cpp_template_args_non_tc(
5556
const irept &irep)
5657
{
57-
assert(irep.id()==ID_template_args);
58+
PRECONDITION(irep.id() == ID_template_args);
5859
return static_cast<const cpp_template_args_non_tct &>(irep);
5960
}
6061

@@ -80,13 +81,13 @@ class cpp_template_args_tct:public cpp_template_args_baset
8081

8182
inline cpp_template_args_tct &to_cpp_template_args_tc(irept &irep)
8283
{
83-
assert(irep.id()==ID_template_args);
84+
PRECONDITION(irep.id() == ID_template_args);
8485
return static_cast<cpp_template_args_tct &>(irep);
8586
}
8687

8788
inline const cpp_template_args_tct &to_cpp_template_args_tc(const irept &irep)
8889
{
89-
assert(irep.id()==ID_template_args);
90+
PRECONDITION(irep.id() == ID_template_args);
9091
return static_cast<const cpp_template_args_tct &>(irep);
9192
}
9293

src/cpp/cpp_template_type.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Author: Daniel Kroening, [email protected]
1010
#ifndef CPROVER_CPP_CPP_TEMPLATE_TYPE_H
1111
#define CPROVER_CPP_CPP_TEMPLATE_TYPE_H
1212

13+
#include <util/invariant.h>
1314
#include <util/type.h>
1415
#include <util/expr.h>
1516

@@ -37,13 +38,13 @@ class template_typet:public typet
3738

3839
inline template_typet &to_template_type(typet &type)
3940
{
40-
assert(type.id()==ID_template);
41+
PRECONDITION(type.id() == ID_template);
4142
return static_cast<template_typet &>(type);
4243
}
4344

4445
inline const template_typet &to_template_type(const typet &type)
4546
{
46-
assert(type.id()==ID_template);
47+
PRECONDITION(type.id() == ID_template);
4748
return static_cast<const template_typet &>(type);
4849
}
4950

src/cpp/cpp_token_buffer.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ Author: Daniel Kroening, [email protected]
1616

1717
#include <list>
1818

19+
#include <util/invariant.h>
20+
1921
class cpp_token_buffert
2022
{
2123
public:
@@ -45,7 +47,7 @@ class cpp_token_buffert
4547
// the token that is currently being read from the file
4648
cpp_tokent &current_token()
4749
{
48-
assert(!tokens.empty());
50+
PRECONDITION(!tokens.empty());
4951
return tokens.back();
5052
}
5153

src/cpp/template_map.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,15 @@ void template_mapt::build(
173173
}
174174

175175
// these should have been typechecked before
176-
assert(instance.size()==template_parameters.size());
176+
DATA_INVARIANT(
177+
instance.size() == template_parameters.size(),
178+
"template instantiation expected to match declaration");
177179

178180
for(cpp_template_args_tct::argumentst::const_iterator
179181
i_it=instance.begin();
180182
i_it!=instance.end();
181183
i_it++, t_it++)
182184
{
183-
assert(t_it!=template_parameters.end());
184185
set(*t_it, *i_it);
185186
}
186187
}

src/util/typecheck.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ Author: Daniel Kroening, [email protected]
66
77
\*******************************************************************/
88

9-
109
#include "typecheck.h"
1110

11+
#include "invariant.h"
12+
1213
bool typecheckt::typecheck_main()
1314
{
14-
assert(message_handler);
15+
PRECONDITION(message_handler);
1516

1617
const unsigned errors_before=
1718
message_handler->get_message_count(messaget::M_ERROR);

0 commit comments

Comments
 (0)