-
Notifications
You must be signed in to change notification settings - Fork 274
Replace owning raw pointers with unique_ptr #1029
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
Changes from 5 commits
513b705
3b56b1b
1a6249c
30d8fb5
9688d11
59169be
f1ae9fe
92e02b5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,12 +12,14 @@ Author: Daniel Kroening, [email protected] | |
#ifndef CPROVER_ANALYSES_AI_H | ||
#define CPROVER_ANALYSES_AI_H | ||
|
||
#include <map> | ||
#include <iosfwd> | ||
#include <map> | ||
#include <memory> | ||
|
||
#include <util/json.h> | ||
#include <util/xml.h> | ||
#include <util/expr.h> | ||
#include <util/make_unique.h> | ||
|
||
#include <goto-programs/goto_model.h> | ||
|
||
|
@@ -334,7 +336,7 @@ class ai_baset | |
const namespacet &ns)=0; | ||
virtual statet &get_state(locationt l)=0; | ||
virtual const statet &find_state(locationt l) const=0; | ||
virtual statet* make_temporary_state(const statet &s)=0; | ||
virtual std::unique_ptr<statet> make_temporary_state(const statet &s)=0; | ||
}; | ||
|
||
// domainT is expected to be derived from ai_domain_baseT | ||
|
@@ -400,9 +402,9 @@ class ait:public ai_baset | |
static_cast<const domainT &>(src), from, to); | ||
} | ||
|
||
statet *make_temporary_state(const statet &s) override | ||
std::unique_ptr<statet> make_temporary_state(const statet &s) override | ||
{ | ||
return new domainT(static_cast<const domainT &>(s)); | ||
return util_make_unique<domainT>(static_cast<const domainT &>(s)); | ||
} | ||
|
||
void fixedpoint( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,8 +9,9 @@ Date: April 2010 | |
\*******************************************************************/ | ||
|
||
|
||
#include <limits> | ||
#include <algorithm> | ||
#include <limits> | ||
#include <memory> | ||
|
||
#include <util/std_code.h> | ||
#include <util/std_expr.h> | ||
|
@@ -19,6 +20,7 @@ Date: April 2010 | |
#include <util/endianness_map.h> | ||
#include <util/arith_tools.h> | ||
#include <util/simplify_expr.h> | ||
#include <util/make_unique.h> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't we need |
||
|
||
#include <goto-programs/goto_functions.h> | ||
|
||
|
@@ -50,12 +52,12 @@ rw_range_sett::~rw_range_sett() | |
for(rw_range_sett::objectst::iterator it=r_range_set.begin(); | ||
it!=r_range_set.end(); | ||
++it) | ||
delete it->second; | ||
it->second=nullptr; | ||
|
||
for(rw_range_sett::objectst::iterator it=w_range_set.begin(); | ||
it!=w_range_set.end(); | ||
++it) | ||
delete it->second; | ||
it->second=nullptr; | ||
} | ||
|
||
void rw_range_sett::output(std::ostream &out) const | ||
|
@@ -462,14 +464,17 @@ void rw_range_sett::add( | |
const range_spect &range_start, | ||
const range_spect &range_end) | ||
{ | ||
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; | ||
objectst::iterator entry= | ||
(mode==get_modet::LHS_W?w_range_set:r_range_set) | ||
.insert( | ||
std::pair<const irep_idt &, std::unique_ptr<range_domain_baset>>( | ||
identifier, nullptr)) | ||
.first; | ||
|
||
if(entry->second==0) | ||
entry->second=new range_domaint(); | ||
if(entry->second==nullptr) | ||
entry->second=util_make_unique<range_domaint>(); | ||
|
||
static_cast<range_domaint*>(entry->second)->push_back( | ||
static_cast<range_domaint&>(*entry->second).push_back( | ||
std::make_pair(range_start, range_end)); | ||
} | ||
|
||
|
@@ -662,16 +667,18 @@ void rw_guarded_range_set_value_sett::add( | |
const range_spect &range_start, | ||
const range_spect &range_end) | ||
{ | ||
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; | ||
|
||
if(entry->second==0) | ||
entry->second=new guarded_range_domaint(); | ||
|
||
static_cast<guarded_range_domaint*>(entry->second)->insert( | ||
std::make_pair(range_start, | ||
std::make_pair(range_end, guard.as_expr()))); | ||
objectst::iterator entry= | ||
(mode==get_modet::LHS_W?w_range_set:r_range_set) | ||
.insert( | ||
std::pair<const irep_idt &, std::unique_ptr<range_domain_baset>>( | ||
identifier, nullptr)) | ||
.first; | ||
|
||
if(entry->second==nullptr) | ||
entry->second=util_make_unique<guarded_range_domaint>(); | ||
|
||
static_cast<guarded_range_domaint&>(*entry->second).insert( | ||
std::make_pair(range_start, std::make_pair(range_end, guard.as_expr()))); | ||
} | ||
|
||
void goto_rw(goto_programt::const_targett target, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ Date: April 2010 | |
#include <map> | ||
#include <ostream> | ||
#include <limits> | ||
#include <memory> // unique_ptr | ||
|
||
#include <util/guard.h> | ||
|
||
|
@@ -83,10 +84,10 @@ class rw_range_sett | |
{ | ||
public: | ||
#ifdef USE_DSTRING | ||
typedef std::map<irep_idt, range_domain_baset*> objectst; | ||
typedef std::map<irep_idt, std::unique_ptr<range_domain_baset>> objectst; | ||
#else | ||
typedef std::unordered_map<irep_idt, range_domain_baset*, string_hash> | ||
objectst; | ||
typedef std::unordered_map< | ||
irep_idt, std::unique_ptr<range_domain_baset>, string_hash> objectst; | ||
#endif | ||
|
||
virtual ~rw_range_sett(); | ||
|
@@ -108,8 +109,8 @@ class rw_range_sett | |
|
||
const range_domaint &get_ranges(objectst::const_iterator it) const | ||
{ | ||
assert(dynamic_cast<range_domaint*>(it->second)!=0); | ||
return *static_cast<range_domaint*>(it->second); | ||
assert(dynamic_cast<range_domaint*>(it->second.get())); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While you're modifying the line, can this become There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not against this, but wonder whether it should really be part of this PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @reuk Yup you're right - it is already a big change |
||
return static_cast<const range_domaint &>(*it->second); | ||
} | ||
|
||
enum class get_modet { LHS_W, READ }; | ||
|
@@ -277,8 +278,8 @@ 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); | ||
return *static_cast<guarded_range_domaint*>(it->second); | ||
assert(dynamic_cast<guarded_range_domaint*>(it->second.get())!=nullptr); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While you're modifying the line, can this become INVARIANT or possibly one of the others? |
||
return static_cast<const guarded_range_domaint &>(*it->second); | ||
} | ||
|
||
virtual void get_objects_rec( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,10 +12,11 @@ Author: Daniel Kroening, [email protected] | |
#ifndef CPROVER_ANALYSES_LOCAL_MAY_ALIAS_H | ||
#define CPROVER_ANALYSES_LOCAL_MAY_ALIAS_H | ||
|
||
#include <stack> | ||
#include <memory> | ||
#include <stack> | ||
|
||
#include <util/union_find.h> | ||
#include <util/make_unique.h> | ||
|
||
#include "locals.h" | ||
#include "dirty.h" | ||
|
@@ -117,8 +118,7 @@ class local_may_alias_factoryt | |
goto_functionst::function_mapt::const_iterator f_it2= | ||
goto_functions->function_map.find(fkt); | ||
assert(f_it2!=goto_functions->function_map.end()); | ||
return *(fkt_map[fkt]=std::unique_ptr<local_may_aliast>( | ||
new local_may_aliast(f_it2->second))); | ||
return *(fkt_map[fkt]=util_make_unique<local_may_aliast>(f_it2->second)); | ||
} | ||
|
||
local_may_aliast &operator()(goto_programt::const_targett t) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -240,14 +240,7 @@ class reaching_definitions_analysist: | |
{ | ||
public: | ||
// constructor | ||
explicit reaching_definitions_analysist(const namespacet &_ns): | ||
concurrency_aware_ait<rd_range_domaint>(), | ||
ns(_ns), | ||
value_sets(0), | ||
is_threaded(0), | ||
is_dirty(0) | ||
{ | ||
} | ||
explicit reaching_definitions_analysist(const namespacet &_ns); | ||
|
||
virtual ~reaching_definitions_analysist(); | ||
|
||
|
@@ -286,9 +279,9 @@ class reaching_definitions_analysist: | |
|
||
protected: | ||
const namespacet &ns; | ||
value_setst * value_sets; | ||
is_threadedt * is_threaded; | ||
dirtyt * is_dirty; | ||
std::unique_ptr<value_setst> value_sets; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need a |
||
std::unique_ptr<is_threadedt> is_threaded; | ||
std::unique_ptr<dirtyt> is_dirty; | ||
}; | ||
|
||
#endif // CPROVER_ANALYSES_REACHING_DEFINITIONS_H |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,10 +16,13 @@ Author: Daniel Kroening, [email protected] | |
#error Deprecated, use ai.h instead | ||
#endif | ||
|
||
#include <map> | ||
#include <iosfwd> | ||
#include <map> | ||
#include <memory> | ||
#include <unordered_set> | ||
|
||
#include <util/make_unique.h> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
#include <goto-programs/goto_functions.h> | ||
|
||
// don't use me -- I am just a base class | ||
|
@@ -252,7 +255,7 @@ class static_analysis_baset | |
virtual void generate_state(locationt l)=0; | ||
virtual statet &get_state(locationt l)=0; | ||
virtual const statet &get_state(locationt l) const=0; | ||
virtual statet* make_temporary_state(statet &s)=0; | ||
virtual std::unique_ptr<statet> make_temporary_state(statet &s)=0; | ||
|
||
typedef domain_baset::expr_sett expr_sett; | ||
|
||
|
@@ -331,9 +334,9 @@ class static_analysist:public static_analysis_baset | |
return static_cast<T &>(a).merge(static_cast<const T &>(b), to); | ||
} | ||
|
||
virtual statet *make_temporary_state(statet &s) | ||
virtual std::unique_ptr<statet> make_temporary_state(statet &s) | ||
{ | ||
return new T(static_cast<T &>(s)); | ||
return util_make_unique<T>(static_cast<T &>(s)); | ||
} | ||
|
||
virtual void generate_state(locationt l) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,10 @@ Author: Daniel Kroening, [email protected] | |
|
||
/*! \defgroup gr_ansi_c ANSI-C front-end */ | ||
|
||
#include <memory> | ||
|
||
#include <util/language.h> | ||
#include <util/make_unique.h> | ||
|
||
#include "ansi_c_parse_tree.h" | ||
|
||
|
@@ -64,8 +67,8 @@ class ansi_c_languaget:public languaget | |
exprt &expr, | ||
const namespacet &ns) override; | ||
|
||
languaget *new_language() override | ||
{ return new ansi_c_languaget; } | ||
std::unique_ptr<languaget> new_language() override | ||
{ return util_make_unique<ansi_c_languaget>(); } | ||
|
||
std::string id() const override { return "C"; } | ||
std::string description() const override { return "ANSI-C 99"; } | ||
|
@@ -78,6 +81,6 @@ class ansi_c_languaget:public languaget | |
std::string parse_path; | ||
}; | ||
|
||
languaget *new_ansi_c_language(); | ||
std::unique_ptr<languaget> new_ansi_c_language(); | ||
|
||
#endif // CPROVER_ANSI_C_ANSI_C_LANGUAGE_H |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we need
#include <memory>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
util/make_unique.h
itself includesmemory
. My preference would be to leave it as-is, and then if we change to C++14 we can find-and-replaceutil/make_unique -> memory
andutil_make_unique -> std::make_unique
.