Skip to content

Use nullptr to represent null pointers (master) #1174

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 4 commits into from
Jul 26, 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
8 changes: 5 additions & 3 deletions src/analyses/invariant_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Author: Daniel Kroening, [email protected]

#include <iostream>

#include <util/base_exceptions.h>
#include <util/symbol_table.h>
#include <util/namespace.h>
#include <util/arith_tools.h>
Expand Down Expand Up @@ -144,7 +145,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 +316,8 @@ void invariant_sett::output(
return;
}

assert(object_store!=NULL);
INVARIANT_STRUCTURED(
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 +901,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
6 changes: 3 additions & 3 deletions src/analyses/invariant_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,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
10 changes: 8 additions & 2 deletions src/analyses/reaching_definitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ void rd_range_domaint::transform(
{
reaching_definitions_analysist *rd=
dynamic_cast<reaching_definitions_analysist*>(&ai);
assert(rd!=0);
INVARIANT_STRUCTURED(
rd!=nullptr,
bad_cast_exceptiont,
"ai has type reaching_definitions_analysist");

assert(bv_container);

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

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

Expand Down
14 changes: 9 additions & 5 deletions src/analyses/reaching_definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Date: February 2013
#ifndef CPROVER_ANALYSES_REACHING_DEFINITIONS_H
#define CPROVER_ANALYSES_REACHING_DEFINITIONS_H

#include <util/base_exceptions.h>
#include <util/threeval.h>

#include "ai.h"
Expand Down Expand Up @@ -102,7 +103,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 +244,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 +260,10 @@ 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_STRUCTURED(
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
4 changes: 2 additions & 2 deletions src/cbmc/cbmc_parse_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,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 @@ -718,7 +718,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
9 changes: 6 additions & 3 deletions src/cpp/cpp_instantiate_template.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Author: Daniel Kroening, [email protected]
#include "cpp_typecheck.h"

#include <util/arith_tools.h>
#include <util/base_exceptions.h>
#include <util/simplify_expr.h>

#include <util/c_types.h>
Expand Down Expand Up @@ -130,7 +131,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_STRUCTURED(
template_scope!=nullptr, nullptr_exceptiont, "template_scope is null");

irep_idt identifier=
id2string(template_scope->prefix)+
Expand Down Expand Up @@ -276,15 +278,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_STRUCTURED(
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: 1 addition & 1 deletion src/cpp/cpp_typecheck_compound_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,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
2 changes: 1 addition & 1 deletion src/cpp/cpp_typecheck_expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ struct operator_entryt
{ ID_notequal, "!=" },
{ ID_dereference, "*" },
{ ID_ptrmember, "->" },
{ irep_idt(), NULL }
{ irep_idt(), nullptr }
};

bool cpp_typecheckt::operator_is_overloaded(exprt &expr)
Expand Down
4 changes: 2 additions & 2 deletions src/cpp/cpp_typecheck_resolve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,7 @@ symbol_typet cpp_typecheck_resolvet::disambiguate_template_classes(
static_cast<cpp_scopet *>(
cpp_typecheck.cpp_scopes.id_map[id]);

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

if(template_scope==NULL)
if(template_scope==nullptr)
{
cpp_typecheck.error().source_location=source_location;
cpp_typecheck.error() << "template identifier: "
Expand Down
9 changes: 7 additions & 2 deletions src/cpp/cpp_typecheck_template.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Author: Daniel Kroening, [email protected]

#include "cpp_typecheck.h"

#include <util/base_exceptions.h>
#include <util/simplify_expr.h>

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

Expand Down Expand Up @@ -960,7 +962,10 @@ cpp_template_args_tct cpp_typecheckt::typecheck_template_args(
{
cpp_save_scopet cpp_saved_scope(cpp_scopes);
cpp_idt *template_scope=cpp_scopes.id_map[template_symbol.name];
assert(template_scope!=NULL);
INVARIANT_STRUCTURED(
template_scope!=nullptr,
nullptr_exceptiont,
"template_scope is null");
cpp_scopes.go_to(*template_scope);
typecheck_type(type);
}
Expand Down
Loading