Skip to content

[depends: #1063] Use nullptr to represent null pointers (targets master) #1159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/analyses/goto_check.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class goto_checkt
const namespacet &_ns,
const optionst &_options):
ns(_ns),
local_bitvector_analysis(0)
local_bitvector_analysis(nullptr)
{
enable_bounds_check=_options.get_bool_option("bounds-check");
enable_pointer_check=_options.get_bool_option("pointer-check");
Expand Down
10 changes: 6 additions & 4 deletions src/analyses/goto_rw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,9 +463,10 @@ void rw_range_sett::add(
{
objectst::iterator entry=(mode==get_modet::LHS_W ? w_range_set : r_range_set).
insert(
std::pair<const irep_idt&, range_domain_baset*>(identifier, 0)).first;
std::pair<const irep_idt&, range_domain_baset*>(
identifier, nullptr)).first;

if(entry->second==0)
if(entry->second==nullptr)
entry->second=new range_domaint();

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

if(entry->second==0)
if(entry->second==nullptr)
entry->second=new guarded_range_domaint();

static_cast<guarded_range_domaint*>(entry->second)->insert(
Expand Down
4 changes: 2 additions & 2 deletions src/analyses/goto_rw.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class rw_range_sett

const range_domaint &get_ranges(objectst::const_iterator it) const
{
assert(dynamic_cast<range_domaint*>(it->second)!=0);
PRECONDITION(dynamic_cast<range_domaint*>(it->second)!=nullptr);
return *static_cast<range_domaint*>(it->second);
}

Expand Down Expand Up @@ -277,7 +277,7 @@ class rw_guarded_range_set_value_sett:public rw_range_set_value_sett

const guarded_range_domaint &get_ranges(objectst::const_iterator it) const
{
assert(dynamic_cast<guarded_range_domaint*>(it->second)!=0);
PRECONDITION(dynamic_cast<guarded_range_domaint*>(it->second)!=nullptr);
return *static_cast<guarded_range_domaint*>(it->second);
}

Expand Down
7 changes: 4 additions & 3 deletions src/analyses/invariant_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ bool invariant_sett::get_object(
const exprt &expr,
unsigned &n) const
{
assert(object_store!=NULL);
PRECONDITION(object_store!=nullptr);
return object_store->get(expr, n);
}

Expand Down Expand Up @@ -315,7 +315,8 @@ void invariant_sett::output(
return;
}

assert(object_store!=NULL);
INVARIANT(
object_store!=nullptr, nullptr_exceptiont("Object store is null"));

for(unsigned i=0; i<eq_set.size(); i++)
if(eq_set.is_root(i) &&
Expand Down Expand Up @@ -899,7 +900,7 @@ std::string invariant_sett::to_string(
unsigned a,
const irep_idt &identifier) const
{
assert(object_store!=NULL);
PRECONDITION(object_store!=nullptr);
return object_store->to_string(a, identifier);
}

Expand Down
8 changes: 5 additions & 3 deletions src/analyses/invariant_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ Author: Daniel Kroening, [email protected]

#include "interval_template.h"

#define nullptr_exceptiont(str) str
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering whether this is the best approach and right place to put?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is temporary, until #1063 gets merged. Of course this should be a custom exception type derived from invariant_failedt, and these common exception types should probably live in util. Should I add a "util/standard_exceptions.h" header and just put macros in it for now?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be ok to wait for #1063 to get merged and then do it properly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's fine with me.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed the PR title in a desperate attempt to introduce dependency tracking into github...


class inv_object_storet
{
public:
Expand Down Expand Up @@ -98,9 +100,9 @@ class invariant_sett
invariant_sett():
threaded(false),
is_false(false),
value_sets(NULL),
object_store(NULL),
ns(NULL)
value_sets(nullptr),
object_store(nullptr),
ns(nullptr)
{
}

Expand Down
4 changes: 2 additions & 2 deletions src/analyses/local_may_alias.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class local_may_aliast
class local_may_alias_factoryt
{
public:
local_may_alias_factoryt():goto_functions(NULL)
local_may_alias_factoryt():goto_functions(nullptr)
{
}

Expand All @@ -109,7 +109,7 @@ class local_may_alias_factoryt

local_may_aliast &operator()(const irep_idt &fkt)
{
assert(goto_functions!=NULL);
PRECONDITION(goto_functions!=nullptr);
fkt_mapt::iterator f_it=fkt_map.find(fkt);
if(f_it!=fkt_map.end())
return *f_it->second;
Expand Down
8 changes: 6 additions & 2 deletions src/analyses/reaching_definitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ void rd_range_domaint::transform(
{
reaching_definitions_analysist *rd=
dynamic_cast<reaching_definitions_analysist*>(&ai);
assert(rd!=0);
INVARIANT(
rd!=nullptr,
bad_cast_exceptiont("ai has type reaching_definitions_analysist"));

assert(bv_container);

Expand Down Expand Up @@ -298,7 +300,9 @@ void rd_range_domaint::transform_assign(
const symbolt *symbol_ptr;
if(ns.lookup(identifier, symbol_ptr))
continue;
assert(symbol_ptr!=0);
INVARIANT(
symbol_ptr!=nullptr,
nullptr_exceptiont("Symbol is in symbol table"));

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

Expand Down
15 changes: 10 additions & 5 deletions src/analyses/reaching_definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class is_threadedt;
class dirtyt;
class reaching_definitions_analysist;

#define bad_cast_exceptiont(str) str
#define nullptr_exceptiont(str) str
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now I'm convinced this isn't the right place.


// requirement: V has a member "identifier" of type irep_idt
template<typename V>
class sparse_bitvector_analysist
Expand Down Expand Up @@ -102,7 +105,7 @@ class rd_range_domaint:public ai_domain_baset
rd_range_domaint():
ai_domain_baset(),
has_values(false),
bv_container(0)
bv_container(nullptr)
{
}

Expand Down Expand Up @@ -243,9 +246,9 @@ class reaching_definitions_analysist:
explicit reaching_definitions_analysist(const namespacet &_ns):
concurrency_aware_ait<rd_range_domaint>(),
ns(_ns),
value_sets(0),
is_threaded(0),
is_dirty(0)
value_sets(nullptr),
is_threaded(nullptr),
is_dirty(nullptr)
{
}

Expand All @@ -259,7 +262,9 @@ class reaching_definitions_analysist:
statet &s=concurrency_aware_ait<rd_range_domaint>::get_state(l);

rd_range_domaint *rd_state=dynamic_cast<rd_range_domaint*>(&s);
assert(rd_state!=0);
INVARIANT(
rd_state!=nullptr,
bad_cast_exceptiont("rd_state has type rd_range_domaint"));

rd_state->set_bitvector_container(*this);

Expand Down
6 changes: 3 additions & 3 deletions src/ansi-c/c_preprocess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ bool c_preprocess(
static bool is_dot_i_file(const std::string &path)
{
const char *ext=strrchr(path.c_str(), '.');
if(ext==NULL)
if(ext==nullptr)
return false;
if(std::string(ext)==".i" ||
std::string(ext)==".ii")
Expand Down Expand Up @@ -889,7 +889,7 @@ bool c_preprocess_gcc_clang(

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

if(stream!=NULL)
if(stream!=nullptr)
{
int ch;
while((ch=fgetc(stream))!=EOF)
Expand Down Expand Up @@ -1011,7 +1011,7 @@ bool c_preprocess_arm(

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

if(stream!=NULL)
if(stream!=nullptr)
{
int ch;
while((ch=fgetc(stream))!=EOF)
Expand Down
2 changes: 1 addition & 1 deletion src/ansi-c/cprover_library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ std::string get_cprover_library_text(
std::size_t count=0;

for(cprover_library_entryt *e=cprover_library;
e->function!=NULL;
e->function!=nullptr;
e++)
{
irep_idt id=e->function;
Expand Down
2 changes: 1 addition & 1 deletion src/ansi-c/expr2c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2664,7 +2664,7 @@ std::string expr2ct::convert_code_decl(

std::string dest=indent_str(indent);

const symbolt *symbol=0;
const symbolt *symbol=nullptr;
if(!ns.lookup(to_symbol_expr(src.op0()).get_identifier(), symbol))
{
if(symbol->is_file_local &&
Expand Down
2 changes: 1 addition & 1 deletion src/big-int/bigint-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ static void
run_clisp_tests (char const *fn)
{
FILE *f = fopen (fn, "rt");
if (f == 0)
if (f == nullptr)
{
fprintf (stderr, "Error opening %s: %s.\n", fn, strerror (errno));
return;
Expand Down
10 changes: 5 additions & 5 deletions src/big-int/bigint.cc
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ digit_div (onedig_t *r, const onedig_t *y, unsigned yl, onedig_t *q, unsigned ql
--qh;
add_back (r, y, yl);
}
if (q != 0)
if (q != nullptr)
q[i] = qh;
}
}
Expand Down Expand Up @@ -580,7 +580,7 @@ char *
BigInt::as_string (char *p, unsigned l, onedig_t b) const
{
if (l < 2)
return 0; // Not enough room for number.
return nullptr; // Not enough room for number.
p[--l] = '\0';
// Check for zero. Would otherwise print as empty string.
unsigned len = length;
Expand All @@ -598,7 +598,7 @@ BigInt::as_string (char *p, unsigned l, onedig_t b) const
do
{
if (l == 0)
return 0;
return nullptr;
onedig_t r = digit_div (dig, len, b);
p[--l] = r < 10 ? r + '0' : 'A' + r - 10;
if (dig[len-1] == 0)
Expand All @@ -608,7 +608,7 @@ BigInt::as_string (char *p, unsigned l, onedig_t b) const
// Maybe attach sign.
if (!positive){
if (l == 0)
return 0;
return nullptr;
else
p[--l] = '-';
}
Expand Down Expand Up @@ -1268,7 +1268,7 @@ BigInt::operator%= (BigInt const &y)
}
if (a[al-1] >= b[bl-1])
a[al++] = 0;
digit_div (a, b, bl, 0, al - bl);
digit_div (a, b, bl, nullptr, al - bl);
length = bl;
adjust();
if (scale != 1)
Expand Down
4 changes: 2 additions & 2 deletions src/cbmc/cbmc_parse_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ int cbmc_parse_optionst::get_goto_program(

languaget *language=get_language_from_filename(filename);

if(language==NULL)
if(language==nullptr)
{
error() << "failed to figure out type of file `"
<< filename << "'" << eom;
Expand Down Expand Up @@ -739,7 +739,7 @@ void cbmc_parse_optionst::preprocessing()

languaget *ptr=get_language_from_filename(filename);

if(ptr==NULL)
if(ptr==nullptr)
{
error() << "failed to figure out type of file" << eom;
return;
Expand Down
2 changes: 1 addition & 1 deletion src/clobber/clobber_parse_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ bool clobber_parse_optionst::get_goto_program(

languaget *language=get_language_from_filename(filename);

if(language==NULL)
if(language==nullptr)
{
error() << "failed to figure out type of file `" << filename << "'"
<< eom;
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/cpp_id.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ cpp_idt::cpp_idt():
id_class(id_classt::UNKNOWN),
this_expr(static_cast<const exprt &>(get_nil_irep())),
compound_counter(0),
parent(NULL)
parent(nullptr)
{
}

Expand Down
3 changes: 2 additions & 1 deletion src/cpp/cpp_id.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Author: Daniel Kroening, [email protected]
#include <iosfwd>

#include <util/expr.h>
#include <util/invariant.h>
#include <util/std_types.h>

class cpp_scopet;
Expand Down Expand Up @@ -81,7 +82,7 @@ class cpp_idt

cpp_idt &get_parent() const
{
assert(parent!=NULL);
PRECONDITION(parent!=nullptr);
return *parent;
}

Expand Down
8 changes: 5 additions & 3 deletions src/cpp/cpp_instantiate_template.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ const symbolt &cpp_typecheckt::class_template_symbol(
cpp_scopet *template_scope=
static_cast<cpp_scopet *>(cpp_scopes.id_map[template_symbol.name]);

assert(template_scope!=NULL);
INVARIANT(
template_scope!=nullptr, nullptr_exceptiont("template_scope is null"));

irep_idt identifier=
id2string(template_scope->prefix)+
Expand Down Expand Up @@ -276,15 +277,16 @@ const symbolt &cpp_typecheckt::instantiate_template(
cpp_scopet *template_scope=
static_cast<cpp_scopet *>(cpp_scopes.id_map[template_symbol.name]);

if(template_scope==NULL)
if(template_scope==nullptr)
{
error().source_location=source_location;
error() << "identifier: " << template_symbol.name << '\n'
<< "template instantiation error: scope not found" << eom;
throw 0;
}

assert(template_scope!=NULL);
INVARIANT(
template_scope!=nullptr, nullptr_exceptiont("template_scope is null"));

// produce new declaration
cpp_declarationt new_decl=to_cpp_declaration(template_symbol.type);
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/cpp_language.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ bool cpp_languaget::preprocess(
// check extension

const char *ext=strrchr(path.c_str(), '.');
if(ext!=NULL && std::string(ext)==".ipp")
if(ext!=nullptr && std::string(ext)==".ipp")
{
std::ifstream infile(path);

Expand Down
2 changes: 2 additions & 0 deletions src/cpp/cpp_typecheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ Author: Daniel Kroening, [email protected]
#include "cpp_template_type.h"
#include "cpp_util.h"

#define nullptr_exceptiont(str) str

bool cpp_typecheck(
cpp_parse_treet &cpp_parse_tree,
symbol_tablet &symbol_table,
Expand Down
2 changes: 1 addition & 1 deletion src/cpp/cpp_typecheck_compound_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ void cpp_typecheckt::typecheck_compound_type(
// get the tag name
bool has_tag=type.find(ID_tag).is_not_nil();
irep_idt base_name;
cpp_scopet *dest_scope=NULL;
cpp_scopet *dest_scope=nullptr;
bool has_body=type.find(ID_body).is_not_nil();
bool tag_only_declaration=type.get_bool(ID_C_tag_only_declaration);

Expand Down
Loading