Skip to content

Commit 38c7fc0

Browse files
author
Daniel Kroening
authored
Merge pull request #1174 from reuk/new-nullptr-master
Use nullptr to represent null pointers (master)
2 parents 49bceb2 + cf9182f commit 38c7fc0

File tree

78 files changed

+260
-194
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+260
-194
lines changed

src/analyses/goto_check.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class goto_checkt
3737
const namespacet &_ns,
3838
const optionst &_options):
3939
ns(_ns),
40-
local_bitvector_analysis(0)
40+
local_bitvector_analysis(nullptr)
4141
{
4242
enable_bounds_check=_options.get_bool_option("bounds-check");
4343
enable_pointer_check=_options.get_bool_option("pointer-check");

src/analyses/goto_rw.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -463,9 +463,10 @@ void rw_range_sett::add(
463463
{
464464
objectst::iterator entry=(mode==get_modet::LHS_W ? w_range_set : r_range_set).
465465
insert(
466-
std::pair<const irep_idt&, range_domain_baset*>(identifier, 0)).first;
466+
std::pair<const irep_idt&, range_domain_baset*>(
467+
identifier, nullptr)).first;
467468

468-
if(entry->second==0)
469+
if(entry->second==nullptr)
469470
entry->second=new range_domaint();
470471

471472
static_cast<range_domaint*>(entry->second)->push_back(
@@ -663,9 +664,10 @@ void rw_guarded_range_set_value_sett::add(
663664
{
664665
objectst::iterator entry=(mode==get_modet::LHS_W ? w_range_set : r_range_set).
665666
insert(
666-
std::pair<const irep_idt&, range_domain_baset*>(identifier, 0)).first;
667+
std::pair<const irep_idt&, range_domain_baset*>(
668+
identifier, nullptr)).first;
667669

668-
if(entry->second==0)
670+
if(entry->second==nullptr)
669671
entry->second=new guarded_range_domaint();
670672

671673
static_cast<guarded_range_domaint*>(entry->second)->insert(

src/analyses/goto_rw.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class rw_range_sett
108108

109109
const range_domaint &get_ranges(objectst::const_iterator it) const
110110
{
111-
assert(dynamic_cast<range_domaint*>(it->second)!=0);
111+
PRECONDITION(dynamic_cast<range_domaint*>(it->second)!=nullptr);
112112
return *static_cast<range_domaint*>(it->second);
113113
}
114114

@@ -277,7 +277,7 @@ class rw_guarded_range_set_value_sett:public rw_range_set_value_sett
277277

278278
const guarded_range_domaint &get_ranges(objectst::const_iterator it) const
279279
{
280-
assert(dynamic_cast<guarded_range_domaint*>(it->second)!=0);
280+
PRECONDITION(dynamic_cast<guarded_range_domaint*>(it->second)!=nullptr);
281281
return *static_cast<guarded_range_domaint*>(it->second);
282282
}
283283

src/analyses/invariant_set.cpp

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

1414
#include <iostream>
1515

16+
#include <util/base_exceptions.h>
1617
#include <util/symbol_table.h>
1718
#include <util/namespace.h>
1819
#include <util/arith_tools.h>
@@ -144,7 +145,7 @@ bool invariant_sett::get_object(
144145
const exprt &expr,
145146
unsigned &n) const
146147
{
147-
assert(object_store!=NULL);
148+
PRECONDITION(object_store!=nullptr);
148149
return object_store->get(expr, n);
149150
}
150151

@@ -315,7 +316,8 @@ void invariant_sett::output(
315316
return;
316317
}
317318

318-
assert(object_store!=NULL);
319+
INVARIANT_STRUCTURED(
320+
object_store!=nullptr, nullptr_exceptiont, "Object store is null");
319321

320322
for(unsigned i=0; i<eq_set.size(); i++)
321323
if(eq_set.is_root(i) &&
@@ -899,7 +901,7 @@ std::string invariant_sett::to_string(
899901
unsigned a,
900902
const irep_idt &identifier) const
901903
{
902-
assert(object_store!=NULL);
904+
PRECONDITION(object_store!=nullptr);
903905
return object_store->to_string(a, identifier);
904906
}
905907

src/analyses/invariant_set.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ class invariant_sett
9898
invariant_sett():
9999
threaded(false),
100100
is_false(false),
101-
value_sets(NULL),
102-
object_store(NULL),
103-
ns(NULL)
101+
value_sets(nullptr),
102+
object_store(nullptr),
103+
ns(nullptr)
104104
{
105105
}
106106

src/analyses/local_may_alias.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ class local_may_aliast
9494
class local_may_alias_factoryt
9595
{
9696
public:
97-
local_may_alias_factoryt():goto_functions(NULL)
97+
local_may_alias_factoryt():goto_functions(nullptr)
9898
{
9999
}
100100

@@ -109,7 +109,7 @@ class local_may_alias_factoryt
109109

110110
local_may_aliast &operator()(const irep_idt &fkt)
111111
{
112-
assert(goto_functions!=NULL);
112+
PRECONDITION(goto_functions!=nullptr);
113113
fkt_mapt::iterator f_it=fkt_map.find(fkt);
114114
if(f_it!=fkt_map.end())
115115
return *f_it->second;

src/analyses/reaching_definitions.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ void rd_range_domaint::transform(
5151
{
5252
reaching_definitions_analysist *rd=
5353
dynamic_cast<reaching_definitions_analysist*>(&ai);
54-
assert(rd!=0);
54+
INVARIANT_STRUCTURED(
55+
rd!=nullptr,
56+
bad_cast_exceptiont,
57+
"ai has type reaching_definitions_analysist");
5558

5659
assert(bv_container);
5760

@@ -298,7 +301,10 @@ void rd_range_domaint::transform_assign(
298301
const symbolt *symbol_ptr;
299302
if(ns.lookup(identifier, symbol_ptr))
300303
continue;
301-
assert(symbol_ptr!=0);
304+
INVARIANT_STRUCTURED(
305+
symbol_ptr!=nullptr,
306+
nullptr_exceptiont,
307+
"Symbol is in symbol table");
302308

303309
const range_domaint &ranges=rw_set.get_ranges(it);
304310

src/analyses/reaching_definitions.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Date: February 2013
1616
#ifndef CPROVER_ANALYSES_REACHING_DEFINITIONS_H
1717
#define CPROVER_ANALYSES_REACHING_DEFINITIONS_H
1818

19+
#include <util/base_exceptions.h>
1920
#include <util/threeval.h>
2021

2122
#include "ai.h"
@@ -102,7 +103,7 @@ class rd_range_domaint:public ai_domain_baset
102103
rd_range_domaint():
103104
ai_domain_baset(),
104105
has_values(false),
105-
bv_container(0)
106+
bv_container(nullptr)
106107
{
107108
}
108109

@@ -243,9 +244,9 @@ class reaching_definitions_analysist:
243244
explicit reaching_definitions_analysist(const namespacet &_ns):
244245
concurrency_aware_ait<rd_range_domaint>(),
245246
ns(_ns),
246-
value_sets(0),
247-
is_threaded(0),
248-
is_dirty(0)
247+
value_sets(nullptr),
248+
is_threaded(nullptr),
249+
is_dirty(nullptr)
249250
{
250251
}
251252

@@ -259,7 +260,10 @@ class reaching_definitions_analysist:
259260
statet &s=concurrency_aware_ait<rd_range_domaint>::get_state(l);
260261

261262
rd_range_domaint *rd_state=dynamic_cast<rd_range_domaint*>(&s);
262-
assert(rd_state!=0);
263+
INVARIANT_STRUCTURED(
264+
rd_state!=nullptr,
265+
bad_cast_exceptiont,
266+
"rd_state has type rd_range_domaint");
263267

264268
rd_state->set_bitvector_container(*this);
265269

src/ansi-c/c_preprocess.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ bool c_preprocess(
344344
static bool is_dot_i_file(const std::string &path)
345345
{
346346
const char *ext=strrchr(path.c_str(), '.');
347-
if(ext==NULL)
347+
if(ext==nullptr)
348348
return false;
349349
if(std::string(ext)==".i" ||
350350
std::string(ext)==".ii")
@@ -889,7 +889,7 @@ bool c_preprocess_gcc_clang(
889889

890890
FILE *stream=popen(command.c_str(), "r");
891891

892-
if(stream!=NULL)
892+
if(stream!=nullptr)
893893
{
894894
int ch;
895895
while((ch=fgetc(stream))!=EOF)
@@ -1011,7 +1011,7 @@ bool c_preprocess_arm(
10111011

10121012
FILE *stream=popen(command.c_str(), "r");
10131013

1014-
if(stream!=NULL)
1014+
if(stream!=nullptr)
10151015
{
10161016
int ch;
10171017
while((ch=fgetc(stream))!=EOF)

src/ansi-c/cprover_library.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ std::string get_cprover_library_text(
3838
std::size_t count=0;
3939

4040
for(cprover_library_entryt *e=cprover_library;
41-
e->function!=NULL;
41+
e->function!=nullptr;
4242
e++)
4343
{
4444
irep_idt id=e->function;

src/ansi-c/expr2c.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2664,7 +2664,7 @@ std::string expr2ct::convert_code_decl(
26642664

26652665
std::string dest=indent_str(indent);
26662666

2667-
const symbolt *symbol=0;
2667+
const symbolt *symbol=nullptr;
26682668
if(!ns.lookup(to_symbol_expr(src.op0()).get_identifier(), symbol))
26692669
{
26702670
if(symbol->is_file_local &&

src/cbmc/cbmc_parse_options.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ int cbmc_parse_optionst::get_goto_program(
569569

570570
languaget *language=get_language_from_filename(filename);
571571

572-
if(language==NULL)
572+
if(language==nullptr)
573573
{
574574
error() << "failed to figure out type of file `"
575575
<< filename << "'" << eom;
@@ -718,7 +718,7 @@ void cbmc_parse_optionst::preprocessing()
718718

719719
languaget *ptr=get_language_from_filename(filename);
720720

721-
if(ptr==NULL)
721+
if(ptr==nullptr)
722722
{
723723
error() << "failed to figure out type of file" << eom;
724724
return;

src/clobber/clobber_parse_options.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ bool clobber_parse_optionst::get_goto_program(
250250

251251
languaget *language=get_language_from_filename(filename);
252252

253-
if(language==NULL)
253+
if(language==nullptr)
254254
{
255255
error() << "failed to figure out type of file `" << filename << "'"
256256
<< eom;

src/cpp/cpp_id.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ cpp_idt::cpp_idt():
2424
id_class(id_classt::UNKNOWN),
2525
this_expr(static_cast<const exprt &>(get_nil_irep())),
2626
compound_counter(0),
27-
parent(NULL)
27+
parent(nullptr)
2828
{
2929
}
3030

src/cpp/cpp_id.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Author: Daniel Kroening, [email protected]
2020
#include <iosfwd>
2121

2222
#include <util/expr.h>
23+
#include <util/invariant.h>
2324
#include <util/std_types.h>
2425

2526
class cpp_scopet;
@@ -81,7 +82,7 @@ class cpp_idt
8182

8283
cpp_idt &get_parent() const
8384
{
84-
assert(parent!=NULL);
85+
PRECONDITION(parent!=nullptr);
8586
return *parent;
8687
}
8788

src/cpp/cpp_instantiate_template.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Author: Daniel Kroening, [email protected]
1212
#include "cpp_typecheck.h"
1313

1414
#include <util/arith_tools.h>
15+
#include <util/base_exceptions.h>
1516
#include <util/simplify_expr.h>
1617

1718
#include <util/c_types.h>
@@ -130,7 +131,8 @@ const symbolt &cpp_typecheckt::class_template_symbol(
130131
cpp_scopet *template_scope=
131132
static_cast<cpp_scopet *>(cpp_scopes.id_map[template_symbol.name]);
132133

133-
assert(template_scope!=NULL);
134+
INVARIANT_STRUCTURED(
135+
template_scope!=nullptr, nullptr_exceptiont, "template_scope is null");
134136

135137
irep_idt identifier=
136138
id2string(template_scope->prefix)+
@@ -276,15 +278,16 @@ const symbolt &cpp_typecheckt::instantiate_template(
276278
cpp_scopet *template_scope=
277279
static_cast<cpp_scopet *>(cpp_scopes.id_map[template_symbol.name]);
278280

279-
if(template_scope==NULL)
281+
if(template_scope==nullptr)
280282
{
281283
error().source_location=source_location;
282284
error() << "identifier: " << template_symbol.name << '\n'
283285
<< "template instantiation error: scope not found" << eom;
284286
throw 0;
285287
}
286288

287-
assert(template_scope!=NULL);
289+
INVARIANT_STRUCTURED(
290+
template_scope!=nullptr, nullptr_exceptiont, "template_scope is null");
288291

289292
// produce new declaration
290293
cpp_declarationt new_decl=to_cpp_declaration(template_symbol.type);

src/cpp/cpp_language.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ bool cpp_languaget::preprocess(
6565
// check extension
6666

6767
const char *ext=strrchr(path.c_str(), '.');
68-
if(ext!=NULL && std::string(ext)==".ipp")
68+
if(ext!=nullptr && std::string(ext)==".ipp")
6969
{
7070
std::ifstream infile(path);
7171

src/cpp/cpp_typecheck_compound_type.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ void cpp_typecheckt::typecheck_compound_type(
110110
// get the tag name
111111
bool has_tag=type.find(ID_tag).is_not_nil();
112112
irep_idt base_name;
113-
cpp_scopet *dest_scope=NULL;
113+
cpp_scopet *dest_scope=nullptr;
114114
bool has_body=type.find(ID_body).is_not_nil();
115115
bool tag_only_declaration=type.get_bool(ID_C_tag_only_declaration);
116116

src/cpp/cpp_typecheck_expr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ struct operator_entryt
471471
{ ID_notequal, "!=" },
472472
{ ID_dereference, "*" },
473473
{ ID_ptrmember, "->" },
474-
{ irep_idt(), NULL }
474+
{ irep_idt(), nullptr }
475475
};
476476

477477
bool cpp_typecheckt::operator_is_overloaded(exprt &expr)

src/cpp/cpp_typecheck_resolve.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1117,7 +1117,7 @@ symbol_typet cpp_typecheck_resolvet::disambiguate_template_classes(
11171117
static_cast<cpp_scopet *>(
11181118
cpp_typecheck.cpp_scopes.id_map[id]);
11191119

1120-
if(template_scope==NULL)
1120+
if(template_scope==nullptr)
11211121
{
11221122
cpp_typecheck.error().source_location=source_location;
11231123
cpp_typecheck.error() << "template identifier: " << id << '\n'
@@ -1959,7 +1959,7 @@ exprt cpp_typecheck_resolvet::guess_function_template_args(
19591959
static_cast<cpp_scopet *>(
19601960
cpp_typecheck.cpp_scopes.id_map[template_identifier]);
19611961

1962-
if(template_scope==NULL)
1962+
if(template_scope==nullptr)
19631963
{
19641964
cpp_typecheck.error().source_location=source_location;
19651965
cpp_typecheck.error() << "template identifier: "

src/cpp/cpp_typecheck_template.cpp

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

1212
#include "cpp_typecheck.h"
1313

14+
#include <util/base_exceptions.h>
1415
#include <util/simplify_expr.h>
1516

1617
#include "cpp_type2name.h"
@@ -910,7 +911,8 @@ cpp_template_args_tct cpp_typecheckt::typecheck_template_args(
910911
// these need to be typechecked in the scope of the template,
911912
// not in the current scope!
912913
cpp_idt *template_scope=cpp_scopes.id_map[template_symbol.name];
913-
assert(template_scope!=NULL);
914+
INVARIANT_STRUCTURED(
915+
template_scope!=nullptr, nullptr_exceptiont, "template_scope is null");
914916
cpp_scopes.go_to(*template_scope);
915917
}
916918

@@ -960,7 +962,10 @@ cpp_template_args_tct cpp_typecheckt::typecheck_template_args(
960962
{
961963
cpp_save_scopet cpp_saved_scope(cpp_scopes);
962964
cpp_idt *template_scope=cpp_scopes.id_map[template_symbol.name];
963-
assert(template_scope!=NULL);
965+
INVARIANT_STRUCTURED(
966+
template_scope!=nullptr,
967+
nullptr_exceptiont,
968+
"template_scope is null");
964969
cpp_scopes.go_to(*template_scope);
965970
typecheck_type(type);
966971
}

0 commit comments

Comments
 (0)