Skip to content

Commit cfb47db

Browse files
author
Lukasz A.J. Wrona
committed
Remove unused functions from string_refinement header
1 parent 8e69d6d commit cfb47db

File tree

2 files changed

+50
-54
lines changed

2 files changed

+50
-54
lines changed

src/solvers/refinement/string_refinement.cpp

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,14 @@ Author: Alberto Griggio, [email protected]
3535
#include <java_bytecode/java_types.h>
3636
#include <util/optional.h>
3737

38+
static exprt substitute_array_with_expr(const exprt &expr, const exprt &index);
3839
static exprt instantiate(
3940
const string_constraintt &axiom, const exprt &str, const exprt &val);
41+
static bool is_char_array(const namespacet &ns, const typet &type);
42+
exprt substitute_array_lists(exprt expr, size_t string_max_length);
43+
exprt concretize_arrays_in_expression(
44+
exprt expr, std::size_t string_max_length);
45+
4046
exprt simplify_sum(const exprt &f);
4147

4248
/// Convert exprt to a specific type. Throw bad_cast if conversion
@@ -83,6 +89,37 @@ T expr_cast_v(const exprt& expr) {
8389
return *maybe;
8490
}
8591

92+
/// Convert index-value map to a vector of values. If a value for an
93+
/// index is not defined, set it to the value referenced by the next higher
94+
/// index. The length of the resulting vector is the key of the map's
95+
/// last element + 1
96+
/// \param index_value: map containing values of specific vector cells
97+
/// \return Vector containing values as described in the map
98+
template <typename T>
99+
static std::vector<T> fill_in_map_as_vector(
100+
const std::map<std::size_t, T> &index_value)
101+
{
102+
std::vector<T> result;
103+
if(!index_value.empty())
104+
{
105+
result.resize(index_value.rbegin()->first+1);
106+
for(auto it=index_value.rbegin(); it!=index_value.rend(); ++it)
107+
{
108+
const std::size_t index=it->first;
109+
const T value=it->second;
110+
const auto next=std::next(it);
111+
const std::size_t leftmost_index_to_pad=
112+
next!=index_value.rend()
113+
? next->first+1
114+
: 0;
115+
for(std::size_t j=leftmost_index_to_pad; j<=index; j++)
116+
result[j]=value;
117+
}
118+
}
119+
return result;
120+
}
121+
122+
86123
static bool validate(const string_refinementt::infot &info)
87124
{
88125
PRECONDITION(info.ns);
@@ -263,13 +300,14 @@ void string_refinementt::set_char_array_equality(
263300
/// remove functions applications and create the necessary axioms
264301
/// \par parameters: an expression containing function applications
265302
/// \return an expression containing no function application
266-
exprt string_refinementt::substitute_function_applications(exprt expr)
303+
exprt substitute_function_applications(
304+
string_constraint_generatort& generator, exprt expr)
267305
{
268306
for(size_t i=0; i<expr.operands().size(); ++i)
269307
{
270308
// TODO: only copy when necessary
271309
exprt op(expr.operands()[i]);
272-
expr.operands()[i]=substitute_function_applications(op);
310+
expr.operands()[i]=substitute_function_applications(generator, op);
273311
}
274312

275313
if(expr.id()==ID_function_application)
@@ -286,10 +324,10 @@ exprt string_refinementt::substitute_function_applications(exprt expr)
286324
/// TODO: this is only for java char array and does not work for other languages
287325
/// \param type: a type
288326
/// \return true if the given type is an array of java characters
289-
bool string_refinementt::is_char_array(const typet &type) const
327+
static bool is_char_array(const namespacet &ns, const typet &type)
290328
{
291329
if(type.id()==ID_symbol)
292-
return is_char_array(ns.follow(type));
330+
return is_char_array(ns, ns.follow(type));
293331

294332
return (type.id()==ID_array && type.subtype()==java_char_type());
295333
}
@@ -302,7 +340,7 @@ bool string_refinementt::is_char_array(const typet &type) const
302340
bool string_refinementt::add_axioms_for_string_assigns(
303341
const exprt &lhs, const exprt &rhs)
304342
{
305-
if(is_char_array(rhs.type()))
343+
if(is_char_array(ns, rhs.type()))
306344
{
307345
set_char_array_equality(lhs, rhs);
308346
if(rhs.id() == ID_symbol || rhs.id() == ID_array)
@@ -444,10 +482,10 @@ void string_refinementt::set_to(const exprt &expr, bool value)
444482
const exprt &rhs=eq_expr.rhs();
445483

446484
// The assignment of a string equality to false is not supported.
447-
PRECONDITION(value || !is_char_array(rhs.type()));
485+
PRECONDITION(value || !is_char_array(ns, rhs.type()));
448486
PRECONDITION(value || !is_refined_string_type(rhs.type()));
449487

450-
PRECONDITION(lhs.id()==ID_symbol || !is_char_array(rhs.type()));
488+
PRECONDITION(lhs.id()==ID_symbol || !is_char_array(ns, rhs.type()));
451489
PRECONDITION(lhs.id()==ID_symbol || !is_refined_string_type(rhs.type()));
452490

453491
// If lhs is not a symbol, let supert::set_to() handle it.
@@ -470,7 +508,7 @@ void string_refinementt::set_to(const exprt &expr, bool value)
470508
debug() << "(sr::set_to) " << from_expr(ns, "", lhs)
471509
<< " = " << from_expr(ns, "", rhs) << eom;
472510

473-
const exprt subst_rhs=substitute_function_applications(rhs);
511+
const exprt subst_rhs=substitute_function_applications(generator, rhs);
474512
if(lhs.type()!=subst_rhs.type())
475513
{
476514
if(lhs.type().id()!=ID_array ||
@@ -832,7 +870,7 @@ void string_refinementt::debug_model()
832870
else
833871
{
834872
INVARIANT(
835-
is_char_array(it.second.type()),
873+
is_char_array(ns, it.second.type()),
836874
string_refinement_invariantt("symbol_resolve should only map to "
837875
"refined_strings or to char_arrays, and refined_strings are already "
838876
"handled"));
@@ -868,8 +906,7 @@ void string_refinementt::debug_model()
868906
/// expression
869907
/// \param index: An index with which to build the equality condition
870908
/// \return An expression containing no 'with' expression
871-
exprt string_refinementt::substitute_array_with_expr(
872-
const exprt &expr, const exprt &index) const
909+
static exprt substitute_array_with_expr(const exprt &expr, const exprt &index)
873910
{
874911
if(expr.id()==ID_with)
875912
{
@@ -941,7 +978,7 @@ exprt fill_in_array_with_expr(const exprt &expr, std::size_t string_max_length)
941978
/// `arr2 := {34}`, the constructed expression will be: `g1 ? 12 : 34`
942979
/// \param expr: an expression containing array accesses
943980
/// \return an expression containing no array access
944-
void string_refinementt::substitute_array_access(exprt &expr) const
981+
static void substitute_array_access(exprt &expr)
945982
{
946983
for(auto &op : expr.operands())
947984
substitute_array_access(op);
@@ -1732,7 +1769,7 @@ exprt string_refinementt::get(const exprt &expr) const
17321769
{
17331770
exprt ecopy(expr);
17341771
replace_expr(symbol_resolve, ecopy);
1735-
if(is_char_array(ecopy.type()))
1772+
if(is_char_array(ns, ecopy.type()))
17361773
{
17371774
auto it_content=found_content.find(ecopy);
17381775
if(it_content!=found_content.end())

src/solvers/refinement/string_refinement.h

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,7 @@ class string_refinementt final: public bv_refinementt
103103
bool simplify=true,
104104
bool add_to_index_set=true);
105105

106-
exprt substitute_function_applications(exprt expr);
107-
typet substitute_java_string_types(typet type);
108-
exprt substitute_java_strings(exprt expr);
109-
exprt substitute_array_with_expr(const exprt &expr, const exprt &index) const;
110-
void substitute_array_access(exprt &expr) const;
111106
void add_symbol_to_symbol_map(const exprt &lhs, const exprt &rhs);
112-
bool is_char_array(const typet &type) const;
113107
bool add_axioms_for_string_assigns(const exprt &lhs, const exprt &rhs);
114108
void set_to(const exprt &expr, bool value) override;
115109

@@ -144,39 +138,4 @@ class string_refinementt final: public bv_refinementt
144138

145139
std::string string_of_array(const array_exprt &arr);
146140
};
147-
148-
exprt substitute_array_lists(exprt expr, size_t string_max_length);
149-
150-
exprt concretize_arrays_in_expression(
151-
exprt expr, std::size_t string_max_length);
152-
153-
/// Convert index-value map to a vector of values. If a value for an
154-
/// index is not defined, set it to the value referenced by the next higher
155-
/// index. The length of the resulting vector is the key of the map's
156-
/// last element + 1
157-
/// \param index_value: map containing values of specific vector cells
158-
/// \return Vector containing values as described in the map
159-
template <typename T>
160-
std::vector<T> fill_in_map_as_vector(
161-
const std::map<std::size_t, T> &index_value)
162-
{
163-
std::vector<T> result;
164-
if(!index_value.empty())
165-
{
166-
result.resize(index_value.rbegin()->first+1);
167-
for(auto it=index_value.rbegin(); it!=index_value.rend(); ++it)
168-
{
169-
const std::size_t index=it->first;
170-
const T value=it->second;
171-
const auto next=std::next(it);
172-
const std::size_t leftmost_index_to_pad=
173-
next!=index_value.rend()
174-
? next->first+1
175-
: 0;
176-
for(std::size_t j=leftmost_index_to_pad; j<=index; j++)
177-
result[j]=value;
178-
}
179-
}
180-
return result;
181-
}
182141
#endif

0 commit comments

Comments
 (0)