Skip to content

Commit c39df55

Browse files
Remove java dependency
Lower bound should not use java_type
1 parent f2c47bf commit c39df55

6 files changed

+42
-19
lines changed

src/solvers/refinement/string_constraint.cpp

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,37 @@
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()
16+
? from_integer(0, upper_bound.type())
17+
: lower_bound_value;
18+
}
19+
20+
void string_constraintt::lower_bound(const exprt &e)
21+
{
22+
lower_bound_value = e;
23+
}
24+
825
void replace(string_constraintt &axiom, const replace_mapt &symbol_resolve)
926
{
1027
replace_expr(symbol_resolve, axiom.index_guard);
1128
replace_expr(symbol_resolve, axiom.body);
1229
replace_expr(symbol_resolve, axiom.univ_var);
1330
replace_expr(symbol_resolve, axiom.upper_bound);
14-
replace_expr(symbol_resolve, axiom.lower_bound);
31+
if(const auto lower_bound = axiom.lower_bound())
32+
replace_expr(symbol_resolve, *lower_bound);
1533
}
1634

1735
exprt univ_within_bounds(const string_constraintt &axiom)
1836
{
1937
return and_exprt(
20-
binary_relation_exprt(axiom.lower_bound, ID_le, axiom.univ_var),
38+
binary_relation_exprt(axiom.get_lower_bound(), ID_le, axiom.univ_var),
2139
binary_relation_exprt(axiom.upper_bound, ID_gt, axiom.univ_var));
2240
}
2341

@@ -27,7 +45,7 @@ std::string from_expr(
2745
const string_constraintt &expr)
2846
{
2947
return "forall " + from_expr(ns, identifier, expr.univ_var) + " in [" +
30-
from_expr(ns, identifier, expr.lower_bound) + ", " +
48+
from_expr(ns, identifier, expr.get_lower_bound()) + ", " +
3149
from_expr(ns, identifier, expr.upper_bound) + "). " +
3250
from_expr(ns, identifier, expr.index_guard) + " => " +
3351
from_expr(ns, identifier, expr.body);

src/solvers/refinement/string_constraint.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,19 @@ class string_constraintt final
6161
exprt index_guard = true_exprt(); // Index guard
6262
exprt body; // value constraint
6363
symbol_exprt univ_var;
64-
// \todo avoid depending on java type
65-
exprt lower_bound = from_integer(0, java_int_type());
6664
exprt upper_bound;
65+
66+
/// \return lower_bound if it has been set, nullptr if undefined
67+
exprt * lower_bound();
68+
69+
/// \return lower_bound if it has been set, expression for 0 otherwise
70+
exprt get_lower_bound() const;
71+
72+
/// Set lower bound to `e`
73+
void lower_bound(const exprt &e);
74+
75+
private:
76+
exprt lower_bound_value = nil_exprt(); // nil_exprt defaults to 0
6777
};
6878

6979
inline void
@@ -73,7 +83,8 @@ replace(string_constraintt &axiom, const union_find_replacet &symbol_resolve)
7383
symbol_resolve.replace_expr(axiom.body);
7484
symbol_resolve.replace_expr(axiom.univ_var);
7585
symbol_resolve.replace_expr(axiom.upper_bound);
76-
symbol_resolve.replace_expr(axiom.lower_bound);
86+
if(axiom.lower_bound())
87+
symbol_resolve.replace_expr(*axiom.lower_bound());
7788
}
7889

7990
exprt univ_within_bounds(const string_constraintt &axiom);

src/solvers/refinement/string_constraint_generator_indexof.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ 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.index_guard = contains;
7272
a4.body = not_exprt(equal_exprt(str[n], c));
@@ -75,7 +75,7 @@ exprt string_constraint_generatort::add_axioms_for_index_of(
7575
symbol_exprt m=fresh_univ_index("QA_index_of", index_type);
7676
string_constraintt a5;
7777
a5.univ_var = m;
78-
a5.lower_bound = lower_bound;
78+
a5.lower_bound(lower_bound);
7979
a5.upper_bound = str.length();
8080
a5.index_guard = not_exprt(contains);
8181
a5.body = notequal_exprt(str[m], c);
@@ -370,7 +370,7 @@ exprt string_constraint_generatort::add_axioms_for_last_index_of(
370370
const symbol_exprt n = fresh_univ_index("QA_last_index_of1", index_type);
371371
string_constraintt a4;
372372
a4.univ_var = n;
373-
a4.lower_bound = plus_exprt(index, index1);
373+
a4.lower_bound(plus_exprt(index, index1));
374374
a4.upper_bound = end_index;
375375
a4.index_guard = contains;
376376
a4.body = notequal_exprt(str[n], c);

src/solvers/refinement/string_constraint_generator_main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ void string_constraint_generatort::add_constraint_on_characters(
372372
binary_relation_exprt(chr, ID_le, from_integer(high_char, chr.type())));
373373
string_constraintt sc;
374374
sc.univ_var = qvar;
375-
sc.lower_bound = start;
375+
sc.lower_bound(start);
376376
sc.upper_bound = end;
377377
sc.body = char_in_set;
378378
constraints.push_back(sc);

src/solvers/refinement/string_constraint_generator_transformation.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,6 @@ exprt string_constraint_generatort::add_axioms_for_char_set(
438438

439439
string_constraintt a3;
440440
a3.univ_var = q;
441-
a3.lower_bound = from_integer(0, q.type());
442441
a3.upper_bound = res.length();
443442
a3.index_guard = a3_guard;
444443
a3.body = a3_body;

src/solvers/refinement/string_refinement.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ Author: Alberto Griggio, alberto.griggio@gmail.com
3030
#include <java_bytecode/java_types.h>
3131
#include <unordered_set>
3232

33-
static bool is_valid_string_constraint(
34-
messaget::mstreamt &stream,
35-
const namespacet &ns,
36-
const string_constraintt &expr);
37-
3833
static optionalt<exprt> find_counter_example(
3934
const namespacet &ns,
4035
ui_message_handlert::uit ui,
@@ -1569,7 +1564,7 @@ static exprt negation_of_not_contains_constraint(
15691564
static exprt negation_of_constraint(const string_constraintt &axiom)
15701565
{
15711566
// If the for all is vacuously true, the negation is false.
1572-
const exprt &lb = axiom.lower_bound;
1567+
const exprt &lb = axiom.get_lower_bound();
15731568
const exprt &ub = axiom.upper_bound;
15741569
if(lb.id()==ID_constant && ub.id()==ID_constant)
15751570
{
@@ -1707,14 +1702,14 @@ static std::pair<bool, std::vector<exprt>> check_axioms(
17071702
{
17081703
const string_constraintt &axiom=axioms.universal[i];
17091704
const symbol_exprt &univ_var = axiom.univ_var;
1710-
const exprt &bound_inf = axiom.lower_bound;
1705+
const exprt &bound_inf = axiom.get_lower_bound();
17111706
const exprt &bound_sup = axiom.upper_bound;
17121707
const exprt &prem = axiom.index_guard;
17131708
const exprt &body = axiom.body;
17141709

17151710
string_constraintt axiom_in_model;
17161711
axiom_in_model.univ_var = univ_var;
1717-
axiom_in_model.lower_bound = get(bound_inf);
1712+
axiom_in_model.lower_bound(get(bound_inf));
17181713
axiom_in_model.upper_bound = get(bound_sup);
17191714
axiom_in_model.index_guard = get(prem);
17201715
axiom_in_model.body = get(body);

0 commit comments

Comments
 (0)