-
Notifications
You must be signed in to change notification settings - Fork 273
Restore irept sharing #1855
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
Closed
NathanJPhillips
wants to merge
1
commit into
diffblue:develop
from
NathanJPhillips:bugfix/restore-irep-sharing
Closed
Restore irept sharing #1855
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,64 +21,40 @@ Author: Daniel Kroening, [email protected] | |
|
||
void exprt::move_to_operands(exprt &expr) | ||
{ | ||
operandst &op=operands(); | ||
op.push_back(static_cast<const exprt &>(get_nil_irep())); | ||
op.back().swap(expr); | ||
move_to_sub(expr); | ||
} | ||
|
||
void exprt::move_to_operands(exprt &e1, exprt &e2) | ||
{ | ||
operandst &op=operands(); | ||
#ifndef USE_LIST | ||
op.reserve(op.size()+2); | ||
#endif | ||
op.push_back(static_cast<const exprt &>(get_nil_irep())); | ||
op.back().swap(e1); | ||
op.push_back(static_cast<const exprt &>(get_nil_irep())); | ||
op.back().swap(e2); | ||
reserve_operands(get_operands_size() + 2); | ||
move_to_sub(e1); | ||
move_to_sub(e2); | ||
} | ||
|
||
void exprt::move_to_operands(exprt &e1, exprt &e2, exprt &e3) | ||
{ | ||
operandst &op=operands(); | ||
#ifndef USE_LIST | ||
op.reserve(op.size()+3); | ||
#endif | ||
op.push_back(static_cast<const exprt &>(get_nil_irep())); | ||
op.back().swap(e1); | ||
op.push_back(static_cast<const exprt &>(get_nil_irep())); | ||
op.back().swap(e2); | ||
op.push_back(static_cast<const exprt &>(get_nil_irep())); | ||
op.back().swap(e3); | ||
reserve_operands(get_operands_size() + 3); | ||
move_to_sub(e1); | ||
move_to_sub(e2); | ||
move_to_sub(e3); | ||
} | ||
|
||
void exprt::copy_to_operands(const exprt &expr) | ||
void exprt::copy_to_operands(exprt expr) | ||
{ | ||
operands().push_back(expr); | ||
// Move the copy created by passing the argument by value to the operands | ||
move_to_operands(expr); | ||
} | ||
|
||
void exprt::copy_to_operands(const exprt &e1, const exprt &e2) | ||
void exprt::copy_to_operands(exprt e1, exprt e2) | ||
{ | ||
operandst &op=operands(); | ||
#ifndef USE_LIST | ||
op.reserve(op.size()+2); | ||
#endif | ||
op.push_back(e1); | ||
op.push_back(e2); | ||
// Move the copies created by passing the arguments by value to the operands | ||
move_to_operands(e1, e2); | ||
} | ||
|
||
void exprt::copy_to_operands( | ||
const exprt &e1, | ||
const exprt &e2, | ||
const exprt &e3) | ||
void exprt::copy_to_operands(exprt e1, exprt e2, exprt e3) | ||
{ | ||
operandst &op=operands(); | ||
#ifndef USE_LIST | ||
op.reserve(op.size()+3); | ||
#endif | ||
op.push_back(e1); | ||
op.push_back(e2); | ||
op.push_back(e3); | ||
// Move the copies created by passing the arguments by value to the operands | ||
move_to_operands(e1, e2, e3); | ||
} | ||
|
||
void exprt::make_typecast(const typet &_type) | ||
|
@@ -105,7 +81,7 @@ void exprt::make_not() | |
|
||
if(id()==ID_not && operands().size()==1) | ||
{ | ||
new_expr.swap(operands().front()); | ||
new_expr.swap(op0()); | ||
} | ||
else | ||
{ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,14 +57,14 @@ const irept &get_nil_irep() | |
|
||
void irept::move_to_named_sub(const irep_namet &name, irept &irep) | ||
{ | ||
add(name).swap(irep); | ||
add(name, std::move(irep)); | ||
irep.clear(); | ||
} | ||
|
||
void irept::move_to_sub(irept &irep) | ||
{ | ||
get_sub().push_back(get_nil_irep()); | ||
get_sub().back().swap(irep); | ||
write(true).sub.push_back(std::move(irep)); | ||
irep.clear(); | ||
} | ||
|
||
const irep_idt &irept::get(const irep_namet &name) const | ||
|
@@ -121,13 +121,13 @@ long long irept::get_long_long(const irep_namet &name) const | |
|
||
void irept::set(const irep_namet &name, const long long value) | ||
{ | ||
add(name).id(std::to_string(value)); | ||
set(name, std::to_string(value)); | ||
} | ||
|
||
void irept::remove(const irep_namet &name) | ||
{ | ||
named_subt &s= | ||
is_comment(name)?get_comments():get_named_sub(); | ||
named_subt &s = | ||
is_comment(name) ? write(true).comments : write(true).named_sub; | ||
|
||
#ifdef SUB_IS_LIST | ||
named_subt::iterator it=named_subt_lower_bound(s, name); | ||
|
@@ -160,47 +160,23 @@ const irept &irept::find(const irep_namet &name) const | |
return it->second; | ||
} | ||
|
||
irept &irept::add(const irep_namet &name) | ||
irept &irept::add(const irep_namet &name, bool mark_sharable) | ||
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. The flag is kinda critical; any chance of some documentation for it? 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. The documentation is now in the header file. |
||
{ | ||
named_subt &s= | ||
is_comment(name)?get_comments():get_named_sub(); | ||
named_subt &s = | ||
is_comment(name) | ||
? write(mark_sharable).comments : write(mark_sharable).named_sub; | ||
|
||
#ifdef SUB_IS_LIST | ||
named_subt::iterator it=named_subt_lower_bound(s, name); | ||
|
||
if(it==s.end() || | ||
it->first!=name) | ||
it=s.insert(it, std::make_pair(name, irept())); | ||
|
||
return it->second; | ||
#else | ||
return s[name]; | ||
#endif | ||
} | ||
|
||
irept &irept::add(const irep_namet &name, const irept &irep) | ||
{ | ||
named_subt &s= | ||
is_comment(name)?get_comments():get_named_sub(); | ||
|
||
#ifdef SUB_IS_LIST | ||
named_subt::iterator it=named_subt_lower_bound(s, name); | ||
|
||
if(it==s.end() || | ||
it->first!=name) | ||
it=s.insert(it, std::make_pair(name, irep)); | ||
else | ||
it->second=irep; | ||
|
||
if(it == s.end() || it->first != name) | ||
it = s.emplace(it, name, irept()); | ||
return it->second; | ||
|
||
#else | ||
std::pair<named_subt::iterator, bool> entry= | ||
s.insert(std::make_pair(name, irep)); | ||
|
||
if(!entry.second) | ||
entry.first->second=irep; | ||
return s[name]; | ||
|
||
return entry.first->second; | ||
#endif | ||
} | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This looks nice in a "use the API, not the internals" kind of way.