Skip to content

Commit 797a71d

Browse files
Remove java dependency
Lower bound should not use java_type
1 parent 81c904c commit 797a71d

5 files changed

+42
-15
lines changed

src/solvers/refinement/string_constraint.cpp

+21-4
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,45 @@
55
#include <util/simplify_expr.h>
66
#include <util/expr_iterator.h>
77

8+
exprt *string_constraintt::lower_bound()
9+
{
10+
return lower_bound_value.is_nil() ? nullptr : &lower_bound_value;
11+
}
12+
13+
exprt string_constraintt::get_lower_bound() const
14+
{
15+
return lower_bound_value.is_nil() ? from_integer(0, upper_bound.type())
16+
: lower_bound_value;
17+
}
18+
19+
void string_constraintt::lower_bound(const exprt &e)
20+
{
21+
lower_bound_value = e;
22+
}
23+
824
void replace(string_constraintt &axiom, const replace_mapt &symbol_resolve)
925
{
1026
replace_expr(symbol_resolve, axiom.index_guard);
1127
replace_expr(symbol_resolve, axiom.body);
1228
replace_expr(symbol_resolve, axiom.univ_var);
1329
replace_expr(symbol_resolve, axiom.upper_bound);
14-
replace_expr(symbol_resolve, axiom.lower_bound);
30+
if(const auto lower_bound = axiom.lower_bound())
31+
replace_expr(symbol_resolve, *lower_bound);
1532
}
1633

1734
exprt univ_within_bounds(const string_constraintt &axiom)
1835
{
1936
return and_exprt(
20-
binary_relation_exprt(axiom.lower_bound, ID_le, axiom.univ_var),
37+
binary_relation_exprt(axiom.get_lower_bound(), ID_le, axiom.univ_var),
2138
binary_relation_exprt(axiom.upper_bound, ID_gt, axiom.univ_var));
2239
}
2340

2441
std::string to_string(const string_constraintt &expr)
2542
{
2643
std::ostringstream out;
2744
out << "forall " << format(expr.univ_var) << " in ["
28-
<< format(expr.lower_bound) << ", " << format(expr.upper_bound) << "). "
29-
<< format(expr.index_guard) << " => " << format(expr.body);
45+
<< format(expr.get_lower_bound()) << ", " << format(expr.upper_bound)
46+
<< "). " << format(expr.index_guard) << " => " << format(expr.body);
3047
return out.str();
3148
}
3249

src/solvers/refinement/string_constraint.h

+14-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ Author: Romain Brenguier, [email protected]
2828
#include <util/refined_string_type.h>
2929
#include <util/string_expr.h>
3030
#include <langapi/language_util.h>
31-
#include <java_bytecode/java_types.h>
3231
#include <util/union_find_replace.h>
3332

3433
/// ### Universally quantified string constraint
@@ -65,9 +64,19 @@ class string_constraintt final
6564
exprt index_guard = true_exprt(); // Index guard
6665
exprt body; // value constraint
6766
symbol_exprt univ_var;
68-
// \todo avoid depending on java type
69-
exprt lower_bound = from_integer(0, java_int_type());
7067
exprt upper_bound;
68+
69+
/// \return lower_bound if it has been set, nullptr if undefined
70+
exprt *lower_bound();
71+
72+
/// \return lower_bound if it has been set, expression for 0 otherwise
73+
exprt get_lower_bound() const;
74+
75+
/// Set lower bound to `e`
76+
void lower_bound(const exprt &e);
77+
78+
private:
79+
exprt lower_bound_value = nil_exprt(); // nil_exprt defaults to 0
7180
};
7281

7382
inline void
@@ -77,7 +86,8 @@ replace(string_constraintt &axiom, const union_find_replacet &symbol_resolve)
7786
symbol_resolve.replace_expr(axiom.body);
7887
symbol_resolve.replace_expr(axiom.univ_var);
7988
symbol_resolve.replace_expr(axiom.upper_bound);
80-
symbol_resolve.replace_expr(axiom.lower_bound);
89+
if(axiom.lower_bound())
90+
symbol_resolve.replace_expr(*axiom.lower_bound());
8191
}
8292

8393
exprt univ_within_bounds(const string_constraintt &axiom);

src/solvers/refinement/string_constraint_generator_indexof.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,15 @@ exprt string_constraint_generatort::add_axioms_for_index_of(
6666
symbol_exprt n=fresh_univ_index("QA_index_of", index_type);
6767
string_constraintt a4;
6868
a4.univ_var = n;
69-
a4.lower_bound = lower_bound;
69+
a4.lower_bound(lower_bound);
7070
a4.upper_bound = index;
7171
a4.body = implies_exprt(contains, not_exprt(equal_exprt(str[n], c)));
7272
constraints.push_back(a4);
7373

7474
symbol_exprt m=fresh_univ_index("QA_index_of", index_type);
7575
string_constraintt a5;
7676
a5.univ_var = m;
77-
a5.lower_bound = lower_bound;
77+
a5.lower_bound(lower_bound);
7878
a5.upper_bound = str.length();
7979
a5.body = implies_exprt(not_exprt(contains), notequal_exprt(str[m], c));
8080
constraints.push_back(a5);
@@ -366,7 +366,7 @@ exprt string_constraint_generatort::add_axioms_for_last_index_of(
366366
const symbol_exprt n = fresh_univ_index("QA_last_index_of1", index_type);
367367
string_constraintt a4;
368368
a4.univ_var = n;
369-
a4.lower_bound = plus_exprt(index, index1);
369+
a4.lower_bound(plus_exprt(index, index1));
370370
a4.upper_bound = end_index;
371371
a4.body = implies_exprt(contains, notequal_exprt(str[n], c));
372372
constraints.push_back(a4);

src/solvers/refinement/string_constraint_generator_main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ void string_constraint_generatort::add_constraint_on_characters(
371371
binary_relation_exprt(chr, ID_le, from_integer(high_char, chr.type())));
372372
string_constraintt sc;
373373
sc.univ_var = qvar;
374-
sc.lower_bound = start;
374+
sc.lower_bound(start);
375375
sc.upper_bound = end;
376376
sc.body = char_in_set;
377377
constraints.push_back(sc);

src/solvers/refinement/string_refinement.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1393,7 +1393,7 @@ static exprt negation_of_not_contains_constraint(
13931393
static exprt negation_of_constraint(const string_constraintt &axiom)
13941394
{
13951395
// If the for all is vacuously true, the negation is false.
1396-
const exprt &lb = axiom.lower_bound;
1396+
const exprt &lb = axiom.get_lower_bound();
13971397
const exprt &ub = axiom.upper_bound;
13981398
if(lb.id()==ID_constant && ub.id()==ID_constant)
13991399
{
@@ -1529,15 +1529,15 @@ static std::pair<bool, std::vector<exprt>> check_axioms(
15291529
{
15301530
const string_constraintt &axiom=axioms.universal[i];
15311531
const symbol_exprt &univ_var = axiom.univ_var;
1532-
const exprt &bound_inf = axiom.lower_bound;
1532+
const exprt &bound_inf = axiom.get_lower_bound();
15331533
const exprt &bound_sup = axiom.upper_bound;
15341534
const exprt &prem = axiom.index_guard;
15351535
INVARIANT(
15361536
prem == true_exprt(), "string constraint premises are not supported");
15371537

15381538
string_constraintt axiom_in_model;
15391539
axiom_in_model.univ_var = univ_var;
1540-
axiom_in_model.lower_bound = get(bound_inf);
1540+
axiom_in_model.lower_bound(get(bound_inf));
15411541
axiom_in_model.upper_bound = get(bound_sup);
15421542
axiom_in_model.index_guard = get(prem);
15431543
axiom_in_model.body = get(axiom.body);

0 commit comments

Comments
 (0)