Skip to content

Commit 302f92e

Browse files
Make string primitives return return_code_type
This could potentially be used to signal exceptions. For primitives whose result is a string given as first parameter, the returned value should have an integer type has given by get_return_code_type().
1 parent b80d063 commit 302f92e

6 files changed

+19
-10
lines changed

src/solvers/refinement/string_constraint_generator.h

+6
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ class string_constraint_generatort final
9393

9494
exprt get_length_of_string_array(const array_string_exprt &s) const;
9595

96+
// Type used by primitives to signal errors
97+
const signedbv_typet get_return_code_type()
98+
{
99+
return signedbv_typet(32);
100+
}
101+
96102
private:
97103
symbol_exprt fresh_boolean(const irep_idt &prefix);
98104
array_string_exprt

src/solvers/refinement/string_constraint_generator_code_points.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ exprt string_constraint_generatort::add_axioms_for_code_point(
6363
equal_exprt(res[1], typecast_exprt(second_char, char_type)));
6464
m_axioms.push_back(a5);
6565

66-
return res;
66+
return from_integer(0, get_return_code_type());
6767
}
6868

6969
/// the output is true when the character is a high surrogate for UTF-16

src/solvers/refinement/string_constraint_generator_concat.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ exprt string_constraint_generatort::add_axioms_for_concat_char(
9393
m_axioms.push_back(a3);
9494

9595
// We should have a enum type for the possible error codes
96-
return from_integer(0, return_code_type);
96+
return from_integer(0, get_return_code_type());
9797
}
9898

9999
/// Add axioms to say that `res` is equal to the concatenation of `s1` and `s2`.

src/solvers/refinement/string_constraint_generator_constants.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ exprt string_constraint_generatort::add_axioms_for_constant(
4848
const exprt s_length = from_integer(str.size(), index_type);
4949

5050
m_axioms.push_back(res.axiom_for_has_length(s_length));
51-
return from_integer(0, signedbv_typet(32));
51+
return from_integer(0, get_return_code_type());
5252
}
5353

5454
/// add axioms to say that the returned string expression is empty
@@ -60,7 +60,7 @@ exprt string_constraint_generatort::add_axioms_for_empty_string(
6060
PRECONDITION(f.arguments().size() == 2);
6161
exprt length = f.arguments()[0];
6262
m_axioms.push_back(equal_exprt(length, from_integer(0, length.type())));
63-
return from_integer(0, length.type());
63+
return from_integer(0, get_return_code_type());
6464
}
6565

6666
/// add axioms to say that the returned string expression is equal to the string

src/solvers/refinement/string_constraint_generator_main.cpp

+7-4
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@ Author: Romain Brenguier, [email protected]
2828
#include <util/ssa_expr.h>
2929

3030
string_constraint_generatort::string_constraint_generatort(
31-
const string_constraint_generatort::infot& info, const namespacet& ns):
32-
max_string_length(info.string_max_length),
33-
m_force_printable_characters(info.string_printable),
34-
m_ns(ns) { }
31+
const string_constraint_generatort::infot &info,
32+
const namespacet &ns)
33+
: max_string_length(info.string_max_length),
34+
m_force_printable_characters(info.string_printable),
35+
m_ns(ns)
36+
{
37+
}
3538

3639
const std::vector<exprt> &string_constraint_generatort::get_axioms() const
3740
{

src/solvers/refinement/string_constraint_generator_valueof.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ exprt string_constraint_generatort::add_axioms_from_int_hex(
244244
m_axioms.push_back(
245245
implies_exprt(premise, not_exprt(equal_exprt(res[0], zero_char))));
246246
}
247-
return res;
247+
return from_integer(0, get_return_code_type());
248248
}
249249

250250
/// add axioms corresponding to the Integer.toHexString(I) java function
@@ -282,7 +282,7 @@ exprt string_constraint_generatort::add_axioms_from_char(
282282
{
283283
and_exprt lemma(equal_exprt(res[0], c), res.axiom_for_has_length(1));
284284
m_axioms.push_back(lemma);
285-
return from_integer(0, signedbv_typet(32));
285+
return from_integer(0, get_return_code_type());
286286
}
287287

288288
/// Add axioms making the return value true if the given string is a correct

0 commit comments

Comments
 (0)