-
Notifications
You must be signed in to change notification settings - Fork 273
Value-set analysis: templatise and virtualise to facilitate customisation #1413
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
smowton
merged 4 commits into
diffblue:develop
from
smowton:smowton/feature/prepare_vsa_for_subclasses
Oct 13, 2017
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a2c1685
Templatize and virtualize value-set analysis
smowton 9465771
Value-set analysis: ignore DEAD statements
smowton e669c12
Add unit tests for value-set-analysis customisation
smowton a99b254
Indirect value_set_domaint -> value_sett operations via non-member fu…
smowton 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
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
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 |
---|---|---|
|
@@ -12,10 +12,10 @@ Author: Daniel Kroening, [email protected] | |
#ifndef CPROVER_POINTER_ANALYSIS_SHOW_VALUE_SETS_H | ||
#define CPROVER_POINTER_ANALYSIS_SHOW_VALUE_SETS_H | ||
|
||
#include <pointer-analysis/value_set_analysis.h> | ||
#include <util/ui_message.h> | ||
|
||
class goto_modelt; | ||
class value_set_analysist; | ||
|
||
void show_value_sets( | ||
ui_message_handlert::uit, | ||
|
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 |
---|---|---|
|
@@ -24,8 +24,20 @@ class namespacet; | |
|
||
class value_sett | ||
{ | ||
typedef std::function<void(exprt &, const namespacet &)> expr_simplifiert; | ||
|
||
static expr_simplifiert default_simplifier; | ||
|
||
public: | ||
value_sett():location_number(0) | ||
value_sett(): | ||
location_number(0), | ||
simplifier(default_simplifier) | ||
{ | ||
} | ||
|
||
explicit value_sett(expr_simplifiert simplifier): | ||
location_number(0), | ||
simplifier(std::move(simplifier)) | ||
{ | ||
} | ||
|
||
|
@@ -166,7 +178,7 @@ class value_sett | |
typedef std::unordered_map<idt, entryt, string_hash> valuest; | ||
#endif | ||
|
||
void get_value_set( | ||
void read_value_set( | ||
const exprt &expr, | ||
value_setst::valuest &dest, | ||
const namespacet &ns) const; | ||
|
@@ -213,7 +225,10 @@ class value_sett | |
|
||
void apply_code( | ||
const codet &code, | ||
const namespacet &ns); | ||
const namespacet &ns) | ||
{ | ||
apply_code_rec(code, ns); | ||
} | ||
|
||
void assign( | ||
const exprt &lhs, | ||
|
@@ -232,7 +247,7 @@ class value_sett | |
const exprt &lhs, | ||
const namespacet &ns); | ||
|
||
void get_reference_set( | ||
void read_reference_set( | ||
const exprt &expr, | ||
value_setst::valuest &dest, | ||
const namespacet &ns) const; | ||
|
@@ -242,13 +257,6 @@ class value_sett | |
const namespacet &ns) const; | ||
|
||
protected: | ||
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. Prefer to make these 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 virtual override points definitely need defer-to-base I'm afraid |
||
void get_value_set_rec( | ||
const exprt &expr, | ||
object_mapt &dest, | ||
const std::string &suffix, | ||
const typet &original_type, | ||
const namespacet &ns) const; | ||
|
||
void get_value_set( | ||
const exprt &expr, | ||
object_mapt &dest, | ||
|
@@ -272,13 +280,6 @@ class value_sett | |
const exprt &src, | ||
exprt &dest) const; | ||
|
||
void assign_rec( | ||
const exprt &lhs, | ||
const object_mapt &values_rhs, | ||
const std::string &suffix, | ||
const namespacet &ns, | ||
bool add_to_sets); | ||
|
||
void do_free( | ||
const exprt &op, | ||
const namespacet &ns); | ||
|
@@ -287,6 +288,67 @@ class value_sett | |
const exprt &src, | ||
const irep_idt &component_name, | ||
const namespacet &ns); | ||
|
||
// Expression simplification: | ||
|
||
private: | ||
/// Expression simplification function; by default, plain old | ||
/// util/simplify_expr, but can be customised by subclass. | ||
expr_simplifiert simplifier; | ||
|
||
protected: | ||
/// Run registered expression simplifier | ||
void run_simplifier(exprt &e, const namespacet &ns) | ||
{ | ||
simplifier(e, ns); | ||
} | ||
|
||
// Subclass customisation points: | ||
|
||
protected: | ||
/// Subclass customisation point for recursion over RHS expression: | ||
virtual void get_value_set_rec( | ||
const exprt &expr, | ||
object_mapt &dest, | ||
const std::string &suffix, | ||
const typet &original_type, | ||
const namespacet &ns) const; | ||
|
||
/// Subclass customisation point for recursion over LHS expression: | ||
virtual void assign_rec( | ||
const exprt &lhs, | ||
const object_mapt &values_rhs, | ||
const std::string &suffix, | ||
const namespacet &ns, | ||
bool add_to_sets); | ||
|
||
/// Subclass customisation point for applying code to this domain: | ||
virtual void apply_code_rec( | ||
const codet &code, | ||
const namespacet &ns); | ||
|
||
private: | ||
/// Subclass customisation point to filter or otherwise alter the value-set | ||
/// returned from get_value_set before it is passed into assign. For example, | ||
/// this is used in one subclass to tag and thus differentiate values that | ||
/// originated in a particular place, vs. those that have been copied. | ||
virtual void adjust_assign_rhs_values( | ||
const exprt &rhs, | ||
const namespacet &ns, | ||
object_mapt &rhs_values) const | ||
{ | ||
} | ||
|
||
/// Subclass customisation point to apply global side-effects to this domain, | ||
/// after RHS values are read but before they are written. For example, this | ||
/// is used in a recency-analysis plugin to demote existing most-recent | ||
/// objects to general case ones. | ||
virtual void apply_assign_side_effects( | ||
const exprt &lhs, | ||
const exprt &rhs, | ||
const namespacet &ns) | ||
{ | ||
} | ||
}; | ||
|
||
#endif // CPROVER_POINTER_ANALYSIS_VALUE_SET_H |
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 |
---|---|---|
|
@@ -13,74 +13,9 @@ Author: Daniel Kroening, [email protected] | |
|
||
#include <util/prefix.h> | ||
#include <util/cprover_prefix.h> | ||
#include <util/xml_expr.h> | ||
#include <util/xml.h> | ||
|
||
#include <langapi/language_util.h> | ||
|
||
void value_set_analysist::initialize( | ||
const goto_programt &goto_program) | ||
{ | ||
baset::initialize(goto_program); | ||
} | ||
|
||
void value_set_analysist::initialize( | ||
const goto_functionst &goto_functions) | ||
{ | ||
baset::initialize(goto_functions); | ||
} | ||
|
||
void value_set_analysist::convert( | ||
const goto_programt &goto_program, | ||
const irep_idt &identifier, | ||
xmlt &dest) const | ||
{ | ||
source_locationt previous_location; | ||
|
||
forall_goto_program_instructions(i_it, goto_program) | ||
{ | ||
const source_locationt &location=i_it->source_location; | ||
|
||
if(location==previous_location) | ||
continue; | ||
|
||
if(location.is_nil() || location.get_file().empty()) | ||
continue; | ||
|
||
// find value set | ||
const value_sett &value_set=(*this)[i_it].value_set; | ||
|
||
xmlt &i=dest.new_element("instruction"); | ||
i.new_element()=::xml(location); | ||
|
||
for(value_sett::valuest::const_iterator | ||
v_it=value_set.values.begin(); | ||
v_it!=value_set.values.end(); | ||
v_it++) | ||
{ | ||
xmlt &var=i.new_element("variable"); | ||
var.new_element("identifier").data= | ||
id2string(v_it->first); | ||
|
||
#if 0 | ||
const value_sett::expr_sett &expr_set= | ||
v_it->second.expr_set(); | ||
|
||
for(value_sett::expr_sett::const_iterator | ||
e_it=expr_set.begin(); | ||
e_it!=expr_set.end(); | ||
e_it++) | ||
{ | ||
std::string value_str= | ||
from_expr(ns, identifier, *e_it); | ||
|
||
var.new_element("value").data= | ||
xmlt::escape(value_str); | ||
} | ||
#endif | ||
} | ||
} | ||
} | ||
void convert( | ||
const goto_functionst &goto_functions, | ||
const value_set_analysist &value_set_analysis, | ||
|
Oops, something went wrong.
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.
Why swap this to a full include when forward declaration was sufficient?
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.
value_set_analysist
is a template specialisation now;class value_set_analysist
won't work as the forward-decl will clash with the actual definition. There might be a way around this but I don't know it.